Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
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
242 changes: 1 addition & 241 deletions apps/meteor/app/ui-sidenav/client/roomList.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { Meteor } from 'meteor/meteor';
import { Template } from 'meteor/templating';

import { callbacks } from '../../../lib/callbacks';
import { UiTextContext } from '../../../definition/IRoomTypeConfig';
import { ChatSubscription, Rooms, Users, Subscriptions } from '../../models/client';
import { ChatSubscription, Rooms, Users } from '../../models/client';
import { getUserPreference } from '../../utils';
import { settings } from '../../settings';
import { roomCoordinator } from '../../../client/lib/rooms/roomCoordinator';
Expand Down Expand Up @@ -117,242 +116,3 @@ Template.roomList.helpers({
return roomCoordinator.getRoomDirectives(instance.data.identifier)?.getUiText(UiTextContext.NO_ROOMS_SUBSCRIBED) || 'No_channels_yet';
},
});

const getLowerCaseNames = (room, nameDefault = '', fnameDefault = '') => {
const name = room.name || nameDefault;
const fname = room.fname || fnameDefault || name;
return {
lowerCaseName: String(!room.prid ? name : fname).toLowerCase(),
lowerCaseFName: String(fname).toLowerCase(),
};
};

const mergeSubRoom = (subscription) => {
const options = {
fields: {
lm: 1,
lastMessage: 1,
uids: 1,
streamingOptions: 1,
usernames: 1,
usersCount: 1,
topic: 1,
encrypted: 1,
// autoTranslate: 1,
// autoTranslateLanguage: 1,
description: 1,
announcement: 1,
broadcast: 1,
archived: 1,
avatarETag: 1,
retention: 1,
teamId: 1,
teamMain: 1,
msgs: 1,
onHold: 1,
metrics: 1,
muted: 1,
servedBy: 1,
ts: 1,
waitingResponse: 1,
v: 1,
transcriptRequest: 1,
tags: 1,
closedAt: 1,
responseBy: 1,
priorityId: 1,
livechatData: 1,
departmentId: 1,
source: 1,
queuedAt: 1,
federated: 1,
},
};

const room = Rooms.findOne({ _id: subscription.rid }, options) || {};

const lastRoomUpdate = room.lm || subscription.ts || subscription._updatedAt;

const {
encrypted,
description,
cl,
topic,
announcement,
broadcast,
archived,
avatarETag,
retention,
lastMessage,
streamingOptions,
teamId,
teamMain,
uids,
usernames,
usersCount,
v,
transcriptRequest,
servedBy,
onHold,
tags,
closedAt,
metrics,
muted,
waitingResponse,
responseBy,
priorityId,
livechatData,
departmentId,
ts,
source,
queuedAt,
federated,
} = room;

subscription.lm = subscription.lr ? new Date(Math.max(subscription.lr, lastRoomUpdate)) : lastRoomUpdate;

return Object.assign(subscription, getLowerCaseNames(subscription), {
encrypted,
description,
cl,
topic,
announcement,
broadcast,
archived,
avatarETag,
retention,
lastMessage,
streamingOptions,
teamId,
teamMain,
uids,
usernames,
usersCount,
v,
transcriptRequest,
servedBy,
onHold,
tags,
closedAt,
metrics,
muted,
waitingResponse,
responseBy,
priorityId,
livechatData,
departmentId,
ts,
source,
queuedAt,
federated,
});
};

const mergeRoomSub = (room) => {
const sub = Subscriptions.findOne({ rid: room._id });
if (!sub) {
return room;
}

const {
encrypted,
description,
cl,
topic,
announcement,
broadcast,
archived,
avatarETag,
retention,
lastMessage,
streamingOptions,
teamId,
teamMain,
uids,
usernames,
usersCount,
v,
transcriptRequest,
servedBy,
onHold,
tags,
closedAt,
metrics,
muted,
waitingResponse,
responseBy,
priorityId,
livechatData,
departmentId,
ts,
source,
queuedAt,
federated,
} = room;

Subscriptions.update(
{
rid: room._id,
},
{
$set: {
encrypted,
description,
cl,
topic,
announcement,
broadcast,
archived,
avatarETag,
retention,
uids,
usernames,
usersCount,
lastMessage,
streamingOptions,
teamId,
teamMain,
v,
transcriptRequest,
servedBy,
onHold,
tags,
closedAt,
metrics,
muted,
waitingResponse,
responseBy,
priorityId,
livechatData,
departmentId,
ts,
source,
queuedAt,
federated,
...getLowerCaseNames(room, sub.name, sub.fname),
},
},
);

Subscriptions.update(
{
rid: room._id,
lm: { $lt: room.lm },
},
{
$set: {
lm: room.lm,
},
},
);

return room;
};

