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()', () => {
|
describe('getMessageTab()', () => {
|
||||||
|
@ -140,6 +140,10 @@ export default createReducer(
|
|||||||
channels.forEach(channel => delete state[server][channel]);
|
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 }) {
|
[actions.socket.CHANNEL_FORWARD](state, { server, old }) {
|
||||||
if (state[server]) {
|
if (state[server]) {
|
||||||
delete state[server][old];
|
delete state[server][old];
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
import sortBy from 'lodash/sortBy';
|
import sortBy from 'lodash/sortBy';
|
||||||
import { findIndex } from 'utils';
|
|
||||||
import createReducer from 'utils/createReducer';
|
import createReducer from 'utils/createReducer';
|
||||||
import { updateSelection } from './tab';
|
import { updateSelection } from './tab';
|
||||||
import * as actions from './actions';
|
import * as actions from './actions';
|
||||||
@ -10,7 +9,7 @@ function open(state, server, nick) {
|
|||||||
if (!state[server]) {
|
if (!state[server]) {
|
||||||
state[server] = [];
|
state[server] = [];
|
||||||
}
|
}
|
||||||
if (findIndex(state[server], n => n === nick) === -1) {
|
if (!state[server].includes(nick)) {
|
||||||
state[server].push(nick);
|
state[server].push(nick);
|
||||||
state[server] = sortBy(state[server], v => v.toLowerCase());
|
state[server] = sortBy(state[server], v => v.toLowerCase());
|
||||||
}
|
}
|
||||||
@ -24,7 +23,7 @@ export default createReducer(
|
|||||||
},
|
},
|
||||||
|
|
||||||
[actions.CLOSE_PRIVATE_CHAT](state, { server, nick }) {
|
[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) {
|
if (i !== -1) {
|
||||||
state[server].splice(i, 1);
|
state[server].splice(i, 1);
|
||||||
}
|
}
|
||||||
@ -53,13 +52,17 @@ export default createReducer(
|
|||||||
);
|
);
|
||||||
|
|
||||||
export function openPrivateChat(server, nick) {
|
export function openPrivateChat(server, nick) {
|
||||||
return {
|
return (dispatch, getState) => {
|
||||||
type: actions.OPEN_PRIVATE_CHAT,
|
if (!getState().privateChats[server]?.includes(nick)) {
|
||||||
server,
|
dispatch({
|
||||||
nick,
|
type: actions.OPEN_PRIVATE_CHAT,
|
||||||
socket: {
|
server,
|
||||||
type: 'open_dm',
|
nick,
|
||||||
data: { server, name: nick }
|
socket: {
|
||||||
|
type: 'open_dm',
|
||||||
|
data: { server, name: nick }
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user