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 9834f564f3b5a53aeb16f1acf56f8c2a31cd0c5b
parent ffb67a1229c95728a25b44fcdf2b5e01a01bf305
Author: Johan Lindskogen <johan.lindskogen@gmail.com>
Date:   Sun,  1 Apr 2018 18:56:30 +0200

Add support for opening and closing buffers

Diffstat:
Msrc/lib/weechat/action_transformer.ts | 54++++++++++++++++++++++++++++++++++++++++++++++++++++++
Msrc/store/buffers.ts | 50+++++++++++++++++++++++++++++++++++++++++++++++++-
Msrc/store/lines.ts | 6++++++
3 files changed, 109 insertions(+), 1 deletion(-)

diff --git a/src/lib/weechat/action_transformer.ts b/src/lib/weechat/action_transformer.ts @@ -19,6 +19,60 @@ export const transformToReduxAction = (data: WeechatResponse<any>) => { payload: line }; } + case "_buffer_closing": { + const object = data.objects[0] as WeechatObject<WeechatBuffer[]>; + const buffer = object.content[0]; + + return { + type: "BUFFER_CLOSED", + bufferId: buffer.pointers[0] + }; + } + case "_buffer_opened": { + const object = data.objects[0] as WeechatObject<WeechatBuffer[]>; + const buffer = object.content[0]; + buffer.id = buffer.pointers[0]; + + return { + type: "BUFFER_OPENED", + payload: buffer, + bufferId: buffer.id + }; + } + case "_buffer_renamed": { + const object = data.objects[0] as WeechatObject<WeechatBuffer[]>; + const buffer = object.content[0]; + buffer.id = buffer.pointers[0]; + + return { + type: "BUFFER_RENAMED", + payload: buffer, + bufferId: buffer.id + }; + } + case "_buffer_localvar_removed": { + const object = data.objects[0] as WeechatObject<WeechatBuffer[]>; + const buffer = object.content[0]; + buffer.id = buffer.pointers[0]; + + return { + type: "BUFFER_LOCALVAR_REMOVE", + payload: buffer, + bufferId: buffer.id + }; + } + case "_buffer_title_changed": + case "_buffer_localvar_added": { + const object = data.objects[0] as WeechatObject<WeechatBuffer[]>; + const buffer = object.content[0]; + buffer.id = buffer.pointers[0]; + + return { + type: "BUFFER_LOCALVAR_UPDATE", + payload: buffer, + bufferId: buffer.id + }; + } case "buffers": { const object = data.objects[0] as WeechatObject<WeechatBuffer[]>; diff --git a/src/store/buffers.ts b/src/store/buffers.ts @@ -1,11 +1,59 @@ +import { omit } from "lodash"; + export type BufferState = { [key: string]: WeechatBuffer }; const initialState: BufferState = {}; export default (state: BufferState = initialState, action): BufferState => { switch (action.type) { - case "FETCH_BUFFERS": + case "FETCH_BUFFERS": { return action.payload; + } + case "BUFFER_CLOSED": { + const newState = omit(state, action.bufferId); + return newState; + } + case "BUFFER_OPENED": { + return { + ...state, + [action.bufferId]: action.payload + }; + } + case "BUFFER_LOCALVAR_UPDATE": { + return { + ...state, + [action.bufferId]: { + ...state[action.bufferId], + local_variables: { + ...state[action.bufferId].local_variables, + ...action.payload.local_variables + } + } + }; + } + case "BUFFER_LOCALVAR_REMOVE": { + if (state[action.bufferId]) { + return { + ...state, + [action.bufferId]: { + ...state[action.bufferId], + local_variables: { + ...action.payload.local_variables + } + } + }; + } + } + case "BUFFER_RENAMED": { + return { + ...state, + [action.bufferId]: { + ...state[action.bufferId], + full_name: action.payload.full_name, + short_name: action.payload.short_name + } + }; + } default: return state; } diff --git a/src/store/lines.ts b/src/store/lines.ts @@ -1,3 +1,5 @@ +import { omit } from "lodash"; + export type LineState = { [key: string]: WeechatLine[] }; const initialState: LineState = {}; @@ -9,6 +11,10 @@ export default (state: LineState = initialState, action): LineState => { ...state, [action.bufferId]: action.payload }; + case "BUFFER_CLOSED": { + const newState = omit(state, action.bufferId); + return newState; + } case "BUFFER_LINE_ADDED": return { ...state,