weechatRN

Weechat relay client for iOS using websockets https://github.com/mhoran/weechatRN
git clone http://git.hanabi.in/repos/weechatRN.git
Log | Files | Refs | README | LICENSE

commit f5db0c711471c25f346db0e15e1189a0950a498c
parent 6e69493fa246734ed63ba61f2f002a1a42efbf8c
Author: Johan Lindskogen <johan.lindskogen@gmail.com>
Date:   Sun,  1 Apr 2018 21:22:44 +0200

Set hotlist from line_added, clear hotlist for buffer when selecting

Diffstat:
Msrc/store/buffers.ts | 3+--
Msrc/store/hotlists.ts | 18++++++++++++++++++
Msrc/store/selectors.ts | 8++++----
Msrc/usecase/App.tsx | 2++
Msrc/usecase/Root.tsx | 8++++++++
Msrc/usecase/buffers/ui/BufferListItem.tsx | 2+-
6 files changed, 34 insertions(+), 7 deletions(-)

diff --git a/src/store/buffers.ts b/src/store/buffers.ts @@ -10,8 +10,7 @@ export default (state: BufferState = initialState, action): BufferState => { return action.payload; } case "BUFFER_CLOSED": { - const newState = omit(state, action.bufferId); - return newState; + return omit(state, action.bufferId); } case "BUFFER_OPENED": { return { diff --git a/src/store/hotlists.ts b/src/store/hotlists.ts @@ -1,4 +1,5 @@ import { omit } from "lodash"; +import { getHotlistForBufferId } from "./selectors"; export type HotListState = { [key: string]: Hotlist }; @@ -8,6 +9,23 @@ export default (state: HotListState = initialState, action): HotListState => { switch (action.type) { case "FETCH_HOTLISTS": return action.payload; + case "CHANGE_CURRENT_BUFFER": + return omit(state, action.bufferId); + case "BUFFER_LINE_ADDED": + const payload = action.payload as WeechatLine; + const hotlist = { + ...getHotlistForBufferId(state, action.bufferId) + }; + + if (payload.highlight !== 0) { + hotlist.highlight++; + } + hotlist.sum++; + + return { + ...state, + [action.bufferId]: hotlist + }; default: return state; } diff --git a/src/store/selectors.ts b/src/store/selectors.ts @@ -1,4 +1,4 @@ -import { StoreState } from "."; +import { HotListState } from "./hotlists"; const createEmptyHotlist = (bufferId: string) => ({ buffer: bufferId, @@ -10,11 +10,11 @@ const createEmptyHotlist = (bufferId: string) => ({ }); export const getHotlistForBufferId = ( - state: StoreState, + state: HotListState, bufferId: string ): Hotlist => { - if (bufferId && state.hotlists[bufferId]) { - return state.hotlists[bufferId]; + if (bufferId && state[bufferId]) { + return state[bufferId]; } else { return createEmptyHotlist(bufferId); } diff --git a/src/usecase/App.tsx b/src/usecase/App.tsx @@ -24,6 +24,7 @@ interface Props { currentBuffer: WeechatBuffer | null; fetchLinesForBuffer: (bufferId: string) => void; sendMessageToBuffer: (fullBufferName: string, message: string) => void; + clearHotlistForBuffer: (fullBufferName: string) => void; dispatch: (any) => void; } @@ -39,6 +40,7 @@ class App extends React.Component<Props> { type: "CHANGE_CURRENT_BUFFER", bufferId: buffer.id }); + this.props.clearHotlistForBuffer(buffer.full_name); fetchLinesForBuffer(buffer.id); } }; diff --git a/src/usecase/Root.tsx b/src/usecase/Root.tsx @@ -43,12 +43,20 @@ export default class WeechatNative extends React.Component { sendMessageToBuffer = (fullBufferName: string, message: string) => { connection && connection.send(`(input) input ${fullBufferName} ${message}`); }; + clearHotlistForBuffer = (fullBufferName: string) => { + this.sendMessageToBuffer(fullBufferName, "/buffer set hotlist -1"); + this.sendMessageToBuffer( + fullBufferName, + "/input set_unread_current_buffer" + ); + }; render() { return ( <Provider store={store}> <ConnectionGate> <StatusBar barStyle="light-content" /> <App + clearHotlistForBuffer={this.clearHotlistForBuffer} sendMessageToBuffer={this.sendMessageToBuffer} fetchLinesForBuffer={this.fetchLines} /> diff --git a/src/usecase/buffers/ui/BufferListItem.tsx b/src/usecase/buffers/ui/BufferListItem.tsx @@ -73,7 +73,7 @@ const BufferListItem = (props: Props) => { }; export default connect((state: StoreState, props: Props) => { - const hotlist = getHotlistForBufferId(state, props.buffer.id); + const hotlist = getHotlistForBufferId(state.hotlists, props.buffer.id); return { hotlist }; })(BufferListItem);