mattermost-mobile/app/actions/websocket/preferences.ts
Elias Nahum 5ea470a235
V1 dependencies and bump to RN 0.67.2 (#5908)
* update dependencies

* eslint fixes

* Upgrade to RN 67

* update other deps

* Update to RN 0.67.2

* fix Android build (mmkv)

* Fix crash when root message is deleted from the thread screen

* Fix gif emoji playing at high speed on iOS ProMotion capable devices
2022-02-02 15:28:57 -03:00

70 lines
2.8 KiB
TypeScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {getAddedDmUsersIfNecessary} from '@actions/helpers/channels';
import {handleCRTPreferenceChange} from '@actions/views/crt';
import {getPost} from '@actions/views/post';
import {PreferenceTypes} from '@mm-redux/action_types';
import {Preferences} from '@mm-redux/constants';
import {getAllPosts} from '@mm-redux/selectors/entities/posts';
import {ActionResult, DispatchFunc, GenericAction, GetStateFunc, batchActions} from '@mm-redux/types/actions';
import {PreferenceType} from '@mm-redux/types/preferences';
import {WebSocketMessage} from '@mm-redux/types/websocket';
export function handlePreferenceChangedEvent(msg: WebSocketMessage) {
return async (dispatch: DispatchFunc, getState: GetStateFunc): Promise<ActionResult> => {
const preference = JSON.parse(msg.data.preference);
const actions: GenericAction[] = [{
type: PreferenceTypes.RECEIVED_PREFERENCES,
data: [preference],
}];
const crtPreferenceChanged = dispatch(handleCRTPreferenceChange([preference])) as ActionResult;
if (crtPreferenceChanged.data) {
return {data: true};
}
const state = getState();
const dmActions = await getAddedDmUsersIfNecessary(state, [preference]);
if (dmActions.length) {
actions.push(...dmActions);
}
dispatch(batchActions(actions, 'BATCH_WS_PREFERENCE_CHANGED'));
return {data: true};
};
}
export function handlePreferencesChangedEvent(msg: WebSocketMessage) {
return async (dispatch: DispatchFunc, getState: GetStateFunc): Promise<ActionResult> => {
const preferences: PreferenceType[] = JSON.parse(msg.data.preferences);
const posts = getAllPosts(getState());
const actions: GenericAction[] = [{
type: PreferenceTypes.RECEIVED_PREFERENCES,
data: preferences,
}];
preferences.forEach((pref) => {
if (pref.category === Preferences.CATEGORY_FLAGGED_POST && !posts[pref.name]) {
dispatch(getPost(pref.name));
}
});
const crtPreferenceChanged = dispatch(handleCRTPreferenceChange(preferences)) as ActionResult;
if (crtPreferenceChanged.data) {
return {data: true};
}
const state = getState();
const dmActions = await getAddedDmUsersIfNecessary(state, preferences);
if (dmActions.length) {
actions.push(...dmActions);
}
dispatch(batchActions(actions, 'BATCH_WS_PREFERENCES_CHANGED'));
return {data: true};
};
}
export function handlePreferencesDeletedEvent(msg: WebSocketMessage): GenericAction {
const preferences = JSON.parse(msg.data.preferences);
return {type: PreferenceTypes.DELETED_PREFERENCES, data: preferences};
}