diff --git a/src/reducers/user-lists.ts b/src/reducers/user-lists.ts index f5b7da7c0..518a43d6c 100644 --- a/src/reducers/user-lists.ts +++ b/src/reducers/user-lists.ts @@ -64,6 +64,7 @@ import { FAVOURITES_EXPAND_SUCCESS, DISLIKES_FETCH_SUCCESS, REACTIONS_FETCH_SUCCESS, + ZAPS_FETCH_SUCCESS, } from 'soapbox/actions/interactions'; import { NOTIFICATIONS_UPDATE, @@ -90,6 +91,17 @@ const ReactionListRecord = ImmutableRecord({ isLoading: false, }); +export const ZapRecord = ImmutableRecord({ + account: '', + zap_comment: '', + zap_amount: 0, // in millisats +}); + +const ZapListRecord = ImmutableRecord({ + items: ImmutableOrderedSet(), + isLoading: false, +}); + export const ParticipationRequestRecord = ImmutableRecord({ account: '', participation_message: null as string | null, @@ -108,6 +120,7 @@ export const ReducerRecord = ImmutableRecord({ favourited_by: ImmutableMap(), disliked_by: ImmutableMap(), reactions: ImmutableMap(), + zapped_by: ImmutableMap(), follow_requests: ListRecord(), blocks: ListRecord(), mutes: ListRecord(), @@ -125,10 +138,12 @@ type State = ReturnType; export type List = ReturnType; type Reaction = ReturnType; type ReactionList = ReturnType; +type Zap = ReturnType; +type ZapList = ReturnType; type ParticipationRequest = ReturnType; type ParticipationRequestList = ReturnType; type Items = ImmutableOrderedSet; -type NestedListPath = ['followers' | 'following' | 'reblogged_by' | 'favourited_by' | 'disliked_by' | 'reactions' | 'pinned' | 'birthday_reminders' | 'familiar_followers' | 'event_participations' | 'event_participation_requests' | 'membership_requests' | 'group_blocks', string]; +type NestedListPath = ['followers' | 'following' | 'reblogged_by' | 'favourited_by' | 'disliked_by' | 'reactions' | 'pinned' | 'birthday_reminders' | 'familiar_followers' | 'event_participations' | 'event_participation_requests' | 'membership_requests' | 'group_blocks' | 'zapped_by', string]; type ListPath = ['follow_requests' | 'blocks' | 'mutes' | 'directory']; const normalizeList = (state: State, path: NestedListPath | ListPath, accounts: APIEntity[], next?: string | null) => { @@ -186,6 +201,13 @@ export default function userLists(state = ReducerRecord(), action: AnyAction) { accounts: ImmutableOrderedSet(accounts.map((account: APIEntity) => account.id)), }))), })); + case ZAPS_FETCH_SUCCESS: + return state.setIn(['zapped_by', action.id], ZapListRecord({ + items: ImmutableOrderedSet(action.zaps.map(({ account, ...zap }: APIEntity) => ZapRecord({ + ...zap, + account: account.id, + }))), + })); case NOTIFICATIONS_UPDATE: return action.notification.type === 'follow_request' ? normalizeFollowRequest(state, action.notification) : state; case FOLLOW_REQUESTS_FETCH_SUCCESS: