Skip to content

Commit

Permalink
Merge branch 'develop' into fix/not-notifying-on-thread-message-removal
Browse files Browse the repository at this point in the history
  • Loading branch information
Gustrb authored Dec 20, 2024
2 parents 51d6f52 + 149c3b5 commit bd9ef32
Show file tree
Hide file tree
Showing 28 changed files with 486 additions and 96 deletions.
22 changes: 22 additions & 0 deletions .changeset/blue-items-raise.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
'@rocket.chat/fuselage-ui-kit': patch
'@rocket.chat/instance-status': patch
'@rocket.chat/ui-theming': patch
'@rocket.chat/model-typings': patch
'@rocket.chat/ui-video-conf': patch
'@rocket.chat/uikit-playground': patch
'@rocket.chat/core-typings': patch
'@rocket.chat/rest-typings': patch
'@rocket.chat/apps-engine': patch
'@rocket.chat/ui-composer': patch
'@rocket.chat/ui-contexts': patch
'@rocket.chat/gazzodown': patch
'@rocket.chat/ui-avatar': patch
'@rocket.chat/ui-client': patch
'@rocket.chat/livechat': patch
'@rocket.chat/ui-voip': patch
'@rocket.chat/i18n': patch
'@rocket.chat/meteor': patch
---

Fixes an error where the engine would not retry a subprocess restart if the last attempt failed
22 changes: 22 additions & 0 deletions .changeset/gold-comics-taste.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
'@rocket.chat/fuselage-ui-kit': patch
'@rocket.chat/instance-status': patch
'@rocket.chat/ui-theming': patch
'@rocket.chat/model-typings': patch
'@rocket.chat/ui-video-conf': patch
'@rocket.chat/uikit-playground': patch
'@rocket.chat/core-typings': patch
'@rocket.chat/rest-typings': patch
'@rocket.chat/apps-engine': patch
'@rocket.chat/ui-composer': patch
'@rocket.chat/ui-contexts': patch
'@rocket.chat/gazzodown': patch
'@rocket.chat/ui-avatar': patch
'@rocket.chat/ui-client': patch
'@rocket.chat/livechat': patch
'@rocket.chat/ui-voip': patch
'@rocket.chat/i18n': patch
'@rocket.chat/meteor': patch
---

Fixes error propagation when trying to get the status of apps in some cases
21 changes: 21 additions & 0 deletions .changeset/perfect-ties-tell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
"@rocket.chat/meteor": minor
"@rocket.chat/core-typings": minor
"@rocket.chat/model-typings": minor
---

Adds statistics related to the new **Contact Identification** feature:
- `totalContacts`: Total number of contacts;
- `totalUnknownContacts`: Total number of unknown contacts;
- `totalMergedContacts`: Total number of merged contacts;
- `totalConflicts`: Total number of merge conflicts;
- `totalResolvedConflicts`: Total number of resolved conflicts;
- `totalBlockedContacts`: Total number of blocked contacts;
- `totalPartiallyBlockedContacts`: Total number of partially blocked contacts;
- `totalFullyBlockedContacts`: Total number of fully blocked contacts;
- `totalVerifiedContacts`: Total number of verified contacts;
- `avgChannelsPerContact`: Average number of channels per contact;
- `totalContactsWithoutChannels`: Number of contacts without channels;
- `totalImportedContacts`: Total number of imported contacts;
- `totalUpsellViews`: Total number of "Advanced Contact Management" Upsell CTA views;
- `totalUpsellClicks`: Total number of "Advanced Contact Management" Upsell CTA clicks;
22 changes: 22 additions & 0 deletions .changeset/proud-planets-applaud.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
'@rocket.chat/fuselage-ui-kit': patch
'@rocket.chat/instance-status': patch
'@rocket.chat/ui-theming': patch
'@rocket.chat/model-typings': patch
'@rocket.chat/ui-video-conf': patch
'@rocket.chat/uikit-playground': patch
'@rocket.chat/core-typings': patch
'@rocket.chat/rest-typings': patch
'@rocket.chat/apps-engine': patch
'@rocket.chat/ui-composer': patch
'@rocket.chat/ui-contexts': patch
'@rocket.chat/gazzodown': patch
'@rocket.chat/ui-avatar': patch
'@rocket.chat/ui-client': patch
'@rocket.chat/livechat': patch
'@rocket.chat/ui-voip': patch
'@rocket.chat/i18n': patch
'@rocket.chat/meteor': patch
---

