summaryrefslogtreecommitdiffstats
path: root/webapp/actions
diff options
context:
space:
mode:
authorGeorge Goldberg <george@gberg.me>2017-01-15 15:40:43 +0000
committerJoram Wilander <jwawilander@gmail.com>2017-01-15 10:40:43 -0500
commit95251258f513d076c99da164e607dae5c39b9275 (patch)
treef221aa0da7fde86153f0258c70d00aea2412db43 /webapp/actions
parent2010f74a21bdc0a4838aed0268bf07dc131e410b (diff)
downloadchat-95251258f513d076c99da164e607dae5c39b9275.tar.gz
chat-95251258f513d076c99da164e607dae5c39b9275.tar.bz2
chat-95251258f513d076c99da164e607dae5c39b9275.zip
PLT-5049 (Webapp) New Channel Members UI. (#5036)
This replaces the existing Channel Members UI with one based on the Team Members UI, so that either a button, a role or a role with a menu can be displayed. Basic logic for which actions and roles are displayed is implemented, although this doesn't change behaviour or functionality at all, as that will come in later PRs. It does, however, add code to fetch the ChannelMember objects as that is necessary to provide the full set of actions and roles as intended.
Diffstat (limited to 'webapp/actions')
-rw-r--r--webapp/actions/channel_actions.jsx3
-rw-r--r--webapp/actions/user_actions.jsx108
2 files changed, 111 insertions, 0 deletions
diff --git a/webapp/actions/channel_actions.jsx b/webapp/actions/channel_actions.jsx
index 71f5abf84..6cf8449f0 100644
--- a/webapp/actions/channel_actions.jsx
+++ b/webapp/actions/channel_actions.jsx
@@ -108,6 +108,9 @@ export function removeUserFromChannel(channelId, userId, success, error) {
}
UserStore.emitInChannelChange();
+ ChannelStore.removeMemberInChannel(channelId, userId);
+ ChannelStore.emitChange();
+
if (success) {
success(data);
}
diff --git a/webapp/actions/user_actions.jsx b/webapp/actions/user_actions.jsx
index a5cef65d8..588e77a0d 100644
--- a/webapp/actions/user_actions.jsx
+++ b/webapp/actions/user_actions.jsx
@@ -58,6 +58,34 @@ export function loadProfilesAndTeamMembers(offset, limit, teamId = TeamStore.get
);
}
+export function loadProfilesAndTeamMembersAndChannelMembers(offset, limit, teamId = TeamStore.getCurrentId(), channelId = ChannelStore.getCurrentId(), success, error) {
+ Client.getProfilesInChannel(
+ channelId,
+ offset,
+ limit,
+ (data) => {
+ AppDispatcher.handleServerAction({
+ type: ActionTypes.RECEIVED_PROFILES_IN_CHANNEL,
+ profiles: data,
+ channel_id: channelId,
+ offset,
+ count: Object.keys(data).length
+ });
+
+ loadTeamMembersForProfilesMap(
+ data,
+ teamId,
+ () => {
+ loadChannelMembersForProfilesMap(data, channelId, success, error);
+ loadStatusesForProfilesMap(data);
+ });
+ },
+ (err) => {
+ AsyncClient.dispatchError(err, 'getProfilesInChannel');
+ }
+ );
+}
+
export function loadTeamMembersForProfilesMap(profiles, teamId = TeamStore.getCurrentId(), success, error) {
const membersToLoad = {};
for (const pid in profiles) {
@@ -132,6 +160,86 @@ function loadTeamMembersForProfiles(userIds, teamId, success, error) {
);
}
+export function loadChannelMembersForProfilesMap(profiles, channelId = ChannelStore.getCurrentId(), success, error) {
+ const membersToLoad = {};
+ for (const pid in profiles) {
+ if (!profiles.hasOwnProperty(pid)) {
+ continue;
+ }
+
+ if (!ChannelStore.hasActiveMemberInChannel(channelId, pid)) {
+ membersToLoad[pid] = true;
+ }
+ }
+
+ const list = Object.keys(membersToLoad);
+ if (list.length === 0) {
+ if (success) {
+ success({});
+ }
+ return;
+ }
+
+ loadChannelMembersForProfiles(list, channelId, success, error);
+}
+
+export function loadTeamMembersAndChannelMembersForProfilesList(profiles, teamId = TeamStore.getCurrentId(), channelId = ChannelStore.getCurrentId(), success, error) {
+ loadTeamMembersForProfilesList(profiles, teamId, () => {
+ loadChannelMembersForProfilesList(profiles, channelId, success, error);
+ }, error);
+}
+
+export function loadChannelMembersForProfilesList(profiles, channelId = ChannelStore.getCurrentId(), success, error) {
+ const membersToLoad = {};
+ for (let i = 0; i < profiles.length; i++) {
+ const pid = profiles[i].id;
+
+ if (!ChannelStore.hasActiveMemberInChannel(channelId, pid)) {
+ membersToLoad[pid] = true;
+ }
+ }
+
+ const list = Object.keys(membersToLoad);
+ if (list.length === 0) {
+ if (success) {
+ success({});
+ }
+ return;
+ }
+
+ loadChannelMembersForProfiles(list, channelId, success, error);
+}
+
+function loadChannelMembersForProfiles(userIds, channelId, success, error) {
+ Client.getChannelMembersByIds(
+ channelId,
+ userIds,
+ (data) => {
+ const memberMap = {};
+ for (let i = 0; i < data.length; i++) {
+ memberMap[data[i].user_id] = data[i];
+ }
+
+ AppDispatcher.handleServerAction({
+ type: ActionTypes.RECEIVED_MEMBERS_IN_CHANNEL,
+ channel_id: channelId,
+ channel_members: memberMap
+ });
+
+ if (success) {
+ success(data);
+ }
+ },
+ (err) => {
+ AsyncClient.dispatchError(err, 'getChannelMembersByIds');
+
+ if (error) {
+ error(err);
+ }
+ }
+ );
+}
+
function populateDMChannelsWithProfiles(userIds) {
const currentUserId = UserStore.getCurrentId();