This repository has no description
Something went wrong. Try again.
1.6 kB · 51 lines
TypeScript
at main
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152// SPDX-License-Identifier: AGPL-3.0-or-later
import type { ReadStateAckBulkRequest, ReadStateAckRequest, ReadStateAckResponse,} from '@fluxer/schema/src/domains/channel/ChannelRequestSchemas';import type {UserID} from '../BrandedTypes';import {createChannelID, createMessageID} from '../BrandedTypes';import {encodeReadStatesResponseProto, mapReadStateResponse} from './ReadStateResponseMapper';import type {ReadStateService} from './ReadStateService';
interface ReadStateAckBulkParams { userId: UserID; data: ReadStateAckBulkRequest;}
interface ReadStateAckParams { userId: UserID; data: ReadStateAckRequest;}
export class ReadStateRequestService { constructor(private readStateService: ReadStateService) {}
async bulkAckMessages({userId, data}: ReadStateAckBulkParams): Promise<void> { await this.readStateService.bulkAckMessages({ userId, readStates: data.read_states.map((readState) => ({ channelId: createChannelID(readState.channel_id), messageId: createMessageID(readState.message_id), })), }); }
async ackReadStates({userId, data}: ReadStateAckParams): Promise<ReadStateAckResponse> { const readStates = await this.readStateService.ackReadStates({ userId, readStates: data.read_states.map((readState) => ({ channelId: createChannelID(readState.channel_id), messageId: createMessageID(readState.message_id), mentionCount: readState.mention_count, manual: readState.manual, })), }); return { read_states: readStates.map(mapReadStateResponse), read_state_proto: encodeReadStatesResponseProto(readStates), }; }}