Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
838f666
[WIP] Reopen without timeOut & ping with 5 sec & Fix Unsubscribe
djorkaeffalexandre Mar 11, 2020
2de060c
[FIX] Remove duplicated close
djorkaeffalexandre Mar 11, 2020
9308eab
[FIX] Use no-dist lib
djorkaeffalexandre Mar 13, 2020
b629e57
[FIX] Try minor fix
djorkaeffalexandre Mar 16, 2020
11b2117
[FIX] Try reopen connection when app was put on foreground
djorkaeffalexandre Mar 17, 2020
b4d70b7
[FIX] Remove timeout
djorkaeffalexandre Mar 17, 2020
f985160
[FIX] Build
djorkaeffalexandre Mar 17, 2020
8dd4ebe
[FIX] Patch
djorkaeffalexandre Mar 17, 2020
093bd05
[FIX] Snapshot
djorkaeffalexandre Mar 17, 2020
d996455
[IMPROVEMENT] Decrease time to reopen
djorkaeffalexandre Mar 17, 2020
0abbf73
[FIX] Some fixes
djorkaeffalexandre Mar 19, 2020
761bee6
Merge branch 'develop' of https://github.com/RocketChat/Rocket.Chat.R…
djorkaeffalexandre Mar 19, 2020
fbfc77e
[FIX] Update sdk version
djorkaeffalexandre Mar 19, 2020
db426e0
[FIX] Subscribe Room Once
djorkaeffalexandre Mar 19, 2020
5ba4845
[CHORE] Update sdk
djorkaeffalexandre Mar 19, 2020
89bc5bf
[FIX] Subscribe Room
djorkaeffalexandre Mar 19, 2020
ca09e93
[FIX] Try to resend missed subs
djorkaeffalexandre Mar 19, 2020
245c93c
[FIX] Users never show status when start app without network
djorkaeffalexandre Mar 20, 2020
2bd622a
[FIX] Subscribe to room
djorkaeffalexandre Mar 20, 2020
40abc98
[FIX] Multiple servers
djorkaeffalexandre Mar 20, 2020
1adc2d5
[CHORE] Update SDK
djorkaeffalexandre Mar 20, 2020
59823ca
[FIX] Don't duplicate streams on subscribeAll
djorkaeffalexandre Mar 20, 2020
b6b936f
[FIX] Server version when start the app offline
djorkaeffalexandre Mar 23, 2020
90f0a62
[FIX] Server version cached
djorkaeffalexandre Mar 23, 2020
0d1ea0d
Merge branch 'develop' of https://github.com/RocketChat/Rocket.Chat.R…
djorkaeffalexandre Mar 23, 2020
a416ee9
[CHORE] Remove unnecessary code
djorkaeffalexandre Mar 23, 2020
cb4a3f8
[FIX] Offline server version
djorkaeffalexandre Mar 24, 2020
fe30e26
[FIX] Subscribe before connect
djorkaeffalexandre Mar 24, 2020
8abd36b
[FIX] Remove unncessary props
djorkaeffalexandre Mar 24, 2020
c876ddb
[FIX] Update sdk
djorkaeffalexandre Mar 26, 2020
4530a82
[FIX] User status & Unsubscribe Typing
djorkaeffalexandre Mar 27, 2020
4a55277
[FIX] Typing at incorrect room
djorkaeffalexandre Mar 27, 2020
d2f90eb
[FIX] Multiple Servers
djorkaeffalexandre Mar 27, 2020
c40800d
Merge branch 'develop' of https://github.com/RocketChat/Rocket.Chat.R…
djorkaeffalexandre Mar 27, 2020
c3dec9d
[CHORE] Update SDK
djorkaeffalexandre Mar 27, 2020
8f8f1dc
[REVERT] Undo some changes on SDK
djorkaeffalexandre Mar 27, 2020
a2dbfae
[CHORE] Update sdk to prevent incorrect subscribes
djorkaeffalexandre Mar 27, 2020
e3d0e92
[FIX] Prevent no reconnect
djorkaeffalexandre Mar 27, 2020
a5ae6f3
[FIX] Remove close on open
djorkaeffalexandre Mar 27, 2020
5a4f413
[FIX] Clear typing when disconnect/connect to SDK
djorkaeffalexandre Mar 28, 2020
3236ddc
[CHORE] Update SDK
djorkaeffalexandre Mar 28, 2020
fe3139c
[CHORE] Update SDK
djorkaeffalexandre Mar 28, 2020
185a643
Merge branch 'develop' into test.sdk-disconnect
diegolmello Mar 30, 2020
827749a
Merge Develop
djorkaeffalexandre Apr 1, 2020
eed9cad
Update SDK
djorkaeffalexandre Apr 1, 2020
2fb0110
fix merge develop
djorkaeffalexandre Apr 1, 2020
17ded17
Merge branch 'develop' into test.sdk-disconnect
diegolmello Apr 1, 2020
e902b4c
Merge branch 'develop' into test.sdk-disconnect
diegolmello Apr 3, 2020
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: 2 additions & 0 deletions __mocks__/@rocket.chat/sdk.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export class Rocketchat {}
export const settings = {};
190 changes: 95 additions & 95 deletions __tests__/__snapshots__/Storyshots.test.js.snap

