summaryrefslogtreecommitdiffstats
path: root/app/channel.go
diff options
context:
space:
mode:
authorDaniel Schalla <daniel@schalla.me>2018-07-07 00:32:55 +0200
committerChristopher Speller <crspeller@gmail.com>2018-07-06 15:32:55 -0700
commit359f12db33d45b6ffade0872ddf3652a5c52f4a8 (patch)
tree6c60918089574d5bbc1e5121be276d23ef41773d /app/channel.go
parent4c1ddcff10b359baf5728b334acb60cc3e1b1123 (diff)
downloadchat-359f12db33d45b6ffade0872ddf3652a5c52f4a8.tar.gz
chat-359f12db33d45b6ffade0872ddf3652a5c52f4a8.tar.bz2
chat-359f12db33d45b6ffade0872ddf3652a5c52f4a8.zip
First batch of new plugin api methods (#9022)
update api mocks Generated new hooks ChannelHasJoinedChannel Implementation User Left Team/Channel Hook; User Joined Team Hook Implementation Update RPC Client and Mocks gofmt go tests fix Add Config API Methods codegne Add Channel Has Been Created Hook Fix ChannelHasBeenCreated hook fix missing context param fix duplicate hooks; remove redudandcy
Diffstat (limited to 'app/channel.go')
-rw-r--r--app/channel.go71
1 files changed, 70 insertions, 1 deletions
diff --git a/app/channel.go b/app/channel.go
index eee27a6de..b6ccd9f91 100644
--- a/app/channel.go
+++ b/app/channel.go
@@ -11,6 +11,7 @@ import (
"github.com/mattermost/mattermost-server/mlog"
"github.com/mattermost/mattermost-server/model"
+ "github.com/mattermost/mattermost-server/plugin"
"github.com/mattermost/mattermost-server/store"
"github.com/mattermost/mattermost-server/utils"
)
@@ -183,6 +184,16 @@ func (a *App) CreateChannel(channel *model.Channel, addMember bool) (*model.Chan
a.InvalidateCacheForUser(channel.CreatorId)
}
+ if a.PluginsReady() {
+ a.Go(func() {
+ pluginContext := &plugin.Context{}
+ a.Plugins.RunMultiPluginHook(func(hooks plugin.Hooks) bool {
+ hooks.ChannelHasBeenCreated(pluginContext, sc)
+ return true
+ }, plugin.ChannelHasBeenCreatedId)
+ })
+ }
+
return sc, nil
}
}
@@ -200,6 +211,16 @@ func (a *App) CreateDirectChannel(userId string, otherUserId string) (*model.Cha
a.InvalidateCacheForUser(userId)
a.InvalidateCacheForUser(otherUserId)
+ if a.PluginsReady() {
+ a.Go(func() {
+ pluginContext := &plugin.Context{}
+ a.Plugins.RunMultiPluginHook(func(hooks plugin.Hooks) bool {
+ hooks.ChannelHasBeenCreated(pluginContext, channel)
+ return true
+ }, plugin.ChannelHasBeenCreatedId)
+ })
+ }
+
message := model.NewWebSocketEvent(model.WEBSOCKET_EVENT_DIRECT_ADDED, "", channel.Id, "", nil)
message.Add("teammate_id", otherUserId)
a.Publish(message)
@@ -774,6 +795,16 @@ func (a *App) AddChannelMember(userId string, channel *model.Channel, userReques
return nil, err
}
+ if a.PluginsReady() {
+ a.Go(func() {
+ pluginContext := &plugin.Context{}
+ a.Plugins.RunMultiPluginHook(func(hooks plugin.Hooks) bool {
+ hooks.UserHasJoinedChannel(pluginContext, cm, userRequestor)
+ return true
+ }, plugin.UserHasJoinedChannelId)
+ })
+ }
+
if userRequestorId == "" || userId == userRequestorId {
a.postJoinChannelMessage(user, channel)
} else {
@@ -1104,10 +1135,21 @@ func (a *App) JoinChannel(channel *model.Channel, userId string) *model.AppError
user := uresult.Data.(*model.User)
if channel.Type == model.CHANNEL_OPEN {
- if _, err := a.AddUserToChannel(user, channel); err != nil {
+ cm, err := a.AddUserToChannel(user, channel)
+ if err != nil {
return err
}
+ if a.PluginsReady() {
+ a.Go(func() {
+ pluginContext := &plugin.Context{}
+ a.Plugins.RunMultiPluginHook(func(hooks plugin.Hooks) bool {
+ hooks.UserHasJoinedChannel(pluginContext, cm, nil)
+ return true
+ }, plugin.UserHasJoinedChannelId)
+ })
+ }
+
if err := a.postJoinChannelMessage(user, channel); err != nil {
return err
}
@@ -1288,6 +1330,11 @@ func (a *App) removeUserFromChannel(userIdToRemove string, removerUserId string,
return model.NewAppError("RemoveUserFromChannel", "api.channel.remove.default.app_error", map[string]interface{}{"Channel": model.DEFAULT_CHANNEL}, "", http.StatusBadRequest)
}
+ cm, err := a.GetChannelMember(channel.Id, userIdToRemove)
+ if err != nil {
+ return err
+ }
+
if cmresult := <-a.Srv.Store.Channel().RemoveMember(channel.Id, userIdToRemove); cmresult.Err != nil {
return cmresult.Err
}
@@ -1298,6 +1345,22 @@ func (a *App) removeUserFromChannel(userIdToRemove string, removerUserId string,
a.InvalidateCacheForUser(userIdToRemove)
a.InvalidateCacheForChannelMembers(channel.Id)
+ if a.PluginsReady() {
+
+ var actorUser *model.User
+ if removerUserId != "" {
+ actorUser, err = a.GetUser(removerUserId)
+ }
+
+ a.Go(func() {
+ pluginContext := &plugin.Context{}
+ a.Plugins.RunMultiPluginHook(func(hooks plugin.Hooks) bool {
+ hooks.UserHasLeftChannel(pluginContext, cm, actorUser)
+ return true
+ }, plugin.UserHasLeftChannelId)
+ })
+ }
+
message := model.NewWebSocketEvent(model.WEBSOCKET_EVENT_USER_REMOVED, "", channel.Id, "", nil)
message.Add("user_id", userIdToRemove)
message.Add("remover_id", removerUserId)
@@ -1314,6 +1377,7 @@ func (a *App) removeUserFromChannel(userIdToRemove string, removerUserId string,
func (a *App) RemoveUserFromChannel(userIdToRemove string, removerUserId string, channel *model.Channel) *model.AppError {
var err *model.AppError
+
if err = a.removeUserFromChannel(userIdToRemove, removerUserId, channel); err != nil {
return err
}
@@ -1326,6 +1390,11 @@ func (a *App) RemoveUserFromChannel(userIdToRemove string, removerUserId string,
if userIdToRemove == removerUserId {
a.postLeaveChannelMessage(user, channel)
} else {
+
+ if err != nil {
+ return err
+ }
+
a.Go(func() {
a.postRemoveFromChannelMessage(removerUserId, user, channel)
})