summaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorHarrison Healey <harrisonmhealey@gmail.com>2017-01-27 15:58:50 -0500
committerGitHub <noreply@github.com>2017-01-27 15:58:50 -0500
commit65b76c2712eea4daa1633e4652fa3cd51037e854 (patch)
tree66306b5bd44ae7a4df4a7121fe85b9887cff160e /app
parent097289f8e473c799ee752aa56e08f605110f5217 (diff)
downloadchat-65b76c2712eea4daa1633e4652fa3cd51037e854.tar.gz
chat-65b76c2712eea4daa1633e4652fa3cd51037e854.tar.bz2
chat-65b76c2712eea4daa1633e4652fa3cd51037e854.zip
PLT-5225 Added separate post types for certain system messages (#5193)
* Added separate post types for system_join_leave and system_add_remove posts * Added username prop to channel deleted posts * Changed slack import to properly generate the new join/leave messages * Added username prop to channel update posts * Moved Post(AddTo/RemoveFrom)ChanneMessage into app package
Diffstat (limited to 'app')
-rw-r--r--app/channel.go130
-rw-r--r--app/slackimport.go13
2 files changed, 106 insertions, 37 deletions
diff --git a/app/channel.go b/app/channel.go
index c9199f829..818e241b7 100644
--- a/app/channel.go
+++ b/app/channel.go
@@ -91,49 +91,39 @@ func JoinDefaultChannels(teamId string, user *model.User, channelRole string) *m
if result := <-Srv.Store.Channel().GetByName(teamId, "town-square", true); result.Err != nil {
err = result.Err
} else {
- cm := &model.ChannelMember{ChannelId: result.Data.(*model.Channel).Id, UserId: user.Id,
+ townSquare := result.Data.(*model.Channel)
+
+ cm := &model.ChannelMember{ChannelId: townSquare.Id, UserId: user.Id,
Roles: channelRole, NotifyProps: model.GetDefaultChannelNotifyProps()}
if cmResult := <-Srv.Store.Channel().SaveMember(cm); cmResult.Err != nil {
err = cmResult.Err
}
- post := &model.Post{
- ChannelId: result.Data.(*model.Channel).Id,
- Message: fmt.Sprintf(utils.T("api.channel.join_channel.post_and_forget"), user.Username),
- Type: model.POST_JOIN_LEAVE,
- UserId: user.Id,
+ if err := postJoinChannelMessage(user, townSquare); err != nil {
+ l4g.Error(utils.T("api.channel.post_user_add_remove_message_and_forget.error"), err)
}
InvalidateCacheForChannelMembers(result.Data.(*model.Channel).Id)
-
- if _, err := CreatePost(post, teamId, false); err != nil {
- l4g.Error(utils.T("api.channel.post_user_add_remove_message_and_forget.error"), err)
- }
}
if result := <-Srv.Store.Channel().GetByName(teamId, "off-topic", true); result.Err != nil {
err = result.Err
} else {
- cm := &model.ChannelMember{ChannelId: result.Data.(*model.Channel).Id, UserId: user.Id,
+ offTopic := result.Data.(*model.Channel)
+
+ cm := &model.ChannelMember{ChannelId: offTopic.Id, UserId: user.Id,
Roles: channelRole, NotifyProps: model.GetDefaultChannelNotifyProps()}
if cmResult := <-Srv.Store.Channel().SaveMember(cm); cmResult.Err != nil {
err = cmResult.Err
}
- post := &model.Post{
- ChannelId: result.Data.(*model.Channel).Id,
- Message: fmt.Sprintf(utils.T("api.channel.join_channel.post_and_forget"), user.Username),
- Type: model.POST_JOIN_LEAVE,
- UserId: user.Id,
+ if err := postJoinChannelMessage(user, offTopic); err != nil {
+ l4g.Error(utils.T("api.channel.post_user_add_remove_message_and_forget.error"), err)
}
InvalidateCacheForChannelMembers(result.Data.(*model.Channel).Id)
-
- if _, err := CreatePost(post, teamId, false); err != nil {
- l4g.Error(utils.T("api.channel.post_user_add_remove_message_and_forget.error"), err)
- }
}
return err
@@ -276,6 +266,9 @@ func DeleteChannel(channel *model.Channel, userId string) *model.AppError {
Message: fmt.Sprintf(T("api.channel.delete_channel.archived"), user.Username),
Type: model.POST_CHANNEL_DELETED,
UserId: userId,
+ Props: model.StringInterface{
+ "username": user.Username,
+ },
}
if _, err := CreatePost(post, channel.TeamId, false); err != nil {
@@ -423,6 +416,7 @@ func PostUpdateChannelHeaderMessage(userId string, channelId string, teamId stri
Type: model.POST_HEADER_CHANGE,
UserId: userId,
Props: model.StringInterface{
+ "username": user.Username,
"old_header": oldChannelHeader,
"new_header": newChannelHeader,
},
@@ -459,6 +453,7 @@ func PostUpdateChannelPurposeMessage(userId string, channelId string, teamId str
Type: model.POST_PURPOSE_CHANGE,
UserId: userId,
Props: model.StringInterface{
+ "username": user.Username,
"old_purpose": oldChannelPurpose,
"new_purpose": newChannelPurpose,
},
@@ -487,6 +482,7 @@ func PostUpdateChannelDisplayNameMessage(userId string, channelId string, teamId
Type: model.POST_DISPLAYNAME_CHANGE,
UserId: userId,
Props: model.StringInterface{
+ "username": user.Username,
"old_displayname": oldChannelDisplayName,
"new_displayname": newChannelDisplayName,
},
@@ -588,7 +584,10 @@ func JoinChannel(channel *model.Channel, userId string) *model.AppError {
if _, err := AddUserToChannel(user, channel); err != nil {
return err
}
- PostUserAddRemoveMessage(userId, channel.Id, channel.TeamId, fmt.Sprintf(utils.T("api.channel.join_channel.post_and_forget"), user.Username), model.POST_JOIN_LEAVE)
+
+ if err := postJoinChannelMessage(user, channel); err != nil {
+ return err
+ }
} else {
return model.NewLocAppError("JoinChannel", "api.channel.join_channel.permissions.app_error", nil, "")
}
@@ -597,6 +596,24 @@ func JoinChannel(channel *model.Channel, userId string) *model.AppError {
return nil
}
+func postJoinChannelMessage(user *model.User, channel *model.Channel) *model.AppError {
+ post := &model.Post{
+ ChannelId: channel.Id,
+ Message: fmt.Sprintf(utils.T("api.channel.join_channel.post_and_forget"), user.Username),
+ Type: model.POST_JOIN_CHANNEL,
+ UserId: user.Id,
+ Props: model.StringInterface{
+ "username": user.Username,
+ },
+ }
+
+ if _, err := CreatePost(post, channel.TeamId, false); err != nil {
+ return model.NewLocAppError("postJoinChannelMessage", "api.channel.post_user_add_remove_message_and_forget.error", nil, err.Error())
+ }
+
+ return nil
+}
+
func LeaveChannel(channelId string, userId string) *model.AppError {
sc := Srv.Store.Channel().Get(channelId, true)
uc := Srv.Store.User().Get(userId)
@@ -629,7 +646,62 @@ func LeaveChannel(channelId string, userId string) *model.AppError {
return err
}
- go PostUserAddRemoveMessage(userId, channel.Id, channel.TeamId, fmt.Sprintf(utils.T("api.channel.leave.left"), user.Username), model.POST_JOIN_LEAVE)
+ go postLeaveChannelMessage(user, channel)
+ }
+
+ return nil
+}
+
+func postLeaveChannelMessage(user *model.User, channel *model.Channel) *model.AppError {
+ post := &model.Post{
+ ChannelId: channel.Id,
+ Message: fmt.Sprintf(utils.T("api.channel.leave.left"), user.Username),
+ Type: model.POST_LEAVE_CHANNEL,
+ UserId: user.Id,
+ Props: model.StringInterface{
+ "username": user.Username,
+ },
+ }
+
+ if _, err := CreatePost(post, channel.TeamId, false); err != nil {
+ return model.NewLocAppError("postLeaveChannelMessage", "api.channel.post_user_add_remove_message_and_forget.error", nil, err.Error())
+ }
+
+ return nil
+}
+
+func PostAddToChannelMessage(user *model.User, addedUser *model.User, channel *model.Channel) *model.AppError {
+ post := &model.Post{
+ ChannelId: channel.Id,
+ Message: fmt.Sprintf(utils.T("api.channel.add_member.added"), addedUser.Username, user.Username),
+ Type: model.POST_ADD_TO_CHANNEL,
+ UserId: user.Id,
+ Props: model.StringInterface{
+ "username": user.Username,
+ "addedUsername": addedUser.Username,
+ },
+ }
+
+ if _, err := CreatePost(post, channel.TeamId, false); err != nil {
+ return model.NewLocAppError("postAddToChannelMessage", "api.channel.post_user_add_remove_message_and_forget.error", nil, err.Error())
+ }
+
+ return nil
+}
+
+func PostRemoveFromChannelMessage(removerUserId string, removedUser *model.User, channel *model.Channel) *model.AppError {
+ post := &model.Post{
+ ChannelId: channel.Id,
+ Message: fmt.Sprintf(utils.T("api.channel.remove_member.removed"), removedUser.Username),
+ Type: model.POST_REMOVE_FROM_CHANNEL,
+ UserId: removerUserId,
+ Props: model.StringInterface{
+ "removedUsername": removedUser.Username,
+ },
+ }
+
+ if _, err := CreatePost(post, channel.TeamId, false); err != nil {
+ return model.NewLocAppError("postRemoveFromChannelMessage", "api.channel.post_user_add_remove_message_and_forget.error", nil, err.Error())
}
return nil
@@ -667,20 +739,6 @@ func RemoveUserFromChannel(userIdToRemove string, removerUserId string, channel
return nil
}
-func PostUserAddRemoveMessage(userId, channelId, teamId, message, postType string) *model.AppError {
- post := &model.Post{
- ChannelId: channelId,
- Message: message,
- Type: postType,
- UserId: userId,
- }
- if _, err := CreatePost(post, teamId, false); err != nil {
- return model.NewLocAppError("PostUserAddRemoveMessage", "api.channel.post_user_add_remove_message_and_forget.error", nil, err.Error())
- }
-
- return nil
-}
-
func GetNumberOfChannelsOnTeam(teamId string) (int, *model.AppError) {
// Get total number of channels on current team
if result := <-Srv.Store.Channel().GetTeamChannels(teamId); result.Err != nil {
diff --git a/app/slackimport.go b/app/slackimport.go
index 3289f140e..e4beb3d3d 100644
--- a/app/slackimport.go
+++ b/app/slackimport.go
@@ -307,12 +307,23 @@ func SlackAddPosts(teamId string, channel *model.Channel, posts []SlackPost, use
l4g.Debug(utils.T("api.slackimport.slack_add_posts.user_no_exists.debug"), sPost.User)
continue
}
+
+ var postType string
+ if sPost.SubType == "channel_join" {
+ postType = model.POST_JOIN_CHANNEL
+ } else {
+ postType = model.POST_LEAVE_CHANNEL
+ }
+
newPost := model.Post{
UserId: users[sPost.User].Id,
ChannelId: channel.Id,
Message: sPost.Text,
CreateAt: SlackConvertTimeStamp(sPost.TimeStamp),
- Type: model.POST_JOIN_LEAVE,
+ Type: postType,
+ Props: model.StringInterface{
+ "username": users[sPost.User].Username,
+ },
}
ImportPost(&newPost)
case sPost.Type == "message" && sPost.SubType == "me_message":