diff options
author | Joram Wilander <jwawilander@gmail.com> | 2017-03-02 17:48:56 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-03-02 17:48:56 -0500 |
commit | 3a91d4e5e419a43ff19a0736ce697f8d611d36e3 (patch) | |
tree | e57ad85d49f8768a575f27c89d338a4ccaeda521 /model/channel.go | |
parent | 8c5cee9521656bcffb371aad9dae4bea8fc70e29 (diff) | |
download | chat-3a91d4e5e419a43ff19a0736ce697f8d611d36e3.tar.gz chat-3a91d4e5e419a43ff19a0736ce697f8d611d36e3.tar.bz2 chat-3a91d4e5e419a43ff19a0736ce697f8d611d36e3.zip |
PLT-3077 Add group messaging (#5489)
* Implement server changes for group messaging
* Majority of client-side implementation
* Some server updates
* Added new React multiselect component
* Fix style issues
* Add custom renderer for options
* Fix model test
* Update ENTER functionality for multiselect control
* Remove buttons from multiselect UI control
* Updating group messaging UI (#5524)
* Move filter controls up a component level
* Scroll with arrow keys
* Updating mobile layout for multiselect (#5534)
* Fix race condition when backspacing quickly
* Hidden or new GMs show up for regular messages
* Add overriding of number remaining text
* Add UI filtering for team if config setting set
* Add icon to channel switcher and class prop to status icon
* Minor updates per feedback
* Improving group messaging UI (#5563)
* UX changes per feedback
* Update email for group messages
* UI fixes for group messaging (#5587)
* Fix missing localization string
* Add maximum users message when adding members to GM
* Fix input clearing on Android
* Updating group messaging UI (#5603)
* Updating UI for group messaging (#5604)
Diffstat (limited to 'model/channel.go')
-rw-r--r-- | model/channel.go | 41 |
1 files changed, 40 insertions, 1 deletions
diff --git a/model/channel.go b/model/channel.go index c89680194..d24fdb2b4 100644 --- a/model/channel.go +++ b/model/channel.go @@ -4,8 +4,12 @@ package model import ( + "crypto/sha1" + "encoding/hex" "encoding/json" "io" + "sort" + "strings" "unicode/utf8" ) @@ -13,6 +17,9 @@ const ( CHANNEL_OPEN = "O" CHANNEL_PRIVATE = "P" CHANNEL_DIRECT = "D" + CHANNEL_GROUP = "G" + CHANNEL_GROUP_MAX_USERS = 8 + CHANNEL_GROUP_MIN_USERS = 3 DEFAULT_CHANNEL = "town-square" CHANNEL_DISPLAY_NAME_MAX_RUNES = 64 CHANNEL_NAME_MIN_LENGTH = 2 @@ -89,7 +96,7 @@ func (o *Channel) IsValid() *AppError { return NewLocAppError("Channel.IsValid", "model.channel.is_valid.2_or_more.app_error", nil, "id="+o.Id) } - if !(o.Type == CHANNEL_OPEN || o.Type == CHANNEL_PRIVATE || o.Type == CHANNEL_DIRECT) { + if !(o.Type == CHANNEL_OPEN || o.Type == CHANNEL_PRIVATE || o.Type == CHANNEL_DIRECT || o.Type == CHANNEL_GROUP) { return NewLocAppError("Channel.IsValid", "model.channel.is_valid.type.app_error", nil, "id="+o.Id) } @@ -126,6 +133,10 @@ func (o *Channel) ExtraUpdated() { o.ExtraUpdateAt = GetMillis() } +func (o *Channel) IsGroupOrDirect() bool { + return o.Type == CHANNEL_DIRECT || o.Type == CHANNEL_GROUP +} + func GetDMNameFromIds(userId1, userId2 string) string { if userId1 > userId2 { return userId2 + "__" + userId1 @@ -133,3 +144,31 @@ func GetDMNameFromIds(userId1, userId2 string) string { return userId1 + "__" + userId2 } } + +func GetGroupDisplayNameFromUsers(users []*User, truncate bool) string { + usernames := make([]string, len(users)) + for index, user := range users { + usernames[index] = user.Username + } + + sort.Strings(usernames) + + name := strings.Join(usernames, ", ") + + if truncate && len(name) > CHANNEL_NAME_MAX_LENGTH { + name = name[:CHANNEL_NAME_MAX_LENGTH] + } + + return name +} + +func GetGroupNameFromUserIds(userIds []string) string { + sort.Strings(userIds) + + h := sha1.New() + for _, id := range userIds { + io.WriteString(h, id) + } + + return hex.EncodeToString(h.Sum(nil)) +} |