diff --git a/apps/core/src/modules/activity/activity.controller.ts b/apps/core/src/modules/activity/activity.controller.ts index 35fceb4d..813a3d15 100644 --- a/apps/core/src/modules/activity/activity.controller.ts +++ b/apps/core/src/modules/activity/activity.controller.ts @@ -85,7 +85,16 @@ export class ActivityController { readerIds.push(item.readerId) } } - const readers = await this.readerService.findReaderInIds(readerIds) + const readers = await this.readerService + .findReaderInIds(readerIds) + .then((arr) => { + return arr.map((item) => { + return snakecaseKeys({ + ...item, + id: item._id.toHexString(), + }) + }) + }) return { data: keyBy( diff --git a/apps/core/src/modules/activity/activity.service.ts b/apps/core/src/modules/activity/activity.service.ts index c5ae5d45..e4968edf 100644 --- a/apps/core/src/modules/activity/activity.service.ts +++ b/apps/core/src/modules/activity/activity.service.ts @@ -43,6 +43,7 @@ import { CommentService } from '../comment/comment.service' import { ConfigsService } from '../configs/configs.service' import { NoteService } from '../note/note.service' import { PostService } from '../post/post.service' +import { ReaderService } from '../reader/reader.service' import { Activity } from './activity.constant' import { ActivityModel } from './activity.model' import { @@ -79,6 +80,7 @@ export class ActivityService implements OnModuleInit, OnModuleDestroy { private readonly postService: PostService, @Inject(forwardRef(() => NoteService)) private readonly noteService: NoteService, + private readonly readerService: ReaderService, ) { this.logger = new Logger(ActivityService.name) } @@ -360,6 +362,12 @@ export class ActivityService implements OnModuleInit, OnModuleDestroy { Reflect.deleteProperty(presenceData, 'ts') const serializedPresenceData = omit(presenceData, 'ip') + if (data.readerId) { + const reader = await this.readerService.findReaderInIds([data.readerId]) + if (reader.length) { + Object.assign(serializedPresenceData, { reader: reader[0] }) + } + } const roomJoinedAtMap = await this.webGateway.getSocketRoomJoinedAtMap(socket) diff --git a/packages/api-client/controllers/activity.ts b/packages/api-client/controllers/activity.ts index b95208cf..d602a54a 100644 --- a/packages/api-client/controllers/activity.ts +++ b/packages/api-client/controllers/activity.ts @@ -1,6 +1,7 @@ import type { IRequestAdapter } from '~/interfaces/adapter' import type { IController } from '~/interfaces/controller' import type { IRequestHandler } from '~/interfaces/request' +import type { AuthUser } from '~/models' import type { ActivityPresence, LastYearPublication, @@ -49,7 +50,10 @@ export class ActivityController implements IController { * @support core >= 5.0.0 */ getPresence(roomName: string) { - return this.proxy.presence.get>({ + return this.proxy.presence.get<{ + data: Record + readers: Record + }>({ params: { room_name: roomName, }, diff --git a/packages/api-client/models/auth.ts b/packages/api-client/models/auth.ts new file mode 100644 index 00000000..46be8d0b --- /dev/null +++ b/packages/api-client/models/auth.ts @@ -0,0 +1,8 @@ +export interface AuthUser { + id: string + email: string + isOwner: boolean + image: string + name: string + provider: string +} diff --git a/packages/api-client/models/index.ts b/packages/api-client/models/index.ts index 14609543..bb968436 100644 --- a/packages/api-client/models/index.ts +++ b/packages/api-client/models/index.ts @@ -1,6 +1,7 @@ export * from './activity' export * from './aggregate' export * from './ai' +export * from './auth' export * from './base' export * from './category' export * from './comment'