Skip to content
Closed
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
5 changes: 5 additions & 0 deletions .changeset/warm-boats-care.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@rocket.chat/meteor": major
---

Removes the deprecated `hideRoomsWithNoActivity` param from `admin/engagement-dashboard/channels/list`
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ export const useChannelsList = ({ period, offset, count }: UseChannelsListOption
end: end.toISOString(),
offset,
count,
hideRoomsWithNoActivity: true,
});

return response
Expand Down
18 changes: 2 additions & 16 deletions apps/meteor/ee/server/api/engagementDashboard/channels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@ import { check, Match } from 'meteor/check';

import { API } from '../../../../app/api/server';
import { getPaginationItems } from '../../../../app/api/server/helpers/getPaginationItems';
import { apiDeprecationLogger } from '../../../../app/lib/server/lib/deprecationWarningLogger';
import { findChannelsWithNumberOfMessages } from '../../lib/engagementDashboard/channels';
import { isDateISOString, mapDateForAPI } from '../../lib/engagementDashboard/date';

declare module '@rocket.chat/rest-typings' {
// eslint-disable-next-line @typescript-eslint/naming-convention
interface Endpoints {
'/v1/engagement-dashboard/channels/list': {
GET: (params: { start: string; end: string; offset?: number; count?: number; hideRoomsWithNoActivity?: boolean }) => {
GET: (params: { start: string; end: string; offset?: number; count?: number }) => {
channels: {
room: {
_id: IRoom['_id'];
Expand Down Expand Up @@ -47,30 +46,17 @@ API.v1.addRoute(
Match.ObjectIncluding({
start: Match.Where(isDateISOString),
end: Match.Where(isDateISOString),
hideRoomsWithNoActivity: Match.Maybe(String),
offset: Match.Maybe(String),
count: Match.Maybe(String),
}),
);

const { start, end, hideRoomsWithNoActivity } = this.queryParams;
const { start, end } = this.queryParams;
const { offset, count } = await getPaginationItems(this.queryParams);

if (hideRoomsWithNoActivity === undefined) {
apiDeprecationLogger.deprecatedParameterUsage(
this.route,
'hideRoomsWithNoActivity',
'7.0.0',
this.response,
({ parameter, endpoint, version }) =>
`Returning rooms that had no activity in ${endpoint} is deprecated and will be removed on version ${version} along with the \`${parameter}\` param. Set \`${parameter}\` as \`true\` to check how the endpoint will behave starting on ${version}`,
);
}

const { channels, total } = await findChannelsWithNumberOfMessages({
start: mapDateForAPI(start),
end: mapDateForAPI(end),
hideRoomsWithNoActivity: hideRoomsWithNoActivity === 'true',
options: { offset, count },
});

Expand Down
57 changes: 1 addition & 56 deletions apps/meteor/ee/server/lib/engagementDashboard/channels.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { IDirectMessageRoom, IRoom } from '@rocket.chat/core-typings';
import { Analytics, Rooms } from '@rocket.chat/models';
import { Analytics } from '@rocket.chat/models';
import moment from 'moment';

import { convertDateToInt, diffBetweenDaysInclusive } from './date';
Expand All @@ -8,12 +8,10 @@ import { roomCoordinator } from '../../../../server/lib/rooms/roomCoordinator';
export const findChannelsWithNumberOfMessages = async ({
start,
end,
hideRoomsWithNoActivity,
options = {},
}: {
start: Date;
end: Date;
hideRoomsWithNoActivity: boolean;
options: {
offset?: number;
count?: number;
Expand All @@ -34,10 +32,6 @@ export const findChannelsWithNumberOfMessages = async ({
}[];
total: number;
}> => {
if (!hideRoomsWithNoActivity) {
return findAllChannelsWithNumberOfMessages({ start, end, options });
}

const daysBetweenDates = diffBetweenDaysInclusive(end, start);
const endOfLastWeek = moment(start).subtract(1, 'days').toDate();
const startOfLastWeek = moment(endOfLastWeek).subtract(daysBetweenDates, 'days').toDate();
Expand All @@ -63,52 +57,3 @@ export const findChannelsWithNumberOfMessages = async ({
total,
};
};

export const findAllChannelsWithNumberOfMessages = async ({
start,
end,
options = {},
}: {
start: Date;
end: Date;
options: {
offset?: number;
count?: number;
};
}): Promise<{
channels: {
room: {
_id: IRoom['_id'];
name: IRoom['name'] | IRoom['fname'];
ts: IRoom['ts'];
t: IRoom['t'];
_updatedAt: IRoom['_updatedAt'];
usernames?: IDirectMessageRoom['usernames'];
};
messages: number;
lastWeekMessages: number;
diffFromLastWeek: number;
}[];
total: number;
}> => {
const daysBetweenDates = diffBetweenDaysInclusive(end, start);
const endOfLastWeek = moment(start).subtract(1, 'days').toDate();
const startOfLastWeek = moment(endOfLastWeek).subtract(daysBetweenDates, 'days').toDate();
const roomTypes = roomCoordinator.getTypesToShowOnDashboard() as Array<IRoom['t']>;

const channels = await Rooms.findChannelsByTypesWithNumberOfMessagesBetweenDate({
types: roomTypes,
start: convertDateToInt(start),
end: convertDateToInt(end),
startOfLastWeek: convertDateToInt(startOfLastWeek),
endOfLastWeek: convertDateToInt(endOfLastWeek),
options,
}).toArray();

const total = await Rooms.countDocuments({ t: { $in: roomTypes } });

return {
channels,
total,
};
};
9 changes: 3 additions & 6 deletions apps/meteor/tests/end-to-end/api/34-engagement-dashboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,14 +148,13 @@ describe('[Engagement Dashboard]', function () {
});
});

it('should not return empty rooms when the hideRoomsWithNoActivity param is provided', async () => {
it('should not return empty rooms', async () => {
await request
.get(api('engagement-dashboard/channels/list'))
.set(credentials)
.query({
end: new Date().toISOString(),
start: new Date(Date.now() - 7 * 24 * 60 * 60 * 1000).toISOString(),
hideRoomsWithNoActivity: true,
})
.expect('Content-Type', 'application/json')
.expect(200)
Expand Down Expand Up @@ -205,15 +204,14 @@ describe('[Engagement Dashboard]', function () {
});
});

it('should correctly count messages diff compared to last week when the hideRoomsWithNoActivity param is provided and there are messages in a room', async () => {
it('should correctly count messages diff compared to last week when the param is provided and there are messages in a room', async () => {
await sendSimpleMessage({ roomId: testRoom._id });
await request
.get(api('engagement-dashboard/channels/list'))
.set(credentials)
.query({
end: new Date().toISOString(),
start: new Date(Date.now() - 7 * 24 * 60 * 60 * 1000).toISOString(),
hideRoomsWithNoActivity: true,
})
.expect('Content-Type', 'application/json')
.expect(200)
Expand Down Expand Up @@ -275,14 +273,13 @@ describe('[Engagement Dashboard]', function () {
});
});

it('should correctly count messages from last week and diff when moving to the next week and providing the hideRoomsWithNoActivity param', async () => {
it('should correctly count messages from last week and diff when moving to the next week', async () => {
await request
.get(api('engagement-dashboard/channels/list'))
.set(credentials)
.query({
end: new Date(Date.now() + 8 * 24 * 60 * 60 * 1000).toISOString(),
start: new Date(Date.now() + 24 * 60 * 60 * 1000).toISOString(),
hideRoomsWithNoActivity: true,
})
.expect('Content-Type', 'application/json')
.expect(200)
Expand Down
Loading