summaryrefslogtreecommitdiffstats
path: root/api
diff options
context:
space:
mode:
Diffstat (limited to 'api')
-rw-r--r--api/channel.go36
-rw-r--r--api/post.go3
2 files changed, 36 insertions, 3 deletions
diff --git a/api/channel.go b/api/channel.go
index 99640e71a..659121bf0 100644
--- a/api/channel.go
+++ b/api/channel.go
@@ -268,19 +268,51 @@ func updateChannelHeader(c *Context, w http.ResponseWriter, r *http.Request) {
if !c.HasPermissionsToTeam(channel.TeamId, "updateChannelHeader") {
return
}
-
+ oldChannelHeader := channel.Header
channel.Header = channelHeader
if ucresult := <-Srv.Store.Channel().Update(channel); ucresult.Err != nil {
c.Err = ucresult.Err
return
} else {
+ PostUpdateChannelHeaderMessageAndForget(c, channel.Id, oldChannelHeader, channelHeader)
c.LogAudit("name=" + channel.Name)
w.Write([]byte(channel.ToJson()))
}
}
}
+func PostUpdateChannelHeaderMessageAndForget(c *Context, channelId string, oldChannelHeader, newChannelHeader string) {
+ go func() {
+ uc := Srv.Store.User().Get(c.Session.UserId)
+
+ if uresult := <-uc; uresult.Err != nil {
+ l4g.Error("Failed to retrieve user while trying to save update channel header message %v", uresult.Err)
+ return
+ } else {
+ user := uresult.Data.(*model.User)
+
+ var message string
+ if oldChannelHeader == "" {
+ message = fmt.Sprintf("%s updated the channel header to: %s", user.Username, newChannelHeader)
+ } else if newChannelHeader == "" {
+ message = fmt.Sprintf("%s removed the channel header (was: %s)", user.Username, oldChannelHeader)
+ } else {
+ message = fmt.Sprintf("%s updated the channel header from: %s to: %s", user.Username, oldChannelHeader, newChannelHeader)
+ }
+
+ post := &model.Post{
+ ChannelId: channelId,
+ Message: message,
+ Type: model.POST_HEADER_CHANGE,
+ }
+ if _, err := CreatePost(c, post, false); err != nil {
+ l4g.Error("Failed to post join/leave message %v", err)
+ }
+ }
+ }()
+}
+
func updateChannelPurpose(c *Context, w http.ResponseWriter, r *http.Request) {
props := model.MapFromJson(r.Body)
channelId := props["channel_id"]
@@ -421,7 +453,7 @@ func JoinChannel(c *Context, channelId string, role string) {
c.Err = err
return
}
- PostUserAddRemoveMessageAndForget(c, channel.Id, fmt.Sprintf(`User %v has joined this channel.`, user.Username))
+ PostUserAddRemoveMessageAndForget(c, channel.Id, fmt.Sprintf(`%v has joined the channel.`, user.Username))
} else {
c.Err = model.NewAppError("join", "You do not have the appropriate permissions", "")
c.Err.StatusCode = http.StatusForbidden
diff --git a/api/post.go b/api/post.go
index 40c5efe8c..e1adc1d98 100644
--- a/api/post.go
+++ b/api/post.go
@@ -561,11 +561,12 @@ func sendNotificationsAndForget(c *Context, post *model.Post, team *model.Team,
msg := model.PushNotification{}
msg.Platform = model.PUSH_NOTIFY_APPLE
- msg.Message = subjectPage.Render()
msg.Badge = 1
msg.DeviceId = strings.TrimPrefix(session.DeviceId, "apple:")
msg.ServerId = utils.CfgDiagnosticId
+ msg.Message = profileMap[id].FirstName + " mentioned you in " + channel.DisplayName
+
httpClient := http.Client{}
request, _ := http.NewRequest("POST", *utils.Cfg.EmailSettings.PushNotificationServer+"/api/v1/send_push", strings.NewReader(msg.ToJson()))