fix: Improve plugin ui entry points, Fix chat scroll, fix notifications, fix user rights
This commit is contained in:
@@ -9,7 +9,7 @@ This page maps the app routes and important DOM areas. It is useful for plugin a
|
||||
## Angular Routes
|
||||
|
||||
| Route | Component | Purpose |
|
||||
| --- | --- | --- |
|
||||
| ---------------------------- | ------------------------- | --------------------------------------------------------------------- |
|
||||
| `/` | Redirect | Redirects to `/search`. |
|
||||
| `/login` | `LoginComponent` | User login. |
|
||||
| `/register` | `RegisterComponent` | User registration. |
|
||||
@@ -46,6 +46,7 @@ The server page is the most important page for plugins.
|
||||
<section>Text Channels</section>
|
||||
<section>Voice Channels</section>
|
||||
<section data-testid="plugin-room-side-panel">
|
||||
<button>View plugins</button>
|
||||
<app-plugin-render-host></app-plugin-render-host>
|
||||
</section>
|
||||
<section>Members</section>
|
||||
@@ -136,10 +137,10 @@ Prefer plugin APIs over DOM selectors. When direct DOM mounting is necessary, us
|
||||
Common targets:
|
||||
|
||||
| Selector | Area |
|
||||
| --- | --- |
|
||||
| ---------------------------------------- | --------------------------------------------------------------------------------------------------------------------- |
|
||||
| `body` | Global overlays or modals. |
|
||||
| `app-chat-messages` | Main text channel surface. |
|
||||
| `app-rooms-side-panel` | Server side panel. |
|
||||
| `[data-testid="plugin-room-side-panel"]` | Plugin side-panel area in the server sidebar. |
|
||||
| `[data-testid="plugin-room-side-panel"]` | Plugin side-panel area in the server sidebar, including the View plugins trigger for `registerToolbarAction()` tiles. |
|
||||
|
||||
Avoid depending on Tailwind utility classes; they are layout details and may change.
|
||||
@@ -72,7 +72,7 @@ Plugins run only in the renderer. They do not run in Electron main and do not ru
|
||||
Choose communication APIs like this:
|
||||
|
||||
| Need | Use | Notes |
|
||||
| --- | --- | --- |
|
||||
| ------------------------------------------- | -------------------------------------------------------------------- | -------------------------------------------------------------- |
|
||||
| Visible normal chat message | `api.messages.send` | Persists locally, updates chat UI, broadcasts peer chat event. |
|
||||
| Visible bot-style message | `api.server.registerPluginUser` plus `api.messages.sendAsPluginUser` | Requires `users.manage` and `messages.send`. |
|
||||
| Plugin state sync between connected clients | `api.messageBus.publish` and `api.messageBus.subscribe` | P2P data-channel envelope, not a visible chat message. |
|
||||
@@ -123,7 +123,7 @@ Main server page shape:
|
||||
Important routes:
|
||||
|
||||
| Route | Purpose |
|
||||
| --- | --- |
|
||||
| ------------------------------- | ------------------------------------------------------------------- |
|
||||
| `/search` | Search and join servers. |
|
||||
| `/room/:roomId` | Main server workspace with text, voice, members, and plugin panels. |
|
||||
| `/dm` and `/dm/:conversationId` | Direct-message workspace. |
|
||||
@@ -136,7 +136,7 @@ Direct DOM mounting is a last resort. Route-specific targets may not exist when
|
||||
Stable direct-mount targets when necessary:
|
||||
|
||||
| Selector | Area |
|
||||
| --- | --- |
|
||||
| ---------------------- | --------------------------------------------------------------------------------------------------------------------- |
|
||||
| `body` | Safest global target for overlays, badges, and modals. It exists during activation. |
|
||||
| `app-chat-messages` | Main text channel surface. Use only after checking the element exists. |
|
||||
| `app-rooms-side-panel` | Server side panel. Use only after checking the element exists. Prefer `registerSidePanel` for plugin sidebar content. |
|
||||
@@ -144,7 +144,8 @@ Stable direct-mount targets when necessary:
|
||||
Do not mount directly into `[data-testid="plugin-room-side-panel"]`. That area is owned by the plugin side-panel registry and is rendered only on the server page. For server sidebar UI, use:
|
||||
|
||||
```js
|
||||
context.subscriptions.push(api.ui.registerSidePanel('control-panel', {
|
||||
context.subscriptions.push(
|
||||
api.ui.registerSidePanel('control-panel', {
|
||||
label: 'Control Panel',
|
||||
order: 20,
|
||||
render: () => {
|
||||
@@ -160,9 +161,12 @@ context.subscriptions.push(api.ui.registerSidePanel('control-panel', {
|
||||
root.append(button);
|
||||
return root;
|
||||
}
|
||||
}));
|
||||
})
|
||||
);
|
||||
```
|
||||
|
||||
For small command-style plugin entries, use `api.ui.registerToolbarAction()`. Those actions appear as icon tiles in the server side panel's View plugins menu and receive `source: 'toolbarAction'` in their action context.
|
||||
|
||||
Do not depend on Tailwind classes or internal styling classes.
|
||||
|
||||
## Manifest
|
||||
@@ -301,7 +305,7 @@ Validation rules:
|
||||
Scope meanings:
|
||||
|
||||
| Scope | Meaning |
|
||||
| --- | --- |
|
||||
| ------------------- | --------------------------------------------------------------------------------------------- |
|
||||
| `client` or omitted | Installed globally for this local user/client. |
|
||||
| `server` | Installed for a specific chat server as local client plugin plus server requirement metadata. |
|
||||
|
||||
@@ -326,10 +330,7 @@ interface TojuClientPluginModule {
|
||||
ready?: (context: TojuPluginActivationContext) => Promise<void> | void;
|
||||
deactivate?: (context: TojuPluginActivationContext) => Promise<void> | void;
|
||||
onPluginDataChanged?: (context: TojuPluginActivationContext, event: unknown) => Promise<void> | void;
|
||||
onServerRequirementsChanged?: (
|
||||
context: TojuPluginActivationContext,
|
||||
snapshot: PluginRequirementsSnapshot
|
||||
) => Promise<void> | void;
|
||||
onServerRequirementsChanged?: (context: TojuPluginActivationContext, snapshot: PluginRequirementsSnapshot) => Promise<void> | void;
|
||||
}
|
||||
```
|
||||
|
||||
@@ -579,9 +580,20 @@ interface ChannelPermissionOverride {
|
||||
## Full Plugin API Types
|
||||
|
||||
```ts
|
||||
interface PluginApiProfileUpdate { displayName: string; description?: string }
|
||||
interface PluginApiAvatarUpdate { avatarUrl: string; avatarMime: string; avatarHash: string }
|
||||
interface PluginApiChannelRequest { name: string; id?: string; position?: number }
|
||||
interface PluginApiProfileUpdate {
|
||||
displayName: string;
|
||||
description?: string;
|
||||
}
|
||||
interface PluginApiAvatarUpdate {
|
||||
avatarUrl: string;
|
||||
avatarMime: string;
|
||||
avatarHash: string;
|
||||
}
|
||||
interface PluginApiChannelRequest {
|
||||
name: string;
|
||||
id?: string;
|
||||
position?: number;
|
||||
}
|
||||
interface PluginApiServerSettingsUpdate {
|
||||
name?: string;
|
||||
description?: string;
|
||||
@@ -590,10 +602,24 @@ interface PluginApiServerSettingsUpdate {
|
||||
password?: string;
|
||||
maxUsers?: number;
|
||||
}
|
||||
interface PluginApiPluginUserRequest { displayName: string; id?: string; avatarUrl?: string }
|
||||
interface PluginApiMessageAsPluginUserRequest { pluginUserId: string; content: string; channelId?: string }
|
||||
interface PluginApiAudioClipRequest { url: string; volume?: number }
|
||||
interface PluginApiCustomStreamRequest { stream: MediaStream; label?: string }
|
||||
interface PluginApiPluginUserRequest {
|
||||
displayName: string;
|
||||
id?: string;
|
||||
avatarUrl?: string;
|
||||
}
|
||||
interface PluginApiMessageAsPluginUserRequest {
|
||||
pluginUserId: string;
|
||||
content: string;
|
||||
channelId?: string;
|
||||
}
|
||||
interface PluginApiAudioClipRequest {
|
||||
url: string;
|
||||
volume?: number;
|
||||
}
|
||||
interface PluginApiCustomStreamRequest {
|
||||
stream: MediaStream;
|
||||
label?: string;
|
||||
}
|
||||
|
||||
type PluginApiActionSource = 'composerAction' | 'toolbarAction' | 'profileAction' | 'manual';
|
||||
interface PluginApiActionContext {
|
||||
@@ -660,13 +686,41 @@ interface PluginApiMessageBusSubscription {
|
||||
handler: (event: PluginApiMessageBusEnvelope) => void;
|
||||
}
|
||||
|
||||
interface PluginApiPageContribution { label: string; path: string; render: () => HTMLElement | string }
|
||||
interface PluginApiSettingsPageContribution { label: string; settingsKey?: string; order?: number; render: () => HTMLElement | string }
|
||||
interface PluginApiPanelContribution { label: string; order?: number; render: () => HTMLElement | string }
|
||||
interface PluginApiChannelSectionContribution { label: string; type?: 'audio' | 'video' | 'custom'; order?: number }
|
||||
interface PluginApiActionContribution { label: string; icon?: string; run: (context: PluginApiActionContext) => Promise<void> | void }
|
||||
interface PluginApiEmbedRendererContribution { embedType: string; render: (payload: unknown) => HTMLElement | string }
|
||||
interface PluginApiDomMountRequest { target: Element | string; element: HTMLElement; position?: InsertPosition }
|
||||
interface PluginApiPageContribution {
|
||||
label: string;
|
||||
path: string;
|
||||
render: () => HTMLElement | string;
|
||||
}
|
||||
interface PluginApiSettingsPageContribution {
|
||||
label: string;
|
||||
settingsKey?: string;
|
||||
order?: number;
|
||||
render: () => HTMLElement | string;
|
||||
}
|
||||
interface PluginApiPanelContribution {
|
||||
label: string;
|
||||
order?: number;
|
||||
render: () => HTMLElement | string;
|
||||
}
|
||||
interface PluginApiChannelSectionContribution {
|
||||
label: string;
|
||||
type?: 'audio' | 'video' | 'custom';
|
||||
order?: number;
|
||||
}
|
||||
interface PluginApiActionContribution {
|
||||
label: string;
|
||||
icon?: string;
|
||||
run: (context: PluginApiActionContext) => Promise<void> | void;
|
||||
}
|
||||
interface PluginApiEmbedRendererContribution {
|
||||
embedType: string;
|
||||
render: (payload: unknown) => HTMLElement | string;
|
||||
}
|
||||
interface PluginApiDomMountRequest {
|
||||
target: Element | string;
|
||||
element: HTMLElement;
|
||||
position?: InsertPosition;
|
||||
}
|
||||
|
||||
interface TojuClientPluginApi {
|
||||
readonly context: { getCurrent: () => PluginApiActionContext };
|
||||
@@ -890,10 +944,7 @@ Capabilities: `messages.read`, `messages.send`, `messages.editOwn`, `messages.de
|
||||
```js
|
||||
const visibleMessages = api.messages.readCurrent();
|
||||
|
||||
const sent = api.messages.send(
|
||||
'Build completed successfully. Docs are ready for review.',
|
||||
'general'
|
||||
);
|
||||
const sent = api.messages.send('Build completed successfully. Docs are ready for review.', 'general');
|
||||
|
||||
api.messages.edit(sent.id, 'Build completed successfully. Docs and plugin examples are ready.');
|
||||
api.messages.delete(sent.id);
|
||||
@@ -1116,7 +1167,7 @@ Desktop uses Electron's local database when available, with renderer localStorag
|
||||
Capabilities:
|
||||
|
||||
| Method | Required capability |
|
||||
| --- | --- |
|
||||
| ------------------------ | -------------------- |
|
||||
| `registerAppPage` | `ui.pages` |
|
||||
| `registerSettingsPage` | `ui.settings` |
|
||||
| `registerSidePanel` | `ui.sidePanel` |
|
||||
@@ -1130,7 +1181,8 @@ Capabilities:
|
||||
Register side panel:
|
||||
|
||||
```js
|
||||
context.subscriptions.push(api.ui.registerSidePanel('summary', {
|
||||
context.subscriptions.push(
|
||||
api.ui.registerSidePanel('summary', {
|
||||
label: 'Plugin Summary',
|
||||
order: 10,
|
||||
render: () => {
|
||||
@@ -1143,15 +1195,34 @@ context.subscriptions.push(api.ui.registerSidePanel('summary', {
|
||||
root.append(heading, text);
|
||||
return root;
|
||||
}
|
||||
}));
|
||||
})
|
||||
);
|
||||
```
|
||||
|
||||
Use `registerSidePanel` for content that belongs in the server sidebar plugin area. Do not query `[data-testid="plugin-room-side-panel"]` and pass it to `mountElement`; that route-specific host may not exist while the plugin activates.
|
||||
|
||||
Register toolbar action for the View plugins menu:
|
||||
|
||||
```js
|
||||
context.subscriptions.push(
|
||||
api.ui.registerToolbarAction('quick-status', {
|
||||
icon: 'QS',
|
||||
label: 'Quick Status',
|
||||
run: (actionContext) => {
|
||||
api.logger.info('Quick Status clicked', {
|
||||
serverId: actionContext.server?.id,
|
||||
source: actionContext.source
|
||||
});
|
||||
}
|
||||
})
|
||||
);
|
||||
```
|
||||
|
||||
Register app page:
|
||||
|
||||
```js
|
||||
context.subscriptions.push(api.ui.registerAppPage('dashboard', {
|
||||
context.subscriptions.push(
|
||||
api.ui.registerAppPage('dashboard', {
|
||||
label: 'Build Dashboard',
|
||||
path: '/plugins/example.build-dashboard/dashboard',
|
||||
render: () => {
|
||||
@@ -1173,30 +1244,32 @@ context.subscriptions.push(api.ui.registerAppPage('dashboard', {
|
||||
root.append(title, button, output);
|
||||
return root;
|
||||
}
|
||||
}));
|
||||
})
|
||||
);
|
||||
```
|
||||
|
||||
Register actions:
|
||||
|
||||
```js
|
||||
context.subscriptions.push(api.ui.registerComposerAction('insert-template', {
|
||||
context.subscriptions.push(
|
||||
api.ui.registerComposerAction('insert-template', {
|
||||
label: 'Insert Template',
|
||||
icon: 'file-text',
|
||||
run: (actionContext) => {
|
||||
api.messages.send(
|
||||
'Template: Please review the latest build notes.',
|
||||
actionContext.textChannel?.id
|
||||
);
|
||||
api.messages.send('Template: Please review the latest build notes.', actionContext.textChannel?.id);
|
||||
}
|
||||
}));
|
||||
})
|
||||
);
|
||||
|
||||
context.subscriptions.push(api.ui.registerToolbarAction('post-standup', {
|
||||
context.subscriptions.push(
|
||||
api.ui.registerToolbarAction('post-standup', {
|
||||
label: 'Post Standup',
|
||||
icon: 'megaphone',
|
||||
run: () => {
|
||||
api.messages.send('Standup starts now. Join the voice channel when ready.');
|
||||
}
|
||||
}));
|
||||
})
|
||||
);
|
||||
```
|
||||
|
||||
Mount DOM directly:
|
||||
@@ -1210,11 +1283,13 @@ banner.textContent = 'Plugin banner mounted in chat messages.';
|
||||
const target = document.querySelector('app-chat-messages');
|
||||
|
||||
if (target) {
|
||||
context.subscriptions.push(api.ui.mountElement('chat-banner', {
|
||||
context.subscriptions.push(
|
||||
api.ui.mountElement('chat-banner', {
|
||||
target,
|
||||
element: banner,
|
||||
position: 'afterbegin'
|
||||
}));
|
||||
})
|
||||
);
|
||||
}
|
||||
```
|
||||
|
||||
@@ -1224,11 +1299,13 @@ Global overlay example:
|
||||
const badge = document.createElement('div');
|
||||
badge.textContent = 'Plugin active';
|
||||
|
||||
context.subscriptions.push(api.ui.mountElement('global-badge', {
|
||||
context.subscriptions.push(
|
||||
api.ui.mountElement('global-badge', {
|
||||
target: 'body',
|
||||
element: badge,
|
||||
position: 'beforeend'
|
||||
}));
|
||||
})
|
||||
);
|
||||
```
|
||||
|
||||
`mountElement` tags the element with plugin ownership metadata, replaces duplicate mounts for the same plugin/id, and removes it on disposal/unload.
|
||||
@@ -1236,7 +1313,7 @@ context.subscriptions.push(api.ui.mountElement('global-badge', {
|
||||
## Capability Cheat Sheet
|
||||
|
||||
| API call group | Capabilities |
|
||||
| --- | --- |
|
||||
| -------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------- |
|
||||
| `profile.getCurrent` | `profile.read` |
|
||||
| `profile.update`, `profile.updateAvatar` | `profile.write` |
|
||||
| `users.getCurrent`, `users.list`, `users.readMembers` | `users.read` |
|
||||
@@ -1319,25 +1396,31 @@ export function activate(context) {
|
||||
|
||||
api.logger.info('Voice Notes activated');
|
||||
|
||||
context.subscriptions.push(api.messageBus.subscribe({
|
||||
context.subscriptions.push(
|
||||
api.messageBus.subscribe({
|
||||
topic: BUS_TOPIC,
|
||||
replayLatest: false,
|
||||
handler: (event) => {
|
||||
api.logger.debug('Received voice notes draft update', event.payload);
|
||||
}
|
||||
}));
|
||||
})
|
||||
);
|
||||
|
||||
context.subscriptions.push(api.ui.registerSidePanel('voice-notes-panel', {
|
||||
context.subscriptions.push(
|
||||
api.ui.registerSidePanel('voice-notes-panel', {
|
||||
label: 'Voice Notes',
|
||||
order: 20,
|
||||
render: () => renderPanel(context)
|
||||
}));
|
||||
})
|
||||
);
|
||||
|
||||
context.subscriptions.push(api.ui.registerAppPage('voice-notes', {
|
||||
context.subscriptions.push(
|
||||
api.ui.registerAppPage('voice-notes', {
|
||||
label: 'Voice Notes',
|
||||
path: '/plugins/example.voice-notes/voice-notes',
|
||||
render: () => renderPanel(context)
|
||||
}));
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
function renderPanel(context) {
|
||||
@@ -1352,9 +1435,7 @@ function renderPanel(context) {
|
||||
|
||||
const current = api.context.getCurrent();
|
||||
heading.textContent = 'Voice Notes';
|
||||
meta.textContent = current.voiceChannel
|
||||
? `Connected to ${current.voiceChannel.name}`
|
||||
: 'Not connected to a voice channel.';
|
||||
meta.textContent = current.voiceChannel ? `Connected to ${current.voiceChannel.name}` : 'Not connected to a voice channel.';
|
||||
textarea.rows = 6;
|
||||
textarea.placeholder = 'Write notes from the current voice session.';
|
||||
save.type = 'button';
|
||||
@@ -1363,13 +1444,16 @@ function renderPanel(context) {
|
||||
post.textContent = 'Post Notes';
|
||||
status.textContent = 'Loading draft...';
|
||||
|
||||
void api.serverData.read(DRAFT_KEY).then((value) => {
|
||||
void api.serverData
|
||||
.read(DRAFT_KEY)
|
||||
.then((value) => {
|
||||
if (value && typeof value === 'object' && typeof value.text === 'string') {
|
||||
textarea.value = value.text;
|
||||
}
|
||||
|
||||
status.textContent = 'Draft loaded.';
|
||||
}).catch((error) => {
|
||||
})
|
||||
.catch((error) => {
|
||||
api.logger.warn('Could not load voice notes draft', error);
|
||||
status.textContent = 'Could not load draft.';
|
||||
});
|
||||
|
||||
@@ -61,7 +61,7 @@ interface PluginApiAvatarUpdate {
|
||||
```
|
||||
|
||||
| Method | Capability | Description |
|
||||
| --- | --- | --- |
|
||||
| ------------------------------ | --------------- | ------------------------------------------------- |
|
||||
| `profile.getCurrent()` | `profile.read` | Returns the current `User` or `null`. |
|
||||
| `profile.update(profile)` | `profile.write` | Updates display name and optional description. |
|
||||
| `profile.updateAvatar(avatar)` | `profile.write` | Updates avatar URL, MIME type, and hash metadata. |
|
||||
@@ -69,7 +69,7 @@ interface PluginApiAvatarUpdate {
|
||||
## Users and Roles
|
||||
|
||||
| Method | Capability | Description |
|
||||
| --- | --- | --- |
|
||||
| ----------------------------------- | -------------- | --------------------------------- |
|
||||
| `users.getCurrent()` | `users.read` | Returns current `User` or `null`. |
|
||||
| `users.list()` | `users.read` | Returns known users. |
|
||||
| `users.readMembers()` | `users.read` | Returns active room members. |
|
||||
@@ -99,7 +99,7 @@ interface PluginApiPluginUserRequest {
|
||||
```
|
||||
|
||||
| Method | Capability | Description |
|
||||
| --- | --- | --- |
|
||||
| --------------------------------------- | --------------- | -------------------------------------------- |
|
||||
| `server.getCurrent()` | `server.read` | Returns the current `Room` or `null`. |
|
||||
| `server.registerPluginUser(request)` | `users.manage` | Adds a plugin-owned user and returns its id. |
|
||||
| `server.updatePermissions(permissions)` | `server.manage` | Updates partial room permissions. |
|
||||
@@ -116,7 +116,7 @@ interface PluginApiChannelRequest {
|
||||
```
|
||||
|
||||
| Method | Capability | Description |
|
||||
| --- | --- | --- |
|
||||
| ----------------------------------- | ----------------- | ---------------------------------- |
|
||||
| `channels.list()` | `channels.read` | Returns current room channels. |
|
||||
| `channels.select(channelId)` | `channels.read` | Selects a channel. |
|
||||
| `channels.addAudioChannel(request)` | `channels.manage` | Adds a voice channel. |
|
||||
@@ -135,7 +135,7 @@ interface PluginApiMessageAsPluginUserRequest {
|
||||
```
|
||||
|
||||
| Method | Capability | Description |
|
||||
| --- | --- | --- |
|
||||
| ------------------------------------------ | -------------------- | -------------------------------------------------- |
|
||||
| `messages.readCurrent()` | `messages.read` | Returns current visible messages. |
|
||||
| `messages.send(content, channelId?)` | `messages.send` | Sends a message and returns the created `Message`. |
|
||||
| `messages.sendAsPluginUser(request)` | `messages.send` | Emits a message from a registered plugin user. |
|
||||
@@ -168,7 +168,7 @@ interface PluginEventEnvelope<TPayload = unknown> {
|
||||
```
|
||||
|
||||
| Method | Capability | Description |
|
||||
| --- | --- | --- |
|
||||
| ------------------------------------------ | ------------------------- | ----------------------------------------------------------- |
|
||||
| `events.publishServer(eventName, payload)` | `events.server.publish` | Sends a declared plugin event through the signaling server. |
|
||||
| `events.subscribeServer(subscription)` | `events.server.subscribe` | Subscribes to a declared server plugin event. |
|
||||
| `events.publishP2p(eventName, payload)` | `events.p2p.publish` | Sends a declared plugin event over peer paths. |
|
||||
@@ -216,7 +216,7 @@ interface PluginApiMessageBusSubscription {
|
||||
```
|
||||
|
||||
| Method | Capability | Description |
|
||||
| --- | --- | --- |
|
||||
| ----------------------------------------- | -------------------------------------------------- | ---------------------------------------------------------------------- |
|
||||
| `messageBus.publish(request)` | `events.p2p.publish`, optionally `messages.read` | Publishes a plugin-bus event, optionally including latest messages. |
|
||||
| `messageBus.sendLatestMessages(request?)` | `events.p2p.publish` and `messages.read` | Sends a latest-message snapshot. |
|
||||
| `messageBus.subscribe(subscription)` | `events.p2p.subscribe`, optionally `messages.read` | Subscribes to plugin-bus events, optionally replaying latest messages. |
|
||||
@@ -236,7 +236,7 @@ interface PluginApiCustomStreamRequest {
|
||||
```
|
||||
|
||||
| Method | Capability | Description |
|
||||
| --- | --- | --- |
|
||||
| ------------------------------------------ | ---------------------- | --------------------------------------------- |
|
||||
| `p2p.connectedPeers()` | `p2p.data` | Returns connected peer ids. |
|
||||
| `p2p.broadcastData(eventName, payload)` | `p2p.data` | Broadcasts plugin data. |
|
||||
| `p2p.sendData(peerId, eventName, payload)` | `p2p.data` | Sends plugin data targeted to a peer. |
|
||||
@@ -249,7 +249,7 @@ interface PluginApiCustomStreamRequest {
|
||||
## Storage
|
||||
|
||||
| Method | Capability | Description |
|
||||
| --- | --- | --- |
|
||||
| ------------------------------ | -------------------------- | --------------------------------------- |
|
||||
| `clientData.read(key)` | `storage.local` | Reads async plugin-local data. |
|
||||
| `clientData.write(key, value)` | `storage.local` | Writes async plugin-local data. |
|
||||
| `clientData.remove(key)` | `storage.local` | Removes async plugin-local data. |
|
||||
@@ -307,21 +307,21 @@ interface PluginApiDomMountRequest {
|
||||
```
|
||||
|
||||
| Method | Capability | Description |
|
||||
| --- | --- | --- |
|
||||
| --------------------------------------------- | -------------------- | --------------------------------------------------------------- |
|
||||
| `ui.registerAppPage(id, contribution)` | `ui.pages` | Adds a plugin app page. |
|
||||
| `ui.registerSettingsPage(id, contribution)` | `ui.settings` | Adds a plugin settings page. |
|
||||
| `ui.registerSidePanel(id, contribution)` | `ui.sidePanel` | Adds a side panel. |
|
||||
| `ui.registerChannelSection(id, contribution)` | `ui.channelsSection` | Adds a channel section. |
|
||||
| `ui.registerComposerAction(id, contribution)` | `ui.pages` | Adds a composer action. |
|
||||
| `ui.registerProfileAction(id, contribution)` | `ui.pages` | Adds a profile action. |
|
||||
| `ui.registerToolbarAction(id, contribution)` | `ui.pages` | Adds a toolbar action. |
|
||||
| `ui.registerToolbarAction(id, contribution)` | `ui.pages` | Adds an action tile to the server side panel View plugins menu. |
|
||||
| `ui.registerEmbedRenderer(id, contribution)` | `ui.embeds` | Adds an embed renderer. |
|
||||
| `ui.mountElement(id, request)` | `ui.dom` | Mounts plugin-owned DOM into a target element or selector. |
|
||||
|
||||
## Context and Logger
|
||||
|
||||
| Method | Capability | Description |
|
||||
| --- | --- | --- |
|
||||
| ------------------------------ | ---------- | -------------------------------------------------------------------------- |
|
||||
| `context.getCurrent()` | None | Reads current user, server, active text channel, and active voice channel. |
|
||||
| `logger.debug(message, data?)` | None | Writes a debug plugin log entry. |
|
||||
| `logger.info(message, data?)` | None | Writes an info plugin log entry. |
|
||||
|
||||
@@ -37,11 +37,12 @@ Example context shape:
|
||||
|
||||
## Action Context
|
||||
|
||||
Composer, toolbar, and profile actions receive context directly.
|
||||
Composer, toolbar, and profile actions receive context directly. Toolbar actions are launched from the server side panel's View plugins menu and report `source: 'toolbarAction'`.
|
||||
|
||||
```js
|
||||
export function activate(context) {
|
||||
context.subscriptions.push(context.api.ui.registerToolbarAction('where-am-i', {
|
||||
context.subscriptions.push(
|
||||
context.api.ui.registerToolbarAction('where-am-i', {
|
||||
label: 'Where am I?',
|
||||
run: (actionContext) => {
|
||||
context.api.logger.info('Toolbar action context', {
|
||||
@@ -51,7 +52,8 @@ export function activate(context) {
|
||||
voiceChannelId: actionContext.voiceChannel?.id
|
||||
});
|
||||
}
|
||||
}));
|
||||
})
|
||||
);
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ Prefer registered UI contributions over direct DOM mounting. Contribution APIs l
|
||||
## Required Capabilities
|
||||
|
||||
| Method | Capability |
|
||||
| --- | --- |
|
||||
| --------------------------------------------- | -------------------- |
|
||||
| `ui.registerAppPage(id, contribution)` | `ui.pages` |
|
||||
| `ui.registerSettingsPage(id, contribution)` | `ui.settings` |
|
||||
| `ui.registerSidePanel(id, contribution)` | `ui.sidePanel` |
|
||||
@@ -28,7 +28,8 @@ Every registration returns a disposable. Push it into `context.subscriptions`.
|
||||
|
||||
```js
|
||||
export function activate(context) {
|
||||
context.subscriptions.push(context.api.ui.registerAppPage('dashboard', {
|
||||
context.subscriptions.push(
|
||||
context.api.ui.registerAppPage('dashboard', {
|
||||
label: 'Raid Dashboard',
|
||||
path: '/plugins/example.raid-helper/dashboard',
|
||||
render: () => {
|
||||
@@ -36,7 +37,8 @@ export function activate(context) {
|
||||
root.innerHTML = '<h1>Raid Dashboard</h1><p>Tonight: dungeon practice.</p>';
|
||||
return root;
|
||||
}
|
||||
}));
|
||||
})
|
||||
);
|
||||
}
|
||||
```
|
||||
|
||||
@@ -46,7 +48,8 @@ The page is hosted by `/plugins/:pluginId/:pageId`.
|
||||
|
||||
```js
|
||||
export function activate(context) {
|
||||
context.subscriptions.push(context.api.ui.registerSettingsPage('preferences', {
|
||||
context.subscriptions.push(
|
||||
context.api.ui.registerSettingsPage('preferences', {
|
||||
label: 'Raid Helper',
|
||||
settingsKey: 'raid-helper',
|
||||
order: 20,
|
||||
@@ -61,7 +64,8 @@ export function activate(context) {
|
||||
wrapper.append(label);
|
||||
return wrapper;
|
||||
}
|
||||
}));
|
||||
})
|
||||
);
|
||||
}
|
||||
```
|
||||
|
||||
@@ -71,7 +75,8 @@ Use `ui.registerSidePanel` for content that belongs in the server sidebar plugin
|
||||
|
||||
```js
|
||||
export function activate(context) {
|
||||
context.subscriptions.push(context.api.ui.registerSidePanel('soundboard', {
|
||||
context.subscriptions.push(
|
||||
context.api.ui.registerSidePanel('soundboard', {
|
||||
label: 'Soundboard',
|
||||
order: 10,
|
||||
render: () => {
|
||||
@@ -80,14 +85,16 @@ export function activate(context) {
|
||||
|
||||
button.type = 'button';
|
||||
button.textContent = 'Play chime';
|
||||
button.onclick = () => context.api.media.playAudioClip({
|
||||
button.onclick = () =>
|
||||
context.api.media.playAudioClip({
|
||||
url: 'https://cdn.example.com/chime.wav',
|
||||
volume: 0.6
|
||||
});
|
||||
panel.append(button);
|
||||
return panel;
|
||||
}
|
||||
}));
|
||||
})
|
||||
);
|
||||
}
|
||||
```
|
||||
|
||||
@@ -97,11 +104,13 @@ Capabilities required: `ui.sidePanel` and `media.playAudio`.
|
||||
|
||||
```js
|
||||
export function activate(context) {
|
||||
context.subscriptions.push(context.api.ui.registerChannelSection('events', {
|
||||
context.subscriptions.push(
|
||||
context.api.ui.registerChannelSection('events', {
|
||||
label: 'Event Rooms',
|
||||
type: 'custom',
|
||||
order: 50
|
||||
}));
|
||||
})
|
||||
);
|
||||
}
|
||||
```
|
||||
|
||||
@@ -109,16 +118,15 @@ export function activate(context) {
|
||||
|
||||
```js
|
||||
export function activate(context) {
|
||||
context.subscriptions.push(context.api.ui.registerComposerAction('insert-standup', {
|
||||
context.subscriptions.push(
|
||||
context.api.ui.registerComposerAction('insert-standup', {
|
||||
icon: 'ST',
|
||||
label: 'Insert standup prompt',
|
||||
run: (actionContext) => {
|
||||
context.api.messages.send(
|
||||
'Standup: yesterday I..., today I..., blocked by...',
|
||||
actionContext.textChannel?.id
|
||||
);
|
||||
context.api.messages.send('Standup: yesterday I..., today I..., blocked by...', actionContext.textChannel?.id);
|
||||
}
|
||||
}));
|
||||
})
|
||||
);
|
||||
}
|
||||
```
|
||||
|
||||
@@ -128,33 +136,52 @@ Capabilities required: `ui.pages` and `messages.send`.
|
||||
|
||||
```js
|
||||
export function activate(context) {
|
||||
context.subscriptions.push(context.api.ui.registerProfileAction('wave', {
|
||||
context.subscriptions.push(
|
||||
context.api.ui.registerProfileAction('wave', {
|
||||
label: 'Wave',
|
||||
run: (actionContext) => {
|
||||
context.api.messages.send(`Waving at ${actionContext.user?.displayName ?? 'someone'}!`);
|
||||
}
|
||||
}));
|
||||
})
|
||||
);
|
||||
}
|
||||
```
|
||||
|
||||
## Toolbar Action
|
||||
|
||||
Toolbar actions are command-style plugin entries shown in the server side panel's View plugins menu. Use them for small actions that should be easy to launch from a server, such as opening a plugin page, sending a status message, starting a timer, or toggling a plugin feature.
|
||||
|
||||
The View plugins link appears in `[data-testid="plugin-room-side-panel"]` when the plugin side-panel area is rendered. Opening it shows an overlay menu, positioned like profile-card overlays, with registered actions laid out as plugin icon tiles. The `icon` field can be short text such as `RH`, an emoji, or an image URL; when omitted, MetoYou falls back to initials from the plugin/action labels.
|
||||
|
||||
Toolbar action callbacks receive an action context with `source: 'toolbarAction'`, the current user, current server, active text channel, and current voice channel when available.
|
||||
|
||||
```js
|
||||
export function activate(context) {
|
||||
context.subscriptions.push(context.api.ui.registerToolbarAction('open-dashboard', {
|
||||
context.subscriptions.push(
|
||||
context.api.ui.registerToolbarAction('open-dashboard', {
|
||||
icon: 'RH',
|
||||
label: 'Raid Helper',
|
||||
run: () => {
|
||||
context.api.logger.info('Open the Raid Helper plugin page from /plugins/example.raid-helper/dashboard');
|
||||
run: (actionContext) => {
|
||||
context.api.logger.info('Raid Helper opened', {
|
||||
channelId: actionContext.textChannel?.id,
|
||||
serverId: actionContext.server?.id
|
||||
});
|
||||
}
|
||||
}));
|
||||
})
|
||||
);
|
||||
}
|
||||
```
|
||||
|
||||
Capabilities required: `ui.pages`. Add any capability your action uses, such as `messages.send` or `server.read`.
|
||||
|
||||
Use `registerSidePanel` instead when the plugin needs persistent sidebar content, and use `registerAppPage` when the plugin needs a full-page workflow.
|
||||
|
||||
## Embed Renderer
|
||||
|
||||
```js
|
||||
export function activate(context) {
|
||||
context.subscriptions.push(context.api.ui.registerEmbedRenderer('raid-card', {
|
||||
context.subscriptions.push(
|
||||
context.api.ui.registerEmbedRenderer('raid-card', {
|
||||
embedType: 'raid.card',
|
||||
render: (payload) => {
|
||||
const card = document.createElement('article');
|
||||
@@ -166,7 +193,8 @@ export function activate(context) {
|
||||
card.append(title, body);
|
||||
return card;
|
||||
}
|
||||
}));
|
||||
})
|
||||
);
|
||||
}
|
||||
```
|
||||
|
||||
@@ -202,11 +230,13 @@ export function activate(context) {
|
||||
badge.style.color = 'white';
|
||||
badge.style.borderRadius = '6px';
|
||||
|
||||
context.subscriptions.push(context.api.ui.mountElement('active-badge', {
|
||||
context.subscriptions.push(
|
||||
context.api.ui.mountElement('active-badge', {
|
||||
target: 'body',
|
||||
position: 'beforeend',
|
||||
element: badge
|
||||
}));
|
||||
})
|
||||
);
|
||||
}
|
||||
```
|
||||
|
||||
@@ -224,11 +254,13 @@ export function activate(context) {
|
||||
const banner = document.createElement('div');
|
||||
banner.textContent = 'Raid helper active in this chat.';
|
||||
|
||||
context.subscriptions.push(context.api.ui.mountElement('chat-banner', {
|
||||
context.subscriptions.push(
|
||||
context.api.ui.mountElement('chat-banner', {
|
||||
target,
|
||||
position: 'afterbegin',
|
||||
element: banner
|
||||
}));
|
||||
})
|
||||
);
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ sidebar_position: 3
|
||||
Capabilities protect privileged app surfaces. A plugin must declare a capability in its manifest and the user must grant it before the runtime allows the corresponding API call.
|
||||
|
||||
| Capability | API areas | Notes |
|
||||
| --- | --- | --- |
|
||||
| -------------------------- | ----------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------- |
|
||||
| `profile.read` | `profile.getCurrent()` | Reads the current user. |
|
||||
| `profile.write` | `profile.update()`, `profile.updateAvatar()` | Updates local profile fields and avatar metadata. |
|
||||
| `users.read` | `users.getCurrent()`, `users.list()`, `users.readMembers()` | Reads users and server members. |
|
||||
@@ -32,7 +32,7 @@ Capabilities protect privileged app surfaces. A plugin must declare a capability
|
||||
| `audio.volume` | `media.setInputVolume()`, `media.setOutputVolume()` | Adjusts local voice volume. |
|
||||
| `audio.effects` | Reserved audio effect features. | Included for audio processing plugins. |
|
||||
| `ui.settings` | `ui.registerSettingsPage()` | Adds settings pages. |
|
||||
| `ui.pages` | `ui.registerAppPage()`, `ui.registerComposerAction()`, `ui.registerProfileAction()`, `ui.registerToolbarAction()` | Adds app pages and actions. |
|
||||
| `ui.pages` | `ui.registerAppPage()`, `ui.registerComposerAction()`, `ui.registerProfileAction()`, `ui.registerToolbarAction()` | Adds app pages and action entry points, including View plugins menu actions. |
|
||||
| `ui.sidePanel` | `ui.registerSidePanel()` | Adds side panels. |
|
||||
| `ui.channelsSection` | `ui.registerChannelSection()` | Adds channel sections. |
|
||||
| `ui.embeds` | `ui.registerEmbedRenderer()` | Renders custom embeds. |
|
||||
|
||||
@@ -27,7 +27,7 @@ The manifest file can be named `toju-plugin.json` or `plugin.json`. Entrypoints
|
||||
"schemaVersion": 1,
|
||||
"id": "example.hello-world",
|
||||
"title": "Hello World",
|
||||
"description": "Adds a toolbar action that sends a message.",
|
||||
"description": "Adds a View plugins menu action that sends a message.",
|
||||
"version": "1.0.0",
|
||||
"kind": "client",
|
||||
"scope": "client",
|
||||
@@ -49,6 +49,7 @@ export function activate(context) {
|
||||
api.logger.info('Hello World activated');
|
||||
|
||||
const disposable = api.ui.registerToolbarAction('hello', {
|
||||
icon: 'HI',
|
||||
label: 'Hello',
|
||||
run: () => api.messages.send('Hello from my plugin')
|
||||
});
|
||||
@@ -65,10 +66,12 @@ export function deactivate(context) {
|
||||
}
|
||||
```
|
||||
|
||||
`registerToolbarAction()` adds an action tile to the server side panel's View plugins menu. Use `icon` for the tile badge and keep the `label` short enough to scan in a grid.
|
||||
|
||||
## Lifecycle Hooks
|
||||
|
||||
| Hook | When it runs | Use it for |
|
||||
| --- | --- | --- |
|
||||
| ------------------------------------------------ | ------------------------------------------------------ | -------------------------------------------------------------------------- |
|
||||
| `activate(context)` | During explicit plugin activation. | Register UI, subscribe to events, initialize state. |
|
||||
| `ready(context)` | After the load-order pass has activated ready plugins. | Cross-plugin coordination that needs other plugins loaded. |
|
||||
| `deactivate(context)` | During unload or reload. | Flush state and log shutdown. Disposables are also cleaned up by the host. |
|
||||
|
||||
@@ -13,7 +13,7 @@ sidebar_position: 5
|
||||
"schemaVersion": 1,
|
||||
"id": "example.toolbar-message",
|
||||
"title": "Toolbar Message",
|
||||
"description": "Adds a toolbar action that sends a reusable message.",
|
||||
"description": "Adds a View plugins menu action that sends a reusable message.",
|
||||
"version": "1.0.0",
|
||||
"kind": "client",
|
||||
"scope": "client",
|
||||
@@ -33,13 +33,18 @@ sidebar_position: 5
|
||||
export function activate(context) {
|
||||
const { api } = context;
|
||||
|
||||
context.subscriptions.push(api.ui.registerToolbarAction('standup-message', {
|
||||
context.subscriptions.push(
|
||||
api.ui.registerToolbarAction('standup-message', {
|
||||
icon: 'ST',
|
||||
label: 'Standup',
|
||||
run: () => api.messages.send('Standup: yesterday, today, blocked')
|
||||
}));
|
||||
run: (actionContext) => api.messages.send('Standup: yesterday, today, blocked', actionContext.textChannel?.id)
|
||||
})
|
||||
);
|
||||
}
|
||||
```
|
||||
|
||||
The action appears as a tile in the server side panel's View plugins menu and runs with `source: 'toolbarAction'`.
|
||||
|
||||
## Settings Page Plugin
|
||||
|
||||
```json
|
||||
@@ -67,7 +72,8 @@ export function activate(context) {
|
||||
export function activate(context) {
|
||||
const { api } = context;
|
||||
|
||||
context.subscriptions.push(api.ui.registerSettingsPage('preferences', {
|
||||
context.subscriptions.push(
|
||||
api.ui.registerSettingsPage('preferences', {
|
||||
label: 'Example Preferences',
|
||||
render: () => {
|
||||
const root = document.createElement('section');
|
||||
@@ -79,7 +85,8 @@ export function activate(context) {
|
||||
root.append(button);
|
||||
return root;
|
||||
}
|
||||
}));
|
||||
})
|
||||
);
|
||||
}
|
||||
```
|
||||
|
||||
@@ -99,13 +106,7 @@ A server-scoped plugin can be installed as a server requirement and auto-install
|
||||
"apiVersion": "1.0.0",
|
||||
"compatibility": { "minimumTojuVersion": "1.0.0" },
|
||||
"entrypoint": "./main.js",
|
||||
"capabilities": [
|
||||
"server.read",
|
||||
"users.manage",
|
||||
"ui.sidePanel",
|
||||
"media.playAudio",
|
||||
"messages.send"
|
||||
],
|
||||
"capabilities": ["server.read", "users.manage", "ui.sidePanel", "media.playAudio", "messages.send"],
|
||||
"pluginUser": {
|
||||
"displayName": "Soundboard",
|
||||
"label": "Audio helper"
|
||||
@@ -121,7 +122,8 @@ export function activate(context) {
|
||||
displayName: 'Soundboard'
|
||||
});
|
||||
|
||||
context.subscriptions.push(api.ui.registerSidePanel('sounds', {
|
||||
context.subscriptions.push(
|
||||
api.ui.registerSidePanel('sounds', {
|
||||
label: 'Soundboard',
|
||||
render: () => {
|
||||
const panel = document.createElement('div');
|
||||
@@ -137,7 +139,8 @@ export function activate(context) {
|
||||
panel.append(button);
|
||||
return panel;
|
||||
}
|
||||
}));
|
||||
})
|
||||
);
|
||||
}
|
||||
```
|
||||
|
||||
@@ -162,12 +165,14 @@ export function activate(context) {
|
||||
export function activate(context) {
|
||||
const { api } = context;
|
||||
|
||||
context.subscriptions.push(api.messageBus.subscribe({
|
||||
context.subscriptions.push(
|
||||
api.messageBus.subscribe({
|
||||
topic: 'poll:votes',
|
||||
replayLatest: true,
|
||||
latestMessageLimit: 20,
|
||||
handler: (event) => api.logger.info('Vote received', event.payload)
|
||||
}));
|
||||
})
|
||||
);
|
||||
|
||||
api.messageBus.publish({
|
||||
topic: 'poll:votes',
|
||||
@@ -192,10 +197,12 @@ export function activate(context) {
|
||||
badge.style.right = '1rem';
|
||||
badge.style.bottom = '1rem';
|
||||
|
||||
context.subscriptions.push(context.api.ui.mountElement('active-badge', {
|
||||
context.subscriptions.push(
|
||||
context.api.ui.mountElement('active-badge', {
|
||||
target: 'body',
|
||||
element: badge
|
||||
}));
|
||||
})
|
||||
);
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ Plugins add features to MetoYou. They can add pages, buttons, panels, settings,
|
||||
## Types of Plugins
|
||||
|
||||
| Type | What it means |
|
||||
| --- | --- |
|
||||
| -------------- | ----------------------------------------------------------------------------------------------------- |
|
||||
| Client plugin | Installed for your app. It follows you across servers when active. |
|
||||
| Server plugin | Installed for a specific server. It may be required, recommended, optional, blocked, or incompatible. |
|
||||
| Library plugin | Shared plugin code used by other plugins. It is not normally something users interact with directly. |
|
||||
@@ -26,6 +26,10 @@ Plugins add features to MetoYou. They can add pages, buttons, panels, settings,
|
||||
|
||||
Server-scoped plugins installed to the server you are currently viewing are enabled and activated automatically after install, so their panels, actions, or embeds can appear immediately.
|
||||
|
||||
## Use Plugin Actions
|
||||
|
||||
When plugins add quick actions to a server, the server side panel shows a View plugins link in the plugin area. Open it to see a grid of plugin action tiles. Selecting a tile runs that plugin's action in the current server and channel context.
|
||||
|
||||
## Install a Local Plugin
|
||||
|
||||
Desktop builds can discover local plugin folders from the app data plugins directory.
|
||||
@@ -41,7 +45,7 @@ Desktop builds can discover local plugin folders from the app data plugins direc
|
||||
When a server uses plugins, MetoYou may show a prompt.
|
||||
|
||||
| Status | Meaning |
|
||||
| --- | --- |
|
||||
| ------------ | --------------------------------------------------------------------------------- |
|
||||
| Required | You must install the plugin to join or continue using that server. |
|
||||
| Recommended | The server suggests the plugin, but you can choose. |
|
||||
| Optional | The plugin is available for the server, but not required. |
|
||||
@@ -57,7 +61,7 @@ Plugins must ask for capabilities before using sensitive features.
|
||||
Examples:
|
||||
|
||||
| Capability area | Why a plugin might ask |
|
||||
| --- | --- |
|
||||
| --------------- | -------------------------------------------------------------------------- |
|
||||
| Messages | Send messages, read current messages, moderate messages, or render embeds. |
|
||||
| Users and roles | Read member lists, create plugin users, or manage users. |
|
||||
| Voice and media | Play audio, add an audio stream, add a video stream, or adjust volume. |
|
||||
|
||||
Binary file not shown.
@@ -0,0 +1,49 @@
|
||||
import type { Room } from '../../../../shared-kernel';
|
||||
import { SYSTEM_ROLE_IDS } from '../constants/access-control.constants';
|
||||
import { normalizeRoomAccessControl } from './room.rules';
|
||||
|
||||
function buildRoom(overrides: Partial<Room> = {}): Room {
|
||||
return {
|
||||
id: 'room-1',
|
||||
name: 'Room',
|
||||
hostId: 'host-1',
|
||||
isPrivate: false,
|
||||
createdAt: 1,
|
||||
userCount: 1,
|
||||
members: [
|
||||
{
|
||||
id: 'user-1',
|
||||
oderId: 'oder-1',
|
||||
username: 'alice',
|
||||
displayName: 'Alice',
|
||||
role: 'admin',
|
||||
joinedAt: 1,
|
||||
lastSeenAt: 1
|
||||
}
|
||||
],
|
||||
...overrides
|
||||
};
|
||||
}
|
||||
|
||||
describe('normalizeRoomRoleAssignments', () => {
|
||||
it('uses legacy member roles when assignments are missing', () => {
|
||||
const room = normalizeRoomAccessControl(buildRoom());
|
||||
|
||||
expect(room.roleAssignments).toEqual([
|
||||
{
|
||||
userId: 'user-1',
|
||||
oderId: 'oder-1',
|
||||
roleIds: [SYSTEM_ROLE_IDS.admin]
|
||||
}
|
||||
]);
|
||||
|
||||
expect(room.members?.[0]?.role).toBe('admin');
|
||||
});
|
||||
|
||||
it('honors an explicit empty assignment list', () => {
|
||||
const room = normalizeRoomAccessControl(buildRoom({ roleAssignments: [] }));
|
||||
|
||||
expect(room.roleAssignments).toEqual([]);
|
||||
expect(room.members?.[0]?.role).toBe('member');
|
||||
});
|
||||
});
|
||||
@@ -45,6 +45,7 @@ export function normalizeRoomRoleAssignments(
|
||||
): RoomRoleAssignment[] {
|
||||
const validRoleIds = new Set(roles.map((role) => role.id).filter((roleId) => roleId !== SYSTEM_ROLE_IDS.everyone));
|
||||
const normalizedByUserKey = new Map<string, RoomRoleAssignment>();
|
||||
const hasExplicitAssignments = Array.isArray(assignments);
|
||||
|
||||
for (const assignment of assignments ?? []) {
|
||||
if (!assignment || typeof assignment !== 'object') {
|
||||
@@ -72,7 +73,7 @@ export function normalizeRoomRoleAssignments(
|
||||
});
|
||||
}
|
||||
|
||||
if (normalizedByUserKey.size > 0) {
|
||||
if (hasExplicitAssignments) {
|
||||
return sortAssignments(Array.from(normalizedByUserKey.values()));
|
||||
}
|
||||
|
||||
|
||||
@@ -52,6 +52,7 @@ import {
|
||||
})
|
||||
export class ChatMessagesComponent {
|
||||
@ViewChild(ChatMessageComposerComponent) composer?: ChatMessageComposerComponent;
|
||||
@ViewChild(ChatMessageListComponent) messageList?: ChatMessageListComponent;
|
||||
|
||||
private readonly electronBridge = inject(ElectronBridgeService);
|
||||
private readonly store = inject(Store);
|
||||
@@ -98,6 +99,8 @@ export class ChatMessagesComponent {
|
||||
}
|
||||
|
||||
handleMessageSubmitted(event: ChatMessageComposerSubmitEvent): void {
|
||||
this.messageList?.scrollToBottomAfterLocalSend();
|
||||
|
||||
this.store.dispatch(
|
||||
MessagesActions.sendMessage({
|
||||
content: event.content,
|
||||
|
||||
@@ -141,9 +141,11 @@ export class ChatMessageListComponent implements AfterViewChecked, OnDestroy {
|
||||
return lookup;
|
||||
});
|
||||
|
||||
private initialScrollObserver: MutationObserver | null = null;
|
||||
private initialScrollTimer: ReturnType<typeof setTimeout> | null = null;
|
||||
private bottomScrollObserver: MutationObserver | null = null;
|
||||
private bottomScrollTimer: ReturnType<typeof setTimeout> | null = null;
|
||||
private boundOnImageLoad: (() => void) | null = null;
|
||||
private localSendScrollPending = false;
|
||||
private localSendScrollTimer: ReturnType<typeof setTimeout> | null = null;
|
||||
private isAutoScrolling = false;
|
||||
private lastMessageCount = 0;
|
||||
private initialScrollPending = true;
|
||||
@@ -170,10 +172,17 @@ export class ChatMessageListComponent implements AfterViewChecked, OnDestroy {
|
||||
|
||||
const distanceFromBottom = element.scrollHeight - element.scrollTop - element.clientHeight;
|
||||
const newMessages = currentCount > this.lastMessageCount;
|
||||
const forceLocalSendScroll = this.shouldForceLocalSendScroll();
|
||||
|
||||
if (newMessages) {
|
||||
if (distanceFromBottom <= 300) {
|
||||
if (forceLocalSendScroll || distanceFromBottom <= 300) {
|
||||
if (forceLocalSendScroll) {
|
||||
this.clearLocalSendScrollPending();
|
||||
this.scheduleScrollToBottomAfterRender(true);
|
||||
} else {
|
||||
this.scheduleScrollToBottomSmooth();
|
||||
}
|
||||
|
||||
this.showNewMessagesBar.set(false);
|
||||
} else {
|
||||
queueMicrotask(() => this.showNewMessagesBar.set(true));
|
||||
@@ -198,7 +207,8 @@ export class ChatMessageListComponent implements AfterViewChecked, OnDestroy {
|
||||
this.isAutoScrolling = false;
|
||||
});
|
||||
|
||||
this.startInitialScrollWatch();
|
||||
this.clearLocalSendScrollPending();
|
||||
this.startBottomScrollWatch();
|
||||
this.showNewMessagesBar.set(false);
|
||||
this.lastMessageCount = this.messages().length;
|
||||
this.scheduleCodeHighlight();
|
||||
@@ -214,7 +224,8 @@ export class ChatMessageListComponent implements AfterViewChecked, OnDestroy {
|
||||
}
|
||||
|
||||
ngOnDestroy(): void {
|
||||
this.stopInitialScrollWatch();
|
||||
this.stopBottomScrollWatch();
|
||||
this.clearLocalSendScrollPending();
|
||||
}
|
||||
|
||||
findRepliedMessage(messageId?: string | null): Message | undefined {
|
||||
@@ -237,8 +248,8 @@ export class ChatMessageListComponent implements AfterViewChecked, OnDestroy {
|
||||
this.showNewMessagesBar.set(false);
|
||||
}
|
||||
|
||||
if (this.initialScrollObserver) {
|
||||
this.stopInitialScrollWatch();
|
||||
if (this.bottomScrollObserver) {
|
||||
this.stopBottomScrollWatch();
|
||||
}
|
||||
|
||||
if (element.scrollTop < 150 && this.hasMoreMessages() && !this.loadingMore()) {
|
||||
@@ -275,6 +286,13 @@ export class ChatMessageListComponent implements AfterViewChecked, OnDestroy {
|
||||
this.showNewMessagesBar.set(false);
|
||||
}
|
||||
|
||||
scrollToBottomAfterLocalSend(): void {
|
||||
this.localSendScrollPending = true;
|
||||
this.showNewMessagesBar.set(false);
|
||||
this.scheduleScrollToBottomAfterRender(true);
|
||||
this.armLocalSendScrollTimeout();
|
||||
}
|
||||
|
||||
scrollToMessage(messageId: string): void {
|
||||
const container = this.messagesContainer?.nativeElement;
|
||||
|
||||
@@ -336,54 +354,42 @@ export class ChatMessageListComponent implements AfterViewChecked, OnDestroy {
|
||||
|
||||
private resetScrollingState(): void {
|
||||
this.initialScrollPending = true;
|
||||
this.stopInitialScrollWatch();
|
||||
this.stopBottomScrollWatch();
|
||||
this.clearLocalSendScrollPending();
|
||||
this.showNewMessagesBar.set(false);
|
||||
this.lastMessageCount = 0;
|
||||
this.displayLimit.set(this.PAGE_SIZE);
|
||||
}
|
||||
|
||||
private startInitialScrollWatch(): void {
|
||||
this.stopInitialScrollWatch();
|
||||
private startBottomScrollWatch(): void {
|
||||
this.stopBottomScrollWatch();
|
||||
|
||||
const element = this.messagesContainer?.nativeElement;
|
||||
|
||||
if (!element)
|
||||
return;
|
||||
|
||||
const snapToBottom = () => {
|
||||
const container = this.messagesContainer?.nativeElement;
|
||||
|
||||
if (!container)
|
||||
return;
|
||||
|
||||
this.isAutoScrolling = true;
|
||||
container.scrollTop = container.scrollHeight;
|
||||
requestAnimationFrame(() => {
|
||||
this.isAutoScrolling = false;
|
||||
});
|
||||
};
|
||||
|
||||
this.initialScrollObserver = new MutationObserver(() => {
|
||||
requestAnimationFrame(snapToBottom);
|
||||
this.bottomScrollObserver = new MutationObserver(() => {
|
||||
requestAnimationFrame(() => this.scrollToBottomInstant());
|
||||
});
|
||||
|
||||
this.initialScrollObserver.observe(element, {
|
||||
this.bottomScrollObserver.observe(element, {
|
||||
childList: true,
|
||||
subtree: true,
|
||||
attributes: true,
|
||||
attributeFilter: ['src']
|
||||
});
|
||||
|
||||
this.boundOnImageLoad = () => requestAnimationFrame(snapToBottom);
|
||||
this.boundOnImageLoad = () => requestAnimationFrame(() => this.scrollToBottomInstant());
|
||||
element.addEventListener('load', this.boundOnImageLoad, true);
|
||||
|
||||
this.initialScrollTimer = setTimeout(() => this.stopInitialScrollWatch(), 5000);
|
||||
this.bottomScrollTimer = setTimeout(() => this.stopBottomScrollWatch(), 5000);
|
||||
}
|
||||
|
||||
private stopInitialScrollWatch(): void {
|
||||
if (this.initialScrollObserver) {
|
||||
this.initialScrollObserver.disconnect();
|
||||
this.initialScrollObserver = null;
|
||||
private stopBottomScrollWatch(): void {
|
||||
if (this.bottomScrollObserver) {
|
||||
this.bottomScrollObserver.disconnect();
|
||||
this.bottomScrollObserver = null;
|
||||
}
|
||||
|
||||
if (this.boundOnImageLoad && this.messagesContainer) {
|
||||
@@ -392,12 +398,41 @@ export class ChatMessageListComponent implements AfterViewChecked, OnDestroy {
|
||||
this.boundOnImageLoad = null;
|
||||
}
|
||||
|
||||
if (this.initialScrollTimer) {
|
||||
clearTimeout(this.initialScrollTimer);
|
||||
this.initialScrollTimer = null;
|
||||
if (this.bottomScrollTimer) {
|
||||
clearTimeout(this.bottomScrollTimer);
|
||||
this.bottomScrollTimer = null;
|
||||
}
|
||||
}
|
||||
|
||||
private armLocalSendScrollTimeout(): void {
|
||||
if (this.localSendScrollTimer) {
|
||||
clearTimeout(this.localSendScrollTimer);
|
||||
}
|
||||
|
||||
this.localSendScrollTimer = setTimeout(() => {
|
||||
this.localSendScrollPending = false;
|
||||
this.localSendScrollTimer = null;
|
||||
}, 1000);
|
||||
}
|
||||
|
||||
private clearLocalSendScrollPending(): void {
|
||||
this.localSendScrollPending = false;
|
||||
|
||||
if (this.localSendScrollTimer) {
|
||||
clearTimeout(this.localSendScrollTimer);
|
||||
this.localSendScrollTimer = null;
|
||||
}
|
||||
}
|
||||
|
||||
private shouldForceLocalSendScroll(): boolean {
|
||||
if (!this.localSendScrollPending)
|
||||
return false;
|
||||
|
||||
const latestMessage = this.channelMessages().at(-1);
|
||||
|
||||
return !!latestMessage && latestMessage.senderId === this.currentUserId();
|
||||
}
|
||||
|
||||
private getMessageDateTimestamp(message: Message): number {
|
||||
return message.timestamp || getMessageTimestamp(message);
|
||||
}
|
||||
@@ -424,6 +459,31 @@ export class ChatMessageListComponent implements AfterViewChecked, OnDestroy {
|
||||
}
|
||||
}
|
||||
|
||||
private scrollToBottomInstant(): void {
|
||||
const element = this.messagesContainer?.nativeElement;
|
||||
|
||||
if (!element)
|
||||
return;
|
||||
|
||||
this.isAutoScrolling = true;
|
||||
element.scrollTop = element.scrollHeight;
|
||||
requestAnimationFrame(() => {
|
||||
this.isAutoScrolling = false;
|
||||
});
|
||||
}
|
||||
|
||||
private scheduleScrollToBottomAfterRender(watchForLayoutChanges = false): void {
|
||||
requestAnimationFrame(() => {
|
||||
requestAnimationFrame(() => {
|
||||
this.scrollToBottomInstant();
|
||||
|
||||
if (watchForLayoutChanges) {
|
||||
this.startBottomScrollWatch();
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
private scheduleScrollToBottomSmooth(): void {
|
||||
requestAnimationFrame(() => {
|
||||
requestAnimationFrame(() => this.scrollToBottomSmooth());
|
||||
|
||||
@@ -13,4 +13,6 @@ Direct calls coordinate private voice sessions started from people cards, direct
|
||||
7. Joining, leaving, ending, participant additions, and call chat conversion updates are mirrored as `direct-call` events over the same P2P/signaling fallback path used by direct messages.
|
||||
8. The server rail shows call icons only while at least one participant is joined. If a user is viewing a private call after the session ends, the route returns to the call's chat view.
|
||||
|
||||
Incoming `direct-call` events are ignored unless the current user is declared in the event's `participantIds` or participant profiles, so only invited PM/group-call participants can receive call audio, the in-app incoming-call modal, or a desktop ring notification.
|
||||
|
||||
Two-person calls use the one-to-one direct-message conversation id as their call id. Converted group calls keep the original call id for media routing but point `conversationId` at the new group chat so active streams stay connected while the chat history boundary changes.
|
||||
|
||||
@@ -87,6 +87,17 @@ describe('DirectCallService', () => {
|
||||
expect(context.service.incomingCall()).toBeNull();
|
||||
});
|
||||
|
||||
it('ignores incoming call events when the current user is not a participant', async () => {
|
||||
const context = createServiceContext({ currentUser: charlie, allUsers: [alice, bob, charlie] });
|
||||
|
||||
context.directCallEvents.next(createCallEvent('ring', alice, ['alice', 'bob']));
|
||||
|
||||
await vi.waitFor(() => expect(context.service.sessionById('dm-alice-bob')).toBeNull());
|
||||
expect(context.audio.playLoop).not.toHaveBeenCalled();
|
||||
expect(context.directMessages.createConversation).not.toHaveBeenCalled();
|
||||
expect(context.directMessages.createGroupConversation).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('answers an incoming call from the modal action', async () => {
|
||||
const context = createServiceContext({ currentUser: bob, allUsers: [alice, bob] });
|
||||
|
||||
|
||||
@@ -355,6 +355,10 @@ export class DirectCallService {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this.callPayloadIncludesParticipant(payload, meId)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const participants = this.callParticipantsFromPayload(payload);
|
||||
const existing = this.sessionById(payload.callId);
|
||||
const incomingSession = this.createSession({
|
||||
@@ -671,6 +675,11 @@ export class DirectCallService {
|
||||
]);
|
||||
}
|
||||
|
||||
private callPayloadIncludesParticipant(payload: DirectCallEventPayload, participantId: string): boolean {
|
||||
return payload.participantIds.includes(participantId)
|
||||
|| (payload.participants ?? []).some((participant) => participant.userId === participantId);
|
||||
}
|
||||
|
||||
private groupConversationTitle(session: DirectCallSession): string {
|
||||
const names = Object.values(session.participants)
|
||||
.map((participant) => participant.profile.displayName || participant.profile.username || participant.userId);
|
||||
|
||||
@@ -23,6 +23,8 @@ direct-message/
|
||||
5. The recipient persists the message as `DELIVERED` and sends a `direct-message-status` event back.
|
||||
6. Opening the conversation marks incoming messages as `ACKNOWLEDGED` and emits a status event.
|
||||
|
||||
Incoming PM and group-chat events are ignored unless the current user is declared in the message recipients, participant profiles, or existing local conversation. Sync requests are only answered for conversation participants, so a stray peer route cannot create unread state or expose private history.
|
||||
|
||||
Status transitions are monotonic, so a stale `SENT` event cannot overwrite `DELIVERED` or `ACKNOWLEDGED`.
|
||||
|
||||
## Chat View
|
||||
|
||||
@@ -2,6 +2,8 @@ import {
|
||||
advanceDirectMessageStatus,
|
||||
createDirectConversation,
|
||||
createGroupConversation,
|
||||
directMessageEventIncludesUser,
|
||||
directMessageSyncIncludesUser,
|
||||
getDirectConversationId,
|
||||
isGroupDirectConversation,
|
||||
updateMessageStatusInConversation,
|
||||
@@ -92,6 +94,30 @@ describe('DirectMessageService domain flow', () => {
|
||||
expect(advanceDirectMessageStatus('DELIVERED', 'SENT')).toBe('DELIVERED');
|
||||
expect(advanceDirectMessageStatus('DELIVERED', 'ACKNOWLEDGED')).toBe('ACKNOWLEDGED');
|
||||
});
|
||||
|
||||
it('recognises only declared direct-message recipients and participants', () => {
|
||||
const payload = {
|
||||
message: createMessage('message-1', 'SENT', 'dm-group-test', ['bob']),
|
||||
participants: [alice, bob],
|
||||
sender: alice
|
||||
};
|
||||
|
||||
expect(directMessageEventIncludesUser(payload, 'bob')).toBe(true);
|
||||
expect(directMessageEventIncludesUser(payload, 'charlie')).toBe(false);
|
||||
});
|
||||
|
||||
it('recognises only declared sync participants', () => {
|
||||
const payload = {
|
||||
conversationId: 'dm-group-test',
|
||||
messages: [],
|
||||
participants: [alice, bob],
|
||||
sender: alice,
|
||||
syncedAt: 30
|
||||
};
|
||||
|
||||
expect(directMessageSyncIncludesUser(payload, 'alice')).toBe(true);
|
||||
expect(directMessageSyncIncludesUser(payload, 'charlie')).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
function createMessage(
|
||||
|
||||
@@ -17,6 +17,9 @@ import {
|
||||
advanceDirectMessageStatus,
|
||||
createDirectConversation,
|
||||
createGroupConversation,
|
||||
directMessageConversationIncludesUser,
|
||||
directMessageEventIncludesUser,
|
||||
directMessageSyncIncludesUser,
|
||||
getDirectConversationId,
|
||||
isGroupDirectConversation,
|
||||
updateMessageStatusInConversation,
|
||||
@@ -464,6 +467,11 @@ export class DirectMessageService {
|
||||
private async handleIncomingMessage(payload: DirectMessageEventPayload): Promise<void> {
|
||||
const ownerId = this.getCurrentUserIdOrThrow();
|
||||
const currentUser = this.requireCurrentUser();
|
||||
|
||||
if (!directMessageEventIncludesUser(payload, ownerId) || payload.sender.userId === ownerId || payload.message.senderId === ownerId) {
|
||||
return;
|
||||
}
|
||||
|
||||
const currentParticipant = toDirectMessageParticipant(currentUser);
|
||||
const sender = payload.sender;
|
||||
const conversationId = payload.message.conversationId
|
||||
@@ -528,7 +536,11 @@ export class DirectMessageService {
|
||||
|
||||
private async handleIncomingMutation(payload: DirectMessageMutationEventPayload): Promise<void> {
|
||||
const ownerId = this.getCurrentUserIdOrThrow();
|
||||
const conversation = await this.requireConversation(ownerId, payload.conversationId);
|
||||
const conversation = await this.findConversation(ownerId, payload.conversationId);
|
||||
|
||||
if (!conversation || !directMessageConversationIncludesUser(conversation, ownerId)) {
|
||||
return;
|
||||
}
|
||||
|
||||
await this.persistConversation(ownerId, this.applyMutation(conversation, payload));
|
||||
}
|
||||
@@ -540,6 +552,14 @@ export class DirectMessageService {
|
||||
return;
|
||||
}
|
||||
|
||||
const conversation = this.conversationsSignal().find((entry) => entry.id === payload.conversationId);
|
||||
|
||||
if (!conversation
|
||||
|| !directMessageConversationIncludesUser(conversation, currentUserId)
|
||||
|| !directMessageConversationIncludesUser(conversation, payload.sender.userId)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!payload.isTyping) {
|
||||
this.typingEntriesSignal.update((entries) => entries.filter((entry) =>
|
||||
!(entry.conversationId === payload.conversationId && entry.userId === payload.sender.userId)
|
||||
@@ -566,10 +586,12 @@ export class DirectMessageService {
|
||||
private async handleIncomingSyncRequest(payload: DirectMessageSyncRequestEventPayload): Promise<void> {
|
||||
const ownerId = this.getCurrentUserIdOrThrow();
|
||||
const currentUser = this.requireCurrentUser();
|
||||
const conversation = this.conversationsSignal().find((entry) => entry.id === payload.conversationId)
|
||||
?? await this.repository.getConversation(ownerId, payload.conversationId);
|
||||
const conversation = await this.findConversation(ownerId, payload.conversationId);
|
||||
|
||||
if (!conversation || payload.sender.userId === ownerId) {
|
||||
if (!conversation
|
||||
|| payload.sender.userId === ownerId
|
||||
|| !directMessageConversationIncludesUser(conversation, ownerId)
|
||||
|| !directMessageConversationIncludesUser(conversation, payload.sender.userId)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -596,6 +618,10 @@ export class DirectMessageService {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!directMessageSyncIncludesUser(payload, ownerId) || !directMessageSyncIncludesUser(payload, payload.sender.userId)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const existingConversation = this.conversationsSignal().find((conversation) => conversation.id === payload.conversationId)
|
||||
?? await this.repository.getConversation(ownerId, payload.conversationId)
|
||||
?? (payload.conversationKind === 'group' || payload.participants.length > 2
|
||||
@@ -863,10 +889,7 @@ export class DirectMessageService {
|
||||
}
|
||||
|
||||
private async requireConversation(ownerId: string, conversationId: string): Promise<DirectMessageConversation> {
|
||||
await this.loadForOwner(ownerId);
|
||||
|
||||
const conversation = this.conversationsSignal().find((entry) => entry.id === conversationId)
|
||||
?? await this.repository.getConversation(ownerId, conversationId);
|
||||
const conversation = await this.findConversation(ownerId, conversationId);
|
||||
|
||||
if (!conversation) {
|
||||
throw new Error('Direct message conversation not found.');
|
||||
@@ -875,6 +898,13 @@ export class DirectMessageService {
|
||||
return conversation;
|
||||
}
|
||||
|
||||
private async findConversation(ownerId: string, conversationId: string): Promise<DirectMessageConversation | null> {
|
||||
await this.loadForOwner(ownerId);
|
||||
|
||||
return this.conversationsSignal().find((entry) => entry.id === conversationId)
|
||||
?? await this.repository.getConversation(ownerId, conversationId);
|
||||
}
|
||||
|
||||
private requireCurrentUser(): User {
|
||||
const currentUser = this.currentUser();
|
||||
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
import type {
|
||||
DirectMessage,
|
||||
DirectMessageConversation,
|
||||
DirectMessageEventPayload,
|
||||
DirectMessageParticipant,
|
||||
DirectMessageSyncEventPayload,
|
||||
DirectMessageStatus
|
||||
} from '../models/direct-message.model';
|
||||
|
||||
@@ -74,6 +76,27 @@ export function isGroupDirectConversation(conversation: DirectMessageConversatio
|
||||
return conversation.kind === 'group' || conversation.participants.length > 2;
|
||||
}
|
||||
|
||||
export function directMessageConversationIncludesUser(
|
||||
conversation: Pick<DirectMessageConversation, 'participantProfiles' | 'participants'>,
|
||||
userId: string
|
||||
): boolean {
|
||||
return conversation.participants.includes(userId) || !!conversation.participantProfiles[userId];
|
||||
}
|
||||
|
||||
export function directMessageEventIncludesUser(
|
||||
payload: DirectMessageEventPayload,
|
||||
userId: string
|
||||
): boolean {
|
||||
return collectDirectMessageEventParticipantIds(payload).has(userId);
|
||||
}
|
||||
|
||||
export function directMessageSyncIncludesUser(
|
||||
payload: DirectMessageSyncEventPayload,
|
||||
userId: string
|
||||
): boolean {
|
||||
return payload.participants.some((participant) => participant.userId === userId);
|
||||
}
|
||||
|
||||
export function upsertDirectMessage(
|
||||
conversation: DirectMessageConversation,
|
||||
message: DirectMessage,
|
||||
@@ -129,6 +152,30 @@ function uniqueDirectMessageParticipants(participants: DirectMessageParticipant[
|
||||
});
|
||||
}
|
||||
|
||||
function collectDirectMessageEventParticipantIds(payload: DirectMessageEventPayload): Set<string> {
|
||||
const participantIds = new Set<string>();
|
||||
|
||||
if (payload.message.senderId) {
|
||||
participantIds.add(payload.message.senderId);
|
||||
}
|
||||
|
||||
if (payload.message.recipientId) {
|
||||
participantIds.add(payload.message.recipientId);
|
||||
}
|
||||
|
||||
for (const recipientId of payload.message.recipientIds ?? []) {
|
||||
participantIds.add(recipientId);
|
||||
}
|
||||
|
||||
for (const participant of payload.participants ?? []) {
|
||||
if (participant.userId) {
|
||||
participantIds.add(participant.userId);
|
||||
}
|
||||
}
|
||||
|
||||
return participantIds;
|
||||
}
|
||||
|
||||
function buildGroupConversationTitle(participants: DirectMessageParticipant[]): string {
|
||||
const names = participants.map((participant) => participant.displayName || participant.username || participant.userId);
|
||||
|
||||
|
||||
@@ -195,6 +195,7 @@ Additional runtime guards:
|
||||
|
||||
- Deleted messages never notify.
|
||||
- The current user's own messages never notify.
|
||||
- Live room messages only notify when the message room is the current room or one of the user's saved rooms.
|
||||
- Duplicate live events are suppressed with a rolling in-memory set of the last 500 notified message IDs.
|
||||
- Unread badges are independent from mute state. Muting changes delivery only; it does not hide unread indicators.
|
||||
|
||||
|
||||
@@ -172,6 +172,12 @@ export class NotificationsService {
|
||||
return;
|
||||
}
|
||||
|
||||
const room = this.getKnownRoom(message.roomId);
|
||||
|
||||
if (!room) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.rememberMessageId(message.id);
|
||||
|
||||
const channelId = resolveMessageChannelId(message);
|
||||
@@ -198,7 +204,6 @@ export class NotificationsService {
|
||||
return;
|
||||
}
|
||||
|
||||
const room = getRoomById(context.rooms, message.roomId);
|
||||
const payload = buildNotificationDisplayPayload(
|
||||
message,
|
||||
room,
|
||||
@@ -512,6 +517,11 @@ export class NotificationsService {
|
||||
return this.getCurrentUserIds().has(senderId);
|
||||
}
|
||||
|
||||
private getKnownRoom(roomId: string): Room | null {
|
||||
return getRoomById(this.savedRooms(), roomId)
|
||||
?? (this.currentRoom()?.id === roomId ? this.currentRoom() ?? null : null);
|
||||
}
|
||||
|
||||
private setSettings(settings: NotificationsSettings): void {
|
||||
this._settings.set(settings);
|
||||
this.storage.save(settings);
|
||||
|
||||
@@ -22,6 +22,8 @@ Plugins can communicate over a plugin-only message bus through `api.messageBus`.
|
||||
|
||||
Plugins can inspect the current interaction context through `api.context.getCurrent()`. Composer action callbacks also receive this context directly, including the local user, current chat server, active text channel, and the user's current voice channel when connected. Plugins with message access can call `api.messages.setTyping(true | false, channelId?)` and can observe peer typing state with `api.messages.subscribeTyping(handler)`, where typing events include the user, server, text channel, and voice channel when those records are available locally.
|
||||
|
||||
Plugins can add quick actions to the server sidebar's View plugins menu with `api.ui.registerToolbarAction(id, { icon, label, run })`. The menu is rendered from the room side-panel plugin area as an overlay grid, and callbacks receive a `toolbarAction` interaction context.
|
||||
|
||||
Desktop plugin preferences that belong to the local user, including capability grants, disabled plugin ids, and previously activated plugin ids, are persisted through Electron's local database meta table with renderer localStorage as the browser fallback.
|
||||
|
||||
Runtime activation is explicit. `PluginHostService.activateReadyPlugins()` imports browser-safe plugin entrypoints from URL-resolvable manifests, passes a frozen `TojuClientPluginApi`, runs `activate`, then runs `ready` after the load-order pass. HTTP(S) entrypoints are imported directly when the host serves module-compatible JavaScript; if a source host serves JavaScript with a non-module MIME type, the runtime fetches the source and imports it through a blob URL. Successfully activated plugin ids are remembered locally, and store-installed plugins are reactivated for the active server when their persisted manifests load again. `deactivate` runs during unload/reload, disposables are cleaned in reverse order, and UI contributions are removed by plugin id.
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
<div
|
||||
appThemeNode="contextMenuSurface"
|
||||
class="w-80 rounded-lg border border-border bg-card p-3 shadow-xl"
|
||||
role="menu"
|
||||
aria-label="Plugin actions"
|
||||
style="animation: profile-card-in 120ms cubic-bezier(0.2, 0, 0, 1) both"
|
||||
>
|
||||
<div class="mb-3 flex items-center justify-between gap-3">
|
||||
<div class="min-w-0">
|
||||
<p class="text-sm font-semibold text-foreground">Plugins</p>
|
||||
<p class="truncate text-xs text-muted-foreground">{{ actions().length }} available actions</p>
|
||||
</div>
|
||||
<button
|
||||
type="button"
|
||||
class="grid h-7 w-7 shrink-0 place-items-center rounded-md text-muted-foreground transition-colors hover:bg-secondary hover:text-foreground"
|
||||
aria-label="Close plugin menu"
|
||||
title="Close"
|
||||
(click)="close()"
|
||||
>
|
||||
<ng-icon
|
||||
name="lucideX"
|
||||
class="h-4 w-4"
|
||||
/>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
@if (actions().length > 0) {
|
||||
<div class="grid max-h-80 grid-cols-3 gap-2 overflow-auto pr-1">
|
||||
@for (record of actions(); track record.id) {
|
||||
<button
|
||||
type="button"
|
||||
class="group flex min-h-20 flex-col items-center justify-start gap-2 rounded-md px-2 py-2 text-center transition-colors hover:text-foreground focus:outline-none focus:ring-2 focus:ring-primary/60"
|
||||
role="menuitem"
|
||||
[attr.aria-label]="actionTitle(record)"
|
||||
[title]="actionTitle(record)"
|
||||
(click)="runAction(record)"
|
||||
>
|
||||
<span
|
||||
class="grid h-11 w-11 shrink-0 place-items-center overflow-hidden rounded-md border border-border bg-secondary text-xs font-semibold text-foreground transition-colors group-hover:border-primary/40"
|
||||
>
|
||||
@if (isImageIcon(record)) {
|
||||
<img
|
||||
class="h-full w-full object-cover"
|
||||
[src]="iconText(record)"
|
||||
[alt]="record.contribution.label"
|
||||
/>
|
||||
} @else {
|
||||
<span class="max-w-full truncate px-1">{{ iconText(record) }}</span>
|
||||
}
|
||||
</span>
|
||||
<span class="line-clamp-2 min-h-8 text-[11px] font-medium leading-4 text-foreground">
|
||||
{{ record.contribution.label }}
|
||||
</span>
|
||||
</button>
|
||||
}
|
||||
</div>
|
||||
} @else {
|
||||
<p class="rounded-md border border-dashed border-border bg-background/40 px-3 py-4 text-center text-sm text-muted-foreground">
|
||||
No plugin actions available.
|
||||
</p>
|
||||
}
|
||||
</div>
|
||||
@@ -0,0 +1,111 @@
|
||||
/* eslint-disable @typescript-eslint/member-ordering */
|
||||
import {
|
||||
Component,
|
||||
HostListener,
|
||||
computed,
|
||||
inject,
|
||||
output
|
||||
} from '@angular/core';
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { NgIcon, provideIcons } from '@ng-icons/core';
|
||||
import { lucideX } from '@ng-icons/lucide';
|
||||
import type { PluginApiActionContribution } from '../../domain/models/plugin-api.models';
|
||||
import { PluginClientApiService } from '../../application/services/plugin-client-api.service';
|
||||
import { PluginLoggerService } from '../../application/services/plugin-logger.service';
|
||||
import { PluginRegistryService } from '../../application/services/plugin-registry.service';
|
||||
import type { PluginUiContributionRecord } from '../../application/services/plugin-ui-registry.service';
|
||||
import { PluginUiRegistryService } from '../../application/services/plugin-ui-registry.service';
|
||||
import { ThemeNodeDirective } from '../../../theme';
|
||||
|
||||
@Component({
|
||||
selector: 'app-plugin-action-menu',
|
||||
standalone: true,
|
||||
imports: [
|
||||
CommonModule,
|
||||
NgIcon,
|
||||
ThemeNodeDirective
|
||||
],
|
||||
viewProviders: [provideIcons({ lucideX })],
|
||||
templateUrl: './plugin-action-menu.component.html'
|
||||
})
|
||||
export class PluginActionMenuComponent {
|
||||
readonly closed = output<undefined>();
|
||||
|
||||
private readonly logger = inject(PluginLoggerService);
|
||||
private readonly pluginApi = inject(PluginClientApiService);
|
||||
private readonly pluginRegistry = inject(PluginRegistryService);
|
||||
private readonly pluginUi = inject(PluginUiRegistryService);
|
||||
|
||||
readonly actions = computed(() => [...this.pluginUi.toolbarActionRecords()]
|
||||
.sort((left, right) => this.sortActionRecords(left, right)));
|
||||
|
||||
@HostListener('document:keydown.escape')
|
||||
close(): void {
|
||||
this.closed.emit(undefined);
|
||||
}
|
||||
|
||||
runAction(record: PluginUiContributionRecord<PluginApiActionContribution>): void {
|
||||
this.closed.emit(undefined);
|
||||
|
||||
void Promise.resolve()
|
||||
.then(() => record.contribution.run(this.pluginApi.createActionContext('toolbarAction')))
|
||||
.catch((error: unknown) => this.logger.error(record.pluginId, 'Toolbar action failed', error));
|
||||
}
|
||||
|
||||
pluginName(pluginId: string): string {
|
||||
return this.pluginRegistry.find(pluginId)?.manifest.title ?? pluginId;
|
||||
}
|
||||
|
||||
actionTitle(record: PluginUiContributionRecord<PluginApiActionContribution>): string {
|
||||
return `${this.pluginName(record.pluginId)}: ${record.contribution.label}`;
|
||||
}
|
||||
|
||||
iconText(record: PluginUiContributionRecord<PluginApiActionContribution>): string {
|
||||
const icon = record.contribution.icon?.trim();
|
||||
|
||||
if (icon) {
|
||||
return icon;
|
||||
}
|
||||
|
||||
return createInitials(this.pluginName(record.pluginId), record.contribution.label);
|
||||
}
|
||||
|
||||
isImageIcon(record: PluginUiContributionRecord<PluginApiActionContribution>): boolean {
|
||||
const icon = record.contribution.icon?.trim() ?? '';
|
||||
|
||||
return icon.startsWith('http://')
|
||||
|| icon.startsWith('https://')
|
||||
|| icon.startsWith('data:image/')
|
||||
|| icon.startsWith('blob:');
|
||||
}
|
||||
|
||||
private sortActionRecords(
|
||||
left: PluginUiContributionRecord<PluginApiActionContribution>,
|
||||
right: PluginUiContributionRecord<PluginApiActionContribution>
|
||||
): number {
|
||||
const leftPlugin = this.pluginName(left.pluginId);
|
||||
const rightPlugin = this.pluginName(right.pluginId);
|
||||
const pluginCompare = leftPlugin.localeCompare(rightPlugin);
|
||||
|
||||
if (pluginCompare !== 0) {
|
||||
return pluginCompare;
|
||||
}
|
||||
|
||||
return left.contribution.label.localeCompare(right.contribution.label);
|
||||
}
|
||||
}
|
||||
|
||||
function createInitials(pluginName: string, actionLabel: string): string {
|
||||
const words = `${pluginName} ${actionLabel}`
|
||||
.split(/[^a-zA-Z0-9]+/)
|
||||
.filter((word) => word.length > 0);
|
||||
|
||||
if (words.length === 0) {
|
||||
return 'PL';
|
||||
}
|
||||
|
||||
return words
|
||||
.slice(0, 2)
|
||||
.map((word) => word.charAt(0).toUpperCase())
|
||||
.join('');
|
||||
}
|
||||
@@ -0,0 +1,139 @@
|
||||
import {
|
||||
ElementRef,
|
||||
Injectable,
|
||||
inject
|
||||
} from '@angular/core';
|
||||
import {
|
||||
ConnectedPosition,
|
||||
Overlay,
|
||||
OverlayRef
|
||||
} from '@angular/cdk/overlay';
|
||||
import { ComponentPortal } from '@angular/cdk/portal';
|
||||
import {
|
||||
Subscription,
|
||||
filter,
|
||||
fromEvent
|
||||
} from 'rxjs';
|
||||
import { PluginActionMenuComponent } from './plugin-action-menu.component';
|
||||
|
||||
const GAP = 10;
|
||||
const VIEWPORT_MARGIN = 8;
|
||||
const POSITIONS: ConnectedPosition[] = [
|
||||
{ originX: 'end', originY: 'top', overlayX: 'start', overlayY: 'top', offsetX: GAP },
|
||||
{ originX: 'end', originY: 'bottom', overlayX: 'start', overlayY: 'bottom', offsetX: GAP },
|
||||
{ originX: 'start', originY: 'top', overlayX: 'end', overlayY: 'top', offsetX: -GAP },
|
||||
{ originX: 'start', originY: 'bottom', overlayX: 'end', overlayY: 'bottom', offsetX: -GAP }
|
||||
];
|
||||
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class PluginActionMenuService {
|
||||
private readonly overlay = inject(Overlay);
|
||||
private currentOrigin: HTMLElement | null = null;
|
||||
private overlayRef: OverlayRef | null = null;
|
||||
private overlaySubscriptions: Subscription | null = null;
|
||||
private scrollBlocker: (() => void) | null = null;
|
||||
|
||||
open(origin: ElementRef | HTMLElement): void {
|
||||
const rawEl = origin instanceof ElementRef ? origin.nativeElement : origin;
|
||||
|
||||
if (this.overlayRef) {
|
||||
const sameOrigin = rawEl === this.currentOrigin;
|
||||
|
||||
this.close();
|
||||
|
||||
if (sameOrigin) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
const elementRef = origin instanceof ElementRef ? origin : new ElementRef(origin);
|
||||
|
||||
this.currentOrigin = rawEl;
|
||||
|
||||
const positionStrategy = this.overlay
|
||||
.position()
|
||||
.flexibleConnectedTo(elementRef)
|
||||
.withPositions(POSITIONS)
|
||||
.withViewportMargin(VIEWPORT_MARGIN)
|
||||
.withPush(true);
|
||||
|
||||
this.overlayRef = this.overlay.create({
|
||||
positionStrategy,
|
||||
scrollStrategy: this.overlay.scrollStrategies.noop()
|
||||
});
|
||||
|
||||
this.syncThemeVars();
|
||||
|
||||
const componentRef = this.overlayRef.attach(new ComponentPortal(PluginActionMenuComponent));
|
||||
const subscriptions = new Subscription();
|
||||
|
||||
subscriptions.add(componentRef.instance.closed.subscribe(() => this.close()));
|
||||
subscriptions.add(fromEvent<PointerEvent>(document, 'pointerdown')
|
||||
.pipe(
|
||||
filter((event) => {
|
||||
const target = event.target as Node;
|
||||
|
||||
if (this.overlayRef?.overlayElement.contains(target)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.currentOrigin?.contains(target)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
})
|
||||
)
|
||||
.subscribe(() => this.close()));
|
||||
|
||||
this.overlaySubscriptions = subscriptions;
|
||||
this.blockScroll();
|
||||
}
|
||||
|
||||
close(): void {
|
||||
this.scrollBlocker?.();
|
||||
this.scrollBlocker = null;
|
||||
this.overlaySubscriptions?.unsubscribe();
|
||||
this.overlaySubscriptions = null;
|
||||
|
||||
if (this.overlayRef) {
|
||||
this.overlayRef.dispose();
|
||||
this.overlayRef = null;
|
||||
this.currentOrigin = null;
|
||||
}
|
||||
}
|
||||
|
||||
private blockScroll(): void {
|
||||
const handler = (event: Event): void => {
|
||||
if (this.overlayRef?.overlayElement.contains(event.target as Node)) {
|
||||
return;
|
||||
}
|
||||
|
||||
event.preventDefault();
|
||||
};
|
||||
const opts: AddEventListenerOptions = { passive: false, capture: true };
|
||||
|
||||
document.addEventListener('wheel', handler, opts);
|
||||
document.addEventListener('touchmove', handler, opts);
|
||||
|
||||
this.scrollBlocker = () => {
|
||||
document.removeEventListener('wheel', handler, opts);
|
||||
document.removeEventListener('touchmove', handler, opts);
|
||||
};
|
||||
}
|
||||
|
||||
private syncThemeVars(): void {
|
||||
const appRoot = document.querySelector<HTMLElement>('[data-theme-key="appRoot"]');
|
||||
const container = document.querySelector<HTMLElement>('.cdk-overlay-container');
|
||||
|
||||
if (!appRoot || !container) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (const prop of Array.from(appRoot.style)) {
|
||||
if (prop.startsWith('--')) {
|
||||
container.style.setProperty(prop, appRoot.style.getPropertyValue(prop));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -16,4 +16,5 @@ export * from './domain/logic/plugin-manifest-validation.logic';
|
||||
export * from './domain/models/plugin-api.models';
|
||||
export * from './domain/models/plugin-runtime.models';
|
||||
export * from './domain/models/plugin-store.models';
|
||||
export * from './feature/plugin-action-menu/plugin-action-menu.service';
|
||||
export * from './infrastructure/local-plugin-discovery.service';
|
||||
|
||||
@@ -259,13 +259,26 @@
|
||||
</div>
|
||||
</section>
|
||||
|
||||
@if (pluginChannelSections().length > 0 || pluginSidePanels().length > 0) {
|
||||
@if (pluginChannelSections().length > 0 || pluginMenuActions().length > 0 || pluginSidePanels().length > 0) {
|
||||
<section
|
||||
class="border-t border-border px-2 py-3"
|
||||
data-testid="plugin-room-side-panel"
|
||||
>
|
||||
<div class="mb-2 px-1">
|
||||
<div class="mb-2 flex items-center justify-between gap-2 px-1">
|
||||
<h4 class="text-xs font-semibold uppercase tracking-[0.18em] text-muted-foreground">Plugins</h4>
|
||||
<button
|
||||
type="button"
|
||||
class="inline-flex items-center gap-1 rounded-md px-1.5 py-1 text-xs font-medium text-muted-foreground transition-colors hover:bg-secondary/60 hover:text-foreground"
|
||||
aria-haspopup="menu"
|
||||
title="View plugins"
|
||||
(click)="openPluginActionMenu($event)"
|
||||
>
|
||||
<ng-icon
|
||||
name="lucidePackage"
|
||||
class="h-3.5 w-3.5"
|
||||
/>
|
||||
<span>View plugins</span>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
@if (pluginChannelSections().length > 0) {
|
||||
|
||||
@@ -24,7 +24,8 @@ import {
|
||||
lucideUsers,
|
||||
lucidePlus,
|
||||
lucideVolumeX,
|
||||
lucideGamepad2
|
||||
lucideGamepad2,
|
||||
lucidePackage
|
||||
} from '@ng-icons/lucide';
|
||||
import { selectOnlineUsers, selectCurrentUser } from '../../../store/users/users.selectors';
|
||||
import {
|
||||
@@ -53,7 +54,7 @@ import { formatGameActivityElapsed } from '../../../domains/game-activity';
|
||||
import { ExternalLinkService } from '../../../core/platform/external-link.service';
|
||||
import { VoiceControlsComponent } from '../../../domains/voice-session/feature/voice-controls/voice-controls.component';
|
||||
import { PluginRenderHostComponent } from '../../../domains/plugins/feature/plugin-render-host/plugin-render-host.component';
|
||||
import { PluginUiRegistryService } from '../../../domains/plugins';
|
||||
import { PluginActionMenuService, PluginUiRegistryService } from '../../../domains/plugins';
|
||||
import { isChannelNameTaken, normalizeChannelName } from '../../../store/rooms/room-channels.rules';
|
||||
import {
|
||||
canManageMember,
|
||||
@@ -108,7 +109,8 @@ type PanelMode = 'channels' | 'users';
|
||||
lucideUsers,
|
||||
lucidePlus,
|
||||
lucideVolumeX,
|
||||
lucideGamepad2
|
||||
lucideGamepad2,
|
||||
lucidePackage
|
||||
})
|
||||
],
|
||||
templateUrl: './rooms-side-panel.component.html'
|
||||
@@ -127,6 +129,7 @@ export class RoomsSidePanelComponent implements OnDestroy {
|
||||
private profileCard = inject(ProfileCardService);
|
||||
private directMessages = inject(DirectMessageService);
|
||||
private readonly externalLinks = inject(ExternalLinkService);
|
||||
private readonly pluginActionMenu = inject(PluginActionMenuService);
|
||||
private readonly voiceActivity = inject(VoiceActivityService);
|
||||
private readonly voiceConnectivity = inject(VoiceConnectivityHealthService);
|
||||
private readonly pluginUi = inject(PluginUiRegistryService);
|
||||
@@ -144,6 +147,7 @@ export class RoomsSidePanelComponent implements OnDestroy {
|
||||
textChannels = this.store.selectSignal(selectTextChannels);
|
||||
voiceChannels = this.store.selectSignal(selectVoiceChannels);
|
||||
pluginChannelSections = this.pluginUi.channelSectionRecords;
|
||||
pluginMenuActions = this.pluginUi.toolbarActionRecords;
|
||||
pluginSidePanels = this.pluginUi.sidePanelRecords;
|
||||
localUserHasDesync = this.voiceConnectivity.localUserHasDesync;
|
||||
roomMembers = computed(() => this.currentRoom()?.members ?? []);
|
||||
@@ -219,6 +223,7 @@ export class RoomsSidePanelComponent implements OnDestroy {
|
||||
ngOnDestroy(): void {
|
||||
clearInterval(this.activityTimer);
|
||||
this.cancelQueuedProfileCardOpen();
|
||||
this.pluginActionMenu.close();
|
||||
}
|
||||
|
||||
gameActivityElapsed(user: User | null | undefined): string {
|
||||
@@ -258,6 +263,12 @@ export class RoomsSidePanelComponent implements OnDestroy {
|
||||
this.queueProfileCardOpen(event.currentTarget as HTMLElement, this.roomMemberToUser(member), false);
|
||||
}
|
||||
|
||||
openPluginActionMenu(event: Event): void {
|
||||
event.stopPropagation();
|
||||
this.cancelQueuedProfileCardOpen();
|
||||
this.pluginActionMenu.open(event.currentTarget as HTMLElement);
|
||||
}
|
||||
|
||||
async openDirectMessage(event: Event, user: User): Promise<void> {
|
||||
event.stopPropagation();
|
||||
this.cancelQueuedProfileCardOpen();
|
||||
|
||||
@@ -123,6 +123,8 @@ Room affinity is authoritative at this layer as well. The renderer repairs each
|
||||
|
||||
Server-relayed fallbacks are intentionally narrow. Room chat (`chat_message`), direct-message events (`direct-message`, `direct-message-status`, `direct-message-mutation`), and voice presence (`voice_state`) may flow over signaling so users can still see written chat and voice roster state while P2P data channels are down. Media, attachments, message inventory sync, screen/camera state, and plugin data-channel traffic remain peer-plane responsibilities.
|
||||
|
||||
Room-scoped chat intake is also guarded on receipt: a `chat-message` or chat sync payload is processed only when its `roomId` is the current room or one of the user's saved rooms. This keeps broad peer meshes from creating unread state or notifications for unrelated chat-servers.
|
||||
|
||||
In UI/debug conversations, a **chat-server** means one of the saved rooms navigated from the server rail. Each chat-server has its own assigned signal server via `sourceId` / `sourceUrl`, and room-scoped feature/config checks must prefer that signal server before considering any global active endpoint. For example, KLIPY GIF picker visibility is resolved against the currently viewed chat-server's signal server so an unrelated offline chat-server does not hide the button everywhere.
|
||||
|
||||
Cold-start routing now waits for the initial server-directory health probes so same-backend aliases can collapse to one canonical signaling endpoint before any saved rooms reconnect. When a room is reconnected on a chosen socket, its background rooms are re-joined on that same socket as well so stale per-signal memberships do not keep orphan managers alive, and reconnect replay only sends `view_server` for rooms that manager still has joined.
|
||||
|
||||
@@ -29,6 +29,7 @@ function createContext(overrides: Record<string, unknown> = {}) {
|
||||
debugging: {},
|
||||
currentUser: null,
|
||||
currentRoom: null,
|
||||
savedRooms: [],
|
||||
...overrides
|
||||
} as const;
|
||||
}
|
||||
@@ -42,7 +43,8 @@ describe('dispatchIncomingMessage room-scoped sync', () => {
|
||||
const context = createContext({
|
||||
db: { getMessages },
|
||||
webrtc: { sendToPeer },
|
||||
currentRoom: { id: 'room-a' }
|
||||
currentRoom: { id: 'room-a' },
|
||||
savedRooms: [{ id: 'room-b' }]
|
||||
});
|
||||
|
||||
await firstValueFrom(
|
||||
@@ -76,7 +78,8 @@ describe('dispatchIncomingMessage room-scoped sync', () => {
|
||||
const context = createContext({
|
||||
db: { getMessages },
|
||||
webrtc: { sendToPeer },
|
||||
currentRoom: { id: 'room-a' }
|
||||
currentRoom: { id: 'room-a' },
|
||||
savedRooms: [{ id: 'room-b' }]
|
||||
});
|
||||
|
||||
await firstValueFrom(
|
||||
@@ -97,4 +100,29 @@ describe('dispatchIncomingMessage room-scoped sync', () => {
|
||||
messages: roomBMessages
|
||||
});
|
||||
});
|
||||
|
||||
it('ignores chat messages for rooms that are not saved or currently viewed', async () => {
|
||||
const saveMessage = vi.fn(async () => undefined);
|
||||
const rememberMessageRoom = vi.fn();
|
||||
const context = createContext({
|
||||
db: { saveMessage },
|
||||
attachments: { rememberMessageRoom },
|
||||
currentRoom: { id: 'room-a' },
|
||||
savedRooms: [{ id: 'room-a' }]
|
||||
});
|
||||
|
||||
const action = await firstValueFrom(
|
||||
dispatchIncomingMessage(
|
||||
{
|
||||
type: 'chat-message',
|
||||
message: createMessage({ roomId: 'room-b' })
|
||||
} as never,
|
||||
context as never
|
||||
).pipe(defaultIfEmpty(null))
|
||||
);
|
||||
|
||||
expect(action).toBeNull();
|
||||
expect(saveMessage).not.toHaveBeenCalled();
|
||||
expect(rememberMessageRoom).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -96,6 +96,7 @@ export interface IncomingMessageContext {
|
||||
debugging: DebuggingService;
|
||||
currentUser: User | null;
|
||||
currentRoom: Room | null;
|
||||
savedRooms?: Room[];
|
||||
}
|
||||
|
||||
/** Signature for an incoming-message handler function. */
|
||||
@@ -110,11 +111,12 @@ type MessageHandler = (
|
||||
*/
|
||||
function handleInventoryRequest(
|
||||
event: IncomingMessageEvent,
|
||||
{ db, webrtc, attachments }: IncomingMessageContext
|
||||
ctx: IncomingMessageContext
|
||||
): Observable<Action> {
|
||||
const { db, webrtc, attachments } = ctx;
|
||||
const { roomId, fromPeerId } = event;
|
||||
|
||||
if (!roomId || !fromPeerId)
|
||||
if (!roomId || !fromPeerId || !isKnownRoomId(roomId, ctx))
|
||||
return EMPTY;
|
||||
|
||||
return from(
|
||||
@@ -155,11 +157,12 @@ function handleInventoryRequest(
|
||||
*/
|
||||
function handleInventory(
|
||||
event: IncomingMessageEvent,
|
||||
{ db, webrtc, attachments }: IncomingMessageContext
|
||||
ctx: IncomingMessageContext
|
||||
): Observable<Action> {
|
||||
const { db, webrtc, attachments } = ctx;
|
||||
const { roomId, fromPeerId, items } = event;
|
||||
|
||||
if (!roomId || !Array.isArray(items) || !fromPeerId)
|
||||
if (!roomId || !Array.isArray(items) || !fromPeerId || !isKnownRoomId(roomId, ctx))
|
||||
return EMPTY;
|
||||
|
||||
return from(
|
||||
@@ -197,11 +200,12 @@ function handleInventory(
|
||||
*/
|
||||
function handleSyncRequestIds(
|
||||
event: IncomingMessageEvent,
|
||||
{ db, webrtc, attachments }: IncomingMessageContext
|
||||
ctx: IncomingMessageContext
|
||||
): Observable<Action> {
|
||||
const { db, webrtc, attachments } = ctx;
|
||||
const { roomId, ids, fromPeerId } = event;
|
||||
|
||||
if (!Array.isArray(ids) || !fromPeerId)
|
||||
if (!roomId || !Array.isArray(ids) || !fromPeerId || !isKnownRoomId(roomId, ctx))
|
||||
return EMPTY;
|
||||
|
||||
return from(
|
||||
@@ -210,7 +214,7 @@ function handleSyncRequestIds(
|
||||
(ids as string[]).map((id) => db.getMessageById(id))
|
||||
);
|
||||
const messages = maybeMessages.filter(
|
||||
(msg): msg is Message => !!msg
|
||||
(msg): msg is Message => !!msg && msg.roomId === roomId
|
||||
);
|
||||
const hydrated = await Promise.all(
|
||||
messages.map((msg) => hydrateMessage(msg, db))
|
||||
@@ -250,19 +254,26 @@ function handleSyncRequestIds(
|
||||
*/
|
||||
function handleSyncBatch(
|
||||
event: IncomingMessageEvent,
|
||||
{ db, attachments }: IncomingMessageContext
|
||||
ctx: IncomingMessageContext
|
||||
): Observable<Action> {
|
||||
if (!hasMessageBatch(event))
|
||||
return EMPTY;
|
||||
|
||||
if (hasAttachmentMetaMap(event.attachments)) {
|
||||
const scopedEvent = scopeMessageBatchToKnownRooms(event, ctx);
|
||||
|
||||
if (!scopedEvent)
|
||||
return EMPTY;
|
||||
|
||||
const { db, attachments } = ctx;
|
||||
|
||||
if (hasAttachmentMetaMap(scopedEvent.attachments)) {
|
||||
attachments.registerSyncedAttachments(
|
||||
event.attachments,
|
||||
Object.fromEntries(event.messages.map((message) => [message.id, message.roomId]))
|
||||
scopedEvent.attachments,
|
||||
Object.fromEntries(scopedEvent.messages.map((message) => [message.id, message.roomId]))
|
||||
);
|
||||
}
|
||||
|
||||
return from(processSyncBatch(event, db, attachments)).pipe(
|
||||
return from(processSyncBatch(scopedEvent, db, attachments)).pipe(
|
||||
mergeMap((toUpsert) =>
|
||||
toUpsert.length > 0
|
||||
? of(MessagesActions.syncMessages({ messages: toUpsert }))
|
||||
@@ -316,18 +327,22 @@ function queueWatchedAttachmentDownloads(
|
||||
/** Saves an incoming chat message to DB and dispatches receiveMessage. */
|
||||
function handleChatMessage(
|
||||
event: IncomingMessageEvent,
|
||||
{
|
||||
ctx: IncomingMessageContext
|
||||
): Observable<Action> {
|
||||
const {
|
||||
db,
|
||||
debugging,
|
||||
attachments,
|
||||
currentUser
|
||||
}: IncomingMessageContext
|
||||
): Observable<Action> {
|
||||
} = ctx;
|
||||
const msg = event.message;
|
||||
|
||||
if (!msg)
|
||||
return EMPTY;
|
||||
|
||||
if (!isKnownRoomId(msg.roomId, ctx))
|
||||
return EMPTY;
|
||||
|
||||
// Skip our own messages (reflected via server relay)
|
||||
const isOwnMessage =
|
||||
msg.senderId === currentUser?.id ||
|
||||
@@ -536,11 +551,12 @@ function handleFileNotFound(
|
||||
*/
|
||||
function handleSyncSummary(
|
||||
event: IncomingMessageEvent,
|
||||
{ db, webrtc, currentRoom }: IncomingMessageContext
|
||||
ctx: IncomingMessageContext
|
||||
): Observable<Action> {
|
||||
const { db, webrtc, currentRoom } = ctx;
|
||||
const targetRoomId = event.roomId || currentRoom?.id;
|
||||
|
||||
if (!targetRoomId)
|
||||
if (!targetRoomId || !isKnownRoomId(targetRoomId, ctx))
|
||||
return EMPTY;
|
||||
|
||||
return from(
|
||||
@@ -575,12 +591,13 @@ function handleSyncSummary(
|
||||
/** Responds to a peer's full sync request by sending all local messages. */
|
||||
function handleSyncRequest(
|
||||
event: IncomingMessageEvent,
|
||||
{ db, webrtc, currentRoom }: IncomingMessageContext
|
||||
ctx: IncomingMessageContext
|
||||
): Observable<Action> {
|
||||
const { db, webrtc, currentRoom } = ctx;
|
||||
const targetRoomId = event.roomId || currentRoom?.id;
|
||||
const fromPeerId = event.fromPeerId;
|
||||
|
||||
if (!targetRoomId || !fromPeerId)
|
||||
if (!targetRoomId || !fromPeerId || !isKnownRoomId(targetRoomId, ctx))
|
||||
return EMPTY;
|
||||
|
||||
return from(
|
||||
@@ -600,12 +617,17 @@ function handleSyncRequest(
|
||||
/** Merges a full message dump from a peer into the local DB and store. */
|
||||
function handleSyncFull(
|
||||
event: IncomingMessageEvent,
|
||||
{ db, attachments }: IncomingMessageContext
|
||||
ctx: IncomingMessageContext
|
||||
): Observable<Action> {
|
||||
if (!hasMessageBatch(event))
|
||||
return EMPTY;
|
||||
|
||||
return from(processSyncBatch(event, db, attachments)).pipe(
|
||||
const scopedEvent = scopeMessageBatchToKnownRooms(event, ctx);
|
||||
|
||||
if (!scopedEvent)
|
||||
return EMPTY;
|
||||
|
||||
return from(processSyncBatch(scopedEvent, ctx.db, ctx.attachments)).pipe(
|
||||
mergeMap((toUpsert) =>
|
||||
toUpsert.length > 0
|
||||
? of(MessagesActions.syncMessages({ messages: toUpsert }))
|
||||
@@ -657,6 +679,49 @@ export function dispatchIncomingMessage(
|
||||
return handler ? handler(event, ctx) : EMPTY;
|
||||
}
|
||||
|
||||
function isKnownRoomId(roomId: string | undefined, ctx: IncomingMessageContext): boolean {
|
||||
if (!roomId) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return ctx.currentRoom?.id === roomId || (ctx.savedRooms ?? []).some((room) => room.id === roomId);
|
||||
}
|
||||
|
||||
function scopeMessageBatchToKnownRooms(
|
||||
event: SyncBatchEvent,
|
||||
ctx: IncomingMessageContext
|
||||
): SyncBatchEvent | null {
|
||||
if (event.roomId && !isKnownRoomId(event.roomId, ctx)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const messages = event.messages.filter((message) => isKnownRoomId(message.roomId, ctx));
|
||||
|
||||
if (messages.length === 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return {
|
||||
...event,
|
||||
attachments: filterAttachmentMapToMessages(event.attachments, messages),
|
||||
messages
|
||||
};
|
||||
}
|
||||
|
||||
function filterAttachmentMapToMessages(
|
||||
attachmentMap: IncomingMessageEvent['attachments'],
|
||||
messages: Message[]
|
||||
): AttachmentMetaMap | undefined {
|
||||
if (!hasAttachmentMetaMap(attachmentMap)) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const messageIds = new Set(messages.map((message) => message.id));
|
||||
const filteredEntries = Object.entries(attachmentMap).filter(([messageId]) => messageIds.has(messageId));
|
||||
|
||||
return filteredEntries.length > 0 ? Object.fromEntries(filteredEntries) : undefined;
|
||||
}
|
||||
|
||||
function trackBackgroundOperation(
|
||||
task: Promise<unknown> | unknown,
|
||||
debugging: DebuggingService,
|
||||
|
||||
@@ -30,7 +30,7 @@ import {
|
||||
import { v4 as uuidv4 } from 'uuid';
|
||||
import { MessagesActions } from './messages.actions';
|
||||
import { selectCurrentUser } from '../users/users.selectors';
|
||||
import { selectCurrentRoom } from '../rooms/rooms.selectors';
|
||||
import { selectCurrentRoom, selectSavedRooms } from '../rooms/rooms.selectors';
|
||||
import { selectMessagesEntities } from './messages.selectors';
|
||||
import { RealtimeSessionFacade } from '../../core/realtime';
|
||||
import { DatabaseService } from '../../infrastructure/persistence';
|
||||
@@ -457,12 +457,14 @@ export class MessagesEffects {
|
||||
this.webrtc.onMessageReceived.pipe(
|
||||
withLatestFrom(
|
||||
this.store.select(selectCurrentUser),
|
||||
this.store.select(selectCurrentRoom)
|
||||
this.store.select(selectCurrentRoom),
|
||||
this.store.select(selectSavedRooms)
|
||||
),
|
||||
mergeMap(([
|
||||
event,
|
||||
currentUser,
|
||||
currentRoom
|
||||
currentRoom,
|
||||
savedRooms
|
||||
]) => {
|
||||
const ctx: IncomingMessageContext = {
|
||||
db: this.db,
|
||||
@@ -470,7 +472,8 @@ export class MessagesEffects {
|
||||
attachments: this.attachments,
|
||||
debugging: this.debugging,
|
||||
currentUser: currentUser ?? null,
|
||||
currentRoom
|
||||
currentRoom,
|
||||
savedRooms
|
||||
};
|
||||
|
||||
return dispatchIncomingMessage(event, ctx).pipe(
|
||||
@@ -502,12 +505,14 @@ export class MessagesEffects {
|
||||
this.webrtc.onSignalingMessage.pipe(
|
||||
withLatestFrom(
|
||||
this.store.select(selectCurrentUser),
|
||||
this.store.select(selectCurrentRoom)
|
||||
this.store.select(selectCurrentRoom),
|
||||
this.store.select(selectSavedRooms)
|
||||
),
|
||||
mergeMap(([
|
||||
event,
|
||||
currentUser,
|
||||
currentRoom
|
||||
currentRoom,
|
||||
savedRooms
|
||||
]) => {
|
||||
if (event.type !== 'chat_message') {
|
||||
return EMPTY;
|
||||
@@ -519,7 +524,8 @@ export class MessagesEffects {
|
||||
attachments: this.attachments,
|
||||
debugging: this.debugging,
|
||||
currentUser: currentUser ?? null,
|
||||
currentRoom
|
||||
currentRoom,
|
||||
savedRooms
|
||||
};
|
||||
|
||||
return dispatchIncomingMessage({
|
||||
|
||||
@@ -20,9 +20,10 @@ import type {
|
||||
} from '../../shared-kernel';
|
||||
import { RealtimeSessionFacade } from '../../core/realtime';
|
||||
import { UsersActions } from '../users/users.actions';
|
||||
import { selectCurrentUser } from '../users/users.selectors';
|
||||
import { selectAllUsers, selectCurrentUser } from '../users/users.selectors';
|
||||
import { RoomsActions } from './rooms.actions';
|
||||
import { selectCurrentRoom, selectSavedRooms } from './rooms.selectors';
|
||||
import { normalizeRoomAccessControl, resolveLegacyRole } from '../../domains/access-control';
|
||||
import {
|
||||
areRoomMembersEqual,
|
||||
findRoomMember,
|
||||
@@ -113,6 +114,40 @@ export class RoomMembersSyncEffects {
|
||||
)
|
||||
);
|
||||
|
||||
/** Keep active-room user roles derived from room access-control assignments. */
|
||||
syncAccessControlRolesIntoUsers$ = createEffect(() =>
|
||||
this.actions$.pipe(
|
||||
ofType(
|
||||
RoomsActions.createRoomSuccess,
|
||||
RoomsActions.joinRoomSuccess,
|
||||
RoomsActions.viewServerSuccess,
|
||||
RoomsActions.updateRoom
|
||||
),
|
||||
withLatestFrom(
|
||||
this.store.select(selectCurrentRoom),
|
||||
this.store.select(selectSavedRooms),
|
||||
this.store.select(selectAllUsers),
|
||||
this.store.select(selectCurrentUser)
|
||||
),
|
||||
mergeMap(([
|
||||
action,
|
||||
currentRoom,
|
||||
savedRooms,
|
||||
allUsers,
|
||||
currentUser
|
||||
]) => {
|
||||
const room = this.resolveRoleSyncRoom(action, currentRoom, savedRooms);
|
||||
|
||||
if (!room)
|
||||
return EMPTY;
|
||||
|
||||
const actions = this.createUserRoleSyncActions(room, allUsers, currentUser ?? null);
|
||||
|
||||
return actions.length > 0 ? actions : EMPTY;
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
/** Update persisted room rosters when signaling presence changes arrive. */
|
||||
signalingPresenceIntoRoomMembers$ = createEffect(() =>
|
||||
this.webrtc.onSignalingMessage.pipe(
|
||||
@@ -342,6 +377,88 @@ export class RoomMembersSyncEffects {
|
||||
: [RoomsActions.updateRoom({ roomId: room.id, changes: { members } })];
|
||||
}
|
||||
|
||||
private resolveRoleSyncRoom(
|
||||
action:
|
||||
| ReturnType<typeof RoomsActions.createRoomSuccess>
|
||||
| ReturnType<typeof RoomsActions.joinRoomSuccess>
|
||||
| ReturnType<typeof RoomsActions.viewServerSuccess>
|
||||
| ReturnType<typeof RoomsActions.updateRoom>,
|
||||
currentRoom: Room | null,
|
||||
savedRooms: Room[]
|
||||
): Room | null {
|
||||
if ('room' in action) {
|
||||
return normalizeRoomAccessControl(action.room);
|
||||
}
|
||||
|
||||
if (currentRoom?.id !== action.roomId || !this.hasRoleRelevantRoomChanges(action.changes)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const room = this.resolveRoom(action.roomId, currentRoom, savedRooms);
|
||||
|
||||
return room ? normalizeRoomAccessControl({ ...room, ...action.changes }) : null;
|
||||
}
|
||||
|
||||
private hasRoleRelevantRoomChanges(changes: Partial<Room>): boolean {
|
||||
return (
|
||||
Object.prototype.hasOwnProperty.call(changes, 'hostId') ||
|
||||
Object.prototype.hasOwnProperty.call(changes, 'members') ||
|
||||
Object.prototype.hasOwnProperty.call(changes, 'permissions') ||
|
||||
Object.prototype.hasOwnProperty.call(changes, 'roles') ||
|
||||
Object.prototype.hasOwnProperty.call(changes, 'roleAssignments') ||
|
||||
Object.prototype.hasOwnProperty.call(changes, 'channelPermissions') ||
|
||||
Object.prototype.hasOwnProperty.call(changes, 'slowModeInterval')
|
||||
);
|
||||
}
|
||||
|
||||
private createUserRoleSyncActions(room: Room, allUsers: User[], currentUser: User | null): Action[] {
|
||||
const usersById = new Map<string, User>();
|
||||
|
||||
for (const user of allUsers) {
|
||||
if (this.shouldSyncUserRoleForRoom(room, user, currentUser)) {
|
||||
usersById.set(user.id, user);
|
||||
}
|
||||
}
|
||||
|
||||
if (currentUser) {
|
||||
usersById.set(currentUser.id, currentUser);
|
||||
}
|
||||
|
||||
return Array.from(usersById.values())
|
||||
.map((user) => ({
|
||||
user,
|
||||
role: resolveLegacyRole(room, user)
|
||||
}))
|
||||
.filter(({ user, role }) => user.role !== role)
|
||||
.map(({ user, role }) => UsersActions.updateUserRole({ userId: user.id,
|
||||
role }));
|
||||
}
|
||||
|
||||
private shouldSyncUserRoleForRoom(room: Room, user: User, currentUser: User | null): boolean {
|
||||
if (currentUser && user.id === currentUser.id) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (room.hostId === user.id || room.hostId === user.oderId) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (Array.isArray(user.presenceServerIds) && user.presenceServerIds.includes(room.id)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (findRoomMember(room.members ?? [], user.oderId || user.id)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return (room.roleAssignments ?? []).some((assignment) => (
|
||||
assignment.userId === user.id ||
|
||||
assignment.userId === user.oderId ||
|
||||
assignment.oderId === user.id ||
|
||||
assignment.oderId === user.oderId
|
||||
));
|
||||
}
|
||||
|
||||
private handleMemberRosterRequest(
|
||||
event: ChatEvent,
|
||||
currentRoom: Room | null,
|
||||
|
||||
Reference in New Issue
Block a user