Fixes wrong data being reported to total failed apps metrics and statistics
11 changes: 9 additions & 2 deletions apps/meteor/app/importer/server/classes/Importer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { ImportDataConverter } from './ImportDataConverter';
import type { ConverterOptions } from './ImportDataConverter';
import { ImporterProgress } from './ImporterProgress';
import { ImporterWebsocket } from './ImporterWebsocket';
import { notifyOnSettingChangedById } from '../../../lib/server/lib/notifyListener';
import { notifyOnSettingChanged, notifyOnSettingChangedById } from '../../../lib/server/lib/notifyListener';
import { t } from '../../../utils/lib/i18n';
import { ProgressStep, ImportPreparingStartedStates } from '../../lib/ImporterProgressStep';
import type { ImporterInfo } from '../definitions/ImporterInfo';
Expand Down Expand Up @@ -183,6 +183,13 @@ export class Importer {
}
};

const afterContactsBatchFn = async (successCount: number) => {
const { value } = await Settings.incrementValueById('Contacts_Importer_Count', successCount, { returnDocument: 'after' });
if (value) {
void notifyOnSettingChanged(value);
}
};

const onErrorFn = async () => {
await this.addCountCompleted(1);
};
Expand All @@ -197,7 +204,7 @@ export class Importer {
await this.converter.convertUsers({ beforeImportFn, afterImportFn, onErrorFn, afterBatchFn });

await this.updateProgress(ProgressStep.IMPORTING_CONTACTS);
await this.converter.convertContacts({ beforeImportFn, afterImportFn, onErrorFn });
await this.converter.convertContacts({ beforeImportFn, afterImportFn, onErrorFn, afterBatchFn: afterContactsBatchFn });

await this.updateProgress(ProgressStep.IMPORTING_CHANNELS);
await this.converter.convertChannels(startedByUserId, { beforeImportFn, afterImportFn, onErrorFn });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ export class RecordConverter<R extends IImportRecord, T extends RecordConverterO

protected failedCount = 0;

protected newCount = 0;

public aborted = false;

constructor(options?: T, logger?: Logger, cache?: ConverterCache) {
Expand Down Expand Up @@ -194,11 +196,13 @@ export class RecordConverter<R extends IImportRecord, T extends RecordConverterO
afterImportFn,
onErrorFn,
processRecord,
afterBatchFn,
}: IConversionCallbacks & { processRecord?: (record: R) => Promise<boolean | undefined> } = {}): Promise<void> {
const records = await this.getDataToImport();

this.skippedCount = 0;
this.failedCount = 0;
this.newCount = 0;

for await (const record of records) {
const { _id } = record;
Expand All @@ -214,8 +218,11 @@ export class RecordConverter<R extends IImportRecord, T extends RecordConverterO

const isNew = await (processRecord || this.convertRecord).call(this, record);

if (typeof isNew === 'boolean' && afterImportFn) {
await afterImportFn(record, isNew);
if (typeof isNew === 'boolean') {
this.newCount++;
if (afterImportFn) {
await afterImportFn(record, isNew);
}
}
} catch (e) {
this.failedCount++;
Expand All @@ -225,6 +232,9 @@ export class RecordConverter<R extends IImportRecord, T extends RecordConverterO
}
}
}
if (afterBatchFn) {
await afterBatchFn(this.newCount, this.failedCount);
}
}

