diff options
author | George Goldberg <george@gberg.me> | 2017-01-15 15:40:43 +0000 |
---|---|---|
committer | Joram Wilander <jwawilander@gmail.com> | 2017-01-15 10:40:43 -0500 |
commit | 95251258f513d076c99da164e607dae5c39b9275 (patch) | |
tree | f221aa0da7fde86153f0258c70d00aea2412db43 /webapp/stores/channel_store.jsx | |
parent | 2010f74a21bdc0a4838aed0268bf07dc131e410b (diff) | |
download | chat-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/stores/channel_store.jsx')
-rw-r--r-- | webapp/stores/channel_store.jsx | 49 |
1 files changed, 48 insertions, 1 deletions
diff --git a/webapp/stores/channel_store.jsx b/webapp/stores/channel_store.jsx index c93edf7f4..c1922d3a6 100644 --- a/webapp/stores/channel_store.jsx +++ b/webapp/stores/channel_store.jsx @@ -5,6 +5,7 @@ import AppDispatcher from '../dispatcher/app_dispatcher.jsx'; import EventEmitter from 'events'; import TeamStore from 'stores/team_store.jsx'; +import UserStore from 'stores/user_store.jsx'; var Utils; import {ActionTypes, Constants} from 'utils/constants.jsx'; @@ -25,6 +26,7 @@ class ChannelStoreClass extends EventEmitter { this.currentId = null; this.postMode = this.POST_MODE_CHANNEL; this.channels = []; + this.members_in_channel = {}; this.myChannelMembers = {}; this.moreChannels = {}; this.stats = {}; @@ -241,6 +243,29 @@ class ChannelStoreClass extends EventEmitter { return this.myChannelMembers; } + saveMembersInChannel(channelId = this.getCurrentId(), members) { + const oldMembers = this.members_in_channel[channelId] || {}; + this.members_in_channel[channelId] = Object.assign({}, oldMembers, members); + } + + removeMemberInChannel(channelId = this.getCurrentId(), userId) { + if (this.members_in_channel[channelId]) { + Reflect.deleteProperty(this.members_in_channel[channelId], userId); + } + } + + getMembersInChannel(channelId = this.getCurrentId()) { + return Object.assign({}, this.members_in_channel[channelId]) || {}; + } + + hasActiveMemberInChannel(channelId = this.getCurrentId(), userId) { + if (this.members_in_channel[channelId] && this.members_in_channel[channelId][userId]) { + return true; + } + + return false; + } + storeMoreChannels(channels, teamId = TeamStore.getCurrentId()) { const newChannels = {}; for (let i = 0; i < channels.length; i++) { @@ -343,6 +368,25 @@ class ChannelStoreClass extends EventEmitter { return channelNamesMap; } + + isChannelAdminForCurrentChannel() { + return this.isChannelAdmin(UserStore.getCurrentId(), this.getCurrentId()); + } + + isChannelAdmin(userId, channelId) { + if (!Utils) { + Utils = require('utils/utils.jsx'); //eslint-disable-line global-require + } + + const channelMembers = this.getMembersInChannel(channelId); + const channelMember = channelMembers[userId]; + + if (channelMember) { + return Utils.isChannelAdmin(channelMember.roles); + } + + return false; + } } var ChannelStore = new ChannelStoreClass(); @@ -409,7 +453,10 @@ ChannelStore.dispatchToken = AppDispatcher.register((payload) => { ChannelStore.storeMoreChannels(action.channels); ChannelStore.emitChange(); break; - + case ActionTypes.RECEIVED_MEMBERS_IN_CHANNEL: + ChannelStore.saveMembersInChannel(action.channel_id, action.channel_members); + ChannelStore.emitChange(); + break; case ActionTypes.RECEIVED_CHANNEL_STATS: var stats = Object.assign({}, ChannelStore.getStats()); stats[action.stats.channel_id] = action.stats; |