Improve error routing, fix dm tab not opening

This commit is contained in:
Ken-Håvard Lieng 2020-06-21 05:13:38 +02:00
parent 1c996822cd
commit ca23b3ded8
4 changed files with 62 additions and 51 deletions

View file

@ -112,6 +112,18 @@ export default function handleSocket({
},
error({ network, target, message }) {
const state = getState();
const tab = state.tab.selected;
if (network === tab.network) {
// Print it in the current channel if the error happened on
// the current network
target = tab.name;
} else if (!state.channels[network]?.[target]) {
// Print it the network tab if the target does not exist
target = null;
}
dispatch(
addMessage({ content: message, type: 'error' }, network, target)
);

View file

@ -1,4 +1,5 @@
import sortBy from 'lodash/sortBy';
import { isChannel } from 'utils';
import createReducer from 'utils/createReducer';
import { updateSelection } from './tab';
import * as actions from './actions';
@ -39,9 +40,10 @@ export default createReducer(
});
},
[actions.socket.PM](state, action) {
if (action.from.indexOf('.') === -1) {
open(state, action.network, action.from);
[actions.ADD_MESSAGE](state, { message }) {
const { network, from } = message;
if (from !== network && !isChannel(from)) {
open(state, network, from);
}
},