Add GetChannelMember method to plugin API (#7930)

Этот коммит содержится в:
Joram Wilander
2017-12-05 09:14:03 -05:00
коммит произвёл GitHub
родитель 46f51197fb
Коммит 7a1f81cd52
5 изменённых файлов: 57 добавлений и 0 удалений

Просмотреть файл

@@ -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 {

Просмотреть файл

@@ -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