summaryrefslogtreecommitdiffstats
path: root/api4/channel.go
diff options
context:
space:
mode:
authorSaturnino Abril <saturnino.abril@gmail.com>2017-11-01 03:48:58 +0800
committerJoram Wilander <jwawilander@gmail.com>2017-10-31 15:48:58 -0400
commit709ef99eca0353585eb00c795cc36f39bac29a1f (patch)
treeea4304506cbbe6825007d75d1c5975b661d394ab /api4/channel.go
parent3024525c3b2ba8fb0f3f83223dd15fa721cca638 (diff)
downloadchat-709ef99eca0353585eb00c795cc36f39bac29a1f.tar.gz
chat-709ef99eca0353585eb00c795cc36f39bac29a1f.tar.bz2
chat-709ef99eca0353585eb00c795cc36f39bac29a1f.zip
[PLT-7362] Add post' root ID to APIv4 addChannelMember to render added user (as system post) at RHS (#7730)
* add post' root ID to apiv4 addChannelMember to render added user (as system post) at RHS * add check to post_root_id parameter * add AddChannelMemberWithRootId function for backward compatibility
Diffstat (limited to 'api4/channel.go')
-rw-r--r--api4/channel.go31
1 files changed, 23 insertions, 8 deletions
diff --git a/api4/channel.go b/api4/channel.go
index 5a3920a0a..f96942a4f 100644
--- a/api4/channel.go
+++ b/api4/channel.go
@@ -783,21 +783,36 @@ func addChannelMember(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
- member := model.ChannelMemberFromJson(r.Body)
- if member == nil {
- c.SetInvalidParam("channel_member")
+ props := model.StringInterfaceFromJson(r.Body)
+ userId, ok := props["user_id"].(string)
+ if !ok || len(userId) != 26 {
+ c.SetInvalidParam("user_id")
return
}
- if len(member.UserId) != 26 {
- c.SetInvalidParam("user_id")
+ member := &model.ChannelMember{
+ ChannelId: c.Params.ChannelId,
+ UserId: userId,
+ }
+
+ postRootId, ok := props["post_root_id"].(string)
+ if ok && len(postRootId) != 0 && len(postRootId) != 26 {
+ c.SetInvalidParam("post_root_id")
return
}
- member.ChannelId = c.Params.ChannelId
+ var err *model.AppError
+ if ok && len(postRootId) == 26 {
+ if rootPost, err := c.App.GetSinglePost(postRootId); err != nil {
+ c.Err = err
+ return
+ } else if rootPost.ChannelId != member.ChannelId {
+ c.SetInvalidParam("post_root_id")
+ return
+ }
+ }
var channel *model.Channel
- var err *model.AppError
if channel, err = c.App.GetChannel(member.ChannelId); err != nil {
c.Err = err
return
@@ -828,7 +843,7 @@ func addChannelMember(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
- if cm, err := c.App.AddChannelMember(member.UserId, channel, c.Session.UserId); err != nil {
+ if cm, err := c.App.AddChannelMember(member.UserId, channel, c.Session.UserId, postRootId); err != nil {
c.Err = err
return
} else {