Skip to content

Commit

Permalink
Merge branch 'develop' into revert-30321-new/dmnotify
Browse files Browse the repository at this point in the history
  • Loading branch information
kodiakhq[bot] authored Sep 12, 2023
2 parents 21a165e + 8202f27 commit e8523fe
Show file tree
Hide file tree
Showing 37 changed files with 497 additions and 544 deletions.
8 changes: 8 additions & 0 deletions .changeset/strong-laws-pump.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
'@rocket.chat/model-typings': patch
'@rocket.chat/meteor': patch
---

Change SAU aggregation to consider only sessions from few days ago instead of the whole past.

This is particularly important for large workspaces in case the cron job did not run for some time, in that case the amount of sessions would accumulate and the aggregation would take a long time to run.
6 changes: 6 additions & 0 deletions .changeset/wise-walls-tan.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@rocket.chat/rest-typings': minor
'@rocket.chat/meteor': minor
---

fix: missing params on updateOwnBasicInfo endpoint
5 changes: 5 additions & 0 deletions .changeset/young-trains-glow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@rocket.chat/meteor': minor
---

Fixed the issue of apps icon uneven alignment in case of missing icons inside message composer toolbar & message toolbar menu.
2 changes: 2 additions & 0 deletions apps/meteor/app/api/server/v1/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,9 @@ API.v1.addRoute(
realname: this.bodyParams.data.name,
username: this.bodyParams.data.username,
nickname: this.bodyParams.data.nickname,
bio: this.bodyParams.data.bio,
statusText: this.bodyParams.data.statusText,
statusType: this.bodyParams.data.statusType,
newPassword: this.bodyParams.data.newPassword,
typedPassword: this.bodyParams.data.currentPassword,
};
Expand Down
25 changes: 25 additions & 0 deletions apps/meteor/app/mentions/server/getMentionedTeamMembers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { Team } from '@rocket.chat/core-services';
import type { IMessage } from '@rocket.chat/core-typings';

import { callbacks } from '../../../lib/callbacks';

interface IExtraDataForNotification {
userMentions: any[];
otherMentions: any[];
message: IMessage;
}

callbacks.add('beforeGetMentions', async (mentionIds: string[], extra?: IExtraDataForNotification) => {
const { otherMentions } = extra ?? {};

const teamIds = otherMentions?.filter(({ type }) => type === 'team').map(({ _id }) => _id);

if (!teamIds?.length) {
return mentionIds;
}

const members = await Team.getMembersByTeamIds(teamIds, { projection: { userId: 1 } });
mentionIds.push(...new Set(members.map(({ userId }) => userId).filter((userId) => !mentionIds.includes(userId))));

return mentionIds;
});
3 changes: 2 additions & 1 deletion apps/meteor/app/mentions/server/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
import './server';
import './getMentionedTeamMembers';
import './methods/getUserMentionsByChannel';
import './server';
24 changes: 18 additions & 6 deletions apps/meteor/app/mentions/server/server.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { api } from '@rocket.chat/core-services';
import type { IUser, IRoom } from '@rocket.chat/core-typings';
import { api, Team } from '@rocket.chat/core-services';
import type { IUser, IRoom, ITeam } from '@rocket.chat/core-typings';
import { Subscriptions, Users, Rooms } from '@rocket.chat/models';
import { Meteor } from 'meteor/meteor';

Expand All @@ -9,16 +9,28 @@ import { settings } from '../../settings/server';
import MentionsServer from './Mentions';