callbacks.add('cachedCollection-received-rooms', mergeRoomSub);
callbacks.add('cachedCollection-sync-rooms', mergeRoomSub);
callbacks.add('cachedCollection-loadFromServer-rooms', mergeRoomSub);

callbacks.add('cachedCollection-received-subscriptions', mergeSubRoom);
callbacks.add('cachedCollection-sync-subscriptions', mergeSubRoom);
callbacks.add('cachedCollection-loadFromServer-subscriptions', mergeSubRoom);
2 changes: 1 addition & 1 deletion apps/meteor/app/ui-utils/client/lib/MessageAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import type { TranslationKey } from '@rocket.chat/ui-contexts';

import { Messages, Rooms, Subscriptions } from '../../../models/client';
import { roomCoordinator } from '../../../../client/lib/rooms/roomCoordinator';
import type { ToolboxContextValue } from '../../../../client/views/room/lib/Toolbox/ToolboxContext';
import type { ToolboxContextValue } from '../../../../client/views/room/contexts/ToolboxContext';

const call = (method: string, ...args: any[]): Promise<any> =>
new Promise((resolve, reject) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { ToolboxContextValue } from '../../../../../../client/views/room/lib/Toolbox/ToolboxContext';
import type { ToolboxContextValue } from '../../../../../../client/views/room/contexts/ToolboxContext';

export type CommonRoomTemplateInstance = {
data: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ function handleOpenUserCardButtonClick(event: JQuery.ClickEvent, template: Commo
target: event.currentTarget,
open: (e: MouseEvent) => {
e.preventDefault();
tabBar.openUserInfo(username);
tabBar.openRoomInfo(username);
},
});
}
Expand Down Expand Up @@ -327,7 +327,7 @@ function handleMentionLinkClick(event: JQuery.ClickEvent, template: CommonRoomTe
target: event.currentTarget,
open: (e: MouseEvent) => {
e.preventDefault();
tabBar.openUserInfo(username);
tabBar.openRoomInfo(username);
},
});
}
Expand Down
36 changes: 36 additions & 0 deletions apps/meteor/client/definitions/SubscriptionWithRoom.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { IOmnichannelRoom, IRoom, IRoomWithRetentionPolicy, ISubscription } from '@rocket.chat/core-typings';

export type SubscriptionWithRoom = ISubscription &
Pick<
IRoom,
| 'description'
| 'cl'
| 'topic'
| 'announcement'
| 'avatarETag'
| 'lastMessage'
| 'streamingOptions'
| 'uids'
| 'usernames'
| 'usersCount'
| 'muted'
| 'federated'
| 'lm'
> &
Pick<
IOmnichannelRoom,
| 'transcriptRequest'
| 'servedBy'
| 'tags'
| 'onHold'
| 'closedAt'
| 'metrics'
| 'waitingResponse'
| 'responseBy'
| 'priorityId'
| 'livechatData'
| 'departmentId'
| 'queuedAt'
> & {
source?: IOmnichannelRoom['source'];
} & Pick<Partial<IRoomWithRetentionPolicy>, 'retention'>;
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,17 @@ export const useStreamUpdatesForMessageList = (messageList: MessageList, uid: IU
return;
}

const unsubscribeFromRoomMessages = subscribeToRoomMessages<RoomMessagesRidEvent>(rid, (message) => {
const unsubscribeFromRoomMessages = subscribeToRoomMessages(rid, (message: RoomMessagesRidEvent) => {
messageList.handle(message);
});

const unsubscribeFromDeleteMessage = subscribeToNotifyRoom<NotifyRoomRidDeleteMessageEvent>(`${rid}/deleteMessage`, ({ _id: mid }) => {
const unsubscribeFromDeleteMessage = subscribeToNotifyRoom(`${rid}/deleteMessage`, ({ _id: mid }: NotifyRoomRidDeleteMessageEvent) => {
messageList.remove(mid);
});

const unsubscribeFromDeleteMessageBulk = subscribeToNotifyRoom<NotifyRoomRidDeleteMessageBulkEvent>(
const unsubscribeFromDeleteMessageBulk = subscribeToNotifyRoom(
`${rid}/deleteMessageBulk`,
(params) => {
(params: NotifyRoomRidDeleteMessageBulkEvent) => {
const matchDeleteCriteria = createDeleteCriteria(params);
messageList.prune(matchDeleteCriteria);
},
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/client/hooks/useEndpointData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { AsyncState, useAsyncState } from './useAsyncState';

const log = (name: string): Console['log'] =>
process.env.NODE_ENV !== 'production' || getConfig('debug') === 'true'
? (...args): void => console.log(name, ...args)
? (...args): void => console.warn(name, ...args)
: (): void => undefined;

const deprecationWarning = log('useEndpointData is deprecated, use @tanstack/react-query instead');
Expand Down
Loading