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

hotlists.ts (1315B)


      1 import { getHotlistForBufferId } from "./selectors";
      2 
      3 export type HotListState = { [key: string]: Hotlist };
      4 
      5 const initialState: HotListState = {};
      6 
      7 export default (state: HotListState = initialState, action): HotListState => {
      8   switch (action.type) {
      9     case "FETCH_HOTLISTS":
     10       if (action.currentBufferId) {
     11         return Object.fromEntries(Object.entries(<HotListState> action.payload)
     12           .filter(([bufferId]) => bufferId !== action.currentBufferId));
     13       }
     14 
     15       return action.payload;
     16     case "CHANGE_CURRENT_BUFFER":
     17       return Object.fromEntries(Object.entries(state)
     18         .filter(([bufferId]) => bufferId !== action.bufferId));
     19     case "BUFFER_LINE_ADDED": {
     20       if (action.bufferId === action.currentBufferId) {
     21         return state;
     22       }
     23 
     24       const payload = action.payload as WeechatLine;
     25       const hotlist = {
     26         ...getHotlistForBufferId(state, action.bufferId)
     27       };
     28 
     29       const shouldNotify = (tag) => (
     30         tag != "irc_smart_filter" && tag != "notify_none"
     31       );
     32       if (payload.tags_array.every(shouldNotify)) {
     33         if (payload.highlight !== 0) {
     34           hotlist.highlight++;
     35         }
     36         hotlist.sum++;
     37       }
     38 
     39       return {
     40         ...state,
     41         [action.bufferId]: hotlist
     42       };
     43     }
     44     default:
     45       return state;
     46   }
     47 };