summaryrefslogtreecommitdiffstats
path: root/api/channel.go
diff options
context:
space:
mode:
Diffstat (limited to 'api/channel.go')
-rw-r--r--api/channel.go333
1 files changed, 88 insertions, 245 deletions
diff --git a/api/channel.go b/api/channel.go
index cc63edd07..f0d520b4e 100644
--- a/api/channel.go
+++ b/api/channel.go
@@ -11,6 +11,7 @@ import (
l4g "github.com/alecthomas/log4go"
"github.com/gorilla/mux"
+ "github.com/mattermost/platform/app"
"github.com/mattermost/platform/model"
"github.com/mattermost/platform/store"
"github.com/mattermost/platform/utils"
@@ -82,7 +83,7 @@ func createChannel(c *Context, w http.ResponseWriter, r *http.Request) {
if channel.TeamId == c.TeamId {
// Get total number of channels on current team
- if result := <-Srv.Store.Channel().GetTeamChannels(channel.TeamId); result.Err != nil {
+ if result := <-app.Srv.Store.Channel().GetTeamChannels(channel.TeamId); result.Err != nil {
c.Err = model.NewLocAppError("createChannel", "api.channel.get_channels.error", nil, result.Err.Message)
return
} else {
@@ -96,38 +97,12 @@ func createChannel(c *Context, w http.ResponseWriter, r *http.Request) {
channel.CreatorId = c.Session.UserId
- if sc, err := CreateChannel(c, channel, true); err != nil {
+ if sc, err := app.CreateChannel(channel, true); err != nil {
c.Err = err
return
} else {
- w.Write([]byte(sc.ToJson()))
- }
-}
-
-func CreateChannel(c *Context, channel *model.Channel, addMember bool) (*model.Channel, *model.AppError) {
- if result := <-Srv.Store.Channel().Save(channel); result.Err != nil {
- return nil, result.Err
- } else {
- sc := result.Data.(*model.Channel)
-
- if addMember {
- cm := &model.ChannelMember{
- ChannelId: sc.Id,
- UserId: c.Session.UserId,
- Roles: model.ROLE_CHANNEL_USER.Id + " " + model.ROLE_CHANNEL_ADMIN.Id,
- NotifyProps: model.GetDefaultChannelNotifyProps(),
- }
-
- if cmresult := <-Srv.Store.Channel().SaveMember(cm); cmresult.Err != nil {
- return nil, cmresult.Err
- }
-
- InvalidateCacheForUser(c.Session.UserId)
- }
-
c.LogAudit("name=" + channel.Name)
-
- return sc, nil
+ w.Write([]byte(sc.ToJson()))
}
}
@@ -153,13 +128,13 @@ func createDirectChannel(c *Context, w http.ResponseWriter, r *http.Request) {
}
func CreateDirectChannel(userId string, otherUserId string) (*model.Channel, *model.AppError) {
- uc := Srv.Store.User().Get(otherUserId)
+ uc := app.Srv.Store.User().Get(otherUserId)
if uresult := <-uc; uresult.Err != nil {
return nil, model.NewLocAppError("CreateDirectChannel", "api.channel.create_direct_channel.invalid_user.app_error", nil, otherUserId)
}
- if result := <-Srv.Store.Channel().CreateDirectChannel(userId, otherUserId); result.Err != nil {
+ if result := <-app.Srv.Store.Channel().CreateDirectChannel(userId, otherUserId); result.Err != nil {
if result.Err.Id == store.CHANNEL_EXISTS_ERROR {
return result.Data.(*model.Channel), nil
} else {
@@ -168,34 +143,17 @@ func CreateDirectChannel(userId string, otherUserId string) (*model.Channel, *mo
} else {
channel := result.Data.(*model.Channel)
- InvalidateCacheForUser(userId)
- InvalidateCacheForUser(otherUserId)
+ app.InvalidateCacheForUser(userId)
+ app.InvalidateCacheForUser(otherUserId)
message := model.NewWebSocketEvent(model.WEBSOCKET_EVENT_DIRECT_ADDED, "", channel.Id, "", nil)
message.Add("teammate_id", otherUserId)
- go Publish(message)
+ go app.Publish(message)
return channel, nil
}
}
-func CreateDefaultChannels(c *Context, teamId string) ([]*model.Channel, *model.AppError) {
- townSquare := &model.Channel{DisplayName: c.T("api.channel.create_default_channels.town_square"), Name: "town-square", Type: model.CHANNEL_OPEN, TeamId: teamId}
-
- if _, err := CreateChannel(c, townSquare, false); err != nil {
- return nil, err
- }
-
- offTopic := &model.Channel{DisplayName: c.T("api.channel.create_default_channels.off_topic"), Name: "off-topic", Type: model.CHANNEL_OPEN, TeamId: teamId}
-
- if _, err := CreateChannel(c, offTopic, false); err != nil {
- return nil, err
- }
-
- channels := []*model.Channel{townSquare, offTopic}
- return channels, nil
-}
-
func CanManageChannel(c *Context, channel *model.Channel) bool {
if channel.Type == model.CHANNEL_OPEN && !HasPermissionToChannelContext(c, channel.Id, model.PERMISSION_MANAGE_PUBLIC_CHANNEL_PROPERTIES) {
return false
@@ -217,8 +175,8 @@ func updateChannel(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
- sc := Srv.Store.Channel().Get(channel.Id, true)
- cmc := Srv.Store.Channel().GetMember(channel.Id, c.Session.UserId)
+ sc := app.Srv.Store.Channel().Get(channel.Id, true)
+ cmc := app.Srv.Store.Channel().GetMember(channel.Id, c.Session.UserId)
if cresult := <-sc; cresult.Err != nil {
c.Err = cresult.Err
@@ -265,8 +223,8 @@ func updateChannel(c *Context, w http.ResponseWriter, r *http.Request) {
oldChannel.Type = channel.Type
}
- InvalidateCacheForChannel(oldChannel.Id)
- if ucresult := <-Srv.Store.Channel().Update(oldChannel); ucresult.Err != nil {
+ app.InvalidateCacheForChannel(oldChannel.Id)
+ if ucresult := <-app.Srv.Store.Channel().Update(oldChannel); ucresult.Err != nil {
c.Err = ucresult.Err
return
} else {
@@ -294,8 +252,8 @@ func updateChannelHeader(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
- sc := Srv.Store.Channel().Get(channelId, true)
- cmc := Srv.Store.Channel().GetMember(channelId, c.Session.UserId)
+ sc := app.Srv.Store.Channel().Get(channelId, true)
+ cmc := app.Srv.Store.Channel().GetMember(channelId, c.Session.UserId)
if cresult := <-sc; cresult.Err != nil {
c.Err = cresult.Err
@@ -314,8 +272,8 @@ func updateChannelHeader(c *Context, w http.ResponseWriter, r *http.Request) {
oldChannelHeader := channel.Header
channel.Header = channelHeader
- InvalidateCacheForChannel(channel.Id)
- if ucresult := <-Srv.Store.Channel().Update(channel); ucresult.Err != nil {
+ app.InvalidateCacheForChannel(channel.Id)
+ if ucresult := <-app.Srv.Store.Channel().Update(channel); ucresult.Err != nil {
c.Err = ucresult.Err
return
} else {
@@ -327,7 +285,7 @@ func updateChannelHeader(c *Context, w http.ResponseWriter, r *http.Request) {
}
func PostUpdateChannelHeaderMessage(c *Context, channelId string, oldChannelHeader, newChannelHeader string) {
- uc := Srv.Store.User().Get(c.Session.UserId)
+ uc := app.Srv.Store.User().Get(c.Session.UserId)
if uresult := <-uc; uresult.Err != nil {
l4g.Error(utils.T("api.channel.post_update_channel_header_message_and_forget.retrieve_user.error"), uresult.Err)
@@ -355,14 +313,14 @@ func PostUpdateChannelHeaderMessage(c *Context, channelId string, oldChannelHead
},
}
- if _, err := CreatePost(c, post, false); err != nil {
+ if _, err := app.CreatePost(post, c.TeamId, false); err != nil {
l4g.Error(utils.T("api.channel.post_update_channel_header_message_and_forget.join_leave.error"), err)
}
}
}
func PostUpdateChannelDisplayNameMessage(c *Context, channelId string, oldChannelDisplayName, newChannelDisplayName string) {
- uc := Srv.Store.User().Get(c.Session.UserId)
+ uc := app.Srv.Store.User().Get(c.Session.UserId)
if uresult := <-uc; uresult.Err != nil {
l4g.Error(utils.T("api.channel.post_update_channel_displayname_message_and_forget.retrieve_user.error"), uresult.Err)
@@ -383,7 +341,7 @@ func PostUpdateChannelDisplayNameMessage(c *Context, channelId string, oldChanne
},
}
- if _, err := CreatePost(c, post, false); err != nil {
+ if _, err := app.CreatePost(post, c.TeamId, false); err != nil {
l4g.Error(utils.T("api.channel.post_update_channel_displayname_message_and_forget.create_post.error"), err)
}
}
@@ -403,8 +361,8 @@ func updateChannelPurpose(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
- sc := Srv.Store.Channel().Get(channelId, true)
- cmc := Srv.Store.Channel().GetMember(channelId, c.Session.UserId)
+ sc := app.Srv.Store.Channel().Get(channelId, true)
+ cmc := app.Srv.Store.Channel().GetMember(channelId, c.Session.UserId)
if cresult := <-sc; cresult.Err != nil {
c.Err = cresult.Err
@@ -422,8 +380,8 @@ func updateChannelPurpose(c *Context, w http.ResponseWriter, r *http.Request) {
channel.Purpose = channelPurpose
- InvalidateCacheForChannel(channel.Id)
- if ucresult := <-Srv.Store.Channel().Update(channel); ucresult.Err != nil {
+ app.InvalidateCacheForChannel(channel.Id)
+ if ucresult := <-app.Srv.Store.Channel().Update(channel); ucresult.Err != nil {
c.Err = ucresult.Err
return
} else {
@@ -441,10 +399,11 @@ func getChannels(c *Context, w http.ResponseWriter, r *http.Request) {
}
// user is already in the team
// Get's all channels the user is a member of
- if result := <-Srv.Store.Channel().GetChannels(c.TeamId, c.Session.UserId); result.Err != nil {
+
+ if result := <-app.Srv.Store.Channel().GetChannels(c.TeamId, c.Session.UserId); result.Err != nil {
if result.Err.Id == "store.sql_channel.get_channels.not_found.app_error" {
// lets make sure the user is valid
- if result := <-Srv.Store.User().Get(c.Session.UserId); result.Err != nil {
+ if result := <-app.Srv.Store.User().Get(c.Session.UserId); result.Err != nil {
c.Err = result.Err
c.RemoveSessionCookie(w, r)
l4g.Error(utils.T("api.channel.get_channels.error"), c.Session.UserId)
@@ -482,7 +441,7 @@ func getMoreChannelsPage(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
- if result := <-Srv.Store.Channel().GetMoreChannels(c.TeamId, c.Session.UserId, offset, limit); result.Err != nil {
+ if result := <-app.Srv.Store.Channel().GetMoreChannels(c.TeamId, c.Session.UserId, offset, limit); result.Err != nil {
c.Err = result.Err
return
} else {
@@ -496,7 +455,7 @@ func getChannelCounts(c *Context, w http.ResponseWriter, r *http.Request) {
// user is already in the team
- if result := <-Srv.Store.Channel().GetChannelCounts(c.TeamId, c.Session.UserId); result.Err != nil {
+ if result := <-app.Srv.Store.Channel().GetChannelCounts(c.TeamId, c.Session.UserId); result.Err != nil {
c.Err = model.NewLocAppError("getChannelCounts", "api.channel.get_channel_counts.app_error", nil, result.Err.Message)
return
} else if HandleEtag(result.Data.(*model.ChannelCounts).Etag(), "Get Channel Counts", w, r) {
@@ -539,15 +498,15 @@ func join(c *Context, w http.ResponseWriter, r *http.Request) {
}
func JoinChannelByName(c *Context, userId string, teamId string, channelName string) (*model.AppError, *model.Channel) {
- channelChannel := Srv.Store.Channel().GetByName(teamId, channelName)
- userChannel := Srv.Store.User().Get(userId)
+ channelChannel := app.Srv.Store.Channel().GetByName(teamId, channelName)
+ userChannel := app.Srv.Store.User().Get(userId)
return joinChannel(c, channelChannel, userChannel)
}
func JoinChannelById(c *Context, userId string, channelId string) (*model.AppError, *model.Channel) {
- channelChannel := Srv.Store.Channel().Get(channelId, true)
- userChannel := Srv.Store.User().Get(userId)
+ channelChannel := app.Srv.Store.Channel().Get(channelId, true)
+ userChannel := app.Srv.Store.User().Get(userId)
return joinChannel(c, channelChannel, userChannel)
}
@@ -561,7 +520,7 @@ func joinChannel(c *Context, channelChannel store.StoreChannel, userChannel stor
channel := cresult.Data.(*model.Channel)
user := uresult.Data.(*model.User)
- if mresult := <-Srv.Store.Channel().GetMember(channel.Id, user.Id); mresult.Err == nil && mresult.Data != nil {
+ if mresult := <-app.Srv.Store.Channel().GetMember(channel.Id, user.Id); mresult.Err == nil && mresult.Data != nil {
// the user is already in the channel so just return successful
return nil, channel
}
@@ -571,7 +530,7 @@ func joinChannel(c *Context, channelChannel store.StoreChannel, userChannel stor
}
if channel.Type == model.CHANNEL_OPEN {
- if _, err := AddUserToChannel(user, channel); err != nil {
+ if _, err := app.AddUserToChannel(user, channel); err != nil {
return err, nil
}
go PostUserAddRemoveMessage(c, channel.Id, fmt.Sprintf(utils.T("api.channel.join_channel.post_and_forget"), user.Username), model.POST_JOIN_LEAVE)
@@ -589,135 +548,19 @@ func PostUserAddRemoveMessage(c *Context, channelId string, message, postType st
Type: postType,
UserId: c.Session.UserId,
}
- if _, err := CreatePost(c, post, false); err != nil {
+ if _, err := app.CreatePost(post, c.TeamId, false); err != nil {
l4g.Error(utils.T("api.channel.post_user_add_remove_message_and_forget.error"), err)
}
}
-func AddUserToChannel(user *model.User, channel *model.Channel) (*model.ChannelMember, *model.AppError) {
- if channel.DeleteAt > 0 {
- return nil, model.NewLocAppError("AddUserToChannel", "api.channel.add_user_to_channel.deleted.app_error", nil, "")
- }
-
- if channel.Type != model.CHANNEL_OPEN && channel.Type != model.CHANNEL_PRIVATE {
- return nil, model.NewLocAppError("AddUserToChannel", "api.channel.add_user_to_channel.type.app_error", nil, "")
- }
-
- tmchan := Srv.Store.Team().GetMember(channel.TeamId, user.Id)
- cmchan := Srv.Store.Channel().GetMember(channel.Id, user.Id)
-
- if result := <-tmchan; result.Err != nil {
- return nil, result.Err
- } else {
- teamMember := result.Data.(model.TeamMember)
- if teamMember.DeleteAt > 0 {
- return nil, model.NewLocAppError("AddUserToChannel", "api.channel.add_user.to.channel.failed.deleted.app_error", nil, "")
- }
- }
-
- if result := <-cmchan; result.Err != nil {
- if result.Err.Id != store.MISSING_CHANNEL_MEMBER_ERROR {
- return nil, result.Err
- }
- } else {
- channelMember := result.Data.(model.ChannelMember)
- return &channelMember, nil
- }
-
- newMember := &model.ChannelMember{
- ChannelId: channel.Id,
- UserId: user.Id,
- NotifyProps: model.GetDefaultChannelNotifyProps(),
- Roles: model.ROLE_CHANNEL_USER.Id,
- }
- if result := <-Srv.Store.Channel().SaveMember(newMember); result.Err != nil {
- l4g.Error("Failed to add member user_id=%v channel_id=%v err=%v", user.Id, channel.Id, result.Err)
- return nil, model.NewLocAppError("AddUserToChannel", "api.channel.add_user.to.channel.failed.app_error", nil, "")
- }
-
- InvalidateCacheForUser(user.Id)
- InvalidateCacheForChannel(channel.Id)
-
- message := model.NewWebSocketEvent(model.WEBSOCKET_EVENT_USER_ADDED, "", channel.Id, "", nil)
- message.Add("user_id", user.Id)
- message.Add("team_id", channel.TeamId)
- go Publish(message)
-
- return newMember, nil
-}
-
-func JoinDefaultChannels(teamId string, user *model.User, channelRole string) *model.AppError {
- // We don't call JoinChannel here since c.Session is not populated on user creation
-
- var err *model.AppError = nil
-
- fakeContext := &Context{
- Session: model.Session{
- UserId: user.Id,
- },
- TeamId: teamId,
- T: utils.TfuncWithFallback(user.Locale),
- }
-
- if result := <-Srv.Store.Channel().GetByName(teamId, "town-square"); result.Err != nil {
- err = result.Err
- } else {
- cm := &model.ChannelMember{ChannelId: result.Data.(*model.Channel).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,
- }
-
- InvalidateCacheForChannel(result.Data.(*model.Channel).Id)
-
- if _, err := CreatePost(fakeContext, post, 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"); result.Err != nil {
- err = result.Err
- } else {
- cm := &model.ChannelMember{ChannelId: result.Data.(*model.Channel).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,
- }
-
- InvalidateCacheForChannel(result.Data.(*model.Channel).Id)
-
- if _, err := CreatePost(fakeContext, post, false); err != nil {
- l4g.Error(utils.T("api.channel.post_user_add_remove_message_and_forget.error"), err)
- }
- }
-
- return err
-}
-
func leave(c *Context, w http.ResponseWriter, r *http.Request) {
params := mux.Vars(r)
id := params["channel_id"]
- sc := Srv.Store.Channel().Get(id, true)
- uc := Srv.Store.User().Get(c.Session.UserId)
- ccm := Srv.Store.Channel().GetMemberCount(id, false)
+ sc := app.Srv.Store.Channel().Get(id, true)
+ uc := app.Srv.Store.User().Get(c.Session.UserId)
+ ccm := app.Srv.Store.Channel().GetMemberCount(id, false)
if cresult := <-sc; cresult.Err != nil {
c.Err = cresult.Err
@@ -751,7 +594,7 @@ func leave(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
- if cmresult := <-Srv.Store.Channel().RemoveMember(channel.Id, c.Session.UserId); cmresult.Err != nil {
+ if cmresult := <-app.Srv.Store.Channel().RemoveMember(channel.Id, c.Session.UserId); cmresult.Err != nil {
c.Err = cmresult.Err
return
}
@@ -771,12 +614,12 @@ func deleteChannel(c *Context, w http.ResponseWriter, r *http.Request) {
params := mux.Vars(r)
id := params["channel_id"]
- sc := Srv.Store.Channel().Get(id, true)
- scm := Srv.Store.Channel().GetMember(id, c.Session.UserId)
- cmc := Srv.Store.Channel().GetMemberCount(id, false)
- uc := Srv.Store.User().Get(c.Session.UserId)
- ihc := Srv.Store.Webhook().GetIncomingByChannel(id)
- ohc := Srv.Store.Webhook().GetOutgoingByChannel(id)
+ sc := app.Srv.Store.Channel().Get(id, true)
+ scm := app.Srv.Store.Channel().GetMember(id, c.Session.UserId)
+ cmc := app.Srv.Store.Channel().GetMemberCount(id, false)
+ uc := app.Srv.Store.User().Get(c.Session.UserId)
+ ihc := app.Srv.Store.Webhook().GetIncomingByChannel(id)
+ ohc := app.Srv.Store.Webhook().GetOutgoingByChannel(id)
if cresult := <-sc; cresult.Err != nil {
c.Err = cresult.Err
@@ -834,35 +677,35 @@ func deleteChannel(c *Context, w http.ResponseWriter, r *http.Request) {
UserId: c.Session.UserId,
}
- if _, err := CreatePost(c, post, false); err != nil {
+ if _, err := app.CreatePost(post, c.TeamId, false); err != nil {
l4g.Error(utils.T("api.channel.delete_channel.failed_post.error"), err)
}
now := model.GetMillis()
for _, hook := range incomingHooks {
- if result := <-Srv.Store.Webhook().DeleteIncoming(hook.Id, now); result.Err != nil {
+ if result := <-app.Srv.Store.Webhook().DeleteIncoming(hook.Id, now); result.Err != nil {
l4g.Error(utils.T("api.channel.delete_channel.incoming_webhook.error"), hook.Id)
}
}
for _, hook := range outgoingHooks {
- if result := <-Srv.Store.Webhook().DeleteOutgoing(hook.Id, now); result.Err != nil {
+ if result := <-app.Srv.Store.Webhook().DeleteOutgoing(hook.Id, now); result.Err != nil {
l4g.Error(utils.T("api.channel.delete_channel.outgoing_webhook.error"), hook.Id)
}
}
- if dresult := <-Srv.Store.Channel().Delete(channel.Id, model.GetMillis()); dresult.Err != nil {
+ if dresult := <-app.Srv.Store.Channel().Delete(channel.Id, model.GetMillis()); dresult.Err != nil {
c.Err = dresult.Err
return
}
- InvalidateCacheForChannel(channel.Id)
+ app.InvalidateCacheForChannel(channel.Id)
c.LogAudit("name=" + channel.Name)
message := model.NewWebSocketEvent(model.WEBSOCKET_EVENT_CHANNEL_DELETED, c.TeamId, "", "", nil)
message.Add("channel_id", channel.Id)
- Publish(message)
+ app.Publish(message)
result := make(map[string]string)
result["id"] = channel.Id
@@ -874,8 +717,8 @@ func getChannel(c *Context, w http.ResponseWriter, r *http.Request) {
params := mux.Vars(r)
id := params["channel_id"]
- cchan := Srv.Store.Channel().Get(id, true)
- cmchan := Srv.Store.Channel().GetMember(id, c.Session.UserId)
+ cchan := app.Srv.Store.Channel().Get(id, true)
+ cmchan := app.Srv.Store.Channel().GetMember(id, c.Session.UserId)
if cresult := <-cchan; cresult.Err != nil {
c.Err = cresult.Err
@@ -904,7 +747,7 @@ func getChannel(c *Context, w http.ResponseWriter, r *http.Request) {
}
func SetActiveChannel(userId string, channelId string) *model.AppError {
- status, err := GetStatus(userId)
+ status, err := app.GetStatus(userId)
if err != nil {
status = &model.Status{userId, model.STATUS_ONLINE, false, model.GetMillis(), channelId}
} else {
@@ -915,7 +758,7 @@ func SetActiveChannel(userId string, channelId string) *model.AppError {
status.LastActivityAt = model.GetMillis()
}
- AddStatusCache(status)
+ app.AddStatusCache(status)
return nil
}
@@ -924,7 +767,7 @@ func getChannelByName(c *Context, w http.ResponseWriter, r *http.Request) {
params := mux.Vars(r)
channelName := params["channel_name"]
- cchan := Srv.Store.Channel().GetByName(c.TeamId, channelName)
+ cchan := app.Srv.Store.Channel().GetByName(c.TeamId, channelName)
if cresult := <-cchan; cresult.Err != nil {
c.Err = cresult.Err
@@ -954,7 +797,7 @@ func getChannelStats(c *Context, w http.ResponseWriter, r *http.Request) {
params := mux.Vars(r)
id := params["channel_id"]
- sc := Srv.Store.Channel().Get(id, true)
+ sc := app.Srv.Store.Channel().Get(id, true)
var channel *model.Channel
if result := <-sc; result.Err != nil {
c.Err = result.Err
@@ -963,7 +806,7 @@ func getChannelStats(c *Context, w http.ResponseWriter, r *http.Request) {
channel = result.Data.(*model.Channel)
}
- if result := <-Srv.Store.Channel().GetMemberCount(id, true); result.Err != nil {
+ if result := <-app.Srv.Store.Channel().GetMemberCount(id, true); result.Err != nil {
c.Err = result.Err
return
} else {
@@ -993,7 +836,7 @@ func getChannelMember(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
- if result := <-Srv.Store.Channel().GetMember(channelId, userId); result.Err != nil {
+ if result := <-app.Srv.Store.Channel().GetMember(channelId, userId); result.Err != nil {
c.Err = result.Err
return
} else {
@@ -1003,7 +846,7 @@ func getChannelMember(c *Context, w http.ResponseWriter, r *http.Request) {
}
func getMyChannelMembers(c *Context, w http.ResponseWriter, r *http.Request) {
- if result := <-Srv.Store.Channel().GetMembersForUser(c.TeamId, c.Session.UserId); result.Err != nil {
+ if result := <-app.Srv.Store.Channel().GetMembersForUser(c.TeamId, c.Session.UserId); result.Err != nil {
c.Err = result.Err
return
} else {
@@ -1024,9 +867,9 @@ func addMember(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
- sc := Srv.Store.Channel().Get(id, true)
- ouc := Srv.Store.User().Get(c.Session.UserId)
- nuc := Srv.Store.User().Get(userId)
+ sc := app.Srv.Store.Channel().Get(id, true)
+ ouc := app.Srv.Store.User().Get(c.Session.UserId)
+ nuc := app.Srv.Store.User().Get(userId)
if nresult := <-nuc; nresult.Err != nil {
c.Err = model.NewLocAppError("addMember", "api.channel.add_member.find_user.app_error", nil, "")
return
@@ -1051,7 +894,7 @@ func addMember(c *Context, w http.ResponseWriter, r *http.Request) {
} else {
oUser := oresult.Data.(*model.User)
- cm, err := AddUserToChannel(nUser, channel)
+ cm, err := app.AddUserToChannel(nUser, channel)
if err != nil {
c.Err = err
return
@@ -1061,7 +904,7 @@ func addMember(c *Context, w http.ResponseWriter, r *http.Request) {
go PostUserAddRemoveMessage(c, channel.Id, fmt.Sprintf(utils.T("api.channel.add_member.added"), nUser.Username, oUser.Username), model.POST_ADD_REMOVE)
- <-Srv.Store.Channel().UpdateLastViewedAt([]string{id}, oUser.Id)
+ <-app.Srv.Store.Channel().UpdateLastViewedAt([]string{id}, oUser.Id)
w.Write([]byte(cm.ToJson()))
}
}
@@ -1079,9 +922,9 @@ func removeMember(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
- sc := Srv.Store.Channel().Get(channelId, true)
- cmc := Srv.Store.Channel().GetMember(channelId, c.Session.UserId)
- ouc := Srv.Store.User().Get(userIdToRemove)
+ sc := app.Srv.Store.Channel().Get(channelId, true)
+ cmc := app.Srv.Store.Channel().GetMember(channelId, c.Session.UserId)
+ ouc := app.Srv.Store.User().Get(userIdToRemove)
if oresult := <-ouc; oresult.Err != nil {
c.Err = model.NewLocAppError("removeMember", "api.channel.remove_member.user.app_error", nil, "")
@@ -1132,23 +975,23 @@ func RemoveUserFromChannel(userIdToRemove string, removerUserId string, channel
return model.NewLocAppError("RemoveUserFromChannel", "api.channel.remove.default.app_error", map[string]interface{}{"Channel": model.DEFAULT_CHANNEL}, "")
}
- if cmresult := <-Srv.Store.Channel().RemoveMember(channel.Id, userIdToRemove); cmresult.Err != nil {
+ if cmresult := <-app.Srv.Store.Channel().RemoveMember(channel.Id, userIdToRemove); cmresult.Err != nil {
return cmresult.Err
}
- InvalidateCacheForUser(userIdToRemove)
- InvalidateCacheForChannel(channel.Id)
+ app.InvalidateCacheForUser(userIdToRemove)
+ app.InvalidateCacheForChannel(channel.Id)
message := model.NewWebSocketEvent(model.WEBSOCKET_EVENT_USER_REMOVED, "", channel.Id, "", nil)
message.Add("user_id", userIdToRemove)
message.Add("remover_id", removerUserId)
- go Publish(message)
+ go app.Publish(message)
// because the removed user no longer belongs to the channel we need to send a separate websocket event
userMsg := model.NewWebSocketEvent(model.WEBSOCKET_EVENT_USER_REMOVED, "", "", userIdToRemove, nil)
userMsg.Add("channel_id", channel.Id)
userMsg.Add("remover_id", removerUserId)
- go Publish(userMsg)
+ go app.Publish(userMsg)
return nil
}
@@ -1172,7 +1015,7 @@ func updateNotifyProps(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
- result := <-Srv.Store.Channel().GetMember(channelId, userId)
+ result := <-app.Srv.Store.Channel().GetMember(channelId, userId)
if result.Err != nil {
c.Err = result.Err
return
@@ -1189,11 +1032,11 @@ func updateNotifyProps(c *Context, w http.ResponseWriter, r *http.Request) {
member.NotifyProps["desktop"] = desktop
}
- if result := <-Srv.Store.Channel().UpdateMember(&member); result.Err != nil {
+ if result := <-app.Srv.Store.Channel().UpdateMember(&member); result.Err != nil {
c.Err = result.Err
return
} else {
- InvalidateCacheForUser(userId)
+ app.InvalidateCacheForUser(userId)
// return the updated notify properties including any unchanged ones
w.Write([]byte(model.MapToJson(member.NotifyProps)))
@@ -1219,7 +1062,7 @@ func searchMoreChannels(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
- if result := <-Srv.Store.Channel().SearchMore(c.Session.UserId, c.TeamId, props.Term); result.Err != nil {
+ if result := <-app.Srv.Store.Channel().SearchMore(c.Session.UserId, c.TeamId, props.Term); result.Err != nil {
c.Err = result.Err
return
} else {
@@ -1239,7 +1082,7 @@ func autocompleteChannels(c *Context, w http.ResponseWriter, r *http.Request) {
var channels *model.ChannelList
- if result := <-Srv.Store.Channel().SearchInTeam(c.TeamId, term); result.Err != nil {
+ if result := <-app.Srv.Store.Channel().SearchInTeam(c.TeamId, term); result.Err != nil {
c.Err = result.Err
return
} else {
@@ -1269,11 +1112,11 @@ func viewChannel(c *Context, w http.ResponseWriter, r *http.Request) {
channelIds = append(channelIds, view.PrevChannelId)
if *utils.Cfg.EmailSettings.SendPushNotifications && !c.Session.IsMobileApp() {
- pchan = Srv.Store.User().GetUnreadCountForChannel(c.Session.UserId, view.ChannelId)
+ pchan = app.Srv.Store.User().GetUnreadCountForChannel(c.Session.UserId, view.ChannelId)
}
}
- uchan := Srv.Store.Channel().UpdateLastViewedAt(channelIds, c.Session.UserId)
+ uchan := app.Srv.Store.Channel().UpdateLastViewedAt(channelIds, c.Session.UserId)
if pchan != nil {
if result := <-pchan; result.Err != nil {
@@ -1281,7 +1124,7 @@ func viewChannel(c *Context, w http.ResponseWriter, r *http.Request) {
return
} else {
if result.Data.(int64) > 0 {
- clearPushNotification(c.Session.UserId, view.ChannelId)
+ app.ClearPushNotification(c.Session.UserId, view.ChannelId)
}
}
}
@@ -1293,7 +1136,7 @@ func viewChannel(c *Context, w http.ResponseWriter, r *http.Request) {
message := model.NewWebSocketEvent(model.WEBSOCKET_EVENT_CHANNEL_VIEWED, c.TeamId, "", c.Session.UserId, nil)
message.Add("channel_id", view.ChannelId)
- go Publish(message)
+ go app.Publish(message)
ReturnStatusOK(w)
}
@@ -1312,7 +1155,7 @@ func getChannelMembersByIds(c *Context, w http.ResponseWriter, r *http.Request)
return
}
- if result := <-Srv.Store.Channel().GetMembersByIds(channelId, userIds); result.Err != nil {
+ if result := <-app.Srv.Store.Channel().GetMembersByIds(channelId, userIds); result.Err != nil {
c.Err = result.Err
return
} else {
@@ -1334,7 +1177,7 @@ func updateChannelMemberRoles(c *Context, w http.ResponseWriter, r *http.Request
return
}
- mchan := Srv.Store.Channel().GetMember(channelId, userId)
+ mchan := app.Srv.Store.Channel().GetMember(channelId, userId)
newRoles := props["new_roles"]
if !(model.IsValidUserRoles(newRoles)) {
@@ -1356,12 +1199,12 @@ func updateChannelMemberRoles(c *Context, w http.ResponseWriter, r *http.Request
member.Roles = newRoles
- if result := <-Srv.Store.Channel().UpdateMember(&member); result.Err != nil {
+ if result := <-app.Srv.Store.Channel().UpdateMember(&member); result.Err != nil {
c.Err = result.Err
return
}
- InvalidateCacheForUser(userId)
+ app.InvalidateCacheForUser(userId)
rdata := map[string]string{}
rdata["status"] = "ok"