[IMPROVEMENT] Stop inserting last message as message object from rooms stream if room is focused (#2069)
* [IMPROVEMENT] No insert last message if the room is focused * fix discussion/threads Co-authored-by: Diego Mello <diegolmello@gmail.com>
This commit is contained in:
parent
022b0330bf
commit
4e948f897c
|
@ -31,7 +31,7 @@ export const ROOMS = createRequestTypes('ROOMS', [
|
||||||
'OPEN_SEARCH_HEADER',
|
'OPEN_SEARCH_HEADER',
|
||||||
'CLOSE_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 APP = createRequestTypes('APP', ['START', 'READY', 'INIT', 'INIT_LOCAL_SETTINGS']);
|
||||||
export const MESSAGES = createRequestTypes('MESSAGES', ['REPLY_BROADCAST']);
|
export const MESSAGES = createRequestTypes('MESSAGES', ['REPLY_BROADCAST']);
|
||||||
export const CREATE_CHANNEL = createRequestTypes('CREATE_CHANNEL', [...defaultTypes]);
|
export const CREATE_CHANNEL = createRequestTypes('CREATE_CHANNEL', [...defaultTypes]);
|
||||||
|
|
|
@ -1,5 +1,19 @@
|
||||||
import * as types from './actionsTypes';
|
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) {
|
export function leaveRoom(rid, t) {
|
||||||
return {
|
return {
|
||||||
type: types.ROOM.LEAVE,
|
type: types.ROOM.LEAVE,
|
||||||
|
|
|
@ -10,6 +10,7 @@ import reduxStore from '../../createStore';
|
||||||
import { addUserTyping, removeUserTyping, clearUserTyping } from '../../../actions/usersTyping';
|
import { addUserTyping, removeUserTyping, clearUserTyping } from '../../../actions/usersTyping';
|
||||||
import debounce from '../../../utils/debounce';
|
import debounce from '../../../utils/debounce';
|
||||||
import RocketChat from '../../rocketchat';
|
import RocketChat from '../../rocketchat';
|
||||||
|
import { subscribeRoom, unsubscribeRoom } from '../../../actions/room';
|
||||||
|
|
||||||
const WINDOW_TIME = 1000;
|
const WINDOW_TIME = 1000;
|
||||||
|
|
||||||
|
@ -38,6 +39,8 @@ export default class RoomSubscription {
|
||||||
if (!this.isAlive) {
|
if (!this.isAlive) {
|
||||||
this.unsubscribe();
|
this.unsubscribe();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
reduxStore.dispatch(subscribeRoom(this.rid));
|
||||||
}
|
}
|
||||||
|
|
||||||
unsubscribe = async() => {
|
unsubscribe = async() => {
|
||||||
|
@ -59,6 +62,8 @@ export default class RoomSubscription {
|
||||||
if (this.timer) {
|
if (this.timer) {
|
||||||
clearTimeout(this.timer);
|
clearTimeout(this.timer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
reduxStore.dispatch(unsubscribeRoom(this.rid));
|
||||||
}
|
}
|
||||||
|
|
||||||
removeListener = async(promise) => {
|
removeListener = async(promise) => {
|
||||||
|
|
|
@ -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 lastMessage = buildMessage(tmp.lastMessage);
|
||||||
const messagesCollection = db.collections.get('messages');
|
const messagesCollection = db.collections.get('messages');
|
||||||
let messageRecord;
|
let messageRecord;
|
||||||
|
|
|
@ -2,11 +2,23 @@ import { ROOM } from '../actions/actionsTypes';
|
||||||
|
|
||||||
const initialState = {
|
const initialState = {
|
||||||
rid: null,
|
rid: null,
|
||||||
isDeleting: false
|
isDeleting: false,
|
||||||
|
rooms: []
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function(state = initialState, action) {
|
export default function(state = initialState, action) {
|
||||||
switch (action.type) {
|
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:
|
case ROOM.LEAVE:
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
|
|
Loading…
Reference in New Issue