Commit 3a91d4e5 authored by Joram Wilander's avatar Joram Wilander Committed by GitHub

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)
parent 8c5cee95
......@@ -25,6 +25,7 @@ func InitChannel() {
BaseRoutes.Channels.Handle("/create", ApiUserRequired(createChannel)).Methods("POST")
BaseRoutes.Channels.Handle("/view", ApiUserRequired(viewChannel)).Methods("POST")
BaseRoutes.Channels.Handle("/create_direct", ApiUserRequired(createDirectChannel)).Methods("POST")
BaseRoutes.Channels.Handle("/create_group", ApiUserRequired(createGroupChannel)).Methods("POST")
BaseRoutes.Channels.Handle("/update", ApiUserRequired(updateChannel)).Methods("POST")
BaseRoutes.Channels.Handle("/update_header", ApiUserRequired(updateChannelHeader)).Methods("POST")
BaseRoutes.Channels.Handle("/update_purpose", ApiUserRequired(updateChannelPurpose)).Methods("POST")
......@@ -98,6 +99,38 @@ func createDirectChannel(c *Context, w http.ResponseWriter, r *http.Request) {
}
}
func createGroupChannel(c *Context, w http.ResponseWriter, r *http.Request) {
if !app.SessionHasPermissionTo(c.Session, model.PERMISSION_CREATE_GROUP_CHANNEL) {
c.SetPermissionError(model.PERMISSION_CREATE_GROUP_CHANNEL)
return
}
userIds := model.ArrayFromJson(r.Body)
if len(userIds) == 0 {
c.SetInvalidParam("createGroupChannel", "user_ids")
return
}
found := false
for _, id := range userIds {
if id == c.Session.UserId {
found = true
break
}
}
if !found {
userIds = append(userIds, c.Session.UserId)
}
if sc, err := app.CreateGroupChannel(userIds); err != nil {
c.Err = err
return
} else {
w.Write([]byte(sc.ToJson()))
}
}
func CanManageChannel(c *Context, channel *model.Channel) bool {
if channel.Type == model.CHANNEL_OPEN && !app.SessionHasPermissionToChannel(c.Session, channel.Id, model.PERMISSION_MANAGE_PUBLIC_CHANNEL_PROPERTIES) {
c.SetPermissionError(model.PERMISSION_MANAGE_PUBLIC_CHANNEL_PROPERTIES)
......@@ -457,7 +490,7 @@ func getChannel(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
if channel.TeamId != c.TeamId && channel.Type != model.CHANNEL_DIRECT {
if channel.TeamId != c.TeamId && !channel.IsGroupOrDirect() {
c.Err = model.NewLocAppError("getChannel", "api.channel.get_channel.wrong_team.app_error", map[string]interface{}{"ChannelId": id, "TeamId": c.TeamId}, "")
return
}
......@@ -493,7 +526,7 @@ func getChannelByName(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
if channel.TeamId != c.TeamId && channel.Type != model.CHANNEL_DIRECT {
if channel.TeamId != c.TeamId && !channel.IsGroupOrDirect() {
c.Err = model.NewLocAppError("getChannel", "api.channel.get_channel.wrong_team.app_error", map[string]interface{}{"ChannelName": channelName, "TeamId": c.TeamId}, "")
return
}
......
......@@ -219,6 +219,46 @@ func TestCreateDirectChannel(t *testing.T) {
}
}
func TestCreateGroupChannel(t *testing.T) {
th := Setup().InitBasic()
Client := th.BasicClient
user := th.BasicUser
user2 := th.BasicUser2
user3 := th.CreateUser(Client)
userIds := []string{user.Id, user2.Id, user3.Id}
var channel *model.Channel
if result, err := Client.CreateGroupChannel(userIds); err != nil {
t.Fatal(err)
} else {
channel = result.Data.(*model.Channel)
}
if channel.Type != model.CHANNEL_GROUP {
t.Fatal("channel type was not group")
}
// Don't fail on group channels already existing and return the original channel again
if result, err := Client.CreateGroupChannel(userIds); err != nil {
t.Fatal(err)
} else if result.Data.(*model.Channel).Id != channel.Id {
t.Fatal("didn't return original group channel when saving a duplicate")
}
if _, err := Client.CreateGroupChannel([]string{user.Id}); err == nil {
t.Fatal("should have failed with not enough users")
}
if _, err := Client.CreateGroupChannel([]string{}); err == nil {
t.Fatal("should have failed with not enough users")
}
if _, err := Client.CreateGroupChannel([]string{user.Id, user2.Id, user3.Id, "junk"}); err == nil {
t.Fatal("should have failed with non-existent user")
}
}
func TestUpdateChannel(t *testing.T) {
th := Setup().InitBasic().InitSystemAdmin()
Client := th.SystemAdminClient
......
......@@ -77,7 +77,7 @@ func JoinDefaultChannels(teamId string, user *model.User, channelRole string) *m
}
func CreateChannelWithUser(channel *model.Channel, userId string) (*model.Channel, *model.AppError) {
if channel.Type == model.CHANNEL_DIRECT {
if channel.IsGroupOrDirect() {
return nil, model.NewAppError("CreateChannelWithUser", "api.channel.create_channel.direct_channel.app_error", nil, "", http.StatusBadRequest)
}
......@@ -197,6 +197,60 @@ func WaitForChannelMembership(channelId string, userId string) {
}
}
func CreateGroupChannel(userIds []string) (*model.Channel, *model.AppError) {
if len(userIds) > model.CHANNEL_GROUP_MAX_USERS || len(userIds) < model.CHANNEL_GROUP_MIN_USERS {
return nil, model.NewAppError("CreateGroupChannel", "api.channel.create_group.bad_size.app_error", nil, "", http.StatusBadRequest)
}
var users []*model.User
if result := <-Srv.Store.User().GetProfileByIds(userIds, true); result.Err != nil {
return nil, result.Err
} else {
users = result.Data.([]*model.User)
}
if len(users) != len(userIds) {
return nil, model.NewAppError("CreateGroupChannel", "api.channel.create_group.bad_user.app_error", nil, "user_ids="+model.ArrayToJson(userIds), http.StatusBadRequest)
}
group := &model.Channel{
Name: model.GetGroupNameFromUserIds(userIds),
DisplayName: model.GetGroupDisplayNameFromUsers(users, true),
Type: model.CHANNEL_GROUP,
}
if result := <-Srv.Store.Channel().Save(group); result.Err != nil {
if result.Err.Id == store.CHANNEL_EXISTS_ERROR {
return result.Data.(*model.Channel), nil
} else {
return nil, result.Err
}
} else {
channel := result.Data.(*model.Channel)
for _, user := range users {
cm := &model.ChannelMember{
UserId: user.Id,
ChannelId: group.Id,
NotifyProps: model.GetDefaultChannelNotifyProps(),
Roles: model.ROLE_CHANNEL_USER.Id,
}
if result := <-Srv.Store.Channel().SaveMember(cm); result.Err != nil {
return nil, result.Err
}
InvalidateCacheForUser(user.Id)
}
message := model.NewWebSocketEvent(model.WEBSOCKET_EVENT_GROUP_ADDED, "", group.Id, "", nil)
message.Add("teammate_ids", model.ArrayToJson(userIds))
Publish(message)
return channel, nil
}
}
func UpdateChannel(channel *model.Channel) (*model.Channel, *model.AppError) {
if result := <-Srv.Store.Channel().Update(channel); result.Err != nil {
return nil, result.Err
......@@ -702,7 +756,7 @@ func LeaveChannel(channelId string, userId string) *model.AppError {
user := uresult.Data.(*model.User)
membersCount := ccmresult.Data.(int64)
if channel.Type == model.CHANNEL_DIRECT {
if channel.IsGroupOrDirect() {
err := model.NewLocAppError("LeaveChannel", "api.channel.leave.direct.app_error", nil, "")
err.StatusCode = http.StatusBadRequest
return err
......
......@@ -244,6 +244,8 @@ func renderBatchedPost(template *utils.HTMLTemplate, post *model.Post, teamName
return ""
} else if channel := result.Data.(*model.Channel); channel.Type == model.CHANNEL_DIRECT {
template.Props["ChannelName"] = translateFunc("api.email_batching.render_batched_post.direct_message")
} else if channel.Type == model.CHANNEL_GROUP {
template.Props["ChannelName"] = translateFunc("api.email_batching.render_batched_post.group_message")
} else {
template.Props["ChannelName"] = channel.DisplayName
}
......
......@@ -118,6 +118,7 @@ func SendNotifications(post *model.Post, team *model.Team, channel *model.Channe
}
senderName := make(map[string]string)
channelName := make(map[string]string)
for _, id := range mentionedUsersList {
senderName[id] = ""
if post.IsSystemMessage() {
......@@ -135,6 +136,19 @@ func SendNotifications(post *model.Post, team *model.Team, channel *model.Channe
}
}
}
if channel.Type == model.CHANNEL_GROUP {
userList := []*model.User{}
for _, u := range profileMap {
if u.Id != sender.Id && u.Id != id {
userList = append(userList, u)
}
}
userList = append(userList, sender)
channelName[id] = model.GetGroupDisplayNameFromUsers(userList, false)
} else {
channelName[id] = channel.DisplayName
}
}
var senderUsername string
......@@ -259,7 +273,7 @@ func SendNotifications(post *model.Post, team *model.Team, channel *model.Channe
}
if ShouldSendPushNotification(profileMap[id], channelMemberNotifyPropsMap[id], true, status, post) {
sendPushNotification(post, profileMap[id], channel, senderName[id], true)
sendPushNotification(post, profileMap[id], channel, senderName[id], channelName[id], true)
}
}
......@@ -272,7 +286,7 @@ func SendNotifications(post *model.Post, team *model.Team, channel *model.Channe
}
if ShouldSendPushNotification(profileMap[id], channelMemberNotifyPropsMap[id], false, status, post) {
sendPushNotification(post, profileMap[id], channel, senderName[id], false)
sendPushNotification(post, profileMap[id], channel, senderName[id], channelName[id], false)
}
}
}
......@@ -313,8 +327,8 @@ func SendNotifications(post *model.Post, team *model.Team, channel *model.Channe
}
func sendNotificationEmail(post *model.Post, user *model.User, channel *model.Channel, team *model.Team, senderName string, sender *model.User) *model.AppError {
if channel.Type == model.CHANNEL_DIRECT && channel.TeamId != team.Id {
// this message is a cross-team DM so it we need to find a team that the recipient is on to use in the link
if channel.IsGroupOrDirect() && channel.TeamId != team.Id {
// this message is a cross-team DM/GM so we need to find a team that the recipient is on to use in the link
if result := <-Srv.Store.Team().GetTeamsByUserId(user.Id); result.Err != nil {
return result.Err
} else {
......@@ -381,6 +395,14 @@ func sendNotificationEmail(post *model.Post, user *model.User, channel *model.Ch
mailTemplate = "api.templates.post_subject_in_direct_message"
mailParameters = map[string]interface{}{"SubjectText": subjectText, "TeamDisplayName": team.DisplayName,
"SenderDisplayName": senderDisplayName, "Month": month, "Day": day, "Year": year}
} else if channel.Type == model.CHANNEL_GROUP {
bodyText = userLocale("api.post.send_notifications_and_forget.mention_body")
senderDisplayName := senderName
mailTemplate = "api.templates.post_subject_in_group_message"
mailParameters = map[string]interface{}{"SenderDisplayName": senderDisplayName, "Month": month, "Day": day, "Year": year}
channelName = userLocale("api.templates.channel_name.group")
} else {
bodyText = userLocale("api.post.send_notifications_and_forget.mention_body")
subjectText = userLocale("api.post.send_notifications_and_forget.mention_subject")
......@@ -456,18 +478,14 @@ func GetMessageForNotification(post *model.Post, translateFunc i18n.TranslateFun
}
}
func sendPushNotification(post *model.Post, user *model.User, channel *model.Channel, senderName string, wasMentioned bool) *model.AppError {
func sendPushNotification(post *model.Post, user *model.User, channel *model.Channel, senderName, channelName string, wasMentioned bool) *model.AppError {
sessions, err := getMobileAppSessions(user.Id)
if err != nil {
return err
}
var channelName string
if channel.Type == model.CHANNEL_DIRECT {
channelName = senderName
} else {
channelName = channel.DisplayName
}
userLocale := utils.GetUserTranslations(user.Locale)
......@@ -495,7 +513,7 @@ func sendPushNotification(post *model.Post, user *model.User, channel *model.Cha
if channel.Type == model.CHANNEL_DIRECT {
msg.Category = model.CATEGORY_DM
msg.Message = senderName + userLocale("api.post.send_notifications_and_forget.push_message")
} else if wasMentioned {
} else if wasMentioned || channel.Type == model.CHANNEL_GROUP {
msg.Message = senderName + userLocale("api.post.send_notifications_and_forget.push_mention") + channelName
} else {
msg.Message = senderName + userLocale("api.post.send_notifications_and_forget.push_non_mention") + channelName
......
......@@ -438,7 +438,7 @@ func LeaveTeam(team *model.Team, user *model.User) *model.AppError {
}
for _, channel := range *channelList {
if channel.Type != model.CHANNEL_DIRECT {
if !channel.IsGroupOrDirect() {
InvalidateCacheForChannelMembers(channel.Id)
if result := <-Srv.Store.Channel().RemoveMember(channel.Id, user.Id); result.Err != nil {
return result.Err
......
......@@ -199,6 +199,14 @@
"id": "api.channel.create_channel.direct_channel.app_error",
"translation": "Must use createDirectChannel API service for direct message channel creation"
},
{
"id": "api.channel.create_group.bad_size.app_error",
"translation": "Group message channels must contain at least 3 and no more than 8 users"
},
{
"id": "api.channel.create_group.bad_user.app_error",
"translation": "One of the provided users does not exist"
},
{
"id": "api.channel.create_channel.invalid_character.app_error",
"translation": "Invalid character '__' in channel name for non-direct channel"
......@@ -887,6 +895,10 @@
"id": "api.email_batching.render_batched_post.direct_message",
"translation": "Direct Message"
},
{
"id": "api.email_batching.render_batched_post.group_message",
"translation": "Group Message"
},
{
"id": "api.email_batching.render_batched_post.go_to_post",
"translation": "Go to Post"
......@@ -2151,6 +2163,14 @@
"id": "api.templates.post_subject_in_direct_message",
"translation": "{{.SubjectText}} in {{.TeamDisplayName}} from {{.SenderDisplayName}} on {{.Month}} {{.Day}}, {{.Year}}"
},
{
"id": "api.templates.channel_name.group",
"translation": "Group Message"
},
{
"id": "api.templates.post_subject_in_group_message",
"translation": "New Group Message from {{ .SenderDisplayName}} on {{.Month}} {{.Day}}, {{.Year}}"
},
{
"id": "api.templates.reset_body.button",
"translation": "Reset Password"
......@@ -3059,6 +3079,14 @@
"id": "app.import.import_line.null_post.error",
"translation": "Import data line has type \"post\" but the post object is null."
},
{
"id": "authentication.permissions.create_group_channel.description",
"translation": "Ability to create new group message channels"
},
{
"id": "authentication.permissions.create_group_channel.name",
"translation": "Create Group Message"
},
{
"id": "authentication.permissions.create_team_roles.description",
"translation": "Ability to create new teams"
......
......@@ -30,6 +30,7 @@ var PERMISSION_MANAGE_ROLES *Permission
var PERMISSION_MANAGE_TEAM_ROLES *Permission
var PERMISSION_MANAGE_CHANNEL_ROLES *Permission
var PERMISSION_CREATE_DIRECT_CHANNEL *Permission
var PERMISSION_CREATE_GROUP_CHANNEL *Permission
var PERMISSION_MANAGE_PUBLIC_CHANNEL_PROPERTIES *Permission
var PERMISSION_MANAGE_PRIVATE_CHANNEL_PROPERTIES *Permission
var PERMISSION_LIST_TEAM_CHANNELS *Permission
......@@ -149,6 +150,11 @@ func InitalizePermissions() {
"authentication.permissions.create_direct_channel.name",
"authentication.permissions.create_direct_channel.description",
}
PERMISSION_CREATE_GROUP_CHANNEL = &Permission{
"create_group_channel",
"authentication.permissions.create_group_channel.name",
"authentication.permissions.create_group_channel.description",
}
PERMISSION_MANAGE_PUBLIC_CHANNEL_PROPERTIES = &Permission{
"manage__publicchannel_properties",
"authentication.permissions.manage_public_channel_properties.name",
......@@ -350,6 +356,7 @@ func InitalizeRoles() {
"authentication.roles.global_user.description",
[]string{
PERMISSION_CREATE_DIRECT_CHANNEL.Id,
PERMISSION_CREATE_GROUP_CHANNEL.Id,
PERMISSION_PERMANENT_DELETE_USER.Id,
PERMISSION_MANAGE_OAUTH.Id,
},
......
......@@ -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))
}
......@@ -104,3 +104,24 @@ func TestChannelPreUpdate(t *testing.T) {
o := Channel{Name: "test"}
o.PreUpdate()
}
func TestGetGroupDisplayNameFromUsers(t *testing.T) {
users := make([]*User, 4)
users[0] = &User{Username: NewId()}
users[1] = &User{Username: NewId()}
users[2] = &User{Username: NewId()}
users[3] = &User{Username: NewId()}
name := GetGroupDisplayNameFromUsers(users, true)
if len(name) > CHANNEL_NAME_MAX_LENGTH {
t.Fatal("name too long")
}
}
func TestGetGroupNameFromUserIds(t *testing.T) {
name := GetGroupNameFromUserIds([]string{NewId(), NewId(), NewId(), NewId(), NewId()})
if len(name) > CHANNEL_NAME_MAX_LENGTH {
t.Fatal("name too long")
}
}
......@@ -1121,6 +1121,16 @@ func (c *Client) CreateDirectChannel(userId string) (*Result, *AppError) {
}
}
func (c *Client) CreateGroupChannel(userIds []string) (*Result, *AppError) {
if r, err := c.DoApiPost(c.GetTeamRoute()+"/channels/create_group", ArrayToJson(userIds)); err != nil {
return nil, err
} else {
defer closeBody(r)
return &Result{r.Header.Get(HEADER_REQUEST_ID),
r.Header.Get(HEADER_ETAG_SERVER), ChannelFromJson(r.Body)}, nil
}
}
func (c *Client) UpdateChannel(channel *Channel) (*Result, *AppError) {
if r, err := c.DoApiPost(c.GetTeamRoute()+"/channels/update", channel.ToJson()); err != nil {
return nil, err
......
......@@ -16,6 +16,7 @@ const (
WEBSOCKET_EVENT_CHANNEL_DELETED = "channel_deleted"
WEBSOCKET_EVENT_CHANNEL_CREATED = "channel_created"
WEBSOCKET_EVENT_DIRECT_ADDED = "direct_added"
WEBSOCKET_EVENT_GROUP_ADDED = "group_added"
WEBSOCKET_EVENT_NEW_USER = "new_user"
WEBSOCKET_EVENT_LEAVE_TEAM = "leave_team"
WEBSOCKET_EVENT_UPDATE_TEAM = "update_team"
......
......@@ -211,7 +211,7 @@ func (s SqlChannelStore) saveChannelT(transaction *gorp.Transaction, channel *mo
return result
}
if channel.Type != model.CHANNEL_DIRECT {
if channel.Type != model.CHANNEL_DIRECT && channel.Type != model.CHANNEL_GROUP {
if count, err := transaction.SelectInt("SELECT COUNT(0) FROM Channels WHERE TeamId = :TeamId AND DeleteAt = 0 AND (Type = 'O' OR Type = 'P')", map[string]interface{}{"TeamId": channel.TeamId}); err != nil {
result.Err = model.NewLocAppError("SqlChannelStore.Save", "store.sql_channel.save_channel.current_count.app_error", nil, "teamId="+channel.TeamId+", "+err.Error())
return result
......
......@@ -9,7 +9,7 @@ import ChannelStore from 'stores/channel_store.jsx';
import * as ChannelUtils from 'utils/channel_utils.jsx';
import PreferenceStore from 'stores/preference_store.jsx';
import {loadProfilesAndTeamMembersForDMSidebar} from 'actions/user_actions.jsx';
import {loadProfilesForSidebar} from 'actions/user_actions.jsx';
import {trackEvent} from 'actions/diagnostics_actions.jsx';
import Client from 'client/web_client.jsx';
......@@ -22,8 +22,12 @@ import {browserHistory} from 'react-router/es6';
export function goToChannel(channel) {
if (channel.fake) {
const user = UserStore.getProfileByUsername(channel.display_name);
if (!user) {
return;
}
openDirectChannelToUser(
UserStore.getProfileByUsername(channel.display_name),
user.id,
() => {
browserHistory.push(TeamStore.getCurrentTeamRelativeUrl() + '/channels/' + channel.name);
},
......@@ -167,18 +171,18 @@ export function makeUserChannelMember(channelId, userId, success, error) {
);
}
export function openDirectChannelToUser(user, success, error) {
const channelName = Utils.getDirectChannelName(UserStore.getCurrentId(), user.id);
export function openDirectChannelToUser(userId, success, error) {
const channelName = Utils.getDirectChannelName(UserStore.getCurrentId(), userId);
const channel = ChannelStore.getByName(channelName);
if (channel) {
trackEvent('api', 'api_channels_join_direct');
PreferenceStore.setPreference(Preferences.CATEGORY_DIRECT_CHANNEL_SHOW, user.id, 'true');
loadProfilesAndTeamMembersForDMSidebar();
PreferenceStore.setPreference(Preferences.CATEGORY_DIRECT_CHANNEL_SHOW, userId, 'true');
loadProfilesForSidebar();
AsyncClient.savePreference(
Preferences.CATEGORY_DIRECT_CHANNEL_SHOW,
user.id,
userId,
'true'
);
......@@ -190,7 +194,7 @@ export function openDirectChannelToUser(user, success, error) {
}
Client.createDirectChannel(
user.id,
userId,
(data) => {
Client.getChannel(
data.id,
......@@ -201,12 +205,12 @@ export function openDirectChannelToUser(user, success, error) {
member: data2.member
});
PreferenceStore.setPreference(Preferences.CATEGORY_DIRECT_CHANNEL_SHOW, user.id, 'true');
loadProfilesAndTeamMembersForDMSidebar();
PreferenceStore.setPreference(Preferences.CATEGORY_DIRECT_CHANNEL_SHOW, userId, 'true');
loadProfilesForSidebar();
AsyncClient.savePreference(
Preferences.CATEGORY_DIRECT_CHANNEL_SHOW,
user.id,
userId,
'true'
);
......@@ -225,6 +229,43 @@ export function openDirectChannelToUser(user, success, error) {
);
}
export function openGroupChannelToUsers(userIds, success, error) {
Client.createGroupChannel(
userIds,
(data) => {
Client.getChannelMember(
data.id,
UserStore.getCurrentId(),
(data2) => {
AppDispatcher.handleServerAction({
type: ActionTypes.RECEIVED_CHANNEL,
channel: data,
member: data2
});
PreferenceStore.setPreference(Preferences.CATEGORY_GROUP_CHANNEL_SHOW, data.id, 'true');
loadProfilesForSidebar();
AsyncClient.savePreference(
Preferences.CATEGORY_GROUP_CHANNEL_SHOW,
data.id,
'true'
);