[FIX] Issues after reconnecting (#3815)
This commit is contained in:
parent
d73da2942b
commit
65c9aec2b4
|
@ -11,7 +11,7 @@ function createRequestTypes(base = {}, types = defaultTypes): Record<string, str
|
||||||
// Login events
|
// Login events
|
||||||
export const LOGIN = createRequestTypes('LOGIN', [...defaultTypes, 'SET_SERVICES', 'SET_PREFERENCE', 'SET_LOCAL_AUTHENTICATED']);
|
export const LOGIN = createRequestTypes('LOGIN', [...defaultTypes, 'SET_SERVICES', 'SET_PREFERENCE', 'SET_LOCAL_AUTHENTICATED']);
|
||||||
export const SHARE = createRequestTypes('SHARE', ['SELECT_SERVER', 'SET_USER', 'SET_SETTINGS', 'SET_SERVER_INFO']);
|
export const SHARE = createRequestTypes('SHARE', ['SELECT_SERVER', 'SET_USER', 'SET_SETTINGS', 'SET_SERVER_INFO']);
|
||||||
export const USER = createRequestTypes('USER', ['SET']);
|
export const USER = createRequestTypes('USER', ['SET', 'CLEAR']);
|
||||||
export const ROOMS = createRequestTypes('ROOMS', [
|
export const ROOMS = createRequestTypes('ROOMS', [
|
||||||
...defaultTypes,
|
...defaultTypes,
|
||||||
'REFRESH',
|
'REFRESH',
|
||||||
|
|
|
@ -93,6 +93,12 @@ export function setUser(user: Partial<IUser>): ISetUser {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function clearUser(): Action {
|
||||||
|
return {
|
||||||
|
type: types.USER.CLEAR
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
export function setLoginServices(data: Record<string, any>): ISetServices {
|
export function setLoginServices(data: Record<string, any>): ISetServices {
|
||||||
return {
|
return {
|
||||||
type: types.LOGIN.SET_SERVICES,
|
type: types.LOGIN.SET_SERVICES,
|
||||||
|
|
|
@ -103,9 +103,16 @@ export default class RoomSubscription {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
handleConnection = () => {
|
handleConnection = async () => {
|
||||||
reduxStore.dispatch(clearUserTyping());
|
try {
|
||||||
RocketChat.loadMissedMessages({ rid: this.rid }).catch(e => console.log(e));
|
reduxStore.dispatch(clearUserTyping());
|
||||||
|
await RocketChat.loadMissedMessages({ rid: this.rid });
|
||||||
|
const _lastOpen = new Date();
|
||||||
|
this.read(_lastOpen);
|
||||||
|
this.lastOpen = _lastOpen;
|
||||||
|
} catch (e) {
|
||||||
|
log(e);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
handleNotifyRoomReceived = protectedFunction((ddpMessage: IDDPMessage) => {
|
handleNotifyRoomReceived = protectedFunction((ddpMessage: IDDPMessage) => {
|
||||||
|
|
|
@ -18,7 +18,7 @@ import { loginRequest, setLoginServices, setUser } from '../../../actions/login'
|
||||||
import sdk from './sdk';
|
import sdk from './sdk';
|
||||||
import I18n from '../../../i18n';
|
import I18n from '../../../i18n';
|
||||||
import RocketChat, { MIN_ROCKETCHAT_VERSION, STATUSES } from '../rocketchat';
|
import RocketChat, { MIN_ROCKETCHAT_VERSION, STATUSES } from '../rocketchat';
|
||||||
import { ICredentials, ILoggedUser, IRocketChat, IUser } from '../../../definitions';
|
import { ICredentials, ILoggedUser, IRocketChat } from '../../../definitions';
|
||||||
import { isIOS } from '../../../utils/deviceInfo';
|
import { isIOS } from '../../../utils/deviceInfo';
|
||||||
import { connectRequest, connectSuccess, disconnect as disconnectAction } from '../../../actions/connect';
|
import { connectRequest, connectSuccess, disconnect as disconnectAction } from '../../../actions/connect';
|
||||||
import { updatePermission } from '../../../actions/permissions';
|
import { updatePermission } from '../../../actions/permissions';
|
||||||
|
@ -38,8 +38,8 @@ interface IServices {
|
||||||
// FIXME: Remove `this` context
|
// FIXME: Remove `this` context
|
||||||
function connect(
|
function connect(
|
||||||
this: IRocketChat,
|
this: IRocketChat,
|
||||||
{ server, user, logoutOnError = false }: { server: string; user: IUser; logoutOnError: boolean }
|
{ server, logoutOnError = false }: { server: string; logoutOnError: boolean }
|
||||||
) {
|
): Promise<void> {
|
||||||
return new Promise<void>(resolve => {
|
return new Promise<void>(resolve => {
|
||||||
if (sdk.current?.client?.host === server) {
|
if (sdk.current?.client?.host === server) {
|
||||||
return resolve();
|
return resolve();
|
||||||
|
@ -107,8 +107,8 @@ function connect(
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
store.dispatch(connectSuccess());
|
store.dispatch(connectSuccess());
|
||||||
const { server: currentServer } = store.getState().server;
|
const { user } = store.getState().login;
|
||||||
if (user?.token && server === currentServer) {
|
if (user?.token) {
|
||||||
store.dispatch(loginRequest({ resume: user.token }, logoutOnError));
|
store.dispatch(loginRequest({ resume: user.token }, logoutOnError));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import {
|
import {
|
||||||
|
clearUser,
|
||||||
loginFailure,
|
loginFailure,
|
||||||
loginRequest,
|
loginRequest,
|
||||||
loginSuccess,
|
loginSuccess,
|
||||||
|
@ -81,6 +82,12 @@ describe('test selectedUsers reducer', () => {
|
||||||
expect(state).toEqual(user.username);
|
expect(state).toEqual(user.username);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should clear user after clearUser', () => {
|
||||||
|
mockedStore.dispatch(clearUser());
|
||||||
|
const state = mockedStore.getState().login.user;
|
||||||
|
expect(state).toEqual({});
|
||||||
|
});
|
||||||
|
|
||||||
// TODO PREFERENCE REDUCER WITH EMPTY PREFERENCE - NON USED?
|
// TODO PREFERENCE REDUCER WITH EMPTY PREFERENCE - NON USED?
|
||||||
// it('should return modified store after setPreference', () => {
|
// it('should return modified store after setPreference', () => {
|
||||||
// mockedStore.dispatch(setPreference({ showAvatar: true }));
|
// mockedStore.dispatch(setPreference({ showAvatar: true }));
|
||||||
|
|
|
@ -80,6 +80,13 @@ export default function login(state = initialState, action: TActionsLogin): ILog
|
||||||
...action.user
|
...action.user
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
case types.USER.CLEAR:
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
user: {},
|
||||||
|
isAuthenticated: false,
|
||||||
|
isLocalAuthenticated: false
|
||||||
|
};
|
||||||
case types.LOGIN.SET_SERVICES:
|
case types.LOGIN.SET_SERVICES:
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
|
|
|
@ -9,8 +9,6 @@ import log from '../utils/log';
|
||||||
import mergeSubscriptionsRooms from '../lib/methods/helpers/mergeSubscriptionsRooms';
|
import mergeSubscriptionsRooms from '../lib/methods/helpers/mergeSubscriptionsRooms';
|
||||||
import RocketChat from '../lib/rocketchat';
|
import RocketChat from '../lib/rocketchat';
|
||||||
import buildMessage from '../lib/methods/helpers/buildMessage';
|
import buildMessage from '../lib/methods/helpers/buildMessage';
|
||||||
import protectedFunction from '../lib/methods/helpers/protectedFunction';
|
|
||||||
import UserPreferences from '../lib/userPreferences';
|
|
||||||
|
|
||||||
const updateRooms = function* updateRooms({ server, newRoomsUpdatedAt }) {
|
const updateRooms = function* updateRooms({ server, newRoomsUpdatedAt }) {
|
||||||
const serversDB = database.servers;
|
const serversDB = database.servers;
|
||||||
|
@ -82,33 +80,46 @@ const handleRoomsRequest = function* handleRoomsRequest({ params }) {
|
||||||
})
|
})
|
||||||
),
|
),
|
||||||
...subsToUpdate.map(subscription => {
|
...subsToUpdate.map(subscription => {
|
||||||
const newSub = subscriptions.find(s => s._id === subscription._id);
|
try {
|
||||||
return subscription.prepareUpdate(() => {
|
const newSub = subscriptions.find(s => s._id === subscription._id);
|
||||||
if (newSub.announcement) {
|
return subscription.prepareUpdate(() => {
|
||||||
if (newSub.announcement !== subscription.announcement) {
|
if (newSub.announcement) {
|
||||||
subscription.bannerClosed = false;
|
if (newSub.announcement !== subscription.announcement) {
|
||||||
|
subscription.bannerClosed = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
Object.assign(subscription, newSub);
|
||||||
Object.assign(subscription, newSub);
|
});
|
||||||
});
|
} catch (e) {
|
||||||
|
log(e);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
...subsToDelete.map(subscription => {
|
||||||
|
try {
|
||||||
|
return subscription.prepareDestroyPermanently();
|
||||||
|
} catch (e) {
|
||||||
|
log(e);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}),
|
}),
|
||||||
...subsToDelete.map(subscription => subscription.prepareDestroyPermanently()),
|
|
||||||
...messagesToCreate.map(message =>
|
...messagesToCreate.map(message =>
|
||||||
messagesCollection.prepareCreate(
|
messagesCollection.prepareCreate(m => {
|
||||||
protectedFunction(m => {
|
m._raw = sanitizedRaw({ id: message._id }, messagesCollection.schema);
|
||||||
m._raw = sanitizedRaw({ id: message._id }, messagesCollection.schema);
|
m.subscription.id = message.rid;
|
||||||
m.subscription.id = message.rid;
|
return Object.assign(m, message);
|
||||||
return Object.assign(m, message);
|
})
|
||||||
})
|
|
||||||
)
|
|
||||||
),
|
),
|
||||||
...messagesToUpdate.map(message => {
|
...messagesToUpdate.map(message => {
|
||||||
const newMessage = lastMessages.find(m => m._id === message.id);
|
const newMessage = lastMessages.find(m => m._id === message.id);
|
||||||
return message.prepareUpdate(
|
return message.prepareUpdate(() => {
|
||||||
protectedFunction(() => {
|
try {
|
||||||
Object.assign(message, newMessage);
|
return Object.assign(message, newMessage);
|
||||||
})
|
} catch (e) {
|
||||||
);
|
log(e);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
});
|
||||||
})
|
})
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,7 @@ import Navigation from '../lib/Navigation';
|
||||||
import { SERVER } from '../actions/actionsTypes';
|
import { SERVER } from '../actions/actionsTypes';
|
||||||
import { selectServerFailure, selectServerRequest, selectServerSuccess, serverFailure } from '../actions/server';
|
import { selectServerFailure, selectServerRequest, selectServerSuccess, serverFailure } from '../actions/server';
|
||||||
import { clearSettings } from '../actions/settings';
|
import { clearSettings } from '../actions/settings';
|
||||||
import { setUser } from '../actions/login';
|
import { clearUser, setUser } from '../actions/login';
|
||||||
import { clearActiveUsers } from '../actions/activeUsers';
|
import { clearActiveUsers } from '../actions/activeUsers';
|
||||||
import RocketChat from '../lib/rocketchat';
|
import RocketChat from '../lib/rocketchat';
|
||||||
import database from '../lib/database';
|
import database from '../lib/database';
|
||||||
|
@ -111,10 +111,11 @@ const handleSelectServer = function* handleSelectServer({ server, version, fetch
|
||||||
|
|
||||||
if (user) {
|
if (user) {
|
||||||
yield put(clearSettings());
|
yield put(clearSettings());
|
||||||
yield RocketChat.connect({ server, user, logoutOnError: true });
|
|
||||||
yield put(setUser(user));
|
yield put(setUser(user));
|
||||||
|
yield RocketChat.connect({ server, logoutOnError: true });
|
||||||
yield put(appStart({ root: RootEnum.ROOT_INSIDE }));
|
yield put(appStart({ root: RootEnum.ROOT_INSIDE }));
|
||||||
} else {
|
} else {
|
||||||
|
yield put(clearUser());
|
||||||
yield RocketChat.connect({ server });
|
yield RocketChat.connect({ server });
|
||||||
yield put(appStart({ root: RootEnum.ROOT_OUTSIDE }));
|
yield put(appStart({ root: RootEnum.ROOT_OUTSIDE }));
|
||||||
}
|
}
|
||||||
|
|
|
@ -3759,8 +3759,8 @@
|
||||||
integrity sha512-NF5KlFt642ZucP/KHnYGBNYLD6O7bcrZMKfRQlH5Y3/1xpnPX1g4wuygtiV7XArMU1FopQT+qmCUPPj8IMDTcw==
|
integrity sha512-NF5KlFt642ZucP/KHnYGBNYLD6O7bcrZMKfRQlH5Y3/1xpnPX1g4wuygtiV7XArMU1FopQT+qmCUPPj8IMDTcw==
|
||||||
|
|
||||||
"@rocket.chat/sdk@RocketChat/Rocket.Chat.js.SDK#mobile":
|
"@rocket.chat/sdk@RocketChat/Rocket.Chat.js.SDK#mobile":
|
||||||
version "1.2.0-mobile"
|
version "1.3.0-mobile"
|
||||||
resolved "https://codeload.github.com/RocketChat/Rocket.Chat.js.SDK/tar.gz/9d18d628b87742302bfa0789d38bbd0c66118941"
|
resolved "https://codeload.github.com/RocketChat/Rocket.Chat.js.SDK/tar.gz/454b4ba784095057b8de862eb99340311b672e15"
|
||||||
dependencies:
|
dependencies:
|
||||||
js-sha256 "^0.9.0"
|
js-sha256 "^0.9.0"
|
||||||
lru-cache "^4.1.1"
|
lru-cache "^4.1.1"
|
||||||
|
|
Loading…
Reference in New Issue