summaryrefslogtreecommitdiffstats
path: root/plugin
diff options
context:
space:
mode:
authorJoram Wilander <jwawilander@gmail.com>2017-12-05 09:14:03 -0500
committerGitHub <noreply@github.com>2017-12-05 09:14:03 -0500
commit7a1f81cd52c4b58a058ae11e361a80ee3b24d141 (patch)
tree8845eba3280d1ac17a0f0014979e4a995a55e023 /plugin
parent46f51197fb8197fe8a5468c86aad64eeab815bad (diff)
downloadchat-7a1f81cd52c4b58a058ae11e361a80ee3b24d141.tar.gz
chat-7a1f81cd52c4b58a058ae11e361a80ee3b24d141.tar.bz2
chat-7a1f81cd52c4b58a058ae11e361a80ee3b24d141.zip
Add GetChannelMember method to plugin API (#7930)
Diffstat (limited to 'plugin')
-rw-r--r--plugin/api.go3
-rw-r--r--plugin/plugintest/api.go10
-rw-r--r--plugin/rpcplugin/api.go30
-rw-r--r--plugin/rpcplugin/api_test.go10
4 files changed, 53 insertions, 0 deletions
diff --git a/plugin/api.go b/plugin/api.go
index 4bcfd112b..fee55eeff 100644
--- a/plugin/api.go
+++ b/plugin/api.go
@@ -70,6 +70,9 @@ type API interface {
// UpdateChannel updates a channel.
UpdateChannel(channel *model.Channel) (*model.Channel, *model.AppError)
+ // GetChannelMember gets a channel membership for a user.
+ GetChannelMember(channelId, userId string) (*model.ChannelMember, *model.AppError)
+
// CreatePost creates a post.
CreatePost(post *model.Post) (*model.Post, *model.AppError)
diff --git a/plugin/plugintest/api.go b/plugin/plugintest/api.go
index a4abbbca3..b00542032 100644
--- a/plugin/plugintest/api.go
+++ b/plugin/plugintest/api.go
@@ -207,6 +207,16 @@ func (m *API) UpdateChannel(channel *model.Channel) (*model.Channel, *model.AppE
return channelOut, err
}
+func (m *API) GetChannelMember(channelId, userId string) (*model.ChannelMember, *model.AppError) {
+ ret := m.Called(channelId, userId)
+ if f, ok := ret.Get(0).(func(_, _ string) (*model.ChannelMember, *model.AppError)); ok {
+ return f(channelId, userId)
+ }
+ member, _ := ret.Get(0).(*model.ChannelMember)
+ err, _ := ret.Get(1).(*model.AppError)
+ return member, err
+}
+
func (m *API) CreatePost(post *model.Post) (*model.Post, *model.AppError) {
ret := m.Called(post)
if f, ok := ret.Get(0).(func(*model.Post) (*model.Post, *model.AppError)); ok {
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