Skip to content

Commit

Permalink
chore: Update typings on callbacks to accept less than a full room ob…
Browse files Browse the repository at this point in the history
…ject (#33305)
  • Loading branch information
KevLehman committed Sep 17, 2024
1 parent 3a161c4 commit f27092b
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 7 deletions.
4 changes: 2 additions & 2 deletions apps/meteor/app/lib/server/functions/isTheLastMessage.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { IMessage, IRoom } from '@rocket.chat/core-typings';
import type { IMessage, IRoom, AtLeast } from '@rocket.chat/core-typings';

import { settings } from '../../../settings/server';

// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
export const isTheLastMessage = (room: IRoom, message: Pick<IMessage, '_id'>) =>
export const isTheLastMessage = (room: AtLeast<IRoom, 'lastMessage'>, message: Pick<IMessage, '_id'>) =>
settings.get('Store_Last_Message') && (!room.lastMessage || room.lastMessage._id === message._id);
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import type { AtLeast } from '@rocket.chat/core-typings';
import { type IMessage, type IRoom, isMessageFromMatrixFederation, isRoomFederated } from '@rocket.chat/core-typings';

import { isFederationEnabled, isFederationReady } from '../../federation/utils';

export class FederationActions {
public static shouldPerformAction(message: IMessage, room: IRoom): boolean {
public static shouldPerformAction(message: IMessage, room: AtLeast<IRoom, 'federated'>): boolean {
if (isMessageFromMatrixFederation(message) || isRoomFederated(room)) {
return isFederationEnabled() && isFederationReady();
}
Expand Down
4 changes: 2 additions & 2 deletions apps/meteor/server/services/messages/service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { IMessageService } from '@rocket.chat/core-services';
import { Authorization, ServiceClassInternal } from '@rocket.chat/core-services';
import { type IMessage, type MessageTypesValues, type IUser, type IRoom, isEditedMessage } from '@rocket.chat/core-typings';
import { type IMessage, type MessageTypesValues, type IUser, type IRoom, isEditedMessage, type AtLeast } from '@rocket.chat/core-typings';
import { Messages, Rooms } from '@rocket.chat/models';

import { deleteMessage } from '../../../app/lib/server/functions/deleteMessage';
Expand Down Expand Up @@ -244,7 +244,7 @@ export class MessageService extends ServiceClassInternal implements IMessageServ
// await Room.join({ room, user });
// }

async beforeReacted(message: IMessage, room: IRoom) {
async beforeReacted(message: IMessage, room: AtLeast<IRoom, 'federated'>) {
if (!FederationActions.shouldPerformAction(message, room)) {
throw new FederationMatrixInvalidConfigurationError('Unable to react to message');
}
Expand Down
4 changes: 2 additions & 2 deletions packages/core-services/src/types/IMessageService.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { IMessage, MessageTypesValues, IUser, IRoom } from '@rocket.chat/core-typings';
import type { IMessage, MessageTypesValues, IUser, IRoom, AtLeast } from '@rocket.chat/core-typings';

export interface IMessageService {
sendMessage({ fromId, rid, msg }: { fromId: string; rid: string; msg: string }): Promise<IMessage>;
Expand All @@ -21,6 +21,6 @@ export interface IMessageService {
deleteMessage(user: IUser, message: IMessage): Promise<void>;
updateMessage(message: IMessage, user: IUser, originalMsg?: IMessage): Promise<void>;
reactToMessage(userId: string, reaction: string, messageId: IMessage['_id'], shouldReact?: boolean): Promise<void>;
beforeReacted(message: IMessage, room: IRoom): Promise<void>;
beforeReacted(message: IMessage, room: AtLeast<IRoom, 'federated'>): Promise<void>;
beforeDelete(message: IMessage, room: IRoom): Promise<void>;
}

0 comments on commit f27092b

Please sign in to comment.