Skip to content
Closed
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
22 changes: 14 additions & 8 deletions app/lib/methods/subscriptions/room.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import reduxStore from '../../createStore';
import { addUserTyping, removeUserTyping, clearUserTyping } from '../../../actions/usersTyping';
import debounce from '../../../utils/debounce';

const unsubscribe = subscriptions => subscriptions.forEach(sub => sub.unsubscribe().catch(() => console.log('unsubscribeRoom')));
const unsubscribe = (subscriptions = []) => Promise.all(subscriptions.map(sub => sub.unsubscribe));
const removeListener = listener => listener.stop();

export default function subscribeRoom({ rid }) {
Expand Down Expand Up @@ -197,25 +197,31 @@ export default function subscribeRoom({ rid }) {
});
});

const stop = () => {
const stop = async() => {
let params;
if (promises) {
promises.then(unsubscribe);
params = await promises;
await unsubscribe(params);
promises = false;
}
if (connectedListener) {
connectedListener.then(removeListener);
params = await connectedListener;
removeListener(params);
connectedListener = false;
}
if (disconnectedListener) {
disconnectedListener.then(removeListener);
params = await disconnectedListener;
removeListener(params);
disconnectedListener = false;
}
if (notifyRoomListener) {
notifyRoomListener.then(removeListener);
params = await notifyRoomListener;
removeListener(params);
notifyRoomListener = false;
}
if (messageReceivedListener) {
messageReceivedListener.then(removeListener);
params = await messageReceivedListener;
removeListener(params);
messageReceivedListener = false;
}
reduxStore.dispatch(clearUserTyping());
Expand All @@ -233,6 +239,6 @@ export default function subscribeRoom({ rid }) {
}

return {
stop: () => stop()
stop
};
}
6 changes: 3 additions & 3 deletions app/views/RoomView/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ class RoomView extends React.Component {
this.setLastOpen(null);
}
RocketChat.readMessages(room.rid, newLastOpen).catch(e => console.log(e));
this.unsubscribe();
await this.unsubscribe();
this.sub = await RocketChat.subscribeRoom(room);
}
}
Expand Down Expand Up @@ -390,9 +390,9 @@ class RoomView extends React.Component {
}
}

unsubscribe = () => {
unsubscribe = async() => {
if (this.sub && this.sub.stop) {
this.sub.stop();
await this.sub.stop();
}
}

Expand Down