snapshot of https://github.com/RocketChat/Rocket.Chat.git (develop, 2026-09-16; blobs > 131072B omitted)
Some checks failed
Create issues from TODOs / todos (push) Failing after 3s
Close inactive issues / close-issues (push) Has been cancelled
Deploy GitHub Pages / deploy-preview (push) Has been cancelled
CI / ⚙️ Variables Setup (push) Has been cancelled
CI / ⚙️ Test Guard (push) Has been cancelled
CI / 🚀 Notify external services - draft (push) Has been cancelled
CI / 📦 Build Packages (push) Has been cancelled
CI / 📦 Meteor Build (coverage) (push) Has been cancelled
CI / 📦 Meteor Build (production) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], fips) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Publish Docker Images (ghcr.io) (push) Has been cancelled
CI / 📦 Track Image Sizes (push) Has been cancelled
CI / 🔎 Code Check - Action Lint (push) Has been cancelled
CI / 🔎 Code Check (push) Has been cancelled
CI / 🔨 Test Storybook (push) Has been cancelled
CI / 🔨 Test Unit (push) Has been cancelled
CI / 🔨 Test API (CE) (push) Has been cancelled
CI / 🔨 Test API Livechat (CE) (push) Has been cancelled
CI / 🔨 Test UI (CE) (push) Has been cancelled
CI / 🔨 Test API (EE) (push) Has been cancelled
CI / 🔨 Test API Livechat (EE) (push) Has been cancelled
CI / 🔨 Test API Apps (deno-runtime - EE) (push) Has been cancelled
CI / 🔨 Test UI (EE) (push) Has been cancelled
CI / 🔨 Test API (FIPS) (push) Has been cancelled
CI / 🔨 Test API Livechat (FIPS) (push) Has been cancelled
CI / 🔨 Test UI (FIPS) (push) Has been cancelled
CI / 🔨 Test Federation Matrix (push) Has been cancelled
CI / 📊 Report Coverage (push) Has been cancelled
CI / ✅ Tests Done (push) Has been cancelled
CI / 🚀 Publish build assets (push) Has been cancelled
CI / 🚀 Publish Docker Images (DockerHub) (push) Has been cancelled
CI / 🚀 Notify external services (push) Has been cancelled
CI / Update Version Durability (push) Has been cancelled
Release / Release (push) Has been cancelled
Auto-close duplicate issues / auto-close-duplicates (push) Failing after 1s
Code scanning - action / CodeQL-Build (push) Failing after 1s
Some checks failed
Create issues from TODOs / todos (push) Failing after 3s
Close inactive issues / close-issues (push) Has been cancelled
Deploy GitHub Pages / deploy-preview (push) Has been cancelled
CI / ⚙️ Variables Setup (push) Has been cancelled
CI / ⚙️ Test Guard (push) Has been cancelled
CI / 🚀 Notify external services - draft (push) Has been cancelled
CI / 📦 Build Packages (push) Has been cancelled
CI / 📦 Meteor Build (coverage) (push) Has been cancelled
CI / 📦 Meteor Build (production) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], fips) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Publish Docker Images (ghcr.io) (push) Has been cancelled
CI / 📦 Track Image Sizes (push) Has been cancelled
CI / 🔎 Code Check - Action Lint (push) Has been cancelled
CI / 🔎 Code Check (push) Has been cancelled
CI / 🔨 Test Storybook (push) Has been cancelled
CI / 🔨 Test Unit (push) Has been cancelled
CI / 🔨 Test API (CE) (push) Has been cancelled
CI / 🔨 Test API Livechat (CE) (push) Has been cancelled
CI / 🔨 Test UI (CE) (push) Has been cancelled
CI / 🔨 Test API (EE) (push) Has been cancelled
CI / 🔨 Test API Livechat (EE) (push) Has been cancelled
CI / 🔨 Test API Apps (deno-runtime - EE) (push) Has been cancelled
CI / 🔨 Test UI (EE) (push) Has been cancelled
CI / 🔨 Test API (FIPS) (push) Has been cancelled
CI / 🔨 Test API Livechat (FIPS) (push) Has been cancelled
CI / 🔨 Test UI (FIPS) (push) Has been cancelled
CI / 🔨 Test Federation Matrix (push) Has been cancelled
CI / 📊 Report Coverage (push) Has been cancelled
CI / ✅ Tests Done (push) Has been cancelled
CI / 🚀 Publish build assets (push) Has been cancelled
CI / 🚀 Publish Docker Images (DockerHub) (push) Has been cancelled
CI / 🚀 Notify external services (push) Has been cancelled
CI / Update Version Durability (push) Has been cancelled
Release / Release (push) Has been cancelled
Auto-close duplicate issues / auto-close-duplicates (push) Failing after 1s
Code scanning - action / CodeQL-Build (push) Failing after 1s
This commit is contained in:
171
apps/meteor/client/lib/RoomManager.ts
Normal file
171
apps/meteor/client/lib/RoomManager.ts
Normal file
@@ -0,0 +1,171 @@
|
||||
import type { IRoom } from '@rocket.chat/core-typings';
|
||||
import { Emitter } from '@rocket.chat/emitter';
|
||||
import { useMemo, useSyncExternalStore } from 'react';
|
||||
|
||||
import { LegacyRoomManager } from './LegacyRoomManager';
|
||||
import { RoomHistoryManager } from './RoomHistoryManager';
|
||||
import { getConfig } from './utils/getConfig';
|
||||
|
||||
const debug = !!(getConfig('debug') || getConfig('debug-RoomStore'));
|
||||
|
||||
type CollapsibleKey = `collapsibleToggled-${string}`;
|
||||
|
||||
export const getCollapsibleEventKey = (key: string): CollapsibleKey => `collapsibleToggled-${key}`;
|
||||
|
||||
class RoomStore extends Emitter<{
|
||||
changed: undefined;
|
||||
[key: CollapsibleKey]: undefined;
|
||||
}> {
|
||||
lastTime?: Date;
|
||||
|
||||
scroll?: number;
|
||||
|
||||
lm?: Date;
|
||||
|
||||
atBottom = true;
|
||||
|
||||
private readonly toggledCollapsibles = new Set<string>();
|
||||
|
||||
constructor(readonly rid: string) {
|
||||
super();
|
||||
|
||||
debug && this.on('changed', () => console.log(`RoomStore ${this.rid} changed`, this));
|
||||
}
|
||||
|
||||
update({ scroll, lastTime, atBottom }: { scroll?: number; lastTime?: Date; atBottom?: boolean }): void {
|
||||
if (scroll !== undefined) {
|
||||
this.scroll = scroll;
|
||||
}
|
||||
if (lastTime !== undefined) {
|
||||
this.lastTime = lastTime;
|
||||
}
|
||||
|
||||
if (atBottom !== undefined) {
|
||||
this.atBottom = atBottom;
|
||||
}
|
||||
if (scroll || lastTime) {
|
||||
this.emit('changed');
|
||||
}
|
||||
}
|
||||
|
||||
toggleCollapsible(key: string): void {
|
||||
if (this.toggledCollapsibles.has(key)) {
|
||||
this.toggledCollapsibles.delete(key);
|
||||
this.emit(getCollapsibleEventKey(key));
|
||||
return;
|
||||
}
|
||||
|
||||
this.toggledCollapsibles.add(key);
|
||||
this.emit(getCollapsibleEventKey(key));
|
||||
}
|
||||
|
||||
isCollapsibleToggled(key: string): boolean {
|
||||
return this.toggledCollapsibles.has(key);
|
||||
}
|
||||
}
|
||||
|
||||
const debugRoomManager = !!(getConfig('debug') || getConfig('debug-RoomManager'));
|
||||
export const RoomManager = new (class RoomManager extends Emitter<{
|
||||
changed: IRoom['_id'] | undefined;
|
||||
opened: IRoom['_id'];
|
||||
closed: IRoom['_id'];
|
||||
back: IRoom['_id'];
|
||||
removed: IRoom['_id'];
|
||||
}> {
|
||||
private rid: IRoom['_id'] | undefined;
|
||||
|
||||
public lastRid: IRoom['_id'] | undefined;
|
||||
|
||||
private rooms: Map<IRoom['_id'], RoomStore> = new Map();
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
debugRoomManager &&
|
||||
this.on('opened', (rid) => {
|
||||
console.log('room opened ->', rid);
|
||||
});
|
||||
|
||||
debugRoomManager &&
|
||||
this.on('back', (rid) => {
|
||||
console.log('room moved to back ->', rid);
|
||||
});
|
||||
|
||||
debugRoomManager &&
|
||||
this.on('closed', (rid) => {
|
||||
console.log('room close ->', rid);
|
||||
});
|
||||
}
|
||||
|
||||
get lastOpened(): IRoom['_id'] | undefined {
|
||||
return this.lastRid;
|
||||
}
|
||||
|
||||
get opened(): IRoom['_id'] | undefined {
|
||||
return this.rid;
|
||||
}
|
||||
|
||||
visitedRooms(): IRoom['_id'][] {
|
||||
return [...this.rooms.keys()];
|
||||
}
|
||||
|
||||
back(rid: IRoom['_id']): void {
|
||||
if (rid === this.rid) {
|
||||
this.lastRid = rid;
|
||||
this.rid = undefined;
|
||||
this.emit('back', rid);
|
||||
this.emit('changed', this.rid);
|
||||
}
|
||||
}
|
||||
|
||||
getMore(rid: IRoom['_id']): void {
|
||||
RoomHistoryManager.getMore(rid);
|
||||
}
|
||||
|
||||
close(rid: IRoom['_id']): void {
|
||||
if (this.rooms.has(rid)) {
|
||||
this.rooms.delete(rid);
|
||||
this.emit('closed', rid);
|
||||
}
|
||||
this.emit('changed', this.rid);
|
||||
}
|
||||
|
||||
open(rid: IRoom['_id']): void {
|
||||
if (rid === this.rid) {
|
||||
return;
|
||||
}
|
||||
this.back(rid);
|
||||
if (!this.rooms.has(rid)) {
|
||||
this.rooms.set(rid, new RoomStore(rid));
|
||||
}
|
||||
this.rid = rid;
|
||||
this.emit('opened', this.rid);
|
||||
this.emit('changed', this.rid);
|
||||
}
|
||||
|
||||
getStore(rid: IRoom['_id']): RoomStore | undefined {
|
||||
return this.rooms.get(rid);
|
||||
}
|
||||
})();
|
||||
|
||||
const subscribeOpenedRoom = [
|
||||
(callback: () => void): (() => void) => RoomManager.on('changed', callback),
|
||||
(): IRoom['_id'] | undefined => RoomManager.opened,
|
||||
] as const;
|
||||
|
||||
export const useOpenedRoom = (): IRoom['_id'] | undefined => useSyncExternalStore(...subscribeOpenedRoom);
|
||||
|
||||
export const useOpenedRoomUnreadSince = (): Date | undefined => {
|
||||
const rid = useOpenedRoom();
|
||||
|
||||
const { subscribe, getSnapshotValue } = useMemo(() => {
|
||||
if (!rid) {
|
||||
return {
|
||||
subscribe: () => () => void 0,
|
||||
getSnapshotValue: () => undefined,
|
||||
};
|
||||
}
|
||||
return LegacyRoomManager.listenRoomPropsByRid(rid, 'unreadSince');
|
||||
}, [rid]);
|
||||
|
||||
return useSyncExternalStore(subscribe, getSnapshotValue);
|
||||
};
|
||||
Reference in New Issue
Block a user