Skip to content

Commit

Permalink
Merge branch 'develop' into refactor/deprecate-set-reaction-callbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
kodiakhq[bot] authored Sep 18, 2024
2 parents 3953c4a + ba8bee4 commit aeb67bf
Show file tree
Hide file tree
Showing 35 changed files with 1,412 additions and 93 deletions.
7 changes: 7 additions & 0 deletions .changeset/dirty-stingrays-beg.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@rocket.chat/meteor": minor
"@rocket.chat/model-typings": minor
"@rocket.chat/rest-typings": minor
---

Added support for specifying a unit on departments' creation and update
5 changes: 5 additions & 0 deletions .changeset/hot-balloons-travel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@rocket.chat/meteor": patch
---

Fixed issue where when you marked a room as unread and you were part of it, sometimes it would mark it as read right after
5 changes: 5 additions & 0 deletions .changeset/small-crabs-travel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@rocket.chat/meteor': patch
---

Fixed avatar blob image setting in setUserAvatar method by correcting service handling logic.
9 changes: 9 additions & 0 deletions .changeset/strong-grapes-brake.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
'@rocket.chat/meteor': patch
---

Fixed remaining direct references to external user avatar URLs

Fixed local avatars having priority over external provider

It mainly corrects the behavior of E2E encryption messages and desktop notifications.
23 changes: 11 additions & 12 deletions apps/meteor/app/lib/server/functions/setUsername.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,23 +102,22 @@ export const _setUsername = async function (userId: string, u: string, fullUser:
// Set new username*
await Users.setUsername(user._id, username);
user.username = username;

if (!previousUsername && settings.get('Accounts_SetDefaultAvatar') === true) {
// eslint-disable-next-line @typescript-eslint/ban-types
const avatarSuggestions = (await getAvatarSuggestionForUser(user)) as {};
let gravatar;
for await (const service of Object.keys(avatarSuggestions)) {
const avatarData = avatarSuggestions[+service as keyof typeof avatarSuggestions];
const avatarSuggestions = await getAvatarSuggestionForUser(user);
let avatarData;
let serviceName = 'gravatar';

for (const service of Object.keys(avatarSuggestions)) {
avatarData = avatarSuggestions[service];
if (service !== 'gravatar') {
// eslint-disable-next-line dot-notation
await setUserAvatar(user, avatarData['blob'], avatarData['contentType'], service);
gravatar = null;
serviceName = service;
break;
}
gravatar = avatarData;
}
if (gravatar != null) {
// eslint-disable-next-line dot-notation
await setUserAvatar(user, gravatar['blob'], gravatar['contentType'], 'gravatar');

if (avatarData) {
await setUserAvatar(user, avatarData.blob, avatarData.contentType, serviceName);
}
}

Expand Down
15 changes: 12 additions & 3 deletions apps/meteor/app/livechat/imports/server/rest/departments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,18 @@ API.v1.addRoute(
check(this.bodyParams, {
department: Object,
agents: Match.Maybe(Array),
departmentUnit: Match.Maybe({ _id: Match.Optional(String) }),
});

const agents = this.bodyParams.agents ? { upsert: this.bodyParams.agents } : {};
const department = await LivechatTs.saveDepartment(null, this.bodyParams.department as ILivechatDepartment, agents);
const { departmentUnit } = this.bodyParams;
const department = await LivechatTs.saveDepartment(
this.userId,
null,
this.bodyParams.department as ILivechatDepartment,
agents,
departmentUnit || {},
);

if (department) {
return API.v1.success({
Expand Down Expand Up @@ -112,17 +120,18 @@ API.v1.addRoute(
check(this.bodyParams, {
department: Object,
agents: Match.Maybe(Array),
departmentUnit: Match.Maybe({ _id: Match.Optional(String) }),
});

const { _id } = this.urlParams;
const { department, agents } = this.bodyParams;
const { department, agents, departmentUnit } = this.bodyParams;

if (!permissionToSave) {
throw new Error('error-not-allowed');
}

const agentParam = permissionToAddAgents && agents ? { upsert: agents } : {};
await LivechatTs.saveDepartment(_id, department, agentParam);
await LivechatTs.saveDepartment(this.userId, _id, department, agentParam, departmentUnit || {});

return API.v1.success({
department: await LivechatDepartment.findOneById(_id),
Expand Down
25 changes: 24 additions & 1 deletion apps/meteor/app/livechat/server/lib/LivechatTyped.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1789,18 +1789,37 @@ class LivechatClass {
* @param {string|null} _id - The department id
* @param {Partial<import('@rocket.chat/core-typings').ILivechatDepartment>} departmentData
* @param {{upsert?: { agentId: string; count?: number; order?: number; }[], remove?: { agentId: string; count?: number; order?: number; }}} [departmentAgents] - The department agents
* @param {{_id?: string}} [departmentUnit] - The department's unit id
*/
async saveDepartment(
userId: string,
_id: string | null,
departmentData: LivechatDepartmentDTO,
departmentAgents?: {
upsert?: { agentId: string; count?: number; order?: number }[];
remove?: { agentId: string; count?: number; order?: number };
},
departmentUnit?: { _id?: string },
) {
check(_id, Match.Maybe(String));
if (departmentUnit?._id !== undefined && typeof departmentUnit._id !== 'string') {
throw new Meteor.Error('error-invalid-department-unit', 'Invalid department unit id provided', {
method: 'livechat:saveDepartment',
});
}

const department = _id ? await LivechatDepartment.findOneById(_id, { projection: { _id: 1, archived: 1, enabled: 1 } }) : null;
const department = _id
? await LivechatDepartment.findOneById(_id, { projection: { _id: 1, archived: 1, enabled: 1, parentId: 1 } })
: null;

if (departmentUnit && !departmentUnit._id && department && department.parentId) {
const isLastDepartmentInUnit = (await LivechatDepartment.countDepartmentsInUnit(department.parentId)) === 1;
if (isLastDepartmentInUnit) {
throw new Meteor.Error('error-unit-cant-be-empty', "The last department in a unit can't be removed", {
method: 'livechat:saveDepartment',
});
}
}

if (!department && !(await isDepartmentCreationAvailable())) {
throw new Meteor.Error('error-max-departments-number-reached', 'Maximum number of departments reached', {
Expand Down Expand Up @@ -1887,6 +1906,10 @@ class LivechatClass {
await callbacks.run('livechat.afterDepartmentDisabled', departmentDB);
}

if (departmentUnit) {
await callbacks.run('livechat.manageDepartmentUnit', { userId, departmentId: departmentDB._id, unitId: departmentUnit._id });
}

return departmentDB;
}
}
Expand Down
5 changes: 3 additions & 2 deletions apps/meteor/app/livechat/server/methods/saveDepartment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,20 @@ declare module '@rocket.chat/ddp-client' {
order?: number | undefined;
}[]
| undefined,
departmentUnit?: { _id?: string },
) => ILivechatDepartment;
}
}

Meteor.methods<ServerMethods>({
async 'livechat:saveDepartment'(_id, departmentData, departmentAgents) {
async 'livechat:saveDepartment'(_id, departmentData, departmentAgents, departmentUnit) {
const uid = Meteor.userId();
if (!uid || !(await hasPermissionAsync(uid, 'manage-livechat-departments'))) {
throw new Meteor.Error('error-not-allowed', 'Not allowed', {
method: 'livechat:saveDepartment',
});
}

return Livechat.saveDepartment(_id, departmentData, { upsert: departmentAgents });
return Livechat.saveDepartment(uid, _id, departmentData, { upsert: departmentAgents }, departmentUnit);
},
});
4 changes: 2 additions & 2 deletions apps/meteor/app/message-mark-as-unread/client/actionButton.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@ Meteor.startup(() => {
const { message = messageArgs(this).msg } = props;

try {
await sdk.call('unreadMessages', message);
const subscription = ChatSubscription.findOne({
rid: message.rid,
});

if (subscription == null) {
return;
}
router.navigate('/home');
await LegacyRoomManager.close(subscription.t + subscription.name);
return router.navigate('/home');
await sdk.call('unreadMessages', message);
} catch (error) {
dispatchToastMessage({ type: 'error', message: error });
}
Expand Down
5 changes: 0 additions & 5 deletions apps/meteor/app/utils/client/getUserAvatarURL.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
import { settings } from '../../settings/client';
import { getAvatarURL } from './getAvatarURL';

export const getUserAvatarURL = function (username: string, cache = ''): string | undefined {
const externalSource = (settings.get<string>('Accounts_AvatarExternalProviderUrl') || '').trim().replace(/\/$/, '');
if (externalSource !== '') {
return externalSource.replace('{username}', username);
}
if (username == null) {
return;
}
Expand Down
5 changes: 0 additions & 5 deletions apps/meteor/app/utils/server/getUserAvatarURL.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
import { settings } from '../../settings/server';
import { getAvatarURL } from './getAvatarURL';

export const getUserAvatarURL = function (username: string, cache = ''): string | undefined {
const externalSource = (settings.get<string>('Accounts_AvatarExternalProviderUrl') || '').trim().replace(/\/$/, '');
if (externalSource !== '') {
return externalSource.replace('{username}', username);
}
if (username == null) {
return;
}
Expand Down
8 changes: 2 additions & 6 deletions apps/meteor/client/providers/AvatarUrlProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AvatarUrlContext, useSetting } from '@rocket.chat/ui-contexts';
import { AvatarUrlContext } from '@rocket.chat/ui-contexts';
import type { ReactNode } from 'react';
import React, { useMemo } from 'react';

Expand All @@ -10,19 +10,15 @@ type AvatarUrlProviderProps = {
};

const AvatarUrlProvider = ({ children }: AvatarUrlProviderProps) => {
const cdnAvatarUrl = String(useSetting('CDN_PREFIX') || '');
const contextValue = useMemo(
() => ({
getUserPathAvatar: ((): ((uid: string, etag?: string) => string) => {
if (cdnAvatarUrl) {
return (uid: string, etag?: string): string => `${cdnAvatarUrl}/avatar/${uid}${etag ? `?etag=${etag}` : ''}`;
}
return (uid: string, etag?: string): string => getURL(`/avatar/${uid}${etag ? `?etag=${etag}` : ''}`);
})(),
getRoomPathAvatar: ({ type, ...room }: any): string =>
roomCoordinator.getRoomDirectives(type || room.t).getAvatarPath({ username: room._id, ...room }) || '',
}),
[cdnAvatarUrl],
[],
);

return <AvatarUrlContext.Provider children={children} value={contextValue} />;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ function SideBarItemTemplateWithData({
const badges = (
<Margins inlineStart={8}>
{showBadge && isUnread && (
<Badge {...({ style: { display: 'inline-flex', flexShrink: 0 } } as any)} variant={variant} title={badgeTitle}>
<Badge role='status' {...({ style: { display: 'inline-flex', flexShrink: 0 } } as any)} variant={variant} title={badgeTitle}>
{unread + tunread?.length}
</Badge>
)}
Expand All @@ -180,6 +180,7 @@ function SideBarItemTemplateWithData({
is='a'
id={id}
data-qa='sidebar-item'
data-unread={highlighted}
unread={highlighted}
selected={selected}
href={href}
Expand All @@ -205,7 +206,7 @@ function SideBarItemTemplateWithData({
threadUnread={threadUnread}
rid={rid}
unread={!!unread}
roomOpen={false}
roomOpen={selected}
type={type}
cl={cl}
name={title}
Expand Down
10 changes: 9 additions & 1 deletion apps/meteor/client/sidebar/RoomMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
useTranslation,
useEndpoint,
} from '@rocket.chat/ui-contexts';
import { useQueryClient } from '@tanstack/react-query';
import type { ReactElement } from 'react';
import React, { memo, useMemo } from 'react';

Expand Down Expand Up @@ -100,6 +101,8 @@ const RoomMenu = ({
const isOmnichannelRoom = type === 'l';
const prioritiesMenu = useOmnichannelPrioritiesMenu(rid);

const queryClient = useQueryClient();

const canLeave = ((): boolean => {
if (type === 'c' && !canLeaveChannel) {
return false;
Expand Down Expand Up @@ -173,17 +176,22 @@ const RoomMenu = ({

const handleToggleRead = useMutableCallback(async () => {
try {
queryClient.invalidateQueries(['sidebar/search/spotlight']);

if (isUnread) {
await readMessages({ rid, readThreads: true });
return;
}
await unreadMessages(undefined, rid);

if (subscription == null) {
return;
}

LegacyRoomManager.close(subscription.t + subscription.name);

router.navigate('/home');

await unreadMessages(undefined, rid);
} catch (error) {
dispatchToastMessage({ type: 'error', message: error });
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ const SidebarItemTemplateWithData = ({
is='a'
id={id}
data-qa='sidebar-item'
data-unread={highlighted}
unread={highlighted}
selected={selected}
href={href}
Expand All @@ -205,7 +206,7 @@ const SidebarItemTemplateWithData = ({
threadUnread={threadUnread}
rid={rid}
unread={!!unread}
roomOpen={false}
roomOpen={selected}
type={type}
cl={cl}
name={title}
Expand Down
10 changes: 9 additions & 1 deletion apps/meteor/client/sidebarv2/RoomMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
useTranslation,
useEndpoint,
} from '@rocket.chat/ui-contexts';
import { useQueryClient } from '@tanstack/react-query';
import type { ReactElement } from 'react';
import React, { memo, useMemo } from 'react';

Expand Down Expand Up @@ -100,6 +101,8 @@ const RoomMenu = ({
const isOmnichannelRoom = type === 'l';
const prioritiesMenu = useOmnichannelPrioritiesMenu(rid);

const queryClient = useQueryClient();

const canLeave = ((): boolean => {
if (type === 'c' && !canLeaveChannel) {
return false;
Expand Down Expand Up @@ -173,17 +176,22 @@ const RoomMenu = ({

const handleToggleRead = useEffectEvent(async () => {
try {
queryClient.invalidateQueries(['sidebar/search/spotlight']);

if (isUnread) {
await readMessages({ rid, readThreads: true });
return;
}
await unreadMessages(undefined, rid);

if (subscription == null) {
return;
}

LegacyRoomManager.close(subscription.t + subscription.name);

router.navigate('/home');

await unreadMessages(undefined, rid);
} catch (error) {
dispatchToastMessage({ type: 'error', message: error });
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@ import './afterInquiryQueued';
import './sendPdfTranscriptOnClose';
import './applyRoomRestrictions';
import './afterTagRemoved';
import './manageDepartmentUnit';
Loading

0 comments on commit aeb67bf

Please sign in to comment.