summaryrefslogtreecommitdiffstats
path: root/webapp/stores/user_store.jsx
diff options
context:
space:
mode:
Diffstat (limited to 'webapp/stores/user_store.jsx')
-rw-r--r--webapp/stores/user_store.jsx107
1 files changed, 107 insertions, 0 deletions
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) {