commit 38f41a5f00deeb9eabf90a46cb285f0fcdde9a4f
parent 37c80c3744015caf959bc00656dd6289a6c33335
Author: Johan Lindskogen <johan.lindskogen@gmail.com>
Date: Sun, 1 Apr 2018 22:30:50 +0200
Don't increment unread if current buffer
Diffstat:
2 files changed, 18 insertions(+), 6 deletions(-)
diff --git a/src/lib/weechat/action_transformer.ts b/src/lib/weechat/action_transformer.ts
@@ -1,3 +1,5 @@
+import { StoreState } from "../../store";
+
export type WeechatReduxAction = {
type: string;
payload: any;
@@ -20,10 +22,15 @@ export const transformToReduxAction = (data: WeechatResponse<any>) => {
const object = data.objects[0] as WeechatObject<WeechatLine[]>;
const line = object.content[0];
- return {
- type: "BUFFER_LINE_ADDED",
- bufferId: line.buffer,
- payload: line
+ return (dispatch, getState) => {
+ const state: StoreState = getState();
+
+ dispatch({
+ type: "BUFFER_LINE_ADDED",
+ bufferId: line.buffer,
+ currentBufferId: state.app.currentBufferId,
+ payload: line
+ });
};
}
case "_buffer_closing": {
@@ -126,6 +133,6 @@ export const transformToReduxAction = (data: WeechatResponse<any>) => {
}
default:
console.log("unhandled event!", data.id, data);
- return null;
+ return undefined;
}
};
diff --git a/src/store/hotlists.ts b/src/store/hotlists.ts
@@ -11,7 +11,11 @@ export default (state: HotListState = initialState, action): HotListState => {
return action.payload;
case "CHANGE_CURRENT_BUFFER":
return omit(state, action.bufferId);
- case "BUFFER_LINE_ADDED":
+ case "BUFFER_LINE_ADDED": {
+ if (action.bufferId === action.currentBufferId) {
+ return state;
+ }
+
const payload = action.payload as WeechatLine;
const hotlist = {
...getHotlistForBufferId(state, action.bufferId)
@@ -26,6 +30,7 @@ export default (state: HotListState = initialState, action): HotListState => {
...state,
[action.bufferId]: hotlist
};
+ }
default:
return state;
}