Large diffs are not rendered by default.

43 changes: 26 additions & 17 deletions app/lib/methods/getUsersPresence.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ import semver from 'semver';

import reduxStore from '../createStore';
import { setActiveUsers } from '../../actions/activeUsers';
import { setUser } from '../../actions/login';

export function subscribeUsersPresence() {
const serverVersion = reduxStore.getState().server.version;

// if server is lower than 1.1.0
if (serverVersion && semver.lt(semver.coerce(serverVersion), '1.1.0')) {
if (serverVersion && semver.lt(serverVersion, '1.1.0')) {
if (this.activeUsersSubTimeout) {
clearTimeout(this.activeUsersSubTimeout);
this.activeUsersSubTimeout = false;
Expand All @@ -25,35 +26,43 @@ let ids = [];

export default async function getUsersPresence() {
const serverVersion = reduxStore.getState().server.version;
const { user: loggedUser } = reduxStore.getState().login;

// if server is greather than or equal 1.1.0
if (serverVersion && !semver.lt(semver.coerce(serverVersion), '1.1.0')) {
if (serverVersion && semver.gte(serverVersion, '1.1.0')) {
let params = {};

// if server is greather than or equal 3.0.0
if (serverVersion && !semver.lt(semver.coerce(serverVersion), '3.0.0')) {
if (serverVersion && semver.gte(serverVersion, '3.0.0')) {
// if not have any id
if (!ids.length) {
return;
}
// Request userPresence on demand
params = { ids: ids.join(',') };
ids = [];
}

// RC 1.1.0
const result = await this.sdk.get('users.presence', params);
if (result.success) {
const activeUsers = result.users.reduce((ret, item) => {
ret[item._id] = {
status: item.status,
statusText: item.statusText
};
return ret;
}, {});
InteractionManager.runAfterInteractions(() => {
reduxStore.dispatch(setActiveUsers(activeUsers));
});
try {
// RC 1.1.0
const result = await this.sdk.get('users.presence', params);
if (result.success) {
const activeUsers = result.users.reduce((ret, item) => {
const { _id, status, statusText } = item;

if (loggedUser && loggedUser.id === _id) {
reduxStore.dispatch(setUser({ status, statusText }));
}

ret[_id] = { status, statusText };
return ret;
}, {});
InteractionManager.runAfterInteractions(() => {
reduxStore.dispatch(setActiveUsers(activeUsers));
});
ids = [];
}
} catch {
// do nothing
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion app/lib/methods/subscriptions/room.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ export default class RoomSubscription {
// do nothing
}
}
reduxStore.dispatch(clearUserTyping());
this.removeListener(this.connectedListener);
this.removeListener(this.disconnectedListener);
this.removeListener(this.notifyRoomListener);
this.removeListener(this.messageReceivedListener);
reduxStore.dispatch(clearUserTyping());
if (this.timer) {
clearTimeout(this.timer);
}
Expand All @@ -73,6 +73,7 @@ export default class RoomSubscription {
};

handleConnection = () => {
reduxStore.dispatch(clearUserTyping());
RocketChat.loadMissedMessages({ rid: this.rid }).catch(e => console.log(e));
};

Expand Down
21 changes: 12 additions & 9 deletions app/lib/rocketchat.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,12 @@ const RocketChat = {
TOKEN_KEY,
callJitsi,
async subscribeRooms() {
if (this.roomsSub) {
this.roomsSub.stop();
}
try {
this.roomsSub = await subscribeRooms.call(this);
} catch (e) {
log(e);
if (!this.roomsSub) {
try {
this.roomsSub = await subscribeRooms.call(this);
} catch (e) {
log(e);
}
}
},
canOpenRoom,
Expand Down Expand Up @@ -189,6 +188,7 @@ const RocketChat = {

if (this.roomsSub) {
this.roomsSub.stop();
this.roomsSub = null;
}

if (this.sdk) {
Expand All @@ -206,7 +206,7 @@ const RocketChat = {
this.sdk = new RocketchatClient({ host: server, protocol: 'ddp', useSsl });
this.getSettings();

this.sdk.connect()
const sdkConnect = () => this.sdk.connect()
.then(() => {
if (user && user.token) {
reduxStore.dispatch(loginRequest({ resume: user.token }, logoutOnError));
Expand All @@ -217,10 +217,12 @@ const RocketChat = {

// when `connect` raises an error, we try again in 10 seconds
this.connectTimeout = setTimeout(() => {
this.connect({ server, user });
sdkConnect();
}, 10000);
});

sdkConnect();

this.connectedListener = this.sdk.onStreamData('connected', () => {
reduxStore.dispatch(connectSuccess());
});
Expand Down Expand Up @@ -410,6 +412,7 @@ const RocketChat = {
async logout({ server }) {
if (this.roomsSub) {
this.roomsSub.stop();
this.roomsSub = null;
}

if (this.activeUsersSubTimeout) {
Expand Down
9 changes: 6 additions & 3 deletions app/presentation/RoomItem/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const attrs = [
'isRead',
'favorite',
'status',
'connected',
'theme'
];

Expand All @@ -40,13 +41,13 @@ const arePropsEqual = (oldProps, newProps) => {
};

const RoomItem = React.memo(({
onPress, width, favorite, toggleFav, isRead, rid, toggleRead, hideChannel, testID, unread, userMentions, name, _updatedAt, alert, type, avatarSize, baseUrl, userId, username, token, id, prid, showLastMessage, hideUnreadStatus, lastMessage, status, avatar, useRealName, getUserPresence, isGroupChat, theme
onPress, width, favorite, toggleFav, isRead, rid, toggleRead, hideChannel, testID, unread, userMentions, name, _updatedAt, alert, type, avatarSize, baseUrl, userId, username, token, id, prid, showLastMessage, hideUnreadStatus, lastMessage, status, avatar, useRealName, getUserPresence, isGroupChat, connected, theme
}) => {
useEffect(() => {
if (type === 'd') {
if (connected && type === 'd' && id) {
getUserPresence(id);
}
}, []);
}, [connected]);

const date = formatDate(_updatedAt);

Expand Down Expand Up @@ -197,6 +198,7 @@ RoomItem.propTypes = {
hideUnreadStatus: PropTypes.bool,
useRealName: PropTypes.bool,
getUserPresence: PropTypes.func,
connected: PropTypes.bool,
isGroupChat: PropTypes.bool,
theme: PropTypes.string
};
Expand All @@ -208,6 +210,7 @@ RoomItem.defaultProps = {
};

const mapStateToProps = (state, ownProps) => ({
connected: state.meteor.connected,
status:
state.meteor.connected && ownProps.type === 'd'
? state.activeUsers[ownProps.id] && state.activeUsers[ownProps.id].status
Expand Down
4 changes: 3 additions & 1 deletion app/sagas/login.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,16 @@ const registerPushToken = function* registerPushToken() {

const fetchUsersPresence = function* fetchUserPresence() {
yield RocketChat.getUsersPresence();
yield RocketChat.subscribeUsersPresence();
RocketChat.subscribeUsersPresence();
};

const handleLoginSuccess = function* handleLoginSuccess({ user }) {
try {
const adding = yield select(state => state.server.adding);
yield RNUserDefaults.set(RocketChat.TOKEN_KEY, user.token);

RocketChat.getUserPresence(user.id);

const server = yield select(getServer);
yield put(roomsRequest());
yield fork(fetchPermissions);
Expand Down
9 changes: 6 additions & 3 deletions app/sagas/selectServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,23 @@ const getServerInfo = function* getServerInfo({ server, raiseError = true }) {
return;
}

const validVersion = semver.coerce(serverInfo.version);
let serverVersion = semver.valid(serverInfo.version);
if (!serverVersion) {
({ version: serverVersion } = semver.coerce(serverInfo.version));
}

const serversDB = database.servers;
const serversCollection = serversDB.collections.get('servers');
yield serversDB.action(async() => {
try {
const serverRecord = await serversCollection.find(server);
await serverRecord.update((record) => {
record.version = validVersion;
record.version = serverVersion;
});
} catch (e) {
await serversCollection.create((record) => {
record._raw = sanitizedRaw({ id: server }, serversCollection.schema);
record.version = validVersion;
record.version = serverVersion;
});
}
});
Expand Down
4 changes: 3 additions & 1 deletion app/views/RoomView/Header/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,10 @@ const mapStateToProps = (state, ownProps) => {
if (type === 'd') {
const user = getUserSelector(state);
if (user.id) {
if (state.activeUsers[roomUserId]) {
if (state.activeUsers[roomUserId] && state.meteor.connected) {
({ status, statusText } = state.activeUsers[roomUserId]);
} else {
status = 'offline';
}
}
}
Expand Down
12 changes: 7 additions & 5 deletions app/views/RoomView/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,10 +222,13 @@ class RoomView extends React.Component {
if (this.tmid) {
navigation.setParams({ toggleFollowThread: this.toggleFollowThread, goRoomActionsView: this.goRoomActionsView });
}
if (isAuthenticated && this.rid) {
this.init();
} else if (this.rid) {
EventEmitter.addEventListener('connected', this.handleConnected);
if (this.rid) {
this.sub.subscribe();
if (isAuthenticated) {
this.init();
} else {
EventEmitter.addEventListener('connected', this.handleConnected);
}
}
if (isIOS && this.rid) {
this.updateUnreadCount();
Expand Down Expand Up @@ -361,7 +364,6 @@ class RoomView extends React.Component {
this.setLastOpen(null);
}
RocketChat.readMessages(room.rid, newLastOpen, true).catch(e => console.log(e));
this.sub.subscribe();
}
}

Expand Down
4 changes: 4 additions & 0 deletions app/views/RoomsListView/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ class RoomsListView extends React.Component {
roomsRequest: PropTypes.func,
closeServerDropdown: PropTypes.func,
useRealName: PropTypes.bool,
connected: PropTypes.bool,
split: PropTypes.bool
};

Expand Down Expand Up @@ -302,6 +303,7 @@ class RoomsListView extends React.Component {
showFavorites,
showUnread,
appState,
connected,
roomsRequest
} = this.props;

Expand All @@ -317,6 +319,7 @@ class RoomsListView extends React.Component {
} else if (
appState === 'foreground'
&& appState !== prevProps.appState
&& connected
) {
roomsRequest();
}
Expand Down Expand Up @@ -894,6 +897,7 @@ class RoomsListView extends React.Component {
const mapStateToProps = state => ({
user: getUserSelector(state),
server: state.server.server,
connected: state.server.connected,
searchText: state.rooms.searchText,
loadingServer: state.server.loading,
showServerDropdown: state.rooms.showServerDropdown,
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"@react-native-community/cameraroll": "^1.3.0",
"@react-native-community/datetimepicker": "^2.1.0",
"@react-native-community/slider": "2.0.5",
"@rocket.chat/sdk": "1.0.0-alpha.41",
"@rocket.chat/sdk": "djorkaeffalexandre/Rocket.Chat.js.SDK#test.fix-ddp",
"@rocket.chat/ui-kit": "^0.2.0-alpha.25",
"base-64": "^0.1.0",
"bugsnag-react-native": "2.23.2",
Expand Down Expand Up @@ -70,7 +70,7 @@
"react-native-keyboard-tracking-view": "^5.6.1",
"react-native-keycommands": "2.0.3",
"react-native-localize": "1.3.1",
"react-native-mime-types": "^2.2.1",
"react-native-mime-types": "2.2.1",
"react-native-modal": "11.5.3",
"react-native-modalize": "^1.3.6",
"react-native-navigation-bar-color": "^1.0.0",
Expand Down
63 changes: 0 additions & 63 deletions patches/@rocket.chat+sdk+1.0.0-alpha.41.patch

This file was deleted.

Loading