summaryrefslogtreecommitdiffstats
path: root/webapp/stores
diff options
context:
space:
mode:
authorGeorge Goldberg <george@gberg.me>2017-04-04 20:17:15 +0100
committerChristopher Speller <crspeller@gmail.com>2017-04-04 15:17:15 -0400
commit1fa3f2351c98e4d1b9c198e357d90ac0d436dcaa (patch)
tree23ff5a64041ed6aa1dc6b7a1db85b85972b2ec66 /webapp/stores
parent77a76487a8e15084c8b5e8e350eb8dc7a87455ea (diff)
downloadchat-1fa3f2351c98e4d1b9c198e357d90ac0d436dcaa.tar.gz
chat-1fa3f2351c98e4d1b9c198e357d90ac0d436dcaa.tar.bz2
chat-1fa3f2351c98e4d1b9c198e357d90ac0d436dcaa.zip
PLT-6023: Add Users to Team in WebApp. (#5956)
* PLT-6198: Use added to channel system message on default channels. Use a different sytem message when a user was added to a default channel by someone else than when they joined themselves. * PLT-6023: Add Users to Team in WebApp. * Fix string text. * Handle added_to_team websocket message. * Fix unread flag on new channel.
Diffstat (limited to 'webapp/stores')
-rw-r--r--webapp/stores/team_store.jsx10
-rw-r--r--webapp/stores/user_store.jsx107
2 files changed, 117 insertions, 0 deletions
diff --git a/webapp/stores/team_store.jsx b/webapp/stores/team_store.jsx
index 6f81a9345..a77527d37 100644
--- a/webapp/stores/team_store.jsx
+++ b/webapp/stores/team_store.jsx
@@ -252,6 +252,12 @@ class TeamStoreClass extends EventEmitter {
}
}
+ removeMemberNotInTeam(teamId = this.getCurrentId(), userId) {
+ if (this.members_not_in_team[teamId]) {
+ Reflect.deleteProperty(this.members_not_in_team[teamId], userId);
+ }
+ }
+
getMembersInTeam(teamId = this.getCurrentId()) {
return Object.assign({}, this.members_in_team[teamId]) || {};
}
@@ -365,6 +371,10 @@ TeamStore.dispatchToken = AppDispatcher.register((payload) => {
TeamStore.saveMyTeam(action.team);
TeamStore.emitChange();
break;
+ case ActionTypes.RECEIVED_TEAM:
+ TeamStore.saveTeam(action.team);
+ TeamStore.emitChange();
+ break;
case ActionTypes.CREATED_TEAM:
TeamStore.saveTeam(action.team);
TeamStore.appendMyTeamMember(action.member);
diff --git a/webapp/stores/user_store.jsx b/webapp/stores/user_store.jsx
index 6f4acae0a..02adeb789 100644
--- a/webapp/stores/user_store.jsx
+++ b/webapp/stores/user_store.jsx
@@ -15,6 +15,7 @@ const UserStatuses = Constants.UserStatuses;
const CHANGE_EVENT_NOT_IN_CHANNEL = 'change_not_in_channel';
const CHANGE_EVENT_IN_CHANNEL = 'change_in_channel';
+const CHANGE_EVENT_NOT_IN_TEAM = 'change_not_in_team';
const CHANGE_EVENT_IN_TEAM = 'change_in_team';
const CHANGE_EVENT_WITHOUT_TEAM = 'change_without_team';
const CHANGE_EVENT = 'change';
@@ -37,6 +38,11 @@ class UserStoreClass extends EventEmitter {
this.paging_count = 0;
// Lists of sorted IDs for users in a team
+ this.profiles_not_in_team = {};
+ this.not_in_team_offset = 0;
+ this.not_in_team_count = 0;
+
+ // Lists of sorted IDs for users in a team
this.profiles_in_team = {};
this.in_team_offset = 0;
this.in_team_count = 0;
@@ -85,6 +91,18 @@ class UserStoreClass extends EventEmitter {
this.removeListener(CHANGE_EVENT_IN_TEAM, callback);
}
+ emitNotInTeamChange() {
+ this.emit(CHANGE_EVENT_NOT_IN_TEAM);
+ }
+
+ addNotInTeamChangeListener(callback) {
+ this.on(CHANGE_EVENT_NOT_IN_TEAM, callback);
+ }
+
+ removeNotInTeamChangeListener(callback) {
+ this.removeListener(CHANGE_EVENT_NOT_IN_TEAM, callback);
+ }
+
emitInChannelChange() {
this.emit(CHANGE_EVENT_IN_CHANNEL);
}
@@ -373,6 +391,75 @@ class UserStoreClass extends EventEmitter {
userIds.splice(index, 1);
}
+ // Not In Team Profiles
+
+ saveProfilesNotInTeam(teamId, profiles) {
+ const oldProfileList = this.profiles_not_in_team[teamId] || [];
+ const oldProfileMap = {};
+ for (let i = 0; i < oldProfileList.length; i++) {
+ oldProfileMap[oldProfileList[i]] = this.getProfile(oldProfileList[i]);
+ }
+
+ const newProfileMap = Object.assign({}, oldProfileMap, profiles);
+ const newProfileList = Object.keys(newProfileMap);
+
+ newProfileList.sort((a, b) => {
+ const aProfile = newProfileMap[a];
+ const bProfile = newProfileMap[b];
+
+ if (aProfile.username < bProfile.username) {
+ return -1;
+ }
+ if (aProfile.username > bProfile.username) {
+ return 1;
+ }
+ return 0;
+ });
+
+ this.profiles_not_in_team[teamId] = newProfileList;
+ this.saveProfiles(profiles);
+ }
+
+ removeProfileNotInTeam(teamId, userId) {
+ const userIds = this.profiles_not_in_team[teamId];
+ if (!userIds) {
+ return;
+ }
+
+ const index = userIds.indexOf(userId);
+ if (index === -1) {
+ return;
+ }
+
+ userIds.splice(index, 1);
+ }
+
+ getProfileListNotInTeam(teamId = TeamStore.getCurrentId(), skipCurrent = false, skipInactive = false) {
+ const userIds = this.profiles_not_in_team[teamId] || [];
+ const profiles = [];
+ const currentId = this.getCurrentId();
+
+ for (let i = 0; i < userIds.length; i++) {
+ const profile = this.getProfile(userIds[i]);
+
+ if (!profile) {
+ continue;
+ }
+
+ if (skipCurrent && profile.id === currentId) {
+ continue;
+ }
+
+ if (skipInactive && profile.delete_at > 0) {
+ continue;
+ }
+
+ profiles.push(profile);
+ }
+
+ return profiles;
+ }
+
// Channel-Wide Profiles
saveProfilesInChannel(channelId = ChannelStore.getCurrentId(), profiles) {
@@ -646,6 +733,19 @@ class UserStoreClass extends EventEmitter {
return this.in_team_count;
}
+ setNotInTeamPage(offset, count) {
+ this.not_in_team_offset = offset + count;
+ this.not_in_team_count = this.not_in_team_count + count;
+ }
+
+ getNotInTeamPagingOffset() {
+ return this.not_in_team_offset;
+ }
+
+ getNotInTeamPagingCount() {
+ return this.not_in_team_count;
+ }
+
setInChannelPage(channelId, offset, count) {
this.in_channel_offset[channelId] = offset + count;
this.in_channel_count[channelId] = this.dm_paging_count + count;
@@ -694,6 +794,13 @@ UserStore.dispatchToken = AppDispatcher.register((payload) => {
}
UserStore.emitInTeamChange();
break;
+ case ActionTypes.RECEIVED_PROFILES_NOT_IN_TEAM:
+ UserStore.saveProfilesNotInTeam(action.team_id, action.profiles);
+ if (action.offset != null && action.count != null) {
+ UserStore.setNotInTeamPage(action.offset, action.count);
+ }
+ UserStore.emitNotInTeamChange();
+ break;
case ActionTypes.RECEIVED_PROFILES_IN_CHANNEL:
UserStore.saveProfilesInChannel(action.channel_id, action.profiles);
if (action.offset != null && action.count != null) {