Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
957fda2
chore: add a flag to disable db watchers on the message collection
Sep 13, 2023
5e61b10
Merge branch 'develop' into chore/remove-message-db-watcher-1
Sep 13, 2023
fef4fb0
chore: enable message event listeners depending on the event
Sep 15, 2023
da806dd
chore: dispatch new event on send message
Sep 15, 2023
66435f5
chore: dispatch new event on update message
Sep 15, 2023
c85ab7e
chore: dispatch new event on delete message
Sep 15, 2023
67b075b
chore: dispatch new event on send system message through svc
Sep 15, 2023
28419b8
chore: adapt discussion feat to work without message events watcher
Sep 15, 2023
be538b1
Merge branch 'develop' into chore/remove-message-db-watcher-1
Sep 15, 2023
b6327ff
Merge branch 'develop' into chore/remove-message-db-watcher-1
Sep 18, 2023
2d77cfb
Merge branch 'chore/remove-message-db-watcher-1' into chore/adapt-mes…
Sep 18, 2023
ef450c8
Merge branch 'develop' into chore/remove-message-db-watcher-1
Oct 26, 2023
95c99ef
Merge branch 'chore/remove-message-db-watcher-1' into chore/adapt-mes…
Oct 26, 2023
1126a8a
Merge branch 'develop' into chore/remove-message-db-watcher-1
sampaiodiego Nov 3, 2023
de50690
Merge branch 'develop' into chore/remove-message-db-watcher-1
sampaiodiego Nov 7, 2023
c28e22f
Merge branch 'chore/remove-message-db-watcher-1' into chore/adapt-mes…
Nov 7, 2023
23b67e3
Merge branch 'develop' into chore/remove-message-db-watcher-1
Nov 8, 2023
9f59186
Merge branch 'chore/remove-message-db-watcher-1' into chore/adapt-mes…
Nov 9, 2023
ce94c2a
Merge branch 'develop' into chore/remove-message-db-watcher-1
Nov 10, 2023
13e4a99
chore: remove unnecessary fn
Nov 10, 2023
4504415
chore: publish events directly using broadcast
Nov 10, 2023
717ca5e
Merge branch 'chore/remove-message-db-watcher-1' into chore/adapt-mes…
Nov 10, 2023
9ac4f19
chore: removing old references
Nov 10, 2023
4a92a42
chore: useless param
Nov 10, 2023
62965d3
Merge branch 'develop' into chore/remove-message-db-watcher-1
Nov 10, 2023
d54a3db
Merge branch 'chore/remove-message-db-watcher-1' into chore/adapt-mes…
Nov 10, 2023
62a7f29
chore: undo param change
Nov 10, 2023
c4e25ba
Merge branch 'chore/remove-message-db-watcher-1' into chore/adapt-mes…
Nov 10, 2023
5312f05
chore: reverting param
Nov 10, 2023
040c1af
chore: delete user working without relying on msg db watcher (#30435)
Nov 10, 2023
076c56c
Merge branch 'chore/remove-message-db-watcher-1' into chore/adapt-mes…
Nov 10, 2023
95c58b6
chore: send updates to client about the thread message as well
Nov 17, 2023
a7a264e
Merge branch 'develop' into chore/remove-message-db-watcher-1
Nov 20, 2023
289cb22
Merge branch 'chore/remove-message-db-watcher-1' into chore/adapt-mes…
Nov 20, 2023
3aac05d
Merge branch 'develop' into chore/adapt-message-events-without-db-wat…
sampaiodiego Nov 23, 2023
01fb41c
chore: Pin, star and react to message without oplog (#30906)
Nov 23, 2023
df22bdd
chore: adding new streamer event for imported messages
Nov 23, 2023
1a1759f
Merge branch 'develop' into chore/importer-message-stream
Nov 24, 2023
e0b18d5
chore: fix stream name
Nov 27, 2023
9f28fd4
chore: add todo in slackbridge pinned system messages
Nov 30, 2023
98918fd
Merge branch 'develop' into chore/importer-message-stream
Dec 7, 2023
6295f55
Merge branch 'develop' into chore/importer-message-stream
sampaiodiego Dec 29, 2023
c5894c4
use api.broadcast and a different stream
sampaiodiego Dec 29, 2023
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
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import http from 'http';
import https from 'https';

import { api } from '@rocket.chat/core-services';
import type { IImport, MessageAttachment, IUpload } from '@rocket.chat/core-typings';
import { Messages } from '@rocket.chat/models';
import { Random } from '@rocket.chat/random';
Expand Down Expand Up @@ -80,6 +81,7 @@ export class PendingFileImporter extends Importer {

try {
const pendingFileMessageList = Messages.findAllImportedMessagesWithFilesToDownload();
const importedRoomIds = new Set<string>();
for await (const message of pendingFileMessageList) {
try {
const { _importFile } = message;
Expand Down Expand Up @@ -140,6 +142,7 @@ export class PendingFileImporter extends Importer {

await Messages.setImportFileRocketChatAttachment(_importFile.id, url, attachment);
await completeFile(details);
importedRoomIds.add(message.rid);
} catch (error) {
await completeFile(details);
logError(error);
Expand All @@ -150,6 +153,8 @@ export class PendingFileImporter extends Importer {
this.logger.error(error);
}
}

void api.broadcast('notify.importedMessages', { roomIds: Array.from(importedRoomIds) });
} catch (error) {
// If the cursor expired, restart the method
if (this.isCursorNotFoundError(error)) {
Expand Down
11 changes: 9 additions & 2 deletions apps/meteor/app/importer/server/classes/ImportDataConverter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -715,7 +715,12 @@ export class ImportDataConverter {
return ImportData.getAllMessages().toArray();
}

async convertMessages({ beforeImportFn, afterImportFn, onErrorFn }: IConversionCallbacks = {}): Promise<void> {
async convertMessages({
beforeImportFn,
afterImportFn,
onErrorFn,
afterImportAllMessagesFn,
}: IConversionCallbacks & { afterImportAllMessagesFn?: (roomIds: string[]) => Promise<void> }): Promise<void> {
const rids: Array<string> = [];
const messages = await this.getMessagesToImport();

Expand All @@ -740,7 +745,6 @@ export class ImportDataConverter {
this._logger.warn(`Imported user not found: ${data.u._id}`);
throw new Error('importer-message-unknown-user');
}

const rid = await this.findImportedRoomId(data.rid);
if (!rid) {
throw new Error('importer-message-unknown-room');
Expand Down Expand Up @@ -813,6 +817,9 @@ export class ImportDataConverter {
this._logger.error(e);
}
}
if (afterImportAllMessagesFn) {
await afterImportAllMessagesFn(rids);
}
}

async updateRoom(room: IRoom, roomData: IImportChannel, startedByUserId: string): Promise<void> {
Expand Down
6 changes: 5 additions & 1 deletion apps/meteor/app/importer/server/classes/Importer.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { api } from '@rocket.chat/core-services';
import type { IImport, IImportRecord, IImportChannel, IImportUser, IImportProgress } from '@rocket.chat/core-typings';
import { Logger } from '@rocket.chat/logger';
import { Settings, ImportData, Imports } from '@rocket.chat/models';
Expand Down Expand Up @@ -170,6 +171,9 @@ export class Importer {
}
};

const afterImportAllMessagesFn = async (importedRoomIds: string[]): Promise<void> =>
api.broadcast('notify.importedMessages', { roomIds: importedRoomIds });

const afterBatchFn = async (successCount: number, errorCount: number) => {
if (successCount) {
await this.addCountCompleted(successCount);
Expand Down Expand Up @@ -203,7 +207,7 @@ export class Importer {
await this.converter.convertChannels(startedByUserId, { beforeImportFn, afterImportFn, onErrorFn });

await this.updateProgress(ProgressStep.IMPORTING_MESSAGES);
await this.converter.convertMessages({ afterImportFn, onErrorFn });
await this.converter.convertMessages({ afterImportFn, onErrorFn, afterImportAllMessagesFn });

await this.updateProgress(ProgressStep.FINISHING);

Expand Down
2 changes: 2 additions & 0 deletions apps/meteor/app/slackbridge/server/SlackAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -1169,6 +1169,7 @@ export default class SlackAdapter {

async processPinnedItemMessage(rocketChannel, rocketUser, slackMessage, isImporting) {
if (slackMessage.attachments && slackMessage.attachments[0] && slackMessage.attachments[0].text) {
// TODO: refactor this logic to use the service to send this system message instead of using sendMessage
const rocketMsgObj = {
rid: rocketChannel._id,
t: 'message_pinned',
Expand Down Expand Up @@ -1380,6 +1381,7 @@ export default class SlackAdapter {
for await (const pin of items) {
if (pin.message) {
const user = await this.rocket.findUser(pin.message.user);
// TODO: send this system message to the room as well (using the service)
const msgObj = {
rid,
t: 'message_pinned',
Expand Down
7 changes: 7 additions & 0 deletions apps/meteor/app/ui-utils/client/lib/LegacyRoomManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,13 @@ const computation = Tracker.autorun(() => {
record.streamActive = true;
openedRoomsDependency.changed();
});

// when we receive a messages imported event we just clear the room history and fetch it again
Notifications.onRoom(record.rid, 'messagesImported', async () => {
await RoomHistoryManager.clear(record.rid);
await RoomHistoryManager.getMore(record.rid);
});

Notifications.onRoom(record.rid, 'deleteMessage', (msg) => {
ChatMessage.remove({ _id: msg._id });

Expand Down
7 changes: 7 additions & 0 deletions apps/meteor/server/modules/listeners/listeners.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,13 @@ export class ListenersModule {
notifications.notifyUserInThisInstance(uid, 'calendar', data);
});

service.onEvent('notify.importedMessages', ({ roomIds }): void => {
roomIds.forEach((rid) => {
// couldnt get TS happy by providing no data, so had to provide null
notifications.notifyRoomInThisInstance(rid, 'messagesImported', null);
});
});

service.onEvent('connector.statuschanged', (enabled): void => {
notifications.notifyLoggedInThisInstance('voip.statuschanged', enabled);
});
Expand Down
1 change: 1 addition & 0 deletions ee/packages/ddp-client/src/types/streams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export interface StreamerEvents {
{ key: `${string}/e2e.keyRequest`; args: [unknown] },
{ key: `${string}/videoconf`; args: [id: string] },
{ key: `${string}/messagesRead`; args: [{ until: Date; tmid?: string }] },
{ key: `${string}/messagesImported`; args: [null] },
/* @deprecated over videoconf*/
// { key: `${string}/${string}`; args: [id: string] },
];
Expand Down
1 change: 1 addition & 0 deletions packages/core-services/src/events/Events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ export type EventSignatures = {
'notify.updateCustomSound'(data: { soundData: ICustomSound }): void;
'notify.calendar'(uid: string, data: ICalendarNotification): void;
'notify.messagesRead'(data: { rid: string; until: Date; tmid?: string }): void;
'notify.importedMessages'(data: { roomIds: string[] }): void;
'permission.changed'(data: { clientAction: ClientAction; data: any }): void;
'room'(data: { action: string; room: Partial<IRoom> }): void;
'room.avatarUpdate'(room: Pick<IRoom, '_id' | 'avatarETag'>): void;
Expand Down