Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Update typings on callbacks to accept less than a full room object #33305

Merged
merged 2 commits into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>;
}
Loading