Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/actions/actionsTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ function createRequestTypes(base = {}, types = defaultTypes): Record<string, str
// Login events
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 USER = createRequestTypes('USER', ['SET']);
export const USER = createRequestTypes('USER', ['SET', 'CLEAR']);
export const ROOMS = createRequestTypes('ROOMS', [
...defaultTypes,
'REFRESH',
Expand Down
6 changes: 6 additions & 0 deletions app/actions/login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
return {
type: types.LOGIN.SET_SERVICES,
Expand Down
13 changes: 10 additions & 3 deletions app/lib/methods/subscriptions/room.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,16 @@ export default class RoomSubscription {
}
};

handleConnection = () => {
reduxStore.dispatch(clearUserTyping());
RocketChat.loadMissedMessages({ rid: this.rid }).catch(e => console.log(e));
handleConnection = async () => {
try {
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) => {
Expand Down
10 changes: 5 additions & 5 deletions app/lib/rocketchat/services/connect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { loginRequest, setLoginServices, setUser } from '../../../actions/login'
import sdk from './sdk';
import I18n from '../../../i18n';
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 { connectRequest, connectSuccess, disconnect as disconnectAction } from '../../../actions/connect';
import { updatePermission } from '../../../actions/permissions';
Expand All @@ -38,8 +38,8 @@ interface IServices {
// FIXME: Remove `this` context
function connect(
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 => {
if (sdk.current?.client?.host === server) {
return resolve();
Expand Down Expand Up @@ -107,8 +107,8 @@ function connect(
return;
}
store.dispatch(connectSuccess());
const { server: currentServer } = store.getState().server;
if (user?.token && server === currentServer) {
const { user } = store.getState().login;
if (user?.token) {
store.dispatch(loginRequest({ resume: user.token }, logoutOnError));
}
});
Expand Down
7 changes: 7 additions & 0 deletions app/reducers/login.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
clearUser,
loginFailure,
loginRequest,
loginSuccess,
Expand Down Expand Up @@ -81,6 +82,12 @@ describe('test selectedUsers reducer', () => {
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?
// it('should return modified store after setPreference', () => {
// mockedStore.dispatch(setPreference({ showAvatar: true }));
Expand Down
7 changes: 7 additions & 0 deletions app/reducers/login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,13 @@ export default function login(state = initialState, action: TActionsLogin): ILog
...action.user
}
};
case types.USER.CLEAR:
return {
...state,
user: {},
isAuthenticated: false,
isLocalAuthenticated: false
};
case types.LOGIN.SET_SERVICES:
return {
...state,
Expand Down
57 changes: 34 additions & 23 deletions app/sagas/rooms.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import log from '../utils/log';
import mergeSubscriptionsRooms from '../lib/methods/helpers/mergeSubscriptionsRooms';
import RocketChat from '../lib/rocketchat';
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 serversDB = database.servers;
Expand Down Expand Up @@ -82,33 +80,46 @@ const handleRoomsRequest = function* handleRoomsRequest({ params }) {
})
),
...subsToUpdate.map(subscription => {
const newSub = subscriptions.find(s => s._id === subscription._id);
return subscription.prepareUpdate(() => {
if (newSub.announcement) {
if (newSub.announcement !== subscription.announcement) {
subscription.bannerClosed = false;
try {
const newSub = subscriptions.find(s => s._id === subscription._id);
return subscription.prepareUpdate(() => {
if (newSub.announcement) {
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 =>
messagesCollection.prepareCreate(
protectedFunction(m => {
m._raw = sanitizedRaw({ id: message._id }, messagesCollection.schema);
m.subscription.id = message.rid;
return Object.assign(m, message);
})
)
messagesCollection.prepareCreate(m => {
m._raw = sanitizedRaw({ id: message._id }, messagesCollection.schema);
m.subscription.id = message.rid;
return Object.assign(m, message);
})
),
...messagesToUpdate.map(message => {
const newMessage = lastMessages.find(m => m._id === message.id);
return message.prepareUpdate(
protectedFunction(() => {
Object.assign(message, newMessage);
})
);
return message.prepareUpdate(() => {
try {
return Object.assign(message, newMessage);
} catch (e) {
log(e);
return null;
}
});
})
];

Expand Down
5 changes: 3 additions & 2 deletions app/sagas/selectServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Navigation from '../lib/Navigation';
import { SERVER } from '../actions/actionsTypes';
import { selectServerFailure, selectServerRequest, selectServerSuccess, serverFailure } from '../actions/server';
import { clearSettings } from '../actions/settings';
import { setUser } from '../actions/login';
import { clearUser, setUser } from '../actions/login';
import { clearActiveUsers } from '../actions/activeUsers';
import RocketChat from '../lib/rocketchat';
import database from '../lib/database';
Expand Down Expand Up @@ -111,10 +111,11 @@ const handleSelectServer = function* handleSelectServer({ server, version, fetch

if (user) {
yield put(clearSettings());
yield RocketChat.connect({ server, user, logoutOnError: true });
yield put(setUser(user));
yield RocketChat.connect({ server, logoutOnError: true });
yield put(appStart({ root: RootEnum.ROOT_INSIDE }));
} else {
yield put(clearUser());
yield RocketChat.connect({ server });
yield put(appStart({ root: RootEnum.ROOT_OUTSIDE }));
}
Expand Down
4 changes: 2 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3759,8 +3759,8 @@
integrity sha512-NF5KlFt642ZucP/KHnYGBNYLD6O7bcrZMKfRQlH5Y3/1xpnPX1g4wuygtiV7XArMU1FopQT+qmCUPPj8IMDTcw==

"@rocket.chat/sdk@RocketChat/Rocket.Chat.js.SDK#mobile":
version "1.2.0-mobile"
resolved "https://codeload.github.com/RocketChat/Rocket.Chat.js.SDK/tar.gz/9d18d628b87742302bfa0789d38bbd0c66118941"
version "1.3.0-mobile"
resolved "https://codeload.github.com/RocketChat/Rocket.Chat.js.SDK/tar.gz/454b4ba784095057b8de862eb99340311b672e15"
dependencies:
js-sha256 "^0.9.0"
lru-cache "^4.1.1"
Expand Down