Multiple cross-team functionality fixes (#2902)

Этот коммит содержится в:
Joram Wilander
2016-05-06 08:06:34 -04:00
коммит произвёл Christopher Speller
родитель 4b2843ee9d
Коммит d75cb02948
7 изменённых файлов: 27 добавлений и 10 удалений

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

@@ -146,7 +146,11 @@ func CreateDirectChannel(userId string, otherUserId string) (*model.Channel, *mo
} }
if result := <-Srv.Store.Channel().SaveDirectChannel(channel, cm1, cm2); result.Err != nil { if result := <-Srv.Store.Channel().SaveDirectChannel(channel, cm1, cm2); result.Err != nil {
return nil, result.Err if result.Err.Id == store.CHANNEL_EXISTS_ERROR {
return result.Data.(*model.Channel), nil
} else {
return nil, result.Err
}
} else { } else {
return result.Data.(*model.Channel), nil return result.Data.(*model.Channel), nil
} }

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

@@ -113,8 +113,9 @@ func TestCreateDirectChannel(t *testing.T) {
t.Fatal("channel type was not direct") t.Fatal("channel type was not direct")
} }
if _, err := Client.CreateDirectChannel(th.BasicUser2.Id); err == nil { // don't fail on direct channels already existing
t.Fatal("channel already exists and should have failed") if _, err := Client.CreateDirectChannel(th.BasicUser2.Id); err != nil {
t.Fatal(err)
} }
if _, err := Client.CreateDirectChannel("junk"); err == nil { if _, err := Client.CreateDirectChannel("junk"); err == nil {

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

@@ -13,6 +13,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" MISSING_MEMBER_ERROR = "store.sql_channel.get_member.missing.app_error"
CHANNEL_EXISTS_ERROR = "store.sql_channel.save_channel.exists.app_error"
) )
type SqlChannelStore struct { type SqlChannelStore struct {
@@ -102,6 +103,7 @@ func (s SqlChannelStore) SaveDirectChannel(directchannel *model.Channel, member1
if channelResult.Err != nil { if channelResult.Err != nil {
transaction.Rollback() transaction.Rollback()
result.Err = channelResult.Err result.Err = channelResult.Err
result.Data = channelResult.Data
} else { } else {
newChannel := channelResult.Data.(*model.Channel) newChannel := channelResult.Data.(*model.Channel)
// Members need new channel ID // Members need new channel ID
@@ -167,9 +169,10 @@ func (s SqlChannelStore) saveChannelT(transaction *gorp.Transaction, channel *mo
dupChannel := model.Channel{} dupChannel := model.Channel{}
s.GetMaster().SelectOne(&dupChannel, "SELECT * FROM Channels WHERE TeamId = :TeamId AND Name = :Name AND DeleteAt > 0", map[string]interface{}{"TeamId": channel.TeamId, "Name": channel.Name}) s.GetMaster().SelectOne(&dupChannel, "SELECT * FROM Channels WHERE TeamId = :TeamId AND Name = :Name AND DeleteAt > 0", map[string]interface{}{"TeamId": channel.TeamId, "Name": channel.Name})
if dupChannel.DeleteAt > 0 { if dupChannel.DeleteAt > 0 {
result.Err = model.NewLocAppError("SqlChannelStore.Update", "store.sql_channel.save_channel.previously.app_error", nil, "id="+channel.Id+", "+err.Error()) result.Err = model.NewLocAppError("SqlChannelStore.Save", "store.sql_channel.save_channel.previously.app_error", nil, "id="+channel.Id+", "+err.Error())
} else { } else {
result.Err = model.NewLocAppError("SqlChannelStore.Update", "store.sql_channel.save_channel.exists.app_error", nil, "id="+channel.Id+", "+err.Error()) result.Err = model.NewLocAppError("SqlChannelStore.Save", CHANNEL_EXISTS_ERROR, nil, "id="+channel.Id+", "+err.Error())
result.Data = &dupChannel
} }
} else { } else {
result.Err = model.NewLocAppError("SqlChannelStore.Save", "store.sql_channel.save_channel.save.app_error", nil, "id="+channel.Id+", "+err.Error()) result.Err = model.NewLocAppError("SqlChannelStore.Save", "store.sql_channel.save_channel.save.app_error", nil, "id="+channel.Id+", "+err.Error())

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

@@ -234,7 +234,7 @@ export function emitPostRecievedEvent(post, msg) {
} else { } else {
AsyncClient.getChannel(post.channel_id); AsyncClient.getChannel(post.channel_id);
} }
} else if (msg && TeamStore.getCurrentId() === msg.team_id) { } else if (msg && (TeamStore.getCurrentId() === msg.team_id || msg.props.channel_type === Constants.DM_CHANNEL)) {
AsyncClient.getChannel(post.channel_id); AsyncClient.getChannel(post.channel_id);
} }

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

@@ -47,13 +47,18 @@ export default class PostsView extends React.Component {
this.scrollStopAction = new DelayedAction(this.handleScrollStop); this.scrollStopAction = new DelayedAction(this.handleScrollStop);
let profiles = UserStore.getProfiles();
if (props.channel.type === Constants.DM_CHANNEL) {
profiles = Object.assign({}, profiles, UserStore.getDirectProfiles());
}
this.state = { this.state = {
displayNameType: PreferenceStore.get(Preferences.CATEGORY_DISPLAY_SETTINGS, 'name_format', 'false'), displayNameType: PreferenceStore.get(Preferences.CATEGORY_DISPLAY_SETTINGS, 'name_format', 'false'),
centerPosts: PreferenceStore.get(Preferences.CATEGORY_DISPLAY_SETTINGS, Preferences.CHANNEL_DISPLAY_MODE, Preferences.CHANNEL_DISPLAY_MODE_DEFAULT) === Preferences.CHANNEL_DISPLAY_MODE_CENTERED, centerPosts: PreferenceStore.get(Preferences.CATEGORY_DISPLAY_SETTINGS, Preferences.CHANNEL_DISPLAY_MODE, Preferences.CHANNEL_DISPLAY_MODE_DEFAULT) === Preferences.CHANNEL_DISPLAY_MODE_CENTERED,
isScrolling: false, isScrolling: false,
topPostId: null, topPostId: null,
currentUser: UserStore.getCurrentUser(), currentUser: UserStore.getCurrentUser(),
profiles: UserStore.getProfiles() profiles
}; };
} }
static get SCROLL_TYPE_FREE() { static get SCROLL_TYPE_FREE() {
@@ -78,7 +83,11 @@ export default class PostsView extends React.Component {
}); });
} }
onUserChange() { onUserChange() {
this.setState({currentUser: UserStore.getCurrentUser(), profiles: JSON.parse(JSON.stringify(UserStore.getProfiles()))}); let profiles = UserStore.getProfiles();
if (this.props.channel.type === Constants.DM_CHANNEL) {
profiles = Object.assign({}, profiles, UserStore.getDirectProfiles());
}
this.setState({currentUser: UserStore.getCurrentUser(), profiles: JSON.parse(JSON.stringify(profiles))});
} }
isAtBottom() { isAtBottom() {
// consider the view to be at the bottom if it's within this many pixels of the bottom // consider the view to be at the bottom if it's within this many pixels of the bottom

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

@@ -43,7 +43,7 @@ class NotificationStoreClass extends EventEmitter {
if (notifyLevel === 'none') { if (notifyLevel === 'none') {
return; return;
} else if (notifyLevel === 'mention' && mentions.indexOf(user.id) === -1 && channel.type !== Constants.DM_CHANNEL) { } else if (notifyLevel === 'mention' && mentions.indexOf(user.id) === -1 && msgProps.channel_type !== Constants.DM_CHANNEL) {
return; return;
} }

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

@@ -111,7 +111,7 @@ class UserStoreClass extends EventEmitter {
} }
hasProfile(userId) { hasProfile(userId) {
return this.getProfiles()[userId] != null; return this.getProfile(userId) != null;
} }
getProfile(userId) { getProfile(userId) {