summaryrefslogtreecommitdiffstats
path: root/webapp/actions/user_actions.jsx
diff options
context:
space:
mode:
Diffstat (limited to 'webapp/actions/user_actions.jsx')
-rw-r--r--webapp/actions/user_actions.jsx193
1 files changed, 137 insertions, 56 deletions
diff --git a/webapp/actions/user_actions.jsx b/webapp/actions/user_actions.jsx
index cf5241511..0f6ac3e9f 100644
--- a/webapp/actions/user_actions.jsx
+++ b/webapp/actions/user_actions.jsx
@@ -225,63 +225,150 @@ function populateDMChannelsWithProfiles(userIds) {
}
}
+function populateChannelWithProfiles(channelId, userIds) {
+ for (let i = 0; i < userIds.length; i++) {
+ UserStore.saveUserIdInChannel(channelId, userIds[i]);
+ }
+ UserStore.emitInChannelChange();
+}
+
export function loadNewDMIfNeeded(userId) {
if (userId === UserStore.getCurrentId()) {
return;
}
- const pref = PreferenceStore.get(Preferences.CATEGORY_DIRECT_CHANNEL_SHOW, userId, 'false');
- if (pref === 'false') {
+ const pref = PreferenceStore.getBool(Preferences.CATEGORY_DIRECT_CHANNEL_SHOW, userId, false);
+ if (pref === false) {
PreferenceStore.setPreference(Preferences.CATEGORY_DIRECT_CHANNEL_SHOW, userId, 'true');
AsyncClient.savePreference(Preferences.CATEGORY_DIRECT_CHANNEL_SHOW, userId, 'true');
- loadProfilesAndTeamMembersForDMSidebar();
+ loadProfilesForDM();
}
}
-export function loadProfilesAndTeamMembersForDMSidebar() {
- const dmPrefs = PreferenceStore.getCategory(Preferences.CATEGORY_DIRECT_CHANNEL_SHOW);
- const teamId = TeamStore.getCurrentId();
- const profilesToLoad = [];
- const membersToLoad = [];
+export function loadNewGMIfNeeded(channelId, userId) {
+ if (userId === UserStore.getCurrentId()) {
+ return;
+ }
- for (const [key, value] of dmPrefs) {
- if (value === 'true') {
- if (!UserStore.hasProfile(key)) {
- profilesToLoad.push(key);
- }
- membersToLoad.push(key);
+ function checkPreference() {
+ const pref = PreferenceStore.getBool(Preferences.CATEGORY_GROUP_CHANNEL_SHOW, channelId, false);
+ if (pref === false) {
+ PreferenceStore.setPreference(Preferences.CATEGORY_GROUP_CHANNEL_SHOW, channelId, 'true');
+ AsyncClient.savePreference(Preferences.CATEGORY_GROUP_CHANNEL_SHOW, channelId, 'true');
+ loadProfilesForGM();
}
}
- const channelMembers = ChannelStore.getMyMembers();
+ const channel = ChannelStore.get(channelId);
+ if (channel) {
+ checkPreference();
+ } else {
+ Client.getChannel(
+ channelId,
+ (data) => {
+ AppDispatcher.handleServerAction({
+ type: ActionTypes.RECEIVED_CHANNEL,
+ channel: data.channel,
+ member: data.member
+ });
+
+ checkPreference();
+ },
+ (err) => {
+ AsyncClient.dispatchError(err, 'getChannel');
+ }
+ );
+ }
+}
+
+export function loadProfilesForSidebar() {
+ loadProfilesForDM();
+ loadProfilesForGM();
+}
+
+export function loadProfilesForGM() {
const channels = ChannelStore.getChannels();
const newPreferences = [];
+
for (let i = 0; i < channels.length; i++) {
const channel = channels[i];
- if (channel.type !== Constants.DM_CHANNEL) {
+ if (channel.type !== Constants.GM_CHANNEL) {
continue;
}
- const member = channelMembers[channel.id];
- if (!member) {
+ if (UserStore.getProfileListInChannel(channel.id).length >= Constants.MIN_USERS_IN_GM) {
continue;
}
- const teammateId = channel.name.replace(member.user_id, '').replace('__', '');
+ const isVisible = PreferenceStore.getBool(Preferences.CATEGORY_GROUP_CHANNEL_SHOW, channel.id);
+
+ if (!isVisible) {
+ const member = ChannelStore.getMyMember(channel.id);
+ if (!member || (member.mention_count === 0 && member.msg_count < member.total_msg_count)) {
+ continue;
+ }
+
+ newPreferences.push({
+ user_id: UserStore.getCurrentId(),
+ category: Preferences.CATEGORY_GROUP_CHANNEL_SHOW,
+ name: channel.id,
+ value: 'true'
+ });
+ }
+
+ Client.getProfilesInChannel(
+ channel.id,
+ 0,
+ Constants.MAX_USERS_IN_GM,
+ (data) => {
+ AppDispatcher.handleServerAction({
+ type: ActionTypes.RECEIVED_PROFILES,
+ profiles: data
+ });
+
+ populateChannelWithProfiles(channel.id, Object.keys(data));
+ }
+ );
+ }
+
+ if (newPreferences.length > 0) {
+ AsyncClient.savePreferences(newPreferences);
+ }
+}
+
+export function loadProfilesForDM() {
+ const channels = ChannelStore.getChannels();
+ const newPreferences = [];
+ const profilesToLoad = [];
+ const profileIds = [];
+
+ for (let i = 0; i < channels.length; i++) {
+ const channel = channels[i];
+ if (channel.type !== Constants.DM_CHANNEL) {
+ continue;
+ }
+
+ const teammateId = channel.name.replace(UserStore.getCurrentId(), '').replace('__', '');
+ const isVisible = PreferenceStore.getBool(Preferences.CATEGORY_DIRECT_CHANNEL_SHOW, teammateId);
+
+ if (!isVisible) {
+ const member = ChannelStore.getMyMember(channel.id);
+ if (!member || member.mention_count === 0) {
+ continue;
+ }
- if (member.mention_count > 0 && membersToLoad.indexOf(teammateId) === -1) {
- membersToLoad.push(teammateId);
newPreferences.push({
user_id: UserStore.getCurrentId(),
category: Preferences.CATEGORY_DIRECT_CHANNEL_SHOW,
name: teammateId,
value: 'true'
});
+ }
- if (!UserStore.hasProfile(teammateId)) {
- profilesToLoad.push(teammateId);
- }
+ if (!UserStore.hasProfile(teammateId)) {
+ profilesToLoad.push(teammateId);
}
+ profileIds.push(teammateId);
}
if (newPreferences.length > 0) {
@@ -298,44 +385,14 @@ export function loadProfilesAndTeamMembersForDMSidebar() {
});
// Use membersToLoad so we get all the DM profiles even if they were already loaded
- populateDMChannelsWithProfiles(membersToLoad);
+ populateDMChannelsWithProfiles(profileIds);
},
(err) => {
AsyncClient.dispatchError(err, 'getProfilesByIds');
}
);
} else {
- populateDMChannelsWithProfiles(membersToLoad);
- }
-
- if (membersToLoad.length > 0) {
- Client.getTeamMembersByIds(
- teamId,
- membersToLoad,
- (data) => {
- const memberMap = {};
- for (let i = 0; i < data.length; i++) {
- memberMap[data[i].user_id] = data[i];
- }
-
- const nonMembersMap = {};
- for (let i = 0; i < membersToLoad.length; i++) {
- if (!memberMap[membersToLoad[i]]) {
- nonMembersMap[membersToLoad[i]] = true;
- }
- }
-
- AppDispatcher.handleServerAction({
- type: ActionTypes.RECEIVED_MEMBERS_IN_TEAM,
- team_id: teamId,
- team_members: memberMap,
- non_team_members: nonMembersMap
- });
- },
- (err) => {
- AsyncClient.dispatchError(err, 'getTeamMembersByIds');
- }
- );
+ populateDMChannelsWithProfiles(profileIds);
}
}
@@ -801,3 +858,27 @@ export function uploadProfileImage(userPicture, success, error) {
}
);
}
+
+export function loadProfiles(offset = UserStore.getPagingOffset(), limit = Constants.PROFILE_CHUNK_SIZE, success, error) {
+ Client.getProfiles(
+ offset,
+ limit,
+ (data) => {
+ AppDispatcher.handleServerAction({
+ type: ActionTypes.RECEIVED_PROFILES,
+ profiles: data
+ });
+
+ if (success) {
+ success(data);
+ }
+ },
+ (err) => {
+ AsyncClient.dispatchError(err, 'getProfiles');
+
+ if (error) {
+ error(err);
+ }
+ }
+ );
+}