summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoram Wilander <jwawilander@gmail.com>2016-05-06 08:06:34 -0400
committerChristopher Speller <crspeller@gmail.com>2016-05-06 08:06:34 -0400
commitd75cb0294896e0e45f280cbccde8581376d501ce (patch)
tree0d82a1d959945aa2a2e73633233d9c681212f209
parent4b2843ee9d513a6b464e1e581e9cee8baaaa4317 (diff)
downloadchat-d75cb0294896e0e45f280cbccde8581376d501ce.tar.gz
chat-d75cb0294896e0e45f280cbccde8581376d501ce.tar.bz2
chat-d75cb0294896e0e45f280cbccde8581376d501ce.zip
Multiple cross-team functionality fixes (#2902)
-rw-r--r--api/channel.go6
-rw-r--r--api/channel_test.go5
-rw-r--r--store/sql_channel_store.go7
-rw-r--r--webapp/action_creators/global_actions.jsx2
-rw-r--r--webapp/components/posts_view.jsx13
-rw-r--r--webapp/stores/notification_store.jsx2
-rw-r--r--webapp/stores/user_store.jsx2
7 files changed, 27 insertions, 10 deletions
diff --git a/api/channel.go b/api/channel.go
index b034e94ba..7cfc22833 100644
--- a/api/channel.go
+++ b/api/channel.go
@@ -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 {
- return nil, result.Err
+ if result.Err.Id == store.CHANNEL_EXISTS_ERROR {
+ return result.Data.(*model.Channel), nil
+ } else {
+ return nil, result.Err
+ }
} else {
return result.Data.(*model.Channel), nil
}
diff --git a/api/channel_test.go b/api/channel_test.go
index 31b201346..69902c3ad 100644
--- a/api/channel_test.go
+++ b/api/channel_test.go
@@ -113,8 +113,9 @@ func TestCreateDirectChannel(t *testing.T) {
t.Fatal("channel type was not direct")
}
- if _, err := Client.CreateDirectChannel(th.BasicUser2.Id); err == nil {
- t.Fatal("channel already exists and should have failed")
+ // don't fail on direct channels already existing
+ if _, err := Client.CreateDirectChannel(th.BasicUser2.Id); err != nil {
+ t.Fatal(err)
}
if _, err := Client.CreateDirectChannel("junk"); err == nil {
diff --git a/store/sql_channel_store.go b/store/sql_channel_store.go
index 6d549c7f0..9f9d86454 100644
--- a/store/sql_channel_store.go
+++ b/store/sql_channel_store.go
@@ -13,6 +13,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"
+ CHANNEL_EXISTS_ERROR = "store.sql_channel.save_channel.exists.app_error"
)
type SqlChannelStore struct {
@@ -102,6 +103,7 @@ func (s SqlChannelStore) SaveDirectChannel(directchannel *model.Channel, member1
if channelResult.Err != nil {
transaction.Rollback()
result.Err = channelResult.Err
+ result.Data = channelResult.Data
} else {
newChannel := channelResult.Data.(*model.Channel)
// Members need new channel ID
@@ -167,9 +169,10 @@ func (s SqlChannelStore) saveChannelT(transaction *gorp.Transaction, channel *mo
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})
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 {
- 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 {
result.Err = model.NewLocAppError("SqlChannelStore.Save", "store.sql_channel.save_channel.save.app_error", nil, "id="+channel.Id+", "+err.Error())
diff --git a/webapp/action_creators/global_actions.jsx b/webapp/action_creators/global_actions.jsx
index 78c56dd12..c1bb4dbc8 100644
--- a/webapp/action_creators/global_actions.jsx
+++ b/webapp/action_creators/global_actions.jsx
@@ -234,7 +234,7 @@ export function emitPostRecievedEvent(post, msg) {
} else {
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);
}
diff --git a/webapp/components/posts_view.jsx b/webapp/components/posts_view.jsx
index 3cc0c1a92..4a81feba2 100644
--- a/webapp/components/posts_view.jsx
+++ b/webapp/components/posts_view.jsx
@@ -47,13 +47,18 @@ export default class PostsView extends React.Component {
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 = {
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,
isScrolling: false,
topPostId: null,
currentUser: UserStore.getCurrentUser(),
- profiles: UserStore.getProfiles()
+ profiles
};
}
static get SCROLL_TYPE_FREE() {
@@ -78,7 +83,11 @@ export default class PostsView extends React.Component {
});
}
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() {
// consider the view to be at the bottom if it's within this many pixels of the bottom
diff --git a/webapp/stores/notification_store.jsx b/webapp/stores/notification_store.jsx
index 6722af281..7d7039780 100644
--- a/webapp/stores/notification_store.jsx
+++ b/webapp/stores/notification_store.jsx
@@ -43,7 +43,7 @@ class NotificationStoreClass extends EventEmitter {
if (notifyLevel === 'none') {
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;
}
diff --git a/webapp/stores/user_store.jsx b/webapp/stores/user_store.jsx
index 5a27d15ea..2d792fa17 100644
--- a/webapp/stores/user_store.jsx
+++ b/webapp/stores/user_store.jsx
@@ -111,7 +111,7 @@ class UserStoreClass extends EventEmitter {
}
hasProfile(userId) {
- return this.getProfiles()[userId] != null;
+ return this.getProfile(userId) != null;
}
getProfile(userId) {