Skip to content

Refact lib #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
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
29 changes: 8 additions & 21 deletions app/lib/rocketchat.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { disconnect, connectSuccess, connectRequest } from '../actions/connect';
import { shareSelectServer, shareSetUser, shareSetSettings } from '../actions/share';

import subscribeRooms from './methods/subscriptions/rooms';
import unsubscribeRooms from './rooms';
import getUsersPresence, { getUserPresence, subscribeUsersPresence } from './methods/getUsersPresence';

import protectedFunction from './methods/helpers/protectedFunction';
Expand Down Expand Up @@ -75,21 +76,8 @@ const RocketChat = {
TOKEN_KEY,
CURRENT_SERVER,
callJitsi,
async subscribeRooms() {
if (!this.roomsSub) {
try {
this.roomsSub = await subscribeRooms.call(this);
} catch (e) {
log(e);
}
}
},
unsubscribeRooms() {
if (this.roomsSub) {
this.roomsSub.stop();
this.roomsSub = null;
}
},
subscribeRooms,
unsubscribeRooms,
canOpenRoom,
createChannel({
name, users, type, readOnly, broadcast, encrypted
Expand Down Expand Up @@ -163,12 +151,11 @@ const RocketChat = {
stopListener(listener) {
return listener && listener.stop();
},
// Abort all requests and create a new AbortController
abort() {
abortRequests() {
if (this.controller) {
this.controller.abort();
this.controller.abortRequests();
if (this.sdk) {
this.sdk.abort();
this.sdk.abortRequests();
}
}
this.controller = new AbortController();
Expand Down Expand Up @@ -526,8 +513,8 @@ const RocketChat = {
await serversDB.action(async() => {
const serverCollection = serversDB.collections.get('servers');
const serverRecord = await serverCollection.find(server);
await serverRecord.update((s) => {
s.roomsUpdatedAt = null;
await serverRecord.update((recServer) => {
recServer.roomsUpdatedAt = null;
});
});
} catch (e) {
Expand Down
22 changes: 22 additions & 0 deletions app/lib/rooms.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import subscribeRooms from './methods/subscriptions/rooms';
import log from '../utils/log';

const Rooms = {
async subscribeRooms() {
if (!this.roomsSub) {
try {
this.roomsSub = await subscribeRooms.call(this);
} catch (error) {
log(error);
}
}
},
unsubscribeRooms() {
if (this.roomsSub) {
this.roomsSub.stop();
this.roomsSub = null;
}
}
};

export default Rooms;