* Switch to SingleDex and remove all locales * WIP Mattermost Start Component for lazy loading modules * Add files changed for native modules * Add Entry component and app global object * dispatch setStatusBarHeight for iOS * Update screen imports * Include Entry screen * Refactor app to mattermost.android.js * Override unnecessary java files * Fix minor issues in changes * Display empty state based on user credentials Also, add proper background theme for empty loading screen * Add native module constant cache support * Fix startup theme regression * Add Keychain support for credentials * Fix Orientation regression * Fix SharedExtension regression * Emit NATIVE_APP_LAUNCHED across bridge only once during cold start * Add iOS Support * Revert to previous implementation of i18n * Fix styling issues * Include listener for SERVER_VERSION_CHANGED * Add SafeAreaView in Entry screen * Register deviceToken early, in order to get iOS PN Support * Include StartTimeModule * Add ReplyFromPush support and remove NATIVE_APP_LAUNCHED listener * Package native constants in StartTimeModule and avoid bridge calls * Fix check-style errors * Code cleanup * Rename StartTimeModule to InitializationModule * Remove NavigationApplication * Documentation and minor changes * Account for app opening after SharedExtension * Refactor getIntl to getTranslations * Move native module constants into it's own forked repos * Include FetchBlob and DeviceInfo forked repos
138 lines
4.7 KiB
JavaScript
138 lines
4.7 KiB
JavaScript
// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
|
|
// See License.txt for license information.
|
|
|
|
import {GeneralTypes, PostTypes} from 'mattermost-redux/action_types';
|
|
import {Client4} from 'mattermost-redux/client';
|
|
import {General} from 'mattermost-redux/constants';
|
|
import {markChannelAsRead} from 'mattermost-redux/actions/channels';
|
|
import {getClientConfig, getDataRetentionPolicy, getLicenseConfig} from 'mattermost-redux/actions/general';
|
|
import {getPosts} from 'mattermost-redux/actions/posts';
|
|
import {getMyTeams, getMyTeamMembers, selectTeam} from 'mattermost-redux/actions/teams';
|
|
|
|
import {ViewTypes} from 'app/constants';
|
|
import {recordTime} from 'app/utils/segment';
|
|
|
|
import {
|
|
handleSelectChannel,
|
|
setChannelDisplayName,
|
|
retryGetPostsAction,
|
|
} from 'app/actions/views/channel';
|
|
|
|
export function startDataCleanup() {
|
|
return async (dispatch, getState) => {
|
|
dispatch({
|
|
type: ViewTypes.DATA_CLEANUP,
|
|
payload: getState(),
|
|
});
|
|
};
|
|
}
|
|
|
|
export function loadConfigAndLicense() {
|
|
return async (dispatch, getState) => {
|
|
const {currentUserId} = getState().entities.users;
|
|
const [configData, licenseData] = await Promise.all([
|
|
getClientConfig()(dispatch, getState),
|
|
getLicenseConfig()(dispatch, getState),
|
|
]);
|
|
|
|
const config = configData.data || {};
|
|
const license = licenseData.data || {};
|
|
|
|
if (currentUserId) {
|
|
if (config.DataRetentionEnableMessageDeletion && config.DataRetentionEnableMessageDeletion === 'true' &&
|
|
license.IsLicensed === 'true' && license.DataRetention === 'true') {
|
|
getDataRetentionPolicy()(dispatch, getState);
|
|
} else {
|
|
dispatch({type: GeneralTypes.RECEIVED_DATA_RETENTION_POLICY, data: {}});
|
|
}
|
|
}
|
|
|
|
return {config, license};
|
|
};
|
|
}
|
|
|
|
export function loadFromPushNotification(notification) {
|
|
return async (dispatch, getState) => {
|
|
const state = getState();
|
|
const {data} = notification;
|
|
const {currentTeamId, teams, myMembers: myTeamMembers} = state.entities.teams;
|
|
const {currentChannelId} = state.entities.channels;
|
|
const channelId = data.channel_id;
|
|
|
|
// when the notification does not have a team id is because its from a DM or GM
|
|
const teamId = data.team_id || currentTeamId;
|
|
|
|
//verify that we have the team loaded
|
|
if (teamId && (!teams[teamId] || !myTeamMembers[teamId])) {
|
|
await Promise.all([
|
|
getMyTeams()(dispatch, getState),
|
|
getMyTeamMembers()(dispatch, getState),
|
|
]);
|
|
}
|
|
|
|
// when the notification is from a team other than the current team
|
|
if (teamId !== currentTeamId) {
|
|
selectTeam({id: teamId})(dispatch, getState);
|
|
}
|
|
|
|
// when the notification is from the same channel as the current channel
|
|
// we should get the posts
|
|
if (channelId === currentChannelId) {
|
|
markChannelAsRead(channelId, null, false)(dispatch, getState);
|
|
await retryGetPostsAction(getPosts(channelId), dispatch, getState);
|
|
} else {
|
|
// when the notification is from a channel other than the current channel
|
|
markChannelAsRead(channelId, currentChannelId, false)(dispatch, getState);
|
|
dispatch(setChannelDisplayName(''));
|
|
handleSelectChannel(channelId)(dispatch, getState);
|
|
}
|
|
};
|
|
}
|
|
|
|
export function purgeOfflineStore() {
|
|
return {type: General.OFFLINE_STORE_PURGE};
|
|
}
|
|
|
|
export function createPost(post) {
|
|
return (dispatch, getState) => {
|
|
const state = getState();
|
|
const currentUserId = state.entities.users.currentUserId;
|
|
|
|
const timestamp = Date.now();
|
|
const pendingPostId = post.pending_post_id || `${currentUserId}:${timestamp}`;
|
|
|
|
const newPost = {
|
|
...post,
|
|
pending_post_id: pendingPostId,
|
|
create_at: timestamp,
|
|
update_at: timestamp,
|
|
};
|
|
|
|
return Client4.createPost({...newPost, create_at: 0}).then((payload) => {
|
|
dispatch({
|
|
type: PostTypes.RECEIVED_POSTS,
|
|
data: {
|
|
order: [],
|
|
posts: {
|
|
[payload.id]: payload,
|
|
},
|
|
},
|
|
channelId: payload.channel_id,
|
|
});
|
|
});
|
|
};
|
|
}
|
|
|
|
export function recordLoadTime(screenName, category) {
|
|
return async (dispatch, getState) => {
|
|
const {currentUserId} = getState().entities.users;
|
|
|
|
recordTime(screenName, category, currentUserId);
|
|
};
|
|
}
|
|
|
|
export default {
|
|
loadConfigAndLicense,
|
|
loadFromPushNotification,
|
|
purgeOfflineStore,
|
|
};
|