Skip to content

Commit

Permalink
refactor: remove deps from FederationRoomEvents model (#34506)
Browse files Browse the repository at this point in the history
  • Loading branch information
sampaiodiego authored Dec 24, 2024
1 parent b31e7f9 commit 1fedb4f
Showing 1 changed file with 13 additions and 16 deletions.
29 changes: 13 additions & 16 deletions apps/meteor/server/models/raw/FederationRoomEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ import type { IFederationRoomEventsModel } from '@rocket.chat/model-typings';
import type { Db, DeleteResult, IndexDescription } from 'mongodb';

import { FederationEventsModel } from './FederationEvents';
import { contextDefinitions } from '../../../app/federation/server/lib/context';

const { type, contextQuery } = contextDefinitions.ROOM;

export class FederationRoomEvents extends FederationEventsModel implements IFederationRoomEventsModel {
constructor(db: Db) {
Expand All @@ -19,11 +16,11 @@ export class FederationRoomEvents extends FederationEventsModel implements IFede

// @ts-expect-error - TODO: Bad extends
async createGenesisEvent(origin: string, room: IRoom): Promise<Omit<IFederationEvent, '_updatedAt'>> {
return super.createGenesisEvent(origin, contextQuery(room._id), { contextType: type, room });
return super.createGenesisEvent(origin, { roomId: room._id }, { contextType: 'room', room });
}

async createDeleteRoomEvent(origin: string, roomId: string): Promise<Omit<IFederationEvent, '_updatedAt'>> {
return super.createEvent(origin, contextQuery(roomId), eventTypes.ROOM_DELETE, { roomId });
return super.createEvent(origin, { roomId }, eventTypes.ROOM_DELETE, { roomId });
}

async createAddUserEvent(
Expand All @@ -33,7 +30,7 @@ export class FederationRoomEvents extends FederationEventsModel implements IFede
subscription: ISubscription,
domainsAfterAdd: string[],
): Promise<Omit<IFederationEvent, '_updatedAt'>> {
return super.createEvent(origin, contextQuery(roomId), eventTypes.ROOM_ADD_USER, {
return super.createEvent(origin, { roomId }, eventTypes.ROOM_ADD_USER, {
roomId,
user,
subscription,
Expand All @@ -47,7 +44,7 @@ export class FederationRoomEvents extends FederationEventsModel implements IFede
user: IUser,
domainsAfterRemoval: string[],
): Promise<Omit<IFederationEvent, '_updatedAt'>> {
return super.createEvent(origin, contextQuery(roomId), eventTypes.ROOM_REMOVE_USER, {
return super.createEvent(origin, { roomId }, eventTypes.ROOM_REMOVE_USER, {
roomId,
user,
domainsAfterRemoval,
Expand All @@ -60,15 +57,15 @@ export class FederationRoomEvents extends FederationEventsModel implements IFede
user: IUser,
domainsAfterLeave: string[],
): Promise<Omit<IFederationEvent, '_updatedAt'>> {
return super.createEvent(origin, contextQuery(roomId), eventTypes.ROOM_USER_LEFT, {
return super.createEvent(origin, { roomId }, eventTypes.ROOM_USER_LEFT, {
roomId,
user,
domainsAfterLeave,
});
}

async createMessageEvent(origin: string, roomId: string, message: string): Promise<Omit<IFederationEvent, '_updatedAt'>> {
return super.createEvent(origin, contextQuery(roomId), eventTypes.ROOM_MESSAGE, { message });
return super.createEvent(origin, { roomId }, eventTypes.ROOM_MESSAGE, { message });
}

async createEditMessageEvent(
Expand All @@ -82,13 +79,13 @@ export class FederationRoomEvents extends FederationEventsModel implements IFede
federation: originalMessage.federation,
};

return super.createEvent(origin, contextQuery(roomId), eventTypes.ROOM_EDIT_MESSAGE, {
return super.createEvent(origin, { roomId }, eventTypes.ROOM_EDIT_MESSAGE, {
message,
});
}

async createDeleteMessageEvent(origin: string, roomId: string, messageId: string): Promise<Omit<IFederationEvent, '_updatedAt'>> {
return super.createEvent(origin, contextQuery(roomId), eventTypes.ROOM_DELETE_MESSAGE, {
return super.createEvent(origin, { roomId }, eventTypes.ROOM_DELETE_MESSAGE, {
roomId,
messageId,
});
Expand All @@ -101,7 +98,7 @@ export class FederationRoomEvents extends FederationEventsModel implements IFede
username: string,
reaction: string,
): Promise<Omit<IFederationEvent, '_updatedAt'>> {
return super.createEvent(origin, contextQuery(roomId), eventTypes.ROOM_SET_MESSAGE_REACTION, {
return super.createEvent(origin, { roomId }, eventTypes.ROOM_SET_MESSAGE_REACTION, {
roomId,
messageId,
username,
Expand All @@ -116,7 +113,7 @@ export class FederationRoomEvents extends FederationEventsModel implements IFede
username: string,
reaction: string,
): Promise<Omit<IFederationEvent, '_updatedAt'>> {
return super.createEvent(origin, contextQuery(roomId), eventTypes.ROOM_UNSET_MESSAGE_REACTION, {
return super.createEvent(origin, { roomId }, eventTypes.ROOM_UNSET_MESSAGE_REACTION, {
roomId,
messageId,
username,
Expand All @@ -125,20 +122,20 @@ export class FederationRoomEvents extends FederationEventsModel implements IFede
}

async createMuteUserEvent(origin: string, roomId: string, user: IUser): Promise<Omit<IFederationEvent, '_updatedAt'>> {
return super.createEvent(origin, contextQuery(roomId), eventTypes.ROOM_MUTE_USER, {
return super.createEvent(origin, { roomId }, eventTypes.ROOM_MUTE_USER, {
roomId,
user,
});
}

async createUnmuteUserEvent(origin: string, roomId: string, user: IUser): Promise<Omit<IFederationEvent, '_updatedAt'>> {
return super.createEvent(origin, contextQuery(roomId), eventTypes.ROOM_UNMUTE_USER, {
return super.createEvent(origin, { roomId }, eventTypes.ROOM_UNMUTE_USER, {
roomId,
user,
});
}

async removeRoomEvents(roomId: string): Promise<DeleteResult> {
return super.removeContextEvents(contextQuery(roomId));
return super.removeContextEvents({ roomId });
}
}

0 comments on commit 1fedb4f

Please sign in to comment.