async convertData(callbacks: IConversionCallbacks = {}): Promise<void> {
Expand Down
21 changes: 17 additions & 4 deletions apps/meteor/app/livechat/server/lib/contacts/updateContact.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { ILivechatContact, ILivechatContactChannel } from '@rocket.chat/core-typings';
import { LivechatContacts, LivechatInquiry, LivechatRooms, Subscriptions } from '@rocket.chat/models';
import { LivechatContacts, LivechatInquiry, LivechatRooms, Settings, Subscriptions } from '@rocket.chat/models';

import { getAllowedCustomFields } from './getAllowedCustomFields';
import { validateContactManager } from './validateContactManager';
Expand All @@ -8,6 +8,7 @@ import {
notifyOnSubscriptionChangedByVisitorIds,
notifyOnRoomChangedByContactId,
notifyOnLivechatInquiryChangedByVisitorIds,
notifyOnSettingChanged,
} from '../../../../lib/server/lib/notifyListener';

export type UpdateContactParams = {
Expand All @@ -24,9 +25,12 @@ export type UpdateContactParams = {
export async function updateContact(params: UpdateContactParams): Promise<ILivechatContact> {
const { contactId, name, emails, phones, customFields: receivedCustomFields, contactManager, channels, wipeConflicts } = params;

const contact = await LivechatContacts.findOneById<Pick<ILivechatContact, '_id' | 'name' | 'customFields'>>(contactId, {
projection: { _id: 1, name: 1, customFields: 1 },
});
const contact = await LivechatContacts.findOneById<Pick<ILivechatContact, '_id' | 'name' | 'customFields' | 'conflictingFields'>>(
contactId,
{
projection: { _id: 1, name: 1, customFields: 1, conflictingFields: 1 },
},
);

if (!contact) {
throw new Error('error-contact-not-found');
Expand All @@ -36,6 +40,15 @@ export async function updateContact(params: UpdateContactParams): Promise<ILivec
await validateContactManager(contactManager);
}

if (wipeConflicts && contact.conflictingFields?.length) {
const { value } = await Settings.incrementValueById('Resolved_Conflicts_Count', contact.conflictingFields.length, {
returnDocument: 'after',
});
if (value) {
void notifyOnSettingChanged(value);
}
}

const workspaceAllowedCustomFields = await getAllowedCustomFields();
const workspaceAllowedCustomFieldsIds = workspaceAllowedCustomFields.map((customField) => customField._id);
const currentCustomFieldsIds = Object.keys(contact.customFields || {});
Expand Down
8 changes: 3 additions & 5 deletions apps/meteor/app/statistics/server/lib/getAppsStatistics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ async function _getAppsStatistics(): Promise<AppsStatistics> {
totalInstalled++;

const status = await app.getStatus();
const storageItem = await app.getStorageItem();
const storageItem = app.getStorageItem();

if (storageItem.installationSource === AppInstallationSource.PRIVATE) {
totalPrivateApps++;
Expand All @@ -51,12 +51,10 @@ async function _getAppsStatistics(): Promise<AppsStatistics> {
}
}

if (status === AppStatus.MANUALLY_DISABLED) {
totalFailed++;
}

if (AppStatusUtils.isEnabled(status)) {
totalActive++;
} else if (status !== AppStatus.MANUALLY_DISABLED) {
totalFailed++;
}
}),
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import type { IStats } from '@rocket.chat/core-typings';
import { LivechatContacts } from '@rocket.chat/models';

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

export async function getContactVerificationStatistics(): Promise<IStats['contactVerification']> {
const [
totalContacts,
totalUnknownContacts,
[{ totalConflicts, avgChannelsPerContact } = { totalConflicts: 0, avgChannelsPerContact: 0 }],
totalBlockedContacts,
totalFullyBlockedContacts,
totalVerifiedContacts,
totalContactsWithoutChannels,
] = await Promise.all([
LivechatContacts.estimatedDocumentCount(),
LivechatContacts.countUnknown(),
LivechatContacts.getStatistics().toArray(),
LivechatContacts.countBlocked(),
LivechatContacts.countFullyBlocked(),
LivechatContacts.countVerified(),
LivechatContacts.countContactsWithoutChannels(),
]);

return {
totalContacts,
totalUnknownContacts,
totalMergedContacts: settings.get('Merged_Contacts_Count'),
totalConflicts,
totalResolvedConflicts: settings.get('Resolved_Conflicts_Count'),
totalBlockedContacts,
totalPartiallyBlockedContacts: totalBlockedContacts - totalFullyBlockedContacts,
totalFullyBlockedContacts,
totalVerifiedContacts,
avgChannelsPerContact,
totalContactsWithoutChannels,
totalImportedContacts: settings.get('Contacts_Importer_Count'),
totalUpsellViews: settings.get('Advanced_Contact_Upsell_Views_Count'),
totalUpsellClicks: settings.get('Advanced_Contact_Upsell_Clicks_Count'),
};
}
2 changes: 2 additions & 0 deletions apps/meteor/app/statistics/server/lib/statistics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import { MongoInternals } from 'meteor/mongo';
import moment from 'moment';

import { getAppsStatistics } from './getAppsStatistics';
import { getContactVerificationStatistics } from './getContactVerificationStatistics';
import { getStatistics as getEnterpriseStatistics } from './getEEStatistics';
import { getImporterStatistics } from './getImporterStatistics';
import { getServicesStatistics } from './getServicesStatistics';
Expand Down Expand Up @@ -477,6 +478,7 @@ export const statistics = {
statistics.services = await getServicesStatistics();
statistics.importer = getImporterStatistics();
statistics.videoConf = await VideoConf.getStatistics();
statistics.contactVerification = await getContactVerificationStatistics();

// If getSettingsStatistics() returns an error, save as empty object.
statsPms.push(
Expand Down
Loading

0 comments on commit bd9ef32

Please sign in to comment.