export class MentionQueries {
async getUsers(usernames: string[]): Promise<(Pick<IUser, '_id' | 'username' | 'name'> & { type: 'user' })[]> {
async getUsers(
usernames: string[],
): Promise<((Pick<IUser, '_id' | 'username' | 'name'> & { type: 'user' }) | (Pick<ITeam, '_id' | 'name'> & { type: 'team' }))[]> {
const uniqueUsernames = [...new Set(usernames)];
const teams = await Team.listByNames(uniqueUsernames, { projection: { name: 1 } });

const users = await Users.find(
{ username: { $in: [...new Set(usernames)] } },
{ username: { $in: uniqueUsernames } },
{ projection: { _id: true, username: true, name: 1 } },
).toArray();

return users.map((user) => ({
const taggedUsers = users.map((user) => ({
...user,
type: 'user',
type: 'user' as const,
}));

const taggedTeams = teams.map((team) => ({
...team,
type: 'team' as const,
}));

return [...taggedUsers, ...taggedTeams];
}

async getUser(userId: string): Promise<IUser | null> {
Expand Down
38 changes: 12 additions & 26 deletions apps/meteor/app/statistics/server/lib/SAUMonitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -318,33 +318,19 @@ export class SAUMonitorClass {
return;
}

logger.info('[aggregate] - Aggregating data.');

const date = new Date();
date.setDate(date.getDate() - 0); // yesterday
const yesterday = getDateObj(date);

for await (const record of aggregates.dailySessionsOfYesterday(Sessions.col, yesterday)) {
await Sessions.updateOne(
{ _id: `${record.userId}-${record.year}-${record.month}-${record.day}` },
{ $set: record },
{ upsert: true },
);
const today = new Date();

// get sessions from 3 days ago to make sure even if a few cron jobs were skipped, we still have the data
const threeDaysAgo = new Date(today.getFullYear(), today.getMonth(), today.getDate() - 3, 0, 0, 0, 0);

const period = { start: getDateObj(threeDaysAgo), end: getDateObj(today) };

logger.info({ msg: '[aggregate] - Aggregating data.', period });

for await (const record of aggregates.dailySessions(Sessions.col, period)) {
await Sessions.updateDailySessionById(`${record.userId}-${record.year}-${record.month}-${record.day}`, record);
}

await Sessions.updateMany(
{
type: 'session',
year: { $lte: yesterday.year },
month: { $lte: yesterday.month },
day: { $lte: yesterday.day },
},
{
$set: {
type: 'computed-session',
_computedAt: new Date(),
},
},
);
await Sessions.updateAllSessionsByDateToComputed(period);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ const MessageActionMenu = ({ options, onChangeMenuVisibility, ...props }: Messag
data-qa-type='message-action'
data-qa-id={option.id}
role={option.role ? option.role : 'button'}
gap={!option.icon && option.type === 'apps'}
/>
))}
{index !== arr.length - 1 && <OptionDivider />}
Expand Down
4 changes: 3 additions & 1 deletion apps/meteor/client/lib/2fa/process2faReturn.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { SHA256 } from '@rocket.chat/sha256';
import { Meteor } from 'meteor/meteor';
import { lazy } from 'react';

import TwoFactorModal from '../../components/TwoFactorModal';
import { imperativeModal } from '../imperativeModal';
import { isTotpInvalidError, isTotpRequiredError } from './utils';

const TwoFactorModal = lazy(() => import('../../components/TwoFactorModal'));

const twoFactorMethods = ['totp', 'email', 'password'] as const;

type TwoFactorMethod = (typeof twoFactorMethods)[number];
Expand Down
24 changes: 13 additions & 11 deletions apps/meteor/client/main.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import '../ee/client/ecdh';
import './polyfills';
import { FlowRouter } from 'meteor/kadira:flow-router';

import '../lib/oauthRedirectUriClient';
import './lib/meteorCallWrapper';
import './importPackages';
FlowRouter.wait();

import '../ee/client';
import './methods';
import './startup';
import './views/admin';
import './views/marketplace';
import './views/account';
FlowRouter.notFound = {
action: () => undefined,
};

import('./polyfills')
.then(() => Promise.all([import('./lib/meteorCallWrapper'), import('../lib/oauthRedirectUriClient')]))
.then(() => import('../ee/client/ecdh'))
.then(() => import('./importPackages'))
.then(() => Promise.all([import('./methods'), import('./startup')]))
.then(() => import('../ee/client'))
.then(() => Promise.all([import('./views/admin'), import('./views/marketplace'), import('./views/account')]));
1 change: 0 additions & 1 deletion apps/meteor/client/polyfills/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,3 @@ import './childNodeRemove';
import './cssVars';
import './customEventPolyfill';
import './hoverTouchClick';
import './objectFromEntries';
5 changes: 0 additions & 5 deletions apps/meteor/client/polyfills/objectFromEntries.ts

This file was deleted.

6 changes: 0 additions & 6 deletions apps/meteor/client/providers/RouterProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,6 @@ import React from 'react';
import { appLayout } from '../lib/appLayout';
import { queueMicrotask } from '../lib/utils/queueMicrotask';

FlowRouter.wait();

FlowRouter.notFound = {
action: () => undefined,
};

const subscribers = new Set<() => void>();

const listenToRouteChange = () => {
Expand Down
90 changes: 90 additions & 0 deletions apps/meteor/client/views/admin/rooms/RoomRow.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import { isDiscussion } from '@rocket.chat/core-typings';
import type { IRoom, RoomAdminFieldsType } from '@rocket.chat/core-typings';
import { Box, Icon } from '@rocket.chat/fuselage';
import { useMediaQuery } from '@rocket.chat/fuselage-hooks';
import { useRouter, useTranslation } from '@rocket.chat/ui-contexts';
import React, { useCallback } from 'react';

import { GenericTableCell, GenericTableRow } from '../../../components/GenericTable';
import RoomAvatar from '../../../components/avatar/RoomAvatar';
import { roomCoordinator } from '../../../lib/rooms/roomCoordinator';

const roomTypeI18nMap = {
l: 'Omnichannel',
c: 'Channel',
d: 'Direct_Message',
p: 'Private_Channel',
} as const;

const getRoomDisplayName = (room: Pick<IRoom, RoomAdminFieldsType>): string | undefined =>
room.t === 'd' ? room.usernames?.join(' x ') : roomCoordinator.getRoomName(room.t, room);

const RoomRow = ({ room }: { room: Pick<IRoom, RoomAdminFieldsType> }) => {
const t = useTranslation();
const mediaQuery = useMediaQuery('(min-width: 1024px)');
const router = useRouter();

const { _id, t: type, usersCount, msgs, default: isDefault, featured, ...args } = room;
const icon = roomCoordinator.getRoomDirectives(room.t).getIcon?.(room);
const roomName = getRoomDisplayName(room);

const getRoomType = (
room: Pick<IRoom, RoomAdminFieldsType>,
): (typeof roomTypeI18nMap)[keyof typeof roomTypeI18nMap] | 'Teams_Public_Team' | 'Teams_Private_Team' | 'Discussion' => {
if (room.teamMain) {
return room.t === 'c' ? 'Teams_Public_Team' : 'Teams_Private_Team';
}
if (isDiscussion(room)) {
return 'Discussion';
}
return roomTypeI18nMap[(room as IRoom).t as keyof typeof roomTypeI18nMap];
};

const onClick = useCallback(
(rid) => (): void =>
router.navigate({
name: 'admin-rooms',
params: {
context: 'edit',
id: rid,
},
}),
[router],
);

return (
<GenericTableRow action key={_id} onKeyDown={onClick(_id)} onClick={onClick(_id)} tabIndex={0} role='link' qa-room-id={_id}>
<GenericTableCell withTruncatedText>
<Box display='flex' alignContent='center'>
<RoomAvatar size={mediaQuery ? 'x28' : 'x40'} room={{ type, name: roomName, _id, ...args }} />
<Box
display='flex'
flexGrow={1}
flexShrink={1}
flexBasis='0%'
flexDirection='row'
alignSelf='center'
alignItems='center'
withTruncatedText
>
{icon && <Icon mi={4} name={icon} fontScale='p2m' color='hint' />}
<Box fontScale='p2m' withTruncatedText color='default' qa-room-name={roomName}>
{roomName}
</Box>
</Box>
</Box>
</GenericTableCell>
<GenericTableCell>
<Box color='hint' fontScale='p2m' withTruncatedText>
{t(getRoomType(room))}
</Box>
</GenericTableCell>
<GenericTableCell withTruncatedText>{usersCount}</GenericTableCell>
{mediaQuery && <GenericTableCell withTruncatedText>{msgs}</GenericTableCell>}
{mediaQuery && <GenericTableCell withTruncatedText>{isDefault ? t('True') : t('False')}</GenericTableCell>}
{mediaQuery && <GenericTableCell withTruncatedText>{featured ? t('True') : t('False')}</GenericTableCell>}
</GenericTableRow>
);
};

export default RoomRow;
Loading

0 comments on commit e8523fe

Please sign in to comment.