diff options
Diffstat (limited to 'webapp/stores')
-rw-r--r-- | webapp/stores/team_store.jsx | 10 | ||||
-rw-r--r-- | webapp/stores/user_store.jsx | 107 |
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) { |