Don't return error if already part of channel being joined (#2814)
Этот коммит содержится в:
коммит произвёл
Christopher Speller
родитель
3dbb5ab4cc
Коммит
383cddd3d1
2
Makefile
2
Makefile
@@ -143,7 +143,7 @@ check-style:
|
|||||||
test: start-docker
|
test: start-docker
|
||||||
@echo Running tests
|
@echo Running tests
|
||||||
|
|
||||||
$(GO) test $(GOFLAGS) -run=$(TESTS) -test.v -test.timeout=240s ./api || exit 1
|
$(GO) test $(GOFLAGS) -run=$(TESTS) -test.v -test.timeout=340s ./api || exit 1
|
||||||
$(GO) test $(GOFLAGS) -run=$(TESTS) -test.v -test.timeout=12s ./model || exit 1
|
$(GO) test $(GOFLAGS) -run=$(TESTS) -test.v -test.timeout=12s ./model || exit 1
|
||||||
$(GO) test $(GOFLAGS) -run=$(TESTS) -test.v -test.timeout=120s ./store || exit 1
|
$(GO) test $(GOFLAGS) -run=$(TESTS) -test.v -test.timeout=120s ./store || exit 1
|
||||||
$(GO) test $(GOFLAGS) -run=$(TESTS) -test.v -test.timeout=120s ./utils || exit 1
|
$(GO) test $(GOFLAGS) -run=$(TESTS) -test.v -test.timeout=120s ./utils || exit 1
|
||||||
|
|||||||
@@ -513,9 +513,18 @@ func AddUserToChannel(user *model.User, channel *model.Channel) (*model.ChannelM
|
|||||||
return nil, model.NewLocAppError("AddUserToChannel", "api.channel.add_user_to_channel.type.app_error", nil, "")
|
return nil, model.NewLocAppError("AddUserToChannel", "api.channel.add_user_to_channel.type.app_error", nil, "")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if result := <-Srv.Store.Channel().GetMember(channel.Id, user.Id); result.Err != nil {
|
||||||
|
if result.Err.Id != store.MISSING_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()}
|
newMember := &model.ChannelMember{ChannelId: channel.Id, UserId: user.Id, NotifyProps: model.GetDefaultChannelNotifyProps()}
|
||||||
if cmresult := <-Srv.Store.Channel().SaveMember(newMember); cmresult.Err != nil {
|
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, cmresult.Err)
|
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, "")
|
return nil, model.NewLocAppError("AddUserToChannel", "api.channel.add_user.to.channel.failed.app_error", nil, "")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -691,8 +691,8 @@ func TestAddChannelMember(t *testing.T) {
|
|||||||
t.Fatal("Should have errored, bad user id")
|
t.Fatal("Should have errored, bad user id")
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := Client.AddChannelMember(channel1.Id, user2.Id); err == nil {
|
if _, err := Client.AddChannelMember(channel1.Id, user2.Id); err != nil {
|
||||||
t.Fatal("Should have errored, user already a member")
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := Client.AddChannelMember("sgdsgsdg", user2.Id); err == nil {
|
if _, err := Client.AddChannelMember("sgdsgsdg", user2.Id); err == nil {
|
||||||
|
|||||||
@@ -2851,6 +2851,10 @@
|
|||||||
"id": "store.sql_channel.get_for_export.app_error",
|
"id": "store.sql_channel.get_for_export.app_error",
|
||||||
"translation": "We couldn't get all the channels"
|
"translation": "We couldn't get all the channels"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"id": "store.sql_channel.get_member.missing.app_error",
|
||||||
|
"translation": "No channel member found for that user id and channel id"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"id": "store.sql_channel.get_member.app_error",
|
"id": "store.sql_channel.get_member.app_error",
|
||||||
"translation": "We couldn't get the channel member"
|
"translation": "We couldn't get the channel member"
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import (
|
|||||||
|
|
||||||
const (
|
const (
|
||||||
MISSING_CHANNEL_ERROR = "store.sql_channel.get_by_name.missing.app_error"
|
MISSING_CHANNEL_ERROR = "store.sql_channel.get_by_name.missing.app_error"
|
||||||
|
MISSING_MEMBER_ERROR = "store.sql_channel.get_member.missing.app_error"
|
||||||
)
|
)
|
||||||
|
|
||||||
type SqlChannelStore struct {
|
type SqlChannelStore struct {
|
||||||
@@ -572,9 +573,13 @@ func (s SqlChannelStore) GetMember(channelId string, userId string) StoreChannel
|
|||||||
result := StoreResult{}
|
result := StoreResult{}
|
||||||
|
|
||||||
var member model.ChannelMember
|
var member model.ChannelMember
|
||||||
err := s.GetReplica().SelectOne(&member, "SELECT * FROM ChannelMembers WHERE ChannelId = :ChannelId AND UserId = :UserId", map[string]interface{}{"ChannelId": channelId, "UserId": userId})
|
|
||||||
if err != nil {
|
if err := s.GetReplica().SelectOne(&member, "SELECT * FROM ChannelMembers WHERE ChannelId = :ChannelId AND UserId = :UserId", map[string]interface{}{"ChannelId": channelId, "UserId": userId}); err != nil {
|
||||||
|
if err == sql.ErrNoRows {
|
||||||
|
result.Err = model.NewLocAppError("SqlChannelStore.GetMember", MISSING_MEMBER_ERROR, nil, "channel_id="+channelId+"user_id="+userId+","+err.Error())
|
||||||
|
} else {
|
||||||
result.Err = model.NewLocAppError("SqlChannelStore.GetMember", "store.sql_channel.get_member.app_error", nil, "channel_id="+channelId+"user_id="+userId+","+err.Error())
|
result.Err = model.NewLocAppError("SqlChannelStore.GetMember", "store.sql_channel.get_member.app_error", nil, "channel_id="+channelId+"user_id="+userId+","+err.Error())
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
result.Data = member
|
result.Data = member
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,8 +9,12 @@ function getCountsStateFromStores() {
|
|||||||
var channels = ChannelStore.getAll();
|
var channels = ChannelStore.getAll();
|
||||||
var members = ChannelStore.getAllMembers();
|
var members = ChannelStore.getAllMembers();
|
||||||
|
|
||||||
channels.forEach(function setChannelInfo(channel) {
|
channels.forEach((channel) => {
|
||||||
var channelMember = members[channel.id];
|
var channelMember = members[channel.id];
|
||||||
|
if (channelMember == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (channel.type === 'D') {
|
if (channel.type === 'D') {
|
||||||
count += channel.total_msg_count - channelMember.msg_count;
|
count += channel.total_msg_count - channelMember.msg_count;
|
||||||
} else if (channelMember.mention_count > 0) {
|
} else if (channelMember.mention_count > 0) {
|
||||||
@@ -20,7 +24,7 @@ function getCountsStateFromStores() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return {count: count};
|
return {count};
|
||||||
}
|
}
|
||||||
|
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user