Skip to content

Commit

Permalink
Merge branch 'develop' into convert-jump-to-message-callback
Browse files Browse the repository at this point in the history
  • Loading branch information
sampaiodiego authored Dec 7, 2023
2 parents 22a5932 + 6f88d8d commit 828ddd2
Show file tree
Hide file tree
Showing 189 changed files with 4,627 additions and 2,125 deletions.
6 changes: 6 additions & 0 deletions .changeset/fifty-maps-deny.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@rocket.chat/meteor": minor
"@rocket.chat/rest-typings": minor
---

Added `push.info` endpoint to enable users to retrieve info about the workspace's push gateway
28 changes: 23 additions & 5 deletions apps/meteor/app/api/server/v1/import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@ import {
isDownloadPendingFilesParamsPOST,
isDownloadPendingAvatarsParamsPOST,
isGetCurrentImportOperationParamsGET,
isImportersListParamsGET,
isImportAddUsersParamsPOST,
} from '@rocket.chat/rest-typings';
import { Meteor } from 'meteor/meteor';

import { PendingAvatarImporter } from '../../../importer-pending-avatars/server/PendingAvatarImporter';
import { PendingFileImporter } from '../../../importer-pending-files/server/PendingFileImporter';
import { Importers } from '../../../importer/server';
import {
executeUploadImportFile,
Expand Down Expand Up @@ -136,9 +139,8 @@ API.v1.addRoute(
}

const operation = await Import.newOperation(this.userId, importer.name, importer.key);

importer.instance = new importer.importer(importer, operation); // eslint-disable-line new-cap
const count = await importer.instance.prepareFileCount();
const instance = new PendingFileImporter(importer, operation);
const count = await instance.prepareFileCount();

return API.v1.success({
count,
Expand All @@ -162,8 +164,8 @@ API.v1.addRoute(
}

const operation = await Import.newOperation(this.userId, importer.name, importer.key);
importer.instance = new importer.importer(importer, operation); // eslint-disable-line new-cap
const count = await importer.instance.prepareFileCount();
const instance = new PendingAvatarImporter(importer, operation);
const count = await instance.prepareFileCount();

return API.v1.success({
count,
Expand All @@ -189,6 +191,22 @@ API.v1.addRoute(
},
);

API.v1.addRoute(
'importers.list',
{
authRequired: true,
validateParams: isImportersListParamsGET,
permissionsRequired: ['run-import'],
},
{
async get() {
const importers = Importers.getAllVisible().map(({ key, name }) => ({ key, name }));

return API.v1.success(importers);
},
},
);

API.v1.addRoute(
'import.clear',
{
Expand Down
18 changes: 17 additions & 1 deletion apps/meteor/app/api/server/v1/push.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { Messages, AppsTokens, Users, Rooms } from '@rocket.chat/models';
import { Messages, AppsTokens, Users, Rooms, Settings } from '@rocket.chat/models';
import { Random } from '@rocket.chat/random';
import { Match, check } from 'meteor/check';
import { Meteor } from 'meteor/meteor';

import { canAccessRoomAsync } from '../../../authorization/server/functions/canAccessRoom';
import PushNotification from '../../../push-notifications/server/lib/PushNotification';
import { settings } from '../../../settings/server';
import { API } from '../api';

API.v1.addRoute(
Expand Down Expand Up @@ -110,3 +111,18 @@ API.v1.addRoute(
},
},
);

API.v1.addRoute(
'push.info',
{ authRequired: true },
{
async get() {
const defaultGateway = (await Settings.findOneById('Push_gateway', { projection: { packageValue: 1 } }))?.packageValue;
const defaultPushGateway = settings.get('Push_gateway') === defaultGateway;
return API.v1.success({
pushGatewayEnabled: settings.get('Push_enable'),
defaultPushGateway,
});
},
},
);
11 changes: 11 additions & 0 deletions apps/meteor/app/autotranslate/server/autotranslate.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { api } from '@rocket.chat/core-services';
import type {
IMessage,
IRoom,
Expand All @@ -15,6 +16,7 @@ import _ from 'underscore';

import { callbacks } from '../../../lib/callbacks';
import { isTruthy } from '../../../lib/isTruthy';
import { broadcastMessageSentEvent } from '../../../server/modules/watchers/lib/messages';
import { Markdown } from '../../markdown/server';
import { settings } from '../../settings/server';

Expand Down Expand Up @@ -305,6 +307,7 @@ export abstract class AutoTranslate {
const translations = await this._translateMessage(targetMessage, targetLanguages);
if (!_.isEmpty(translations)) {
await Messages.addTranslations(message._id, translations, TranslationProviderRegistry[Provider] || '');
this.notifyTranslatedMessage(message._id);
}
});
}
Expand All @@ -320,6 +323,7 @@ export abstract class AutoTranslate {

if (!_.isEmpty(translations)) {
await Messages.addAttachmentTranslations(message._id, String(index), translations);
this.notifyTranslatedMessage(message._id);
}
}
}
Expand All @@ -328,6 +332,13 @@ export abstract class AutoTranslate {
return Messages.findOneById(message._id);
}

private notifyTranslatedMessage(messageId: string): void {
void broadcastMessageSentEvent({
id: messageId,
broadcastCallback: (message) => api.broadcast('message.sent', message),
});
}

/**
* Returns metadata information about the service provider which is used by
* the generic implementation
Expand Down
42 changes: 42 additions & 0 deletions apps/meteor/app/federation/server/endpoints/dispatch.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { eventTypes } from '@rocket.chat/core-typings';
import { FederationServers, FederationRoomEvents, Rooms, Messages, Subscriptions, Users, ReadReceipts } from '@rocket.chat/models';
import EJSON from 'ejson';

import { broadcastMessageSentEvent } from '../../../../server/modules/watchers/lib/messages';
import { API } from '../../../api/server';
import { FileUpload } from '../../../file-upload/server';
import { deleteRoom } from '../../../lib/server/functions/deleteRoom';
Expand Down Expand Up @@ -214,11 +215,13 @@ const eventHandlers = {

// Check if message exists
const persistedMessage = await Messages.findOne({ _id: message._id });
let messageForNotification;

if (persistedMessage) {
// Update the federation
if (!persistedMessage.federation) {
await Messages.updateOne({ _id: persistedMessage._id }, { $set: { federation: message.federation } });
messageForNotification = { ...persistedMessage, federation: message.federation };
}
} else {
// Load the room
Expand Down Expand Up @@ -275,10 +278,18 @@ const eventHandlers = {
// Notify users
await notifyUsersOnMessage(denormalizedMessage, room);
sendAllNotifications(denormalizedMessage, room);
messageForNotification = denormalizedMessage;
} catch (err) {
serverLogger.debug(`Error on creating message: ${message._id}`);
}
}
if (messageForNotification) {
void broadcastMessageSentEvent({
id: messageForNotification._id,
data: messageForNotification,
broadcastCallback: (message) => api.broadcast('message.sent', message),
});
}
}

return eventResult;
Expand All @@ -305,6 +316,15 @@ const eventHandlers = {
} else {
// Update the message
await Messages.updateOne({ _id: persistedMessage._id }, { $set: { msg: message.msg, federation: message.federation } });
void broadcastMessageSentEvent({
id: persistedMessage._id,
data: {
...persistedMessage,
msg: message.msg,
federation: message.federation,
},
broadcastCallback: (message) => api.broadcast('message.sent', message),
});
}
}

Expand Down Expand Up @@ -367,6 +387,17 @@ const eventHandlers = {

// Update the property
await Messages.updateOne({ _id: messageId }, { $set: { [`reactions.${reaction}`]: reactionObj } });
void broadcastMessageSentEvent({
id: persistedMessage._id,
data: {
...persistedMessage,
reactions: {
...persistedMessage.reactions,
[reaction]: reactionObj,
},
},
broadcastCallback: (message) => api.broadcast('message.sent', message),
});
}

return eventResult;
Expand Down Expand Up @@ -415,6 +446,17 @@ const eventHandlers = {
// Otherwise, update the property
await Messages.updateOne({ _id: messageId }, { $set: { [`reactions.${reaction}`]: reactionObj } });
}
void broadcastMessageSentEvent({
id: persistedMessage._id,
data: {
...persistedMessage,
reactions: {
...persistedMessage.reactions,
[reaction]: reactionObj,
},
},
broadcastCallback: (message) => api.broadcast('message.sent', message),
});
}

return eventResult;
Expand Down
4 changes: 0 additions & 4 deletions apps/meteor/app/importer-csv/client/adder.js

This file was deleted.

1 change: 0 additions & 1 deletion apps/meteor/app/importer-csv/client/index.ts

This file was deleted.

12 changes: 0 additions & 12 deletions apps/meteor/app/importer-csv/lib/info.js

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
import type { IImport } from '@rocket.chat/core-typings';
import { Settings, Users } from '@rocket.chat/models';
import { Random } from '@rocket.chat/random';
import { parse } from 'csv-parse/lib/sync';

import { Base, ProgressStep, ImporterWebsocket } from '../../importer/server';
import { Importer, ProgressStep, ImporterWebsocket } from '../../importer/server';
import type { IConverterOptions } from '../../importer/server/classes/ImportDataConverter';
import type { ImporterProgress } from '../../importer/server/classes/ImporterProgress';
import type { ImporterInfo } from '../../importer/server/definitions/ImporterInfo';

export class CsvImporter extends Base {
constructor(info, importRecord, converterOptions = {}) {
super(info, importRecord, converterOptions);
export class CsvImporter extends Importer {
private csvParser: (csv: string) => string[];

const { parse } = require('csv-parse/lib/sync');
constructor(info: ImporterInfo, importRecord: IImport, converterOptions: IConverterOptions = {}) {
super(info, importRecord, converterOptions);

this.csvParser = parse;
}

async prepareUsingLocalFile(fullFilePath) {
async prepareUsingLocalFile(fullFilePath: string): Promise<ImporterProgress> {
this.logger.debug('start preparing import operation');
await this.converter.clearImportData();

Expand Down Expand Up @@ -40,17 +45,21 @@ export class CsvImporter extends Base {
let messagesCount = 0;
let usersCount = 0;
let channelsCount = 0;
const dmRooms = new Map();
const roomIds = new Map();
const usedUsernames = new Set();
const availableUsernames = new Set();

const getRoomId = (roomName) => {
if (!roomIds.has(roomName)) {
roomIds.set(roomName, Random.id());
const dmRooms = new Set<string>();
const roomIds = new Map<string, string>();
const usedUsernames = new Set<string>();
const availableUsernames = new Set<string>();

const getRoomId = (roomName: string) => {
const roomId = roomIds.get(roomName);

if (roomId === undefined) {
const fallbackRoomId = Random.id();
roomIds.set(roomName, fallbackRoomId);
return fallbackRoomId;
}

return roomIds.get(roomName);
return roomId;
};

for await (const entry of zip.getEntries()) {
Expand Down Expand Up @@ -149,7 +158,7 @@ export class CsvImporter extends Base {
continue;
}

let data;
let data: { username: string; ts: string; text: string; otherUsername?: string; isDirect?: true }[];
const msgGroupData = item[1].split('.')[0]; // messages
let isDirect = false;

Expand All @@ -173,6 +182,10 @@ export class CsvImporter extends Base {

if (isDirect) {
for await (const msg of data) {
if (!msg.otherUsername) {
continue;
}

const sourceId = [msg.username, msg.otherUsername].sort().join('/');

if (!dmRooms.has(sourceId)) {
Expand All @@ -182,7 +195,7 @@ export class CsvImporter extends Base {
t: 'd',
});

dmRooms.set(sourceId, true);
dmRooms.add(sourceId);
}

const newMessage = {
Expand Down Expand Up @@ -217,8 +230,6 @@ export class CsvImporter extends Base {
}

await super.updateRecord({ 'count.messages': messagesCount, 'messagesstatus': null });
increaseProgressCount();
continue;
}

increaseProgressCount();
Expand Down
9 changes: 6 additions & 3 deletions apps/meteor/app/importer-csv/server/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { Importers } from '../../importer/server';
import { CsvImporterInfo } from '../lib/info';
import { CsvImporter } from './importer';
import { CsvImporter } from './CsvImporter';

Importers.add(new CsvImporterInfo(), CsvImporter);
Importers.add({
key: 'csv',
name: 'CSV',
importer: CsvImporter,
});
4 changes: 0 additions & 4 deletions apps/meteor/app/importer-hipchat-enterprise/client/adder.ts

This file was deleted.

This file was deleted.

12 changes: 0 additions & 12 deletions apps/meteor/app/importer-hipchat-enterprise/lib/info.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ import { Readable } from 'stream';
import { Settings } from '@rocket.chat/models';
import { Meteor } from 'meteor/meteor';

import { Base, ProgressStep } from '../../importer/server';
import { Importer, ProgressStep } from '../../importer/server';

export class HipChatEnterpriseImporter extends Base {
/** @deprecated HipChat was discontinued at 2019-02-15 */
export class HipChatEnterpriseImporter extends Importer {
constructor(info, importRecord, converterOptions = {}) {
super(info, importRecord, converterOptions);

Expand Down
Loading

0 comments on commit 828ddd2

Please sign in to comment.