forked from Ivasoft/mattermost-mobile
Add validations in cleanup middleware (#1122)
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
|
||||
// See License.txt for license information.
|
||||
|
||||
import {PostTypes} from 'mattermost-redux/action_types';
|
||||
import {Client4} from 'mattermost-redux/client';
|
||||
import {General} from 'mattermost-redux/constants';
|
||||
import {getClientConfig, getLicenseConfig} from 'mattermost-redux/actions/general';
|
||||
import {getPosts} from 'mattermost-redux/actions/posts';
|
||||
@@ -63,6 +65,41 @@ export function purgeOfflineStore() {
|
||||
return {type: General.OFFLINE_STORE_PURGE};
|
||||
}
|
||||
|
||||
export function createPost(post) {
|
||||
return async (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
|
||||
};
|
||||
|
||||
try {
|
||||
const payload = Client4.createPost({...newPost, create_at: 0});
|
||||
dispatch({
|
||||
type: PostTypes.RECEIVED_POSTS,
|
||||
data: {
|
||||
order: [],
|
||||
posts: {
|
||||
[payload.id]: payload
|
||||
}
|
||||
},
|
||||
channelId: payload.channel_id
|
||||
});
|
||||
} catch (error) {
|
||||
return {error};
|
||||
}
|
||||
|
||||
return {data: true};
|
||||
};
|
||||
}
|
||||
|
||||
export default {
|
||||
loadConfigAndLicense,
|
||||
loadFromPushNotification,
|
||||
|
||||
@@ -45,6 +45,9 @@ const state = {
|
||||
preferences: {
|
||||
myPreferences: {}
|
||||
},
|
||||
search: {
|
||||
recent: []
|
||||
},
|
||||
typing: {}
|
||||
},
|
||||
errors: [],
|
||||
@@ -252,8 +255,7 @@ const state = {
|
||||
navigation: '',
|
||||
views: {
|
||||
channel: {
|
||||
drafts: {},
|
||||
loading: false
|
||||
drafts: {}
|
||||
},
|
||||
fetchCache: {},
|
||||
i18n: {
|
||||
@@ -270,7 +272,9 @@ const state = {
|
||||
selectServer: {
|
||||
serverUrl: Config.DefaultServerUrl
|
||||
},
|
||||
team: {},
|
||||
team: {
|
||||
lastTeamId: ''
|
||||
},
|
||||
thread: {
|
||||
drafts: {}
|
||||
}
|
||||
|
||||
@@ -23,7 +23,6 @@ import {General} from 'mattermost-redux/constants';
|
||||
import {setAppState, setDeviceToken, setServerVersion} from 'mattermost-redux/actions/general';
|
||||
import {markChannelAsRead} from 'mattermost-redux/actions/channels';
|
||||
import {logError} from 'mattermost-redux/actions/errors';
|
||||
import {createPost} from 'mattermost-redux/actions/posts';
|
||||
import {logout} from 'mattermost-redux/actions/users';
|
||||
import {close as closeWebSocket} from 'mattermost-redux/actions/websocket';
|
||||
import {Client, Client4} from 'mattermost-redux/client';
|
||||
@@ -36,7 +35,7 @@ import {
|
||||
setStatusBarHeight
|
||||
} from 'app/actions/device';
|
||||
import {
|
||||
|
||||
createPost,
|
||||
loadConfigAndLicense,
|
||||
loadFromPushNotification,
|
||||
purgeOfflineStore
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
import DeviceInfo from 'react-native-device-info';
|
||||
|
||||
import {ViewTypes} from 'app/constants';
|
||||
import initialState from 'app/initial_state';
|
||||
import Config from 'assets/config';
|
||||
|
||||
export function messageRetention() {
|
||||
@@ -23,6 +24,7 @@ export function messageRetention() {
|
||||
|
||||
// Keep only the last 60 messages for the last 5 viewed channels in each team
|
||||
// and apply data retention on those posts if applies
|
||||
|
||||
return next(cleanupState(action));
|
||||
} else if (action.type === ViewTypes.DATA_CLEANUP) {
|
||||
const nextAction = cleanupState(action, true);
|
||||
@@ -36,8 +38,22 @@ export function messageRetention() {
|
||||
function resetStateForNewVersion(action) {
|
||||
const {payload} = action;
|
||||
const lastChannelForTeam = getLastChannelForTeam(payload);
|
||||
let users = {};
|
||||
|
||||
let general = initialState.entities.general;
|
||||
if (payload.entities.general) {
|
||||
general = payload.entities.general;
|
||||
}
|
||||
|
||||
let teams = initialState.entities.teams;
|
||||
if (payload.entities.teams) {
|
||||
teams = {
|
||||
currentTeamId: payload.entities.teams.currentTeamId,
|
||||
teams: payload.entities.teams.teams,
|
||||
myMembers: payload.entities.teams.myMembers
|
||||
};
|
||||
}
|
||||
|
||||
let users = initialState.entities.users;
|
||||
if (payload.entities.users) {
|
||||
const currentUserId = payload.entities.users.currentUserId;
|
||||
if (currentUserId) {
|
||||
@@ -50,38 +66,74 @@ function resetStateForNewVersion(action) {
|
||||
}
|
||||
}
|
||||
|
||||
let preferences = initialState.entities.preferences;
|
||||
if (payload.entities.preferences) {
|
||||
preferences = payload.entities.preferences;
|
||||
}
|
||||
|
||||
let search = initialState.entities.search;
|
||||
if (payload.entities.search && payload.entities.search.recent) {
|
||||
search = {
|
||||
recent: payload.entities.search.recent
|
||||
};
|
||||
}
|
||||
|
||||
let channelDrafts = initialState.views.channel.drafts;
|
||||
if (payload.views.channel && payload.views.channel.drafts) {
|
||||
channelDrafts = payload.views.channel.drafts;
|
||||
}
|
||||
|
||||
let i18n = initialState.views.i18n;
|
||||
if (payload.views.i18n) {
|
||||
i18n = payload.views.i18n;
|
||||
}
|
||||
|
||||
let fetchCache = initialState.views.fetchCache;
|
||||
if (payload.views.fetchCache) {
|
||||
fetchCache = payload.views.fetchCache;
|
||||
}
|
||||
|
||||
let lastTeamId = initialState.views.team.lastTeamId;
|
||||
if (payload.views.team && payload.views.team.lastTeamId) {
|
||||
lastTeamId = payload.views.team.lastTeamId;
|
||||
}
|
||||
|
||||
let threadDrafts = initialState.views.thread.drafts;
|
||||
if (payload.views.thread && payload.views.thread.drafts) {
|
||||
threadDrafts = payload.views.thread.drafts;
|
||||
}
|
||||
|
||||
let selectServer = initialState.views.selectServer;
|
||||
if (payload.views.selectServer) {
|
||||
selectServer = payload.views.selectServer;
|
||||
}
|
||||
|
||||
const nextState = {
|
||||
app: {
|
||||
build: DeviceInfo.getBuildNumber(),
|
||||
version: DeviceInfo.getVersion()
|
||||
},
|
||||
entities: {
|
||||
general: payload.entities.general,
|
||||
teams: {
|
||||
currentTeamId: payload.entities.teams.currentTeamId,
|
||||
teams: payload.entities.teams.teams,
|
||||
myMembers: payload.entities.teams.myMembers
|
||||
},
|
||||
general,
|
||||
teams,
|
||||
users,
|
||||
preferences: payload.entities.preferences,
|
||||
search: {
|
||||
recent: payload.entities.search ? payload.entities.search.recent : {}
|
||||
}
|
||||
preferences,
|
||||
search
|
||||
},
|
||||
views: {
|
||||
channel: {
|
||||
drafts: payload.views.channel.drafts
|
||||
drafts: channelDrafts
|
||||
},
|
||||
i18n: payload.views.i18n,
|
||||
fetchCache: payload.views.fetchCache,
|
||||
i18n,
|
||||
fetchCache,
|
||||
team: {
|
||||
lastTeamId: payload.views.team.lastTeamId,
|
||||
lastTeamId,
|
||||
lastChannelForTeam
|
||||
},
|
||||
thread: {
|
||||
drafts: payload.views.thread.drafts
|
||||
drafts: threadDrafts
|
||||
},
|
||||
selectServer: payload.views.selectServer
|
||||
selectServer
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
{
|
||||
"DefaultServerUrl": "",
|
||||
"EnableMessageRetention": false,
|
||||
"MessageRetentionPeriod": 30,
|
||||
"TestServerUrl": "http://localhost:8065",
|
||||
"DefaultTheme": "default",
|
||||
"ShowErrorsList": false,
|
||||
|
||||
Reference in New Issue
Block a user