Skip to content
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

[IMPROVEMENT] Stop inserting last message as message object from rooms stream if room is focused #2069

Merged
merged 3 commits into from
Apr 30, 2020
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.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const ROOMS = createRequestTypes('ROOMS', [
'OPEN_SEARCH_HEADER',
'CLOSE_SEARCH_HEADER'
]);
export const ROOM = createRequestTypes('ROOM', ['LEAVE', 'DELETE', 'REMOVED', 'USER_TYPING']);
export const ROOM = createRequestTypes('ROOM', ['SUBSCRIBE', 'UNSUBSCRIBE', 'LEAVE', 'DELETE', 'REMOVED', 'USER_TYPING']);
export const APP = createRequestTypes('APP', ['START', 'READY', 'INIT', 'INIT_LOCAL_SETTINGS']);
export const MESSAGES = createRequestTypes('MESSAGES', ['REPLY_BROADCAST']);
export const CREATE_CHANNEL = createRequestTypes('CREATE_CHANNEL', [...defaultTypes]);
Expand Down
14 changes: 14 additions & 0 deletions app/actions/room.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
import * as types from './actionsTypes';

export function subscribeRoom(rid) {
return {
type: types.ROOM.SUBSCRIBE,
rid
};
}

export function unsubscribeRoom(rid) {
return {
type: types.ROOM.UNSUBSCRIBE,
rid
};
}

export function leaveRoom(rid, t) {
return {
type: types.ROOM.LEAVE,
Expand Down
5 changes: 5 additions & 0 deletions app/lib/methods/subscriptions/room.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import reduxStore from '../../createStore';
import { addUserTyping, removeUserTyping, clearUserTyping } from '../../../actions/usersTyping';
import debounce from '../../../utils/debounce';
import RocketChat from '../../rocketchat';
import { subscribeRoom, unsubscribeRoom } from '../../../actions/room';

const WINDOW_TIME = 1000;

Expand Down Expand Up @@ -38,6 +39,8 @@ export default class RoomSubscription {
if (!this.isAlive) {
this.unsubscribe();
}

reduxStore.dispatch(subscribeRoom(this.rid));
}

unsubscribe = async() => {
Expand All @@ -59,6 +62,8 @@ export default class RoomSubscription {
if (this.timer) {
clearTimeout(this.timer);
}

reduxStore.dispatch(unsubscribeRoom(this.rid));
}

removeListener = async(promise) => {
Expand Down
3 changes: 2 additions & 1 deletion app/lib/methods/subscriptions/rooms.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,8 @@ const createOrUpdateSubscription = async(subscription, room) => {
}
}

if (tmp.lastMessage) {
const { rooms } = store.getState().room;
if (tmp.lastMessage && !rooms.includes(tmp.rid)) {
const lastMessage = buildMessage(tmp.lastMessage);
const messagesCollection = db.collections.get('messages');
let messageRecord;
Expand Down
14 changes: 13 additions & 1 deletion app/reducers/room.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,23 @@ import { ROOM } from '../actions/actionsTypes';

const initialState = {
rid: null,
isDeleting: false
isDeleting: false,
rooms: []
};

export default function(state = initialState, action) {
switch (action.type) {
case ROOM.SUBSCRIBE:
return {
...state,
rooms: [action.rid, ...state.rooms]
};
case ROOM.UNSUBSCRIBE:
return {
...state,
rooms: state.rooms
.filter(room => room.rid === action.rid)
};
case ROOM.LEAVE:
return {
...state,
Expand Down