Remove local messages when closing dm tab, avoid sending open_dm if already open
This commit is contained in:
parent
2a72b198e3
commit
08ffc79a65
File diff suppressed because one or more lines are too long
@ -250,6 +250,33 @@ describe('message reducer', () => {
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
it('deletes direct messages when closing a direct message tab', () => {
|
||||
let state = {
|
||||
srv: {
|
||||
bob: [{ content: 'msg1' }, { content: 'msg2' }],
|
||||
'#chan2': [{ content: 'msg' }]
|
||||
},
|
||||
srv2: {
|
||||
'#chan1': [{ content: 'msg' }]
|
||||
}
|
||||
};
|
||||
|
||||
state = reducer(state, {
|
||||
type: actions.CLOSE_PRIVATE_CHAT,
|
||||
server: 'srv',
|
||||
nick: 'bob'
|
||||
});
|
||||
|
||||
expect(state).toEqual({
|
||||
srv: {
|
||||
'#chan2': [{ content: 'msg' }]
|
||||
},
|
||||
srv2: {
|
||||
'#chan1': [{ content: 'msg' }]
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('getMessageTab()', () => {
|
||||
|
@ -140,6 +140,10 @@ export default createReducer(
|
||||
channels.forEach(channel => delete state[server][channel]);
|
||||
},
|
||||
|
||||
[actions.CLOSE_PRIVATE_CHAT](state, { server, nick }) {
|
||||
delete state[server][nick];
|
||||
},
|
||||
|
||||
[actions.socket.CHANNEL_FORWARD](state, { server, old }) {
|
||||
if (state[server]) {
|
||||
delete state[server][old];
|
||||
|
@ -1,5 +1,4 @@
|
||||
import sortBy from 'lodash/sortBy';
|
||||
import { findIndex } from 'utils';
|
||||
import createReducer from 'utils/createReducer';
|
||||
import { updateSelection } from './tab';
|
||||
import * as actions from './actions';
|
||||
@ -10,7 +9,7 @@ function open(state, server, nick) {
|
||||
if (!state[server]) {
|
||||
state[server] = [];
|
||||
}
|
||||
if (findIndex(state[server], n => n === nick) === -1) {
|
||||
if (!state[server].includes(nick)) {
|
||||
state[server].push(nick);
|
||||
state[server] = sortBy(state[server], v => v.toLowerCase());
|
||||
}
|
||||
@ -24,7 +23,7 @@ export default createReducer(
|
||||
},
|
||||
|
||||
[actions.CLOSE_PRIVATE_CHAT](state, { server, nick }) {
|
||||
const i = findIndex(state[server], n => n === nick);
|
||||
const i = state[server]?.findIndex(n => n === nick);
|
||||
if (i !== -1) {
|
||||
state[server].splice(i, 1);
|
||||
}
|
||||
@ -53,13 +52,17 @@ export default createReducer(
|
||||
);
|
||||
|
||||
export function openPrivateChat(server, nick) {
|
||||
return {
|
||||
type: actions.OPEN_PRIVATE_CHAT,
|
||||
server,
|
||||
nick,
|
||||
socket: {
|
||||
type: 'open_dm',
|
||||
data: { server, name: nick }
|
||||
return (dispatch, getState) => {
|
||||
if (!getState().privateChats[server]?.includes(nick)) {
|
||||
dispatch({
|
||||
type: actions.OPEN_PRIVATE_CHAT,
|
||||
server,
|
||||
nick,
|
||||
socket: {
|
||||
type: 'open_dm',
|
||||
data: { server, name: nick }
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user