From d8bd57901e33a7057e26e782e295099ffcc0da89 Mon Sep 17 00:00:00 2001 From: Christopher Speller Date: Wed, 6 Sep 2017 23:04:13 -0700 Subject: Removing webapp --- webapp/stores/analytics_store.jsx | 58 ---- webapp/stores/browser_store.jsx | 208 ------------ webapp/stores/channel_store.jsx | 585 -------------------------------- webapp/stores/emoji_store.jsx | 206 ----------- webapp/stores/error_store.jsx | 110 ------ webapp/stores/integration_store.jsx | 103 ------ webapp/stores/localization_store.jsx | 60 ---- webapp/stores/message_history_store.jsx | 79 ----- webapp/stores/modal_store.jsx | 56 --- webapp/stores/notification_store.jsx | 45 --- webapp/stores/opengraph_store.jsx | 68 ---- webapp/stores/post_store.jsx | 242 ------------- webapp/stores/preference_store.jsx | 181 ---------- webapp/stores/redux_store.jsx | 19 -- webapp/stores/search_store.jsx | 230 ------------- webapp/stores/suggestion_store.jsx | 329 ------------------ webapp/stores/team_store.jsx | 470 ------------------------- webapp/stores/user_store.jsx | 515 ---------------------------- webapp/stores/user_typing_store.jsx | 108 ------ webapp/stores/webrtc_store.jsx | 110 ------ 20 files changed, 3782 deletions(-) delete mode 100644 webapp/stores/analytics_store.jsx delete mode 100644 webapp/stores/browser_store.jsx delete mode 100644 webapp/stores/channel_store.jsx delete mode 100644 webapp/stores/emoji_store.jsx delete mode 100644 webapp/stores/error_store.jsx delete mode 100644 webapp/stores/integration_store.jsx delete mode 100644 webapp/stores/localization_store.jsx delete mode 100644 webapp/stores/message_history_store.jsx delete mode 100644 webapp/stores/modal_store.jsx delete mode 100644 webapp/stores/notification_store.jsx delete mode 100644 webapp/stores/opengraph_store.jsx delete mode 100644 webapp/stores/post_store.jsx delete mode 100644 webapp/stores/preference_store.jsx delete mode 100644 webapp/stores/redux_store.jsx delete mode 100644 webapp/stores/search_store.jsx delete mode 100644 webapp/stores/suggestion_store.jsx delete mode 100644 webapp/stores/team_store.jsx delete mode 100644 webapp/stores/user_store.jsx delete mode 100644 webapp/stores/user_typing_store.jsx delete mode 100644 webapp/stores/webrtc_store.jsx (limited to 'webapp/stores') diff --git a/webapp/stores/analytics_store.jsx b/webapp/stores/analytics_store.jsx deleted file mode 100644 index 63c8a5bee..000000000 --- a/webapp/stores/analytics_store.jsx +++ /dev/null @@ -1,58 +0,0 @@ -// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved. -// See License.txt for license information. - -import EventEmitter from 'events'; - -const CHANGE_EVENT = 'change'; - -import store from 'stores/redux_store.jsx'; - -class AnalyticsStoreClass extends EventEmitter { - constructor() { - super(); - - this.entities = {}; - - store.subscribe(() => { - const newEntities = store.getState().entities.admin; - - if (newEntities.analytics !== this.entities.analytics) { - this.emitChange(); - } - - if (newEntities.teamAnalytics !== this.entities.teamAnalytics) { - this.emitChange(); - } - - this.entities = newEntities; - }); - } - - emitChange() { - this.emit(CHANGE_EVENT); - } - - addChangeListener(callback) { - this.on(CHANGE_EVENT, callback); - } - - removeChangeListener(callback) { - this.removeListener(CHANGE_EVENT, callback); - } - - getAllSystem() { - return JSON.parse(JSON.stringify(store.getState().entities.admin.analytics)); - } - - getAllTeam(id) { - const teamStats = store.getState().entities.admin.teamAnalytics[id]; - if (teamStats) { - return JSON.parse(JSON.stringify(teamStats)); - } - - return {}; - } -} - -var AnalyticsStore = new AnalyticsStoreClass(); -export default AnalyticsStore; diff --git a/webapp/stores/browser_store.jsx b/webapp/stores/browser_store.jsx deleted file mode 100644 index a7c5294cd..000000000 --- a/webapp/stores/browser_store.jsx +++ /dev/null @@ -1,208 +0,0 @@ -// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. -// See License.txt for license information. - -import {browserHistory} from 'react-router/es6'; -import * as Utils from 'utils/utils.jsx'; -import {Constants, ErrorPageTypes} from 'utils/constants.jsx'; - -function getPrefix() { - if (global.mm_user) { - return global.mm_user.id + '_'; - } - - console.warn('BrowserStore tried to operate without user present'); //eslint-disable-line no-console - - return 'unknown_'; -} - -class BrowserStoreClass { - constructor() { - this.hasCheckedLocalStorage = false; - this.localStorageSupported = false; - } - - setItem(name, value) { - this.setGlobalItem(getPrefix() + name, value); - } - - getItem(name, defaultValue) { - return this.getGlobalItem(getPrefix() + name, defaultValue); - } - - removeItem(name) { - this.removeGlobalItem(getPrefix() + name); - } - - setGlobalItem(name, value) { - try { - if (this.isLocalStorageSupported()) { - localStorage.setItem(name, JSON.stringify(value)); - } else { - sessionStorage.setItem(name, JSON.stringify(value)); - } - } catch (err) { - console.log('An error occurred while setting local storage, clearing all props'); //eslint-disable-line no-console - localStorage.clear(); - sessionStorage.clear(); - window.location.reload(true); - } - } - - getGlobalItem(name, defaultValue = null) { - var result = null; - - try { - if (this.isLocalStorageSupported()) { - result = JSON.parse(localStorage.getItem(name)); - } else { - result = JSON.parse(sessionStorage.getItem(name)); - } - } catch (err) { - result = null; - } - - if (typeof result === 'undefined' || result === null) { - result = defaultValue; - } - - return result; - } - - removeGlobalItem(name) { - if (this.isLocalStorageSupported()) { - localStorage.removeItem(name); - } else { - sessionStorage.removeItem(name); - } - } - - signalLogout() { - if (this.isLocalStorageSupported()) { - // PLT-1285 store an identifier in session storage so we can catch if the logout came from this tab on IE11 - const logoutId = Utils.generateId(); - - sessionStorage.setItem('__logout__', logoutId); - localStorage.setItem('__logout__', logoutId); - localStorage.removeItem('__logout__'); - } - } - - isSignallingLogout(logoutId) { - return logoutId === sessionStorage.getItem('__logout__'); - } - - signalLogin() { - if (this.isLocalStorageSupported()) { - // PLT-1285 store an identifier in session storage so we can catch if the logout came from this tab on IE11 - const loginId = Utils.generateId(); - - sessionStorage.setItem('__login__', loginId); - localStorage.setItem('__login__', loginId); - localStorage.removeItem('__login__'); - } - } - - isSignallingLogin(loginId) { - return loginId === sessionStorage.getItem('__login__'); - } - - /** - * Preforms the given action on each item that has the given prefix - * Signature for action is action(key, value) - */ - actionOnGlobalItemsWithPrefix(prefix, action) { - var storage = sessionStorage; - if (this.isLocalStorageSupported()) { - storage = localStorage; - } - - for (var key in storage) { - if (key.lastIndexOf(prefix, 0) === 0) { - action(key, this.getGlobalItem(key)); - } - } - } - - actionOnItemsWithPrefix(prefix, action) { - var globalPrefix = getPrefix(); - var globalPrefixiLen = globalPrefix.length; - for (var key in sessionStorage) { - if (key.lastIndexOf(globalPrefix + prefix, 0) === 0) { - var userkey = key.substring(globalPrefixiLen); - action(userkey, this.getGlobalItem(key)); - } - } - } - - clear() { - // persist some values through logout since they're independent of which user is logged in - const logoutId = sessionStorage.getItem('__logout__'); - const landingPageSeen = this.hasSeenLandingPage(); - const selectedTeams = this.getItem('selected_teams'); - const recentEmojis = localStorage.getItem(Constants.RECENT_EMOJI_KEY); - - sessionStorage.clear(); - localStorage.clear(); - - if (recentEmojis) { - localStorage.setItem(Constants.RECENT_EMOJI_KEY, recentEmojis); - } - - if (logoutId) { - sessionStorage.setItem('__logout__', logoutId); - } - - if (landingPageSeen) { - this.setLandingPageSeen(landingPageSeen); - } - - if (selectedTeams) { - this.setItem('selected_teams', selectedTeams); - } - } - - isLocalStorageSupported() { - if (this.hasCheckedLocalStorage) { - return this.localStorageSupported; - } - - this.localStorageSupported = false; - - try { - localStorage.setItem('__testLocal__', '1'); - if (localStorage.getItem('__testLocal__') === '1') { - this.localStorageSupported = true; - } - localStorage.removeItem('__testLocal__', '1'); - } catch (e) { - this.localStorageSupported = false; - } - - try { - sessionStorage.setItem('__testSession__', '1'); - sessionStorage.removeItem('__testSession__'); - } catch (e) { - // Session storage not usable, website is unusable - browserHistory.push('/error?type=' + ErrorPageTypes.LOCAL_STORAGE); - } - - this.hasCheckedLocalStorage = true; - - return this.localStorageSupported; - } - - hasSeenLandingPage() { - if (this.isLocalStorageSupported()) { - return JSON.parse(sessionStorage.getItem('__landingPageSeen__')); - } - - return true; - } - - setLandingPageSeen(landingPageSeen) { - return sessionStorage.setItem('__landingPageSeen__', JSON.stringify(landingPageSeen)); - } -} - -var BrowserStore = new BrowserStoreClass(); -export default BrowserStore; diff --git a/webapp/stores/channel_store.jsx b/webapp/stores/channel_store.jsx deleted file mode 100644 index 1ffad280f..000000000 --- a/webapp/stores/channel_store.jsx +++ /dev/null @@ -1,585 +0,0 @@ -// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. -// See License.txt for license information. - -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 ChannelUtils; -var Utils; -import {ActionTypes, Constants} from 'utils/constants.jsx'; -import {isSystemMessage, isFromWebhook} from 'utils/post_utils.jsx'; -const NotificationPrefs = Constants.NotificationPrefs; - -const CHANGE_EVENT = 'change'; -const STATS_EVENT = 'stats'; -const LAST_VIEVED_EVENT = 'last_viewed'; - -import store from 'stores/redux_store.jsx'; -import * as Selectors from 'mattermost-redux/selectors/entities/channels'; -import {ChannelTypes, UserTypes} from 'mattermost-redux/action_types'; -import {batchActions} from 'redux-batched-actions'; - -class ChannelStoreClass extends EventEmitter { - constructor(props) { - super(props); - this.setMaxListeners(600); - this.clear(); - - this.entities = store.getState().entities.channels; - - store.subscribe(() => { - const newEntities = store.getState().entities.channels; - let doEmit = false; - - if (newEntities.currentChannelId !== this.entities.currentChannelId) { - doEmit = true; - } - if (newEntities.channels !== this.entities.channels) { - this.setUnreadCountsByChannels(Object.values(newEntities.channels)); - doEmit = true; - } - if (newEntities.myMembers !== this.entities.myMembers) { - this.setUnreadCountsByMembers(Object.values(newEntities.myMembers)); - this.emitLastViewed(); - doEmit = true; - } - if (newEntities.membersInChannel !== this.entities.membersInChannel) { - doEmit = true; - } - if (newEntities.stats !== this.entities.stats) { - this.emitStatsChange(); - } - - if (doEmit) { - this.emitChange(); - } - - this.entities = newEntities; - }); - } - - clear() { - this.postMode = this.POST_MODE_CHANNEL; - this.unreadCounts = {}; - } - - get POST_MODE_CHANNEL() { - return 1; - } - - get POST_MODE_FOCUS() { - return 2; - } - - emitChange() { - this.emit(CHANGE_EVENT); - } - - addChangeListener(callback) { - this.on(CHANGE_EVENT, callback); - } - - removeChangeListener(callback) { - this.removeListener(CHANGE_EVENT, callback); - } - - emitStatsChange() { - this.emit(STATS_EVENT); - } - - addStatsChangeListener(callback) { - this.on(STATS_EVENT, callback); - } - - removeStatsChangeListener(callback) { - this.removeListener(STATS_EVENT, callback); - } - - emitLastViewed() { - this.emit(LAST_VIEVED_EVENT); - } - - addLastViewedListener(callback) { - this.on(LAST_VIEVED_EVENT, callback); - } - - removeLastViewedListener(callback) { - this.removeListener(LAST_VIEVED_EVENT, callback); - } - - findFirstBy(field, value) { - return this.doFindFirst(field, value, this.getChannels()); - } - - findFirstMoreBy(field, value) { - return this.doFindFirst(field, value, this.getMoreChannels()); - } - - doFindFirst(field, value, channels) { - for (var i = 0; i < channels.length; i++) { - if (channels[i][field] === value) { - return channels[i]; - } - } - - return null; - } - - get(id) { - return this.findFirstBy('id', id); - } - - getMyMember(id) { - return this.getMyMembers()[id]; - } - - getByName(name) { - return this.findFirstBy('name', name); - } - - getByDisplayName(displayName) { - return this.findFirstBy('display_name', displayName); - } - - getMoreByName(name) { - return this.findFirstMoreBy('name', name); - } - - getAll() { - return this.getChannels(); - } - - getMoreAll() { - return this.getMoreChannels(); - } - - setCurrentId(id) { - store.dispatch({ - type: ChannelTypes.SELECT_CHANNEL, - data: id, - member: this.getMyMember(id) - }); - } - - resetCounts(ids) { - const membersToStore = []; - ids.forEach((id) => { - const member = this.getMyMember(id); - const channel = this.get(id); - if (member && channel) { - const memberToStore = {...member}; - memberToStore.msg_count = channel.total_msg_count; - memberToStore.mention_count = 0; - membersToStore.push(memberToStore); - this.setUnreadCountByChannel(id); - } - }); - - this.storeMyChannelMembersList(membersToStore); - } - - getCurrentId() { - return Selectors.getCurrentChannelId(store.getState()); - } - - getCurrent() { - var currentId = this.getCurrentId(); - - if (currentId) { - return this.get(currentId); - } - - return null; - } - - getCurrentMember() { - var currentId = this.getCurrentId(); - - if (currentId) { - return this.getMyMembers()[currentId]; - } - - return null; - } - - getCurrentStats() { - return this.getStats(this.getCurrentId()); - } - - getStats(channelId) { - let stats; - - if (channelId) { - stats = Selectors.getAllChannelStats(store.getState())[channelId]; - } - - if (stats) { - // create a defensive copy - stats = Object.assign({}, stats); - } else { - stats = {member_count: 0}; - } - - return stats; - } - - storeChannel(channel) { - var channels = this.getChannels(); - var found; - - for (var i = 0; i < channels.length; i++) { - if (channels[i].id === channel.id) { - channels[i] = channel; - found = true; - break; - } - } - - if (!found) { - channels.push(channel); - } - - if (!ChannelUtils) { - ChannelUtils = require('utils/channel_utils.jsx'); //eslint-disable-line global-require - } - - channels = channels.sort(ChannelUtils.sortChannelsByDisplayName); - this.storeChannels(channels); - } - - storeChannels(channels) { - store.dispatch({ - type: ChannelTypes.RECEIVED_CHANNELS, - data: channels, - teamId: channels[0].team_id - }); - } - - getChannels() { - return Selectors.getMyChannels(store.getState()); - } - - getChannelById(id) { - return this.get(id); - } - - storeMyChannelMember(channelMember) { - store.dispatch({ - type: ChannelTypes.RECEIVED_MY_CHANNEL_MEMBER, - data: channelMember - }); - } - - storeMyChannelMembers(channelMembers) { - store.dispatch({ - type: ChannelTypes.RECEIVED_MY_CHANNEL_MEMBERS, - data: Object.values(channelMembers) - }); - } - - storeMyChannelMembersList(channelMembers) { - store.dispatch({ - type: ChannelTypes.RECEIVED_MY_CHANNEL_MEMBERS, - data: channelMembers - }); - } - - getMyMembers() { - return Selectors.getMyChannelMemberships(store.getState()); - } - - saveMembersInChannel(channelId = this.getCurrentId(), members) { - store.dispatch({ - type: ChannelTypes.RECEIVED_CHANNEL_MEMBERS, - data: Object.values(members) - }); - } - - removeMemberInChannel(channelId = this.getCurrentId(), userId) { - store.dispatch({ - type: UserTypes.RECEIVED_PROFILE_NOT_IN_CHANNEL, - data: {id: channelId, user_id: userId} - }); - } - - getMembersInChannel(channelId = this.getCurrentId()) { - return Selectors.getChannelMembersInChannels(store.getState())[channelId] || {}; - } - - hasActiveMemberInChannel(channelId = this.getCurrentId(), userId) { - const members = this.getMembersInChannel(channelId); - if (members && members[userId]) { - return true; - } - - return false; - } - - storeMoreChannels(channels, teamId = TeamStore.getCurrentId()) { - store.dispatch({ - type: ChannelTypes.RECEIVED_CHANNELS, - data: channels, - teamId - }); - } - - getMoreChannels() { - const channels = Selectors.getOtherChannels(store.getState()); - const channelMap = {}; - channels.forEach((c) => { - channelMap[c.id] = c; - }); - return channelMap; - } - - getMoreChannelsList() { - return Selectors.getOtherChannels(store.getState()); - } - - isDefault(channel) { - return channel.name === Constants.DEFAULT_CHANNEL; - } - - setPostMode(mode) { - this.postMode = mode; - } - - getPostMode() { - return this.postMode; - } - - setUnreadCountsByMembers(members) { - members.forEach((m) => { - this.setUnreadCountByChannel(m.channel_id); - }); - } - - setUnreadCountsByCurrentMembers() { - Object.keys(this.getMyMembers()).forEach((key) => { - this.setUnreadCountByChannel(this.getMyMember(key).channel_id); - }); - } - - setUnreadCountsByChannels(channels) { - channels.forEach((c) => { - this.setUnreadCountByChannel(c.id); - }); - } - - setUnreadCountByChannel(id) { - const ch = this.get(id); - const chMember = this.getMyMember(id); - - if (ch == null || chMember == null) { - return; - } - - const chMentionCount = chMember.mention_count; - let chUnreadCount = ch.total_msg_count - chMember.msg_count; - - if (chMember.notify_props && chMember.notify_props.mark_unread === NotificationPrefs.MENTION) { - chUnreadCount = 0; - } - - this.unreadCounts[id] = {msgs: chUnreadCount, mentions: chMentionCount}; - } - - getUnreadCount(id) { - return this.unreadCounts[id] || {msgs: 0, mentions: 0}; - } - - getUnreadCounts() { - return this.unreadCounts; - } - - getChannelNamesMap() { - var channelNamesMap = {}; - - var channels = this.getChannels(); - for (var key in channels) { - if (channels.hasOwnProperty(key)) { - var channel = channels[key]; - channelNamesMap[channel.name] = channel; - } - } - - var moreChannels = this.getMoreChannels(); - for (var moreKey in moreChannels) { - if (moreChannels.hasOwnProperty(moreKey)) { - var moreChannel = moreChannels[moreKey]; - channelNamesMap[moreChannel.name] = moreChannel; - } - } - - return channelNamesMap; - } - - isChannelAdminForCurrentChannel() { - if (!Utils) { - Utils = require('utils/utils.jsx'); //eslint-disable-line global-require - } - - const member = this.getMyMember(this.getCurrentId()); - - if (!member) { - return false; - } - - return Utils.isChannelAdmin(member.roles); - } - - 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; - } - - incrementMessages(id, markRead = false) { - if (!this.unreadCounts[id]) { - // Should never happen - console.log(`Missing channel_id=${id} in unreads object`); //eslint-disable-line no-console - } - - const member = this.getMyMember(id); - if (member && member.notify_props && member.notify_props.mark_unread === NotificationPrefs.MENTION) { - return; - } - - const channel = {...this.get(id)}; - channel.total_msg_count++; - - const actions = []; - if (markRead) { - actions.push({ - type: ChannelTypes.RECEIVED_MY_CHANNEL_MEMBER, - data: {...member, msg_count: channel.total_msg_count} - }); - } - - actions.push( - { - type: ChannelTypes.RECEIVED_CHANNEL, - data: channel - } - ); - store.dispatch(batchActions(actions)); - } - - incrementMentionsIfNeeded(id, msgProps) { - let mentions = []; - if (msgProps && msgProps.mentions) { - mentions = JSON.parse(msgProps.mentions); - } - - if (!this.unreadCounts[id]) { - // Should never happen - console.log(`Missing channel_id=${id} in unreads object`); //eslint-disable-line no-console - } - - if (mentions.indexOf(UserStore.getCurrentId()) !== -1) { - const member = {...this.getMyMember(id)}; - member.mention_count++; - store.dispatch({ - type: ChannelTypes.RECEIVED_MY_CHANNEL_MEMBER, - data: member - }); - } - } -} - -var ChannelStore = new ChannelStoreClass(); - -ChannelStore.dispatchToken = AppDispatcher.register((payload) => { - var action = payload.action; - - switch (action.type) { - case ActionTypes.CLICK_CHANNEL: - ChannelStore.setCurrentId(action.id); - ChannelStore.setPostMode(ChannelStore.POST_MODE_CHANNEL); - break; - - case ActionTypes.RECEIVED_FOCUSED_POST: { - const post = action.post_list.posts[action.postId]; - ChannelStore.setCurrentId(post.channel_id); - ChannelStore.setPostMode(ChannelStore.POST_MODE_FOCUS); - ChannelStore.emitChange(); - break; - } - - case ActionTypes.RECEIVED_CHANNELS: - ChannelStore.storeChannels(action.channels); - break; - - case ActionTypes.RECEIVED_CHANNEL: - ChannelStore.storeChannel(action.channel); - if (action.member) { - ChannelStore.storeMyChannelMember(action.member); - } - break; - - case ActionTypes.RECEIVED_MY_CHANNEL_MEMBERS: - ChannelStore.storeMyChannelMembersList(action.members); - break; - case ActionTypes.RECEIVED_CHANNEL_MEMBER: - ChannelStore.storeMyChannelMember(action.member); - break; - case ActionTypes.RECEIVED_MORE_CHANNELS: - ChannelStore.storeMoreChannels(action.channels); - break; - case ActionTypes.RECEIVED_MEMBERS_IN_CHANNEL: - ChannelStore.saveMembersInChannel(action.channel_id, action.channel_members); - break; - case ActionTypes.RECEIVED_CHANNEL_STATS: - store.dispatch({ - type: ChannelTypes.RECEIVED_CHANNEL_STATS, - data: action.stats - }); - break; - - case ActionTypes.RECEIVED_POST: - if (Constants.IGNORE_POST_TYPES.indexOf(action.post.type) !== -1) { - return; - } - - if (action.post.user_id === UserStore.getCurrentId() && !isSystemMessage(action.post) && !isFromWebhook(action.post)) { - return; - } - - var id = action.post.channel_id; - var teamId = action.websocketMessageProps ? action.websocketMessageProps.team_id : null; - var markRead = id === ChannelStore.getCurrentId() && window.isActive; - - if (TeamStore.getCurrentId() === teamId || teamId === '') { - if (!markRead) { - ChannelStore.incrementMentionsIfNeeded(id, action.websocketMessageProps); - } - ChannelStore.incrementMessages(id, markRead); - } - break; - - case ActionTypes.CREATE_POST: - ChannelStore.incrementMessages(action.post.channel_id, true); - break; - - case ActionTypes.CREATE_COMMENT: - ChannelStore.incrementMessages(action.post.channel_id, true); - break; - - default: - break; - } -}); - -export default ChannelStore; diff --git a/webapp/stores/emoji_store.jsx b/webapp/stores/emoji_store.jsx deleted file mode 100644 index 0ec3468ff..000000000 --- a/webapp/stores/emoji_store.jsx +++ /dev/null @@ -1,206 +0,0 @@ -// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved. -// See License.txt for license information. - -import AppDispatcher from 'dispatcher/app_dispatcher.jsx'; -import Constants from 'utils/constants.jsx'; -import EventEmitter from 'events'; -import * as Emoji from 'utils/emoji.jsx'; - -import store from 'stores/redux_store.jsx'; -import {getCustomEmojisByName} from 'mattermost-redux/selectors/entities/emojis'; -import {Client4} from 'mattermost-redux/client'; - -const ActionTypes = Constants.ActionTypes; - -const CHANGE_EVENT = 'changed'; -const MAXIMUM_RECENT_EMOJI = 27; - -// Wrap the contents of the store so that we don't need to construct an ES6 map where most of the content -// (the system emojis) will never change. It provides the get/has functions of a map and an iterator so -// that it can be used in for..of loops -export class EmojiMap { - constructor(customEmojis) { - this.customEmojis = customEmojis; - - // Store customEmojis to an array so we can iterate it more easily - this.customEmojisArray = [...customEmojis]; - } - - has(name) { - return Emoji.EmojiIndicesByAlias.has(name) || this.customEmojis.has(name); - } - - get(name) { - if (Emoji.EmojiIndicesByAlias.has(name)) { - return Emoji.Emojis[Emoji.EmojiIndicesByAlias.get(name)]; - } - - return this.customEmojis.get(name); - } - - [Symbol.iterator]() { - const customEmojisArray = this.customEmojisArray; - - return { - systemIndex: 0, - customIndex: 0, - next() { - if (this.systemIndex < Emoji.Emojis.length) { - const emoji = Emoji.Emojis[this.systemIndex]; - - this.systemIndex += 1; - - return {value: [emoji.aliases[0], emoji]}; - } - - if (this.customIndex < customEmojisArray.length) { - const emoji = customEmojisArray[this.customIndex][1]; - - this.customIndex += 1; - - return {value: [emoji.name, emoji]}; - } - - return {done: true}; - } - }; - } -} - -class EmojiStore extends EventEmitter { - constructor() { - super(); - - this.dispatchToken = AppDispatcher.register(this.handleEventPayload.bind(this)); - - this.setMaxListeners(600); - - this.map = new EmojiMap(getCustomEmojisByName(store.getState())); - - this.entities = {}; - - store.subscribe(() => { - const newEntities = store.getState().entities.emojis.customEmoji; - - if (newEntities !== this.entities) { - this.map = new EmojiMap(getCustomEmojisByName(store.getState())); - this.emitChange(); - } - - this.entities = newEntities; - }); - } - - addChangeListener(callback) { - this.on(CHANGE_EVENT, callback); - } - - removeChangeListener(callback) { - this.removeListener(CHANGE_EVENT, callback); - } - - emitChange() { - this.emit(CHANGE_EVENT); - } - - hasSystemEmoji(name) { - return Emoji.EmojiIndicesByAlias.has(name); - } - - getCustomEmojiMap() { - return getCustomEmojisByName(store.getState()); - } - - getEmojis() { - return this.map; - } - - has(name) { - return this.map.has(name); - } - - get(name) { - return this.map.get(name); - } - - addRecentEmoji(alias) { - const recentEmojis = this.getRecentEmojis(); - - let name; - const emoji = this.get(alias); - if (!emoji) { - return; - } else if (emoji.name) { - name = emoji.name; - } else { - name = emoji.aliases[0]; - } - - const index = recentEmojis.indexOf(name); - if (index !== -1) { - recentEmojis.splice(index, 1); - } - - recentEmojis.push(name); - - if (recentEmojis.length > MAXIMUM_RECENT_EMOJI) { - recentEmojis.splice(0, recentEmojis.length - MAXIMUM_RECENT_EMOJI); - } - - localStorage.setItem(Constants.RECENT_EMOJI_KEY, JSON.stringify(recentEmojis)); - } - - getRecentEmojis() { - let recentEmojis; - try { - recentEmojis = JSON.parse(localStorage.getItem(Constants.RECENT_EMOJI_KEY)); - } catch (e) { - // Errors are handled below - } - - if (!recentEmojis) { - return []; - } - - if (recentEmojis.length > 0 && typeof recentEmojis[0] === 'object') { - // Prior to PLT-7267, recent emojis were stored with the entire object for the emoji, but this - // has been changed to store only the names of the emojis, so we need to change that - recentEmojis = recentEmojis.map((emoji) => { - return emoji.name || emoji.aliases[0]; - }); - } - - return recentEmojis; - } - - hasUnicode(codepoint) { - return Emoji.EmojiIndicesByUnicode.has(codepoint); - } - - getUnicode(codepoint) { - return Emoji.Emojis[Emoji.EmojiIndicesByUnicode.get(codepoint)]; - } - - getEmojiImageUrl(emoji) { - if (emoji.id) { - return Client4.getUrlVersion() + '/emoji/' + emoji.id + '/image'; - } - - const filename = emoji.filename || emoji.aliases[0]; - - return Constants.EMOJI_PATH + '/' + filename + '.png'; - } - - handleEventPayload(payload) { - const action = payload.action; - - switch (action.type) { - case ActionTypes.EMOJI_POSTED: - this.addRecentEmoji(action.alias); - this.emitChange(); - break; - } - } -} - -export default new EmojiStore(); diff --git a/webapp/stores/error_store.jsx b/webapp/stores/error_store.jsx deleted file mode 100644 index 38f5eb249..000000000 --- a/webapp/stores/error_store.jsx +++ /dev/null @@ -1,110 +0,0 @@ -// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. -// See License.txt for license information. - -import AppDispatcher from '../dispatcher/app_dispatcher.jsx'; -import EventEmitter from 'events'; - -import Constants from 'utils/constants.jsx'; -const ActionTypes = Constants.ActionTypes; - -import BrowserStore from 'stores/browser_store.jsx'; - -const CHANGE_EVENT = 'change'; - -class ErrorStoreClass extends EventEmitter { - constructor() { - super(); - - this.emitChange = this.emitChange.bind(this); - this.addChangeListener = this.addChangeListener.bind(this); - this.removeChangeListener = this.removeChangeListener.bind(this); - this.getLastError = this.getLastError.bind(this); - this.storeLastError = this.storeLastError.bind(this); - this.getIgnoreNotification = this.getIgnoreNotification.bind(this); - this.ignore_notification = false; - } - - getIgnoreNotification() { - return this.ignore_notification; - } - - emitChange() { - this.emit(CHANGE_EVENT); - } - - addChangeListener(callback) { - this.on(CHANGE_EVENT, callback); - } - - removeChangeListener(callback) { - this.removeListener(CHANGE_EVENT, callback); - } - - getLastError() { - return BrowserStore.getGlobalItem('last_error'); - } - - storeLastError(error) { - BrowserStore.setGlobalItem('last_error', error); - } - - getConnectionErrorCount() { - var count = BrowserStore.getGlobalItem('last_error_conn'); - - if (count == null) { - return 0; - } - - return count; - } - - setConnectionErrorCount(count) { - BrowserStore.setGlobalItem('last_error_conn', count); - } - - clearError(message) { - const lastError = this.getLastError(); - - if (lastError && lastError.message === message) { - this.clearLastError(true); - } - } - - clearLastError(force) { - var lastError = this.getLastError(); - - // preview message can only be cleared by clearNotificationError - if (!force && lastError && lastError.notification) { - return; - } - - BrowserStore.removeGlobalItem('last_error'); - BrowserStore.removeGlobalItem('last_error_conn'); - if (lastError) { - this.emitChange(); - } - } - - clearNotificationError() { - this.ignore_notification = true; - this.storeLastError(''); - this.clearLastError(); - } -} - -var ErrorStore = new ErrorStoreClass(); - -ErrorStore.dispatchToken = AppDispatcher.register((payload) => { - var action = payload.action; - switch (action.type) { - case ActionTypes.RECEIVED_ERROR: - ErrorStore.storeLastError(action.err); - ErrorStore.emitChange(); - break; - - default: - } -}); - -export default ErrorStore; -window.ErrorStore = ErrorStore; diff --git a/webapp/stores/integration_store.jsx b/webapp/stores/integration_store.jsx deleted file mode 100644 index f1e86d881..000000000 --- a/webapp/stores/integration_store.jsx +++ /dev/null @@ -1,103 +0,0 @@ -// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved. -// See License.txt for license information. - -import EventEmitter from 'events'; - -const CHANGE_EVENT = 'changed'; - -import store from 'stores/redux_store.jsx'; - -class IntegrationStore extends EventEmitter { - constructor() { - super(); - - this.entities = {}; - - store.subscribe(() => { - const newEntities = store.getState().entities.integrations; - if (newEntities !== this.entities) { - this.emitChange(); - } - - this.entities = newEntities; - }); - } - - addChangeListener(callback) { - this.on(CHANGE_EVENT, callback); - } - - removeChangeListener(callback) { - this.removeListener(CHANGE_EVENT, callback); - } - - emitChange() { - this.emit(CHANGE_EVENT); - } - - hasReceivedIncomingWebhooks(teamId) { - const hooks = store.getState().entities.integrations.incomingHooks || {}; - - let hasTeam = false; - Object.values(hooks).forEach((hook) => { - if (hook.team_id === teamId) { - hasTeam = true; - } - }); - - return hasTeam; - } - - getIncomingWebhooks(teamId) { - const hooks = store.getState().entities.integrations.incomingHooks; - - const teamHooks = []; - Object.values(hooks).forEach((hook) => { - if (hook.team_id === teamId) { - teamHooks.push(hook); - } - }); - - return teamHooks; - } - - hasReceivedOutgoingWebhooks(teamId) { - const hooks = store.getState().entities.integrations.outgoingHooks; - - let hasTeam = false; - Object.values(hooks).forEach((hook) => { - if (hook.team_id === teamId) { - hasTeam = true; - } - }); - - return hasTeam; - } - - getOutgoingWebhooks(teamId) { - const hooks = store.getState().entities.integrations.outgoingHooks; - - const teamHooks = []; - Object.values(hooks).forEach((hook) => { - if (hook.team_id === teamId) { - teamHooks.push(hook); - } - }); - - return teamHooks; - } - - getOutgoingWebhook(teamId, id) { - return store.getState().entities.integrations.outgoingHooks[id]; - } - - hasReceivedOAuthApps() { - return Object.keys(store.getState().entities.integrations.oauthApps).length > 0; - } - - getOAuthApps() { - return Object.values(store.getState().entities.integrations.oauthApps); - } -} - -export default new IntegrationStore(); diff --git a/webapp/stores/localization_store.jsx b/webapp/stores/localization_store.jsx deleted file mode 100644 index 2eb482699..000000000 --- a/webapp/stores/localization_store.jsx +++ /dev/null @@ -1,60 +0,0 @@ -// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. -// See License.txt for license information. - -import AppDispatcher from '../dispatcher/app_dispatcher.jsx'; -import EventEmitter from 'events'; -import Constants from 'utils/constants.jsx'; -const ActionTypes = Constants.ActionTypes; - -const CHANGE_EVENT = 'change'; - -class LocalizationStoreClass extends EventEmitter { - constructor() { - super(); - - this.currentLocale = 'en'; - this.currentTranslations = null; - } - - emitChange() { - this.emit(CHANGE_EVENT); - } - - addChangeListener(callback) { - this.on(CHANGE_EVENT, callback); - } - - removeChangeListener(callback) { - this.removeListener(CHANGE_EVENT, callback); - } - - setCurrentLocale(locale, translations) { - this.currentLocale = locale; - this.currentTranslations = translations; - } - - getLocale() { - return this.currentLocale; - } - - getTranslations() { - return this.currentTranslations; - } -} - -var LocalizationStore = new LocalizationStoreClass(); -LocalizationStore.setMaxListeners(0); - -LocalizationStore.dispatchToken = AppDispatcher.register((payload) => { - var action = payload.action; - - switch (action.type) { - case ActionTypes.RECEIVED_LOCALE: - LocalizationStore.setCurrentLocale(action.locale, action.translations); - LocalizationStore.emitChange(); - break; - default: - } -}); - -export default LocalizationStore; diff --git a/webapp/stores/message_history_store.jsx b/webapp/stores/message_history_store.jsx deleted file mode 100644 index 6c758fb05..000000000 --- a/webapp/stores/message_history_store.jsx +++ /dev/null @@ -1,79 +0,0 @@ -// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved. -// See License.txt for license information. - -import Constants from 'utils/constants.jsx'; - -const TYPE_POST = 'post'; -const TYPE_COMMENT = 'comment'; - -class MessageHistoryStoreClass { - constructor() { - this.messageHistory = []; - this.index = []; - this.index[TYPE_POST] = 0; - this.index[TYPE_COMMENT] = 0; - } - - getMessageInHistory(type) { - if (this.index[type] >= this.messageHistory.length) { - return ''; - } else if (this.index[type] < 0) { - return null; - } - - return this.messageHistory[this.index[type]]; - } - - getHistoryLength() { - if (this.messageHistory === null) { - return 0; - } - return this.messageHistory.length; - } - - storeMessageInHistory(message) { - this.messageHistory.push(message); - this.resetAllHistoryIndex(); - if (this.messageHistory.length > Constants.MAX_PREV_MSGS) { - this.messageHistory = this.messageHistory.slice(1, Constants.MAX_PREV_MSGS + 1); - } - } - - storeMessageInHistoryByIndex(index, message) { - this.messageHistory[index] = message; - } - - resetAllHistoryIndex() { - this.index[TYPE_POST] = this.messageHistory.length; - this.index[TYPE_COMMENT] = this.messageHistory.length; - } - - resetHistoryIndex(type) { - this.index[type] = this.messageHistory.length; - } - - nextMessageInHistory(keyCode, messageText, type) { - if (messageText !== '' && messageText !== this.getMessageInHistory(type)) { - return null; - } - - if (keyCode === Constants.KeyCodes.UP) { - this.index[type]--; - } else if (keyCode === Constants.KeyCodes.DOWN) { - this.index[type]++; - } - - if (this.index[type] < 0) { - this.index[type] = 0; - return null; - } else if (this.index[type] >= this.getHistoryLength()) { - this.index[type] = this.getHistoryLength(); - } - - return this.getMessageInHistory(type); - } -} - -var MessageHistoryStore = new MessageHistoryStoreClass(); - -export default MessageHistoryStore; diff --git a/webapp/stores/modal_store.jsx b/webapp/stores/modal_store.jsx deleted file mode 100644 index c47095d05..000000000 --- a/webapp/stores/modal_store.jsx +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. -// See License.txt for license information. - -import AppDispatcher from '../dispatcher/app_dispatcher.jsx'; -import EventEmitter from 'events'; - -import Constants from 'utils/constants.jsx'; -const ActionTypes = Constants.ActionTypes; - -class ModalStoreClass extends EventEmitter { - constructor() { - super(); - - this.addModalListener = this.addModalListener.bind(this); - this.removeModalListener = this.removeModalListener.bind(this); - - this.handleEventPayload = this.handleEventPayload.bind(this); - this.dispatchToken = AppDispatcher.register(this.handleEventPayload); - } - - addModalListener(action, callback) { - this.on(action, callback); - } - - removeModalListener(action, callback) { - this.removeListener(action, callback); - } - - handleEventPayload(payload) { - // toggle event handlers should accept a boolean show/hide value and can accept a map of arguments - const {type, value, ...args} = payload.action; //eslint-disable-line no-use-before-define - - switch (type) { - case ActionTypes.TOGGLE_ACCOUNT_SETTINGS_MODAL: - case ActionTypes.TOGGLE_SHORTCUTS_MODAL: - case ActionTypes.TOGGLE_IMPORT_THEME_MODAL: - case ActionTypes.TOGGLE_INVITE_MEMBER_MODAL: - case ActionTypes.TOGGLE_LEAVE_TEAM_MODAL: - case ActionTypes.TOGGLE_DELETE_POST_MODAL: - case ActionTypes.TOGGLE_GET_POST_LINK_MODAL: - case ActionTypes.TOGGLE_GET_TEAM_INVITE_LINK_MODAL: - case ActionTypes.TOGGLE_GET_PUBLIC_LINK_MODAL: - case ActionTypes.TOGGLE_DM_MODAL: - case ActionTypes.TOGGLE_QUICK_SWITCH_MODAL: - case ActionTypes.TOGGLE_CHANNEL_HEADER_UPDATE_MODAL: - case ActionTypes.TOGGLE_CHANNEL_PURPOSE_UPDATE_MODAL: - case ActionTypes.TOGGLE_CHANNEL_NAME_UPDATE_MODAL: - case ActionTypes.TOGGLE_LEAVE_PRIVATE_CHANNEL_MODAL: - this.emit(type, value, args); - break; - } - } -} - -const ModalStore = new ModalStoreClass(); -export default ModalStore; diff --git a/webapp/stores/notification_store.jsx b/webapp/stores/notification_store.jsx deleted file mode 100644 index 27259bbdd..000000000 --- a/webapp/stores/notification_store.jsx +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved. -// See License.txt for license information. - -import AppDispatcher from '../dispatcher/app_dispatcher.jsx'; -import EventEmitter from 'events'; -import Constants from 'utils/constants.jsx'; -const ActionTypes = Constants.ActionTypes; - -const CHANGE_EVENT = 'change'; - -class NotificationStoreClass extends EventEmitter { - emitChange() { - this.emit(CHANGE_EVENT); - } - - addChangeListener(callback) { - this.on(CHANGE_EVENT, callback); - } - - removeChangeListener(callback) { - this.removeListener(CHANGE_EVENT, callback); - } - - setFocus(focus) { - this.inFocus = focus; - } - - getFocus() { - return this.inFocus; - } -} - -var NotificationStore = new NotificationStoreClass(); - -NotificationStore.dispatchToken = AppDispatcher.register((payload) => { - const action = payload.action; - - switch (action.type) { - case ActionTypes.BROWSER_CHANGE_FOCUS: - NotificationStore.setFocus(action.focus); - break; - } -}); - -export default NotificationStore; diff --git a/webapp/stores/opengraph_store.jsx b/webapp/stores/opengraph_store.jsx deleted file mode 100644 index 4ad156df0..000000000 --- a/webapp/stores/opengraph_store.jsx +++ /dev/null @@ -1,68 +0,0 @@ -import EventEmitter from 'events'; - -import AppDispatcher from 'dispatcher/app_dispatcher.jsx'; -import Constants from 'utils/constants.jsx'; - -const ActionTypes = Constants.ActionTypes; - -const CHANGE_EVENT = 'change'; -const URL_DATA_CHANGE_EVENT = 'url_data_change'; - -class OpenGraphStoreClass extends EventEmitter { - constructor() { - super(); - this.ogDataObject = {}; // Format: {: } - } - - emitChange() { - this.emit(CHANGE_EVENT); - } - - addChangeListener(callback) { - this.on(CHANGE_EVENT, callback); - } - - removeChangeListener(callback) { - this.removeListener(CHANGE_EVENT, callback); - } - - emitUrlDataChange(url) { - this.emit(URL_DATA_CHANGE_EVENT, url); - } - - addUrlDataChangeListener(callback) { - this.on(URL_DATA_CHANGE_EVENT, callback); - } - - removeUrlDataChangeListener(callback) { - this.removeListener(URL_DATA_CHANGE_EVENT, callback); - } - - storeOgInfo(url, ogInfo) { - this.ogDataObject[url] = ogInfo; - } - - getOgInfo(url) { - return this.ogDataObject[url]; - } -} - -var OpenGraphStore = new OpenGraphStoreClass(); - -// Not expecting more that `Constants.POST_CHUNK_SIZE` post previews rendered at a time -OpenGraphStore.setMaxListeners(Constants.POST_CHUNK_SIZE); - -OpenGraphStore.dispatchToken = AppDispatcher.register((payload) => { - var action = payload.action; - - switch (action.type) { - case ActionTypes.RECIVED_OPEN_GRAPH_METADATA: - OpenGraphStore.storeOgInfo(action.url, action.data); - OpenGraphStore.emitUrlDataChange(action.url); - OpenGraphStore.emitChange(); - break; - default: - } -}); - -export default OpenGraphStore; diff --git a/webapp/stores/post_store.jsx b/webapp/stores/post_store.jsx deleted file mode 100644 index a1bdfa4e9..000000000 --- a/webapp/stores/post_store.jsx +++ /dev/null @@ -1,242 +0,0 @@ -// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. -// See License.txt for license information. - -import AppDispatcher from '../dispatcher/app_dispatcher.jsx'; -import EventEmitter from 'events'; - -import ChannelStore from 'stores/channel_store.jsx'; -import BrowserStore from 'stores/browser_store.jsx'; -import UserStore from 'stores/user_store.jsx'; - -import * as PostUtils from 'utils/post_utils.jsx'; -import {Constants} from 'utils/constants.jsx'; -const ActionTypes = Constants.ActionTypes; - -const FOCUSED_POST_CHANGE = 'focused_post_change'; -const EDIT_POST_EVENT = 'edit_post'; -const POST_PINNED_CHANGE_EVENT = 'post_pinned_change'; - -import store from 'stores/redux_store.jsx'; -const dispatch = store.dispatch; -const getState = store.getState; - -import * as Selectors from 'mattermost-redux/selectors/entities/posts'; - -class PostStoreClass extends EventEmitter { - constructor() { - super(); - this.selectedPostId = null; - this.currentFocusedPostId = null; - } - - emitPostFocused() { - this.emit(FOCUSED_POST_CHANGE); - } - - addPostFocusedListener(callback) { - this.on(FOCUSED_POST_CHANGE, callback); - } - - removePostFocusedListener(callback) { - this.removeListener(FOCUSED_POST_CHANGE, callback); - } - - emitEditPost(post) { - this.emit(EDIT_POST_EVENT, post); - } - - addEditPostListener(callback) { - this.on(EDIT_POST_EVENT, callback); - } - - removeEditPostListner(callback) { - this.removeListener(EDIT_POST_EVENT, callback); - } - - emitPostPinnedChange() { - this.emit(POST_PINNED_CHANGE_EVENT); - } - - addPostPinnedChangeListener(callback) { - this.on(POST_PINNED_CHANGE_EVENT, callback); - } - - removePostPinnedChangeListener(callback) { - this.removeListener(POST_PINNED_CHANGE_EVENT, callback); - } - - getLatestPostId(channelId) { - const postsInChannel = getState().entities.posts.postsInChannel[channelId] || []; - return postsInChannel[0]; - } - - getLatestReplyablePost(channelId) { - const postIds = getState().entities.posts.postsInChannel[channelId] || []; - const posts = getState().entities.posts.posts; - - for (const postId of postIds) { - const post = posts[postId] || {}; - if (post.state !== Constants.POST_DELETED && !PostUtils.isSystemMessage(post)) { - return post; - } - } - - return null; - } - - getVisiblePosts() { - const posts = Selectors.getPostsInCurrentChannel(getState()); - const currentChannelId = getState().entities.channels.currentChannelId; - return posts.slice(0, getState().views.channel.postVisibility[currentChannelId]); - } - - getFocusedPostId() { - return this.currentFocusedPostId; - } - - storeFocusedPostId(postId) { - this.currentFocusedPostId = postId; - } - - clearFocusedPost() { - this.currentFocusedPostId = null; - } - - getCurrentUsersLatestPost(channelId, rootId) { - const userId = UserStore.getCurrentId(); - - const postIds = getState().entities.posts.postsInChannel[channelId] || []; - - let lastPost = null; - - for (const id of postIds) { - const post = Selectors.getPost(getState(), id) || {}; - - // don't edit webhook posts, deleted posts, or system messages - if (post.user_id !== userId || - (post.props && post.props.from_webhook) || - post.state === Constants.POST_DELETED || - (post.type && post.type.startsWith(Constants.SYSTEM_MESSAGE_PREFIX))) { - continue; - } - - if (rootId) { - if (post.root_id === rootId || post.id === rootId) { - lastPost = post; - break; - } - } else { - lastPost = post; - break; - } - } - - return lastPost; - } - - normalizeDraft(originalDraft) { - let draft = { - message: '', - uploadsInProgress: [], - fileInfos: [] - }; - - // Make sure that the post draft is non-null and has all the required fields - if (originalDraft) { - draft = { - message: originalDraft.message || draft.message, - uploadsInProgress: originalDraft.uploadsInProgress || draft.uploadsInProgress, - fileInfos: originalDraft.fileInfos || draft.fileInfos - }; - } - - return draft; - } - - storeCurrentDraft(draft) { - var channelId = ChannelStore.getCurrentId(); - BrowserStore.setGlobalItem('draft_' + channelId, draft); - } - - getCurrentDraft() { - var channelId = ChannelStore.getCurrentId(); - return this.getDraft(channelId); - } - - storeDraft(channelId, draft) { - BrowserStore.setGlobalItem('draft_' + channelId, draft); - } - - getDraft(channelId) { - return this.normalizeDraft(BrowserStore.getGlobalItem('draft_' + channelId)); - } - - storeCommentDraft(parentPostId, draft) { - BrowserStore.setGlobalItem('comment_draft_' + parentPostId, draft); - } - - getCommentDraft(parentPostId) { - return this.normalizeDraft(BrowserStore.getGlobalItem('comment_draft_' + parentPostId)); - } - - clearDraftUploads() { - BrowserStore.actionOnGlobalItemsWithPrefix('draft_', (key, value) => { - if (value) { - value.uploadsInProgress = []; - BrowserStore.setGlobalItem(key, value); - } - }); - } - - clearCommentDraftUploads() { - BrowserStore.actionOnGlobalItemsWithPrefix('comment_draft_', (key, value) => { - if (value) { - value.uploadsInProgress = []; - BrowserStore.setGlobalItem(key, value); - } - }); - } - - getCommentCount(rootPost) { - const postIds = getState().entities.posts.postsInChannel[rootPost.channel_id] || []; - - let commentCount = 0; - for (const postId of postIds) { - const post = Selectors.getPost(getState(), postId) || {}; - if (post.root_id === rootPost.id) { - commentCount += 1; - } - } - - return commentCount; - } -} - -var PostStore = new PostStoreClass(); - -PostStore.dispatchToken = AppDispatcher.register((payload) => { - var action = payload.action; - - switch (action.type) { - case ActionTypes.RECEIVED_FOCUSED_POST: - PostStore.storeFocusedPostId(action.postId); - PostStore.emitPostFocused(); - break; - case ActionTypes.CLICK_CHANNEL: - PostStore.clearFocusedPost(); - break; - case ActionTypes.RECEIVED_EDIT_POST: - PostStore.emitEditPost(action); - break; - case ActionTypes.RECEIVED_POST_SELECTED: - dispatch({...action, type: ActionTypes.SELECT_POST}); - break; - case ActionTypes.RECEIVED_POST_PINNED: - case ActionTypes.RECEIVED_POST_UNPINNED: - PostStore.emitPostPinnedChange(); - break; - default: - } -}); - -export default PostStore; diff --git a/webapp/stores/preference_store.jsx b/webapp/stores/preference_store.jsx deleted file mode 100644 index cd8ae68be..000000000 --- a/webapp/stores/preference_store.jsx +++ /dev/null @@ -1,181 +0,0 @@ -// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. -// See License.txt for license information. - -import Constants from 'utils/constants.jsx'; -const ActionTypes = Constants.ActionTypes; -import AppDispatcher from '../dispatcher/app_dispatcher.jsx'; -import EventEmitter from 'events'; - -const CHANGE_EVENT = 'change'; - -import store from 'stores/redux_store.jsx'; -import * as Selectors from 'mattermost-redux/selectors/entities/preferences'; -import {PreferenceTypes} from 'mattermost-redux/action_types'; - -class PreferenceStore extends EventEmitter { - constructor() { - super(); - - this.handleEventPayload = this.handleEventPayload.bind(this); - this.dispatchToken = AppDispatcher.register(this.handleEventPayload); - - this.preferences = new Map(); - this.entities = Selectors.getMyPreferences(store.getState()); - Object.keys(this.entities).forEach((key) => { - this.preferences.set(key, this.entities[key].value); - }); - - store.subscribe(() => { - const newEntities = Selectors.getMyPreferences(store.getState()); - if (this.entities !== newEntities) { - this.preferences = new Map(); - Object.keys(newEntities).forEach((key) => { - this.preferences.set(key, newEntities[key].value); - }); - this.emitChange(); - } - - this.entities = newEntities; - }); - - this.setMaxListeners(600); - } - - getKey(category, name) { - return `${category}--${name}`; - } - - get(category, name, defaultValue = '') { - const key = this.getKey(category, name); - - if (!this.preferences.has(key)) { - return defaultValue; - } - - return this.preferences.get(key); - } - - getBool(category, name, defaultValue = false) { - const key = this.getKey(category, name); - - if (!this.preferences.has(key)) { - return defaultValue; - } - - return this.preferences.get(key) !== 'false'; - } - - getInt(category, name, defaultValue = 0) { - const key = this.getKey(category, name); - - if (!this.preferences.has(key)) { - return defaultValue; - } - - return parseInt(this.preferences.get(key), 10); - } - - getObject(category, name, defaultValue = null) { - const key = this.getKey(category, name); - - if (!this.preferences.has(key)) { - return defaultValue; - } - - return JSON.parse(this.preferences.get(key)); - } - - getCategory(category) { - const prefix = category + '--'; - - const preferences = new Map(); - - for (const [key, value] of this.preferences) { - if (key.startsWith(prefix)) { - preferences.set(key.substring(prefix.length), value); - } - } - - return preferences; - } - - setPreference(category, name, value) { - store.dispatch({ - type: PreferenceTypes.RECEIVED_PREFERENCES, - data: [{category, name, value}] - }); - } - - setPreferencesFromServer(newPreferences) { - store.dispatch({ - type: PreferenceTypes.RECEIVED_PREFERENCES, - data: newPreferences - }); - } - - deletePreference(preference) { - store.dispatch({ - type: PreferenceTypes.DELETED_PREFERENCES, - data: [preference] - }); - } - - emitChange(category) { - this.emit(CHANGE_EVENT, category); - } - - addChangeListener(callback) { - this.on(CHANGE_EVENT, callback); - } - - removeChangeListener(callback) { - this.removeListener(CHANGE_EVENT, callback); - } - - getTheme(teamId) { - if (this.preferences.has(this.getKey(Constants.Preferences.CATEGORY_THEME, teamId))) { - return this.getObject(Constants.Preferences.CATEGORY_THEME, teamId); - } - - if (this.preferences.has(this.getKey(Constants.Preferences.CATEGORY_THEME, ''))) { - return this.getObject(Constants.Preferences.CATEGORY_THEME, ''); - } - - for (const k in Constants.THEMES) { - if (Constants.THEMES.hasOwnProperty(k) && k === global.mm_config.DefaultTheme) { - return Constants.THEMES[k]; - } - } - - return Constants.THEMES.default; - } - - handleEventPayload(payload) { - const action = payload.action; - - switch (action.type) { - case ActionTypes.RECEIVED_PREFERENCE: { - const preference = action.preference; - this.setPreference(preference.category, preference.name, preference.value); - this.emitChange(preference.category); - break; - } - case ActionTypes.RECEIVED_PREFERENCES: - this.setPreferencesFromServer(action.preferences); - this.emitChange(); - break; - case ActionTypes.DELETED_PREFERENCES: - for (const preference of action.preferences) { - this.deletePreference(preference); - } - this.emitChange(); - break; - case ActionTypes.CLICK_CHANNEL: - this.setPreference(action.team_id, 'channel', action.id); - break; - } - } -} - -global.PreferenceStore = new PreferenceStore(); -export default global.PreferenceStore; diff --git a/webapp/stores/redux_store.jsx b/webapp/stores/redux_store.jsx deleted file mode 100644 index de5099d27..000000000 --- a/webapp/stores/redux_store.jsx +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright (c) 2017 Mattermost, Inc. All Rights Reserved. -// See License.txt for license information. - -// This is a temporary store while we are transitioning from Flux to Redux. This file exports -// the configured Redux store for use by actions and selectors. - -import configureStore from 'store'; -const store = configureStore(); - -export function bindActionToRedux(action, ...args) { - return async () => { - await action(...args)(store.dispatch, store.getState); - }; -} - -window.store = store; - -export default store; - diff --git a/webapp/stores/search_store.jsx b/webapp/stores/search_store.jsx deleted file mode 100644 index 7db0ed92a..000000000 --- a/webapp/stores/search_store.jsx +++ /dev/null @@ -1,230 +0,0 @@ -// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. -// See License.txt for license information. - -import AppDispatcher from '../dispatcher/app_dispatcher.jsx'; -import EventEmitter from 'events'; - -import Constants from 'utils/constants.jsx'; -import ChannelStore from 'stores/channel_store.jsx'; - -var ActionTypes = Constants.ActionTypes; - -var CHANGE_EVENT = 'change'; -var SEARCH_CHANGE_EVENT = 'search_change'; -var SEARCH_TERM_CHANGE_EVENT = 'search_term_change'; -var SHOW_SEARCH_EVENT = 'show_search'; - -class SearchStoreClass extends EventEmitter { - constructor() { - super(); - - this.searchResults = null; - this.isMentionSearch = false; - this.isFlaggedPosts = false; - this.isPinnedPosts = false; - this.isVisible = false; - this.searchTerm = ''; - this.loading = false; - } - - emitChange() { - this.emit(CHANGE_EVENT); - } - - addChangeListener(callback) { - this.on(CHANGE_EVENT, callback); - } - - removeChangeListener(callback) { - this.removeListener(CHANGE_EVENT, callback); - } - - emitSearchChange() { - this.emit(SEARCH_CHANGE_EVENT); - } - - addSearchChangeListener(callback) { - this.on(SEARCH_CHANGE_EVENT, callback); - } - - removeSearchChangeListener(callback) { - this.removeListener(SEARCH_CHANGE_EVENT, callback); - } - - emitSearchTermChange(doSearch, isMentionSearch) { - this.emit(SEARCH_TERM_CHANGE_EVENT, doSearch, isMentionSearch); - } - - addSearchTermChangeListener(callback) { - this.on(SEARCH_TERM_CHANGE_EVENT, callback); - } - - removeSearchTermChangeListener(callback) { - this.removeListener(SEARCH_TERM_CHANGE_EVENT, callback); - } - - emitShowSearch() { - this.emit(SHOW_SEARCH_EVENT); - } - - addShowSearchListener(callback) { - this.on(SHOW_SEARCH_EVENT, callback); - } - - removeShowSearchListener(callback) { - this.removeListener(SHOW_SEARCH_EVENT, callback); - } - - getSearchResults() { - return this.searchResults; - } - - getIsMentionSearch() { - return this.isMentionSearch; - } - - getIsFlaggedPosts() { - return this.isFlaggedPosts; - } - - getIsPinnedPosts() { - return this.isPinnedPosts; - } - - storeSearchTerm(term) { - this.searchTerm = term; - } - - getSearchTerm() { - return this.searchTerm; - } - - storeSearchResults(results, isMentionSearch = false, isFlaggedPosts = false, isPinnedPosts = false) { - this.searchResults = results; - this.isMentionSearch = isMentionSearch; - this.isFlaggedPosts = isFlaggedPosts; - this.isPinnedPosts = isPinnedPosts; - } - - deletePost(post) { - const results = this.getSearchResults(); - if (results == null) { - return; - } - - if (post.id in results.posts) { - // make sure to copy the post so that component state changes work properly - results.posts[post.id] = Object.assign({}, post, { - state: Constants.POST_DELETED, - file_ids: [] - }); - } - } - - updatePost(post) { - const results = this.getSearchResults(); - if (!post || results == null) { - return; - } - - if (post.id in results.posts) { - results.posts[post.id] = Object.assign({}, post); - } - } - - togglePinPost(postId, isPinned) { - const results = this.getSearchResults(); - if (results == null || results.posts == null) { - return; - } - - if (postId in results.posts) { - const post = results.posts[postId]; - results.posts[postId] = Object.assign({}, post, { - is_pinned: isPinned - }); - } - } - - removePost(post) { - const results = this.getSearchResults(); - if (results == null) { - return; - } - - const index = results.order.indexOf(post.id); - if (index > -1) { - delete results.posts[post.id]; - results.order.splice(index, 1); - } - } - - setLoading(loading) { - this.loading = loading; - } - - isLoading() { - return this.loading; - } -} - -var SearchStore = new SearchStoreClass(); - -SearchStore.dispatchToken = AppDispatcher.register((payload) => { - var action = payload.action; - - switch (action.type) { - case ActionTypes.RECEIVED_SEARCH: { - const results = SearchStore.getSearchResults() || {}; - const posts = Object.values(results.posts || {}); - const channelId = posts.length > 0 ? posts[0].channel_id : ''; - if (SearchStore.getIsPinnedPosts() === action.is_pinned_posts && - action.is_pinned_posts === true && - channelId !== '' && - ChannelStore.getCurrentId() !== channelId) { - // ignore pin posts update after switch to a new channel - return; - } - SearchStore.setLoading(false); - SearchStore.storeSearchResults(action.results, action.is_mention_search, action.is_flagged_posts, action.is_pinned_posts); - SearchStore.emitSearchChange(); - break; - } - case ActionTypes.RECEIVED_SEARCH_TERM: - if (action.do_search) { - // while a search is in progress, hide results from previous search - SearchStore.setLoading(true); - SearchStore.storeSearchResults(null, false, false, false); - SearchStore.emitSearchChange(); - } - SearchStore.storeSearchTerm(action.term); - SearchStore.emitSearchTermChange(action.do_search, action.is_mention_search); - break; - case ActionTypes.SHOW_SEARCH: - SearchStore.emitShowSearch(); - break; - case ActionTypes.POST_DELETED: - SearchStore.deletePost(action.post); - SearchStore.emitSearchChange(); - break; - case ActionTypes.POST_UPDATED: - SearchStore.updatePost(action.post); - SearchStore.emitSearchChange(); - break; - case ActionTypes.RECEIVED_POST_PINNED: - SearchStore.togglePinPost(action.postId, true); - SearchStore.emitSearchChange(); - break; - case ActionTypes.RECEIVED_POST_UNPINNED: - SearchStore.togglePinPost(action.postId, false); - SearchStore.emitSearchChange(); - break; - case ActionTypes.REMOVE_POST: - SearchStore.removePost(action.post); - SearchStore.emitSearchChange(); - break; - default: - } -}); - -export default SearchStore; diff --git a/webapp/stores/suggestion_store.jsx b/webapp/stores/suggestion_store.jsx deleted file mode 100644 index 902886ed7..000000000 --- a/webapp/stores/suggestion_store.jsx +++ /dev/null @@ -1,329 +0,0 @@ -// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. -// See License.txt for license information. - -import AppDispatcher from 'dispatcher/app_dispatcher.jsx'; -import Constants from 'utils/constants.jsx'; -import EventEmitter from 'events'; - -const ActionTypes = Constants.ActionTypes; - -const COMPLETE_WORD_EVENT = 'complete_word'; -const PRETEXT_CHANGED_EVENT = 'pretext_changed'; -const SUGGESTIONS_CHANGED_EVENT = 'suggestions_changed'; -const POPOVER_MENTION_KEY_CLICK_EVENT = 'popover_mention_key_click'; - -class SuggestionStore extends EventEmitter { - constructor() { - super(); - - this.addSuggestionsChangedListener = this.addSuggestionsChangedListener.bind(this); - this.removeSuggestionsChangedListener = this.removeSuggestionsChangedListener.bind(this); - this.emitSuggestionsChanged = this.emitSuggestionsChanged.bind(this); - - this.addPretextChangedListener = this.addPretextChangedListener.bind(this); - this.removePretextChangedListener = this.removePretextChangedListener.bind(this); - this.emitPretextChanged = this.emitPretextChanged.bind(this); - - this.addCompleteWordListener = this.addCompleteWordListener.bind(this); - this.removeCompleteWordListener = this.removeCompleteWordListener.bind(this); - this.emitCompleteWord = this.emitCompleteWord.bind(this); - - this.addPopoverMentionKeyClickListener = this.addPopoverMentionKeyClickListener.bind(this); - this.removePopoverMentionKeyClickListener = this.removePopoverMentionKeyClickListener.bind(this); - this.emitPopoverMentionKeyClick = this.emitPopoverMentionKeyClick.bind(this); - - this.handleEventPayload = this.handleEventPayload.bind(this); - this.dispatchToken = AppDispatcher.register(this.handleEventPayload); - - // this.suggestions stores the state of all SuggestionBoxes by mapping their unique identifier to an - // object with the following fields: - // pretext: the text before the cursor - // matchedPretext: a list of the text before the cursor that will be replaced if the corresponding autocomplete term is selected - // terms: a list of strings which the previously typed text may be replaced by - // items: a list of objects backing the terms which may be used in rendering - // components: a list of react components that can be used to render their corresponding item - // selection: the term currently selected by the keyboard - this.suggestions = new Map(); - } - - addSuggestionsChangedListener(id, callback) { - this.on(SUGGESTIONS_CHANGED_EVENT + id, callback); - } - removeSuggestionsChangedListener(id, callback) { - this.removeListener(SUGGESTIONS_CHANGED_EVENT + id, callback); - } - emitSuggestionsChanged(id) { - this.emit(SUGGESTIONS_CHANGED_EVENT + id); - } - - addPretextChangedListener(id, callback) { - this.on(PRETEXT_CHANGED_EVENT + id, callback); - } - removePretextChangedListener(id, callback) { - this.removeListener(PRETEXT_CHANGED_EVENT + id, callback); - } - emitPretextChanged(id, pretext) { - this.emit(PRETEXT_CHANGED_EVENT + id, pretext); - } - - addCompleteWordListener(id, callback) { - this.on(COMPLETE_WORD_EVENT + id, callback); - } - removeCompleteWordListener(id, callback) { - this.removeListener(COMPLETE_WORD_EVENT + id, callback); - } - emitCompleteWord(id, term, matchedPretext) { - this.emit(COMPLETE_WORD_EVENT + id, term, matchedPretext); - } - - addPopoverMentionKeyClickListener(id, callback) { - this.on(POPOVER_MENTION_KEY_CLICK_EVENT + id, callback); - } - removePopoverMentionKeyClickListener(id, callback) { - this.removeListener(POPOVER_MENTION_KEY_CLICK_EVENT + id, callback); - } - emitPopoverMentionKeyClick(isRHS, mentionKey) { - this.emit(POPOVER_MENTION_KEY_CLICK_EVENT + isRHS, mentionKey); - } - - registerSuggestionBox(id) { - this.suggestions.set(id, { - pretext: '', - matchedPretext: [], - terms: [], - items: [], - components: [], - selection: '' - }); - } - - unregisterSuggestionBox(id) { - this.suggestions.delete(id); - } - - clearSuggestions(id) { - const suggestion = this.getSuggestions(id); - - suggestion.matchedPretext = []; - suggestion.terms = []; - suggestion.items = []; - suggestion.components = []; - } - - clearSelection(id) { - const suggestion = this.getSuggestions(id); - - suggestion.selection = ''; - } - - hasSuggestions(id) { - return this.getSuggestions(id).terms.length > 0; - } - - setPretext(id, pretext) { - const suggestion = this.getSuggestions(id); - - suggestion.pretext = pretext; - } - - addSuggestion(id, term, item, component, matchedPretext) { - const suggestion = this.getSuggestions(id); - - suggestion.terms.push(term); - suggestion.items.push(item); - suggestion.components.push(component); - suggestion.matchedPretext.push(matchedPretext); - } - - addSuggestions(id, terms, items, component, matchedPretext) { - const suggestion = this.getSuggestions(id); - - suggestion.terms.push(...terms); - suggestion.items.push(...items); - - for (let i = 0; i < terms.length; i++) { - suggestion.components.push(component); - suggestion.matchedPretext.push(matchedPretext); - } - } - - // make sure that if suggestions exist, then one of them is selected. return true if the selection changes. - ensureSelectionExists(id) { - const suggestion = this.getSuggestions(id); - - if (suggestion.terms.length > 0) { - // if the current selection is no longer in the map, select the first term in the list - if (!suggestion.selection || suggestion.terms.indexOf(suggestion.selection) === -1) { - suggestion.selection = suggestion.terms[0]; - - return true; - } - } else if (suggestion.selection) { - suggestion.selection = ''; - - return true; - } - - return false; - } - - getPretext(id) { - return this.getSuggestions(id).pretext; - } - - getSelectedMatchedPretext(id) { - const suggestion = this.getSuggestions(id); - - for (let i = 0; i < suggestion.terms.length; i++) { - if (suggestion.terms[i] === suggestion.selection) { - return suggestion.matchedPretext[i]; - } - } - - return ''; - } - - getItems(id) { - return this.getSuggestions(id).items; - } - - getTerms(id) { - return this.getSuggestions(id).terms; - } - - getComponents(id) { - return this.getSuggestions(id).components; - } - - getSuggestions(id) { - return this.suggestions.get(id) || {}; - } - - getSelection(id) { - return this.getSuggestions(id).selection; - } - - selectNext(id) { - this.setSelectionByDelta(id, 1); - } - - selectPrevious(id) { - this.setSelectionByDelta(id, -1); - } - - setSelectionByDelta(id, delta) { - const suggestion = this.suggestions.get(id); - - let selectionIndex = suggestion.terms.indexOf(suggestion.selection); - - if (selectionIndex === -1) { - // this should never happen since selection should always be in terms - throw new Error('selection is not in terms'); - } - - selectionIndex += delta; - - if (selectionIndex < 0) { - selectionIndex = 0; - } else if (selectionIndex > suggestion.terms.length - 1) { - selectionIndex = suggestion.terms.length - 1; - } - - suggestion.selection = suggestion.terms[selectionIndex]; - } - - checkIfPretextMatches(id, matchedPretext) { - const pretext = this.getPretext(id) || ''; - return pretext.endsWith(matchedPretext); - } - - setSuggestionsPending(id, pending) { - this.suggestions.get(id).suggestionsPending = pending; - } - - areSuggestionsPending(id) { - return this.suggestions.get(id).suggestionsPending; - } - - setCompletePending(id, pending) { - this.suggestions.get(id).completePending = pending; - } - - isCompletePending(id) { - return this.suggestions.get(id).completePending; - } - - completeWord(id, term = '', matchedPretext = '') { - this.emitCompleteWord(id, term || this.getSelection(id), matchedPretext || this.getSelectedMatchedPretext(id)); - - this.setPretext(id, ''); - this.clearSuggestions(id); - this.clearSelection(id); - this.emitSuggestionsChanged(id); - } - - handleEventPayload(payload) { - const {type, id, ...other} = payload.action; - - switch (type) { - case ActionTypes.SUGGESTION_PRETEXT_CHANGED: - // Clear the suggestions if the pretext is empty or ends with whitespace - if (other.pretext === '') { - this.clearSuggestions(id); - } - - other.pretext = other.pretext.toLowerCase(); - - this.setPretext(id, other.pretext); - this.emitPretextChanged(id, other.pretext); - - this.ensureSelectionExists(id); - this.emitSuggestionsChanged(id); - break; - case ActionTypes.SUGGESTION_RECEIVED_SUGGESTIONS: - if (!this.checkIfPretextMatches(id, other.matchedPretext)) { - // These suggestions are out of date since the pretext has changed - return; - } - - this.clearSuggestions(id); - this.addSuggestions(id, other.terms, other.items, other.component, other.matchedPretext); - this.ensureSelectionExists(id); - - this.setSuggestionsPending(id, false); - - if (this.isCompletePending(id)) { - this.completeWord(id); - } else { - this.emitSuggestionsChanged(id); - } - break; - case ActionTypes.SUGGESTION_CLEAR_SUGGESTIONS: - this.setPretext(id, ''); - this.clearSuggestions(id); - this.clearSelection(id); - this.emitSuggestionsChanged(id); - break; - case ActionTypes.SUGGESTION_SELECT_NEXT: - this.selectNext(id); - this.emitSuggestionsChanged(id); - break; - case ActionTypes.SUGGESTION_SELECT_PREVIOUS: - this.selectPrevious(id); - this.emitSuggestionsChanged(id); - break; - case ActionTypes.SUGGESTION_COMPLETE_WORD: - if (this.areSuggestionsPending(id)) { - this.setCompletePending(id, true); - } else { - this.completeWord(id, other.term, other.matchedPretext); - } - break; - case ActionTypes.POPOVER_MENTION_KEY_CLICK: - this.emitPopoverMentionKeyClick(other.isRHS, other.mentionKey); - break; - } - } -} - -export default new SuggestionStore(); diff --git a/webapp/stores/team_store.jsx b/webapp/stores/team_store.jsx deleted file mode 100644 index 1c38ba5e7..000000000 --- a/webapp/stores/team_store.jsx +++ /dev/null @@ -1,470 +0,0 @@ -// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. -// See License.txt for license information. - -import AppDispatcher from '../dispatcher/app_dispatcher.jsx'; -import EventEmitter from 'events'; -import UserStore from 'stores/user_store.jsx'; -import ChannelStore from 'stores/channel_store.jsx'; - -import Constants from 'utils/constants.jsx'; -const NotificationPrefs = Constants.NotificationPrefs; - -import {getSiteURL} from 'utils/url.jsx'; -import {isSystemMessage, isFromWebhook} from 'utils/post_utils.jsx'; -const ActionTypes = Constants.ActionTypes; - -const CHANGE_EVENT = 'change'; -const STATS_EVENT = 'stats'; -const UNREAD_EVENT = 'unread'; - -import store from 'stores/redux_store.jsx'; -import * as Selectors from 'mattermost-redux/selectors/entities/teams'; -import {TeamTypes} from 'mattermost-redux/action_types'; - -var Utils; - -class TeamStoreClass extends EventEmitter { - constructor() { - super(); - - this.entities = store.getState().entities.teams; - - store.subscribe(() => { - const newEntities = store.getState().entities.teams; - let doEmit = false; - - if (newEntities.currentTeamId !== this.entities.currentTeamId) { - doEmit = true; - } - if (newEntities.teams !== this.entities.teams) { - doEmit = true; - } - if (newEntities.myMembers !== this.entities.myMembers) { - doEmit = true; - this.emitUnreadChange(); - } - if (newEntities.membersInTeam !== this.entities.membersInTeam) { - doEmit = true; - } - if (newEntities.stats !== this.entities.stats) { - this.emitStatsChange(); - } - - if (doEmit) { - this.emitChange(); - } - - this.entities = newEntities; - }); - } - - emitChange() { - this.emit(CHANGE_EVENT); - } - - addChangeListener(callback) { - this.on(CHANGE_EVENT, callback); - } - - removeChangeListener(callback) { - this.removeListener(CHANGE_EVENT, callback); - } - - emitStatsChange() { - this.emit(STATS_EVENT); - } - - addStatsChangeListener(callback) { - this.on(STATS_EVENT, callback); - } - - removeStatsChangeListener(callback) { - this.removeListener(STATS_EVENT, callback); - } - - emitUnreadChange() { - this.emit(UNREAD_EVENT); - } - - addUnreadChangeListener(callback) { - this.on(UNREAD_EVENT, callback); - } - - removeUnreadChangeListener(callback) { - this.removeListener(UNREAD_EVENT, callback); - } - - get(id) { - var c = this.getAll(); - return c[id]; - } - - getByName(name) { - const t = this.getAll(); - - for (const id in t) { - if (t.hasOwnProperty(id)) { - if (t[id].name === name) { - return t[id]; - } - } - } - - return null; - } - - getAll() { - const list = Selectors.getMyTeams(store.getState()); - const teams = {}; - list.forEach((t) => { - teams[t.id] = t; - }); - return teams; - } - - getCurrentId() { - return Selectors.getCurrentTeamId(store.getState()); - } - - setCurrentId(id) { - store.dispatch({ - type: TeamTypes.SELECT_TEAM, - data: id - }); - } - - getCurrent() { - const team = Selectors.getCurrentTeam(store.getState()); - - if (team) { - return team; - } - - return null; - } - - getCurrentTeamUrl() { - return this.getTeamUrl(this.getCurrentId()); - } - - getCurrentTeamRelativeUrl() { - if (this.getCurrent()) { - return '/' + this.getCurrent().name; - } - return ''; - } - - getCurrentInviteLink() { - const current = this.getCurrent(); - - if (current) { - return getSiteURL() + '/signup_user_complete/?id=' + current.invite_id; - } - - return ''; - } - - getTeamUrl(id) { - const team = this.get(id); - - if (!team) { - return ''; - } - - return getSiteURL() + '/' + team.name; - } - - getCurrentStats() { - return this.getStats(this.getCurrentId()); - } - - getStats(teamId) { - let stats; - - if (teamId) { - stats = Selectors.getTeamStats(store.getState())[teamId]; - } - - if (stats) { - // create a defensive copy - stats = Object.assign({}, stats); - } else { - stats = {member_count: 0}; - } - - return stats; - } - - saveTeam(team) { - const teams = {}; - teams[team.id] = team; - this.saveTeams(teams); - } - - saveTeams(teams) { - store.dispatch({ - type: TeamTypes.RECEIVED_TEAMS, - data: teams - }); - } - - updateTeam(team) { - const t = JSON.parse(team); - const teams = Object.assign({}, this.getAll(), this.getTeamListings()); - if (teams && teams[t.id]) { - this.saveTeam(t); - } - } - - saveMyTeam(team) { - this.saveTeam(team); - this.setCurrentId(team.id); - } - - saveStats(teamId, stats) { - store.dispatch({ - type: TeamTypes.RECEIVED_TEAM_STATS, - data: stats - }); - } - - saveMyTeamMembers(members) { - store.dispatch({ - type: TeamTypes.RECEIVED_MY_TEAM_MEMBERS, - data: members - }); - } - - appendMyTeamMember(member) { - const members = this.getMyTeamMembers(); - members.push(member); - this.saveMyTeamMembers(members); - } - - saveMyTeamMembersUnread(members) { - const myMembers = this.getMyTeamMembers(); - for (let i = 0; i < myMembers.length; i++) { - const team = myMembers[i]; - const member = members.filter((m) => m.team_id === team.team_id)[0]; - - if (member) { - myMembers[i] = Object.assign({}, - team, - { - msg_count: member.msg_count, - mention_count: member.mention_count - }); - } - } - - this.saveMyTeamMembers(myMembers); - } - - removeMyTeamMember(teamId) { - const myMembers = this.getMyTeamMembers(); - for (let i = 0; i < myMembers.length; i++) { - if (myMembers[i].team_id === teamId) { - myMembers.splice(i, 1); - } - } - - this.saveMyTeamMembers(myMembers); - } - - getMyTeamMembers() { - return Object.values(Selectors.getTeamMemberships(store.getState())); - } - - saveMembersInTeam(teamId = this.getCurrentId(), members) { - store.dispatch({ - type: TeamTypes.RECEIVED_MEMBERS_IN_TEAM, - data: Object.values(members) - }); - } - - removeMemberInTeam(teamId = this.getCurrentId(), userId) { - store.dispatch({ - type: TeamTypes.REMOVE_MEMBER_FROM_TEAM, - data: {team_id: teamId, user_id: userId} - }); - } - - getMembersInTeam(teamId = this.getCurrentId()) { - return Selectors.getMembersInTeams(store.getState())[teamId] || {}; - } - - getMemberInTeam(teamId = this.getCurrentId(), userId) { - return Selectors.getTeamMember(store.getState(), teamId, userId); - } - - hasActiveMemberInTeam(teamId = this.getCurrentId(), userId) { - if (this.getMemberInTeam(teamId, userId)) { - return true; - } - - return false; - } - - getTeamListings() { - return Selectors.getJoinableTeams(store.getState()); - } - - isTeamAdminForAnyTeam() { - if (!Utils) { - Utils = require('utils/utils.jsx'); //eslint-disable-line global-require - } - - for (const teamMember of this.getMyTeamMembers()) { - if (Utils.isAdmin(teamMember.roles)) { - return true; - } - } - - return false; - } - - isTeamAdminForCurrentTeam() { - return this.isTeamAdmin(UserStore.getCurrentId(), this.getCurrentId()); - } - - isTeamAdmin(userId, teamId) { - if (!Utils) { - Utils = require('utils/utils.jsx'); //eslint-disable-line global-require - } - - var teamMembers = this.getMyTeamMembers(); - const teamMember = teamMembers.find((m) => m.user_id === userId && m.team_id === teamId); - - if (teamMember) { - return Utils.isAdmin(teamMember.roles); - } - - return false; - } - - updateMyRoles(member) { - const teamMembers = this.getMyTeamMembers(); - const teamMember = teamMembers.find((m) => m.user_id === member.user_id && m.team_id === member.team_id); - - if (teamMember) { - const newMember = Object.assign({}, teamMember, { - roles: member.roles - }); - - store.dispatch({ - type: TeamTypes.RECEIVED_MY_TEAM_MEMBER, - data: newMember - }); - } - } - - subtractUnread(teamId, msgs, mentions) { - let member = this.getMyTeamMembers().filter((m) => m.team_id === teamId)[0]; - if (member) { - const msgCount = member.msg_count - msgs; - const mentionCount = member.mention_count - mentions; - - member = Object.assign({}, member); - member.msg_count = (msgCount > 0) ? msgCount : 0; - member.mention_count = (mentionCount > 0) ? mentionCount : 0; - - store.dispatch({ - type: TeamTypes.RECEIVED_MY_TEAM_MEMBER, - data: member - }); - } - } - - incrementMessages(id, channelId) { - const channelMember = ChannelStore.getMyMember(channelId); - if (channelMember && channelMember.notify_props && channelMember.notify_props.mark_unread === NotificationPrefs.MENTION) { - return; - } - - const member = Object.assign({}, this.getMyTeamMembers().filter((m) => m.team_id === id)[0]); - member.msg_count++; - - store.dispatch({ - type: TeamTypes.RECEIVED_MY_TEAM_MEMBER, - data: member - }); - } - - incrementMentionsIfNeeded(id, msgProps) { - let mentions = []; - if (msgProps && msgProps.mentions) { - mentions = JSON.parse(msgProps.mentions); - } - - if (mentions.indexOf(UserStore.getCurrentId()) !== -1) { - const member = Object.assign({}, this.getMyTeamMembers().filter((m) => m.team_id === id)[0]); - member.mention_count++; - - store.dispatch({ - type: TeamTypes.RECEIVED_MY_TEAM_MEMBER, - data: member - }); - } - } -} - -var TeamStore = new TeamStoreClass(); - -TeamStore.dispatchToken = AppDispatcher.register((payload) => { - var action = payload.action; - - switch (action.type) { - case ActionTypes.RECEIVED_MY_TEAM: - TeamStore.saveMyTeam(action.team); - break; - case ActionTypes.RECEIVED_TEAM: - TeamStore.saveTeam(action.team); - break; - case ActionTypes.CREATED_TEAM: - TeamStore.saveTeam(action.team); - TeamStore.appendMyTeamMember(action.member); - break; - case ActionTypes.UPDATE_TEAM: - TeamStore.saveTeam(action.team); - break; - case ActionTypes.RECEIVED_ALL_TEAMS: - TeamStore.saveTeams(action.teams); - break; - case ActionTypes.RECEIVED_MY_TEAM_MEMBERS: - TeamStore.saveMyTeamMembers(action.team_members); - break; - case ActionTypes.RECEIVED_MY_TEAMS_UNREAD: - TeamStore.saveMyTeamMembersUnread(action.team_members); - break; - case ActionTypes.RECEIVED_ALL_TEAM_LISTINGS: - TeamStore.saveTeamListings(action.teams); - break; - case ActionTypes.RECEIVED_MEMBERS_IN_TEAM: - TeamStore.saveMembersInTeam(action.team_id, action.team_members); - break; - case ActionTypes.RECEIVED_TEAM_STATS: - TeamStore.saveStats(action.team_id, action.stats); - break; - case ActionTypes.RECEIVED_POST: - if (Constants.IGNORE_POST_TYPES.indexOf(action.post.type) !== -1) { - return; - } - - if (action.post.user_id === UserStore.getCurrentId() && !isSystemMessage(action.post) && !isFromWebhook(action.post)) { - return; - } - - var id = action.websocketMessageProps ? action.websocketMessageProps.team_id : null; - if (id && TeamStore.getCurrentId() !== id) { - TeamStore.incrementMessages(id, action.post.channel_id); - TeamStore.incrementMentionsIfNeeded(id, action.websocketMessageProps); - } - break; - default: - } -}); - -TeamStore.setMaxListeners(15); - -window.TeamStore = TeamStore; -export default TeamStore; diff --git a/webapp/stores/user_store.jsx b/webapp/stores/user_store.jsx deleted file mode 100644 index c2ea619e8..000000000 --- a/webapp/stores/user_store.jsx +++ /dev/null @@ -1,515 +0,0 @@ -// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. -// See License.txt for license information. - -import EventEmitter from 'events'; - -import Constants from 'utils/constants.jsx'; -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'; -const CHANGE_EVENT_SESSIONS = 'change_sessions'; -const CHANGE_EVENT_AUDITS = 'change_audits'; -const CHANGE_EVENT_STATUSES = 'change_statuses'; - -import store from 'stores/redux_store.jsx'; -import * as Selectors from 'mattermost-redux/selectors/entities/users'; -import {UserTypes} from 'mattermost-redux/action_types'; - -import ChannelStore from 'stores/channel_store.jsx'; -import TeamStore from 'stores/team_store.jsx'; - -var Utils; - -class UserStoreClass extends EventEmitter { - constructor() { - super(); - - this.noAccounts = false; - this.entities = {}; - - store.subscribe(() => { - const newEntities = store.getState().entities.users; - - if (newEntities.profiles !== this.entities.profiles) { - this.emitChange(); - } - if (newEntities.profilesInChannel !== this.entities.profilesInChannel) { - this.emitInChannelChange(); - } - if (newEntities.profilesNotInChannel !== this.entities.profilesNotInChannel) { - this.emitNotInChannelChange(); - } - if (newEntities.profilesInTeam !== this.entities.profilesInTeam) { - this.emitInTeamChange(); - } - if (newEntities.profilesNotInTeam !== this.entities.profilesNotInTeam) { - this.emitNotInTeamChange(); - } - if (newEntities.profilesWithoutTeam !== this.entities.profilesWithoutTeam) { - this.emitWithoutTeamChange(); - } - if (newEntities.statuses !== this.entities.statuses) { - this.emitStatusesChange(); - } - if (newEntities.myAudits !== this.entities.myAudits) { - this.emitAuditsChange(); - } - if (newEntities.mySessions !== this.entities.mySessions) { - this.emitSessionsChange(); - } - - this.entities = newEntities; - }); - } - - emitChange(userId) { - this.emit(CHANGE_EVENT, userId); - } - - addChangeListener(callback) { - this.on(CHANGE_EVENT, callback); - } - - removeChangeListener(callback) { - this.removeListener(CHANGE_EVENT, callback); - } - - emitInTeamChange() { - this.emit(CHANGE_EVENT_IN_TEAM); - } - - addInTeamChangeListener(callback) { - this.on(CHANGE_EVENT_IN_TEAM, callback); - } - - removeInTeamChangeListener(callback) { - 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); - } - - addInChannelChangeListener(callback) { - this.on(CHANGE_EVENT_IN_CHANNEL, callback); - } - - removeInChannelChangeListener(callback) { - this.removeListener(CHANGE_EVENT_IN_CHANNEL, callback); - } - - emitNotInChannelChange() { - this.emit(CHANGE_EVENT_NOT_IN_CHANNEL); - } - - addNotInChannelChangeListener(callback) { - this.on(CHANGE_EVENT_NOT_IN_CHANNEL, callback); - } - - removeNotInChannelChangeListener(callback) { - this.removeListener(CHANGE_EVENT_NOT_IN_CHANNEL, callback); - } - - emitWithoutTeamChange() { - this.emit(CHANGE_EVENT_WITHOUT_TEAM); - } - - addWithoutTeamChangeListener(callback) { - this.on(CHANGE_EVENT_WITHOUT_TEAM, callback); - } - - removeWithoutTeamChangeListener(callback) { - this.removeListener(CHANGE_EVENT_WITHOUT_TEAM, callback); - } - - emitSessionsChange() { - this.emit(CHANGE_EVENT_SESSIONS); - } - - addSessionsChangeListener(callback) { - this.on(CHANGE_EVENT_SESSIONS, callback); - } - - removeSessionsChangeListener(callback) { - this.removeListener(CHANGE_EVENT_SESSIONS, callback); - } - - emitAuditsChange() { - this.emit(CHANGE_EVENT_AUDITS); - } - - addAuditsChangeListener(callback) { - this.on(CHANGE_EVENT_AUDITS, callback); - } - - removeAuditsChangeListener(callback) { - this.removeListener(CHANGE_EVENT_AUDITS, callback); - } - - emitStatusesChange() { - this.emit(CHANGE_EVENT_STATUSES); - } - - addStatusesChangeListener(callback) { - this.on(CHANGE_EVENT_STATUSES, callback); - } - - removeStatusesChangeListener(callback) { - this.removeListener(CHANGE_EVENT_STATUSES, callback); - } - - // General - - getCurrentUser() { - return Selectors.getCurrentUser(store.getState()); - } - - getCurrentId() { - return Selectors.getCurrentUserId(store.getState()); - } - - // System-Wide Profiles - - getProfiles() { - return Selectors.getUsers(store.getState()); - } - - getProfile(userId) { - return Selectors.getUser(store.getState(), userId); - } - - getProfileListForIds(userIds, skipCurrent = false, skipInactive = false) { - 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; - } - - hasProfile(userId) { - return this.getProfiles().hasOwnProperty(userId); - } - - getProfileByUsername(username) { - return this.getProfilesUsernameMap()[username]; - } - - getProfilesUsernameMap() { - return Selectors.getUsersByUsername(store.getState()); - } - - getProfileByEmail(email) { - return Selectors.getUsersByEmail(store.getState())[email]; - } - - getActiveOnlyProfiles(skipCurrent) { - const active = {}; - const profiles = this.getProfiles(); - const currentId = this.getCurrentId(); - - for (var key in profiles) { - if (!(profiles[key].id === currentId && skipCurrent) && profiles[key].delete_at === 0) { - active[key] = profiles[key]; - } - } - - return active; - } - - getActiveOnlyProfileList() { - const profileMap = this.getActiveOnlyProfiles(); - const profiles = []; - - for (const id in profileMap) { - if (profileMap.hasOwnProperty(id)) { - profiles.push(profileMap[id]); - } - } - - profiles.sort((a, b) => { - if (a.username < b.username) { - return -1; - } - if (a.username > b.username) { - return 1; - } - return 0; - }); - - return profiles; - } - - getProfileList(skipCurrent = false, allowInactive = false) { - const profiles = []; - const currentId = this.getCurrentId(); - const profileMap = this.getProfiles(); - - for (const id in profileMap) { - if (profileMap.hasOwnProperty(id)) { - var profile = profileMap[id]; - - if (skipCurrent && id === currentId) { - continue; - } - - if (allowInactive || profile.delete_at === 0) { - profiles.push(profile); - } - } - } - - profiles.sort((a, b) => { - if (a.username < b.username) { - return -1; - } - if (a.username > b.username) { - return 1; - } - return 0; - }); - - return profiles; - } - - saveProfile(profile) { - store.dispatch({ - type: UserTypes.RECEIVED_PROFILE, - data: profile - }); - } - - // Team-Wide Profiles - - getProfileListInTeam(teamId = TeamStore.getCurrentId(), skipCurrent = false, skipInactive = false) { - const userIds = Array.from(Selectors.getUserIdsInTeams(store.getState())[teamId] || []); - - return this.getProfileListForIds(userIds, skipCurrent, skipInactive); - } - - removeProfileFromTeam(teamId, userId) { - store.dispatch({ - type: UserTypes.RECEIVED_PROFILE_NOT_IN_TEAM, - data: {user_id: userId}, - id: teamId - }); - } - - // Not In Team Profiles - - getProfileListNotInTeam(teamId = TeamStore.getCurrentId(), skipCurrent = false, skipInactive = false) { - const userIds = Array.from(Selectors.getUserIdsNotInTeams(store.getState())[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; - } - - removeProfileNotInTeam(teamId, userId) { - store.dispatch({ - type: UserTypes.RECEIVED_PROFILE_IN_TEAM, - data: {user_id: userId}, - id: teamId - }); - } - - // Channel-Wide Profiles - - saveProfileInChannel(channelId = ChannelStore.getCurrentId(), profile) { - store.dispatch({ - type: UserTypes.RECEIVED_PROFILE_IN_CHANNEL, - data: {user_id: profile.id}, - id: channelId - }); - } - - saveUserIdInChannel(channelId = ChannelStore.getCurrentId(), userId) { - store.dispatch({ - type: UserTypes.RECEIVED_PROFILE_IN_CHANNEL, - data: {user_id: userId}, - id: channelId - }); - } - - removeProfileInChannel(channelId, userId) { - store.dispatch({ - type: UserTypes.RECEIVED_PROFILE_NOT_IN_CHANNEL, - data: {user_id: userId}, - id: channelId - }); - } - - getProfileListInChannel(channelId = ChannelStore.getCurrentId(), skipCurrent = false, skipInactive = false) { - const userIds = Array.from(Selectors.getUserIdsInChannels(store.getState())[channelId] || []); - - return this.getProfileListForIds(userIds, skipCurrent, skipInactive); - } - - saveProfileNotInChannel(channelId = ChannelStore.getCurrentId(), profile) { - store.dispatch({ - type: UserTypes.RECEIVED_PROFILE_NOT_IN_CHANNEL, - data: {user_id: profile.id}, - id: channelId - }); - } - - removeProfileNotInChannel(channelId, userId) { - store.dispatch({ - type: UserTypes.RECEIVED_PROFILE_IN_CHANNEL, - data: {user_id: userId}, - id: channelId - }); - } - - getProfileListNotInChannel(channelId = ChannelStore.getCurrentId(), skipInactive = false) { - const userIds = Array.from(Selectors.getUserIdsNotInChannels(store.getState())[channelId] || []); - - return this.getProfileListForIds(userIds, false, skipInactive); - } - - // Profiles without any teams - - getProfileListWithoutTeam(skipCurrent = false, skipInactive = false) { - const userIds = Array.from(Selectors.getUserIdsWithoutTeam(store.getState()) || []); - - return this.getProfileListForIds(userIds, skipCurrent, skipInactive); - } - - // Other - - getSessions() { - return store.getState().entities.users.mySessions; - } - - getAudits() { - return store.getState().entities.users.myAudits; - } - - getCurrentMentionKeys() { - return this.getMentionKeys(this.getCurrentId()); - } - - getMentionKeys(id) { - var user = this.getProfile(id); - - var keys = []; - - if (!user || !user.notify_props) { - return keys; - } - - if (user.notify_props.mention_keys) { - keys = keys.concat(user.notify_props.mention_keys.split(',')); - } - - if (user.notify_props.first_name === 'true' && user.first_name) { - keys.push(user.first_name); - } - - if (user.notify_props.channel === 'true') { - keys.push('@channel'); - keys.push('@all'); - } - - const usernameKey = '@' + user.username; - if (keys.indexOf(usernameKey) === -1) { - keys.push(usernameKey); - } - - return keys; - } - - setStatus(userId, status) { - const data = [{user_id: userId, status}]; - store.dispatch({ - type: UserTypes.RECEIVED_STATUSES, - data - }); - } - - getStatuses() { - return store.getState().entities.users.statuses; - } - - getStatus(id) { - return this.getStatuses()[id] || UserStatuses.OFFLINE; - } - - getNoAccounts() { - return global.window.mm_config.NoAccounts === 'true'; - } - - setNoAccounts(noAccounts) { - this.noAccounts = noAccounts; - } - - isSystemAdminForCurrentUser() { - if (!Utils) { - Utils = require('utils/utils.jsx'); //eslint-disable-line global-require - } - - var current = this.getCurrentUser(); - - if (current) { - return Utils.isSystemAdmin(current.roles); - } - - return false; - } -} - -var UserStore = new UserStoreClass(); -UserStore.setMaxListeners(600); - -export {UserStore as default}; diff --git a/webapp/stores/user_typing_store.jsx b/webapp/stores/user_typing_store.jsx deleted file mode 100644 index 39805fdb4..000000000 --- a/webapp/stores/user_typing_store.jsx +++ /dev/null @@ -1,108 +0,0 @@ -// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved. -// See License.txt for license information. - -import AppDispatcher from '../dispatcher/app_dispatcher.jsx'; -import UserStore from 'stores/user_store.jsx'; -import EventEmitter from 'events'; -import * as Utils from 'utils/utils.jsx'; - -import Constants from 'utils/constants.jsx'; -const ActionTypes = Constants.ActionTypes; - -const CHANGE_EVENT = 'change'; - -class UserTypingStoreClass extends EventEmitter { - constructor() { - super(); - - // All typeing users by channel - // this.typingUsers.[channelId+postParentId].user if present then user us typing - // Value is timeout to remove user - this.typingUsers = {}; - } - - emitChange() { - this.emit(CHANGE_EVENT); - } - - addChangeListener(callback) { - this.on(CHANGE_EVENT, callback); - } - - removeChangeListener(callback) { - this.removeListener(CHANGE_EVENT, callback); - } - - nameFromId(userId) { - let name = Utils.localizeMessage('msg_typing.someone', 'Someone'); - if (UserStore.hasProfile(userId)) { - name = Utils.displayUsername(userId); - } - return name; - } - - userTyping(channelId, userId, postParentId) { - const name = this.nameFromId(userId); - - // Key representing a location where users can type - const loc = channelId + postParentId; - - // Create entry - if (!this.typingUsers[loc]) { - this.typingUsers[loc] = {}; - } - - // If we already have this user, clear it's timeout to be deleted - if (this.typingUsers[loc][name]) { - clearTimeout(this.typingUsers[loc][name].timeout); - } - - // Set the user and a timeout to remove it - this.typingUsers[loc][name] = setTimeout(() => { - Reflect.deleteProperty(this.typingUsers[loc], name); - if (this.typingUsers[loc] === {}) { - Reflect.deleteProperty(this.typingUsers, loc); - } - this.emitChange(); - }, parseInt(window.mm_config.TimeBetweenUserTypingUpdatesMilliseconds, 10)); - this.emitChange(); - } - - getUsersTyping(channelId, postParentId) { - // Key representing a location where users can type - const loc = channelId + postParentId; - - return this.typingUsers[loc]; - } - - userPosted(userId, channelId, postParentId) { - const name = this.nameFromId(userId); - const loc = channelId + postParentId; - - if (this.typingUsers[loc]) { - clearTimeout(this.typingUsers[loc][name]); - Reflect.deleteProperty(this.typingUsers[loc], name); - if (this.typingUsers[loc] === {}) { - Reflect.deleteProperty(this.typingUsers, loc); - } - this.emitChange(); - } - } -} - -var UserTypingStore = new UserTypingStoreClass(); - -UserTypingStore.dispatchToken = AppDispatcher.register((payload) => { - var action = payload.action; - - switch (action.type) { - case ActionTypes.RECEIVED_POST: - UserTypingStore.userPosted(action.post.user_id, action.post.channel_id, action.post.parent_id); - break; - case ActionTypes.USER_TYPING: - UserTypingStore.userTyping(action.channelId, action.userId, action.postParentId); - break; - } -}); - -export default UserTypingStore; diff --git a/webapp/stores/webrtc_store.jsx b/webapp/stores/webrtc_store.jsx deleted file mode 100644 index d5828eebc..000000000 --- a/webapp/stores/webrtc_store.jsx +++ /dev/null @@ -1,110 +0,0 @@ -// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved. -// See License.txt for license information. - -import AppDispatcher from 'dispatcher/app_dispatcher.jsx'; -import EventEmitter from 'events'; -import {WebrtcActionTypes} from 'utils/constants.jsx'; - -class WebrtcStoreClass extends EventEmitter { - constructor() { - super(); - - this.video_call_with = null; - } - - setVideoCallWith(userId) { - this.video_call_with = userId; - this.emitBusy(userId !== null); - } - - getVideoCallWith() { - return this.video_call_with; - } - - isBusy() { - return this.video_call_with !== null; - } - - emitInit(userId, isCaller) { - this.emit(WebrtcActionTypes.INITIALIZE, userId, isCaller); - } - - addInitListener(callback) { - this.on(WebrtcActionTypes.INITIALIZE, callback); - } - - removeInitListener(callback) { - this.removeListener(WebrtcActionTypes.INITIALIZE, callback); - } - - emitBusy(isBusy) { - this.emit(WebrtcActionTypes.BUSY, isBusy); - } - - addBusyListener(callback) { - this.on(WebrtcActionTypes.BUSY, callback); - } - - removeBusyListener(callback) { - this.removeListener(WebrtcActionTypes.BUSY, callback); - } - - emitNotify(message) { - this.emit(WebrtcActionTypes.NOTIFY, message); - } - - addNotifyListener(callback) { - this.on(WebrtcActionTypes.NOTIFY, callback); - } - - removeNotifyListener(callback) { - this.removeListener(WebrtcActionTypes.NOTIFY, callback); - } - - emitChanged(message) { - this.emit(WebrtcActionTypes.CHANGED, message); - } - - addChangedListener(callback) { - this.on(WebrtcActionTypes.CHANGED, callback); - } - - removeChangedListener(callback) { - this.removeListener(WebrtcActionTypes.CHANGED, callback); - } - - emitRhsChanged(isOpen) { - this.emit(WebrtcActionTypes.RHS, isOpen); - } - - addRhsChangedListener(callback) { - this.on(WebrtcActionTypes.RHS, callback); - } - - removeRhsChangedListener(callback) { - this.removeListener(WebrtcActionTypes.RHS, callback); - } -} - -var WebrtcStore = new WebrtcStoreClass(); -WebrtcStore.setMaxListeners(0); - -WebrtcStore.dispatchToken = AppDispatcher.register((payload) => { - var action = payload.action; - - switch (action.type) { - case WebrtcActionTypes.INITIALIZE: - WebrtcStore.emitInit(action.user_id, action.is_calling); - break; - case WebrtcActionTypes.NOTIFY: - WebrtcStore.emitNotify(action.message); - break; - default: - if (action.message) { - WebrtcStore.emitChanged(action.message); - } - break; - } -}); - -export default WebrtcStore; -- cgit v1.2.3-1-g7c22