diff options
author | Joram Wilander <jwawilander@gmail.com> | 2017-12-05 09:14:03 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-12-05 09:14:03 -0500 |
commit | 7a1f81cd52c4b58a058ae11e361a80ee3b24d141 (patch) | |
tree | 8845eba3280d1ac17a0f0014979e4a995a55e023 /plugin/rpcplugin | |
parent | 46f51197fb8197fe8a5468c86aad64eeab815bad (diff) | |
download | chat-7a1f81cd52c4b58a058ae11e361a80ee3b24d141.tar.gz chat-7a1f81cd52c4b58a058ae11e361a80ee3b24d141.tar.bz2 chat-7a1f81cd52c4b58a058ae11e361a80ee3b24d141.zip |
Add GetChannelMember method to plugin API (#7930)
Diffstat (limited to 'plugin/rpcplugin')
-rw-r--r-- | plugin/rpcplugin/api.go | 30 | ||||
-rw-r--r-- | plugin/rpcplugin/api_test.go | 10 |
2 files changed, 40 insertions, 0 deletions
diff --git a/plugin/rpcplugin/api.go b/plugin/rpcplugin/api.go index f2068e815..fb3517ae2 100644 --- a/plugin/rpcplugin/api.go +++ b/plugin/rpcplugin/api.go @@ -154,11 +154,21 @@ type APIGetGroupChannelArgs struct { UserIds []string } +type APIGetChannelMemberArgs struct { + ChannelId string + UserId string +} + type APIChannelReply struct { Channel *model.Channel Error *model.AppError } +type APIChannelMemberReply struct { + ChannelMember *model.ChannelMember + Error *model.AppError +} + func (api *LocalAPI) CreateChannel(args *model.Channel, reply *APIChannelReply) error { channel, err := api.api.CreateChannel(args) *reply = APIChannelReply{ @@ -220,6 +230,15 @@ func (api *LocalAPI) UpdateChannel(args *model.Channel, reply *APIChannelReply) return nil } +func (api *LocalAPI) GetChannelMember(args *APIGetChannelMemberArgs, reply *APIChannelMemberReply) error { + member, err := api.api.GetChannelMember(args.ChannelId, args.UserId) + *reply = APIChannelMemberReply{ + ChannelMember: member, + Error: err, + } + return nil +} + type APIPostReply struct { Post *model.Post Error *model.AppError @@ -476,6 +495,17 @@ func (api *RemoteAPI) UpdateChannel(channel *model.Channel) (*model.Channel, *mo return reply.Channel, reply.Error } +func (api *RemoteAPI) GetChannelMember(channelId, userId string) (*model.ChannelMember, *model.AppError) { + var reply APIChannelMemberReply + if err := api.client.Call("LocalAPI.GetChannelMember", &APIGetChannelMemberArgs{ + ChannelId: channelId, + UserId: userId, + }, &reply); err != nil { + return nil, model.NewAppError("RemoteAPI.GetChannelMember", "plugin.rpcplugin.invocation.error", nil, "err="+err.Error(), http.StatusInternalServerError) + } + return reply.ChannelMember, reply.Error +} + func (api *RemoteAPI) CreatePost(post *model.Post) (*model.Post, *model.AppError) { var reply APIPostReply if err := api.client.Call("LocalAPI.CreatePost", post, &reply); err != nil { diff --git a/plugin/rpcplugin/api_test.go b/plugin/rpcplugin/api_test.go index 0c7321162..8a36ef4f6 100644 --- a/plugin/rpcplugin/api_test.go +++ b/plugin/rpcplugin/api_test.go @@ -54,6 +54,11 @@ func TestAPI(t *testing.T) { Id: "thechannelid", } + testChannelMember := &model.ChannelMember{ + ChannelId: "thechannelid", + UserId: "theuserid", + } + testTeam := &model.Team{ Id: "theteamid", } @@ -111,6 +116,11 @@ func TestAPI(t *testing.T) { assert.Equal(t, testChannel, channel) assert.Nil(t, err) + api.On("GetChannelMember", "thechannelid", "theuserid").Return(testChannelMember, nil).Once() + member, err := remote.GetChannelMember("thechannelid", "theuserid") + assert.Equal(t, testChannelMember, member) + assert.Nil(t, err) + api.On("CreateUser", mock.AnythingOfType("*model.User")).Return(func(u *model.User) (*model.User, *model.AppError) { u.Id = "theuserid" return u, nil |