From 2d7cd02abcd62ffd60fe3c6e16e5189169de349e Mon Sep 17 00:00:00 2001 From: Jesse Hallam Date: Tue, 26 Jun 2018 16:46:58 -0400 Subject: MM-10833: send down computed channel props (#8953) * MM-10833: send down computed channel props This allows channel headers to reference channel mentions for a client that doesn't already know about the channels in question. We intentionally don't send down the props for the autocomplete and search endpoints since they aren't used in that context, and would add unnecessary overhead. * update channel props on patch * revert to treating channel purpose as plaintext --- model/channel.go | 43 ++++++++++++++++++++++++++++--------------- model/channel_mentions.go | 28 ++++++++++++++++++++++++++++ model/post.go | 17 ++--------------- 3 files changed, 58 insertions(+), 30 deletions(-) create mode 100644 model/channel_mentions.go (limited to 'model') diff --git a/model/channel.go b/model/channel.go index 5617240e6..7a57496ae 100644 --- a/model/channel.go +++ b/model/channel.go @@ -32,21 +32,22 @@ const ( ) type Channel struct { - Id string `json:"id"` - CreateAt int64 `json:"create_at"` - UpdateAt int64 `json:"update_at"` - DeleteAt int64 `json:"delete_at"` - TeamId string `json:"team_id"` - Type string `json:"type"` - DisplayName string `json:"display_name"` - Name string `json:"name"` - Header string `json:"header"` - Purpose string `json:"purpose"` - LastPostAt int64 `json:"last_post_at"` - TotalMsgCount int64 `json:"total_msg_count"` - ExtraUpdateAt int64 `json:"extra_update_at"` - CreatorId string `json:"creator_id"` - SchemeId *string `json:"scheme_id"` + Id string `json:"id"` + CreateAt int64 `json:"create_at"` + UpdateAt int64 `json:"update_at"` + DeleteAt int64 `json:"delete_at"` + TeamId string `json:"team_id"` + Type string `json:"type"` + DisplayName string `json:"display_name"` + Name string `json:"name"` + Header string `json:"header"` + Purpose string `json:"purpose"` + LastPostAt int64 `json:"last_post_at"` + TotalMsgCount int64 `json:"total_msg_count"` + ExtraUpdateAt int64 `json:"extra_update_at"` + CreatorId string `json:"creator_id"` + SchemeId *string `json:"scheme_id"` + Props map[string]interface{} `json:"props" db:"-"` } type ChannelPatch struct { @@ -163,6 +164,18 @@ func (o *Channel) Patch(patch *ChannelPatch) { } } +func (o *Channel) MakeNonNil() { + if o.Props == nil { + o.Props = make(map[string]interface{}) + } +} + +func (o *Channel) AddProp(key string, value interface{}) { + o.MakeNonNil() + + o.Props[key] = value +} + func GetDMNameFromIds(userId1, userId2 string) string { if userId1 > userId2 { return userId2 + "__" + userId1 diff --git a/model/channel_mentions.go b/model/channel_mentions.go new file mode 100644 index 000000000..795ec379c --- /dev/null +++ b/model/channel_mentions.go @@ -0,0 +1,28 @@ +// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. +// See License.txt for license information. + +package model + +import ( + "regexp" + "strings" +) + +var channelMentionRegexp = regexp.MustCompile(`\B~[a-zA-Z0-9\-_]+`) + +func ChannelMentions(message string) []string { + var names []string + + if strings.Contains(message, "~") { + alreadyMentioned := make(map[string]bool) + for _, match := range channelMentionRegexp.FindAllString(message, -1) { + name := match[1:] + if !alreadyMentioned[name] { + names = append(names, name) + alreadyMentioned[name] = true + } + } + } + + return names +} diff --git a/model/post.go b/model/post.go index 3d7a31ab5..1dd0a4db6 100644 --- a/model/post.go +++ b/model/post.go @@ -7,7 +7,6 @@ import ( "encoding/json" "io" "net/http" - "regexp" "sort" "strings" "unicode/utf8" @@ -343,20 +342,8 @@ func PostPatchFromJson(data io.Reader) *PostPatch { return &post } -var channelMentionRegexp = regexp.MustCompile(`\B~[a-zA-Z0-9\-_]+`) - -func (o *Post) ChannelMentions() (names []string) { - if strings.Contains(o.Message, "~") { - alreadyMentioned := make(map[string]bool) - for _, match := range channelMentionRegexp.FindAllString(o.Message, -1) { - name := match[1:] - if !alreadyMentioned[name] { - names = append(names, name) - alreadyMentioned[name] = true - } - } - } - return +func (o *Post) ChannelMentions() []string { + return ChannelMentions(o.Message) } func (r *PostActionIntegrationRequest) ToJson() string { -- cgit v1.2.3-1-g7c22 From f17c15c9d83e42e46adb8e8c1fb9706b22fe6f50 Mon Sep 17 00:00:00 2001 From: Emil Velikov Date: Wed, 27 Jun 2018 01:23:13 +0100 Subject: Simplify oauth (#8972) * Remove unused OauthProvider::GetIdentifier Signed-off-by: Emil Velikov * Reuse gitlab's getAuthData() instead of open-coding it Signed-off-by: Emil Velikov * Remove OauthProvider::GetAuthDataFromJson interface The data is already available via GetUserFromJson().AuthData Signed-off-by: Emil Velikov --- model/gitlab/gitlab.go | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) (limited to 'model') diff --git a/model/gitlab/gitlab.go b/model/gitlab/gitlab.go index 7e0cb10af..f0a388b6a 100644 --- a/model/gitlab/gitlab.go +++ b/model/gitlab/gitlab.go @@ -47,7 +47,7 @@ func userFromGitLabUser(glu *GitLabUser) *model.User { user.FirstName = glu.Name } user.Email = glu.Email - userId := strconv.FormatInt(glu.Id, 10) + userId := glu.getAuthData() user.AuthData = &userId user.AuthService = model.USER_AUTH_SERVICE_GITLAB @@ -90,10 +90,6 @@ func (glu *GitLabUser) getAuthData() string { return strconv.FormatInt(glu.Id, 10) } -func (m *GitLabProvider) GetIdentifier() string { - return model.USER_AUTH_SERVICE_GITLAB -} - func (m *GitLabProvider) GetUserFromJson(data io.Reader) *model.User { glu := gitLabUserFromJson(data) if glu.IsValid() { @@ -102,13 +98,3 @@ func (m *GitLabProvider) GetUserFromJson(data io.Reader) *model.User { return &model.User{} } - -func (m *GitLabProvider) GetAuthDataFromJson(data io.Reader) string { - glu := gitLabUserFromJson(data) - - if glu.IsValid() { - return glu.getAuthData() - } - - return "" -} -- cgit v1.2.3-1-g7c22 From 437f9f5b64ddb4e1f84e6c4e993120d074001777 Mon Sep 17 00:00:00 2001 From: Kenny Au Date: Wed, 27 Jun 2018 13:35:15 -0600 Subject: Gfycat integration (#8971) * Gfycat integration * Added gfycat api credentials to config. --- model/config.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'model') diff --git a/model/config.go b/model/config.go index 868bb01d5..ce66f2f05 100644 --- a/model/config.go +++ b/model/config.go @@ -210,6 +210,9 @@ type ServiceSettings struct { WebserverMode *string EnableCustomEmoji *bool EnableEmojiPicker *bool + EnableGifPicker *bool + GfycatApiKey *string + GfycatApiSecret *string RestrictCustomEmojiCreation *string RestrictPostDelete *string AllowEditPost *string @@ -413,6 +416,18 @@ func (s *ServiceSettings) SetDefaults() { s.EnableEmojiPicker = NewBool(true) } + if s.EnableGifPicker == nil { + s.EnableGifPicker = NewBool(true) + } + + if s.GfycatApiKey == nil { + s.GfycatApiKey = NewString("") + } + + if s.GfycatApiSecret == nil { + s.GfycatApiSecret = NewString("") + } + if s.RestrictCustomEmojiCreation == nil { s.RestrictCustomEmojiCreation = NewString(RESTRICT_EMOJI_CREATION_ALL) } -- cgit v1.2.3-1-g7c22