Don't return error if already part of channel being joined (#2814)

This commit is contained in:
Joram Wilander
2016-04-28 10:56:19 -04:00
committed by Christopher Speller
parent 3dbb5ab4cc
commit 383cddd3d1
6 changed files with 32 additions and 10 deletions

View File

@@ -143,7 +143,7 @@ check-style:
test: start-docker
@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=120s ./store || exit 1
$(GO) test $(GOFLAGS) -run=$(TESTS) -test.v -test.timeout=120s ./utils || exit 1

View File

@@ -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, "")
}
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()}
if cmresult := <-Srv.Store.Channel().SaveMember(newMember); cmresult.Err != nil {
l4g.Error("Failed to add member user_id=%v channel_id=%v err=%v", user.Id, channel.Id, cmresult.Err)
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, result.Err)
return nil, model.NewLocAppError("AddUserToChannel", "api.channel.add_user.to.channel.failed.app_error", nil, "")
}

View File

@@ -691,8 +691,8 @@ func TestAddChannelMember(t *testing.T) {
t.Fatal("Should have errored, bad user id")
}
if _, err := Client.AddChannelMember(channel1.Id, user2.Id); err == nil {
t.Fatal("Should have errored, user already a member")
if _, err := Client.AddChannelMember(channel1.Id, user2.Id); err != nil {
t.Fatal(err)
}
if _, err := Client.AddChannelMember("sgdsgsdg", user2.Id); err == nil {

View File

@@ -2851,6 +2851,10 @@
"id": "store.sql_channel.get_for_export.app_error",
"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",
"translation": "We couldn't get the channel member"

View File

@@ -12,6 +12,7 @@ import (
const (
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 {
@@ -572,9 +573,13 @@ func (s SqlChannelStore) GetMember(channelId string, userId string) StoreChannel
result := StoreResult{}
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 {
result.Err = model.NewLocAppError("SqlChannelStore.GetMember", "store.sql_channel.get_member.app_error", nil, "channel_id="+channelId+"user_id="+userId+","+err.Error())
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())
}
} else {
result.Data = member
}

View File

@@ -9,8 +9,12 @@ function getCountsStateFromStores() {
var channels = ChannelStore.getAll();
var members = ChannelStore.getAllMembers();
channels.forEach(function setChannelInfo(channel) {
channels.forEach((channel) => {
var channelMember = members[channel.id];
if (channelMember == null) {
return;
}
if (channel.type === 'D') {
count += channel.total_msg_count - channelMember.msg_count;
} else if (channelMember.mention_count > 0) {
@@ -20,7 +24,7 @@ function getCountsStateFromStores() {
}
});
return {count: count};
return {count};
}
import React from 'react';