Compare commits
66
Commits
sw-fix
..
34fe223aa4
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
34fe223aa4 | ||
|
|
19eded89c1 | ||
|
|
d0c13b1a49 | ||
|
|
ff575212ee | ||
|
|
a461543916 | ||
|
|
9f8fae964d | ||
|
|
7e64ea398b | ||
|
|
086e4b3b03 | ||
|
|
d0017e4a78 | ||
|
|
e96bd527a0 | ||
|
|
1a5ca81513 | ||
|
|
d280f66d5c | ||
|
|
e2e9f75e40 | ||
|
|
7aba71490a | ||
|
|
2e14980de6 | ||
|
|
6b16c789a4 | ||
|
|
535302aed9 | ||
|
|
a25777a77a | ||
|
|
3adba22ddf | ||
|
|
bacfef5558 | ||
|
|
6aa459df31 | ||
|
|
8f92029b47 | ||
|
|
49c4641ca8 | ||
|
|
ac0ec9f42d | ||
|
|
0f7f0100af | ||
|
|
91def3ad34 | ||
|
|
a29be7953b | ||
|
|
26c70f5a1d | ||
|
|
fc68e0a769 | ||
|
|
fb14db6d50 | ||
|
|
6b9c8de393 | ||
|
|
32e5fec6f3 | ||
|
|
8210ee7046 | ||
|
|
d0dccdeb67 | ||
|
|
dddaa4183e | ||
|
|
c8e49d3855 | ||
|
|
9bdf4ff1fd | ||
|
|
23ee156f2f | ||
|
|
9a85a48704 | ||
|
|
f3119e3dc2 | ||
|
|
cecf65a3a1 | ||
|
|
02592ed43c | ||
|
|
6bd2903de1 | ||
|
|
7c52027afb | ||
|
|
2344c8273e | ||
|
|
6e4c4bc795 | ||
|
|
e447fdc0f3 | ||
|
|
4dd0e6637d | ||
|
|
dfccaec9dc | ||
|
|
9019d7c21e | ||
|
|
eef1d14492 | ||
|
|
2b66dcc08c | ||
|
|
dac74f098e | ||
|
|
d4d1b4957f | ||
|
|
c4aa1567d7 | ||
|
|
a6ddafb446 | ||
|
|
6c1a9942b0 | ||
|
|
4bea48959e | ||
|
|
34a3352e21 | ||
|
|
3cc5f0cc6a | ||
|
|
fd93339ad4 | ||
|
|
b1ecb0c46b | ||
|
|
4656f08802 | ||
|
|
a631e90ea2 | ||
|
|
10270b75ca | ||
|
|
7925866868 |
+49
-43
@@ -30,8 +30,13 @@ jobs:
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version-file: '.node-version'
|
||||
cache: npm
|
||||
|
||||
# No npm / node_modules cache: the act_runner's internal cache server is
|
||||
# unreachable from job containers (`getCacheEntry failed: connect ETIMEDOUT
|
||||
# 172.17.0.2`), so every cache restore hangs ~5 min and then fails — pure
|
||||
# cost, zero benefit. `cache: npm` was removed from Setup Node above for the
|
||||
# same reason. Re-enable both (setup-node `cache: npm` + an actions/cache
|
||||
# node_modules step) once the runner's cache server is reachable from jobs.
|
||||
- name: Install dependencies
|
||||
# Harden against transient registry network failures (ECONNRESET etc.):
|
||||
# raise npm's built-in fetch retries/timeouts and retry `npm ci` up to
|
||||
@@ -52,58 +57,59 @@ jobs:
|
||||
sleep $((attempt * 15))
|
||||
done
|
||||
|
||||
# ── Critical gate — if this fails, nothing deploys ──────────────────
|
||||
# ── Quality gates run BEFORE the slow build so a format/lint/type/test
|
||||
# error fails in seconds instead of after the ~minutes-long build. All are
|
||||
# hard gates — any failure fails the job and blocks the deploy. The tree is
|
||||
# held clean (prettier formatted, eslint 0 errors, typecheck 0), so these
|
||||
# gate real regressions. NOTE: the lotus-build.sh upstream-merge path can
|
||||
# deploy without CI; a later normal push surfaces any introduced issue here
|
||||
# — fix forward (or briefly re-soften a gate) rather than deploy broken.
|
||||
# eslint gates on errors, plus a warning ratchet (Gitea #97): `check:eslint`
|
||||
# runs with `--max-warnings 74`, the exact warning count on this tree at
|
||||
# the time the ratchet was added. New warnings push the count over that
|
||||
# ceiling and fail the build; fixing an existing warning is free to do
|
||||
# and should lower the ceiling in the same PR so the count can only go
|
||||
# down over time, never back up.
|
||||
- name: Prettier
|
||||
run: npm run check:prettier
|
||||
|
||||
- name: ESLint
|
||||
run: npm run check:eslint
|
||||
|
||||
- name: TypeScript
|
||||
run: npm run typecheck
|
||||
|
||||
# Deterministic pure-logic tests on Node's built-in runner via tsx (no
|
||||
# vitest — Vite 8 is ahead of vitest's range). A failure blocks the deploy.
|
||||
- name: Unit tests
|
||||
run: npm test
|
||||
|
||||
# ── Critical gate — if this fails, nothing deploys. Produces dist/. ──
|
||||
- name: Build
|
||||
run: npm run build
|
||||
env:
|
||||
NODE_OPTIONS: '--max_old_space_size=4096'
|
||||
VITE_APP_VERSION: ${{ github.sha }}
|
||||
|
||||
# Unit tests are a hard gate too — deterministic pure-logic tests on Node's
|
||||
# built-in runner via tsx (no vitest — Vite 8 is ahead of vitest's range).
|
||||
# A failure blocks the deploy.
|
||||
- name: Unit tests
|
||||
run: npm test
|
||||
# ── Boot check — actually loads the built dist/, not just builds it ──
|
||||
- name: Boot check
|
||||
run: node scripts/boot-check.mjs
|
||||
|
||||
# ── Quality gates (hard — a failure fails the job and blocks deploy) ──
|
||||
# The tree is held clean (typecheck 0, eslint 0 errors, prettier
|
||||
# formatted), so these gate real regressions instead of relying on local
|
||||
# runs. NOTE: an upstream-stable merge (the lotus-build.sh path) could
|
||||
# introduce upstream type/lint/format issues; that path deploys without
|
||||
# CI, but a subsequent normal push would surface the failure here — fix
|
||||
# forward (or briefly re-soften a gate) rather than let it deploy broken.
|
||||
# eslint gates on errors only (existing `no-explicit-any` warnings stay
|
||||
# informational — `check:eslint` has no --max-warnings).
|
||||
- name: TypeScript
|
||||
run: npm run typecheck
|
||||
|
||||
- name: ESLint
|
||||
run: npm run check:eslint
|
||||
|
||||
- name: Prettier Check and Fix
|
||||
run: |
|
||||
npx prettier --write .
|
||||
npm run check:prettier
|
||||
|
||||
# ── Security (informational — findings shouldn't block a deploy) ─────
|
||||
# ── Security — hard gate. #24 cleared the outstanding advisories (0
|
||||
# vulnerabilities on this tree, verified with `npm audit --omit=dev`), so
|
||||
# there is nothing left this should be soft against. Hard on both
|
||||
# `push` and `pull_request`: a new high/critical advisory should block
|
||||
# the deploy just as much as it should block the PR.
|
||||
- name: Audit (high/critical)
|
||||
run: npm audit --audit-level=high --omit=dev
|
||||
continue-on-error: true
|
||||
|
||||
# ── Bundle size report (informational — never blocks a deploy) ───────
|
||||
- name: Report bundle sizes
|
||||
continue-on-error: true
|
||||
run: |
|
||||
echo "### Bundle sizes" >> $GITHUB_STEP_SUMMARY
|
||||
echo "" >> $GITHUB_STEP_SUMMARY
|
||||
echo "| File | Size | Gzip |" >> $GITHUB_STEP_SUMMARY
|
||||
echo "|------|------|------|" >> $GITHUB_STEP_SUMMARY
|
||||
find dist/assets -name "*.js" -not -name "*.map" | sort | while read f; do
|
||||
name=$(basename "$f")
|
||||
size=$(du -sh "$f" | cut -f1)
|
||||
gzip_size=$(gzip -c "$f" | wc -c | awk '{printf "%.1f kB", $1/1024}')
|
||||
echo "| $name | $size | $gzip_size |" >> $GITHUB_STEP_SUMMARY
|
||||
done
|
||||
# ── Bundle size budget — hard gate on pull_request, warning on push (a
|
||||
# push has already merged; failing it can only delay deploying an
|
||||
# otherwise-good commit, not prevent the regression, so pull_request is
|
||||
# where this should be caught). Budgets live in scripts/bundle-budget.json.
|
||||
- name: Check bundle size budget
|
||||
continue-on-error: ${{ github.event_name == 'push' }}
|
||||
run: node scripts/check-bundle-size.mjs ${{ github.event_name }}
|
||||
|
||||
# ── Desktop build trigger ──────────────────────────────────────────────
|
||||
# Gated on `build` succeeding so a broken push (e.g. failing `npm ci` or
|
||||
|
||||
+1
-3
@@ -1,3 +1 @@
|
||||
# These are commented until we enable lint and typecheck
|
||||
# npx tsc -p tsconfig.json --noEmit
|
||||
# npx lint-staged
|
||||
npx lint-staged
|
||||
|
||||
+19
-19
@@ -154,13 +154,13 @@ A "Pause Background Animations" toggle is exposed in **Settings → Appearance**
|
||||
|
||||
### Animation Improvements (June 2026)
|
||||
|
||||
All five animated backgrounds were rewritten for smoother, more organic motion:
|
||||
All five animated backgrounds were rewritten for smoother, more organic motion. Each background drives its own single drift/scroll keyframe (no secondary glow or blink layers):
|
||||
|
||||
- **Digital Rain** — added a phosphor glow flicker (`animRainGlowKeyframe`, 2.1 s) layered on top of the column scroll; stripe opacity increased for better visibility
|
||||
- **Digital Rain** — column scroll keyframe; stripe opacity increased for better visibility
|
||||
- **Star Drift** — each of the three dot layers now moves by exactly its own tile width/height per cycle (`−130 px`, `−190 px`, `−260 px`), eliminating the visible seam on loop
|
||||
- **Grid Pulse** — independent brightness oscillation (`animGridBrightnessKeyframe`, 3.3 s) runs alongside the size breathe (4 s) at a prime period ratio so they never synchronise
|
||||
- **Grid Pulse** — size breathe keyframe (4 s)
|
||||
- **Aurora Flow** — four gradient layers now have individual `backgroundSize` values (`200%`, `250%`, `300%`, `220%`); the keyframe drives each layer through a distinct 5-stop path, replacing the robotic single back-and-forth
|
||||
- **Fireflies** — glow pulse (`animFirefliesGlowKeyframe`, 2.3 s `filter: brightness`) and opacity blink (`animFirefliesBlinkKeyframe`, 1.7 s) added on top of the position drift; prime periods create unsynchronised bioluminescence
|
||||
- **Fireflies** — position drift keyframe with per-firefly duration/delay so motion stays unsynchronised
|
||||
|
||||
### Files
|
||||
|
||||
@@ -175,19 +175,19 @@ Decorative CSS-only overlays that activate automatically on holidays and events.
|
||||
|
||||
### Themes
|
||||
|
||||
| Theme | Window | Effect |
|
||||
| -------------------- | ------------- | -------------------------------------------------------------------------------------------------- |
|
||||
| 🎆 New Year | Dec 31–Jan 2 | Radial firework bursts in gold, red, cyan, purple; gold shimmer sweep |
|
||||
| 🏮 Lunar New Year | Jan 22–Feb 5 | Floating paper lanterns bobbing; silk texture; gold shimmer accent |
|
||||
| 💖 Valentine's Day | Feb 10–15 | ♥ hearts floating upward; soft pink ambient glow |
|
||||
| 🍀 St. Patrick's Day | Mar 15–18 | ☘ clovers drifting down; gold metallic shimmer top border |
|
||||
| 🃏 April Fool's | Apr 1 | Glitch overlay: RGB channel separation, hue-rotate spikes, scanline sweep, "SIGNAL LOST" watermark |
|
||||
| 🌱 Earth Day | Apr 20–23 | 🌿🍃 leaf emoji drift; sage green ambient tint; vine accent on left edge |
|
||||
| 🍂 Autumn | Sep 21–Oct 31 | Warm orange/amber leaf shapes rotating and falling |
|
||||
| 👾 Arcade Day | Sep 12 | CRT scanlines; blinking pixel corner decorations; "INSERT COIN" prompt |
|
||||
| 🚀 Deep Space Week | Oct 4–10 | Warp-speed star streaks radiating from screen centre; nebula purple/blue ambient |
|
||||
| 🎃 Halloween | Oct 15–Nov 1 | Purple and orange glowing particles; SVG spider web in top-left corner; dark purple tint |
|
||||
| ❄️ Christmas | Dec 10–Jan 2 | White dot snowfall in multiple layers at varied speeds |
|
||||
| Theme | Window | Effect |
|
||||
| -------------------- | ------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| 🎆 New Year | Dec 31–Jan 2 | Radial firework bursts in gold, red, cyan, purple; gold shimmer sweep |
|
||||
| 🏮 Lunar New Year | Jan 22–Feb 5 | Floating paper lanterns bobbing; silk texture; gold shimmer accent |
|
||||
| 💖 Valentine's Day | Feb 10–15 | ♥ hearts floating upward; soft pink ambient glow |
|
||||
| 🍀 St. Patrick's Day | Mar 15–18 | ☘ clovers drifting down; gold metallic shimmer top border |
|
||||
| 🃏 April Fool's | Apr 1 | Glitch overlay: RGB channel separation, hue-rotate spikes, scanline sweep, "SIGNAL LOST" watermark |
|
||||
| 🌱 Earth Day | Apr 20–23 | 🌿🍃 leaf emoji drift; sage green ambient tint; vine accent on left edge |
|
||||
| 🍂 Autumn | Sep 21–Oct 31 | Warm orange/amber leaf shapes rotating and falling |
|
||||
| 👾 Arcade Day | Sep 12 | Synthwave CRT: neon perspective grid framing the timeline (faded through the chat column), broken horizon line, rolling scanlines, pixel sparkles, bottom-right "1UP / INSERT COIN" HUD |
|
||||
| 🚀 Deep Space Week | Oct 4–10 | Violet void with drifting magenta/cyan nebula clouds, two-depth parallax starfield (~60 twinkling stars + 6 hero gleams), slow galaxy spiral, occasional comet streaks |
|
||||
| 🎃 Halloween | Oct 15–Nov 1 | Purple and orange glowing particles; SVG spider web in top-left corner; dark purple tint |
|
||||
| ❄️ Christmas | Dec 10–Jan 2 | White dot snowfall in multiple layers at varied speeds |
|
||||
|
||||
### Implementation
|
||||
|
||||
@@ -742,7 +742,7 @@ never leaves it.
|
||||
|
||||
### Message Search Date Range
|
||||
|
||||
- The search panel accepts `from_ts` and `to_ts` values (epoch milliseconds) passed to the search API
|
||||
- The search panel accepts `from_ts` and `to_ts` values (epoch milliseconds); server results are filtered client-side by `origin_server_ts` (they are not Matrix filter fields), matching the local encrypted-room search
|
||||
- A chip shows the active date range with an **×** button to clear it
|
||||
|
||||
### Encrypted Search Cache (P4-8, opt-in)
|
||||
@@ -1205,7 +1205,7 @@ Hook: `src/app/hooks/usePendingKnocks.ts`
|
||||
|
||||
### Room Emoji Prefix
|
||||
|
||||
A leading emoji in a room name is rendered at 1.15× size in the sidebar for visual hierarchy. An emoji picker button (😊) is added to all room name input fields, prepending the selected emoji to the room name.
|
||||
An emoji picker button (😊) is added to all room name input fields, prepending the selected emoji to the room name.
|
||||
|
||||
### Configurable Composer Toolbar (P3-6)
|
||||
|
||||
|
||||
+4
-2
@@ -372,9 +372,11 @@ Re-run `/_matrix/client/versions` + `unstable_features` after each Synapse upgra
|
||||
|
||||
### Element Call fork — operational reference
|
||||
|
||||
Fork = `LotusGuild/element-call` (branch `lotus`, from upstream tag `v0.20.1`); cinny consumes the npm package `@lotusguild/element-call-embedded` (built bundle copied into `public/element-call/`).
|
||||
Fork = `LotusGuild/element-call` (branch `lotus`, upstream base **v0.25.0** since the 2026-09 sync — was v0.20.1); cinny consumes the npm package `@lotusguild/element-call-embedded` (built bundle copied into `public/element-call/`).
|
||||
|
||||
**Publish a new version (manual; needs the Gitea npm token):** bump `embedded/web/package.json` (current unpublished `0.20.1-lotus.2`) → `pnpm run build:embedded` (Node 24, pnpm 10.33) → `cd embedded/web && npm version <tag> --no-git-tag-version && npm publish` (Gitea registry) → in cinny bump the `@lotusguild/element-call-embedded` pin (currently `0.20.1-lotus.1`) → `npm install` → build.
|
||||
**Toolchain (upstream-driven, accepted 2026-09):** Node ≥ 22.13 (`.node-version` = 24) and **pnpm 11**, installed directly (`npm i -g pnpm@<packageManager version>`, currently 11.21.0) — **not** via `corepack enable`: `matrix-js-sdk` is a git dependency pnpm builds from source, and its own devEngines pins pnpm 11.9.0; a corepack-shimmed pnpm refuses to switch for that nested install and `pnpm install` fails (fork CI run #1854). pnpm 10 rejects the lockfile and Node 20 cannot build. Lint is **oxlint + oxfmt** (upstream dropped eslint/prettier in v0.25.0): `pnpm lint` (tsc + oxlint + knip) and `pnpm format:check` / `pnpm format`. `matrix-js-sdk` is pinned to a `matrix-org/matrix-js-sdk#develop` commit in the lockfile, as upstream ships it. Fork CI (`.gitea/workflows/ci.yml`) hard-gates lint + format + `pnpm test:unit` before build, with `concurrency: cancel-in-progress`.
|
||||
|
||||
**Publish a new version (CI on tag push; needs the `GITEA_NPM_TOKEN` secret):** the published version is derived from the git tag — bump `embedded/web/package.json` (currently `0.25.0-lotus.1`, published by CI 2026-09-12 — the first CI publish; the secret is `NPM_PUBLISH_TOKEN`, names starting `GITEA_` are reserved), push `lotus`, then `git push lotus v0.25.0-lotus.1`; the `publish` job builds and publishes to the Gitea registry. Always push (never delete) the annotated `vX.Y.Z-lotus.N` tag for every published version. Then in cinny bump the `@lotusguild/element-call-embedded` pin (currently `0.25.0-lotus.1`) → `npm install` → build. Manual fallback: `pnpm run build:embedded && cd embedded/web && npm version <ver> --no-git-tag-version && npm publish`.
|
||||
|
||||
**`io.lotus.*` widget actions** (add new toWidget actions to the enum + `LOTUS_TO_WIDGET_ACTIONS` in `src/lotus/lotusActions.ts`; only send AFTER call-join or a 10s timeout fires):
|
||||
|
||||
|
||||
@@ -13,38 +13,7 @@ The source code is licensed under [AGPLv3](LICENSE), the same license as the ups
|
||||
The Lotus Chat logo (`public/res/Lotus.png`) is a derivative work based on the original Cinny logo by Ajay Bura and contributors, used under [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/). The modified logo is © Lotus Guild and is also made available under CC BY 4.0.
|
||||
|
||||
---
|
||||
## Development Environment Setup
|
||||
#### Getting correct Node version
|
||||
- Ensure you have the correct version of node installed, specified in `.node-version`
|
||||
- Use this command from the terminal to install nvm
|
||||
```bash
|
||||
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.3/install.sh | bash
|
||||
```
|
||||
- Reload your terminal shell using (for Ubuntu):
|
||||
```bash
|
||||
source ~/.bashrc
|
||||
```
|
||||
- Install the specified Node version
|
||||
```bash
|
||||
NODE_VERSION="$(tr -d '[:space:]' < .node-version)"
|
||||
nvm install "$NODE_VERSION"
|
||||
nvm use "$NODE_VERSION"
|
||||
```
|
||||
- verify the correct version was installed by running
|
||||
```bash
|
||||
node --version
|
||||
```
|
||||
and comparing the output to what is listed in `.node-version`
|
||||
#### Install npm packages
|
||||
- To install the npm packages listed in `package.json` run:
|
||||
```bash
|
||||
npm i
|
||||
```
|
||||
### Start Development Server
|
||||
```bash
|
||||
npm run start
|
||||
```
|
||||
You should now have an active development server at `localhost:8080`, where you can make changes to the code and see the UI update in real time
|
||||
|
||||
## Features
|
||||
|
||||
### Messaging
|
||||
@@ -53,7 +22,7 @@ You should now have an active development server at `localhost:8080`, where you
|
||||
- Slack-style thread notifications: by default you're only pinged for threads you're in or where you're @mentioned; set any thread to All / Mentions-only / Mute from the panel's bell menu (muted threads stop bumping badges; syncs across devices)
|
||||
- See who has read each message, and track delivery status (sending / sent / failed)
|
||||
- Bookmark any message and revisit saved messages from the sidebar
|
||||
- Schedule messages to send at a specific time
|
||||
- Schedule messages to send at a specific time (unencrypted rooms only — MSC4140 delayed events cannot be end-to-end encrypted, so the option is hidden in E2EE rooms)
|
||||
- Click "edited" on any message to see the full edit history
|
||||
- Drafts are saved automatically and survive page reloads
|
||||
- Long messages collapse automatically — click "Read more" to expand
|
||||
@@ -104,7 +73,6 @@ You should now have an active development server at `localhost:8080`, where you
|
||||
- Toggle to pause background animations
|
||||
- Glassmorphism sidebar — frosted glass effect that lets the background show through
|
||||
- Night Light / blue light filter with an adjustable intensity slider
|
||||
- Emoji prefixes on room names render larger in the sidebar (e.g. 🎮 general)
|
||||
- Rename any room for yourself only — other members see the original name
|
||||
- Emoji picker on all room name inputs
|
||||
|
||||
@@ -160,7 +128,16 @@ Lotus Chat has a desktop app for Windows, macOS, and Linux. It wraps the same we
|
||||
|
||||
### Download
|
||||
|
||||
Download the latest release from the [Releases page on code.lotusguild.org](https://code.lotusguild.org).
|
||||
Operating System | Download
|
||||
---|---
|
||||
Windows | [Get the installer (.exe)](https://code.lotusguild.org/LotusGuild/cinny-desktop/releases/download/latest/LotusChat-x86_64-setup.exe)
|
||||
Linux (AppImage, any distro) | [Get the AppImage](https://code.lotusguild.org/LotusGuild/cinny-desktop/releases/download/latest/LotusChat-x86_64.AppImage)
|
||||
Linux (Debian/Ubuntu) | [Get the .deb](https://code.lotusguild.org/LotusGuild/cinny-desktop/releases/download/latest/LotusChat-x86_64.deb)
|
||||
Linux (Arch/CachyOS/EndeavourOS) | [Get the .pkg.tar.zst](https://code.lotusguild.org/LotusGuild/cinny-desktop/releases/download/latest/LotusChat-x86_64.pkg.tar.zst) — install with `pacman -U LotusChat-x86_64.pkg.tar.zst`
|
||||
|
||||
All Linux builds need `webkit2gtk-4.1` and, for calls to work, GStreamer's `good`/`bad`/`ugly`/`libav` plugin sets (the pacman package pulls these in automatically; on the AppImage/.deb, install them via your package manager if joining a call shows "browser does not support WebRTC").
|
||||
|
||||
See the full [Releases page on code.lotusguild.org](https://code.lotusguild.org/LotusGuild/cinny-desktop/releases) for signatures and older builds.
|
||||
|
||||
### SmartScreen Warning (Windows)
|
||||
|
||||
@@ -218,7 +195,7 @@ The dev server defaults to **port 8080** (`vite.config.js`); if 8080 is already
|
||||
### 🔱 Element Call fork ("Lotus Call") — LIVE
|
||||
|
||||
Voice/video channels embed **Element Call**, which is now our **self-built fork**
|
||||
(`@lotusguild/element-call-embedded` `0.20.1-lotus.1`, source at
|
||||
(`@lotusguild/element-call-embedded` `0.25.0-lotus.1`, upstream base v0.25.0, source at
|
||||
`LotusGuild/element-call`), published to our private Gitea npm registry and served
|
||||
same-origin. We no longer depend on the upstream prebuilt bundle, so in-call
|
||||
behavior is editable source instead of fragile DOM/widget hacks.
|
||||
|
||||
+3
-3
@@ -4,9 +4,9 @@
|
||||
"allowCustomHomeservers": true,
|
||||
"featuredCommunities": {
|
||||
"openAsDefault": false,
|
||||
"spaces": [],
|
||||
"rooms": [],
|
||||
"servers": []
|
||||
"spaces": ["!-1ZBnAH-JiCOV8MGSKN77zDGTuI3pgSdy8Unu_DrDyc", "#homelab:codestorm.net"],
|
||||
"rooms": ["#jellyfin:matrix.org"],
|
||||
"servers": ["matrixrooms.info"]
|
||||
},
|
||||
"hashRouter": {
|
||||
"enabled": false,
|
||||
|
||||
+1
-1
@@ -109,7 +109,7 @@ export default [
|
||||
{ argsIgnorePattern: '^_', varsIgnorePattern: '^_', caughtErrorsIgnorePattern: '^_' },
|
||||
],
|
||||
'@typescript-eslint/no-shadow': 'error',
|
||||
'@typescript-eslint/no-explicit-any': 'off',
|
||||
'@typescript-eslint/no-explicit-any': 'warn',
|
||||
|
||||
// jsx-a11y — media captions not required for this app
|
||||
'jsx-a11y/media-has-caption': 'off',
|
||||
|
||||
Generated
+432
-414
File diff suppressed because it is too large
Load Diff
+17
-14
@@ -1,23 +1,24 @@
|
||||
{
|
||||
"name": "lotus-chat",
|
||||
"version": "4.12.3-lotus",
|
||||
"description": "Lotus Chat — Matrix client for Lotus Guild",
|
||||
"description": "Lotus Chat \u2014 Matrix client for Lotus Guild",
|
||||
"main": "index.js",
|
||||
"type": "module",
|
||||
"engines": {
|
||||
"node": ">=16.0.0"
|
||||
"node": ">=20.0.0"
|
||||
},
|
||||
"scripts": {
|
||||
"start": "vite",
|
||||
"build": "vite build",
|
||||
"preview": "vite preview",
|
||||
"lint": "npm run check:eslint && npm run check:prettier",
|
||||
"check:eslint": "eslint \"src/**/*.{js,jsx,ts,tsx}\"",
|
||||
"check:eslint": "eslint src/* --max-warnings 68",
|
||||
"check:prettier": "prettier --check .",
|
||||
"fix:prettier": "prettier --write .",
|
||||
"typecheck": "tsc --noEmit",
|
||||
"test": "node --import tsx --test $(find src -name '*.test.ts')",
|
||||
"prepare": "husky",
|
||||
"commit": "git-cz",
|
||||
"postinstall": "node scripts/patch-folds.mjs",
|
||||
"sync:decorations": "node scripts/syncDecorations.mjs"
|
||||
},
|
||||
@@ -25,6 +26,11 @@
|
||||
"*.{ts,tsx,js,jsx}": "eslint",
|
||||
"*": "prettier --ignore-unknown --write"
|
||||
},
|
||||
"config": {
|
||||
"commitizen": {
|
||||
"path": "./node_modules/cz-conventional-changelog"
|
||||
}
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "Ajay Bura",
|
||||
"license": "AGPL-3.0-only",
|
||||
@@ -37,7 +43,7 @@
|
||||
"@fontsource-variable/inter": "5.2.8",
|
||||
"@giphy/js-fetch-api": "5.8.0",
|
||||
"@giphy/js-types": "5.1.0",
|
||||
"@giphy/js-util": "2.0.0",
|
||||
"@giphy/js-util": "5.2.0",
|
||||
"@giphy/react-components": "10.1.2",
|
||||
"@sapphi-red/web-noise-suppressor": "0.3.5",
|
||||
"@tanstack/react-query": "5.100.13",
|
||||
@@ -69,13 +75,13 @@
|
||||
"is-hotkey": "0.2.0",
|
||||
"jotai": "2.20.0",
|
||||
"jsqr": "1.4.0",
|
||||
"katex": "0.16.11",
|
||||
"katex": "0.16.47",
|
||||
"linkify-react": "4.3.3",
|
||||
"linkifyjs": "4.3.3",
|
||||
"matrix-js-sdk": "41.7.0",
|
||||
"matrix-widget-api": "1.17.0",
|
||||
"millify": "6.1.0",
|
||||
"pdfjs-dist": "5.7.284",
|
||||
"pdfjs-dist": "6.3.289",
|
||||
"prismjs": "1.30.0",
|
||||
"qrcode": "1.5.4",
|
||||
"qrcode.react": "4.2.0",
|
||||
@@ -88,8 +94,8 @@
|
||||
"react-google-recaptcha": "3.1.0",
|
||||
"react-i18next": "17.0.8",
|
||||
"react-range": "1.10.0",
|
||||
"react-router-dom": "7.15.1",
|
||||
"sanitize-html": "2.17.6",
|
||||
"react-router-dom": "7.18.3",
|
||||
"sanitize-html": "2.17.7",
|
||||
"slate": "0.124.1",
|
||||
"slate-dom": "0.124.1",
|
||||
"slate-history": "0.113.1",
|
||||
@@ -99,7 +105,7 @@
|
||||
"workbox-precaching": "7.4.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@lotusguild/element-call-embedded": "0.20.1-lotus.1",
|
||||
"@lotusguild/element-call-embedded": "0.25.0-lotus.1",
|
||||
"@rollup/plugin-inject": "5.0.5",
|
||||
"@rollup/plugin-wasm": "6.2.2",
|
||||
"@types/chroma-js": "3.1.2",
|
||||
@@ -124,7 +130,6 @@
|
||||
"cz-conventional-changelog": "3.3.0",
|
||||
"eslint": "9.39.4",
|
||||
"eslint-config-airbnb": "19.0.4",
|
||||
"eslint-config-airbnb-base": "15.0.0",
|
||||
"eslint-config-prettier": "10.1.8",
|
||||
"eslint-plugin-import": "2.32.0",
|
||||
"eslint-plugin-jsx-a11y": "6.10.2",
|
||||
@@ -141,11 +146,9 @@
|
||||
},
|
||||
"overrides": {
|
||||
"@giphy/js-util": {
|
||||
"dompurify": ">=3.3.4"
|
||||
"dompurify": ">=3.3.4",
|
||||
"uuid": ">=11.1.1"
|
||||
},
|
||||
"js-cookie": ">=3.0.6"
|
||||
},
|
||||
"allowScripts": {
|
||||
"esbuild@0.28.1": true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,148 @@
|
||||
#!/usr/bin/env node
|
||||
// Boot-check (Gitea #92): after `npm run build`, nothing actually loaded the
|
||||
// built dist/ — a build that produces a broken bundle (bad base path, a 500
|
||||
// from an asset, a malformed config.json) still went green. This script
|
||||
// serves dist/ the same way production does (vite preview) and makes a
|
||||
// handful of real HTTP requests against it, so a broken bundle fails CI
|
||||
// instead of surfacing after deploy.
|
||||
//
|
||||
// No Playwright here: playwright-core is not a project dependency (only the
|
||||
// browser binary caches happen to be present on this machine), so we don't
|
||||
// depend on it being installed. Plain fetch is enough to catch the class of
|
||||
// bug this check exists for — a page/asset/config that doesn't come back.
|
||||
import { spawn } from 'node:child_process';
|
||||
|
||||
const PORT = 4173;
|
||||
const HOST = '127.0.0.1';
|
||||
const BASE_URL = `http://${HOST}:${PORT}`;
|
||||
const BOOT_TIMEOUT_MS = 30_000;
|
||||
|
||||
function log(msg) {
|
||||
console.log(`[boot-check] ${msg}`);
|
||||
}
|
||||
|
||||
function waitForPort(url, timeoutMs) {
|
||||
const deadline = Date.now() + timeoutMs;
|
||||
const attempt = async () => {
|
||||
try {
|
||||
const res = await fetch(url, { method: 'GET' });
|
||||
return res;
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
return new Promise((resolve, reject) => {
|
||||
const poll = async () => {
|
||||
const res = await attempt();
|
||||
if (res) {
|
||||
resolve();
|
||||
return;
|
||||
}
|
||||
if (Date.now() > deadline) {
|
||||
reject(new Error(`Timed out waiting for ${url} to come up`));
|
||||
return;
|
||||
}
|
||||
setTimeout(poll, 300);
|
||||
};
|
||||
poll();
|
||||
});
|
||||
}
|
||||
|
||||
async function assert(condition, message) {
|
||||
if (!condition) {
|
||||
throw new Error(`Assertion failed: ${message}`);
|
||||
}
|
||||
log(`ok: ${message}`);
|
||||
}
|
||||
|
||||
async function main() {
|
||||
const preview = spawn(
|
||||
'npx',
|
||||
['vite', 'preview', '--port', String(PORT), '--strictPort', '--host', HOST],
|
||||
{ stdio: ['ignore', 'pipe', 'pipe'] },
|
||||
);
|
||||
|
||||
let previewOutput = '';
|
||||
preview.stdout.on('data', (d) => (previewOutput += d.toString()));
|
||||
preview.stderr.on('data', (d) => (previewOutput += d.toString()));
|
||||
|
||||
const cleanup = () => {
|
||||
if (!preview.killed) {
|
||||
preview.kill('SIGTERM');
|
||||
}
|
||||
};
|
||||
process.on('exit', cleanup);
|
||||
process.on('SIGINT', () => {
|
||||
cleanup();
|
||||
process.exit(1);
|
||||
});
|
||||
process.on('SIGTERM', () => {
|
||||
cleanup();
|
||||
process.exit(1);
|
||||
});
|
||||
|
||||
try {
|
||||
await waitForPort(BASE_URL, BOOT_TIMEOUT_MS);
|
||||
|
||||
// 1. index page loads and contains the SPA mount point.
|
||||
const indexRes = await fetch(`${BASE_URL}/`);
|
||||
await assert(indexRes.status === 200, `GET / returns 200 (got ${indexRes.status})`);
|
||||
const indexHtml = await indexRes.text();
|
||||
await assert(indexHtml.includes('<div id="root"'), 'GET / contains <div id="root"');
|
||||
|
||||
// 2. runtime config is valid JSON.
|
||||
const configRes = await fetch(`${BASE_URL}/config.json`);
|
||||
await assert(
|
||||
configRes.status === 200,
|
||||
`GET /config.json returns 200 (got ${configRes.status})`,
|
||||
);
|
||||
const configText = await configRes.text();
|
||||
let configJson;
|
||||
try {
|
||||
configJson = JSON.parse(configText);
|
||||
} catch (err) {
|
||||
throw new Error(`GET /config.json is not valid JSON: ${err.message}`);
|
||||
}
|
||||
await assert(
|
||||
typeof configJson === 'object' && configJson !== null,
|
||||
'/config.json parses to an object',
|
||||
);
|
||||
|
||||
// 3. the main JS entry referenced from index.html actually loads.
|
||||
const scriptMatch = indexHtml.match(/<script[^>]+type="module"[^>]+src="([^"]+)"/);
|
||||
await assert(!!scriptMatch, 'index.html references a module script entry');
|
||||
const mainScriptUrl = new URL(scriptMatch[1], BASE_URL).toString();
|
||||
const scriptRes = await fetch(mainScriptUrl);
|
||||
await assert(
|
||||
scriptRes.status === 200,
|
||||
`GET ${scriptMatch[1]} returns 200 (got ${scriptRes.status})`,
|
||||
);
|
||||
const scriptContentType = scriptRes.headers.get('content-type') || '';
|
||||
await assert(
|
||||
/javascript/.test(scriptContentType),
|
||||
`GET ${scriptMatch[1]} has a JS content-type (got "${scriptContentType}")`,
|
||||
);
|
||||
|
||||
// 4. Element Call widget bundle is present.
|
||||
const callRes = await fetch(`${BASE_URL}/public/element-call/index.html`);
|
||||
await assert(
|
||||
callRes.status === 200,
|
||||
`GET /public/element-call/index.html returns 200 (got ${callRes.status})`,
|
||||
);
|
||||
|
||||
log('all checks passed');
|
||||
} finally {
|
||||
cleanup();
|
||||
}
|
||||
}
|
||||
|
||||
main()
|
||||
.catch((err) => {
|
||||
console.error(`[boot-check] FAILED: ${err.message}`);
|
||||
process.exitCode = 1;
|
||||
})
|
||||
.finally(() => {
|
||||
// The killed preview server's stdio pipes can keep the event loop alive
|
||||
// briefly; force the process down promptly with whatever exit code was set.
|
||||
process.exit(process.exitCode ?? 0);
|
||||
});
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"$comment": "Gitea #96. Budgets are seeded from the dist/assets gzip sizes on the tree at seed time, +10% headroom. Regenerate deliberately (not just to silence a failure) when a real feature addition grows the bundle: measure the new gzip sizes and bump these with the same +10% margin.",
|
||||
"totalGzipBytes": 1731120,
|
||||
"largestChunkGzipBytes": 358317
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
#!/usr/bin/env node
|
||||
// Bundle size budget (Gitea #96). The CI "Report bundle sizes" step printed
|
||||
// numbers with nothing to compare them against, so a bundle could balloon
|
||||
// silently. This script compares dist/assets gzip sizes against a small
|
||||
// checked-in budget (scripts/bundle-budget.json) and prints the same report.
|
||||
//
|
||||
// Mode is passed via argv: `pull_request` fails the build over budget,
|
||||
// anything else (e.g. `push`) only warns — a push has already merged, so
|
||||
// blocking it can't prevent the regression, only delay the deploy of an
|
||||
// otherwise-good commit; the pull_request gate is where this should be caught.
|
||||
import { appendFileSync, readFileSync, readdirSync, statSync } from 'node:fs';
|
||||
import { gzipSync } from 'node:zlib';
|
||||
import path from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
|
||||
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
||||
const mode = process.argv[2] || 'push';
|
||||
const distAssetsDir = path.join(__dirname, '..', 'dist', 'assets');
|
||||
const budgetPath = path.join(__dirname, 'bundle-budget.json');
|
||||
|
||||
function formatKb(bytes) {
|
||||
return `${(bytes / 1024).toFixed(1)} kB`;
|
||||
}
|
||||
|
||||
function main() {
|
||||
const budget = JSON.parse(readFileSync(budgetPath, 'utf-8'));
|
||||
|
||||
const jsFiles = readdirSync(distAssetsDir)
|
||||
.filter((f) => f.endsWith('.js') && !f.endsWith('.map'))
|
||||
.sort();
|
||||
|
||||
if (jsFiles.length === 0) {
|
||||
console.error(
|
||||
`[check-bundle-size] No .js files found in ${distAssetsDir} — did the build run?`,
|
||||
);
|
||||
process.exitCode = 1;
|
||||
return;
|
||||
}
|
||||
|
||||
const rows = jsFiles.map((name) => {
|
||||
const filePath = path.join(distAssetsDir, name);
|
||||
const size = statSync(filePath).size;
|
||||
const gzipSize = gzipSync(readFileSync(filePath)).length;
|
||||
return { name, size, gzipSize };
|
||||
});
|
||||
|
||||
const totalGzipBytes = rows.reduce((sum, r) => sum + r.gzipSize, 0);
|
||||
const largest = rows.reduce((max, r) => (r.gzipSize > max.gzipSize ? r : max), rows[0]);
|
||||
|
||||
const summaryLines = [
|
||||
'### Bundle sizes',
|
||||
'',
|
||||
'| File | Size | Gzip |',
|
||||
'|------|------|------|',
|
||||
...rows.map((r) => `| ${r.name} | ${formatKb(r.size)} | ${formatKb(r.gzipSize)} |`),
|
||||
'',
|
||||
`**Total gzip:** ${formatKb(totalGzipBytes)} (budget ${formatKb(budget.totalGzipBytes)})`,
|
||||
`**Largest chunk gzip:** ${largest.name} — ${formatKb(largest.gzipSize)} (budget ${formatKb(
|
||||
budget.largestChunkGzipBytes,
|
||||
)})`,
|
||||
];
|
||||
|
||||
const summaryText = summaryLines.join('\n');
|
||||
console.log(summaryText);
|
||||
if (process.env.GITHUB_STEP_SUMMARY) {
|
||||
// Gitea Actions/act_runner honors the same GITHUB_STEP_SUMMARY convention.
|
||||
appendFileSync(process.env.GITHUB_STEP_SUMMARY, `${summaryText}\n`);
|
||||
}
|
||||
|
||||
const overBudget = [];
|
||||
if (totalGzipBytes > budget.totalGzipBytes) {
|
||||
overBudget.push(
|
||||
`total gzip ${formatKb(totalGzipBytes)} exceeds budget ${formatKb(budget.totalGzipBytes)}`,
|
||||
);
|
||||
}
|
||||
if (largest.gzipSize > budget.largestChunkGzipBytes) {
|
||||
overBudget.push(
|
||||
`largest chunk (${largest.name}) gzip ${formatKb(largest.gzipSize)} exceeds budget ${formatKb(
|
||||
budget.largestChunkGzipBytes,
|
||||
)}`,
|
||||
);
|
||||
}
|
||||
|
||||
if (overBudget.length > 0) {
|
||||
const message = `[check-bundle-size] Over budget: ${overBudget.join('; ')}`;
|
||||
if (mode === 'pull_request') {
|
||||
console.error(message);
|
||||
process.exitCode = 1;
|
||||
} else {
|
||||
console.warn(`${message} (warning only on "${mode}")`);
|
||||
}
|
||||
} else {
|
||||
console.log('[check-bundle-size] Within budget.');
|
||||
}
|
||||
}
|
||||
|
||||
main();
|
||||
@@ -45,6 +45,8 @@ import { useMatrixClient } from '../hooks/useMatrixClient';
|
||||
import { previewRingtone, startRingtone, unlockRingtoneAudio } from '../utils/ringtones';
|
||||
import { useCallMembersChange, useCallSession } from '../hooks/useCall';
|
||||
import { useCallJoinLeaveSounds } from '../hooks/useCallJoinLeaveSounds';
|
||||
import { useCallHotkeys } from '../hooks/useCallHotkeys';
|
||||
import { useAfkAutoMute } from '../hooks/useAfkAutoMute';
|
||||
import { useCallQuality } from '../hooks/useCallQuality';
|
||||
import { useRemoteAllMuted } from '../hooks/useCallSpeakers';
|
||||
import { useRoomAvatar, useRoomName } from '../hooks/useRoomMeta';
|
||||
@@ -58,6 +60,7 @@ import { ExitFullscreenIcon, FullscreenIcon } from '../features/call/Controls';
|
||||
import { useTheme, ThemeKind } from '../hooks/useTheme';
|
||||
import { useReducedMotion } from '../hooks/useReducedMotion';
|
||||
import { useSetting } from '../state/hooks/settings';
|
||||
import { useCallPreferences } from '../state/hooks/callPreferences';
|
||||
import { settingsAtom } from '../state/settings';
|
||||
import { getStateEvent, getStateEvents, getMemberName } from '../utils/room';
|
||||
import { StateEvent } from '../../types/matrix/room';
|
||||
@@ -410,6 +413,8 @@ function IncomingCallListener({ callEmbed, joined }: IncomingCallListenerProps)
|
||||
const [callInfo, setCallInfo] = useState<IncomingCallInfo>();
|
||||
const dm = callInfo ? directs.has(callInfo.room.roomId) : false;
|
||||
const startCall = useCallStart(dm);
|
||||
const { microphone, sound } = useCallPreferences();
|
||||
const [cameraOnJoin] = useSetting(settingsAtom, 'cameraOnJoin');
|
||||
|
||||
// C-L6: handleTimelineEvent awaits decryption before calling setState; guard
|
||||
// against the component unmounting during that await.
|
||||
@@ -566,11 +571,15 @@ function IncomingCallListener({ callEmbed, joined }: IncomingCallListenerProps)
|
||||
|
||||
const handleAnswer = useCallback(
|
||||
(room: Room, video: boolean) => {
|
||||
startCall(room, { microphone: true, video, sound: true });
|
||||
// Honour cameraOnJoin and the persisted mic/sound preferences instead of
|
||||
// forcing camera+mic+sound on — every other join path does this, and
|
||||
// Answer was skipping it, publishing the camera with no prescreen.
|
||||
// (PTT's forceAudioOff is applied downstream inside useCallStart.)
|
||||
startCall(room, { microphone, video: cameraOnJoin && video, sound });
|
||||
setCallInfo(undefined);
|
||||
navigateRoom(room.roomId);
|
||||
},
|
||||
[startCall, navigateRoom],
|
||||
[startCall, navigateRoom, microphone, sound, cameraOnJoin],
|
||||
);
|
||||
|
||||
if (!callInfo) return null;
|
||||
@@ -602,9 +611,15 @@ function IncomingCallListener({ callEmbed, joined }: IncomingCallListenerProps)
|
||||
);
|
||||
}
|
||||
|
||||
function CallUtils({ embed }: { embed: CallEmbed }) {
|
||||
function CallUtils({ embed, joined }: { embed: CallEmbed; joined: boolean }) {
|
||||
const setCallEmbed = useSetAtom(callEmbedAtom);
|
||||
|
||||
// [Gitea #9] PTT/deafen hotkeys and AFK auto-mute are bound here, for the
|
||||
// embed's whole lifetime, rather than in CallControls (which only renders
|
||||
// while the call room is selected) — so they keep working in PiP and behind
|
||||
// the mobile in-call chat. Both are gated on `joined`.
|
||||
useCallHotkeys(embed, joined);
|
||||
useAfkAutoMute(joined ? embed : undefined);
|
||||
useCallMemberSoundSync(embed);
|
||||
useCallJoinLeaveSounds(embed);
|
||||
useCallThemeSync(embed);
|
||||
@@ -616,6 +631,22 @@ function CallUtils({ embed }: { embed: CallEmbed }) {
|
||||
}, [setCallEmbed]),
|
||||
);
|
||||
|
||||
// [Gitea #58] Warn before an accidental tab close/reload drops the user out
|
||||
// of a live call. Only armed while actually joined, and torn down on
|
||||
// hangup/dispose since this effect re-runs when `joined` flips back to false.
|
||||
useEffect(() => {
|
||||
if (!joined) return undefined;
|
||||
const onBeforeUnload = (event: BeforeUnloadEvent) => {
|
||||
event.preventDefault();
|
||||
// Legacy browsers require returnValue to be set to show the prompt.
|
||||
event.returnValue = '';
|
||||
};
|
||||
window.addEventListener('beforeunload', onBeforeUnload);
|
||||
return () => {
|
||||
window.removeEventListener('beforeunload', onBeforeUnload);
|
||||
};
|
||||
}, [joined]);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -720,12 +751,6 @@ export function CallEmbedProvider({ children }: CallEmbedProviderProps) {
|
||||
};
|
||||
}, []);
|
||||
|
||||
// Sync pip mode into CallControl so it can adjust behavior accordingly
|
||||
useEffect(() => {
|
||||
if (!callEmbed) return;
|
||||
callEmbed.control.setPipMode(!!pipMode);
|
||||
}, [pipMode, callEmbed]);
|
||||
|
||||
// When entering pip with screenshare active (or screenshare starts while in pip),
|
||||
// enable spotlight so the screenshare fills the pip window.
|
||||
// When screenshare ends, release the spotlight we auto-enabled.
|
||||
@@ -1139,7 +1164,7 @@ export function CallEmbedProvider({ children }: CallEmbedProviderProps) {
|
||||
|
||||
return (
|
||||
<CallEmbedContextProvider value={callEmbed}>
|
||||
{callEmbed && <CallUtils embed={callEmbed} />}
|
||||
{callEmbed && <CallUtils embed={callEmbed} joined={joined} />}
|
||||
<CallEmbedRefContextProvider value={callEmbedRef}>
|
||||
<IncomingCallListener callEmbed={callEmbed} joined={joined} />
|
||||
{children}
|
||||
|
||||
@@ -209,6 +209,13 @@ type GifPickerProps = {
|
||||
|
||||
export function GifPicker({ apiKey, onSelect, requestClose }: GifPickerProps) {
|
||||
const [lotusTerminal] = useSetting(settingsAtom, 'lotusTerminal');
|
||||
const [gifPickerEnabled] = useSetting(settingsAtom, 'gifPickerEnabled');
|
||||
|
||||
// Searches (and every keystroke) go straight to Giphy's API, so the picker
|
||||
// is opt-in (Settings → Messages) and must not render or fetch until then.
|
||||
if (!gifPickerEnabled) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const containerStyle = lotusTerminal
|
||||
? {
|
||||
|
||||
@@ -21,12 +21,31 @@ type KaTeXProps = {
|
||||
* inline (in its error colour) rather than throwing. The HTML returned by
|
||||
* `renderToString` is produced by our own trusted call from a fixed options
|
||||
* object — it is safe to inject via `dangerouslySetInnerHTML`.
|
||||
*
|
||||
* `maxSize`/`maxExpand` cap how large a single glyph (`\\rule`, etc.) or macro
|
||||
* expansion remote LaTeX can request, and `trust: false` disables commands
|
||||
* that can embed arbitrary HTML/URLs (e.g. `\\includegraphics`, `\\href`) —
|
||||
* without these a hostile `$$...$$` from a remote message can DoS or (via
|
||||
* `trust`) inject unsafe links (Gitea #65). `strict: 'ignore'` keeps unknown-
|
||||
* but-harmless LaTeX from spamming the console as before. Extremely long
|
||||
* source is rendered as plain text rather than handed to KaTeX at all.
|
||||
*/
|
||||
const MAX_LATEX_LENGTH = 5000;
|
||||
|
||||
export default function KaTeX({ latex, displayMode = false }: KaTeXProps) {
|
||||
if (latex.length > MAX_LATEX_LENGTH) {
|
||||
const Plain = displayMode ? 'div' : 'span';
|
||||
return <Plain>{latex}</Plain>;
|
||||
}
|
||||
|
||||
const html = katex.renderToString(latex, {
|
||||
displayMode,
|
||||
throwOnError: false,
|
||||
output: 'htmlAndMathml',
|
||||
maxSize: 10,
|
||||
maxExpand: 100,
|
||||
trust: false,
|
||||
strict: 'ignore',
|
||||
});
|
||||
|
||||
const Wrapper = displayMode ? 'div' : 'span';
|
||||
@@ -34,6 +53,7 @@ export default function KaTeX({ latex, displayMode = false }: KaTeXProps) {
|
||||
return (
|
||||
<Wrapper
|
||||
// KaTeX output is generated by our own render call (trusted-safe).
|
||||
|
||||
dangerouslySetInnerHTML={{ __html: html }}
|
||||
/>
|
||||
);
|
||||
|
||||
@@ -15,6 +15,7 @@ import {
|
||||
MessageVerificationRequestContent,
|
||||
} from './content';
|
||||
import { useMessageTranslation } from '../../hooks/useMessageTranslation';
|
||||
import { useReducedMotion } from '../../hooks/useReducedMotion';
|
||||
import { languageName } from '../../utils/translation/langUtils';
|
||||
import {
|
||||
IAudioContent,
|
||||
@@ -62,8 +63,9 @@ function CollapsibleBody({ eventId, children }: CollapsibleBodyProps) {
|
||||
return () => observer.disconnect();
|
||||
}, []);
|
||||
|
||||
const prefersReducedMotion =
|
||||
typeof window !== 'undefined' && window.matchMedia('(prefers-reduced-motion: reduce)').matches;
|
||||
// A one-time matchMedia() read never updated if the OS setting changed mid-session
|
||||
// (Gitea #85); useReducedMotion subscribes to the change event instead.
|
||||
const prefersReducedMotion = useReducedMotion();
|
||||
|
||||
return (
|
||||
<div>
|
||||
@@ -633,6 +635,13 @@ type MLocationProps = {
|
||||
};
|
||||
export function MLocation({ content }: MLocationProps) {
|
||||
const { t } = useTranslation();
|
||||
// The OpenStreetMap iframe used to mount unconditionally on render, silently
|
||||
// handing the sender's coordinates (and this client's IP/UA) to
|
||||
// openstreetmap.org for every location message rendered, autoplay or not.
|
||||
// Gate it behind an explicit click instead (Gitea #66). There's no
|
||||
// location-specific auto-load setting in settings.ts to opt back into this,
|
||||
// so it always requires a click.
|
||||
const [mapLoaded, setMapLoaded] = useState(false);
|
||||
// Prefer the legacy top-level geo_uri, but fall back to the MSC3488 extensible
|
||||
// location block so events from clients that only send the new shape (uri under
|
||||
// org.matrix.msc3488.location / m.location) still render instead of appearing
|
||||
@@ -660,20 +669,33 @@ export function MLocation({ content }: MLocationProps) {
|
||||
|
||||
return (
|
||||
<Box direction="Column" alignItems="Start" gap="200">
|
||||
<iframe
|
||||
title="Location"
|
||||
src={mapSrc}
|
||||
style={{
|
||||
width: '280px',
|
||||
height: '160px',
|
||||
border: `${config.borderWidth.B300} solid ${color.SurfaceVariant.ContainerLine}`,
|
||||
borderRadius: '8px',
|
||||
display: 'block',
|
||||
}}
|
||||
scrolling="no"
|
||||
loading="lazy"
|
||||
sandbox="allow-scripts"
|
||||
/>
|
||||
{mapLoaded ? (
|
||||
<iframe
|
||||
title="Location"
|
||||
src={mapSrc}
|
||||
style={{
|
||||
width: '280px',
|
||||
height: '160px',
|
||||
border: `${config.borderWidth.B300} solid ${color.SurfaceVariant.ContainerLine}`,
|
||||
borderRadius: '8px',
|
||||
display: 'block',
|
||||
}}
|
||||
scrolling="no"
|
||||
loading="lazy"
|
||||
sandbox="allow-scripts"
|
||||
/>
|
||||
) : (
|
||||
<Button
|
||||
size="400"
|
||||
radii="300"
|
||||
variant="Secondary"
|
||||
fill="Soft"
|
||||
onClick={() => setMapLoaded(true)}
|
||||
before={<Icon src={Icons.Pin} size="50" />}
|
||||
>
|
||||
<Text size="B300">{t('Organisms.Message.load_map', 'Load map')}</Text>
|
||||
</Button>
|
||||
)}
|
||||
{description && (
|
||||
<Text size="T300" style={{ wordBreak: 'break-word', maxWidth: '280px' }}>
|
||||
{description}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
import React, { KeyboardEvent, useCallback, useEffect, useMemo, useState } from 'react';
|
||||
import { Box, Chip, color, config, Icon, Icons, Text, toRem } from 'folds';
|
||||
import { RelationsEvent } from 'matrix-js-sdk/lib/models/relations';
|
||||
|
||||
@@ -84,7 +84,15 @@ export function SeasonalPreview({ theme }: { theme: SeasonTheme }) {
|
||||
return (
|
||||
<div
|
||||
aria-hidden="true"
|
||||
style={{ position: 'absolute', inset: 0, overflow: 'hidden', pointerEvents: 'none' }}
|
||||
style={{
|
||||
position: 'absolute',
|
||||
inset: 0,
|
||||
overflow: 'hidden',
|
||||
pointerEvents: 'none',
|
||||
// Size container so overlays can scale/hide fixed-size details (e.g.
|
||||
// Arcade's HUD text) with `cqw` instead of rendering clipped in a swatch.
|
||||
containerType: 'inline-size',
|
||||
}}
|
||||
>
|
||||
{buildOverlayContent(theme, true)}
|
||||
</div>
|
||||
|
||||
@@ -102,12 +102,12 @@ export const animSparkleTwinkle = keyframes({
|
||||
* Opacity + a hair of scale for a CRT bloom feel.
|
||||
*/
|
||||
export const animCoinBlink = keyframes({
|
||||
'0%': { opacity: '0.85', transform: 'translateX(-50%) scale(1)' },
|
||||
'6%': { opacity: '1', transform: 'translateX(-50%) scale(1.015)' },
|
||||
'12%': { opacity: '0.85', transform: 'translateX(-50%) scale(1)' },
|
||||
'49%': { opacity: '0.85', transform: 'translateX(-50%) scale(1)' },
|
||||
'50%': { opacity: '0', transform: 'translateX(-50%) scale(1)' },
|
||||
'100%': { opacity: '0', transform: 'translateX(-50%) scale(1)' },
|
||||
'0%': { opacity: '0.85', transform: 'scale(1)' },
|
||||
'6%': { opacity: '1', transform: 'scale(1.015)' },
|
||||
'12%': { opacity: '0.85', transform: 'scale(1)' },
|
||||
'49%': { opacity: '0.85', transform: 'scale(1)' },
|
||||
'50%': { opacity: '0', transform: 'scale(1)' },
|
||||
'100%': { opacity: '0', transform: 'scale(1)' },
|
||||
});
|
||||
|
||||
/**
|
||||
|
||||
@@ -46,6 +46,10 @@ const NEON_CYAN = 'oklch(0.80 0.15 200)';
|
||||
const GRID_PURPLE = 'oklch(0.45 0.18 300)';
|
||||
|
||||
// The receding grid as an inline SVG data-URI (CSP-safe, no external assets).
|
||||
// Strokes use vector-effect=non-scaling-stroke so a line is ~1px whether the
|
||||
// tile is stretched across a 2000px plane (preserveAspectRatio=none would
|
||||
// otherwise fatten the verticals ~4x) or squeezed into the 76px settings
|
||||
// swatch (where scaled strokes disappeared entirely).
|
||||
// It is a 1x2 vertical tile of horizontal rule lines + a single set of vertical
|
||||
// lines fanning toward a top-center vanishing point. The plane is then placed
|
||||
// under a CSS `perspective` rotateX so the lines genuinely recede. Scrolling the
|
||||
@@ -58,7 +62,7 @@ function gridDataUri(): string {
|
||||
rows.forEach((y) => {
|
||||
lines.push(
|
||||
`<line x1='0' y1='${y}' x2='600' y2='${y}' stroke='${GRID_PURPLE}' ` +
|
||||
`stroke-width='1.4' stroke-opacity='0.9'/>`,
|
||||
`stroke-width='1.2' stroke-opacity='0.9' vector-effect='non-scaling-stroke'/>`,
|
||||
);
|
||||
});
|
||||
// Vertical lines fanning out from the top-center vanishing point.
|
||||
@@ -67,7 +71,7 @@ function gridDataUri(): string {
|
||||
const botX = 300 + i * 95; // wide at the foreground
|
||||
lines.push(
|
||||
`<line x1='${topX}' y1='0' x2='${botX}' y2='600' stroke='${GRID_PURPLE}' ` +
|
||||
`stroke-width='1.4' stroke-opacity='0.8'/>`,
|
||||
`stroke-width='1.2' stroke-opacity='0.8' vector-effect='non-scaling-stroke'/>`,
|
||||
);
|
||||
}
|
||||
const svg =
|
||||
@@ -105,6 +109,13 @@ const RESTING_SPARKLES: ReadonlyArray<{
|
||||
|
||||
const GRID_URI = gridDataUri();
|
||||
|
||||
// HUD text size: 11px on any real viewport, 0px (invisible) inside anything
|
||||
// narrower than ~330px. `cqw` resolves against the nearest size container —
|
||||
// the settings swatch (`SeasonalPreview` sets container-type) — and falls back
|
||||
// to the viewport width when there is no container, i.e. the full-screen
|
||||
// overlay. clamp(0, 100cqw - 320px, 11px) → 76px swatch: 0px; 1440px app: 11px.
|
||||
const HUD_FONT_SIZE = 'clamp(0px, calc(100cqw - 320px), 11px)';
|
||||
|
||||
export function ArcadeOverlay({ reduced }: SeasonalOverlayProps) {
|
||||
// Deterministic sparkle field, computed ONCE. No per-frame state.
|
||||
const sparkles = useMemo<Sparkle[]>(() => {
|
||||
@@ -134,9 +145,9 @@ export function ArcadeOverlay({ reduced }: SeasonalOverlayProps) {
|
||||
position: 'absolute',
|
||||
inset: 0,
|
||||
backgroundImage: [
|
||||
'radial-gradient(140% 80% at 50% -8%, oklch(0.65 0.25 350 / 0.16) 0%, transparent 55%)',
|
||||
'radial-gradient(120% 70% at 50% 112%, oklch(0.45 0.18 300 / 0.20) 0%, transparent 60%)',
|
||||
'linear-gradient(180deg, oklch(0.12 0.05 300 / 0.10) 0%, transparent 38%, oklch(0.10 0.06 310 / 0.16) 100%)',
|
||||
'radial-gradient(140% 80% at 50% -8%, oklch(0.65 0.25 350 / 0.12) 0%, transparent 55%)',
|
||||
'radial-gradient(120% 70% at 50% 112%, oklch(0.45 0.18 300 / 0.16) 0%, transparent 60%)',
|
||||
'linear-gradient(180deg, oklch(0.12 0.05 300 / 0.08) 0%, transparent 38%, oklch(0.10 0.06 310 / 0.12) 100%)',
|
||||
].join(','),
|
||||
contain: 'layout paint style',
|
||||
}}
|
||||
@@ -147,41 +158,59 @@ export function ArcadeOverlay({ reduced }: SeasonalOverlayProps) {
|
||||
a vanishing point at the top (the horizon). It lives in the lower
|
||||
half of the screen — the "floor". The inner plane scrolls upward by
|
||||
one tile via transform translateY, which reads as the grid flowing
|
||||
toward the viewer. Pure transform; never background-position. */}
|
||||
toward the viewer. Pure transform; never background-position.
|
||||
|
||||
Two masks are nested (multiple mask-images on one element union by
|
||||
default, and `mask-composite: intersect` isn't universal yet): the
|
||||
outer wrapper fades the lattice through the central column where the
|
||||
message timeline lives, so it frames the chat instead of striping
|
||||
the text; the inner box fades it in from the horizon. */}
|
||||
<div
|
||||
aria-hidden="true"
|
||||
style={{
|
||||
position: 'absolute',
|
||||
left: '-25%',
|
||||
right: '-25%',
|
||||
bottom: 0,
|
||||
height: '62%',
|
||||
overflow: 'hidden',
|
||||
perspective: '280px',
|
||||
perspectiveOrigin: '50% 0%',
|
||||
maskImage: 'linear-gradient(180deg, transparent 0%, #000 26%, #000 100%)',
|
||||
WebkitMaskImage: 'linear-gradient(180deg, transparent 0%, #000 26%, #000 100%)',
|
||||
opacity: reduced ? 0.5 : 0.62,
|
||||
inset: 0,
|
||||
maskImage:
|
||||
'linear-gradient(90deg, #000 0%, #000 12%, rgba(0,0,0,0.3) 34%, rgba(0,0,0,0.3) 66%, #000 88%, #000 100%)',
|
||||
WebkitMaskImage:
|
||||
'linear-gradient(90deg, #000 0%, #000 12%, rgba(0,0,0,0.3) 34%, rgba(0,0,0,0.3) 66%, #000 88%, #000 100%)',
|
||||
opacity: reduced ? 0.4 : 0.46,
|
||||
contain: 'layout paint style',
|
||||
}}
|
||||
>
|
||||
<div
|
||||
style={{
|
||||
position: 'absolute',
|
||||
left: 0,
|
||||
right: 0,
|
||||
top: 0,
|
||||
height: '200%',
|
||||
transformOrigin: 'top center',
|
||||
transform: 'rotateX(74deg)',
|
||||
backgroundImage: GRID_URI,
|
||||
backgroundRepeat: 'repeat-y',
|
||||
backgroundSize: '100% 50%',
|
||||
filter: 'drop-shadow(0 0 3px oklch(0.55 0.22 320 / 0.6))',
|
||||
willChange: reduced ? undefined : 'transform',
|
||||
animation: reduced ? 'none' : `${animGridScroll} 7s linear infinite`,
|
||||
left: '-25%',
|
||||
right: '-25%',
|
||||
bottom: 0,
|
||||
height: '62%',
|
||||
overflow: 'hidden',
|
||||
perspective: '280px',
|
||||
perspectiveOrigin: '50% 0%',
|
||||
maskImage: 'linear-gradient(180deg, transparent 0%, #000 26%, #000 100%)',
|
||||
WebkitMaskImage: 'linear-gradient(180deg, transparent 0%, #000 26%, #000 100%)',
|
||||
contain: 'layout paint style',
|
||||
}}
|
||||
/>
|
||||
>
|
||||
<div
|
||||
style={{
|
||||
position: 'absolute',
|
||||
left: 0,
|
||||
right: 0,
|
||||
top: 0,
|
||||
height: '200%',
|
||||
transformOrigin: 'top center',
|
||||
transform: 'rotateX(74deg)',
|
||||
backgroundImage: GRID_URI,
|
||||
backgroundRepeat: 'repeat-y',
|
||||
backgroundSize: '100% 50%',
|
||||
filter: 'drop-shadow(0 0 2px oklch(0.55 0.22 320 / 0.55))',
|
||||
willChange: reduced ? undefined : 'transform',
|
||||
animation: reduced ? 'none' : `${animGridScroll} 7s linear infinite`,
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 3. Horizon glow + neon horizon line. A soft synthwave sun-bloom sits
|
||||
@@ -197,7 +226,7 @@ export function ArcadeOverlay({ reduced }: SeasonalOverlayProps) {
|
||||
height: '34%',
|
||||
transform: 'translate(-50%, -50%)',
|
||||
backgroundImage:
|
||||
'radial-gradient(60% 100% at 50% 100%, oklch(0.70 0.22 350 / 0.22) 0%, oklch(0.65 0.18 330 / 0.10) 40%, transparent 72%)',
|
||||
'radial-gradient(60% 100% at 50% 100%, oklch(0.70 0.22 350 / 0.16) 0%, oklch(0.65 0.18 330 / 0.08) 40%, transparent 72%)',
|
||||
contain: 'layout paint style',
|
||||
}}
|
||||
/>
|
||||
@@ -209,8 +238,10 @@ export function ArcadeOverlay({ reduced }: SeasonalOverlayProps) {
|
||||
right: '12%',
|
||||
top: '38%',
|
||||
height: '1.5px',
|
||||
background: `linear-gradient(90deg, transparent 0%, ${NEON_CYAN} 25%, oklch(0.92 0.10 320 / 0.95) 50%, ${NEON_CYAN} 75%, transparent 100%)`,
|
||||
opacity: 0.55,
|
||||
// Bright at the flanks, dropped out through the centre column so the
|
||||
// rule frames the timeline rather than underlining a message.
|
||||
background: `linear-gradient(90deg, transparent 0%, ${NEON_CYAN} 14%, oklch(0.92 0.10 320 / 0.95) 22%, transparent 34%, transparent 66%, oklch(0.92 0.10 320 / 0.95) 78%, ${NEON_CYAN} 86%, transparent 100%)`,
|
||||
opacity: 0.4,
|
||||
filter: 'blur(0.4px) drop-shadow(0 0 4px oklch(0.78 0.16 200 / 0.7))',
|
||||
}}
|
||||
/>
|
||||
@@ -273,7 +304,7 @@ export function ArcadeOverlay({ reduced }: SeasonalOverlayProps) {
|
||||
inset: 0,
|
||||
overflow: 'hidden',
|
||||
mixBlendMode: 'multiply',
|
||||
opacity: 0.5,
|
||||
opacity: 0.32,
|
||||
contain: 'layout paint style',
|
||||
}}
|
||||
>
|
||||
@@ -285,7 +316,7 @@ export function ArcadeOverlay({ reduced }: SeasonalOverlayProps) {
|
||||
top: '-8px',
|
||||
bottom: '-8px',
|
||||
backgroundImage:
|
||||
'repeating-linear-gradient(0deg, oklch(0.10 0.04 300 / 0.55) 0px, oklch(0.10 0.04 300 / 0.55) 1px, transparent 1px, transparent 3px)',
|
||||
'repeating-linear-gradient(0deg, oklch(0.10 0.04 300 / 0.45) 0px, oklch(0.10 0.04 300 / 0.45) 1px, transparent 1px, transparent 4px)',
|
||||
willChange: reduced ? undefined : 'transform',
|
||||
animation: reduced ? 'none' : `${animScanRoll} 6s linear infinite`,
|
||||
}}
|
||||
@@ -309,51 +340,54 @@ export function ArcadeOverlay({ reduced }: SeasonalOverlayProps) {
|
||||
}}
|
||||
/>
|
||||
|
||||
{/* 7a. Glowing "INSERT COIN" attract-mode blip, low-opacity, bottom-center.
|
||||
Static scene shows it steady (no blink). */}
|
||||
{/* 7. Attract-mode HUD: a tiny SCORE readout over a glowing "INSERT COIN"
|
||||
blip, stacked bottom-right. That corner is the one spot that is
|
||||
clear in every layout (below the members list, or the empty right
|
||||
end of the read-receipt strip) — top-left collided with the space
|
||||
bar and bottom-centre sat on the composer. Static scene shows both
|
||||
steady (no blink). The font-size clamp collapses the text to nothing
|
||||
when the host is narrower than ~330px, so the 76px settings swatch
|
||||
never shows clipped glyphs. */}
|
||||
<div
|
||||
aria-hidden="true"
|
||||
style={{
|
||||
position: 'absolute',
|
||||
bottom: '5%',
|
||||
left: '50%',
|
||||
transform: 'translateX(-50%)',
|
||||
right: '14px',
|
||||
bottom: '8px',
|
||||
display: 'flex',
|
||||
flexDirection: 'column',
|
||||
alignItems: 'flex-end',
|
||||
gap: '3px',
|
||||
fontFamily: '"Courier New", monospace',
|
||||
fontSize: '12px',
|
||||
fontSize: HUD_FONT_SIZE,
|
||||
fontWeight: 700,
|
||||
letterSpacing: '0.32em',
|
||||
color: NEON_CYAN,
|
||||
textShadow: '0 0 6px oklch(0.80 0.15 200 / 0.9), 0 0 14px oklch(0.65 0.25 350 / 0.5)',
|
||||
lineHeight: 1,
|
||||
userSelect: 'none',
|
||||
whiteSpace: 'nowrap',
|
||||
opacity: reduced ? 0.6 : undefined,
|
||||
animation: reduced ? 'none' : `${animCoinBlink} 1.6s step-end infinite`,
|
||||
}}
|
||||
>
|
||||
INSERT COIN
|
||||
</div>
|
||||
|
||||
{/* 7b. Corner SCORE HUD glyph — a tiny pixel score that blips, top-left,
|
||||
very low opacity so it reads as ambient chrome, not UI. */}
|
||||
<div
|
||||
aria-hidden="true"
|
||||
style={{
|
||||
position: 'absolute',
|
||||
top: '2.5%',
|
||||
left: '2%',
|
||||
fontFamily: '"Courier New", monospace',
|
||||
fontSize: '10px',
|
||||
fontWeight: 700,
|
||||
letterSpacing: '0.18em',
|
||||
color: NEON_MAGENTA,
|
||||
textShadow: '0 0 6px oklch(0.65 0.25 350 / 0.8)',
|
||||
userSelect: 'none',
|
||||
whiteSpace: 'nowrap',
|
||||
opacity: reduced ? 0.5 : undefined,
|
||||
animation: reduced ? 'none' : `${animScoreBlip} 2.4s ease-in-out infinite`,
|
||||
}}
|
||||
>
|
||||
1UP 00<span style={{ color: NEON_CYAN }}>0000</span>
|
||||
<div
|
||||
style={{
|
||||
letterSpacing: '0.18em',
|
||||
color: NEON_MAGENTA,
|
||||
textShadow: '0 0 6px oklch(0.65 0.25 350 / 0.8)',
|
||||
opacity: reduced ? 0.5 : undefined,
|
||||
animation: reduced ? 'none' : `${animScoreBlip} 2.4s ease-in-out infinite`,
|
||||
}}
|
||||
>
|
||||
1UP 00<span style={{ color: NEON_CYAN }}>0000</span>
|
||||
</div>
|
||||
<div
|
||||
style={{
|
||||
letterSpacing: '0.32em',
|
||||
color: NEON_CYAN,
|
||||
textShadow: '0 0 6px oklch(0.80 0.15 200 / 0.9), 0 0 14px oklch(0.65 0.25 350 / 0.5)',
|
||||
opacity: reduced ? 0.6 : undefined,
|
||||
animation: reduced ? 'none' : `${animCoinBlink} 1.6s step-end infinite`,
|
||||
}}
|
||||
>
|
||||
INSERT COIN
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 8. CRT vignette + screen-glow. A radial darkening frames the corners,
|
||||
|
||||
@@ -97,8 +97,8 @@ function makeStars(count: number, seedBase: number): Star[] {
|
||||
|
||||
export function DeepSpaceOverlay({ reduced }: SeasonalOverlayProps) {
|
||||
// Two parallax depths. Far = dense + faint, Near = sparser + slightly larger.
|
||||
const farStars = useMemo<Star[]>(() => makeStars(16, 1000), []);
|
||||
const nearStars = useMemo<Star[]>(() => makeStars(12, 2000), []);
|
||||
const farStars = useMemo<Star[]>(() => makeStars(40, 1000), []);
|
||||
const nearStars = useMemo<Star[]>(() => makeStars(22, 2000), []);
|
||||
|
||||
const heroStars = useMemo<HeroStar[]>(
|
||||
() =>
|
||||
@@ -144,7 +144,7 @@ export function DeepSpaceOverlay({ reduced }: SeasonalOverlayProps) {
|
||||
position: 'absolute',
|
||||
inset: '-6%',
|
||||
contain: 'layout paint style',
|
||||
backgroundColor: 'oklch(0.2 0.12 300 / 0.16)',
|
||||
backgroundColor: 'oklch(0.2 0.12 300 / 0.12)',
|
||||
backgroundImage: [
|
||||
'radial-gradient(120% 90% at 50% -8%, oklch(0.28 0.13 295 / 0.2) 0%, transparent 60%)',
|
||||
'radial-gradient(100% 80% at 12% 18%, oklch(0.55 0.2 330 / 0.1) 0%, transparent 55%)',
|
||||
|
||||
@@ -183,15 +183,17 @@ export function EarthDayOverlay({ reduced }: SeasonalOverlayProps) {
|
||||
))}
|
||||
</div>
|
||||
|
||||
{/* ── Blue-marble Earth tucked into the bottom-right corner ── */}
|
||||
{/* ── Blue-marble Earth tucked into the bottom-right corner ──
|
||||
Kept above the composer strip: bottom offset + size keep the
|
||||
globe's footprint within the top ~90% of the viewport. ── */}
|
||||
<div
|
||||
aria-hidden="true"
|
||||
style={{
|
||||
position: 'absolute',
|
||||
right: '-6%',
|
||||
bottom: '-10%',
|
||||
width: '300px',
|
||||
height: '300px',
|
||||
right: '-4%',
|
||||
bottom: '10%',
|
||||
width: '200px',
|
||||
height: '200px',
|
||||
contain: 'layout paint style',
|
||||
willChange: reduced ? undefined : 'transform, opacity',
|
||||
transform: reduced ? 'scale(1.02)' : undefined,
|
||||
|
||||
@@ -164,7 +164,7 @@ export function HalloweenOverlay({ reduced }: SeasonalOverlayProps) {
|
||||
height: `${f.height}px`,
|
||||
backgroundImage: `radial-gradient(60% 100% at 50% 100%, ${FOG_TINT} 0%, transparent 75%)`,
|
||||
filter: 'blur(14px)',
|
||||
willChange: 'transform, opacity',
|
||||
willChange: reduced ? undefined : 'transform, opacity',
|
||||
opacity: reduced ? 0.5 : undefined,
|
||||
transform: reduced ? 'translate3d(2%, 0, 0) scale(1.18)' : undefined,
|
||||
animation: reduced
|
||||
|
||||
@@ -73,6 +73,32 @@ const formatClipSeconds = (seconds: number): string => {
|
||||
return `${m}:${s.toString().padStart(2, '0')}`;
|
||||
};
|
||||
|
||||
/**
|
||||
* [Gitea #31] Pure running-count cap check for `handleFiles`: given how many
|
||||
* clips already exist (staged uploads included) before this batch starts,
|
||||
* decide which of the batch's files fit under `max`. Kept pure/exported so the
|
||||
* "running count, not a stale double-counted closure value" logic can be unit
|
||||
* tested without a DOM/MatrixClient.
|
||||
*/
|
||||
export function acceptClips<T>(
|
||||
currentCount: number,
|
||||
files: readonly T[],
|
||||
max: number,
|
||||
): { accepted: T[]; rejected: T[] } {
|
||||
const accepted: T[] = [];
|
||||
const rejected: T[] = [];
|
||||
let count = currentCount;
|
||||
files.forEach((file) => {
|
||||
if (count >= max) {
|
||||
rejected.push(file);
|
||||
} else {
|
||||
accepted.push(file);
|
||||
count += 1;
|
||||
}
|
||||
});
|
||||
return { accepted, rejected };
|
||||
}
|
||||
|
||||
type ClipDraft = {
|
||||
url: string;
|
||||
body: string;
|
||||
@@ -186,11 +212,19 @@ export function SoundboardPackEditor({ pack, canEdit, onUpdate }: SoundboardPack
|
||||
...existing.map((c) => c.shortcode),
|
||||
...uploads.map((u) => u.shortcode),
|
||||
]);
|
||||
for (let i = 0; i < files.length; i += 1) {
|
||||
const file = files[i];
|
||||
if (clipCount + uploads.length >= SOUNDBOARD_MAX_CLIPS) {
|
||||
throw new Error(`Soundboard is full (max ${SOUNDBOARD_MAX_CLIPS} clips).`);
|
||||
}
|
||||
// [Gitea #31] `clipCount` already includes staged `uploads`, so don't
|
||||
// add `uploads.length` again here (double-counting). And since
|
||||
// `setUploads` inside the loop doesn't update this closure's
|
||||
// `clipCount`, track the running total in a local variable that starts
|
||||
// from the real current total instead of re-reading a stale value for
|
||||
// every file in the batch.
|
||||
const { accepted, rejected } = acceptClips(
|
||||
clipCount,
|
||||
Array.from(files),
|
||||
SOUNDBOARD_MAX_CLIPS,
|
||||
);
|
||||
for (let i = 0; i < accepted.length; i += 1) {
|
||||
const file = accepted[i];
|
||||
if (file.size > SOUNDBOARD_MAX_CLIP_BYTES) {
|
||||
throw new Error(`"${file.name}" is too large (max 1 MB).`);
|
||||
}
|
||||
@@ -215,6 +249,9 @@ export function SoundboardPackEditor({ pack, canEdit, onUpdate }: SoundboardPack
|
||||
},
|
||||
]);
|
||||
}
|
||||
if (rejected.length > 0) {
|
||||
throw new Error(`Soundboard is full (max ${SOUNDBOARD_MAX_CLIPS} clips).`);
|
||||
}
|
||||
} catch (e) {
|
||||
setError(e instanceof Error ? e.message : 'Upload failed.');
|
||||
} finally {
|
||||
|
||||
@@ -214,24 +214,56 @@ function UserPrivateNotes({ userId }: { userId: string }) {
|
||||
const [draft, setDraft] = useState(() => getNote(userId));
|
||||
const [saving, setSaving] = useState(false);
|
||||
const saveTimer = useRef<ReturnType<typeof setTimeout> | undefined>(undefined);
|
||||
// True while the user has unsaved local edits — prevents the store-sync
|
||||
// effect below from reacting to the echo of our own save and reverting text
|
||||
// typed after the debounce fired but before that save's account-data echo
|
||||
// landed (mirrors statusDirtyRef in Profile.tsx's ProfileStatus).
|
||||
const dirtyRef = useRef(false);
|
||||
// Latest draft/userId, kept current on every render so the unmount cleanup
|
||||
// can flush a pending save without capturing a stale closure.
|
||||
const draftRef = useRef(draft);
|
||||
draftRef.current = draft;
|
||||
const userIdRef = useRef(userId);
|
||||
userIdRef.current = userId;
|
||||
const setNoteRef = useRef(setNote);
|
||||
setNoteRef.current = setNote;
|
||||
const prevUserIdRef = useRef(userId);
|
||||
|
||||
// Sync if account data arrives after mount
|
||||
// Sync if account data arrives after mount, but never while there are
|
||||
// unsaved local edits (including our own save's in-flight echo).
|
||||
useEffect(() => {
|
||||
if (prevUserIdRef.current !== userId) {
|
||||
prevUserIdRef.current = userId;
|
||||
dirtyRef.current = false;
|
||||
}
|
||||
if (dirtyRef.current) return;
|
||||
setDraft(getNote(userId));
|
||||
}, [getNote, userId]);
|
||||
|
||||
const handleChange = (e: React.ChangeEvent<HTMLTextAreaElement>) => {
|
||||
const val = e.target.value;
|
||||
dirtyRef.current = true;
|
||||
setDraft(val);
|
||||
clearTimeout(saveTimer.current);
|
||||
saveTimer.current = setTimeout(async () => {
|
||||
dirtyRef.current = false;
|
||||
setSaving(true);
|
||||
await setNote(userId, val);
|
||||
setSaving(false);
|
||||
}, 800);
|
||||
};
|
||||
|
||||
useEffect(() => () => clearTimeout(saveTimer.current), []);
|
||||
useEffect(
|
||||
() => () => {
|
||||
clearTimeout(saveTimer.current);
|
||||
// Flush a still-pending debounced save instead of dropping it (e.g. the
|
||||
// profile panel closes within the 800ms debounce window).
|
||||
if (dirtyRef.current) {
|
||||
setNoteRef.current(userIdRef.current, draftRef.current);
|
||||
}
|
||||
},
|
||||
[],
|
||||
);
|
||||
|
||||
const charsLeft = USER_NOTE_MAX_LENGTH - draft.length;
|
||||
|
||||
|
||||
@@ -103,7 +103,8 @@ function BookmarkItem({ bookmark, onJump, onRemove, preview, senderName }: Bookm
|
||||
const mx = useMatrixClient();
|
||||
const useAuthentication = useMediaAuthentication();
|
||||
const room = mx.getRoom(bookmark.roomId) ?? undefined;
|
||||
const displayRoomName = room?.name ?? bookmark.roomName;
|
||||
// E2EE-room bookmarks store no roomName; fall back past the '' placeholder.
|
||||
const displayRoomName = room?.name || bookmark.roomName || 'Unknown room';
|
||||
const avatarUrl = room
|
||||
? (getRoomAvatarUrl(mx, room, 96, useAuthentication) ?? undefined)
|
||||
: undefined;
|
||||
@@ -162,7 +163,7 @@ function BookmarkItem({ bookmark, onJump, onRemove, preview, senderName }: Bookm
|
||||
style={{ justifyContent: 'flex-start', height: 'unset', padding: config.space.S200 }}
|
||||
>
|
||||
<Text className={css.BookmarkPreview} size="T200" priority="400">
|
||||
{preview ?? (bookmark.previewText || '(no preview)')}
|
||||
{preview ?? (bookmark.previewText || 'Message unavailable')}
|
||||
</Text>
|
||||
</Button>
|
||||
</Box>
|
||||
@@ -173,13 +174,16 @@ type LiveBookmarkItemProps = BookmarkItemProps & { room: Room };
|
||||
|
||||
// Renders the same layout as BookmarkItem, but resolves the message body live so
|
||||
// edits (m.replace, applied by useRoomEvent) and redactions are reflected. The
|
||||
// stored snapshot (previewText) remains the fallback for loading/failed/empty states.
|
||||
// stored snapshot (previewText) remains the fallback for loading/failed/empty
|
||||
// states; bookmarks from E2EE rooms have no snapshot at all (account data is
|
||||
// server-readable), so the live event is their only source of text.
|
||||
function LiveBookmarkItem({ room, bookmark, onJump, onRemove }: LiveBookmarkItemProps) {
|
||||
const liveEvent = useRoomEvent(room, bookmark.eventId, () =>
|
||||
room.findEventById(bookmark.eventId),
|
||||
);
|
||||
|
||||
const snapshot = bookmark.previewText || '(no preview)';
|
||||
const snapshot =
|
||||
bookmark.previewText || (liveEvent === undefined ? 'Loading…' : 'Message unavailable');
|
||||
let preview: ReactNode = snapshot;
|
||||
|
||||
// undefined (loading) and null (fetch failed / not found) both keep the snapshot.
|
||||
@@ -234,7 +238,7 @@ function RoomGroupHeader({
|
||||
const mx = useMatrixClient();
|
||||
const useAuthentication = useMediaAuthentication();
|
||||
const room = mx.getRoom(roomId) ?? undefined;
|
||||
const displayRoomName = room?.name ?? roomName;
|
||||
const displayRoomName = room?.name || roomName || 'Unknown room';
|
||||
const avatarUrl = room
|
||||
? (getRoomAvatarUrl(mx, room, 96, useAuthentication) ?? undefined)
|
||||
: undefined;
|
||||
@@ -327,13 +331,20 @@ export function BookmarksPanel({ onClose }: BookmarksPanelProps) {
|
||||
() =>
|
||||
query.length === 0
|
||||
? bookmarks
|
||||
: bookmarks.filter(
|
||||
(bk) =>
|
||||
bk.previewText.toLowerCase().includes(query) ||
|
||||
: bookmarks.filter((bk) => {
|
||||
// E2EE-room bookmarks have no stored text: match against the locally
|
||||
// cached event body / live room name instead (nothing is fetched here).
|
||||
const room = mx.getRoom(bk.roomId);
|
||||
const localBody = room?.findEventById(bk.eventId)?.getContent()?.body;
|
||||
return (
|
||||
(bk.previewText?.toLowerCase().includes(query) ?? false) ||
|
||||
(typeof localBody === 'string' && localBody.toLowerCase().includes(query)) ||
|
||||
bk.roomName.toLowerCase().includes(query) ||
|
||||
(bk.senderName?.toLowerCase().includes(query) ?? false),
|
||||
),
|
||||
[bookmarks, query],
|
||||
(room?.name.toLowerCase().includes(query) ?? false) ||
|
||||
(bk.senderName?.toLowerCase().includes(query) ?? false)
|
||||
);
|
||||
}),
|
||||
[mx, bookmarks, query],
|
||||
);
|
||||
|
||||
// Prune collapsed roomIds that no longer have any bookmark, so a room re-saved
|
||||
|
||||
@@ -1,11 +1,25 @@
|
||||
import { Box, Chip, Icon, IconButton, Icons, Spinner, Text, Tooltip, TooltipProvider } from 'folds';
|
||||
import React, { useCallback } from 'react';
|
||||
import {
|
||||
Box,
|
||||
Button,
|
||||
Chip,
|
||||
color,
|
||||
config,
|
||||
Icon,
|
||||
IconButton,
|
||||
Icons,
|
||||
Spinner,
|
||||
Text,
|
||||
Tooltip,
|
||||
TooltipProvider,
|
||||
} from 'folds';
|
||||
import React, { useCallback, useEffect, useState } from 'react';
|
||||
import { useSetAtom } from 'jotai';
|
||||
import { StatusDivider } from './components';
|
||||
import { CallEmbed, useCallControlState } from '../../plugins/call';
|
||||
import { AsyncStatus, useAsyncCallback } from '../../hooks/useAsyncCallback';
|
||||
import { callEmbedAtom } from '../../state/callEmbed';
|
||||
import { MobileTouchTarget } from '../../styles/mobile.css';
|
||||
import { useRoomCallPolicy } from '../../hooks/useRoomCallPolicy';
|
||||
|
||||
type MicrophoneButtonProps = {
|
||||
enabled: boolean;
|
||||
@@ -177,6 +191,23 @@ export function CallControl({
|
||||
const { microphone, video, sound, screenshare } = useCallControlState(callEmbed.control);
|
||||
const setCallEmbed = useSetAtom(callEmbedAtom);
|
||||
|
||||
// [Gitea #26] Apply the same room-level camera/screenshare policy as the
|
||||
// in-room CallControls bar, so the status bar can't be used to bypass it.
|
||||
const { allowCamera, allowScreenshare } = useRoomCallPolicy(callEmbed.room);
|
||||
// Keep a forbidden control visible while its track is still live (so the user
|
||||
// can stop it); otherwise hide it entirely.
|
||||
const showCamera = allowCamera || video;
|
||||
const showScreenshare = allowScreenshare || screenshare;
|
||||
const [shareConfirm, setShareConfirm] = useState(false);
|
||||
useEffect(() => {
|
||||
if (!shareConfirm) return undefined;
|
||||
const onKeyDown = (e: KeyboardEvent) => {
|
||||
if (e.key === 'Escape') setShareConfirm(false);
|
||||
};
|
||||
window.addEventListener('keydown', onKeyDown);
|
||||
return () => window.removeEventListener('keydown', onKeyDown);
|
||||
}, [shareConfirm]);
|
||||
|
||||
const handleMicrophoneToggle = useCallback(
|
||||
() => callEmbed.control.toggleMicrophone(),
|
||||
[callEmbed],
|
||||
@@ -198,7 +229,65 @@ export function CallControl({
|
||||
};
|
||||
|
||||
return (
|
||||
<Box shrink="No" alignItems="Center" gap="300">
|
||||
<Box shrink="No" alignItems="Center" gap="300" style={{ position: 'relative' }}>
|
||||
{shareConfirm && (
|
||||
<>
|
||||
<div
|
||||
style={{ position: 'fixed', inset: 0, zIndex: 99 }}
|
||||
onClick={() => setShareConfirm(false)}
|
||||
aria-hidden="true"
|
||||
/>
|
||||
<Box
|
||||
style={{
|
||||
position: 'absolute',
|
||||
bottom: '110%',
|
||||
left: 0,
|
||||
background: color.Surface.Container,
|
||||
border: `${config.borderWidth.B300} solid ${color.Surface.ContainerLine}`,
|
||||
borderRadius: '0.75rem',
|
||||
padding: '1rem 1.25rem',
|
||||
zIndex: 100,
|
||||
minWidth: '260px',
|
||||
maxWidth: `calc(100vw - 2 * ${config.space.S400})`,
|
||||
boxShadow: '0 8px 32px rgba(0,0,0,0.35)',
|
||||
display: 'flex',
|
||||
flexDirection: 'column',
|
||||
gap: '0.75rem',
|
||||
}}
|
||||
>
|
||||
<Text size="T300" style={{ fontWeight: 600 }}>
|
||||
Share your screen?
|
||||
</Text>
|
||||
<Text size="T200" style={{ opacity: 0.75 }}>
|
||||
Your screen will be visible to all participants in this call.
|
||||
</Text>
|
||||
<Box gap="200">
|
||||
<Button
|
||||
size="300"
|
||||
variant="Success"
|
||||
fill="Solid"
|
||||
radii="300"
|
||||
onClick={() => {
|
||||
callEmbed.control.toggleScreenshare();
|
||||
setShareConfirm(false);
|
||||
}}
|
||||
>
|
||||
<Text size="B300">Share</Text>
|
||||
</Button>
|
||||
<Button
|
||||
size="300"
|
||||
variant="Secondary"
|
||||
fill="Soft"
|
||||
radii="300"
|
||||
outlined
|
||||
onClick={() => setShareConfirm(false)}
|
||||
>
|
||||
<Text size="B300">Cancel</Text>
|
||||
</Button>
|
||||
</Box>
|
||||
</Box>
|
||||
</>
|
||||
)}
|
||||
<Box alignItems="Inherit" gap="200">
|
||||
<MicrophoneButton
|
||||
enabled={microphone}
|
||||
@@ -210,12 +299,16 @@ export function CallControl({
|
||||
onToggle={() => callEmbed.control.toggleSound()}
|
||||
disabled={!callJoined}
|
||||
/>
|
||||
{!compact && <StatusDivider />}
|
||||
<VideoButton enabled={video} onToggle={handleVideoToggle} disabled={!callJoined} />
|
||||
{!compact && (
|
||||
{!compact && (showCamera || showScreenshare) && <StatusDivider />}
|
||||
{showCamera && (
|
||||
<VideoButton enabled={video} onToggle={handleVideoToggle} disabled={!callJoined} />
|
||||
)}
|
||||
{!compact && showScreenshare && (
|
||||
<ScreenShareButton
|
||||
enabled={screenshare}
|
||||
onToggle={() => callEmbed.control.toggleScreenshare()}
|
||||
onToggle={() =>
|
||||
screenshare ? callEmbed.control.toggleScreenshare() : setShareConfirm(true)
|
||||
}
|
||||
disabled={!callJoined}
|
||||
/>
|
||||
)}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Box, config, Icon, Icons, Menu, MenuItem, PopOut, RectCords, Text } from 'folds';
|
||||
import { CallMembership } from 'matrix-js-sdk/lib/matrixrtc/CallMembership';
|
||||
import React, { useState } from 'react';
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import FocusTrap from 'focus-trap-react';
|
||||
import { Room } from 'matrix-js-sdk';
|
||||
import { UserAvatar } from '../../components/user-avatar';
|
||||
@@ -12,8 +12,31 @@ import { StackedAvatar } from '../../components/stacked-avatar';
|
||||
import { useOpenUserRoomProfile } from '../../state/hooks/userRoomProfile';
|
||||
import { stopPropagation } from '../../utils/keyboard';
|
||||
import { CallEmbed } from '../../plugins/call/CallEmbed';
|
||||
import { CallControlEvent } from '../../plugins/call/CallControl';
|
||||
import * as css from './styles.css';
|
||||
|
||||
// [Gitea #56] Subscribes to CallControl's focus pin so the menu can render a
|
||||
// "Focus camera" / "Unfocus camera" toggle instead of a one-way pin.
|
||||
function useFocusedUserId(callEmbed?: CallEmbed): string | null {
|
||||
const control = callEmbed?.control;
|
||||
const [focusedUserId, setFocusedUserId] = useState<string | null>(control?.focusedUserId ?? null);
|
||||
|
||||
useEffect(() => {
|
||||
if (!control) {
|
||||
setFocusedUserId(null);
|
||||
return undefined;
|
||||
}
|
||||
setFocusedUserId(control.focusedUserId);
|
||||
const handleUpdate = () => setFocusedUserId(control.focusedUserId);
|
||||
control.on(CallControlEvent.StateUpdate, handleUpdate);
|
||||
return () => {
|
||||
control.off(CallControlEvent.StateUpdate, handleUpdate);
|
||||
};
|
||||
}, [control]);
|
||||
|
||||
return focusedUserId;
|
||||
}
|
||||
|
||||
type ParticipantMenuProps = {
|
||||
anchor: RectCords;
|
||||
name: string;
|
||||
@@ -33,15 +56,23 @@ function ParticipantMenu({
|
||||
profileCords,
|
||||
}: ParticipantMenuProps) {
|
||||
const openUserProfile = useOpenUserRoomProfile();
|
||||
const focusedUserId = useFocusedUserId(callEmbed);
|
||||
const isFocused = focusedUserId === userId;
|
||||
|
||||
const handleViewProfile = () => {
|
||||
onClose();
|
||||
openUserProfile(room.roomId, undefined, userId, profileCords, 'Top');
|
||||
};
|
||||
|
||||
// [Gitea #56] Toggle: focusing the already-focused participant clears the
|
||||
// pin and returns EC to speaker-follows, instead of leaving no way back.
|
||||
const handleFocusCamera = () => {
|
||||
onClose();
|
||||
callEmbed?.control.focusCameraParticipant(userId);
|
||||
if (isFocused) {
|
||||
callEmbed?.control.clearFocusParticipant();
|
||||
} else {
|
||||
callEmbed?.control.focusCameraParticipant(userId);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
@@ -78,7 +109,7 @@ function ParticipantMenu({
|
||||
before={<Icon size="100" src={Icons.VideoCamera} />}
|
||||
onClick={handleFocusCamera}
|
||||
>
|
||||
<Text size="B300">Focus camera</Text>
|
||||
<Text size="B300">{isFocused ? 'Unfocus camera' : 'Focus camera'}</Text>
|
||||
</MenuItem>
|
||||
)}
|
||||
<MenuItem
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import React, { MouseEventHandler, useCallback, useEffect, useRef, useState } from 'react';
|
||||
import { useSetAtom } from 'jotai';
|
||||
import { useAtomValue, useSetAtom } from 'jotai';
|
||||
import {
|
||||
Box,
|
||||
Button,
|
||||
@@ -39,7 +39,7 @@ import { ScreenSize, useScreenSize } from '../../hooks/useScreenSize';
|
||||
import { stopPropagation } from '../../utils/keyboard';
|
||||
import { AsyncStatus, useAsyncCallback } from '../../hooks/useAsyncCallback';
|
||||
import { useCallEmbedRef } from '../../hooks/useCallEmbed';
|
||||
import { useAfkAutoMute } from '../../hooks/useAfkAutoMute';
|
||||
import { pttActiveAtom } from '../../hooks/useCallHotkeys';
|
||||
import { CallSoundboard } from './CallSoundboard';
|
||||
import { useStateEvent } from '../../hooks/useStateEvent';
|
||||
import { StateEvent } from '../../../types/matrix/room';
|
||||
@@ -88,8 +88,6 @@ export function CallControls({ callEmbed }: CallControlsProps) {
|
||||
const { microphone, video, sound, screenshare, spotlight, screenshareAudioMuted } =
|
||||
useCallControlState(callEmbed.control);
|
||||
|
||||
useAfkAutoMute(callEmbed);
|
||||
|
||||
const [cords, setCords] = useState<RectCords>();
|
||||
const [shareConfirm, setShareConfirm] = useState(false);
|
||||
useEffect(() => {
|
||||
@@ -102,8 +100,12 @@ export function CallControls({ callEmbed }: CallControlsProps) {
|
||||
}, [shareConfirm]);
|
||||
const [pttMode] = useSetting(settingsAtom, 'pttMode');
|
||||
const [pttKey] = useSetting(settingsAtom, 'pttKey');
|
||||
const [deafenKey] = useSetting(settingsAtom, 'deafenKey');
|
||||
const [soundboardEnabled] = useSetting(settingsAtom, 'soundboardEnabled');
|
||||
// [Gitea #9] PTT/deafen key handling and AFK auto-mute live in useCallHotkeys
|
||||
// / useAfkAutoMute, mounted from CallEmbedProvider for the embed's lifetime
|
||||
// (this component only renders while the call room is selected). Only the
|
||||
// visual PTT chip remains here.
|
||||
const pttActive = useAtomValue(pttActiveAtom);
|
||||
|
||||
// [P5-31] Hard room publish policy — hide controls the server will refuse so
|
||||
// users don't click dead buttons. Absent/true = allowed.
|
||||
@@ -116,28 +118,6 @@ export function CallControls({ callEmbed }: CallControlsProps) {
|
||||
const showCamera = cameraAllowed || video;
|
||||
const showScreenshare = screenshareAllowed || screenshare;
|
||||
const showVideoGroup = showCamera || showScreenshare || !!document.fullscreenEnabled;
|
||||
const [pttActive, setPttActive] = useState(false);
|
||||
|
||||
// Track microphone via ref so the PTT effect doesn't need it as a dep (avoids listener churn)
|
||||
const microphoneRef = useRef(microphone);
|
||||
useEffect(() => {
|
||||
microphoneRef.current = microphone;
|
||||
}, [microphone]);
|
||||
|
||||
// Handle PTT mode toggle mid-call — save/restore mic state (I-4)
|
||||
const pttModeRef = useRef(pttMode);
|
||||
const micBeforePTTRef = useRef<boolean | null>(null);
|
||||
useEffect(() => {
|
||||
if (pttMode && !pttModeRef.current) {
|
||||
micBeforePTTRef.current = microphoneRef.current;
|
||||
callEmbed.control.setMicrophone(false);
|
||||
} else if (!pttMode && pttModeRef.current) {
|
||||
callEmbed.control.setMicrophone(micBeforePTTRef.current ?? true);
|
||||
micBeforePTTRef.current = null;
|
||||
}
|
||||
pttModeRef.current = pttMode;
|
||||
}, [pttMode, callEmbed]);
|
||||
|
||||
const handleOpenMenu: MouseEventHandler<HTMLButtonElement> = (evt) => {
|
||||
setCords(evt.currentTarget.getBoundingClientRect());
|
||||
};
|
||||
@@ -163,114 +143,6 @@ export function CallControls({ callEmbed }: CallControlsProps) {
|
||||
);
|
||||
const handleVideoToggle = useCallback(() => callEmbed.control.toggleVideo(), [callEmbed]);
|
||||
|
||||
const pttActiveRef = useRef(false);
|
||||
|
||||
useEffect(() => {
|
||||
if (!pttMode) return;
|
||||
const iframeWindow = callEmbed.iframe.contentWindow;
|
||||
|
||||
const onKeyDown = (e: KeyboardEvent) => {
|
||||
if (e.code !== pttKey || e.repeat) return;
|
||||
const target = e.target as HTMLElement;
|
||||
// BUG-7: use ownerDocument.body so isEditable works inside the EC iframe
|
||||
const isEditable = (el: HTMLElement): boolean => {
|
||||
const tag = el.tagName;
|
||||
if (tag === 'INPUT' || tag === 'TEXTAREA' || tag === 'SELECT') return true;
|
||||
let node: HTMLElement | null = el;
|
||||
while (node && node !== el.ownerDocument.body) {
|
||||
if (node.contentEditable === 'true') return true;
|
||||
if (node.contentEditable === 'false') return false;
|
||||
node = node.parentElement;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
if (isEditable(target)) return;
|
||||
e.preventDefault();
|
||||
// C-M5: mark PTT active BEFORE unmuting so the mic echo (onMediaState)
|
||||
// doesn't treat this transient unmute as a user-initiated undeafen.
|
||||
callEmbed.control.pttActive = true;
|
||||
if (!microphoneRef.current) callEmbed.control.setMicrophone(true);
|
||||
pttActiveRef.current = true;
|
||||
setPttActive(true);
|
||||
};
|
||||
const onKeyUp = (e: KeyboardEvent) => {
|
||||
if (e.code !== pttKey) return;
|
||||
callEmbed.control.pttActive = false;
|
||||
callEmbed.control.setMicrophone(false);
|
||||
pttActiveRef.current = false;
|
||||
setPttActive(false);
|
||||
};
|
||||
const onBlur = () => {
|
||||
callEmbed.control.pttActive = false;
|
||||
callEmbed.control.setMicrophone(false);
|
||||
pttActiveRef.current = false;
|
||||
setPttActive(false);
|
||||
};
|
||||
const onFocus = () => {
|
||||
callEmbed.control.pttActive = false;
|
||||
callEmbed.control.setMicrophone(false);
|
||||
pttActiveRef.current = false;
|
||||
setPttActive(false);
|
||||
};
|
||||
window.addEventListener('keydown', onKeyDown);
|
||||
window.addEventListener('keyup', onKeyUp);
|
||||
window.addEventListener('blur', onBlur);
|
||||
window.addEventListener('focus', onFocus);
|
||||
// BUG-9: also wire iframe blur/focus so stuck-mic release works when focus moves to iframe
|
||||
iframeWindow?.addEventListener('keydown', onKeyDown);
|
||||
iframeWindow?.addEventListener('keyup', onKeyUp);
|
||||
iframeWindow?.addEventListener('blur', onBlur);
|
||||
iframeWindow?.addEventListener('focus', onFocus);
|
||||
return () => {
|
||||
window.removeEventListener('keydown', onKeyDown);
|
||||
window.removeEventListener('keyup', onKeyUp);
|
||||
window.removeEventListener('blur', onBlur);
|
||||
window.removeEventListener('focus', onFocus);
|
||||
iframeWindow?.removeEventListener('keydown', onKeyDown);
|
||||
iframeWindow?.removeEventListener('keyup', onKeyUp);
|
||||
iframeWindow?.removeEventListener('blur', onBlur);
|
||||
iframeWindow?.removeEventListener('focus', onFocus);
|
||||
// BUG-8: if callEmbed changes while PTT is active, release mic on cleanup
|
||||
if (pttActiveRef.current) {
|
||||
callEmbed.control.pttActive = false;
|
||||
callEmbed.control.setMicrophone(false);
|
||||
pttActiveRef.current = false;
|
||||
setPttActive(false);
|
||||
}
|
||||
};
|
||||
// microphone intentionally read via microphoneRef — excluded from deps to avoid listener churn
|
||||
}, [pttMode, pttKey, callEmbed]);
|
||||
|
||||
useEffect(() => {
|
||||
const isEditable = (el: HTMLElement): boolean => {
|
||||
const tag = el.tagName;
|
||||
if (tag === 'INPUT' || tag === 'TEXTAREA' || tag === 'SELECT') return true;
|
||||
let node: HTMLElement | null = el;
|
||||
while (node && node !== el.ownerDocument.body) {
|
||||
if (node.contentEditable === 'true') return true;
|
||||
if (node.contentEditable === 'false') return false;
|
||||
node = node.parentElement;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
const onKeyDown = (e: KeyboardEvent) => {
|
||||
if (e.code !== deafenKey) return;
|
||||
if (e.repeat) return;
|
||||
if (isEditable(e.target as HTMLElement)) return;
|
||||
e.preventDefault();
|
||||
callEmbed.control.toggleSound();
|
||||
};
|
||||
// C-L4: also bind the EC iframe window so the deafen key works when focus is
|
||||
// inside the iframe (mirrors the PTT binding above).
|
||||
const iframeWindow = callEmbed.iframe.contentWindow;
|
||||
window.addEventListener('keydown', onKeyDown);
|
||||
iframeWindow?.addEventListener('keydown', onKeyDown);
|
||||
return () => {
|
||||
window.removeEventListener('keydown', onKeyDown);
|
||||
iframeWindow?.removeEventListener('keydown', onKeyDown);
|
||||
};
|
||||
}, [callEmbed, deafenKey]);
|
||||
|
||||
const [hangupState, hangup] = useAsyncCallback(
|
||||
useCallback(() => callEmbed.hangup(), [callEmbed]),
|
||||
);
|
||||
|
||||
@@ -18,8 +18,7 @@ import { useMatrixClient } from '../../hooks/useMatrixClient';
|
||||
import { StateEvent } from '../../../types/matrix/room';
|
||||
import { useCallMembers, useCallSession } from '../../hooks/useCall';
|
||||
import { LotusDecorationPusher } from '../lotus/LotusDecorationPusher';
|
||||
import { useStateEvent } from '../../hooks/useStateEvent';
|
||||
import { VoiceLimitContent } from '../common-settings/general/RoomVoiceLimit';
|
||||
import { useVoiceChannelFull } from '../../hooks/useVoiceChannelFull';
|
||||
import { CallMemberRenderer } from './CallMemberCard';
|
||||
import * as css from './styles.css';
|
||||
import { CallControls } from './CallControls';
|
||||
@@ -114,12 +113,9 @@ function CallPrescreen() {
|
||||
const callEmbed = useCallEmbed();
|
||||
const inOtherCall = callEmbed && callEmbed.roomId !== room.roomId;
|
||||
|
||||
// Voice channel user limit (io.lotus.voice_limit). 0 / absent means no limit.
|
||||
const limitEvent = useStateEvent(room, StateEvent.LotusVoiceLimit);
|
||||
const maxUsers = limitEvent?.getContent<VoiceLimitContent>().max_users ?? 0;
|
||||
// A user already counted in the session is rejoining and should not be blocked.
|
||||
const alreadyMember = callMembers.some((m) => m.sender === mx.getSafeUserId());
|
||||
const channelFull = maxUsers > 0 && !alreadyMember && callMembers.length >= maxUsers;
|
||||
// [Gitea #30] Voice channel user limit (io.lotus.voice_limit), shared with the
|
||||
// room-nav join path via useVoiceChannelFull so both agree on "full".
|
||||
const { channelFull, current: callMembersCount, max: maxUsers } = useVoiceChannelFull(room);
|
||||
|
||||
const canJoin = hasPermission && livekitSupported && rtcSupported && !channelFull;
|
||||
|
||||
@@ -144,7 +140,7 @@ function CallPrescreen() {
|
||||
<Box className={css.PrescreenMessage} alignItems="Center">
|
||||
{!inOtherCall && !hasPermission && <NoPermissionMessage />}
|
||||
{!inOtherCall && hasPermission && channelFull && (
|
||||
<ChannelFullMessage current={callMembers.length} max={maxUsers} />
|
||||
<ChannelFullMessage current={callMembersCount} max={maxUsers} />
|
||||
)}
|
||||
{!inOtherCall && hasPermission && !channelFull && (
|
||||
<JoinMessage
|
||||
|
||||
@@ -74,7 +74,8 @@ export function SoundButton({ enabled, onToggle }: SoundButtonProps) {
|
||||
size="400"
|
||||
className={MobileTouchTarget}
|
||||
onClick={() => onToggle()}
|
||||
aria-label={enabled ? 'Undeafen' : 'Deafen'}
|
||||
aria-label={enabled ? 'Deafen' : 'Undeafen'}
|
||||
aria-pressed={enabled}
|
||||
outlined
|
||||
>
|
||||
<Icon
|
||||
|
||||
@@ -58,6 +58,7 @@ export function DeveloperTools({ requestClose }: DeveloperToolsProps) {
|
||||
|
||||
const submitAccountData: AccountDataSubmitCallback = useCallback(
|
||||
async (type, content) => {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
await mx.setRoomAccountData(room.roomId, type as any, content);
|
||||
},
|
||||
[mx, room.roomId],
|
||||
|
||||
@@ -31,6 +31,7 @@ export function RoomRetention({ permissions }: RoomRetentionProps) {
|
||||
const content: RetentionContent = ms > 0 ? { max_lifetime: ms } : {};
|
||||
// Lotus custom-state convention: cast the type key (RoomRetention isn't a
|
||||
// typed key in the SDK's StateEvents map).
|
||||
|
||||
await sendStateEvent(mx, room.roomId, StateEvent.RoomRetention, content);
|
||||
},
|
||||
[mx, room.roomId],
|
||||
|
||||
Binary file not shown.
@@ -5,6 +5,7 @@ import {
|
||||
DECORATION_CATEGORIES,
|
||||
ALL_DECORATIONS,
|
||||
decorationUrl,
|
||||
isValidDecorationSlug,
|
||||
} from './avatarDecorations';
|
||||
|
||||
test('decorationUrl builds a CDN png url from the slug', () => {
|
||||
@@ -66,3 +67,20 @@ test('slugs use the snake_case charset (lowercase, digits, underscore)', () => {
|
||||
assert.match(decoration.slug, /^[a-z0-9_]+$/, `bad slug: ${decoration.slug}`);
|
||||
});
|
||||
});
|
||||
|
||||
test('isValidDecorationSlug: accepts a real catalog slug', () => {
|
||||
assert.equal(isValidDecorationSlug('joystick'), true);
|
||||
assert.equal(isValidDecorationSlug('lotus_flower'), true);
|
||||
});
|
||||
|
||||
test('isValidDecorationSlug: rejects a path-traversal string', () => {
|
||||
assert.equal(isValidDecorationSlug('../../anything'), false);
|
||||
});
|
||||
|
||||
test('isValidDecorationSlug: rejects a slug carrying a query string', () => {
|
||||
assert.equal(isValidDecorationSlug('joystick?u=probe'), false);
|
||||
});
|
||||
|
||||
test('isValidDecorationSlug: rejects an empty string', () => {
|
||||
assert.equal(isValidDecorationSlug(''), false);
|
||||
});
|
||||
|
||||
@@ -188,6 +188,19 @@ export const ALL_DECORATIONS: AvatarDecoration[] = DECORATION_CATEGORIES.flatMap
|
||||
(c) => c.decorations,
|
||||
);
|
||||
|
||||
const DECORATION_SLUGS = new Set(ALL_DECORATIONS.map((d) => d.slug));
|
||||
|
||||
/**
|
||||
* Whether `slug` is a known catalog decoration. `io.lotus.avatar_decoration`
|
||||
* is a free-form MSC4133 profile field set by a remote user (and their
|
||||
* homeserver), and its value is interpolated verbatim into `decorationUrl`
|
||||
* — so anything not in the catalog (path traversal, a query string, an
|
||||
* oversized value) must be rejected before it reaches a URL.
|
||||
*/
|
||||
export function isValidDecorationSlug(slug: string): boolean {
|
||||
return DECORATION_SLUGS.has(slug);
|
||||
}
|
||||
|
||||
export function decorationUrl(slug: string): string {
|
||||
return `${RESOLVED_DECORATION_CDN}/${slug}.png`;
|
||||
}
|
||||
|
||||
@@ -36,6 +36,7 @@ import { mDirectAtom } from '../../state/mDirectList';
|
||||
import { getStateEvent } from '../../utils/room';
|
||||
import { StateEvent } from '../../../types/matrix/room';
|
||||
import {
|
||||
filterGroupsByDateRange,
|
||||
filterGroupsByMsgType,
|
||||
filterGroupsByPinned,
|
||||
MessageSearchParams,
|
||||
@@ -316,12 +317,21 @@ export function MessageSearch({
|
||||
getNextPageParam: (lastPage) => lastPage.nextToken,
|
||||
});
|
||||
|
||||
// Shared client-side post-filter (msgtype + pinned) applied to BOTH the
|
||||
// server results and the local/encrypted-cache results, so the filter chips
|
||||
// narrow the whole UI consistently rather than only the server section.
|
||||
// Shared client-side post-filter (date range + msgtype + pinned) applied to
|
||||
// BOTH the server results and the local/encrypted-cache results, so the
|
||||
// filter chips narrow the whole UI consistently rather than only the
|
||||
// server section. The date range must be enforced here because the Matrix
|
||||
// search API has no timestamp filter fields (see useMessageSearch.ts); the
|
||||
// local/encrypted path already filters in-range before this runs, so this
|
||||
// is a no-op there and only actually trims the server section.
|
||||
const applyResultFilters = useCallback(
|
||||
(allGroups: ResultGroup[]): ResultGroup[] => {
|
||||
const byMsgType = filterGroupsByMsgType(allGroups, msgTypeFilters);
|
||||
const inDateRange = filterGroupsByDateRange(
|
||||
allGroups,
|
||||
msgSearchParams.fromTs,
|
||||
msgSearchParams.toTs,
|
||||
);
|
||||
const byMsgType = filterGroupsByMsgType(inDateRange, msgTypeFilters);
|
||||
if (!pinnedOnly) return byMsgType;
|
||||
// Build a per-room pinned-event lookup. Heavy Matrix reads stay here
|
||||
// (where `mx` is available); the pure helper only consumes the predicate.
|
||||
@@ -343,7 +353,7 @@ export function MessageSearch({
|
||||
};
|
||||
return filterGroupsByPinned(byMsgType, pinnedOnly, isPinned);
|
||||
},
|
||||
[msgTypeFilters, pinnedOnly, mx],
|
||||
[msgSearchParams.fromTs, msgSearchParams.toTs, msgTypeFilters, pinnedOnly, mx],
|
||||
);
|
||||
|
||||
const groups = useMemo(() => {
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
import { test } from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { SearchCacheRow } from '../../utils/searchCache';
|
||||
|
||||
// useLocalMessageSearch.ts imports searchCacheEnabledAtom, which touches
|
||||
// localStorage at module-load time (atomWithLocalStorage reads the initial
|
||||
// value eagerly). Stub it before a dynamic import — a static import would
|
||||
// hoist above the stub. Same pattern as state/plaintextCaches.test.ts.
|
||||
(globalThis as { localStorage?: unknown }).localStorage = {
|
||||
getItem: () => null,
|
||||
setItem: () => {},
|
||||
removeItem: () => {},
|
||||
};
|
||||
|
||||
const { rowToResultItem } = await import('./useLocalMessageSearch');
|
||||
|
||||
const row = (overrides: Partial<SearchCacheRow> = {}): SearchCacheRow => ({
|
||||
roomId: '!r1',
|
||||
eventId: '$1',
|
||||
ts: 100,
|
||||
sender: '@a',
|
||||
body: 'hello world',
|
||||
...overrides,
|
||||
});
|
||||
|
||||
// Gitea #14 — cached rows for a locally-known-redacted event must carry a
|
||||
// `redacted_because` marker so SearchResultGroup's guard renders the
|
||||
// "message deleted" placeholder instead of the stale plaintext.
|
||||
|
||||
test('rowToResultItem: plain row has no redacted_because marker', () => {
|
||||
const item = rowToResultItem(row());
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
assert.equal((item.event as any).unsigned?.redacted_because, undefined);
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
assert.equal((item.event as any).content.body, 'hello world');
|
||||
});
|
||||
|
||||
test('rowToResultItem: redacted=true sets the redacted_because marker', () => {
|
||||
const item = rowToResultItem(row(), true);
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
assert.ok((item.event as any).unsigned?.redacted_because);
|
||||
});
|
||||
|
||||
test('rowToResultItem: falls back to pollText when body is empty', () => {
|
||||
const item = rowToResultItem(row({ body: '', pollText: 'question answer' }));
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
assert.equal((item.event as any).content.body, 'question answer');
|
||||
});
|
||||
|
||||
test('rowToResultItem: carries formattedBody as HTML when present', () => {
|
||||
const item = rowToResultItem(row({ formattedBody: '<b>hi</b>' }));
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const content = (item.event as any).content;
|
||||
assert.equal(content.format, 'org.matrix.custom.html');
|
||||
assert.equal(content.formatted_body, '<b>hi</b>');
|
||||
});
|
||||
@@ -1,4 +1,4 @@
|
||||
import { EventType, MatrixEvent } from 'matrix-js-sdk';
|
||||
import { EventType, MatrixEvent, RelationType } from 'matrix-js-sdk';
|
||||
import { useCallback } from 'react';
|
||||
import { useAtomValue } from 'jotai';
|
||||
import { useMatrixClient } from '../../hooks/useMatrixClient';
|
||||
@@ -38,14 +38,17 @@ type ExtractedText = {
|
||||
const POLL_START_TYPES = ['m.poll.start', 'org.matrix.msc3381.poll.start'];
|
||||
|
||||
/**
|
||||
* Pull the text we index/search from a decrypted event's content. Returns
|
||||
* `null` for events that carry no searchable text (e.g. stickers).
|
||||
* Pull the text we index/search from an event type + content pair. Returns
|
||||
* `null` when there's no searchable text (e.g. stickers). Split out from
|
||||
* `extractText` so an edit's `m.new_content` can be run through the same
|
||||
* logic as a normal event's content.
|
||||
*/
|
||||
const extractText = (event: MatrixEvent): ExtractedText | null => {
|
||||
const evType = event.getType();
|
||||
const content = event.getContent();
|
||||
|
||||
const extractTextFromContent = (
|
||||
evType: string,
|
||||
content: Record<string, unknown>,
|
||||
): ExtractedText | null => {
|
||||
if (POLL_START_TYPES.includes(evType)) {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const poll = (content['m.poll'] ?? content['org.matrix.msc3381.poll.start']) as any;
|
||||
if (!poll) return null;
|
||||
const qBody =
|
||||
@@ -56,6 +59,7 @@ const extractText = (event: MatrixEvent): ExtractedText | null => {
|
||||
.map(
|
||||
(a) =>
|
||||
((a['m.text'] as Array<{ body: string }> | undefined)?.[0]?.body ??
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
(a['org.matrix.msc3381.poll.answer'] as any)?.body ??
|
||||
'') as string,
|
||||
)
|
||||
@@ -72,6 +76,13 @@ const extractText = (event: MatrixEvent): ExtractedText | null => {
|
||||
return { body, formattedBody, pollText: '' };
|
||||
};
|
||||
|
||||
/**
|
||||
* Pull the text we index/search from a decrypted event's content. Returns
|
||||
* `null` for events that carry no searchable text (e.g. stickers).
|
||||
*/
|
||||
const extractText = (event: MatrixEvent): ExtractedText | null =>
|
||||
extractTextFromContent(event.getType(), event.getContent());
|
||||
|
||||
/** Does the extracted text contain the (already-lowercased) term? */
|
||||
const matchesTerm = (text: ExtractedText, termLower: string): boolean =>
|
||||
text.body.toLowerCase().includes(termLower) ||
|
||||
@@ -83,8 +94,17 @@ const rowMatchesTerm = (row: SearchCacheRow, termLower: string): boolean =>
|
||||
(row.formattedBody ?? '').toLowerCase().includes(termLower) ||
|
||||
(row.pollText ?? '').toLowerCase().includes(termLower);
|
||||
|
||||
/** Build the synthetic result item a cached row renders as (text message). */
|
||||
const rowToResultItem = (row: SearchCacheRow): ResultItem => {
|
||||
/**
|
||||
* Build the synthetic result item a cached row renders as (text message).
|
||||
*
|
||||
* `redacted` marks a row whose event we can tell, from the local timeline,
|
||||
* has since been redacted (the async cache-delete listener in
|
||||
* `searchCacheInvalidation.ts` may not have caught up yet). It carries a
|
||||
* `redacted_because` marker on `unsigned` so `SearchResultGroup`'s existing
|
||||
* guard renders the "message deleted" placeholder instead of the stale
|
||||
* plaintext (Gitea #14).
|
||||
*/
|
||||
export const rowToResultItem = (row: SearchCacheRow, redacted = false): ResultItem => {
|
||||
const bodyText = row.body || row.pollText || '';
|
||||
const content: Record<string, unknown> = { msgtype: 'm.text', body: bodyText };
|
||||
if (row.formattedBody) {
|
||||
@@ -98,10 +118,11 @@ const rowToResultItem = (row: SearchCacheRow): ResultItem => {
|
||||
sender: row.sender,
|
||||
origin_server_ts: row.ts,
|
||||
content,
|
||||
unsigned: {},
|
||||
unsigned: redacted ? { redacted_because: { content: {} } } : {},
|
||||
};
|
||||
return {
|
||||
rank: 0,
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
event: syntheticEvent as any,
|
||||
context: { events_before: [], events_after: [], profile_info: {} },
|
||||
};
|
||||
@@ -184,8 +205,9 @@ export const useLocalMessageSearch = () => {
|
||||
const isMessageLike =
|
||||
evType === EventType.RoomMessage || POLL_START_TYPES.includes(evType);
|
||||
|
||||
// Sender-only mode indexes/returns all message types; text mode needs text.
|
||||
if (!senderOnlyMode && !isMessageLike && !isSticker) continue;
|
||||
// Both modes are restricted to message-like events/stickers — sender-only
|
||||
// mode must not surface membership/state/reaction/redaction events (Gitea #62).
|
||||
if (!isMessageLike && !isSticker) continue;
|
||||
|
||||
const sender = event.getSender() ?? '';
|
||||
const ts = event.getTs();
|
||||
@@ -193,16 +215,43 @@ export const useLocalMessageSearch = () => {
|
||||
|
||||
// Persist every indexable (text-bearing) event we scanned, regardless
|
||||
// of whether it matches the current term — future searches benefit.
|
||||
if (cacheEnabled && text && event.getId()) {
|
||||
rowsToPersist.push({
|
||||
roomId,
|
||||
eventId: event.getId() as string,
|
||||
ts,
|
||||
sender,
|
||||
body: text.body,
|
||||
...(text.formattedBody ? { formattedBody: text.formattedBody } : {}),
|
||||
...(text.pollText ? { pollText: text.pollText } : {}),
|
||||
});
|
||||
if (cacheEnabled && event.getId()) {
|
||||
// An edit (`m.replace`) event's own body is just a "* new text"
|
||||
// fallback. Indexing it under its own event id would leave two
|
||||
// separate matching rows (the stale pre-edit text and the edit
|
||||
// fallback) searchable forever. Instead, upsert the *original*
|
||||
// event's row with the edit's `m.new_content` (Gitea #14).
|
||||
const editTargetId =
|
||||
event.getRelation()?.rel_type === RelationType.Replace
|
||||
? event.getRelation()?.event_id
|
||||
: undefined;
|
||||
if (editTargetId) {
|
||||
const newContent = (event.getContent()['m.new_content'] ?? {}) as Record<
|
||||
string,
|
||||
unknown
|
||||
>;
|
||||
const editedText = extractTextFromContent(EventType.RoomMessage, newContent);
|
||||
if (editedText) {
|
||||
rowsToPersist.push({
|
||||
roomId,
|
||||
eventId: editTargetId,
|
||||
ts: room.findEventById(editTargetId)?.getTs() ?? ts,
|
||||
sender,
|
||||
body: editedText.body,
|
||||
...(editedText.formattedBody ? { formattedBody: editedText.formattedBody } : {}),
|
||||
});
|
||||
}
|
||||
} else if (text) {
|
||||
rowsToPersist.push({
|
||||
roomId,
|
||||
eventId: event.getId() as string,
|
||||
ts,
|
||||
sender,
|
||||
body: text.body,
|
||||
...(text.formattedBody ? { formattedBody: text.formattedBody } : {}),
|
||||
...(text.pollText ? { pollText: text.pollText } : {}),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (senderSet && !senderSet.has(sender)) continue;
|
||||
@@ -224,6 +273,7 @@ export const useLocalMessageSearch = () => {
|
||||
};
|
||||
memoryItems.push({
|
||||
rank: 0,
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
event: syntheticEvent as any,
|
||||
context: { events_before: [], events_after: [], profile_info: {} },
|
||||
});
|
||||
@@ -235,7 +285,12 @@ export const useLocalMessageSearch = () => {
|
||||
if (senderSet && !senderSet.has(row.sender)) return;
|
||||
if (!inRange(row.ts)) return;
|
||||
if (!senderOnlyMode && !rowMatchesTerm(row, termLower)) return;
|
||||
cachedItems.push(rowToResultItem(row));
|
||||
// The cache-delete listener (searchCacheInvalidation.ts) removes a
|
||||
// row on redaction asynchronously; if the event is still around
|
||||
// locally we can check for certain and must not surface stale
|
||||
// plaintext in the meantime (Gitea #14).
|
||||
const localEvent = room.findEventById(row.eventId);
|
||||
cachedItems.push(rowToResultItem(row, localEvent?.isRedacted()));
|
||||
});
|
||||
|
||||
const items = mergeSearchResults(memoryItems, cachedItems);
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
import { test } from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { filterGroupsByMsgType, filterGroupsByPinned, ResultGroup } from './useMessageSearch';
|
||||
import {
|
||||
filterGroupsByDateRange,
|
||||
filterGroupsByMsgType,
|
||||
filterGroupsByPinned,
|
||||
ResultGroup,
|
||||
} from './useMessageSearch';
|
||||
|
||||
// Minimal ResultGroup/ResultItem fixtures — only the fields the filters read
|
||||
// (event.content.msgtype, event.event_id, group.roomId).
|
||||
@@ -9,6 +14,11 @@ const item = (msgtype: string | undefined, eventId: string) => ({
|
||||
event: { event_id: eventId, content: msgtype === undefined ? {} : { msgtype } },
|
||||
context: {},
|
||||
});
|
||||
const tsItem = (eventId: string, ts: number) => ({
|
||||
rank: 1,
|
||||
event: { event_id: eventId, origin_server_ts: ts, content: {} },
|
||||
context: {},
|
||||
});
|
||||
const mkGroups = (
|
||||
...groups: { roomId: string; items: ReturnType<typeof item>[] }[]
|
||||
): ResultGroup[] => groups as unknown as ResultGroup[];
|
||||
@@ -48,6 +58,33 @@ test('filterGroupsByMsgType: ignores items with a non-string msgtype', () => {
|
||||
assert.equal(out[0].items[0].event.event_id, '$2');
|
||||
});
|
||||
|
||||
test('filterGroupsByDateRange: no bounds returns groups unchanged', () => {
|
||||
const groups = mkGroups({ roomId: '!r1', items: [tsItem('$1', 100)] });
|
||||
assert.equal(filterGroupsByDateRange(groups, undefined, undefined), groups);
|
||||
});
|
||||
|
||||
test('filterGroupsByDateRange: keeps only items within an inclusive range', () => {
|
||||
const groups = mkGroups({
|
||||
roomId: '!r1',
|
||||
items: [tsItem('$1', 50), tsItem('$2', 100), tsItem('$3', 150), tsItem('$4', 200)],
|
||||
});
|
||||
const out = filterGroupsByDateRange(groups, 100, 150);
|
||||
assert.deepEqual(
|
||||
out[0].items.map((i) => i.event.event_id),
|
||||
['$2', '$3'],
|
||||
);
|
||||
});
|
||||
|
||||
test('filterGroupsByDateRange: drops groups left empty and supports one-sided bounds', () => {
|
||||
const groups = mkGroups(
|
||||
{ roomId: '!r1', items: [tsItem('$1', 50)] },
|
||||
{ roomId: '!r2', items: [tsItem('$2', 500)] },
|
||||
);
|
||||
const out = filterGroupsByDateRange(groups, 100, undefined);
|
||||
assert.equal(out.length, 1);
|
||||
assert.equal(out[0].roomId, '!r2');
|
||||
});
|
||||
|
||||
test('filterGroupsByPinned: disabled returns groups unchanged', () => {
|
||||
const groups = mkGroups({ roomId: '!r1', items: [item('m.text', '$1')] });
|
||||
assert.equal(
|
||||
|
||||
@@ -71,6 +71,31 @@ export const filterGroupsByPinned = (
|
||||
.filter((group) => group.items.length > 0);
|
||||
};
|
||||
|
||||
/** Inclusive-range predicate, mirrored from `inRange` in useLocalMessageSearch.ts. */
|
||||
export const inTsRange = (ts: number, fromTs?: number, toTs?: number): boolean =>
|
||||
(fromTs === undefined || ts >= fromTs) && (toTs === undefined || ts <= toTs);
|
||||
|
||||
/**
|
||||
* Filter result groups to items whose `origin_server_ts` falls within
|
||||
* [fromTs, toTs] (inclusive, either bound optional). The Matrix search API
|
||||
* has no timestamp filter fields, so server results must be post-filtered
|
||||
* here — the same predicate the local/encrypted search already applies.
|
||||
* Now-empty groups are dropped.
|
||||
*/
|
||||
export const filterGroupsByDateRange = (
|
||||
groups: ResultGroup[],
|
||||
fromTs?: number,
|
||||
toTs?: number,
|
||||
): ResultGroup[] => {
|
||||
if (fromTs === undefined && toTs === undefined) return groups;
|
||||
return groups
|
||||
.map((group) => ({
|
||||
...group,
|
||||
items: group.items.filter((item) => inTsRange(item.event.origin_server_ts, fromTs, toTs)),
|
||||
}))
|
||||
.filter((group) => group.items.length > 0);
|
||||
};
|
||||
|
||||
const groupSearchResult = (results: ISearchResult[]): ResultGroup[] => {
|
||||
const groups: ResultGroup[] = [];
|
||||
|
||||
@@ -119,7 +144,9 @@ export type MessageSearchParams = {
|
||||
};
|
||||
export const useMessageSearch = (params: MessageSearchParams) => {
|
||||
const mx = useMatrixClient();
|
||||
const { term, order, rooms, senders, fromTs, toTs, containsUrl } = params;
|
||||
// fromTs/toTs are intentionally not sent to the server (see comment below) —
|
||||
// callers post-filter results with filterGroupsByDateRange instead.
|
||||
const { term, order, rooms, senders, containsUrl } = params;
|
||||
|
||||
const searchMessages = useCallback(
|
||||
async (nextBatch?: string) => {
|
||||
@@ -142,10 +169,12 @@ export const useMessageSearch = (params: MessageSearchParams) => {
|
||||
limit,
|
||||
rooms,
|
||||
senders,
|
||||
// from_ts / to_ts and contains_url are valid Matrix spec fields not yet in SDK types
|
||||
...(fromTs !== undefined && { from_ts: fromTs }),
|
||||
...(toTs !== undefined && { to_ts: toTs }),
|
||||
// `RoomEventFilter` has no timestamp bounds — from_ts/to_ts are not
|
||||
// Matrix filter fields and the homeserver silently drops them, so the
|
||||
// date range is instead enforced client-side (see filterGroupsByDateRange).
|
||||
// contains_url is a valid spec field not yet in SDK types.
|
||||
...(containsUrl !== undefined && { contains_url: containsUrl }),
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
} as any,
|
||||
include_state: false,
|
||||
order_by: order as SearchOrderBy.Recent,
|
||||
@@ -160,7 +189,7 @@ export const useMessageSearch = (params: MessageSearchParams) => {
|
||||
});
|
||||
return parseSearchResult(r);
|
||||
},
|
||||
[mx, term, order, rooms, senders, fromTs, toTs, containsUrl],
|
||||
[mx, term, order, rooms, senders, containsUrl],
|
||||
);
|
||||
|
||||
return searchMessages;
|
||||
|
||||
@@ -6,7 +6,7 @@ import React, {
|
||||
useRef,
|
||||
useState,
|
||||
} from 'react';
|
||||
import { MatrixClient, Room } from 'matrix-js-sdk';
|
||||
import { Room } from 'matrix-js-sdk';
|
||||
import {
|
||||
Avatar,
|
||||
Box,
|
||||
@@ -42,7 +42,6 @@ import { NavItem, NavItemContent, NavItemOptions, NavLink } from '../../componen
|
||||
import { UnreadBadge, UnreadBadgeCenter } from '../../components/unread-badge';
|
||||
import { RoomAvatar, RoomIcon } from '../../components/room-avatar';
|
||||
import { getDirectRoomAvatarUrl, getRoomAvatarUrl, getStateEvent } from '../../utils/room';
|
||||
import { setAccountData } from '../../utils/accountData';
|
||||
import { nameInitials } from '../../utils/common';
|
||||
import { useMatrixClient } from '../../hooks/useMatrixClient';
|
||||
import { useRoomUnread } from '../../state/hooks/unread';
|
||||
@@ -66,19 +65,22 @@ import { useSpaceOptionally } from '../../hooks/useSpace';
|
||||
import {
|
||||
getRoomNotificationModeIcon,
|
||||
RoomNotificationMode,
|
||||
setRoomNotificationPreference,
|
||||
} from '../../hooks/useRoomsNotificationPreferences';
|
||||
import { RoomNotificationModeSwitcher } from '../../components/RoomNotificationSwitcher';
|
||||
import { scheduleMuteTimer, unmuteRoom } from './muteTimers';
|
||||
import { getRoomCreatorsForRoomId, useRoomCreators } from '../../hooks/useRoomCreators';
|
||||
import { getRoomPermissionsAPI, useRoomPermissions } from '../../hooks/useRoomPermissions';
|
||||
import { InviteUserPrompt } from '../../components/invite-user-prompt';
|
||||
import {
|
||||
LOCAL_ROOM_NAMES_KEY,
|
||||
getLocalRoomNamesContent,
|
||||
setLocalRoomName,
|
||||
useHasLocalRoomName,
|
||||
useLocalRoomName,
|
||||
} from '../../hooks/useRoomMeta';
|
||||
import { useCallMembers, useCallSession } from '../../hooks/useCall';
|
||||
import { useCallEmbed, useCallStart } from '../../hooks/useCallEmbed';
|
||||
import { useVoiceChannelFull } from '../../hooks/useVoiceChannelFull';
|
||||
import { callChatAtom } from '../../state/callEmbed';
|
||||
import { createErrorToast, toastQueueAtom } from '../../state/toast';
|
||||
import { useCallPreferencesAtom } from '../../state/hooks/callPreferences';
|
||||
@@ -136,22 +138,16 @@ function RenameRoomDialog({ room, onClose }: RenameRoomDialogProps) {
|
||||
const handleSave = useCallback(() => {
|
||||
const newName = inputRef.current?.value.trim() ?? '';
|
||||
if (newName.length > 255) return;
|
||||
const existing = getLocalRoomNamesContent(mx);
|
||||
if (newName === '') {
|
||||
const { [room.roomId]: _removed, ...rest } = existing.rooms;
|
||||
setAccountData(mx, LOCAL_ROOM_NAMES_KEY, { rooms: rest });
|
||||
} else {
|
||||
setAccountData(mx, LOCAL_ROOM_NAMES_KEY, {
|
||||
rooms: { ...existing.rooms, [room.roomId]: newName },
|
||||
});
|
||||
}
|
||||
// Routed through the shared write queue (setLocalRoomName) instead of a
|
||||
// read-modify-write against the SDK's local cache, which stays stale
|
||||
// until the /sync echo lands and would otherwise let a second rename
|
||||
// clobber a still-in-flight first rename.
|
||||
setLocalRoomName(mx, room.roomId, newName);
|
||||
onClose();
|
||||
}, [mx, room.roomId, onClose]);
|
||||
|
||||
const handleClear = useCallback(() => {
|
||||
const existing = getLocalRoomNamesContent(mx);
|
||||
const { [room.roomId]: _removed, ...rest } = existing.rooms;
|
||||
setAccountData(mx, LOCAL_ROOM_NAMES_KEY, { rooms: rest });
|
||||
setLocalRoomName(mx, room.roomId, '');
|
||||
onClose();
|
||||
}, [mx, room.roomId, onClose]);
|
||||
|
||||
@@ -273,49 +269,6 @@ function RenameRoomDialog({ room, onClose }: RenameRoomDialogProps) {
|
||||
);
|
||||
}
|
||||
|
||||
// localStorage key for timed mute timers
|
||||
export const MUTE_TIMERS_KEY = 'io.lotus.mute_timers';
|
||||
|
||||
// setTimeout's delay is a signed 32-bit int; larger values overflow and fire
|
||||
// immediately. Clamp long delays to this max (~24.8 days).
|
||||
export const MAX_MUTE_TIMEOUT_MS = 2_147_483_647;
|
||||
|
||||
export type MuteTimerEntry = { roomId: string; unmuteAt: number };
|
||||
|
||||
export function loadMuteTimers(): MuteTimerEntry[] {
|
||||
try {
|
||||
const parsed = JSON.parse(localStorage.getItem(MUTE_TIMERS_KEY) ?? '[]');
|
||||
return Array.isArray(parsed) ? parsed : [];
|
||||
} catch {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
export function saveMuteTimers(timers: MuteTimerEntry[]): void {
|
||||
localStorage.setItem(MUTE_TIMERS_KEY, JSON.stringify(timers));
|
||||
}
|
||||
|
||||
// Reverse a timed mute: restore the room's notification mode to Unset and drop
|
||||
// its persisted timer. Shared by the in-session timer and the boot-time restore.
|
||||
export async function unmuteRoom(mx: MatrixClient, roomId: string): Promise<void> {
|
||||
const { setRoomNotificationPreference } =
|
||||
await import('../../hooks/useRoomsNotificationPreferences');
|
||||
await setRoomNotificationPreference(
|
||||
mx,
|
||||
roomId,
|
||||
RoomNotificationMode.Unset,
|
||||
RoomNotificationMode.Mute,
|
||||
).catch(() => {});
|
||||
saveMuteTimers(loadMuteTimers().filter((e) => e.roomId !== roomId));
|
||||
}
|
||||
|
||||
function scheduleMuteTimer(roomId: string, durationMs: number, onUnmute: () => void): void {
|
||||
const unmuteAt = Date.now() + durationMs;
|
||||
const existing = loadMuteTimers().filter((e) => e.roomId !== roomId);
|
||||
saveMuteTimers([...existing, { roomId, unmuteAt }]);
|
||||
setTimeout(onUnmute, Math.min(durationMs, MAX_MUTE_TIMEOUT_MS));
|
||||
}
|
||||
|
||||
type RoomNavItemMenuProps = {
|
||||
room: Room;
|
||||
requestClose: () => void;
|
||||
@@ -392,8 +345,6 @@ const RoomNavItemMenu = forwardRef<HTMLDivElement, RoomNavItemMenuProps>(
|
||||
|
||||
const handleMuteFor = useCallback(
|
||||
async (durationMs: number | null) => {
|
||||
const { setRoomNotificationPreference } =
|
||||
await import('../../hooks/useRoomsNotificationPreferences');
|
||||
const prevMode = notificationMode ?? RoomNotificationMode.Unset;
|
||||
await setRoomNotificationPreference(
|
||||
mx,
|
||||
@@ -741,8 +692,12 @@ function RoomNavItem_({
|
||||
const callMembers = useCallMembers(callSession);
|
||||
const startCall = useCallStart(direct);
|
||||
const callEmbed = useCallEmbed();
|
||||
// [Gitea #30] Same voice-limit check the call prescreen uses, so the sidebar
|
||||
// second-click join path can't bypass a full channel.
|
||||
const { channelFull, current: voiceCurrent, max: voiceMax } = useVoiceChannelFull(room);
|
||||
const callPref = useAtomValue(useCallPreferencesAtom());
|
||||
const autoDiscoveryInfo = useAutoDiscoveryInfo();
|
||||
const setToast = useSetAtom(toastQueueAtom);
|
||||
|
||||
const handleStartCall: MouseEventHandler<HTMLAnchorElement> = (evt) => {
|
||||
const powerLevelsEvent = getStateEvent(room, StateEvent.RoomPowerLevels);
|
||||
@@ -764,6 +719,22 @@ function RoomNavItem_({
|
||||
if (callEmbed) {
|
||||
return;
|
||||
}
|
||||
|
||||
// [Gitea #30] Refuse to start a call into a full voice channel — the
|
||||
// prescreen already blocks this, but the sidebar second-click join path
|
||||
// skipped the check entirely.
|
||||
if (channelFull) {
|
||||
evt.preventDefault();
|
||||
setToast(
|
||||
createErrorToast(
|
||||
`Channel full (${voiceCurrent}/${voiceMax})`,
|
||||
Icons.Warning,
|
||||
'Cannot join',
|
||||
),
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
// Start call in second click
|
||||
if (selected) {
|
||||
evt.preventDefault();
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
import { test } from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { RoomNotificationMode } from '../../hooks/useRoomsNotificationPreferences';
|
||||
import { shouldResetMuteOnUnmute } from './muteTimers';
|
||||
|
||||
test('resets to Unset when the room is still Mute at expiry', () => {
|
||||
assert.equal(shouldResetMuteOnUnmute(RoomNotificationMode.Mute), true);
|
||||
});
|
||||
|
||||
test('does not reset when the user switched to All messages during the mute window', () => {
|
||||
assert.equal(shouldResetMuteOnUnmute(RoomNotificationMode.AllMessages), false);
|
||||
});
|
||||
|
||||
test('does not reset when the user switched to Special messages during the mute window', () => {
|
||||
assert.equal(shouldResetMuteOnUnmute(RoomNotificationMode.SpecialMessages), false);
|
||||
});
|
||||
|
||||
test('does not reset when the mode is already Unset', () => {
|
||||
assert.equal(shouldResetMuteOnUnmute(RoomNotificationMode.Unset), false);
|
||||
});
|
||||
@@ -0,0 +1,88 @@
|
||||
import { IPushRule, IPushRules, MatrixClient } from 'matrix-js-sdk';
|
||||
import { AccountDataEvent } from '../../../types/matrix/accountData';
|
||||
import { getAccountData } from '../../utils/room';
|
||||
import { getNotificationMode, NotificationMode } from '../../hooks/useNotificationMode';
|
||||
import {
|
||||
RoomNotificationMode,
|
||||
setRoomNotificationPreference,
|
||||
} from '../../hooks/useRoomsNotificationPreferences';
|
||||
|
||||
// localStorage key for timed mute timers
|
||||
export const MUTE_TIMERS_KEY = 'io.lotus.mute_timers';
|
||||
|
||||
// setTimeout's delay is a signed 32-bit int; larger values overflow and fire
|
||||
// immediately. Clamp long delays to this max (~24.8 days).
|
||||
export const MAX_MUTE_TIMEOUT_MS = 2_147_483_647;
|
||||
|
||||
export type MuteTimerEntry = { roomId: string; unmuteAt: number };
|
||||
|
||||
export function loadMuteTimers(): MuteTimerEntry[] {
|
||||
try {
|
||||
const parsed = JSON.parse(localStorage.getItem(MUTE_TIMERS_KEY) ?? '[]');
|
||||
return Array.isArray(parsed) ? parsed : [];
|
||||
} catch {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
export function saveMuteTimers(timers: MuteTimerEntry[]): void {
|
||||
localStorage.setItem(MUTE_TIMERS_KEY, JSON.stringify(timers));
|
||||
}
|
||||
|
||||
// Pure decision for the unmute guard: a timed mute should only be reset back to
|
||||
// Unset if the room's notification mode is still Mute at expiry time. If the user
|
||||
// manually changed it (e.g. to All messages) while the timer was pending, leave
|
||||
// their choice alone — just let the stale timer entry get dropped.
|
||||
export function shouldResetMuteOnUnmute(currentMode: RoomNotificationMode): boolean {
|
||||
return currentMode === RoomNotificationMode.Mute;
|
||||
}
|
||||
|
||||
// Reads the room's live notification mode straight from account data push rules,
|
||||
// mirroring useRoomsNotificationPreferences' per-room derivation, without needing
|
||||
// the React hook (this runs from plain timers/effects, not components).
|
||||
export function getLiveRoomNotificationMode(
|
||||
mx: MatrixClient,
|
||||
roomId: string,
|
||||
): RoomNotificationMode {
|
||||
const pushRules = getAccountData(mx, AccountDataEvent.PushRules)?.getContent<IPushRules>();
|
||||
const global = pushRules?.global;
|
||||
|
||||
const overrideRule = global?.override?.find((rule: IPushRule) => rule.rule_id === roomId);
|
||||
if (overrideRule && getNotificationMode(overrideRule.actions) === NotificationMode.OFF) {
|
||||
return RoomNotificationMode.Mute;
|
||||
}
|
||||
|
||||
const roomRule = global?.room?.find((rule: IPushRule) => rule.rule_id === roomId);
|
||||
if (roomRule) {
|
||||
return getNotificationMode(roomRule.actions) === NotificationMode.OFF
|
||||
? RoomNotificationMode.SpecialMessages
|
||||
: RoomNotificationMode.AllMessages;
|
||||
}
|
||||
|
||||
return RoomNotificationMode.Unset;
|
||||
}
|
||||
|
||||
// Reverse a timed mute: restore the room's notification mode to Unset and drop
|
||||
// its persisted timer. Shared by the in-session timer and the boot-time restore.
|
||||
// Only resets the mode if it is still Mute — otherwise a manual change made
|
||||
// during the mute window (e.g. switching to "All messages") would silently get
|
||||
// reverted when the stale timer fires.
|
||||
export async function unmuteRoom(mx: MatrixClient, roomId: string): Promise<void> {
|
||||
const currentMode = getLiveRoomNotificationMode(mx, roomId);
|
||||
if (shouldResetMuteOnUnmute(currentMode)) {
|
||||
await setRoomNotificationPreference(
|
||||
mx,
|
||||
roomId,
|
||||
RoomNotificationMode.Unset,
|
||||
RoomNotificationMode.Mute,
|
||||
).catch(() => {});
|
||||
}
|
||||
saveMuteTimers(loadMuteTimers().filter((e) => e.roomId !== roomId));
|
||||
}
|
||||
|
||||
export function scheduleMuteTimer(roomId: string, durationMs: number, onUnmute: () => void): void {
|
||||
const unmuteAt = Date.now() + durationMs;
|
||||
const existing = loadMuteTimers().filter((e) => e.roomId !== roomId);
|
||||
saveMuteTimers([...existing, { roomId, unmuteAt }]);
|
||||
setTimeout(onUnmute, Math.min(durationMs, MAX_MUTE_TIMEOUT_MS));
|
||||
}
|
||||
@@ -7,6 +7,7 @@ import { useRoom } from '../../hooks/useRoom';
|
||||
import { useRoomName } from '../../hooks/useRoomMeta';
|
||||
import { SequenceCard } from '../../components/sequence-card';
|
||||
import { SequenceCardStyle } from '../common-settings/styles.css';
|
||||
import { RawExportRecord, formatExportBody, resolveMessageEdits } from './exportRoomHistory.utils';
|
||||
|
||||
type ExportFormat = 'txt' | 'json' | 'html';
|
||||
|
||||
@@ -63,15 +64,11 @@ export function ExportRoomHistory({ requestClose }: ExportRoomHistoryProps) {
|
||||
const fromTs = fromDate ? new Date(`${fromDate}T00:00:00`).getTime() : null;
|
||||
const toTs = toDate ? new Date(`${toDate}T23:59:59`).getTime() : null;
|
||||
|
||||
type MsgRecord = {
|
||||
ts: number;
|
||||
sender: string;
|
||||
body: string;
|
||||
eventId: string;
|
||||
msgtype: string;
|
||||
};
|
||||
|
||||
const collected: MsgRecord[] = [];
|
||||
const rawRecords: RawExportRecord[] = [];
|
||||
// mxc/media-file URL for message events that carry one, keyed by eventId -
|
||||
// surfaced in the JSON export since the export never includes the actual
|
||||
// media (see the UI note below the Export button).
|
||||
const mediaUrlByEventId = new Map<string, string>();
|
||||
// timeline.getEvents() returns the entire growing window on every call,
|
||||
// so we must deduplicate by eventId to avoid re-adding the same events
|
||||
// on each pagination step.
|
||||
@@ -113,11 +110,39 @@ export function ExportRoomHistory({ requestClose }: ExportRoomHistoryProps) {
|
||||
if (fromTs !== null && ts < fromTs) continue;
|
||||
if (toTs !== null && ts > toTs) continue;
|
||||
const content = ev.getContent();
|
||||
|
||||
// m.replace (edit) events must not become their own row — collect
|
||||
// them separately and substitute the new content into the original
|
||||
// event's row below, instead of adding a stale original + a garbled
|
||||
// "* new text" duplicate line.
|
||||
const relatesTo = content['m.relates_to'] as
|
||||
| { rel_type?: string; event_id?: string }
|
||||
| undefined;
|
||||
if (relatesTo?.rel_type === 'm.replace' && relatesTo.event_id) {
|
||||
const newContent = content['m.new_content'] as { body?: string } | undefined;
|
||||
const newBody = newContent?.body ?? '';
|
||||
if (!newBody) continue;
|
||||
rawRecords.push({
|
||||
eventId: evId,
|
||||
ts,
|
||||
sender: ev.getSender() ?? '',
|
||||
body: '',
|
||||
msgtype: '',
|
||||
editsEventId: relatesTo.event_id,
|
||||
newBody,
|
||||
});
|
||||
continue;
|
||||
}
|
||||
|
||||
const body: string = content.body ?? '';
|
||||
const msgtype: string = content.msgtype ?? '';
|
||||
if (!body) continue;
|
||||
if (ts < oldestTs) oldestTs = ts;
|
||||
collected.push({
|
||||
const mediaUrl =
|
||||
(content.url as string | undefined) ??
|
||||
(content.file as { url?: string } | undefined)?.url;
|
||||
if (mediaUrl) mediaUrlByEventId.set(evId, mediaUrl);
|
||||
rawRecords.push({
|
||||
ts,
|
||||
sender: ev.getSender() ?? '',
|
||||
body,
|
||||
@@ -125,7 +150,9 @@ export function ExportRoomHistory({ requestClose }: ExportRoomHistoryProps) {
|
||||
msgtype,
|
||||
});
|
||||
}
|
||||
setExportCount(collected.length);
|
||||
// Approximate progress — excludes edit rows, which never become their
|
||||
// own line in the final (edit-resolved) output.
|
||||
setExportCount(rawRecords.filter((r) => !r.editsEventId).length);
|
||||
};
|
||||
|
||||
await addEvents(timeline.getEvents());
|
||||
@@ -159,6 +186,10 @@ export function ExportRoomHistory({ requestClose }: ExportRoomHistoryProps) {
|
||||
await addEvents(timeline.getEvents());
|
||||
}
|
||||
|
||||
// Resolve m.replace edits against their target row (drops the edit rows,
|
||||
// substitutes m.new_content into the original) before sorting/rendering.
|
||||
const collected = resolveMessageEdits(rawRecords);
|
||||
|
||||
if (cancelled) {
|
||||
setNotice(`Export cancelled after ${collected.length} messages.`);
|
||||
return;
|
||||
@@ -186,7 +217,7 @@ export function ExportRoomHistory({ requestClose }: ExportRoomHistoryProps) {
|
||||
const d = new Date(msg.ts);
|
||||
const pad = (n: number) => String(n).padStart(2, '0');
|
||||
const dateLabel = `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())} ${pad(d.getHours())}:${pad(d.getMinutes())}`;
|
||||
lines.push(`[${dateLabel}] ${msg.sender}: ${msg.body}`);
|
||||
lines.push(`[${dateLabel}] ${msg.sender}: ${formatExportBody(msg)}`);
|
||||
}
|
||||
content = lines.join('\n');
|
||||
mimeType = 'text/plain';
|
||||
@@ -201,6 +232,8 @@ export function ExportRoomHistory({ requestClose }: ExportRoomHistoryProps) {
|
||||
body: m.body,
|
||||
eventId: m.eventId,
|
||||
type: m.msgtype,
|
||||
edited: m.edited,
|
||||
mediaUrl: mediaUrlByEventId.get(m.eventId),
|
||||
})),
|
||||
};
|
||||
content = JSON.stringify(payload, null, 2);
|
||||
@@ -220,7 +253,7 @@ export function ExportRoomHistory({ requestClose }: ExportRoomHistoryProps) {
|
||||
const d = new Date(msg.ts);
|
||||
const pad = (n: number) => String(n).padStart(2, '0');
|
||||
const dateLabel = `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())} ${pad(d.getHours())}:${pad(d.getMinutes())}`;
|
||||
return `<div class="msg"><span class="ts">[${esc(dateLabel)}]</span> <span class="sender">${esc(msg.sender)}</span><span class="body">: ${esc(msg.body)}</span></div>`;
|
||||
return `<div class="msg"><span class="ts">[${esc(dateLabel)}]</span> <span class="sender">${esc(msg.sender)}</span><span class="body">: ${esc(formatExportBody(msg))}</span></div>`;
|
||||
})
|
||||
.join('\n');
|
||||
|
||||
@@ -388,6 +421,11 @@ ${msgRows}
|
||||
{notice}
|
||||
</Text>
|
||||
)}
|
||||
<Text size="T200" priority="300">
|
||||
Attachments (images, videos, audio, files) are not included in the export -
|
||||
media messages are marked with a type label (e.g. "[Image]") but only
|
||||
their filename is exported, not the file itself.
|
||||
</Text>
|
||||
</SequenceCard>
|
||||
</Box>
|
||||
</Box>
|
||||
|
||||
@@ -24,6 +24,14 @@ const POLICY_USER_EVENT = 'm.policy.rule.user';
|
||||
const POLICY_ROOM_EVENT = 'm.policy.rule.room';
|
||||
const POLICY_SERVER_EVENT = 'm.policy.rule.server';
|
||||
|
||||
// Legacy, unstable-prefixed event types still emitted by Draupnir/Mjolnir
|
||||
// policy lists that predate MSC stabilization (or haven't migrated). Queried
|
||||
// alongside the stable types and merged/de-duped so those lists don't show
|
||||
// as falsely empty.
|
||||
const LEGACY_POLICY_USER_EVENT = 'org.matrix.mjolnir.rule.user';
|
||||
const LEGACY_POLICY_ROOM_EVENT = 'org.matrix.mjolnir.rule.room';
|
||||
const LEGACY_POLICY_SERVER_EVENT = 'org.matrix.mjolnir.rule.server';
|
||||
|
||||
type PolicyRuleContent = {
|
||||
entity?: string;
|
||||
reason?: string;
|
||||
@@ -76,6 +84,23 @@ function extractPolicyEntries(events: MatrixEvent[]): PolicyEntry[] {
|
||||
.filter((entry) => entry.entity !== '');
|
||||
}
|
||||
|
||||
/**
|
||||
* Merge policy entries from the stable and legacy event types for a rule
|
||||
* kind, de-duplicating by entity+recommendation so a room that emits both a
|
||||
* stable and a legacy rule for the same target isn't double-listed.
|
||||
*/
|
||||
export function dedupePolicyEntries(entries: PolicyEntry[]): PolicyEntry[] {
|
||||
const seen = new Set<string>();
|
||||
const result: PolicyEntry[] = [];
|
||||
entries.forEach((entry) => {
|
||||
const key = `${entry.entity} ${entry.recommendation}`;
|
||||
if (seen.has(key)) return;
|
||||
seen.add(key);
|
||||
result.push(entry);
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
// ── Entry row ─────────────────────────────────────────────────────────────────
|
||||
|
||||
function PolicyEntryRow({ entry }: { entry: PolicyEntry }) {
|
||||
@@ -201,9 +226,24 @@ export function PolicyListViewer({ requestClose }: PolicyListViewerProps) {
|
||||
return;
|
||||
}
|
||||
|
||||
setUserEntries(extractPolicyEntries(getRoomPolicyEvents(room, POLICY_USER_EVENT)));
|
||||
setRoomEntries(extractPolicyEntries(getRoomPolicyEvents(room, POLICY_ROOM_EVENT)));
|
||||
setServerEntries(extractPolicyEntries(getRoomPolicyEvents(room, POLICY_SERVER_EVENT)));
|
||||
setUserEntries(
|
||||
dedupePolicyEntries([
|
||||
...extractPolicyEntries(getRoomPolicyEvents(room, POLICY_USER_EVENT)),
|
||||
...extractPolicyEntries(getRoomPolicyEvents(room, LEGACY_POLICY_USER_EVENT)),
|
||||
]),
|
||||
);
|
||||
setRoomEntries(
|
||||
dedupePolicyEntries([
|
||||
...extractPolicyEntries(getRoomPolicyEvents(room, POLICY_ROOM_EVENT)),
|
||||
...extractPolicyEntries(getRoomPolicyEvents(room, LEGACY_POLICY_ROOM_EVENT)),
|
||||
]),
|
||||
);
|
||||
setServerEntries(
|
||||
dedupePolicyEntries([
|
||||
...extractPolicyEntries(getRoomPolicyEvents(room, POLICY_SERVER_EVENT)),
|
||||
...extractPolicyEntries(getRoomPolicyEvents(room, LEGACY_POLICY_SERVER_EVENT)),
|
||||
]),
|
||||
);
|
||||
setLoadedRoomId(roomId);
|
||||
setError(undefined);
|
||||
}, [mx, roomIdInput]);
|
||||
|
||||
@@ -63,8 +63,26 @@ function describeEvent(mx: ReturnType<typeof useMatrixClient>, ev: MatrixEvent):
|
||||
const prevMembership = prevContent.membership as string | undefined;
|
||||
const reason = content.reason as string | undefined;
|
||||
const targetName = getDisplayName(mx, stateKey);
|
||||
// getPrevContent() falls back to {} when unsigned.prev_content is missing,
|
||||
// which is common for state events fetched via back-pagination (homeservers
|
||||
// don't always include it in /messages). That makes prevMembership
|
||||
// indistinguishable from "no prior membership" (fresh join). Check the raw
|
||||
// unsigned field so we only apply the join/leave-transition assumptions
|
||||
// below to events where the SDK actually gave us prior state.
|
||||
const hasPrevContent = ev.getUnsigned().prev_content !== undefined;
|
||||
|
||||
if (membership === 'join') {
|
||||
if (!hasPrevContent) {
|
||||
return {
|
||||
text: (
|
||||
<>
|
||||
<strong>{targetName}</strong>'s membership changed to <strong>joined</strong>
|
||||
</>
|
||||
),
|
||||
iconSrc: Icons.User,
|
||||
filter: 'members',
|
||||
};
|
||||
}
|
||||
if (
|
||||
prevMembership === 'invite' ||
|
||||
prevMembership === 'knock' ||
|
||||
@@ -94,6 +112,17 @@ function describeEvent(mx: ReturnType<typeof useMatrixClient>, ev: MatrixEvent):
|
||||
}
|
||||
|
||||
if (membership === 'leave') {
|
||||
if (!hasPrevContent) {
|
||||
return {
|
||||
text: (
|
||||
<>
|
||||
<strong>{targetName}</strong>'s membership changed to <strong>left</strong>
|
||||
</>
|
||||
),
|
||||
iconSrc: Icons.User,
|
||||
filter: 'members',
|
||||
};
|
||||
}
|
||||
if (prevMembership === 'ban') {
|
||||
return {
|
||||
text: (
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import React, { useMemo } from 'react';
|
||||
import React, { useCallback, useEffect, useMemo, useState } from 'react';
|
||||
import { Avatar, Box, Icon, IconButton, Icons, IconSrc, Scroll, Text, color, config } from 'folds';
|
||||
import { EventType } from 'matrix-js-sdk';
|
||||
import { EventType, MatrixEvent, Room, RoomEvent } from 'matrix-js-sdk';
|
||||
import { Page, PageContent, PageHeader } from '../../components/page';
|
||||
import { SequenceCard } from '../../components/sequence-card';
|
||||
import { useRoom } from '../../hooks/useRoom';
|
||||
@@ -20,6 +20,15 @@ function formatDate(ts: number): string {
|
||||
});
|
||||
}
|
||||
|
||||
function formatUpdatedAt(ts: number): string {
|
||||
return new Date(ts).toLocaleTimeString(undefined, { hour: 'numeric', minute: '2-digit' });
|
||||
}
|
||||
|
||||
// Throttle window for re-computing stats on new timeline events - avoids
|
||||
// re-running every heatmap/list computation on every single incoming message
|
||||
// during a burst.
|
||||
const RECOMPUTE_THROTTLE_MS = 2000;
|
||||
|
||||
// ── Section header ────────────────────────────────────────────────────────────
|
||||
|
||||
function SectionHeader({ label }: { label: string }) {
|
||||
@@ -69,6 +78,52 @@ export function RoomInsights({ requestClose }: RoomInsightsProps) {
|
||||
const room = useRoom();
|
||||
const useAuthentication = useMediaAuthentication();
|
||||
|
||||
const [lastUpdated, setLastUpdated] = useState(() => Date.now());
|
||||
// Bumped to force the stats useMemo below to re-run; the value itself is unused.
|
||||
const [recomputeTick, setRecomputeTick] = useState(0);
|
||||
|
||||
const recomputeNow = useCallback(() => {
|
||||
setRecomputeTick((n) => n + 1);
|
||||
setLastUpdated(Date.now());
|
||||
}, []);
|
||||
|
||||
// Stats were previously computed once (keyed only on `room`, whose reference
|
||||
// never changes) and never reflected new activity while the panel stayed
|
||||
// open. Re-run on new timeline events for this room, throttled so a burst of
|
||||
// messages doesn't recompute on every single event.
|
||||
useEffect(() => {
|
||||
let throttleTimer: ReturnType<typeof setTimeout> | undefined;
|
||||
let pending = false;
|
||||
|
||||
const scheduleTrailing = () => {
|
||||
throttleTimer = setTimeout(() => {
|
||||
if (pending) {
|
||||
pending = false;
|
||||
recomputeNow();
|
||||
scheduleTrailing();
|
||||
} else {
|
||||
throttleTimer = undefined;
|
||||
}
|
||||
}, RECOMPUTE_THROTTLE_MS);
|
||||
};
|
||||
|
||||
const handleTimeline = (_event: MatrixEvent, eventRoom: Room | undefined) => {
|
||||
if (eventRoom?.roomId !== room.roomId) return;
|
||||
if (throttleTimer) {
|
||||
pending = true;
|
||||
return;
|
||||
}
|
||||
recomputeNow();
|
||||
scheduleTrailing();
|
||||
};
|
||||
|
||||
mx.on(RoomEvent.Timeline, handleTimeline);
|
||||
return () => {
|
||||
mx.removeListener(RoomEvent.Timeline, handleTimeline);
|
||||
if (throttleTimer) clearTimeout(throttleTimer);
|
||||
};
|
||||
}, [mx, room, recomputeNow]);
|
||||
|
||||
const stats = useMemo(() => {
|
||||
const events = room.getLiveTimeline().getEvents();
|
||||
|
||||
@@ -137,7 +192,10 @@ export function RoomInsights({ requestClose }: RoomInsightsProps) {
|
||||
newestTs,
|
||||
totalCached: events.length,
|
||||
};
|
||||
}, [room]);
|
||||
// recomputeTick is intentionally in the deps (unused in the body) - it's the
|
||||
// signal bumped by the timeline listener above to force this to re-run.
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [room, recomputeTick]);
|
||||
|
||||
const maxHour = Math.max(...stats.hourBuckets, 1);
|
||||
const maxMsgCount = stats.top5.length > 0 ? (stats.top5[0]?.[1] ?? 1) : 1;
|
||||
@@ -167,7 +225,7 @@ export function RoomInsights({ requestClose }: RoomInsightsProps) {
|
||||
{/* ── Disclaimer banner ── */}
|
||||
<SequenceCard variant="SurfaceVariant" gap="200" alignItems="Center">
|
||||
<Icon src={Icons.Warning} size="200" style={{ color: color.Warning.Main }} />
|
||||
<Box direction="Column" gap="100">
|
||||
<Box grow="Yes" direction="Column" gap="100">
|
||||
<Text size="T300">
|
||||
<strong>
|
||||
Based on {stats.totalMessages} locally cached message
|
||||
@@ -179,6 +237,20 @@ export function RoomInsights({ requestClose }: RoomInsightsProps) {
|
||||
from {formatDate(stats.oldestTs)} to {formatDate(stats.newestTs)}
|
||||
</Text>
|
||||
)}
|
||||
<Text size="T200" priority="300">
|
||||
Last updated {formatUpdatedAt(lastUpdated)}
|
||||
</Text>
|
||||
</Box>
|
||||
<Box shrink="No">
|
||||
<IconButton
|
||||
onClick={recomputeNow}
|
||||
variant="SurfaceVariant"
|
||||
size="300"
|
||||
radii="300"
|
||||
aria-label="Refresh insights"
|
||||
>
|
||||
<Icon src={Icons.Reload} size="100" />
|
||||
</IconButton>
|
||||
</Box>
|
||||
</SequenceCard>
|
||||
|
||||
|
||||
@@ -341,6 +341,7 @@ export function RoomServerACL({ requestClose }: RoomServerACLProps) {
|
||||
variant="Primary"
|
||||
/>
|
||||
<Box direction="Column" gap="0">
|
||||
{}
|
||||
<label
|
||||
htmlFor="allow-ip-literals"
|
||||
style={{ cursor: canEdit ? 'pointer' : 'default' }}
|
||||
|
||||
@@ -0,0 +1,93 @@
|
||||
import { test } from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import {
|
||||
resolveMessageEdits,
|
||||
formatExportBody,
|
||||
RawExportRecord,
|
||||
ResolvedExportRecord,
|
||||
} from './exportRoomHistory.utils';
|
||||
|
||||
const msg = (over: Partial<RawExportRecord>): RawExportRecord => ({
|
||||
eventId: '$1',
|
||||
ts: 1000,
|
||||
sender: '@alice:example.org',
|
||||
body: 'hello',
|
||||
msgtype: 'm.text',
|
||||
...over,
|
||||
});
|
||||
|
||||
test('resolveMessageEdits leaves unedited messages untouched', () => {
|
||||
const out = resolveMessageEdits([msg({ eventId: '$1', body: 'hi' })]);
|
||||
assert.deepEqual(out, [
|
||||
{
|
||||
eventId: '$1',
|
||||
ts: 1000,
|
||||
sender: '@alice:example.org',
|
||||
body: 'hi',
|
||||
msgtype: 'm.text',
|
||||
edited: false,
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
test('resolveMessageEdits substitutes the new content into the original row and drops the edit row', () => {
|
||||
const out = resolveMessageEdits([
|
||||
msg({ eventId: '$1', body: 'origianl typo' }),
|
||||
msg({ eventId: '$2', editsEventId: '$1', newBody: 'original fixed' }),
|
||||
]);
|
||||
assert.equal(out.length, 1);
|
||||
assert.equal(out[0].eventId, '$1');
|
||||
assert.equal(out[0].body, 'original fixed');
|
||||
assert.equal(out[0].edited, true);
|
||||
});
|
||||
|
||||
test('resolveMessageEdits works regardless of whether the edit appears before its target', () => {
|
||||
const out = resolveMessageEdits([
|
||||
msg({ eventId: '$2', editsEventId: '$1', newBody: 'fixed' }),
|
||||
msg({ eventId: '$1', body: 'orig' }),
|
||||
]);
|
||||
assert.equal(out.length, 1);
|
||||
assert.equal(out[0].body, 'fixed');
|
||||
assert.equal(out[0].edited, true);
|
||||
});
|
||||
|
||||
test('resolveMessageEdits ignores an edit with no matching target (target never collected)', () => {
|
||||
const out = resolveMessageEdits([msg({ eventId: '$2', editsEventId: '$1', newBody: 'fixed' })]);
|
||||
assert.deepEqual(out, []);
|
||||
});
|
||||
|
||||
test('formatExportBody prefixes media messages with a type marker', () => {
|
||||
const record: ResolvedExportRecord = {
|
||||
eventId: '$1',
|
||||
ts: 1000,
|
||||
sender: '@alice:example.org',
|
||||
body: 'photo.jpg',
|
||||
msgtype: 'm.image',
|
||||
edited: false,
|
||||
};
|
||||
assert.equal(formatExportBody(record), '[Image] photo.jpg');
|
||||
});
|
||||
|
||||
test('formatExportBody appends an (edited) suffix', () => {
|
||||
const record: ResolvedExportRecord = {
|
||||
eventId: '$1',
|
||||
ts: 1000,
|
||||
sender: '@alice:example.org',
|
||||
body: 'fixed text',
|
||||
msgtype: 'm.text',
|
||||
edited: true,
|
||||
};
|
||||
assert.equal(formatExportBody(record), 'fixed text (edited)');
|
||||
});
|
||||
|
||||
test('formatExportBody combines media prefix and edited suffix', () => {
|
||||
const record: ResolvedExportRecord = {
|
||||
eventId: '$1',
|
||||
ts: 1000,
|
||||
sender: '@alice:example.org',
|
||||
body: 'photo.jpg',
|
||||
msgtype: 'm.file',
|
||||
edited: true,
|
||||
};
|
||||
assert.equal(formatExportBody(record), '[File] photo.jpg (edited)');
|
||||
});
|
||||
@@ -0,0 +1,76 @@
|
||||
// Pure helpers for ExportRoomHistory.tsx, kept SDK/DOM-free so they're easy to
|
||||
// unit test in isolation.
|
||||
|
||||
export type RawExportRecord = {
|
||||
eventId: string;
|
||||
ts: number;
|
||||
sender: string;
|
||||
body: string;
|
||||
msgtype: string;
|
||||
// Set when this record IS an m.replace edit event, to the event id it targets.
|
||||
editsEventId?: string;
|
||||
// The m.new_content.body carried by an m.replace edit event.
|
||||
newBody?: string;
|
||||
};
|
||||
|
||||
export type ResolvedExportRecord = {
|
||||
eventId: string;
|
||||
ts: number;
|
||||
sender: string;
|
||||
body: string;
|
||||
msgtype: string;
|
||||
edited: boolean;
|
||||
};
|
||||
|
||||
// Human-readable label for media msgtypes, used to prefix txt/html export rows
|
||||
// so a media message isn't indistinguishable from a plain-text one.
|
||||
export const MEDIA_TYPE_LABELS: Partial<Record<string, string>> = {
|
||||
'm.image': 'Image',
|
||||
'm.video': 'Video',
|
||||
'm.audio': 'Audio',
|
||||
'm.file': 'File',
|
||||
};
|
||||
|
||||
/**
|
||||
* Resolves m.replace (edit) events against the original message they target:
|
||||
* the edit event is dropped from the output (it should not appear as its own
|
||||
* row), and the original message's body is replaced with the edit's
|
||||
* `m.new_content.body`, marked `edited: true`.
|
||||
*
|
||||
* Order-independent: edits may appear before or after their target in the
|
||||
* input (e.g. across separate back-pagination batches).
|
||||
*/
|
||||
export function resolveMessageEdits(records: RawExportRecord[]): ResolvedExportRecord[] {
|
||||
const edits = new Map<string, string>();
|
||||
for (const record of records) {
|
||||
if (record.editsEventId && record.newBody) {
|
||||
edits.set(record.editsEventId, record.newBody);
|
||||
}
|
||||
}
|
||||
|
||||
const resolved: ResolvedExportRecord[] = [];
|
||||
for (const record of records) {
|
||||
// Edit events never become their own row.
|
||||
if (record.editsEventId) continue;
|
||||
const editedBody = edits.get(record.eventId);
|
||||
resolved.push({
|
||||
eventId: record.eventId,
|
||||
ts: record.ts,
|
||||
sender: record.sender,
|
||||
body: editedBody ?? record.body,
|
||||
msgtype: record.msgtype,
|
||||
edited: editedBody !== undefined,
|
||||
});
|
||||
}
|
||||
return resolved;
|
||||
}
|
||||
|
||||
// Prefixes a media message's body with a "[Image]"-style marker for txt/html
|
||||
// export output, and appends an "(edited)" suffix when applicable. Plain-text
|
||||
// messages are returned unchanged (aside from the edited suffix).
|
||||
export function formatExportBody(record: ResolvedExportRecord): string {
|
||||
const label = MEDIA_TYPE_LABELS[record.msgtype];
|
||||
const mediaPrefix = label ? `[${label}] ` : '';
|
||||
const editedSuffix = record.edited ? ' (edited)' : '';
|
||||
return `${mediaPrefix}${record.body}${editedSuffix}`;
|
||||
}
|
||||
@@ -30,6 +30,7 @@ import {
|
||||
import { MatrixClient, Room, RoomMember } from 'matrix-js-sdk';
|
||||
import { useVirtualizer } from '@tanstack/react-virtual';
|
||||
import classNames from 'classnames';
|
||||
import { useSetAtom } from 'jotai';
|
||||
import { MobileTouchTarget } from '../../styles/mobile.css';
|
||||
import { Membership } from '../../../types/matrix/room';
|
||||
|
||||
@@ -71,6 +72,7 @@ import { MemberVerificationBadge } from '../../components/MemberVerificationBadg
|
||||
import { useUserPresence } from '../../hooks/useUserPresence';
|
||||
import { PresenceBadge, PresenceRingAvatar } from '../../components/presence';
|
||||
import { AvatarDecoration } from '../../components/avatar-decoration/AvatarDecoration';
|
||||
import { createErrorToast, toastQueueAtom } from '../../state/toast';
|
||||
|
||||
type MemberDrawerHeaderProps = {
|
||||
room: Room;
|
||||
@@ -239,11 +241,55 @@ export function MembersDrawer({ room, members }: MembersDrawerProps) {
|
||||
const myUserId = mx.getUserId();
|
||||
const myPowerLevel = readPowerLevel.user(powerLevels, myUserId ?? undefined);
|
||||
const invitePowerLevel = readPowerLevel.action(powerLevels, 'invite');
|
||||
const kickPowerLevel = readPowerLevel.action(powerLevels, 'kick');
|
||||
const canApproveKnock = myPowerLevel >= invitePowerLevel;
|
||||
// Deny uses mx.kick, which is gated by the room's kick power level, not invite -
|
||||
// these can differ (e.g. moderators can invite but only admins can kick).
|
||||
const canDenyKnock = myPowerLevel >= kickPowerLevel;
|
||||
const knockMembers = useMemo(
|
||||
() => (canApproveKnock ? room.getMembersWithMembership(Membership.Knock) : []),
|
||||
[room, canApproveKnock],
|
||||
);
|
||||
const setToast = useSetAtom(toastQueueAtom);
|
||||
const [pendingKnockAction, setPendingKnockAction] = useState<string | undefined>(undefined);
|
||||
|
||||
const handleApproveKnock = useCallback(
|
||||
(userId: string) => {
|
||||
setPendingKnockAction(userId);
|
||||
mx.invite(room.roomId, userId)
|
||||
.catch((err: unknown) => {
|
||||
console.error('Failed to approve knock request:', err);
|
||||
setToast(
|
||||
createErrorToast(
|
||||
'Could not approve this request. Please try again.',
|
||||
Icons.Warning,
|
||||
'Failed',
|
||||
),
|
||||
);
|
||||
})
|
||||
.finally(() => setPendingKnockAction(undefined));
|
||||
},
|
||||
[mx, room.roomId, setToast],
|
||||
);
|
||||
|
||||
const handleDenyKnock = useCallback(
|
||||
(userId: string) => {
|
||||
setPendingKnockAction(userId);
|
||||
mx.kick(room.roomId, userId)
|
||||
.catch((err: unknown) => {
|
||||
console.error('Failed to deny knock request:', err);
|
||||
setToast(
|
||||
createErrorToast(
|
||||
'Could not deny this request. Please try again.',
|
||||
Icons.Warning,
|
||||
'Failed',
|
||||
),
|
||||
);
|
||||
})
|
||||
.finally(() => setPendingKnockAction(undefined));
|
||||
},
|
||||
[mx, room.roomId, setToast],
|
||||
);
|
||||
|
||||
const filteredMembers = useMemo(
|
||||
() => members.filter(membershipFilter.filterFn).sort(memberSort.sortFn).sort(memberPowerSort),
|
||||
@@ -462,20 +508,24 @@ export function MembersDrawer({ room, members }: MembersDrawerProps) {
|
||||
radii="300"
|
||||
fill="Soft"
|
||||
className={MobileTouchTarget}
|
||||
onClick={() => mx.invite(room.roomId, knockMember.userId)}
|
||||
disabled={pendingKnockAction === knockMember.userId}
|
||||
onClick={() => handleApproveKnock(knockMember.userId)}
|
||||
>
|
||||
<Text size="B300">Approve</Text>
|
||||
</Button>
|
||||
<Button
|
||||
size="300"
|
||||
variant="Critical"
|
||||
radii="300"
|
||||
fill="Soft"
|
||||
className={MobileTouchTarget}
|
||||
onClick={() => mx.kick(room.roomId, knockMember.userId)}
|
||||
>
|
||||
<Text size="B300">Deny</Text>
|
||||
</Button>
|
||||
{canDenyKnock && (
|
||||
<Button
|
||||
size="300"
|
||||
variant="Critical"
|
||||
radii="300"
|
||||
fill="Soft"
|
||||
className={MobileTouchTarget}
|
||||
disabled={pendingKnockAction === knockMember.userId}
|
||||
onClick={() => handleDenyKnock(knockMember.userId)}
|
||||
>
|
||||
<Text size="B300">Deny</Text>
|
||||
</Button>
|
||||
)}
|
||||
</Box>
|
||||
</Box>
|
||||
);
|
||||
|
||||
@@ -25,10 +25,12 @@ import { useModalStyle } from '../../hooks/useModalStyle';
|
||||
interface PollCreatorProps {
|
||||
roomId: string;
|
||||
room: Room;
|
||||
/** Set when the composer is inside a thread so the poll lands in that thread. */
|
||||
threadRootId?: string;
|
||||
onClose: () => void;
|
||||
}
|
||||
|
||||
export function PollCreator({ roomId, onClose }: PollCreatorProps) {
|
||||
export function PollCreator({ roomId, threadRootId, onClose }: PollCreatorProps) {
|
||||
const mx = useMatrixClient();
|
||||
const modalStyle = useModalStyle(440);
|
||||
const [question, setQuestion] = useState('');
|
||||
@@ -85,7 +87,9 @@ export function PollCreator({ roomId, onClose }: PollCreatorProps) {
|
||||
const fallbackBody = [trimmedQuestion, ...filledOptions.map((o, i) => `${i + 1}. ${o}`)].join(
|
||||
'\n',
|
||||
);
|
||||
await mx.sendEvent(roomId, 'm.poll.start' as any, {
|
||||
// Pass the thread id explicitly (like the sticker path in RoomInput); the
|
||||
// legacy 3-arg form always resolves to the main timeline.
|
||||
await mx.sendEvent(roomId, threadRootId ?? null, 'm.poll.start' as any, {
|
||||
'm.poll': {
|
||||
question: { 'm.text': trimmedQuestion },
|
||||
answers: filledOptions.map((o, i) => ({ 'm.id': `${i}`, 'm.text': o })),
|
||||
|
||||
@@ -105,6 +105,7 @@ import {
|
||||
settingsAtom,
|
||||
} from '../../state/settings';
|
||||
import {
|
||||
buildCompressedUploadItem,
|
||||
getAudioMsgContent,
|
||||
getFileMsgContent,
|
||||
getImageMsgContent,
|
||||
@@ -240,12 +241,18 @@ export const RoomInput = forwardRef<HTMLDivElement, RoomInputProps>(
|
||||
const showFormat = composerToolbarButtons?.showFormat ?? true;
|
||||
const showEmoji = composerToolbarButtons?.showEmoji ?? true;
|
||||
const showSticker = composerToolbarButtons?.showSticker ?? true;
|
||||
const showGif = composerToolbarButtons?.showGif ?? true;
|
||||
// [Gitea #68] The GIF picker is opt-in (searches go to Giphy); hide the
|
||||
// toolbar button entirely when it's off so it never opens an empty popover.
|
||||
const [gifPickerEnabled] = useSetting(settingsAtom, 'gifPickerEnabled');
|
||||
const showGif = (composerToolbarButtons?.showGif ?? true) && gifPickerEnabled;
|
||||
const showLocation = composerToolbarButtons?.showLocation ?? true;
|
||||
const showPoll = composerToolbarButtons?.showPoll ?? true;
|
||||
const showVoice = composerToolbarButtons?.showVoice ?? true;
|
||||
// Schedule-send is hidden in thread mode (v1 reduction).
|
||||
const showSchedule = (composerToolbarButtons?.showSchedule ?? true) && !threadRootId;
|
||||
// Schedule-send is hidden in thread mode (v1 reduction) and in encrypted rooms:
|
||||
// MSC4140 delayed events are PUT as plaintext m.room.message, bypassing the
|
||||
// SDK's encryption pipeline, so scheduling in an E2EE room would leak the body.
|
||||
const showSchedule =
|
||||
(composerToolbarButtons?.showSchedule ?? true) && !threadRootId && !isEncrypted;
|
||||
const composerButtonOrder = useMemo(
|
||||
() => normalizeComposerToolbarOrder(composerToolbarButtons?.order),
|
||||
[composerToolbarButtons?.order],
|
||||
@@ -394,27 +401,47 @@ export const RoomInput = forwardRef<HTMLDivElement, RoomInputProps>(
|
||||
try {
|
||||
const stored = localStorage.getItem(`draft-msg-${draftKey}`);
|
||||
if (stored) {
|
||||
const nodes = JSON.parse(stored);
|
||||
if (Array.isArray(nodes) && nodes.length > 0) {
|
||||
Transforms.insertFragment(editor, nodes);
|
||||
// Mirror the restored draft into the atom so the draft indicator
|
||||
// (reads roomIdToMsgDraftAtomFamily) reflects a persisted draft
|
||||
// after a page reload — not only on same-session room re-entry.
|
||||
setMsgDraft(nodes);
|
||||
const parsed = JSON.parse(stored);
|
||||
// [Gitea #41] Only restore a draft this same account wrote. A legacy
|
||||
// draft (stored as a bare array, pre-dating user-scoping) or one
|
||||
// written by a different userId is foreign — drop it rather than
|
||||
// risk pre-filling another account's unsent text into the composer.
|
||||
const foreign =
|
||||
!parsed ||
|
||||
typeof parsed !== 'object' ||
|
||||
Array.isArray(parsed) ||
|
||||
parsed.userId !== mx.getUserId();
|
||||
if (foreign) {
|
||||
localStorage.removeItem(`draft-msg-${draftKey}`);
|
||||
} else {
|
||||
const nodes = parsed.nodes;
|
||||
if (Array.isArray(nodes) && nodes.length > 0) {
|
||||
Transforms.insertFragment(editor, nodes);
|
||||
// Mirror the restored draft into the atom so the draft indicator
|
||||
// (reads roomIdToMsgDraftAtomFamily) reflects a persisted draft
|
||||
// after a page reload — not only on same-session room re-entry.
|
||||
setMsgDraft(nodes);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
// Ignore malformed stored draft
|
||||
}
|
||||
}
|
||||
}, [editor, msgDraft, draftKey, setMsgDraft]);
|
||||
}, [editor, msgDraft, draftKey, setMsgDraft, mx]);
|
||||
|
||||
useEffect(
|
||||
() => () => {
|
||||
if (!isEmptyEditor(editor)) {
|
||||
const parsedDraft = JSON.parse(JSON.stringify(editor.children));
|
||||
setMsgDraft(parsedDraft);
|
||||
localStorage.setItem(`draft-msg-${draftKey}`, JSON.stringify(parsedDraft));
|
||||
// [Gitea #41] Tag the persisted draft with the writing user's id so a
|
||||
// different account logging into this browser can't have it hydrated
|
||||
// into their composer (see useHydrateMsgDrafts / clearPlaintextCaches).
|
||||
localStorage.setItem(
|
||||
`draft-msg-${draftKey}`,
|
||||
JSON.stringify({ userId: mx.getUserId(), nodes: parsedDraft }),
|
||||
);
|
||||
} else {
|
||||
setMsgDraft([]);
|
||||
localStorage.removeItem(`draft-msg-${draftKey}`);
|
||||
@@ -422,7 +449,7 @@ export const RoomInput = forwardRef<HTMLDivElement, RoomInputProps>(
|
||||
resetEditor(editor);
|
||||
resetEditorHistory(editor);
|
||||
},
|
||||
[draftKey, editor, setMsgDraft],
|
||||
[draftKey, editor, setMsgDraft, mx],
|
||||
);
|
||||
|
||||
const handleFileMetadata = useCallback(
|
||||
@@ -485,22 +512,29 @@ export const RoomInput = forwardRef<HTMLDivElement, RoomInputProps>(
|
||||
const compressedFile = new File([compressionResult.blob], compressedName, {
|
||||
type: compressedType,
|
||||
});
|
||||
const uploadRes = await mx.uploadContent(compressedFile, {
|
||||
name: compressedName,
|
||||
type: compressedType,
|
||||
});
|
||||
// Compression re-encodes the image, so in an encrypted room the new
|
||||
// bytes must be encrypted before upload (and the event must carry the
|
||||
// *new* encInfo) — reusing the original's encInfo would publish the
|
||||
// image in the clear and yield an undecryptable attachment.
|
||||
const encrypted = fileItem.encInfo ? await encryptFile(compressedFile) : undefined;
|
||||
const uploadRes = encrypted
|
||||
? await mx.uploadContent(encrypted.file)
|
||||
: await mx.uploadContent(compressedFile, {
|
||||
name: compressedName,
|
||||
type: compressedType,
|
||||
});
|
||||
const compressedMxc = (uploadRes as { content_uri: string }).content_uri;
|
||||
if (compressedMxc) {
|
||||
// Delete the pre-uploaded original so only one copy lives on the server.
|
||||
tryDeleteMxcContent(mx, upload.mxc);
|
||||
mxc = compressedMxc;
|
||||
// Build a synthetic fileItem that refers to the compressed file so
|
||||
// getImageMsgContent picks up the correct dimensions and type.
|
||||
const compressedItem = {
|
||||
...fileItem,
|
||||
file: compressedFile,
|
||||
originalFile: compressedFile,
|
||||
};
|
||||
// Synthetic fileItem referring to the compressed file so
|
||||
// getImageMsgContent picks up the correct dimensions, type and encInfo.
|
||||
const compressedItem = buildCompressedUploadItem(
|
||||
fileItem,
|
||||
compressedFile,
|
||||
encrypted,
|
||||
);
|
||||
return getImageMsgContent(mx, compressedItem, mxc);
|
||||
}
|
||||
}
|
||||
@@ -697,11 +731,14 @@ export const RoomInput = forwardRef<HTMLDivElement, RoomInputProps>(
|
||||
}, [editor, isMarkdown, mx, roomId, replyDraft]);
|
||||
|
||||
const handleScheduleClick = useCallback(() => {
|
||||
// Defense in depth: scheduling sends an unencrypted m.room.message, so never
|
||||
// open the modal for an encrypted room even if the button somehow renders.
|
||||
if (isEncrypted) return;
|
||||
// Pre-fill from editor if there's content; open blank if editor is empty.
|
||||
const content = buildCurrentTextContent();
|
||||
setScheduleContent(content);
|
||||
setScheduleOpen(true);
|
||||
}, [buildCurrentTextContent]);
|
||||
}, [buildCurrentTextContent, isEncrypted]);
|
||||
|
||||
const handleScheduled = useCallback(
|
||||
(delayId: string, sendAt: number, content: IContent) => {
|
||||
@@ -823,18 +860,38 @@ export const RoomInput = forwardRef<HTMLDivElement, RoomInputProps>(
|
||||
return;
|
||||
}
|
||||
|
||||
const uploadRes = await mx.uploadContent(
|
||||
new File([blob], 'image.gif', { type: 'image/gif' }),
|
||||
{ type: 'image/gif', name: 'image.gif', includeFilename: false },
|
||||
);
|
||||
const mxcUrl = (uploadRes as { content_uri: string }).content_uri;
|
||||
if (!mxcUrl) return;
|
||||
mx.sendMessage(roomId, threadRootId ?? null, {
|
||||
const gifFile = new File([blob], 'image.gif', { type: 'image/gif' });
|
||||
const baseContent = {
|
||||
msgtype: MsgType.Image,
|
||||
body: 'image.gif',
|
||||
url: mxcUrl,
|
||||
info: { mimetype: 'image/gif', w, h, size: blob.size },
|
||||
});
|
||||
};
|
||||
|
||||
// Mirror the attachment/voice paths: in an encrypted room the media
|
||||
// itself must be encrypted, otherwise the homeserver (and anyone with
|
||||
// the mxc URI) can see the GIF even though the event body is encrypted.
|
||||
if (room.hasEncryptionStateEvent()) {
|
||||
const { encInfo, file: encBlob } = await encryptFile(gifFile);
|
||||
const uploadRes = await mx.uploadContent(encBlob);
|
||||
const mxcUrl = (uploadRes as { content_uri: string }).content_uri;
|
||||
if (!mxcUrl) return;
|
||||
mx.sendMessage(roomId, threadRootId ?? null, {
|
||||
...baseContent,
|
||||
file: { ...encInfo, url: mxcUrl },
|
||||
} as any);
|
||||
} else {
|
||||
const uploadRes = await mx.uploadContent(gifFile, {
|
||||
type: 'image/gif',
|
||||
name: 'image.gif',
|
||||
includeFilename: false,
|
||||
});
|
||||
const mxcUrl = (uploadRes as { content_uri: string }).content_uri;
|
||||
if (!mxcUrl) return;
|
||||
mx.sendMessage(roomId, threadRootId ?? null, {
|
||||
...baseContent,
|
||||
url: mxcUrl,
|
||||
} as any);
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('GIF send failed:', e instanceof Error ? e.message : 'unknown error');
|
||||
if (!alive()) return;
|
||||
@@ -844,7 +901,7 @@ export const RoomInput = forwardRef<HTMLDivElement, RoomInputProps>(
|
||||
if (alive()) setGifUploading(false);
|
||||
}
|
||||
},
|
||||
[mx, roomId, threadRootId, alive],
|
||||
[mx, room, roomId, threadRootId, alive],
|
||||
);
|
||||
|
||||
const handleStickerSelect = useCallback(
|
||||
@@ -1446,7 +1503,14 @@ export const RoomInput = forwardRef<HTMLDivElement, RoomInputProps>(
|
||||
</>
|
||||
}
|
||||
/>
|
||||
{pollOpen && <PollCreator room={room} roomId={roomId} onClose={() => setPollOpen(false)} />}
|
||||
{pollOpen && (
|
||||
<PollCreator
|
||||
room={room}
|
||||
roomId={roomId}
|
||||
threadRootId={threadRootId}
|
||||
onClose={() => setPollOpen(false)}
|
||||
/>
|
||||
)}
|
||||
{scheduleOpen && (
|
||||
<ScheduleMessageModal
|
||||
roomId={roomId}
|
||||
|
||||
@@ -42,7 +42,7 @@ import {
|
||||
recentForwardTargetsAtom,
|
||||
addRecentForwardTarget,
|
||||
} from '../../../state/recentForwardTargets';
|
||||
import { buildForwardContent } from './forwardContent';
|
||||
import { buildForwardContent, buildPlaintextAttachmentContent } from './forwardContent';
|
||||
|
||||
type RoomRowProps = {
|
||||
room: Room;
|
||||
@@ -314,11 +314,43 @@ export function ForwardMessageDialog({ mEvent, onClose }: Props) {
|
||||
setError(null);
|
||||
|
||||
const ids = [...selectedRoomIds];
|
||||
|
||||
// `fwdContent.file` (present on encrypted attachments) carries the AES key/iv
|
||||
// needed to decrypt it. Sending it as-is into a room that isn't encrypted would
|
||||
// publish that key in plaintext (Gitea #63), so any unencrypted destination gets
|
||||
// a decrypted-and-re-uploaded plaintext version instead. Built once (not per
|
||||
// room) since every unencrypted destination gets the same re-upload.
|
||||
let plaintextContent: Record<string, unknown> | undefined;
|
||||
let plaintextContentError: string | undefined;
|
||||
if (fwdContent.file) {
|
||||
const needsPlaintext = ids.some((id) => !mx.getRoom(id)?.hasEncryptionStateEvent());
|
||||
if (needsPlaintext) {
|
||||
try {
|
||||
plaintextContent = await buildPlaintextAttachmentContent(
|
||||
mx,
|
||||
fwdContent,
|
||||
useAuthentication,
|
||||
);
|
||||
} catch {
|
||||
plaintextContentError = 'Could not prepare this attachment for an unencrypted room.';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const commentBody = comment.trim();
|
||||
const results = await Promise.allSettled(
|
||||
ids.map((id) => {
|
||||
const destEncrypted = !!mx.getRoom(id)?.hasEncryptionStateEvent();
|
||||
// Encrypted destinations keep the original (possibly encrypted-attachment)
|
||||
// content; unencrypted ones get the plaintext version, or fail outright if
|
||||
// that couldn't be built — never fall back to sending the encrypted `file`.
|
||||
const contentToSend = fwdContent.file && !destEncrypted ? plaintextContent : fwdContent;
|
||||
if (fwdContent.file && !destEncrypted && !contentToSend) {
|
||||
return Promise.reject(new Error(plaintextContentError));
|
||||
}
|
||||
// threadId-aware overload (P3-8): explicit null = send to the main timeline.
|
||||
const sendForward = () => mx.sendEvent(id, null, mEvent.getType() as any, fwdContent);
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const sendForward = () => mx.sendEvent(id, null, mEvent.getType() as any, contentToSend);
|
||||
// Send the optional comment first so it reads as a note above the
|
||||
// forwarded content. The room counts as failed if either send rejects.
|
||||
// Track rooms whose comment already landed so a retry (after the FORWARD
|
||||
@@ -326,6 +358,7 @@ export function ForwardMessageDialog({ mEvent, onClose }: Props) {
|
||||
const needsComment = commentBody && !commentSentRef.current.has(id);
|
||||
const step = needsComment
|
||||
? mx
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
.sendMessage(id, null, { msgtype: MsgType.Text, body: commentBody } as any)
|
||||
.then(() => {
|
||||
commentSentRef.current.add(id);
|
||||
@@ -368,7 +401,7 @@ export function ForwardMessageDialog({ mEvent, onClose }: Props) {
|
||||
return;
|
||||
}
|
||||
setError(`Forwarded to ${succeeded}/${total}. Failed: ${failedNames.join(', ')}.`);
|
||||
}, [mx, mEvent, onClose, sending, selectedRoomIds, comment, setRecents]);
|
||||
}, [mx, mEvent, onClose, sending, selectedRoomIds, comment, setRecents, useAuthentication]);
|
||||
|
||||
return (
|
||||
<Overlay open backdrop={<OverlayBackdrop />}>
|
||||
|
||||
@@ -1273,6 +1273,9 @@ export const Message = React.memo(
|
||||
const content = mEvent.getContent();
|
||||
const body: string =
|
||||
(content?.body as string | undefined) ?? '';
|
||||
// For E2EE rooms useBookmarks strips the text
|
||||
// fields before persisting (account data is
|
||||
// server-readable); the panel resolves them live.
|
||||
addBookmark({
|
||||
roomId: room.roomId,
|
||||
eventId,
|
||||
@@ -1390,6 +1393,7 @@ export const Message = React.memo(
|
||||
after={<Icon size="100" src={Icons.Send} />}
|
||||
radii="300"
|
||||
onClick={() => {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
(mx as any).resendEvent(mEvent, room);
|
||||
closeMenu();
|
||||
}}
|
||||
@@ -1408,6 +1412,7 @@ export const Message = React.memo(
|
||||
after={<Icon size="100" src={Icons.Cross} />}
|
||||
radii="300"
|
||||
onClick={() => {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
(mx as any).cancelPendingEvent(mEvent);
|
||||
closeMenu();
|
||||
}}
|
||||
|
||||
@@ -187,6 +187,7 @@ export const MessageEditor = as<'div', MessageEditorProps>(
|
||||
rel_type: RelationType.Replace,
|
||||
},
|
||||
};
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
return mx.sendMessage(roomId, content as any);
|
||||
}
|
||||
|
||||
@@ -235,6 +236,7 @@ export const MessageEditor = as<'div', MessageEditorProps>(
|
||||
},
|
||||
};
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
return mx.sendMessage(roomId, content as any);
|
||||
}, [
|
||||
mx,
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
import { MatrixClient, MatrixEvent } from 'matrix-js-sdk';
|
||||
import { getEditedEvent, trimReplyFromBody, trimReplyFromFormattedBody } from '../../../utils/room';
|
||||
import { decryptFile, downloadEncryptedMedia, mxcUrlToHttp } from '../../../utils/matrix';
|
||||
import { FALLBACK_MIMETYPE } from '../../../utils/mimeTypes';
|
||||
import { IEncryptedFile } from '../../../../types/matrix/common';
|
||||
|
||||
/**
|
||||
* Build the content to forward:
|
||||
@@ -40,3 +43,44 @@ export function buildForwardContent(
|
||||
}
|
||||
return content;
|
||||
}
|
||||
|
||||
/**
|
||||
* `content.file` on an encrypted attachment carries the AES key/iv/hashes
|
||||
* needed to decrypt it. Forwarding that content verbatim into a room that
|
||||
* isn't itself encrypted would publish the key in plaintext to anyone who can
|
||||
* read the destination room (Gitea #63). Re-encrypting for the destination is
|
||||
* out of scope, so instead download+decrypt the attachment here and re-upload
|
||||
* it as a plain (unencrypted) upload, sending `url` in place of `file`.
|
||||
*
|
||||
* Throws if the attachment can't be fetched/decrypted — callers must treat
|
||||
* that as a hard failure for this forward rather than falling back to
|
||||
* sending the encrypted `file` block into the plaintext room.
|
||||
*/
|
||||
export async function buildPlaintextAttachmentContent(
|
||||
mx: MatrixClient,
|
||||
content: Record<string, unknown>,
|
||||
useAuthentication: boolean,
|
||||
): Promise<Record<string, unknown>> {
|
||||
const file = content.file as IEncryptedFile;
|
||||
const info = content.info as Record<string, unknown> | undefined;
|
||||
const mimeType = (info?.mimetype as string | undefined) ?? FALLBACK_MIMETYPE;
|
||||
|
||||
const mediaUrl = mxcUrlToHttp(mx, file.url, useAuthentication);
|
||||
if (!mediaUrl) throw new Error('Invalid attachment URL');
|
||||
const blob = await downloadEncryptedMedia(mediaUrl, (buf) => decryptFile(buf, mimeType, file));
|
||||
const uploadResult = await mx.uploadContent(blob, { type: mimeType });
|
||||
|
||||
const plainContent = { ...content };
|
||||
delete plainContent.file;
|
||||
plainContent.url = uploadResult.content_uri;
|
||||
|
||||
// The thumbnail can carry its own encryption key (`thumbnail_file`); drop it
|
||||
// rather than leak it too — the full attachment still forwards fine without
|
||||
// a thumbnail.
|
||||
if (info && (info.thumbnail_file || info.thumbnail_url)) {
|
||||
const { thumbnail_file: _tf, thumbnail_url: _tu, ...restInfo } = info;
|
||||
plainContent.info = restInfo;
|
||||
}
|
||||
|
||||
return plainContent;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
import { test } from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { EncryptedAttachmentInfo } from 'browser-encrypt-attachment';
|
||||
import { buildCompressedUploadItem } from './msgContent';
|
||||
import { TUploadItem } from '../../state/room/roomInputDrafts';
|
||||
|
||||
// buildCompressedUploadItem decides which bytes are uploaded and which encInfo
|
||||
// (if any) the resulting m.image event carries. Getting this wrong either leaks
|
||||
// a plaintext image into an E2EE room or produces an undecryptable attachment.
|
||||
|
||||
const enc = (tag: string): EncryptedAttachmentInfo =>
|
||||
({
|
||||
v: 'v2',
|
||||
key: { alg: 'A256CTR', k: tag },
|
||||
iv: `iv-${tag}`,
|
||||
hashes: { sha256: `sha-${tag}` },
|
||||
}) as unknown as EncryptedAttachmentInfo;
|
||||
|
||||
const fakeFile = (name: string, size: number): File =>
|
||||
new File([new Uint8Array(size)], name, { type: 'image/jpeg' });
|
||||
|
||||
const makeItem = (encInfo?: EncryptedAttachmentInfo): TUploadItem =>
|
||||
({
|
||||
file: fakeFile('photo.png', 900),
|
||||
originalFile: fakeFile('photo.png', 900),
|
||||
encInfo,
|
||||
metadata: { markedAsSpoiler: false, compressImage: true },
|
||||
}) as unknown as TUploadItem;
|
||||
|
||||
test('unencrypted room: compressed item uploads the plain file and carries no encInfo', () => {
|
||||
const compressed = fakeFile('photo.jpg', 300);
|
||||
const item = buildCompressedUploadItem(makeItem(), compressed);
|
||||
|
||||
assert.equal(item.file, compressed);
|
||||
assert.equal(item.originalFile, compressed);
|
||||
assert.equal(item.encInfo, undefined);
|
||||
});
|
||||
|
||||
test('encrypted room: compressed item carries the NEW encInfo, never the original one', () => {
|
||||
const compressed = fakeFile('photo.jpg', 300);
|
||||
const encryptedBlob = fakeFile('photo.jpg', 320);
|
||||
const item = buildCompressedUploadItem(makeItem(enc('original')), compressed, {
|
||||
file: encryptedBlob,
|
||||
encInfo: enc('compressed'),
|
||||
});
|
||||
|
||||
// The ciphertext is what gets uploaded; the plaintext stays available for
|
||||
// dimensions/blurhash only.
|
||||
assert.equal(item.file, encryptedBlob);
|
||||
assert.equal(item.originalFile, compressed);
|
||||
assert.deepEqual(item.encInfo, enc('compressed'));
|
||||
assert.notDeepEqual(item.encInfo, enc('original'));
|
||||
});
|
||||
|
||||
test('encrypted room: an encInfo-less compressed item never inherits the original encInfo', () => {
|
||||
// Defensive: even if the caller forgets to re-encrypt, we must not emit the
|
||||
// stale encInfo (that is the bug this helper exists to prevent).
|
||||
const item = buildCompressedUploadItem(makeItem(enc('original')), fakeFile('photo.jpg', 300));
|
||||
assert.equal(item.encInfo, undefined);
|
||||
});
|
||||
|
||||
test('metadata (caption, spoiler) is preserved on the compressed item', () => {
|
||||
const base = makeItem();
|
||||
base.metadata.caption = 'a caption';
|
||||
base.metadata.markedAsSpoiler = true;
|
||||
const item = buildCompressedUploadItem(base, fakeFile('photo.jpg', 300));
|
||||
assert.equal(item.metadata.caption, 'a caption');
|
||||
assert.equal(item.metadata.markedAsSpoiler, true);
|
||||
});
|
||||
|
||||
// getImageMsgContent itself is not covered here: it needs a DOM (loadImageElement).
|
||||
// Its encInfo branch (content.file vs content.url) is exercised by the sibling
|
||||
// msgContent.test.ts builders, which share the same shape.
|
||||
@@ -1,5 +1,6 @@
|
||||
import { IContent, MatrixClient, MsgType } from 'matrix-js-sdk';
|
||||
import to from 'await-to-js';
|
||||
import { EncryptedAttachmentInfo } from 'browser-encrypt-attachment';
|
||||
import {
|
||||
IThumbnailContent,
|
||||
MATRIX_BLUR_HASH_PROPERTY_NAME,
|
||||
@@ -43,6 +44,28 @@ const generateThumbnailContent = async (
|
||||
return thumbnailContent;
|
||||
};
|
||||
|
||||
/**
|
||||
* Build the synthetic upload item for a *re-encoded* (compressed) image.
|
||||
*
|
||||
* The compressed bytes are a brand new payload, so the item must never inherit
|
||||
* the original's `encInfo` — that key/iv/sha256 describes the pre-compression
|
||||
* ciphertext and would make receivers fail to decrypt. In an encrypted room the
|
||||
* caller re-runs `encryptFile` and passes the new ciphertext + encInfo here; in
|
||||
* an unencrypted room both are omitted and the item carries no `encInfo` at all.
|
||||
*/
|
||||
export const buildCompressedUploadItem = (
|
||||
item: TUploadItem,
|
||||
compressedFile: File,
|
||||
encrypted?: { file: File; encInfo: EncryptedAttachmentInfo },
|
||||
): TUploadItem => ({
|
||||
...item,
|
||||
// `file` is what gets uploaded/described, `originalFile` is the plaintext used
|
||||
// for dimensions + blurhash.
|
||||
file: encrypted?.file ?? compressedFile,
|
||||
originalFile: compressedFile,
|
||||
encInfo: encrypted?.encInfo,
|
||||
});
|
||||
|
||||
export const getImageMsgContent = async (
|
||||
mx: MatrixClient,
|
||||
item: TUploadItem,
|
||||
|
||||
@@ -116,6 +116,8 @@ export function ThreadPanel({ room, threadId, requestClose }: ThreadPanelProps)
|
||||
const editor = useEditor();
|
||||
const thread = useThreadInstance(room, threadId);
|
||||
const [privateReadReceipts] = useSetting(settingsAtom, 'privateReadReceipts');
|
||||
// "Hide Typing & Read Receipts" must also make thread receipts private (matches markAsRead).
|
||||
const [hideActivity] = useSetting(settingsAtom, 'hideActivity');
|
||||
const fileDropContainerRef = useRef<HTMLDivElement>(null) as React.RefObject<HTMLDivElement>;
|
||||
|
||||
useKeyDown(
|
||||
@@ -157,7 +159,7 @@ export function ThreadPanel({ room, threadId, requestClose }: ThreadPanelProps)
|
||||
}
|
||||
if (!latestId || latestId === lastReadEventIdRef.current) return;
|
||||
lastReadEventIdRef.current = latestId;
|
||||
markThreadAsRead(mx, thread, privateReadReceipts).catch(() => {
|
||||
markThreadAsRead(mx, thread, hideActivity || privateReadReceipts).catch(() => {
|
||||
// Allow a retry on the next event if the receipt POST failed.
|
||||
if (lastReadEventIdRef.current === latestId) {
|
||||
lastReadEventIdRef.current = undefined;
|
||||
@@ -171,7 +173,7 @@ export function ThreadPanel({ room, threadId, requestClose }: ThreadPanelProps)
|
||||
thread.off(ThreadEvent.NewReply, markRead);
|
||||
thread.off(RoomEvent.Timeline, markRead);
|
||||
};
|
||||
}, [mx, thread, privateReadReceipts]);
|
||||
}, [mx, thread, privateReadReceipts, hideActivity]);
|
||||
|
||||
return (
|
||||
<Box
|
||||
|
||||
@@ -545,9 +545,19 @@ export function ThreadTimeline({ room, thread, editor }: ThreadTimelineProps) {
|
||||
[room, thread, setReplyDraft, editor],
|
||||
);
|
||||
|
||||
// Non-thread relations (reactions, edits) that target the thread root live only in
|
||||
// the room's main timeline set (matrix-js-sdk Room.eventShouldLiveIn), so lookups
|
||||
// for the root must use the room set instead of the thread set.
|
||||
const getRelationTimelineSet = useCallback(
|
||||
(eventId: string) =>
|
||||
eventId === thread.id ? room.getUnfilteredTimelineSet() : thread.getUnfilteredTimelineSet(),
|
||||
[room, thread],
|
||||
);
|
||||
|
||||
const handleReactionToggle = useCallback(
|
||||
(targetEventId: string, key: string, shortcode?: string) => {
|
||||
const timelineSet = thread.getUnfilteredTimelineSet();
|
||||
const isRoot = targetEventId === thread.id;
|
||||
const timelineSet = getRelationTimelineSet(targetEventId);
|
||||
const relations = getEventReactions(timelineSet, targetEventId);
|
||||
const allReactions = relations?.getSortedAnnotationsByKey() ?? [];
|
||||
const [, reactionsSet] = allReactions.find(([k]) => k === key) ?? [];
|
||||
@@ -563,12 +573,14 @@ export function ThreadTimeline({ room, thread, editor }: ThreadTimelineProps) {
|
||||
(reactions.find(eventWithShortcode)?.getContent().shortcode as string | undefined);
|
||||
mx.sendEvent(
|
||||
room.roomId,
|
||||
thread.id,
|
||||
// A reaction on the root is a main-timeline event, not a thread reply.
|
||||
isRoot ? null : thread.id,
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
MessageEvent.Reaction as any,
|
||||
getReactionContent(targetEventId, key, rShortcode),
|
||||
);
|
||||
},
|
||||
[mx, room, thread],
|
||||
[mx, room, thread, getRelationTimelineSet],
|
||||
);
|
||||
|
||||
const handleEdit = useCallback(
|
||||
@@ -714,7 +726,7 @@ export function ThreadTimeline({ room, thread, editor }: ThreadTimelineProps) {
|
||||
): ReactNode => {
|
||||
const mEventId = mEvent.getId();
|
||||
if (!mEventId) return null;
|
||||
const timelineSet = thread.getUnfilteredTimelineSet();
|
||||
const timelineSet = getRelationTimelineSet(mEventId);
|
||||
const reactionRelations = getEventReactions(timelineSet, mEventId);
|
||||
const reactions = reactionRelations?.getSortedAnnotationsByKey();
|
||||
const hasReactions = !!reactions && reactions.length > 0;
|
||||
@@ -782,7 +794,6 @@ export function ThreadTimeline({ room, thread, editor }: ThreadTimelineProps) {
|
||||
);
|
||||
},
|
||||
[
|
||||
thread,
|
||||
room,
|
||||
messageSpacing,
|
||||
messageLayout,
|
||||
@@ -809,6 +820,7 @@ export function ThreadTimeline({ room, thread, editor }: ThreadTimelineProps) {
|
||||
lotusTerminal,
|
||||
mx,
|
||||
renderMessageContent,
|
||||
getRelationTimelineSet,
|
||||
],
|
||||
);
|
||||
|
||||
|
||||
@@ -95,6 +95,7 @@ export function WidgetsPanel({ room, requestClose }: WidgetsPanelProps) {
|
||||
|
||||
const handleRemove = (id: string) => {
|
||||
if (viewingId === id) setViewingId(null);
|
||||
|
||||
sendStateEvent(mx, room.roomId, StateEvent.Widget, {}, id).catch(() => undefined);
|
||||
};
|
||||
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
import { test } from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import type { MatrixEvent } from 'matrix-js-sdk';
|
||||
import { widgetsFromStateEvents } from './useRoomWidgets';
|
||||
|
||||
const APP = 'https://chat.lotusguild.org';
|
||||
|
||||
// Minimal fake MatrixEvent, just enough of the surface widgetsFromStateEvents reads.
|
||||
const fakeEvent = (stateKey: string, sender: string, content: Record<string, unknown>) =>
|
||||
({
|
||||
getStateKey: () => stateKey,
|
||||
getSender: () => sender,
|
||||
getContent: () => content,
|
||||
}) as unknown as MatrixEvent;
|
||||
|
||||
test('returns a Widget for a valid im.vector.modular.widgets state event', () => {
|
||||
// Regression test for matrix-widget-api 1.17.0's broken isValidUrl, which
|
||||
// compares URL.protocol ("https:") to "https" and rejects every URL,
|
||||
// making WidgetParser.parseWidgetsFromRoomState always return [].
|
||||
const events = new Map([
|
||||
[
|
||||
'w1',
|
||||
fakeEvent('w1', '@a:example.org', {
|
||||
id: 'w1',
|
||||
type: 'custom',
|
||||
url: 'https://example.com/widget',
|
||||
name: 'My Widget',
|
||||
creatorUserId: '@a:example.org',
|
||||
}),
|
||||
],
|
||||
]);
|
||||
|
||||
const widgets = widgetsFromStateEvents(events, APP);
|
||||
assert.equal(widgets.length, 1);
|
||||
assert.equal(widgets[0].id, 'w1');
|
||||
assert.equal(widgets[0].templateUrl, 'https://example.com/widget');
|
||||
assert.equal(widgets[0].creatorUserId, '@a:example.org');
|
||||
assert.equal(widgets[0].name, 'My Widget');
|
||||
});
|
||||
|
||||
test('skips removed widgets (empty content)', () => {
|
||||
const events = new Map([['w1', fakeEvent('w1', '@a:example.org', {})]]);
|
||||
assert.deepEqual(widgetsFromStateEvents(events, APP), []);
|
||||
});
|
||||
|
||||
test('skips non-https and same-origin urls', () => {
|
||||
const events = new Map([
|
||||
[
|
||||
'w1',
|
||||
fakeEvent('w1', '@a:example.org', {
|
||||
id: 'w1',
|
||||
type: 'custom',
|
||||
url: 'http://example.com/widget',
|
||||
creatorUserId: '@a:example.org',
|
||||
}),
|
||||
],
|
||||
[
|
||||
'w2',
|
||||
fakeEvent('w2', '@a:example.org', {
|
||||
id: 'w2',
|
||||
type: 'custom',
|
||||
url: `${APP}/evil`,
|
||||
creatorUserId: '@a:example.org',
|
||||
}),
|
||||
],
|
||||
]);
|
||||
assert.deepEqual(widgetsFromStateEvents(events, APP), []);
|
||||
});
|
||||
|
||||
test('undefined state map yields no widgets', () => {
|
||||
assert.deepEqual(widgetsFromStateEvents(undefined, APP), []);
|
||||
});
|
||||
@@ -1,21 +1,67 @@
|
||||
import { Room } from 'matrix-js-sdk';
|
||||
import { Room, MatrixEvent } from 'matrix-js-sdk';
|
||||
import { useMemo } from 'react';
|
||||
import { Widget, WidgetParser, IStateEvent } from 'matrix-widget-api';
|
||||
import { Widget } from 'matrix-widget-api';
|
||||
import { StateEvent } from '../../../../types/matrix/room';
|
||||
import { useRoomState } from '../../../hooks/useRoomState';
|
||||
import { StateKeyToEvents, useRoomState } from '../../../hooks/useRoomState';
|
||||
import { isWidgetUrlSafe } from './widgetUtils';
|
||||
|
||||
/**
|
||||
* Builds the `Widget` list from raw `im.vector.modular.widgets` state events.
|
||||
*
|
||||
* NOTE: we do NOT use `WidgetParser.parseWidgetsFromRoomState` here. In
|
||||
* matrix-widget-api 1.17.0 its `isValidUrl` compares `URL.protocol` (which is
|
||||
* always colon-suffixed, e.g. "https:") against the bare strings "http"/
|
||||
* "https", so it rejects every URL and the parser always returns []. We build
|
||||
* the `Widget`s ourselves with a correct scheme check plus the existing
|
||||
* `isWidgetUrlSafe` origin check.
|
||||
*/
|
||||
export const widgetsFromStateEvents = (
|
||||
widgetEvents: StateKeyToEvents | undefined,
|
||||
appOrigin: string,
|
||||
): Widget[] => {
|
||||
if (!widgetEvents) return [];
|
||||
const widgets: Widget[] = [];
|
||||
Array.from(widgetEvents.values()).forEach((event: MatrixEvent) => {
|
||||
const content = event.getContent();
|
||||
// Removed widgets are represented as an empty content state event.
|
||||
if (!content || Object.keys(content).length === 0) return;
|
||||
|
||||
const id = event.getStateKey();
|
||||
const { type, url, name, data, waitForIframeLoad } = content;
|
||||
const creatorUserId = content.creatorUserId || event.getSender();
|
||||
if (!id || !type || !url || !creatorUserId) return;
|
||||
|
||||
let scheme: string;
|
||||
try {
|
||||
scheme = new URL(url).protocol;
|
||||
} catch {
|
||||
return;
|
||||
}
|
||||
if (scheme !== 'https:') return;
|
||||
if (!isWidgetUrlSafe(url, appOrigin)) return;
|
||||
|
||||
widgets.push(
|
||||
new Widget({
|
||||
id,
|
||||
creatorUserId,
|
||||
type,
|
||||
url,
|
||||
name,
|
||||
data,
|
||||
waitForIframeLoad,
|
||||
}),
|
||||
);
|
||||
});
|
||||
return widgets;
|
||||
};
|
||||
|
||||
/**
|
||||
* All valid `im.vector.modular.widgets` room widgets, reactive on room state.
|
||||
* `WidgetParser` drops empty/removed (`{}`) and malformed entries.
|
||||
*/
|
||||
export const useRoomWidgets = (room: Room): Widget[] => {
|
||||
const state = useRoomState(room);
|
||||
return useMemo(() => {
|
||||
const widgetEvents = state.get(StateEvent.Widget);
|
||||
if (!widgetEvents) return [];
|
||||
const stateEvents = Array.from(widgetEvents.values()).map(
|
||||
(event) => event.getEffectiveEvent() as unknown as IStateEvent,
|
||||
);
|
||||
return WidgetParser.parseWidgetsFromRoomState(stateEvents);
|
||||
}, [state]);
|
||||
return useMemo(
|
||||
() => widgetsFromStateEvents(state.get(StateEvent.Widget), window.location.origin),
|
||||
[state],
|
||||
);
|
||||
};
|
||||
|
||||
@@ -751,22 +751,32 @@ function ProfilePronouns() {
|
||||
|
||||
const [pronouns, setPronouns] = useState<string>('');
|
||||
const [savedPronouns, setSavedPronouns] = useState<string>('');
|
||||
// True once the user has edited the field — guards against the mount-time
|
||||
// fetch below clobbering a fresh edit if it resolves late (mirrors
|
||||
// ProfileStatus's statusDirtyRef in this file).
|
||||
const pronounsDirtyRef = useRef(false);
|
||||
|
||||
useEffect(() => {
|
||||
let cancelled = false;
|
||||
mx.http
|
||||
.authedRequest<{ 'm.pronouns': string }>(
|
||||
Method.Get,
|
||||
`/profile/${encodeURIComponent(userId)}/m.pronouns`,
|
||||
)
|
||||
.then((res) => {
|
||||
if (cancelled || pronounsDirtyRef.current) return;
|
||||
const val = res['m.pronouns'] ?? '';
|
||||
setPronouns(val);
|
||||
setSavedPronouns(val);
|
||||
})
|
||||
.catch(() => {
|
||||
if (cancelled || pronounsDirtyRef.current) return;
|
||||
setPronouns('');
|
||||
setSavedPronouns('');
|
||||
});
|
||||
return () => {
|
||||
cancelled = true;
|
||||
};
|
||||
}, [mx, userId]);
|
||||
|
||||
const [saveState, savePronouns] = useAsyncCallback(
|
||||
@@ -788,10 +798,12 @@ function ProfilePronouns() {
|
||||
const saving = saveState.status === AsyncStatus.Loading;
|
||||
|
||||
const handleChange: ChangeEventHandler<HTMLInputElement> = (evt) => {
|
||||
pronounsDirtyRef.current = true;
|
||||
setPronouns(evt.currentTarget.value);
|
||||
};
|
||||
|
||||
const handleReset = () => {
|
||||
pronounsDirtyRef.current = true;
|
||||
setPronouns(savedPronouns);
|
||||
};
|
||||
|
||||
@@ -875,10 +887,15 @@ function ProfileTimezone() {
|
||||
|
||||
const [timezone, setTimezone] = useState<string>('');
|
||||
const [savedTimezone, setSavedTimezone] = useState<string>('');
|
||||
// True once the user has edited the field — guards against the mount-time
|
||||
// fetch below clobbering a fresh edit if it resolves late (mirrors
|
||||
// ProfileStatus's statusDirtyRef in this file).
|
||||
const timezoneDirtyRef = useRef(false);
|
||||
|
||||
useEffect(() => {
|
||||
let cancelled = false;
|
||||
const cached = getAccountData<{ timezone: string }>(mx, 'im.lotus.timezone');
|
||||
if (cached?.timezone) {
|
||||
if (cached?.timezone && !timezoneDirtyRef.current) {
|
||||
setTimezone(cached.timezone);
|
||||
setSavedTimezone(cached.timezone);
|
||||
}
|
||||
@@ -889,6 +906,7 @@ function ProfileTimezone() {
|
||||
`/user/${encodeURIComponent(userId)}/account_data/im.lotus.timezone`,
|
||||
)
|
||||
.then((res) => {
|
||||
if (cancelled || timezoneDirtyRef.current) return;
|
||||
const val = res.timezone ?? '';
|
||||
setTimezone(val);
|
||||
setSavedTimezone(val);
|
||||
@@ -896,6 +914,9 @@ function ProfileTimezone() {
|
||||
.catch(() => {
|
||||
/* no stored timezone yet */
|
||||
});
|
||||
return () => {
|
||||
cancelled = true;
|
||||
};
|
||||
}, [mx, userId]);
|
||||
|
||||
const [saveState, saveTimezone] = useAsyncCallback(
|
||||
@@ -921,7 +942,13 @@ function ProfileTimezone() {
|
||||
);
|
||||
const saving = saveState.status === AsyncStatus.Loading;
|
||||
|
||||
const handleChange = (value: string) => {
|
||||
timezoneDirtyRef.current = true;
|
||||
setTimezone(value);
|
||||
};
|
||||
|
||||
const handleReset = () => {
|
||||
timezoneDirtyRef.current = true;
|
||||
setTimezone(savedTimezone);
|
||||
};
|
||||
|
||||
@@ -955,7 +982,7 @@ function ProfileTimezone() {
|
||||
{ value: '', label: '— select timezone —' },
|
||||
...COMMON_TIMEZONES.map((tz) => ({ value: tz, label: tz })),
|
||||
]}
|
||||
onChange={setTimezone}
|
||||
onChange={handleChange}
|
||||
disabled={saving}
|
||||
aria-label="Timezone"
|
||||
/>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import React, { useCallback, useEffect, useState } from 'react';
|
||||
import React, { useCallback, useEffect, useRef, useState } from 'react';
|
||||
import { Box, Button, Text, Spinner, color } from 'folds';
|
||||
import { Method } from 'matrix-js-sdk';
|
||||
import { useMatrixClient } from '../../../hooks/useMatrixClient';
|
||||
@@ -67,24 +67,47 @@ export function ProfileDecoration() {
|
||||
|
||||
const [current, setCurrent] = useState<string | null>(null);
|
||||
const [selected, setSelected] = useState<string | null>(null);
|
||||
// Distinguish "confirmed no decoration" from "failed to load": a fetch
|
||||
// failure must not be shown as (and saved over) "None".
|
||||
const [loadError, setLoadError] = useState(false);
|
||||
const [loading, setLoading] = useState(true);
|
||||
// True once the user has picked/cleared a decoration — guards against the
|
||||
// mount-time fetch below clobbering a fresh selection if it resolves late
|
||||
// (mirrors ProfileStatus's statusDirtyRef in Profile.tsx).
|
||||
const dirtyRef = useRef(false);
|
||||
|
||||
useEffect(() => {
|
||||
const fetchDecoration = useCallback(() => {
|
||||
let cancelled = false;
|
||||
setLoading(true);
|
||||
// Fetch the whole profile, not the `/{field}` sub-resource: an unset field
|
||||
// 404s (a console error for anyone without a decoration). The full profile
|
||||
// returns 200 with all fields incl. custom MSC4133 ones — read it out.
|
||||
mx.http
|
||||
.authedRequest<Record<string, string>>(Method.Get, `/profile/${encodeURIComponent(userId)}`)
|
||||
.then((res) => {
|
||||
if (cancelled) return;
|
||||
setLoadError(false);
|
||||
setLoading(false);
|
||||
if (dirtyRef.current) return;
|
||||
const val = (res[PROFILE_FIELD] as string | undefined) ?? null;
|
||||
setCurrent(val);
|
||||
setSelected(val);
|
||||
})
|
||||
.catch(() => {
|
||||
setCurrent(null);
|
||||
setSelected(null);
|
||||
if (cancelled) return;
|
||||
setLoading(false);
|
||||
// Do NOT touch current/selected here — a network failure is not proof
|
||||
// there's no decoration, and defaulting to null risks the user saving
|
||||
// "None" over a real, still-set decoration (see #46).
|
||||
setLoadError(true);
|
||||
});
|
||||
return () => {
|
||||
cancelled = true;
|
||||
};
|
||||
}, [mx, userId]);
|
||||
|
||||
useEffect(() => fetchDecoration(), [fetchDecoration]);
|
||||
|
||||
const [saveState, save] = useAsyncCallback(
|
||||
useCallback(
|
||||
async (slug: string | null) => {
|
||||
@@ -105,16 +128,27 @@ export function ProfileDecoration() {
|
||||
const hasChanges = selected !== current;
|
||||
|
||||
const handleSelect = (slug: string) => {
|
||||
dirtyRef.current = true;
|
||||
setSelected((prev) => (prev === slug ? null : slug));
|
||||
};
|
||||
|
||||
const handleClear = () => setSelected(null);
|
||||
const handleClear = () => {
|
||||
dirtyRef.current = true;
|
||||
setSelected(null);
|
||||
};
|
||||
|
||||
const handleSave = () => {
|
||||
if (!hasChanges || saving) return;
|
||||
// Refuse to save while the initial load failed: `current`/`selected` are
|
||||
// not known-good, so saving could silently overwrite a real decoration.
|
||||
if (!hasChanges || saving || loadError) return;
|
||||
save(selected);
|
||||
};
|
||||
|
||||
const handleRetry = () => {
|
||||
dirtyRef.current = false;
|
||||
fetchDecoration();
|
||||
};
|
||||
|
||||
return (
|
||||
<SettingTile
|
||||
title={
|
||||
@@ -159,13 +193,15 @@ export function ProfileDecoration() {
|
||||
</div>
|
||||
<Box grow="Yes" direction="Column" gap="100">
|
||||
<Text size="T300">
|
||||
{selected
|
||||
? (DECORATION_CATEGORIES.flatMap((c) => c.decorations).find(
|
||||
(d) => d.slug === selected,
|
||||
)?.name ?? selected)
|
||||
: 'None'}
|
||||
{loadError
|
||||
? 'Failed to load'
|
||||
: selected
|
||||
? (DECORATION_CATEGORIES.flatMap((c) => c.decorations).find(
|
||||
(d) => d.slug === selected,
|
||||
)?.name ?? selected)
|
||||
: 'None'}
|
||||
</Text>
|
||||
{selected && (
|
||||
{selected && !loadError && (
|
||||
<Button
|
||||
type="button"
|
||||
size="300"
|
||||
@@ -178,7 +214,7 @@ export function ProfileDecoration() {
|
||||
</Button>
|
||||
)}
|
||||
</Box>
|
||||
{hasChanges && (
|
||||
{hasChanges && !loadError && (
|
||||
<Button
|
||||
type="button"
|
||||
size="400"
|
||||
@@ -194,6 +230,26 @@ export function ProfileDecoration() {
|
||||
)}
|
||||
</Box>
|
||||
|
||||
{loadError && (
|
||||
<Box alignItems="Center" gap="200">
|
||||
<Text size="T200" style={{ color: color.Critical.Main }}>
|
||||
Could not load your current decoration. Saving is disabled until this succeeds, so you
|
||||
don’t overwrite it based on a wrong display.
|
||||
</Text>
|
||||
<Button
|
||||
type="button"
|
||||
size="300"
|
||||
radii="300"
|
||||
variant="Secondary"
|
||||
fill="Soft"
|
||||
onClick={handleRetry}
|
||||
disabled={loading}
|
||||
>
|
||||
<Text size="B300">{loading ? 'Retrying…' : 'Retry'}</Text>
|
||||
</Button>
|
||||
</Box>
|
||||
)}
|
||||
|
||||
{saveState.status === AsyncStatus.Error && (
|
||||
<Text size="T200" style={{ color: color.Critical.Main }}>
|
||||
Failed to save. Try again.
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import React, {
|
||||
ChangeEventHandler,
|
||||
FocusEventHandler,
|
||||
FormEventHandler,
|
||||
KeyboardEventHandler,
|
||||
MouseEventHandler,
|
||||
@@ -117,6 +118,7 @@ import { playCallJoinSound } from '../../../utils/callSounds';
|
||||
import { previewRingtone, RINGTONE_OPTIONS } from '../../../utils/ringtones';
|
||||
import { DenoiseTester } from './DenoiseTester';
|
||||
import { SettingsSelect } from '../../../components/settings-select/SettingsSelect';
|
||||
import { isBindableCallKey } from '../../../utils/callKeybind';
|
||||
|
||||
/**
|
||||
* P5-47 — opt-in TDS window chrome toggle (desktop only). Renders nothing in the
|
||||
@@ -394,6 +396,16 @@ function PageZoomInput() {
|
||||
setCurrentZoom(evt.target.value);
|
||||
};
|
||||
|
||||
// Shared by Enter and blur so a typed-but-unconfirmed value is never
|
||||
// silently dropped when the input loses focus.
|
||||
const commitZoom = (value: string) => {
|
||||
const newZoom = parseInt(value, 10);
|
||||
if (Number.isNaN(newZoom)) return;
|
||||
const safeZoom = Math.max(Math.min(newZoom, 150), 75);
|
||||
setPageZoom(safeZoom);
|
||||
setCurrentZoom(safeZoom.toString());
|
||||
};
|
||||
|
||||
const handleZoomEnter: KeyboardEventHandler<HTMLInputElement> = (evt) => {
|
||||
if (isKeyHotkey('escape', evt)) {
|
||||
evt.stopPropagation();
|
||||
@@ -404,14 +416,14 @@ function PageZoomInput() {
|
||||
'value' in evt.target &&
|
||||
typeof evt.target.value === 'string'
|
||||
) {
|
||||
const newZoom = parseInt(evt.target.value, 10);
|
||||
if (Number.isNaN(newZoom)) return;
|
||||
const safeZoom = Math.max(Math.min(newZoom, 150), 75);
|
||||
setPageZoom(safeZoom);
|
||||
setCurrentZoom(safeZoom.toString());
|
||||
commitZoom(evt.target.value);
|
||||
}
|
||||
};
|
||||
|
||||
const handleZoomBlur: FocusEventHandler<HTMLInputElement> = (evt) => {
|
||||
commitZoom(evt.target.value);
|
||||
};
|
||||
|
||||
return (
|
||||
<Input
|
||||
style={{ width: toRem(100) }}
|
||||
@@ -425,6 +437,7 @@ function PageZoomInput() {
|
||||
value={currentZoom}
|
||||
onChange={handleZoomChange}
|
||||
onKeyDown={handleZoomEnter}
|
||||
onBlur={handleZoomBlur}
|
||||
after={<Text size="T300">%</Text>}
|
||||
outlined
|
||||
/>
|
||||
@@ -1474,8 +1487,12 @@ function Privacy() {
|
||||
);
|
||||
}
|
||||
|
||||
function useKeyBind(setter: (code: string) => void) {
|
||||
// [Gitea #23] Denylist navigation-critical/modifier codes and reject a code that
|
||||
// collides with the other call key (`otherKey`), so a rebind can never trap
|
||||
// keyboard focus in-call or silently double-bind PTT and deafen to the same key.
|
||||
function useKeyBind(setter: (code: string) => void, otherKey?: string) {
|
||||
const [listening, setListening] = useState(false);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const listenerRef = useRef<((e: KeyboardEvent) => void) | null>(null);
|
||||
|
||||
useEffect(
|
||||
@@ -1487,19 +1504,28 @@ function useKeyBind(setter: (code: string) => void) {
|
||||
|
||||
const startListening = useCallback(() => {
|
||||
if (listening) return;
|
||||
setError(null);
|
||||
setListening(true);
|
||||
const onKey = (e: KeyboardEvent) => {
|
||||
e.preventDefault();
|
||||
if (e.code !== 'Escape') setter(e.code);
|
||||
if (e.code === 'Escape') {
|
||||
// Escape always cancels the rebind without changing the key.
|
||||
} else if (!isBindableCallKey(e.code)) {
|
||||
setError('That key can’t be bound — it’s needed for keyboard navigation.');
|
||||
} else if (otherKey && e.code === otherKey) {
|
||||
setError('That key is already bound to the other call shortcut.');
|
||||
} else {
|
||||
setter(e.code);
|
||||
}
|
||||
setListening(false);
|
||||
window.removeEventListener('keydown', onKey, true);
|
||||
listenerRef.current = null;
|
||||
};
|
||||
listenerRef.current = onKey;
|
||||
window.addEventListener('keydown', onKey, true);
|
||||
}, [listening, setter]);
|
||||
}, [listening, setter, otherKey]);
|
||||
|
||||
return { listening, startListening };
|
||||
return { listening, startListening, error };
|
||||
}
|
||||
|
||||
const keyLabel = (code: string) =>
|
||||
@@ -1556,8 +1582,8 @@ function Calls() {
|
||||
previewRingtone(value, Math.max(0, Math.min(1, ringtoneVolume / 100)));
|
||||
};
|
||||
|
||||
const pttBind = useKeyBind(setPttKey);
|
||||
const deafenBind = useKeyBind(setDeafenKey);
|
||||
const pttBind = useKeyBind(setPttKey, deafenKey);
|
||||
const deafenBind = useKeyBind(setDeafenKey, pttKey);
|
||||
|
||||
const mlSupported = isMLDenoiseSupported();
|
||||
const selectedDenoiseModel = DENOISE_MODELS.find((m) => m.id === callDenoiseModel);
|
||||
@@ -1823,7 +1849,7 @@ function Calls() {
|
||||
{pttMode && (
|
||||
<SettingTile
|
||||
title="PTT Key"
|
||||
description="Press a key to bind it as your push-to-talk key."
|
||||
description={pttBind.error ?? 'Press a key to bind it as your push-to-talk key.'}
|
||||
after={
|
||||
<Button
|
||||
size="300"
|
||||
@@ -1841,7 +1867,9 @@ function Calls() {
|
||||
)}
|
||||
<SettingTile
|
||||
title="Push to Deafen"
|
||||
description="Toggle speaker mute during a call. Press Escape to cancel rebind."
|
||||
description={
|
||||
deafenBind.error ?? 'Toggle speaker mute during a call. Press Escape to cancel rebind.'
|
||||
}
|
||||
after={
|
||||
<Button
|
||||
size="300"
|
||||
@@ -2328,6 +2356,7 @@ function Messages() {
|
||||
'translateTargetLang',
|
||||
);
|
||||
const [autoTranslate, setAutoTranslate] = useSetting(settingsAtom, 'autoTranslate');
|
||||
const [gifPickerEnabled, setGifPickerEnabled] = useSetting(settingsAtom, 'gifPickerEnabled');
|
||||
const translationSupported = chromeTranslationEngine.isSupported();
|
||||
const selectedTargetLang = isSupportedTargetLang(translateTargetLang)
|
||||
? normalizeLang(translateTargetLang)
|
||||
@@ -2430,6 +2459,15 @@ function Messages() {
|
||||
}
|
||||
/>
|
||||
</SequenceCard>
|
||||
<SequenceCard className={SequenceCardStyle} variant="SurfaceVariant" direction="Column">
|
||||
<SettingTile
|
||||
title="GIF Picker"
|
||||
description="Every search term (and your IP address) is sent directly to Giphy, not through your homeserver. Off by default."
|
||||
after={
|
||||
<Switch variant="Primary" value={gifPickerEnabled} onChange={setGifPickerEnabled} />
|
||||
}
|
||||
/>
|
||||
</SequenceCard>
|
||||
<SequenceCard className={SequenceCardStyle} variant="SurfaceVariant" direction="Column">
|
||||
<SettingTile
|
||||
title="Show Hidden Events"
|
||||
|
||||
@@ -11,12 +11,19 @@ import { SequenceCard } from '../../../components/sequence-card';
|
||||
import { SequenceCardStyle } from '../styles.css';
|
||||
import { SettingTile } from '../../../components/setting-tile';
|
||||
import { settingsAtom, Settings } from '../../../state/settings';
|
||||
import { notificationSnoozeUntilAtom } from '../../../state/notificationSnooze';
|
||||
|
||||
const PRESETS: Array<{
|
||||
label: string;
|
||||
icon: IconSrc;
|
||||
description: string;
|
||||
patch: Partial<Settings>;
|
||||
// Whether applying this preset should also clear an active "Pause
|
||||
// Notifications" snooze. Work/Gaming both claim notifications end up on,
|
||||
// so a leftover snooze would silently contradict them (#48). Sleep's
|
||||
// description ("All notifications off") is still true with a snooze left
|
||||
// active, so it does not need to touch it.
|
||||
clearSnooze: boolean;
|
||||
}> = [
|
||||
{
|
||||
label: 'Gaming',
|
||||
@@ -29,6 +36,7 @@ const PRESETS: Array<{
|
||||
inviteSoundId: 'none',
|
||||
quietHoursEnabled: false,
|
||||
},
|
||||
clearSnooze: true,
|
||||
},
|
||||
{
|
||||
label: 'Work',
|
||||
@@ -41,6 +49,7 @@ const PRESETS: Array<{
|
||||
inviteSoundId: 'invite',
|
||||
quietHoursEnabled: false,
|
||||
},
|
||||
clearSnooze: true,
|
||||
},
|
||||
{
|
||||
label: 'Sleep',
|
||||
@@ -51,15 +60,23 @@ const PRESETS: Array<{
|
||||
isNotificationSounds: false,
|
||||
quietHoursEnabled: false,
|
||||
},
|
||||
clearSnooze: false,
|
||||
},
|
||||
];
|
||||
|
||||
function NotificationPresets() {
|
||||
const settings = useAtomValue(settingsAtom);
|
||||
const setSettings = useSetAtom(settingsAtom);
|
||||
const setSnoozeUntil = useSetAtom(notificationSnoozeUntilAtom);
|
||||
|
||||
const applyPreset = (patch: Partial<Settings>) => {
|
||||
const applyPreset = (patch: Partial<Settings>, clearSnooze: boolean) => {
|
||||
setSettings({ ...settings, ...patch });
|
||||
// Work/Gaming promise notifications are on; an active snooze from an
|
||||
// earlier "Pause Notifications" would otherwise keep them silently
|
||||
// suppressed despite the preset applying successfully (#48).
|
||||
if (clearSnooze) {
|
||||
setSnoozeUntil(0);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
@@ -71,7 +88,7 @@ function NotificationPresets() {
|
||||
<Button
|
||||
key={preset.label}
|
||||
type="button"
|
||||
onClick={() => applyPreset(preset.patch)}
|
||||
onClick={() => applyPreset(preset.patch, preset.clearSnooze)}
|
||||
title={preset.description}
|
||||
variant="Secondary"
|
||||
fill="Soft"
|
||||
|
||||
@@ -18,6 +18,7 @@ import { useMatrixClient } from '../../../hooks/useMatrixClient';
|
||||
import { AsyncStatus, useAsyncCallback } from '../../../hooks/useAsyncCallback';
|
||||
import {
|
||||
getNotificationModeActions,
|
||||
getNotificationModeOptionsFromActions,
|
||||
NotificationMode,
|
||||
useNotificationModeActions,
|
||||
} from '../../../hooks/useNotificationMode';
|
||||
@@ -131,7 +132,13 @@ type RuleModeSwitcherProps = {
|
||||
|
||||
function RuleModeSwitcher({ kind, pushRule }: RuleModeSwitcherProps) {
|
||||
const mx = useMatrixClient();
|
||||
const getModeActions = useNotificationModeActions();
|
||||
// Preserve any `highlight`/custom sound tweak already on the rule — otherwise
|
||||
// switching mode here rebuilds actions from scratch and silently drops them.
|
||||
const options = useMemo(
|
||||
() => getNotificationModeOptionsFromActions(pushRule.actions),
|
||||
[pushRule.actions],
|
||||
);
|
||||
const getModeActions = useNotificationModeActions(options);
|
||||
|
||||
const handleChange = useCallback(
|
||||
async (mode: NotificationMode) => {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
import { MatrixError, Method } from 'matrix-js-sdk';
|
||||
import { useMatrixClient } from './useMatrixClient';
|
||||
import { isValidDecorationSlug } from '../features/lotus/avatarDecorations';
|
||||
|
||||
const PROFILE_FIELD = 'io.lotus.avatar_decoration';
|
||||
|
||||
@@ -51,7 +52,10 @@ function fetchDecoration(
|
||||
// all fields (incl. custom MSC4133 ones); read the decoration out of it.
|
||||
return authedRequest(Method.Get, `/profile/${encodeURIComponent(userId)}`)
|
||||
.then((res) => {
|
||||
const val = (res[PROFILE_FIELD] as string | undefined) ?? null;
|
||||
const rawVal = (res[PROFILE_FIELD] as string | undefined) ?? null;
|
||||
// The remote profile field is free-form and attacker-controlled; only
|
||||
// accept it when it names a real catalog decoration (see decorationUrl).
|
||||
const val = rawVal && isValidDecorationSlug(rawVal) ? rawVal : null;
|
||||
cache.set(userId, val);
|
||||
return val;
|
||||
})
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
import { test } from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import {
|
||||
Bookmark,
|
||||
cleanupEncryptedBookmarks,
|
||||
hasBookmarkText,
|
||||
stripBookmarkText,
|
||||
toStorableBookmark,
|
||||
} from './useBookmarks';
|
||||
import { cleanupEncryptedReminders, Reminder, toStorableReminder } from './useReminders';
|
||||
|
||||
// E2EE policy for bookmarks/reminders (Gitea #10): account data is stored
|
||||
// unencrypted on the homeserver, so entries for encrypted rooms must carry no
|
||||
// message text or names. `isEncryptedRoom` is injected to keep these pure.
|
||||
const isEncrypted = (roomId: string) => roomId === '!enc';
|
||||
|
||||
const full = (roomId: string): Bookmark => ({
|
||||
roomId,
|
||||
eventId: `$ev-${roomId}`,
|
||||
savedAt: 100,
|
||||
previewText: 'secret text',
|
||||
roomName: 'Room',
|
||||
senderName: 'Alice',
|
||||
});
|
||||
|
||||
test('stripBookmarkText keeps only roomId/eventId/savedAt', () => {
|
||||
const stripped = stripBookmarkText(full('!enc'));
|
||||
assert.deepEqual(stripped, { roomId: '!enc', eventId: '$ev-!enc', savedAt: 100, roomName: '' });
|
||||
assert.equal(hasBookmarkText(stripped), false);
|
||||
assert.equal(hasBookmarkText(full('!enc')), true);
|
||||
});
|
||||
|
||||
test('toStorableBookmark strips text for encrypted rooms only', () => {
|
||||
const plain = full('!plain');
|
||||
assert.equal(toStorableBookmark(plain, isEncrypted), plain);
|
||||
const enc = toStorableBookmark(full('!enc'), isEncrypted);
|
||||
assert.equal(enc.previewText, undefined);
|
||||
assert.equal(enc.senderName, undefined);
|
||||
assert.equal(enc.roomName, '');
|
||||
});
|
||||
|
||||
test('cleanupEncryptedBookmarks returns undefined when nothing to strip', () => {
|
||||
const already = stripBookmarkText(full('!enc'));
|
||||
assert.equal(cleanupEncryptedBookmarks([full('!plain'), already], isEncrypted), undefined);
|
||||
assert.equal(cleanupEncryptedBookmarks([], isEncrypted), undefined);
|
||||
});
|
||||
|
||||
test('cleanupEncryptedBookmarks strips legacy encrypted entries and keeps the rest', () => {
|
||||
const plain = full('!plain');
|
||||
const out = cleanupEncryptedBookmarks([plain, full('!enc')], isEncrypted);
|
||||
assert.ok(out);
|
||||
assert.equal(out[0], plain);
|
||||
assert.deepEqual(out[1], stripBookmarkText(full('!enc')));
|
||||
// Running it again on the result is a no-op (no write loop).
|
||||
assert.equal(cleanupEncryptedBookmarks(out, isEncrypted), undefined);
|
||||
});
|
||||
|
||||
const reminder = (roomId: string): Reminder => ({
|
||||
roomId,
|
||||
eventId: `$ev-${roomId}`,
|
||||
timestamp: 200,
|
||||
message: 'secret text',
|
||||
});
|
||||
|
||||
test('toStorableReminder drops message for encrypted rooms only', () => {
|
||||
const plain = reminder('!plain');
|
||||
assert.equal(toStorableReminder(plain, isEncrypted), plain);
|
||||
assert.deepEqual(toStorableReminder(reminder('!enc'), isEncrypted), {
|
||||
roomId: '!enc',
|
||||
eventId: '$ev-!enc',
|
||||
timestamp: 200,
|
||||
});
|
||||
});
|
||||
|
||||
test('cleanupEncryptedReminders strips legacy entries once', () => {
|
||||
const out = cleanupEncryptedReminders([reminder('!plain'), reminder('!enc')], isEncrypted);
|
||||
assert.ok(out);
|
||||
assert.equal(out[0].message, 'secret text');
|
||||
assert.equal(out[1].message, undefined);
|
||||
assert.equal(cleanupEncryptedReminders(out, isEncrypted), undefined);
|
||||
});
|
||||
@@ -1,4 +1,5 @@
|
||||
import { useCallback } from 'react';
|
||||
import { useCallback, useEffect } from 'react';
|
||||
import { MatrixClient } from 'matrix-js-sdk';
|
||||
import { useMatrixClient } from './useMatrixClient';
|
||||
import { createAccountDataListStore } from './createAccountDataListStore';
|
||||
|
||||
@@ -6,7 +7,14 @@ export type Bookmark = {
|
||||
roomId: string;
|
||||
eventId: string;
|
||||
savedAt: number;
|
||||
previewText: string;
|
||||
// Snapshot fields. Account data is stored UNENCRYPTED on the homeserver, so
|
||||
// for E2EE rooms none of these are persisted (see stripBookmarkText) — the
|
||||
// panel resolves the preview / room / author live from the local timeline
|
||||
// instead. They remain for unencrypted rooms (already server-visible) and for
|
||||
// entries saved before this policy, so older stored bookmarks still render.
|
||||
previewText?: string;
|
||||
// Kept as a (possibly empty) string in memory because the grouping helpers in
|
||||
// utils/bookmarks read it directly; the store omits it from the wire when empty.
|
||||
roomName: string;
|
||||
// Author display name, snapshotted at save time. Optional for backward
|
||||
// compatibility with bookmarks stored before attribution was added; the panel
|
||||
@@ -16,22 +24,83 @@ export type Bookmark = {
|
||||
senderName?: string;
|
||||
};
|
||||
|
||||
// Wire shape: identical to Bookmark except that `roomName` may be absent.
|
||||
type StoredBookmark = Omit<Bookmark, 'roomName'> & { roomName?: string };
|
||||
|
||||
const BOOKMARKS_KEY = 'io.lotus.bookmarks';
|
||||
const MAX_BOOKMARKS = 500;
|
||||
|
||||
type BookmarksContent = {
|
||||
bookmarks: Bookmark[];
|
||||
bookmarks: StoredBookmark[];
|
||||
};
|
||||
|
||||
/** True when the entry carries any of the text fields we refuse to upload for E2EE rooms. */
|
||||
export const hasBookmarkText = (b: Bookmark): boolean =>
|
||||
b.previewText !== undefined || b.roomName !== '' || b.senderName !== undefined;
|
||||
|
||||
/**
|
||||
* Reduce a bookmark to its non-text fields ({roomId, eventId, savedAt}). Used for
|
||||
* messages in encrypted rooms so no decrypted plaintext (or who said it) ever
|
||||
* reaches the server's account-data store.
|
||||
*/
|
||||
export const stripBookmarkText = (b: Bookmark): Bookmark => ({
|
||||
roomId: b.roomId,
|
||||
eventId: b.eventId,
|
||||
savedAt: b.savedAt,
|
||||
roomName: '',
|
||||
});
|
||||
|
||||
/**
|
||||
* Apply the E2EE storage policy to a bookmark about to be persisted.
|
||||
* `isEncryptedRoom` is injected so the policy is testable without a client.
|
||||
*/
|
||||
export const toStorableBookmark = (
|
||||
b: Bookmark,
|
||||
isEncryptedRoom: (roomId: string) => boolean,
|
||||
): Bookmark => (isEncryptedRoom(b.roomId) ? stripBookmarkText(b) : b);
|
||||
|
||||
/**
|
||||
* One-time cleanup for entries persisted before the E2EE policy: returns the list
|
||||
* with text fields stripped for every bookmark whose room is currently encrypted,
|
||||
* or `undefined` when nothing needs to change (so callers can skip the write).
|
||||
*/
|
||||
export const cleanupEncryptedBookmarks = (
|
||||
bookmarks: Bookmark[],
|
||||
isEncryptedRoom: (roomId: string) => boolean,
|
||||
): Bookmark[] | undefined => {
|
||||
let changed = false;
|
||||
const next = bookmarks.map((b) => {
|
||||
if (hasBookmarkText(b) && isEncryptedRoom(b.roomId)) {
|
||||
changed = true;
|
||||
return stripBookmarkText(b);
|
||||
}
|
||||
return b;
|
||||
});
|
||||
return changed ? next : undefined;
|
||||
};
|
||||
|
||||
const isEncryptedRoomFor =
|
||||
(mx: MatrixClient) =>
|
||||
(roomId: string): boolean =>
|
||||
mx.getRoom(roomId)?.hasEncryptionStateEvent() ?? false;
|
||||
|
||||
// Shared, concurrency-safe store. See createAccountDataListStore for why the
|
||||
// snapshot + write queue must be module-scoped (writes are serialized to avoid
|
||||
// lost updates, since setAccountData replaces the whole content with no merge).
|
||||
const bookmarksStore = createAccountDataListStore<Bookmark[], BookmarksContent>({
|
||||
eventType: BOOKMARKS_KEY,
|
||||
read: (content) => content?.bookmarks ?? [],
|
||||
write: (bookmarks) => ({ bookmarks }),
|
||||
read: (content) => (content?.bookmarks ?? []).map((b) => ({ ...b, roomName: b.roomName ?? '' })),
|
||||
write: (bookmarks) => ({
|
||||
// Drop the in-memory '' placeholder so stripped entries stay {roomId, eventId, savedAt}.
|
||||
bookmarks: bookmarks.map(({ roomName, ...rest }) => (roomName ? { ...rest, roomName } : rest)),
|
||||
}),
|
||||
});
|
||||
|
||||
// Guard so the load-time cleanup below runs once per client, not on every mount
|
||||
// (useBookmarks is mounted by every message row) and not again after its own
|
||||
// write echoes back.
|
||||
let cleanedUpFor: MatrixClient | null = null;
|
||||
|
||||
export function useBookmarks(): {
|
||||
bookmarks: Bookmark[];
|
||||
addBookmark: (b: Bookmark) => Promise<void>;
|
||||
@@ -41,12 +110,33 @@ export function useBookmarks(): {
|
||||
const mx = useMatrixClient();
|
||||
const bookmarks = bookmarksStore.useValue(mx);
|
||||
|
||||
// Strip text from entries saved (by older builds) for rooms that are encrypted,
|
||||
// writing the store back at most once per client.
|
||||
useEffect(() => {
|
||||
if (cleanedUpFor === mx) return;
|
||||
cleanedUpFor = mx;
|
||||
const cleaned = cleanupEncryptedBookmarks(bookmarksStore.getLatest(mx), isEncryptedRoomFor(mx));
|
||||
if (cleaned) {
|
||||
bookmarksStore
|
||||
.enqueueWrite(
|
||||
mx,
|
||||
(current) => cleanupEncryptedBookmarks(current, isEncryptedRoomFor(mx)) ?? current,
|
||||
)
|
||||
.catch(() => {
|
||||
// Retry on the next client (re)mount.
|
||||
if (cleanedUpFor === mx) cleanedUpFor = null;
|
||||
});
|
||||
}
|
||||
}, [mx]);
|
||||
|
||||
const addBookmark = useCallback(
|
||||
(b: Bookmark) =>
|
||||
bookmarksStore.enqueueWrite(mx, (current) => {
|
||||
// Never upload plaintext for E2EE rooms — account data is server-readable.
|
||||
const stored = toStorableBookmark(b, isEncryptedRoomFor(mx));
|
||||
// Avoid duplicates
|
||||
const filtered = current.filter((bk) => bk.eventId !== b.eventId);
|
||||
let next = [b, ...filtered];
|
||||
const filtered = current.filter((bk) => bk.eventId !== stored.eventId);
|
||||
let next = [stored, ...filtered];
|
||||
if (next.length > MAX_BOOKMARKS) {
|
||||
next = next.slice(0, MAX_BOOKMARKS);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
import { test } from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { isDeafenKeyDown, isPttKeyDown } from './useCallHotkeys';
|
||||
|
||||
const key = (
|
||||
code: string,
|
||||
mods: Partial<Record<'repeat' | 'ctrlKey' | 'altKey' | 'metaKey' | 'shiftKey', boolean>> = {},
|
||||
) => ({
|
||||
code,
|
||||
repeat: false,
|
||||
ctrlKey: false,
|
||||
altKey: false,
|
||||
metaKey: false,
|
||||
shiftKey: false,
|
||||
...mods,
|
||||
});
|
||||
|
||||
test('isPttKeyDown: matches the bare key and Shift, ignores repeats and Ctrl/Alt/Meta chords (#23)', () => {
|
||||
assert.equal(isPttKeyDown(key('Space'), 'Space'), true);
|
||||
assert.equal(isPttKeyDown(key('Space', { shiftKey: true }), 'Space'), true);
|
||||
assert.equal(isPttKeyDown(key('KeyV'), 'Space'), false);
|
||||
assert.equal(isPttKeyDown(key('Space', { repeat: true }), 'Space'), false);
|
||||
assert.equal(isPttKeyDown(key('Space', { ctrlKey: true }), 'Space'), false);
|
||||
assert.equal(isPttKeyDown(key('Space', { altKey: true }), 'Space'), false);
|
||||
assert.equal(isPttKeyDown(key('Space', { metaKey: true }), 'Space'), false);
|
||||
});
|
||||
|
||||
test('isDeafenKeyDown: matches only the bare key — any modifier (incl. Shift) is ignored (#23)', () => {
|
||||
assert.equal(isDeafenKeyDown(key('KeyM'), 'KeyM'), true);
|
||||
assert.equal(isDeafenKeyDown(key('KeyN'), 'KeyM'), false);
|
||||
assert.equal(isDeafenKeyDown(key('KeyM', { repeat: true }), 'KeyM'), false);
|
||||
assert.equal(isDeafenKeyDown(key('KeyM', { shiftKey: true }), 'KeyM'), false);
|
||||
assert.equal(isDeafenKeyDown(key('KeyM', { ctrlKey: true }), 'KeyM'), false);
|
||||
assert.equal(isDeafenKeyDown(key('KeyM', { metaKey: true }), 'KeyM'), false);
|
||||
});
|
||||
@@ -0,0 +1,214 @@
|
||||
import { useEffect, useRef } from 'react';
|
||||
import { atom, useSetAtom } from 'jotai';
|
||||
import { CallEmbed, useCallControlState } from '../plugins/call';
|
||||
import { useSetting } from '../state/hooks/settings';
|
||||
import { settingsAtom } from '../state/settings';
|
||||
|
||||
/**
|
||||
* True while a push-to-talk key is held. Written by useCallHotkeys (mounted for
|
||||
* the lifetime of the embed) and read by the PTT chip in CallControls, which
|
||||
* only renders while the call room is selected.
|
||||
*/
|
||||
export const pttActiveAtom = atom(false);
|
||||
|
||||
type KeyLike = {
|
||||
code: string;
|
||||
repeat: boolean;
|
||||
ctrlKey: boolean;
|
||||
altKey: boolean;
|
||||
metaKey: boolean;
|
||||
shiftKey: boolean;
|
||||
};
|
||||
|
||||
/**
|
||||
* Whether a keydown should engage push-to-talk for `pttKey`.
|
||||
* [Gitea #23] Ignore the PTT key with Ctrl/Alt/Meta held so it doesn't hijack
|
||||
* OS/app chords (e.g. Cmd+Space) that happen to share the code. Shift is
|
||||
* allowed through — Shift+Space is a harmless combo for PTT.
|
||||
*/
|
||||
export const isPttKeyDown = (e: KeyLike, pttKey: string): boolean =>
|
||||
e.code === pttKey && !e.repeat && !e.ctrlKey && !e.altKey && !e.metaKey;
|
||||
|
||||
/**
|
||||
* Whether a keydown should toggle deafen for `deafenKey`.
|
||||
* [Gitea #23] Ignore the deafen key with any modifier held — with the default
|
||||
* 'KeyM', Ctrl+M / Alt+M / Cmd+M are common OS/app chords that shouldn't also
|
||||
* toggle deafen (and previously got preventDefault()ed).
|
||||
*/
|
||||
export const isDeafenKeyDown = (e: KeyLike, deafenKey: string): boolean =>
|
||||
e.code === deafenKey && !e.repeat && !e.ctrlKey && !e.altKey && !e.metaKey && !e.shiftKey;
|
||||
|
||||
// BUG-7: use ownerDocument.body so isEditable works inside the EC iframe
|
||||
const isEditable = (el: HTMLElement): boolean => {
|
||||
const tag = el.tagName;
|
||||
if (tag === 'INPUT' || tag === 'TEXTAREA' || tag === 'SELECT') return true;
|
||||
let node: HTMLElement | null = el;
|
||||
while (node && node !== el.ownerDocument.body) {
|
||||
if (node.contentEditable === 'true') return true;
|
||||
if (node.contentEditable === 'false') return false;
|
||||
node = node.parentElement;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
// [Gitea #23] Don't swallow Space on a focused button/link/etc — PTT still
|
||||
// engages the mic, but the key's default action (activating the control)
|
||||
// is left alone so keyboard users can still Tab+Space the call buttons.
|
||||
const isInteractive = (el: HTMLElement): boolean => {
|
||||
const tag = el.tagName;
|
||||
if (tag === 'BUTTON' || tag === 'A' || tag === 'SELECT') return true;
|
||||
let node: HTMLElement | null = el;
|
||||
while (node && node !== el.ownerDocument.body) {
|
||||
const role = node.getAttribute('role');
|
||||
if (role === 'button' || role === 'link' || role === 'menuitem' || role === 'tab') {
|
||||
return true;
|
||||
}
|
||||
node = node.parentElement;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
/**
|
||||
* Bind listeners to the EC iframe's window and keep them bound across document
|
||||
* reloads. [Gitea #60] Listeners registered on a contentWindow are discarded
|
||||
* when that window navigates to a new document (crash recovery, in-widget
|
||||
* navigation), so re-run `bind` from the iframe's `load` event and detach the
|
||||
* previous set. Returns a cleanup that detaches everything.
|
||||
*/
|
||||
const bindIframeWindow = (
|
||||
iframe: HTMLIFrameElement,
|
||||
bind: (win: Window) => () => void,
|
||||
): (() => void) => {
|
||||
let unbind: (() => void) | undefined;
|
||||
const attach = () => {
|
||||
unbind?.();
|
||||
const win = iframe.contentWindow;
|
||||
unbind = win ? bind(win) : undefined;
|
||||
};
|
||||
attach();
|
||||
iframe.addEventListener('load', attach);
|
||||
return () => {
|
||||
iframe.removeEventListener('load', attach);
|
||||
unbind?.();
|
||||
unbind = undefined;
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* Push-to-talk and deafen hotkeys for the active call.
|
||||
*
|
||||
* [Gitea #9] Mounted from CallUtils (CallEmbedProvider) so the bindings live as
|
||||
* long as the embed — not only while the call room is the selected room. Before
|
||||
* this lived in CallControls, so navigating away (PiP) or opening the in-call
|
||||
* chat on mobile silently dropped PTT and the deafen key. Gated on `joined` so
|
||||
* nothing is sent over the widget transport before EC's handler mounts.
|
||||
*/
|
||||
export function useCallHotkeys(callEmbed: CallEmbed | undefined, joined: boolean): void {
|
||||
const embed = joined ? callEmbed : undefined;
|
||||
const [pttMode] = useSetting(settingsAtom, 'pttMode');
|
||||
const [pttKey] = useSetting(settingsAtom, 'pttKey');
|
||||
const [deafenKey] = useSetting(settingsAtom, 'deafenKey');
|
||||
const { microphone } = useCallControlState(embed?.control);
|
||||
const setPttActive = useSetAtom(pttActiveAtom);
|
||||
|
||||
// Track microphone via ref so the PTT effect doesn't need it as a dep (avoids listener churn)
|
||||
const microphoneRef = useRef(microphone);
|
||||
useEffect(() => {
|
||||
microphoneRef.current = microphone;
|
||||
}, [microphone]);
|
||||
|
||||
// Handle PTT mode toggle mid-call — save/restore mic state (I-4)
|
||||
const pttModeRef = useRef(pttMode);
|
||||
const micBeforePTTRef = useRef<boolean | null>(null);
|
||||
useEffect(() => {
|
||||
if (embed) {
|
||||
if (pttMode && !pttModeRef.current) {
|
||||
micBeforePTTRef.current = microphoneRef.current;
|
||||
embed.control.setMicrophone(false);
|
||||
} else if (!pttMode && pttModeRef.current) {
|
||||
embed.control.setMicrophone(micBeforePTTRef.current ?? true);
|
||||
micBeforePTTRef.current = null;
|
||||
}
|
||||
}
|
||||
pttModeRef.current = pttMode;
|
||||
}, [pttMode, embed]);
|
||||
|
||||
const pttActiveRef = useRef(false);
|
||||
|
||||
useEffect(() => {
|
||||
if (!embed || !pttMode) return undefined;
|
||||
|
||||
const release = () => {
|
||||
embed.control.pttActive = false;
|
||||
embed.control.setMicrophone(false);
|
||||
pttActiveRef.current = false;
|
||||
setPttActive(false);
|
||||
};
|
||||
const onKeyDown = (e: KeyboardEvent) => {
|
||||
if (!isPttKeyDown(e, pttKey)) return;
|
||||
const target = e.target as HTMLElement;
|
||||
if (isEditable(target)) return;
|
||||
if (!isInteractive(target)) e.preventDefault();
|
||||
// C-M5: mark PTT active BEFORE unmuting so the mic echo (onMediaState)
|
||||
// doesn't treat this transient unmute as a user-initiated undeafen.
|
||||
embed.control.pttActive = true;
|
||||
if (!microphoneRef.current) embed.control.setMicrophone(true);
|
||||
pttActiveRef.current = true;
|
||||
setPttActive(true);
|
||||
};
|
||||
const onKeyUp = (e: KeyboardEvent) => {
|
||||
if (e.code !== pttKey) return;
|
||||
release();
|
||||
};
|
||||
// BUG-9: release a held key when focus leaves/enters so the mic can't stick
|
||||
// open after the keyup lands elsewhere. [Gitea #27] Only when a PTT hold is
|
||||
// actually in progress — the mic button is still usable in PTT mode, and a
|
||||
// deliberate hands-free unmute must survive a click into the iframe/alt-tab.
|
||||
const onFocusChange = () => {
|
||||
if (pttActiveRef.current) release();
|
||||
};
|
||||
const bind = (win: Window) => {
|
||||
win.addEventListener('keydown', onKeyDown);
|
||||
win.addEventListener('keyup', onKeyUp);
|
||||
win.addEventListener('blur', onFocusChange);
|
||||
win.addEventListener('focus', onFocusChange);
|
||||
return () => {
|
||||
win.removeEventListener('keydown', onKeyDown);
|
||||
win.removeEventListener('keyup', onKeyUp);
|
||||
win.removeEventListener('blur', onFocusChange);
|
||||
win.removeEventListener('focus', onFocusChange);
|
||||
};
|
||||
};
|
||||
const unbindHost = bind(window);
|
||||
// BUG-9: also wire iframe key/blur/focus so PTT works with focus in the iframe
|
||||
const unbindIframe = bindIframeWindow(embed.iframe, bind);
|
||||
return () => {
|
||||
unbindHost();
|
||||
unbindIframe();
|
||||
// BUG-8: if the embed changes while PTT is active, release mic on cleanup
|
||||
if (pttActiveRef.current) release();
|
||||
};
|
||||
// microphone intentionally read via microphoneRef — excluded from deps to avoid listener churn
|
||||
}, [pttMode, pttKey, embed, setPttActive]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!embed) return undefined;
|
||||
const onKeyDown = (e: KeyboardEvent) => {
|
||||
if (!isDeafenKeyDown(e, deafenKey)) return;
|
||||
if (isEditable(e.target as HTMLElement)) return;
|
||||
e.preventDefault();
|
||||
embed.control.toggleSound();
|
||||
};
|
||||
window.addEventListener('keydown', onKeyDown);
|
||||
// C-L4: also bind the EC iframe window so the deafen key works when focus is
|
||||
// inside the iframe (mirrors the PTT binding above).
|
||||
const unbindIframe = bindIframeWindow(embed.iframe, (win) => {
|
||||
win.addEventListener('keydown', onKeyDown);
|
||||
return () => win.removeEventListener('keydown', onKeyDown);
|
||||
});
|
||||
return () => {
|
||||
window.removeEventListener('keydown', onKeyDown);
|
||||
unbindIframe();
|
||||
};
|
||||
}, [embed, deafenKey]);
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
import { useEffect } from 'react';
|
||||
import { useStore } from 'jotai';
|
||||
import { Descendant } from 'slate';
|
||||
import { roomIdToMsgDraftAtomFamily } from '../state/room/roomInputDrafts';
|
||||
import { DRAFT_MSG_KEY_PREFIX, hasMsgDraft } from '../utils/draft';
|
||||
import { useMatrixClient } from './useMatrixClient';
|
||||
|
||||
/**
|
||||
* On startup, pre-fill the per-room message-draft atoms from their localStorage
|
||||
@@ -13,11 +13,19 @@ import { DRAFT_MSG_KEY_PREFIX, hasMsgDraft } from '../utils/draft';
|
||||
* (identical content), so composer restore is unaffected.
|
||||
*
|
||||
* Thread drafts (key contains `::`) are skipped — the nav indicator is room-level.
|
||||
*
|
||||
* [Gitea #41] Drafts are stored as `{ userId, nodes }` (RoomInput's persist
|
||||
* path) so a draft written by a different account never gets hydrated into the
|
||||
* currently logged-in user's session. A legacy draft (stored as a bare array,
|
||||
* pre-dating user-scoping) has no userId to check, so it's treated as foreign
|
||||
* and dropped rather than trusted.
|
||||
*/
|
||||
export function useHydrateMsgDrafts(): void {
|
||||
const store = useStore();
|
||||
const mx = useMatrixClient();
|
||||
|
||||
useEffect(() => {
|
||||
const userId = mx.getUserId();
|
||||
let keys: string[];
|
||||
try {
|
||||
keys = Object.keys(localStorage);
|
||||
@@ -34,7 +42,19 @@ export function useHydrateMsgDrafts(): void {
|
||||
try {
|
||||
const stored = localStorage.getItem(key);
|
||||
if (!stored) return;
|
||||
const nodes = JSON.parse(stored) as Descendant[];
|
||||
const parsed = JSON.parse(stored);
|
||||
const foreign =
|
||||
!parsed ||
|
||||
typeof parsed !== 'object' ||
|
||||
Array.isArray(parsed) ||
|
||||
parsed.userId !== userId;
|
||||
if (foreign) {
|
||||
// Another account's (or a pre-scoping legacy) draft — never hydrate it,
|
||||
// and drop it so it can't resurface for the next login either.
|
||||
localStorage.removeItem(key);
|
||||
return;
|
||||
}
|
||||
const nodes = parsed.nodes;
|
||||
if (Array.isArray(nodes) && hasMsgDraft(nodes)) {
|
||||
store.set(roomIdToMsgDraftAtomFamily(draftKey), nodes);
|
||||
}
|
||||
@@ -42,5 +62,5 @@ export function useHydrateMsgDrafts(): void {
|
||||
// Ignore a malformed stored draft.
|
||||
}
|
||||
});
|
||||
}, [store]);
|
||||
}, [store, mx]);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
import { test } from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { PushRuleActionName, TweakName } from 'matrix-js-sdk';
|
||||
import { getNotificationModeOptionsFromActions } from './useNotificationMode';
|
||||
|
||||
test('getNotificationModeOptionsFromActions: no tweaks -> no highlight, no sound value', () => {
|
||||
const options = getNotificationModeOptionsFromActions([PushRuleActionName.Notify]);
|
||||
assert.deepEqual(options, { soundValue: undefined, highlight: false });
|
||||
});
|
||||
|
||||
test('getNotificationModeOptionsFromActions: picks up highlight: true', () => {
|
||||
const options = getNotificationModeOptionsFromActions([
|
||||
PushRuleActionName.Notify,
|
||||
{ set_tweak: TweakName.Highlight, value: true },
|
||||
]);
|
||||
assert.equal(options.highlight, true);
|
||||
});
|
||||
|
||||
test('getNotificationModeOptionsFromActions: highlight: false is not treated as set', () => {
|
||||
const options = getNotificationModeOptionsFromActions([
|
||||
PushRuleActionName.Notify,
|
||||
{ set_tweak: TweakName.Highlight, value: false },
|
||||
]);
|
||||
assert.equal(options.highlight, false);
|
||||
});
|
||||
|
||||
test('getNotificationModeOptionsFromActions: picks up a custom sound value', () => {
|
||||
const options = getNotificationModeOptionsFromActions([
|
||||
PushRuleActionName.Notify,
|
||||
{ set_tweak: TweakName.Sound, value: 'ping.ogg' },
|
||||
]);
|
||||
assert.equal(options.soundValue, 'ping.ogg');
|
||||
});
|
||||
|
||||
test('getNotificationModeOptionsFromActions: picks up both tweaks together', () => {
|
||||
const options = getNotificationModeOptionsFromActions([
|
||||
PushRuleActionName.Notify,
|
||||
{ set_tweak: TweakName.Sound, value: 'ping.ogg' },
|
||||
{ set_tweak: TweakName.Highlight, value: true },
|
||||
]);
|
||||
assert.deepEqual(options, { soundValue: 'ping.ogg', highlight: true });
|
||||
});
|
||||
@@ -49,6 +49,29 @@ export const getNotificationModeActions = (
|
||||
return actions;
|
||||
};
|
||||
|
||||
// Derive the options that would reproduce an existing rule's tweaks, so a mode
|
||||
// switch rebuilds actions on top of them instead of silently dropping a
|
||||
// `highlight` tweak (or a custom sound) that isn't part of the mode itself.
|
||||
export const getNotificationModeOptionsFromActions = (
|
||||
actions: PushRuleAction[],
|
||||
): NotificationModeOptions => {
|
||||
const soundTweak = actions.find(
|
||||
(action) => typeof action === 'object' && action.set_tweak === TweakName.Sound,
|
||||
);
|
||||
const highlightTweak = actions.find(
|
||||
(action) => typeof action === 'object' && action.set_tweak === TweakName.Highlight,
|
||||
);
|
||||
|
||||
return {
|
||||
soundValue:
|
||||
soundTweak && typeof soundTweak === 'object' && typeof soundTweak.value === 'string'
|
||||
? soundTweak.value
|
||||
: undefined,
|
||||
highlight:
|
||||
!!highlightTweak && typeof highlightTweak === 'object' && highlightTweak.value !== false,
|
||||
};
|
||||
};
|
||||
|
||||
export type GetNotificationModeCallback = (mode: NotificationMode) => PushRuleAction[];
|
||||
export const useNotificationModeActions = (
|
||||
options?: NotificationModeOptions,
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { useCallback } from 'react';
|
||||
import { useCallback, useEffect } from 'react';
|
||||
import { MatrixClient } from 'matrix-js-sdk';
|
||||
import { useMatrixClient } from './useMatrixClient';
|
||||
import { createAccountDataListStore } from './createAccountDataListStore';
|
||||
|
||||
@@ -6,7 +7,10 @@ export type Reminder = {
|
||||
roomId: string;
|
||||
eventId: string;
|
||||
timestamp: number;
|
||||
message: string;
|
||||
// Message preview. Account data is stored UNENCRYPTED on the homeserver, so
|
||||
// this is omitted for E2EE rooms (see stripReminderText) and the toast resolves
|
||||
// the text locally at fire time. Optional for entries stored before that policy.
|
||||
message?: string;
|
||||
};
|
||||
|
||||
const REMINDERS_KEY = 'io.lotus.reminders';
|
||||
@@ -15,6 +19,43 @@ type RemindersContent = {
|
||||
reminders: Reminder[];
|
||||
};
|
||||
|
||||
/** Reduce a reminder to its non-text fields ({roomId, eventId, timestamp}). */
|
||||
export const stripReminderText = (r: Reminder): Reminder => ({
|
||||
roomId: r.roomId,
|
||||
eventId: r.eventId,
|
||||
timestamp: r.timestamp,
|
||||
});
|
||||
|
||||
/** Apply the E2EE storage policy to a reminder about to be persisted. */
|
||||
export const toStorableReminder = (
|
||||
r: Reminder,
|
||||
isEncryptedRoom: (roomId: string) => boolean,
|
||||
): Reminder => (isEncryptedRoom(r.roomId) ? stripReminderText(r) : r);
|
||||
|
||||
/**
|
||||
* One-time cleanup for entries persisted before the E2EE policy; `undefined`
|
||||
* when nothing needs to change (so callers can skip the write).
|
||||
*/
|
||||
export const cleanupEncryptedReminders = (
|
||||
reminders: Reminder[],
|
||||
isEncryptedRoom: (roomId: string) => boolean,
|
||||
): Reminder[] | undefined => {
|
||||
let changed = false;
|
||||
const next = reminders.map((r) => {
|
||||
if (r.message !== undefined && isEncryptedRoom(r.roomId)) {
|
||||
changed = true;
|
||||
return stripReminderText(r);
|
||||
}
|
||||
return r;
|
||||
});
|
||||
return changed ? next : undefined;
|
||||
};
|
||||
|
||||
const isEncryptedRoomFor =
|
||||
(mx: MatrixClient) =>
|
||||
(roomId: string): boolean =>
|
||||
mx.getRoom(roomId)?.hasEncryptionStateEvent() ?? false;
|
||||
|
||||
// Shared, concurrency-safe store. See createAccountDataListStore for why the
|
||||
// snapshot + write queue must be module-scoped (writes are serialized to avoid
|
||||
// lost updates, since setAccountData replaces the whole content with no merge).
|
||||
@@ -24,6 +65,9 @@ const remindersStore = createAccountDataListStore<Reminder[], RemindersContent>(
|
||||
write: (reminders) => ({ reminders }),
|
||||
});
|
||||
|
||||
// Once-per-client guard for the load-time cleanup (mirrors useBookmarks).
|
||||
let cleanedUpFor: MatrixClient | null = null;
|
||||
|
||||
export function useReminders(): {
|
||||
reminders: Reminder[];
|
||||
addReminder: (r: Reminder) => Promise<void>;
|
||||
@@ -33,8 +77,30 @@ export function useReminders(): {
|
||||
const mx = useMatrixClient();
|
||||
const reminders = remindersStore.useValue(mx);
|
||||
|
||||
// Strip text from entries saved (by older builds) for rooms that are encrypted,
|
||||
// writing the store back at most once per client.
|
||||
useEffect(() => {
|
||||
if (cleanedUpFor === mx) return;
|
||||
cleanedUpFor = mx;
|
||||
if (cleanupEncryptedReminders(remindersStore.getLatest(mx), isEncryptedRoomFor(mx))) {
|
||||
remindersStore
|
||||
.enqueueWrite(
|
||||
mx,
|
||||
(current) => cleanupEncryptedReminders(current, isEncryptedRoomFor(mx)) ?? current,
|
||||
)
|
||||
.catch(() => {
|
||||
if (cleanedUpFor === mx) cleanedUpFor = null;
|
||||
});
|
||||
}
|
||||
}, [mx]);
|
||||
|
||||
const addReminder = useCallback(
|
||||
(r: Reminder) => remindersStore.enqueueWrite(mx, (current) => [...current, r]),
|
||||
(r: Reminder) =>
|
||||
remindersStore.enqueueWrite(mx, (current) => [
|
||||
...current,
|
||||
// Never upload plaintext for E2EE rooms — account data is server-readable.
|
||||
toStorableReminder(r, isEncryptedRoomFor(mx)),
|
||||
]),
|
||||
[mx],
|
||||
);
|
||||
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
import { Room } from 'matrix-js-sdk';
|
||||
import { useMemo } from 'react';
|
||||
import { useStateEvent } from './useStateEvent';
|
||||
import { StateEvent } from '../../types/matrix/room';
|
||||
import { RoomQualityContent } from '../utils/callQuality';
|
||||
|
||||
export type RoomCallPolicy = {
|
||||
allowCamera: boolean;
|
||||
allowScreenshare: boolean;
|
||||
};
|
||||
|
||||
/**
|
||||
* [Gitea #26] Shared room-level camera/screenshare policy, read from the
|
||||
* `io.lotus.room_quality` state event. Absent/true = allowed; only an explicit
|
||||
* `false` forbids. Hoisted out of `CallControls` so other call surfaces (e.g.
|
||||
* the app-wide `CallStatus` bar) can apply the same gating.
|
||||
*/
|
||||
export const useRoomCallPolicy = (room: Room): RoomCallPolicy => {
|
||||
const roomQualityEvent = useStateEvent(room, StateEvent.LotusRoomQuality);
|
||||
|
||||
return useMemo(() => {
|
||||
const roomQuality = roomQualityEvent?.getContent<RoomQualityContent>();
|
||||
return {
|
||||
allowCamera: roomQuality?.allow_camera !== false,
|
||||
allowScreenshare: roomQuality?.allow_screenshare !== false,
|
||||
};
|
||||
}, [roomQualityEvent]);
|
||||
};
|
||||
@@ -0,0 +1,93 @@
|
||||
import { test } from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import type { MatrixClient } from 'matrix-js-sdk';
|
||||
import { getLocalRoomNamesContent, setLocalRoomName } from './useRoomMeta';
|
||||
|
||||
// Minimal fake client. Mirrors the real SDK behavior that matters here:
|
||||
// setAccountData resolves WITHOUT updating what getAccountData returns — the
|
||||
// local cache only updates once the /sync echo is delivered via the
|
||||
// AccountData listener. This is exactly the staleness that let two
|
||||
// back-to-back renames clobber each other before the fix (issue #17).
|
||||
const makeFakeMx = () => {
|
||||
const accountData: Record<string, unknown> = {};
|
||||
const listeners: Array<(e: { getType: () => string; getContent: () => unknown }) => void> = [];
|
||||
const setAccountDataCalls: Array<{ type: string; content: unknown }> = [];
|
||||
|
||||
const mx = {
|
||||
getAccountData: (type: string) => {
|
||||
const content = accountData[type];
|
||||
return content ? { getContent: () => content } : undefined;
|
||||
},
|
||||
setAccountData: (type: string, content: unknown) => {
|
||||
setAccountDataCalls.push({ type, content });
|
||||
// Deliberately do NOT update `accountData` here — the real SDK doesn't
|
||||
// either. It only updates on the emitted echo below.
|
||||
return Promise.resolve();
|
||||
},
|
||||
on: (_event: unknown, h: (e: { getType: () => string; getContent: () => unknown }) => void) => {
|
||||
listeners.push(h);
|
||||
},
|
||||
removeListener: (
|
||||
_event: unknown,
|
||||
h: (e: { getType: () => string; getContent: () => unknown }) => void,
|
||||
) => {
|
||||
const i = listeners.indexOf(h);
|
||||
if (i >= 0) listeners.splice(i, 1);
|
||||
},
|
||||
};
|
||||
|
||||
const emitEcho = (type: string, content: unknown) => {
|
||||
accountData[type] = content;
|
||||
listeners.forEach((h) => h({ getType: () => type, getContent: () => content }));
|
||||
};
|
||||
|
||||
return {
|
||||
mx: mx as unknown as MatrixClient,
|
||||
emitEcho,
|
||||
setAccountDataCalls,
|
||||
};
|
||||
};
|
||||
|
||||
test('back-to-back renames of different rooms both survive with no echo in between', async () => {
|
||||
const { mx } = makeFakeMx();
|
||||
|
||||
// Rename room A, then room B, before either write's /sync echo has landed —
|
||||
// the exact scenario from issue #17.
|
||||
const writeA = setLocalRoomName(mx, '!a:example.org', 'Room A renamed');
|
||||
const writeB = setLocalRoomName(mx, '!b:example.org', 'Room B renamed');
|
||||
await Promise.all([writeA, writeB]);
|
||||
|
||||
const content = getLocalRoomNamesContent(mx);
|
||||
assert.deepEqual(content.rooms, {
|
||||
'!a:example.org': 'Room A renamed',
|
||||
'!b:example.org': 'Room B renamed',
|
||||
});
|
||||
});
|
||||
|
||||
test("writes are serialized: the second write computes from the first write's result", async () => {
|
||||
const { mx, setAccountDataCalls } = makeFakeMx();
|
||||
|
||||
await Promise.all([
|
||||
setLocalRoomName(mx, '!a:example.org', 'A'),
|
||||
setLocalRoomName(mx, '!b:example.org', 'B'),
|
||||
]);
|
||||
|
||||
// The last PUT to the server must carry both renames — proof the second
|
||||
// write's compute() saw the first write's in-memory result rather than a
|
||||
// stale snapshot from before it landed.
|
||||
const lastCall = setAccountDataCalls[setAccountDataCalls.length - 1];
|
||||
assert.deepEqual(lastCall.content, {
|
||||
rooms: { '!a:example.org': 'A', '!b:example.org': 'B' },
|
||||
});
|
||||
});
|
||||
|
||||
test('clearing a local name removes only that room', async () => {
|
||||
const { mx } = makeFakeMx();
|
||||
|
||||
await setLocalRoomName(mx, '!a:example.org', 'A');
|
||||
await setLocalRoomName(mx, '!b:example.org', 'B');
|
||||
await setLocalRoomName(mx, '!a:example.org', '');
|
||||
|
||||
const content = getLocalRoomNamesContent(mx);
|
||||
assert.deepEqual(content.rooms, { '!b:example.org': 'B' });
|
||||
});
|
||||
@@ -1,10 +1,10 @@
|
||||
import { useCallback, useEffect, useState } from 'react';
|
||||
import { useEffect, useState } from 'react';
|
||||
import { RoomJoinRulesEventContent } from 'matrix-js-sdk/lib/types';
|
||||
import { ClientEvent, MatrixEvent, Room, RoomEvent, RoomEventHandlerMap } from 'matrix-js-sdk';
|
||||
import { Room, RoomEvent, RoomEventHandlerMap } from 'matrix-js-sdk';
|
||||
import { StateEvent } from '../../types/matrix/room';
|
||||
import { useStateEvent } from './useStateEvent';
|
||||
import { useMatrixClient } from './useMatrixClient';
|
||||
import { getAccountData } from '../utils/accountData';
|
||||
import { createAccountDataListStore } from './createAccountDataListStore';
|
||||
|
||||
export const useRoomAvatar = (room: Room, dm?: boolean): string | undefined => {
|
||||
const avatarEvent = useStateEvent(room, StateEvent.RoomAvatar);
|
||||
@@ -40,73 +40,72 @@ export const LOCAL_ROOM_NAMES_KEY = 'io.lotus.room_names';
|
||||
|
||||
export type LocalRoomNamesContent = { rooms: Record<string, string> };
|
||||
|
||||
type LocalRoomNamesMap = Record<string, string>;
|
||||
|
||||
// Shared, concurrency-safe store. See createAccountDataListStore for why the
|
||||
// snapshot + write queue must be module-scoped: setAccountData does not update
|
||||
// the SDK's local cache (it only resolves once the /sync echo lands), so a
|
||||
// plain read-modify-write against getAccountData can lose a rename that is
|
||||
// still in flight when a second rename is issued (fixed: back-to-back renames
|
||||
// of different rooms no longer clobber each other).
|
||||
const roomNamesStore = createAccountDataListStore<LocalRoomNamesMap, LocalRoomNamesContent>({
|
||||
eventType: LOCAL_ROOM_NAMES_KEY,
|
||||
read: (content) =>
|
||||
content && typeof content === 'object' && typeof content.rooms === 'object'
|
||||
? content.rooms
|
||||
: {},
|
||||
write: (rooms) => ({ rooms }),
|
||||
});
|
||||
|
||||
export function getLocalRoomNamesContent(
|
||||
mx: ReturnType<typeof useMatrixClient>,
|
||||
): LocalRoomNamesContent {
|
||||
const raw: unknown = getAccountData<unknown>(mx, LOCAL_ROOM_NAMES_KEY);
|
||||
if (raw && typeof raw === 'object' && 'rooms' in raw && typeof (raw as any).rooms === 'object') {
|
||||
return raw as LocalRoomNamesContent;
|
||||
}
|
||||
return { rooms: {} };
|
||||
return { rooms: roomNamesStore.getLatest(mx) };
|
||||
}
|
||||
|
||||
/**
|
||||
* Set (or clear, when `name` is empty) the local display name for a room.
|
||||
* Routed through the shared write queue so back-to-back renames of different
|
||||
* rooms are always computed from the latest snapshot instead of a stale one.
|
||||
*/
|
||||
export function setLocalRoomName(
|
||||
mx: ReturnType<typeof useMatrixClient>,
|
||||
roomId: string,
|
||||
name: string,
|
||||
): Promise<void> {
|
||||
return roomNamesStore.enqueueWrite(mx, (current) => {
|
||||
if (!name) {
|
||||
const { [roomId]: _removed, ...rest } = current;
|
||||
return rest;
|
||||
}
|
||||
return { ...current, [roomId]: name };
|
||||
});
|
||||
}
|
||||
|
||||
export const useLocalRoomName = (room: Room): string => {
|
||||
const mx = useMatrixClient();
|
||||
|
||||
const getLocalName = useCallback((): string => {
|
||||
const content = getLocalRoomNamesContent(mx);
|
||||
return content.rooms[room.roomId] ?? room.name;
|
||||
}, [mx, room]);
|
||||
|
||||
const [name, setName] = useState(getLocalName);
|
||||
const localNames = roomNamesStore.useValue(mx);
|
||||
const [name, setName] = useState(room.name);
|
||||
|
||||
useEffect(() => {
|
||||
setName(getLocalName());
|
||||
|
||||
const handleAccountData = (event: MatrixEvent) => {
|
||||
if (event.getType() !== LOCAL_ROOM_NAMES_KEY) return;
|
||||
setName(getLocalName());
|
||||
};
|
||||
mx.on(ClientEvent.AccountData, handleAccountData);
|
||||
setName(room.name);
|
||||
|
||||
const handleRoomNameChange: RoomEventHandlerMap[RoomEvent.Name] = () => {
|
||||
setName(getLocalName());
|
||||
setName(room.name);
|
||||
};
|
||||
room.on(RoomEvent.Name, handleRoomNameChange);
|
||||
|
||||
return () => {
|
||||
mx.removeListener(ClientEvent.AccountData, handleAccountData);
|
||||
room.removeListener(RoomEvent.Name, handleRoomNameChange);
|
||||
};
|
||||
}, [mx, room, getLocalName]);
|
||||
}, [room]);
|
||||
|
||||
return name;
|
||||
return localNames[room.roomId] ?? name;
|
||||
};
|
||||
|
||||
export const useHasLocalRoomName = (roomId: string): boolean => {
|
||||
const mx = useMatrixClient();
|
||||
|
||||
const check = useCallback((): boolean => {
|
||||
const content = getLocalRoomNamesContent(mx);
|
||||
return !!content.rooms[roomId];
|
||||
}, [mx, roomId]);
|
||||
|
||||
const [hasLocal, setHasLocal] = useState(check);
|
||||
|
||||
useEffect(() => {
|
||||
setHasLocal(check());
|
||||
|
||||
const handleAccountData = (event: MatrixEvent) => {
|
||||
if (event.getType() !== LOCAL_ROOM_NAMES_KEY) return;
|
||||
setHasLocal(check());
|
||||
};
|
||||
mx.on(ClientEvent.AccountData, handleAccountData);
|
||||
return () => {
|
||||
mx.removeListener(ClientEvent.AccountData, handleAccountData);
|
||||
};
|
||||
}, [mx, check]);
|
||||
|
||||
return hasLocal;
|
||||
const localNames = roomNamesStore.useValue(mx);
|
||||
return !!localNames[roomId];
|
||||
};
|
||||
|
||||
export type RoomTopicContent = {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Room, RoomEvent, RoomMemberEvent, MatrixEvent } from 'matrix-js-sdk';
|
||||
import { Room, RoomEvent, RoomMember, RoomMemberEvent, MatrixEvent } from 'matrix-js-sdk';
|
||||
import { useEffect, useState } from 'react';
|
||||
import { useMatrixClient } from './useMatrixClient';
|
||||
import { reactionOrEditEvent } from '../utils/room';
|
||||
@@ -52,15 +52,21 @@ export function useRoomReadPositions(room: Room): Map<string, string[]> {
|
||||
debounceTimer = null;
|
||||
}, 150);
|
||||
};
|
||||
const onMembership = (): void => setPositions(computePositions(room, myUserId));
|
||||
// RoomMemberEvent.Membership is emitted on the RoomMember (and re-emitted on the
|
||||
// MatrixClient), never on Room — listening on `room` never fired. Subscribe on
|
||||
// the client and filter to this room (Gitea #61).
|
||||
const onMembership = (_ev: MatrixEvent, member: RoomMember): void => {
|
||||
if (member.roomId !== room.roomId) return;
|
||||
setPositions(computePositions(room, myUserId));
|
||||
};
|
||||
room.on(RoomEvent.Receipt, onReceipt);
|
||||
(room as any).on(RoomMemberEvent.Membership, onMembership);
|
||||
mx.on(RoomMemberEvent.Membership, onMembership);
|
||||
return () => {
|
||||
if (debounceTimer !== null) clearTimeout(debounceTimer);
|
||||
room.removeListener(RoomEvent.Receipt, onReceipt);
|
||||
(room as any).removeListener(RoomMemberEvent.Membership, onMembership);
|
||||
mx.removeListener(RoomMemberEvent.Membership, onMembership);
|
||||
};
|
||||
}, [room, myUserId]);
|
||||
}, [room, myUserId, mx]);
|
||||
|
||||
return positions;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
import { useEffect } from 'react';
|
||||
import { getFallbackSession, subscribeSessionChanges } from '../state/sessions';
|
||||
|
||||
/**
|
||||
* #69 — `useSessionSync` (the full cross-tab session sync, with in-place token
|
||||
* rotation handling) is mounted only inside the authenticated `ClientRoot`
|
||||
* shell, so a tab parked on the login/register/OIDC-callback pages never
|
||||
* learns that another tab just signed in. Left alone, that tab keeps showing
|
||||
* the login form and, if submitted, starts a second device/session for the
|
||||
* same account.
|
||||
*
|
||||
* This is a deliberately lighter watcher for the unauthenticated routes: it
|
||||
* only cares about a session APPEARING where there was none before (a fresh
|
||||
* login completed in another tab) and reloads so this tab picks up the
|
||||
* authenticated shell instead. It does not need `useSessionSync`'s
|
||||
* rotation/relogin handling since there is no running client here to keep in
|
||||
* sync — do not import/duplicate that logic, just reload.
|
||||
*/
|
||||
export function useSessionAppeared(): void {
|
||||
useEffect(() => {
|
||||
// If we already have a session, there's nothing to watch for here — the
|
||||
// authenticated shell's own useSessionSync takes over once mounted.
|
||||
if (getFallbackSession()) return undefined;
|
||||
|
||||
const unsubscribe = subscribeSessionChanges((session) => {
|
||||
if (session) {
|
||||
window.location.reload();
|
||||
}
|
||||
});
|
||||
|
||||
return unsubscribe;
|
||||
}, []);
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
import { test } from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { classifySessionChange, SessionIdentity } from './useSessionSync';
|
||||
|
||||
const alice: SessionIdentity = { userId: '@alice:hs', deviceId: 'DEV1', accessToken: 'tok-1' };
|
||||
|
||||
test('classifySessionChange: session removed elsewhere → removed', () => {
|
||||
assert.equal(classifySessionChange(alice, null), 'removed');
|
||||
});
|
||||
|
||||
test('classifySessionChange: nothing before or after → none', () => {
|
||||
assert.equal(classifySessionChange(null, null), 'none');
|
||||
});
|
||||
|
||||
test('classifySessionChange: session appeared → relogin', () => {
|
||||
assert.equal(classifySessionChange(null, alice), 'relogin');
|
||||
});
|
||||
|
||||
test('classifySessionChange: different user or device → relogin', () => {
|
||||
assert.equal(classifySessionChange(alice, { ...alice, userId: '@bob:hs' }), 'relogin');
|
||||
assert.equal(classifySessionChange(alice, { ...alice, deviceId: 'DEV2' }), 'relogin');
|
||||
// Even when the access token also changed, the identity change wins.
|
||||
assert.equal(
|
||||
classifySessionChange(alice, { ...alice, deviceId: 'DEV2', accessToken: 'tok-2' }),
|
||||
'relogin',
|
||||
);
|
||||
});
|
||||
|
||||
test('classifySessionChange: same user+device, new access token → rotated (no reload)', () => {
|
||||
assert.equal(classifySessionChange(alice, { ...alice, accessToken: 'tok-2' }), 'rotated');
|
||||
});
|
||||
|
||||
test('classifySessionChange: identical credentials (metadata-only rewrite) → none', () => {
|
||||
assert.equal(classifySessionChange(alice, { ...alice }), 'none');
|
||||
});
|
||||
@@ -1,5 +1,32 @@
|
||||
import { useEffect } from 'react';
|
||||
import { getFallbackSession, subscribeSessionChanges } from '../state/sessions';
|
||||
import type { MatrixClient } from 'matrix-js-sdk';
|
||||
import { getFallbackSession, Session, subscribeSessionChanges } from '../state/sessions';
|
||||
|
||||
/** The credential identity this tab is currently running on. */
|
||||
export type SessionIdentity = Pick<Session, 'userId' | 'deviceId' | 'accessToken'>;
|
||||
|
||||
/**
|
||||
* What an out-of-tab session change means for this tab:
|
||||
* - `none` — nothing credential-relevant changed (metadata-only rewrite,
|
||||
* or a duplicate storage event from the dual-write).
|
||||
* - `removed` — the session disappeared (logout / localStorage.clear()).
|
||||
* - `relogin` — a different user or device signed in.
|
||||
* - `rotated` — same user + device, only the access token changed (an OIDC
|
||||
* refresh performed by another tab).
|
||||
*/
|
||||
export type SessionChange = 'none' | 'removed' | 'relogin' | 'rotated';
|
||||
|
||||
/** Pure: classify a freshly-read session against the one this tab runs on. */
|
||||
export const classifySessionChange = (
|
||||
current: SessionIdentity | null,
|
||||
next: SessionIdentity | null,
|
||||
): SessionChange => {
|
||||
if (!next) return current ? 'removed' : 'none';
|
||||
if (!current) return 'relogin';
|
||||
if (next.userId !== current.userId || next.deviceId !== current.deviceId) return 'relogin';
|
||||
if (next.accessToken !== current.accessToken) return 'rotated';
|
||||
return 'none';
|
||||
};
|
||||
|
||||
/**
|
||||
* Keep this tab in sync with session changes performed in other tabs/windows.
|
||||
@@ -11,26 +38,39 @@ import { getFallbackSession, subscribeSessionChanges } from '../state/sessions';
|
||||
* Default action is the safest one for auth-critical state — a full reload:
|
||||
* - session REMOVED elsewhere (logout / localStorage.clear()) → the access
|
||||
* token disappears, so we reload; the router bounces to auth on next boot.
|
||||
* - session APPEARED or its access token CHANGED elsewhere (a fresh login or
|
||||
* a token rotation) → we reload so the client re-initialises with the new
|
||||
* credentials rather than running on a stale/revoked token.
|
||||
* - session APPEARED or its user/device CHANGED elsewhere (a fresh login) →
|
||||
* we reload so the client re-initialises with the new credentials rather
|
||||
* than running on a stale/revoked token.
|
||||
*
|
||||
* A change that does not alter the access token (e.g. an OIDC metadata-only
|
||||
* #16 — a same-user, same-device access-token ROTATION (a routine OIDC refresh
|
||||
* in another tab) must NOT reload: that would drop in-progress calls/uploads
|
||||
* every few minutes. Instead the new tokens are swapped into the running
|
||||
* client in place. When no client is available yet we fall back to the reload.
|
||||
*
|
||||
* A change that does not alter the credentials (e.g. an OIDC metadata-only
|
||||
* rewrite) is ignored, which also collapses the several storage events emitted
|
||||
* by a single dual-write into at most one reload.
|
||||
* by a single dual-write into at most one reaction.
|
||||
*/
|
||||
export const useSessionSync = (): void => {
|
||||
export const useSessionSync = (mx?: MatrixClient): void => {
|
||||
useEffect(() => {
|
||||
// Snapshot the credential this tab booted with; compare against it so we
|
||||
// only reload on a genuine credential change.
|
||||
const initialAccessToken = getFallbackSession()?.accessToken ?? null;
|
||||
// Snapshot the credential this tab runs on; compare against it so we only
|
||||
// react to a genuine credential change. Updated on an in-place rotation.
|
||||
let current: SessionIdentity | null = getFallbackSession() ?? null;
|
||||
|
||||
const unsubscribe = subscribeSessionChanges((session) => {
|
||||
const nextAccessToken = session?.accessToken ?? null;
|
||||
if (nextAccessToken === initialAccessToken) return;
|
||||
const change = classifySessionChange(current, session);
|
||||
if (change === 'none') return;
|
||||
if (change === 'rotated' && mx && session) {
|
||||
// Same opts object backs the SDK's TokenRefresher, so updating the
|
||||
// refresh token here keeps its next refresh on the rotated token.
|
||||
mx.setAccessToken(session.accessToken);
|
||||
if (session.refreshToken) mx.http.opts.refreshToken = session.refreshToken;
|
||||
current = session;
|
||||
return;
|
||||
}
|
||||
window.location.reload();
|
||||
});
|
||||
|
||||
return unsubscribe;
|
||||
}, []);
|
||||
}, [mx]);
|
||||
};
|
||||
|
||||
@@ -14,5 +14,11 @@ export function useTauriCallPower(): void {
|
||||
const callEmbed = useAtomValue(callEmbedAtom);
|
||||
useEffect(() => {
|
||||
invokeTauri('set_call_active', { active: callEmbed !== undefined });
|
||||
// #76 — if the shell unmounts while a call is still active (forced
|
||||
// reload/HMR, or a future teardown path that doesn't end the call first),
|
||||
// release the native keep-awake state instead of leaving it held forever.
|
||||
return () => {
|
||||
invokeTauri('set_call_active', { active: false });
|
||||
};
|
||||
}, [callEmbed]);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import { MsgType } from 'matrix-js-sdk';
|
||||
import { useSetAtom } from 'jotai';
|
||||
import { Icons } from 'folds';
|
||||
import { useMatrixClient } from './useMatrixClient';
|
||||
import { useTauriEvent } from './useTauri';
|
||||
import { createErrorToast, toastQueueAtom } from '../state/toast';
|
||||
|
||||
/** Payload of the `lotus-notification-activate` event (a plain body click). */
|
||||
interface ActivateDetail {
|
||||
@@ -27,6 +30,7 @@ interface ReplyDetail {
|
||||
export function useTauriToastActions(): void {
|
||||
const navigate = useNavigate();
|
||||
const mx = useMatrixClient();
|
||||
const setToast = useSetAtom(toastQueueAtom);
|
||||
|
||||
useTauriEvent<ActivateDetail>('lotus-notification-activate', ({ path }) => {
|
||||
if (path) navigate(path);
|
||||
@@ -34,6 +38,17 @@ export function useTauriToastActions(): void {
|
||||
|
||||
useTauriEvent<ReplyDetail>('lotus-notification-reply', ({ roomId, text }) => {
|
||||
if (!roomId || !text) return;
|
||||
mx.sendMessage(roomId, { msgtype: MsgType.Text, body: text }).catch(() => undefined);
|
||||
// #79 — a quick-reply failure (offline, no send permission, etc.) used to
|
||||
// be swallowed with no feedback, leaving the user believing it was sent.
|
||||
// Surface it via the in-app error toast instead.
|
||||
mx.sendMessage(roomId, { msgtype: MsgType.Text, body: text }).catch(() => {
|
||||
setToast(
|
||||
createErrorToast(
|
||||
'Your quick reply could not be sent. Please try again.',
|
||||
Icons.Warning,
|
||||
'Reply failed',
|
||||
),
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
import { Room } from 'matrix-js-sdk';
|
||||
import { useMemo } from 'react';
|
||||
import { useStateEvent } from './useStateEvent';
|
||||
import { StateEvent } from '../../types/matrix/room';
|
||||
import { VoiceLimitContent } from '../features/common-settings/general/RoomVoiceLimit';
|
||||
import { useCallMembers, useCallSession } from './useCall';
|
||||
import { useMatrixClient } from './useMatrixClient';
|
||||
|
||||
export type VoiceChannelFull = {
|
||||
channelFull: boolean;
|
||||
current: number;
|
||||
max: number;
|
||||
};
|
||||
|
||||
/**
|
||||
* [Gitea #30] Voice channel user limit (`io.lotus.voice_limit`), shared between
|
||||
* `CallPrescreen` and any other join path (e.g. the room-nav second-click join)
|
||||
* so they agree on when a channel is full. 0/absent `max_users` means no limit.
|
||||
*/
|
||||
export const useVoiceChannelFull = (room: Room): VoiceChannelFull => {
|
||||
const mx = useMatrixClient();
|
||||
const callSession = useCallSession(room);
|
||||
const callMembers = useCallMembers(callSession);
|
||||
|
||||
const limitEvent = useStateEvent(room, StateEvent.LotusVoiceLimit);
|
||||
|
||||
return useMemo(() => {
|
||||
const maxUsers = limitEvent?.getContent<VoiceLimitContent>().max_users ?? 0;
|
||||
// A user already counted in the session is rejoining and should not be blocked.
|
||||
const alreadyMember = callMembers.some((m) => m.sender === mx.getSafeUserId());
|
||||
const channelFull = maxUsers > 0 && !alreadyMember && callMembers.length >= maxUsers;
|
||||
return { channelFull, current: callMembers.length, max: maxUsers };
|
||||
}, [limitEvent, callMembers, mx]);
|
||||
};
|
||||
@@ -26,6 +26,7 @@ import { settingsAtom } from '../state/settings';
|
||||
import { isWithinTimeWindow } from '../utils/timeWindow';
|
||||
import { LotusToastContainer } from '../features/toast/LotusToastContainer';
|
||||
import { useTauriNotificationBadge } from '../hooks/useTauriNotificationBadge';
|
||||
import { useSessionAppeared } from '../hooks/useSessionAppeared';
|
||||
import { useTauriWindowChrome } from '../hooks/useTauriWindowChrome';
|
||||
import { isTauri } from '../hooks/useTauri';
|
||||
import { TitleBar } from '../features/desktop/TitleBar';
|
||||
@@ -165,6 +166,12 @@ const queryClient = new QueryClient();
|
||||
function App() {
|
||||
const screenSize = useScreenSize();
|
||||
useCompositionEndTracking();
|
||||
// #69 — cross-tab session sync (useSessionSync) only mounts inside the
|
||||
// authenticated ClientRoot shell, so a tab still on the unauthenticated
|
||||
// routes (login/register/OIDC callback) never learns that another tab just
|
||||
// signed in. This lighter watcher covers that gap by reloading once a
|
||||
// session appears where there was none.
|
||||
useSessionAppeared();
|
||||
|
||||
const portalContainer = document.getElementById('portalContainer') ?? undefined;
|
||||
|
||||
|
||||
@@ -6,7 +6,12 @@ import {
|
||||
registerOidcClient,
|
||||
} from 'matrix-js-sdk';
|
||||
import { getOidcCallbackUrl, getOidcClientMetadata } from './oidcConfig';
|
||||
import { cacheClientId, getCachedClientId, invalidateCachedClient } from './oidcState';
|
||||
import {
|
||||
cacheClientId,
|
||||
getCachedClientId,
|
||||
invalidateCachedClient,
|
||||
isStaleClientError,
|
||||
} from './oidcState';
|
||||
|
||||
export { completeAuthorizationCodeGrant };
|
||||
|
||||
@@ -42,8 +47,11 @@ export const startOidcLogin = async (issuer: string, homeserverBaseUrl: string):
|
||||
});
|
||||
window.location.assign(url);
|
||||
} catch (e) {
|
||||
// Drop a possibly-stale cached client so the next attempt re-registers.
|
||||
invalidateCachedClient(issuer);
|
||||
// #67 — drop the cached client so the next attempt re-registers, but ONLY
|
||||
// when the failure says the client id itself was rejected. Network and
|
||||
// discovery failures keep the cache, otherwise each retry would register
|
||||
// yet another throwaway dynamic client at the provider.
|
||||
if (isStaleClientError(e)) invalidateCachedClient(issuer);
|
||||
throw e;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -5,6 +5,7 @@ import {
|
||||
cacheClientId,
|
||||
invalidateCachedClient,
|
||||
parseOidcCallbackParams,
|
||||
isStaleClientError,
|
||||
} from './oidcState';
|
||||
|
||||
const installStorage = (): Map<string, string> => {
|
||||
@@ -60,3 +61,24 @@ test('parseOidcCallbackParams classifies success / error / invalid', () => {
|
||||
assert.deepEqual(parseOidcCallbackParams('?code=only'), { kind: 'invalid' });
|
||||
assert.deepEqual(parseOidcCallbackParams(''), { kind: 'invalid' });
|
||||
});
|
||||
|
||||
test('isStaleClientError: only client-rejection shapes invalidate the cache', () => {
|
||||
// OAuth error responses naming the client (oidc-client-ts ErrorResponse shape).
|
||||
assert.equal(isStaleClientError({ error: 'invalid_client' }), true);
|
||||
assert.equal(isStaleClientError({ error: 'unauthorized_client' }), true);
|
||||
// HTTP 400/401 from the registration/authorize step (MatrixError-style).
|
||||
assert.equal(isStaleClientError({ httpStatus: 400 }), true);
|
||||
assert.equal(isStaleClientError({ httpStatus: 401 }), true);
|
||||
assert.equal(isStaleClientError({ status: 401 }), true);
|
||||
assert.equal(isStaleClientError({ httpStatus: 500 }), false);
|
||||
assert.equal(isStaleClientError({ httpStatus: 400, status: 200 }), true); // httpStatus wins
|
||||
});
|
||||
|
||||
test('isStaleClientError: transient / discovery / local failures keep the cache', () => {
|
||||
assert.equal(isStaleClientError(new TypeError('Failed to fetch')), false);
|
||||
assert.equal(isStaleClientError(new Error('Something went wrong with OIDC discovery')), false);
|
||||
assert.equal(isStaleClientError({ error: 'server_error' }), false);
|
||||
assert.equal(isStaleClientError(new Error('crypto.randomUUID is not a function')), false);
|
||||
assert.equal(isStaleClientError(undefined), false);
|
||||
assert.equal(isStaleClientError('invalid_client'), false); // bare strings are not error objects
|
||||
});
|
||||
|
||||
@@ -40,6 +40,32 @@ export const invalidateCachedClient = (issuer: string): void => {
|
||||
}
|
||||
};
|
||||
|
||||
// OAuth error codes that mean the provider no longer recognises our client id
|
||||
// (deleted/expired dynamic registration, or one issued by a different deployment).
|
||||
const STALE_CLIENT_ERROR_CODES = new Set(['invalid_client', 'unauthorized_client']);
|
||||
|
||||
/**
|
||||
* #67 — pure: does a `startOidcLogin` failure indicate the CACHED client id is
|
||||
* bad? Only then is dropping the registration cache justified; a transient
|
||||
* network error, an offline discovery fetch, or a local (`crypto.randomUUID`)
|
||||
* failure must leave it alone, otherwise every retry performs a fresh dynamic
|
||||
* registration and piles throwaway clients onto the provider. Recognised
|
||||
* shapes: an OAuth error response (`{ error: 'invalid_client' }`, as thrown by
|
||||
* oidc-client-ts `ErrorResponse`), or an HTTP 400/401 carried as
|
||||
* `httpStatus`/`status` (MatrixError-style) from the registration/authorize step.
|
||||
*/
|
||||
export const isStaleClientError = (e: unknown): boolean => {
|
||||
if (!e || typeof e !== 'object') return false;
|
||||
const { error, httpStatus, status } = e as {
|
||||
error?: unknown;
|
||||
httpStatus?: unknown;
|
||||
status?: unknown;
|
||||
};
|
||||
if (typeof error === 'string' && STALE_CLIENT_ERROR_CODES.has(error)) return true;
|
||||
const code = typeof httpStatus === 'number' ? httpStatus : status;
|
||||
return code === 400 || code === 401;
|
||||
};
|
||||
|
||||
/** Parsed shape of the provider's redirect back to our callback URL. */
|
||||
export type OidcCallbackParams =
|
||||
| { kind: 'success'; code: string; state: string }
|
||||
|
||||
@@ -26,6 +26,7 @@ import { settingsAtom } from '../../state/settings';
|
||||
import { allInvitesAtom } from '../../state/room-list/inviteList';
|
||||
import { useMatrixClient } from '../../hooks/useMatrixClient';
|
||||
import { useHydrateMsgDrafts } from '../../hooks/useHydrateMsgDrafts';
|
||||
import { useSearchCacheInvalidation } from '../../utils/searchCacheInvalidation';
|
||||
import {
|
||||
getDirectRoomPath,
|
||||
getHomeRoomPath,
|
||||
@@ -51,7 +52,7 @@ import {
|
||||
MuteTimerEntry,
|
||||
loadMuteTimers,
|
||||
unmuteRoom,
|
||||
} from '../../features/room-nav/RoomNavItem';
|
||||
} from '../../features/room-nav/muteTimers';
|
||||
import { STATUS_EXPIRY_KEY, STATUS_MSG_KEY } from '../../features/settings/account/Profile';
|
||||
import { useDeepLinkNavigate } from '../../hooks/useDeepLinkNavigate';
|
||||
import { toastQueueAtom } from '../../state/toast';
|
||||
@@ -70,12 +71,12 @@ import {
|
||||
THREAD_NOTIFICATIONS_FALLBACK_BEHAVIOR,
|
||||
} from '../../utils/threadNotifications';
|
||||
|
||||
// Grace period after the initial sync settles before invite notifications arm, so
|
||||
// the async invite-atom population lands first and isn't mistaken for new invites.
|
||||
const LogoSVG = withOriginBaseUrl(getOriginBaseUrl(), '/public/res/lotus.png');
|
||||
const LogoUnreadSVG = withOriginBaseUrl(getOriginBaseUrl(), '/public/res/lotus-unread.png');
|
||||
const LogoHighlightSVG = withOriginBaseUrl(getOriginBaseUrl(), '/public/res/lotus-highlight.png');
|
||||
|
||||
// Grace period after the initial sync settles before invite notifications arm, so
|
||||
// the async invite-atom population lands first and isn't mistaken for new invites.
|
||||
const INVITE_NOTIFY_ARM_DELAY_MS = 3000;
|
||||
|
||||
function SystemEmojiFeature() {
|
||||
@@ -722,14 +723,23 @@ function ReminderMonitor() {
|
||||
if (!firedRef.current.has(key)) {
|
||||
firedRef.current.add(key);
|
||||
const room = mx.getRoom(r.roomId);
|
||||
const roomName = room?.name ?? 'Unknown Room';
|
||||
// Reminders for E2EE rooms carry no text (account data is server-
|
||||
// readable), so resolve the body from the local timeline at fire time.
|
||||
const localBody = room?.findEventById(r.eventId)?.getContent()?.body;
|
||||
const body =
|
||||
r.message ??
|
||||
(typeof localBody === 'string' && localBody
|
||||
? localBody.slice(0, 120)
|
||||
: `Reminder for a message in ${roomName}`);
|
||||
const hashPath = mDirectsRef.current.has(r.roomId)
|
||||
? getDirectRoomPath(r.roomId, r.eventId)
|
||||
: getHomeRoomPath(r.roomId, r.eventId);
|
||||
setToast({
|
||||
id: `reminder-${key}`,
|
||||
displayName: 'Reminder',
|
||||
body: r.message,
|
||||
roomName: room?.name ?? 'Unknown Room',
|
||||
body,
|
||||
roomName,
|
||||
roomId: r.roomId,
|
||||
hashPath,
|
||||
});
|
||||
@@ -896,10 +906,18 @@ function MsgDraftHydrator(): null {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Gitea #14 — keeps the opt-in persistent search cache from outliving the
|
||||
// plaintext it indexed (redactions + leaving/being banned from a room).
|
||||
function SearchCacheInvalidationFeature(): null {
|
||||
useSearchCacheInvalidation();
|
||||
return null;
|
||||
}
|
||||
|
||||
export function ClientNonUIFeatures({ children }: ClientNonUIFeaturesProps) {
|
||||
return (
|
||||
<>
|
||||
<MsgDraftHydrator />
|
||||
<SearchCacheInvalidationFeature />
|
||||
<SystemEmojiFeature />
|
||||
<PageZoomFeature />
|
||||
<FaviconUpdater />
|
||||
|
||||
@@ -208,9 +208,11 @@ export function ClientRoot({ children }: ClientRootProps) {
|
||||
);
|
||||
|
||||
useLogoutListener(mx);
|
||||
// Cross-tab session sync: another tab logging out / in (access token changed
|
||||
// in localStorage) reloads this tab so it never runs with stale credentials.
|
||||
useSessionSync();
|
||||
// Cross-tab session sync: another tab logging out / in reloads this tab so it
|
||||
// never runs with stale credentials. A same-device token *rotation* (OIDC
|
||||
// refresh in another tab) is swapped into the running client instead of
|
||||
// reloading, which would drop an in-progress call/upload (#16).
|
||||
useSessionSync(mx);
|
||||
|
||||
useEffect(() => {
|
||||
if (loadState.status === AsyncStatus.Idle) {
|
||||
|
||||
@@ -33,7 +33,10 @@ export class CallControl extends EventEmitter implements CallControlState {
|
||||
// re-observe pass so a busy EC re-render doesn't thrash the control observer.
|
||||
private bodyMutationTimer?: ReturnType<typeof setTimeout>;
|
||||
|
||||
private _pipMode = false;
|
||||
// [Gitea #56] Tracks the participant currently pinned via focusCameraParticipant(),
|
||||
// so callers (MemberGlance) can render a "Focus camera" / "Unfocus camera" toggle
|
||||
// instead of a one-way pin with no way back. null == no manual pin (speaker-follows).
|
||||
private _focusedUserId: string | null = null;
|
||||
|
||||
// C-M3: last quality payload requested via setQuality(). Held so we can (re)send
|
||||
// it once joined (io.lotus.set_quality must not be sent before call-join — a
|
||||
@@ -422,10 +425,6 @@ export class CallControl extends EventEmitter implements CallControlState {
|
||||
this.spotlightButton?.click();
|
||||
}
|
||||
|
||||
public setPipMode(pip: boolean) {
|
||||
this._pipMode = pip;
|
||||
}
|
||||
|
||||
public toggleReactions() {
|
||||
this.reactionsButton?.click();
|
||||
}
|
||||
@@ -446,17 +445,29 @@ export class CallControl extends EventEmitter implements CallControlState {
|
||||
* participant has their camera off and EC didn't render a video tile for
|
||||
* them yet).
|
||||
*/
|
||||
public get focusedUserId(): string | null {
|
||||
return this._focusedUserId;
|
||||
}
|
||||
|
||||
public focusCameraParticipant(userId: string): void {
|
||||
// [lotus #4] Pin the participant via the fork's widget action instead of
|
||||
// DOM-poking tiles. EC's layout honors it — including surfacing the camera
|
||||
// alongside a screenshare (A5) — and it's version-stable. The fork always
|
||||
// acks, so the promise resolves regardless.
|
||||
this._focusedUserId = userId;
|
||||
this.call.transport.send('io.lotus.focus_participant', { userId }).catch(() => undefined);
|
||||
// [Gitea #56] Notify state-update listeners so the menu can flip to "Unfocus camera".
|
||||
this.emitStateUpdate();
|
||||
}
|
||||
|
||||
/** [lotus #4] Clear any manual spotlight pin and return to speaker-follows. */
|
||||
public clearFocusParticipant(): void {
|
||||
// [Gitea #56] No-op (and no redundant widget send) if nothing is pinned —
|
||||
// dispose() calls this unconditionally on every call teardown.
|
||||
if (this._focusedUserId === null) return;
|
||||
this._focusedUserId = null;
|
||||
this.call.transport.send('io.lotus.focus_participant', { userId: null }).catch(() => undefined);
|
||||
this.emitStateUpdate();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -502,6 +513,8 @@ export class CallControl extends EventEmitter implements CallControlState {
|
||||
clearTimeout(this.bodyMutationTimer);
|
||||
this.bodyMutationTimer = undefined;
|
||||
}
|
||||
// [Gitea #56] Don't let a manual focus pin outlive the call.
|
||||
this.clearFocusParticipant();
|
||||
this.bodyMutationObserver.disconnect();
|
||||
this.controlMutationObserver.disconnect();
|
||||
}
|
||||
|
||||
@@ -21,7 +21,8 @@ export const usePdfDocumentLoader = (pdfJS: typeof PdfJsDist | undefined, src: s
|
||||
if (!pdfJS) {
|
||||
throw new Error('PdfJS is not loaded');
|
||||
}
|
||||
const doc = await pdfJS.getDocument(src).promise;
|
||||
// pdfjs-dist 6 dropped the bare-string overload; pass the URL explicitly.
|
||||
const doc = await pdfJS.getDocument({ url: src }).promise;
|
||||
return doc;
|
||||
}, [pdfJS, src]),
|
||||
);
|
||||
|
||||
@@ -5,6 +5,31 @@ import { clearRecentForwardTargets } from './recentForwardTargets';
|
||||
import { clearRecentGifs } from './recentGifs';
|
||||
import { clearRecentStickers } from './recentStickers';
|
||||
import { clearNavToActivePathStore } from './navToActivePath';
|
||||
import { DRAFT_MSG_KEY_PREFIX } from '../utils/draft';
|
||||
|
||||
/**
|
||||
* [Gitea #41] Wipe every persisted composer draft (`draft-msg-<roomId>`). Drafts
|
||||
* hold decrypted, unsent message text with no user scoping, so leaving them in
|
||||
* place across logout lets the next account on this device see (and send) the
|
||||
* previous user's draft the moment they open the same room.
|
||||
*/
|
||||
const clearMsgDrafts = (): void => {
|
||||
let keys: string[];
|
||||
try {
|
||||
keys = Object.keys(localStorage);
|
||||
} catch {
|
||||
return;
|
||||
}
|
||||
keys.forEach((key) => {
|
||||
if (key.startsWith(DRAFT_MSG_KEY_PREFIX)) {
|
||||
try {
|
||||
localStorage.removeItem(key);
|
||||
} catch {
|
||||
// Best-effort — a single unreadable/blocked key must not abort the sweep.
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Single auditable place that wipes the `localStorage` caches holding decrypted
|
||||
@@ -18,6 +43,10 @@ import { clearNavToActivePathStore } from './navToActivePath';
|
||||
* - `cinny_recent_forward_targets_v1` — recent forward contact/room graph (PII)
|
||||
* - `cinny_recent_gifs_v1` / `cinny_recent_stickers_v1` — media the user sent
|
||||
* - `navToActivePath<userId>` — per-space last-visited room paths (needs userId)
|
||||
* - `draft-msg-*` — unsent composer drafts (decrypted message text, unscoped by
|
||||
* user — see [Gitea #41]; previously deliberately preserved across logout
|
||||
* (N98), which let the next account on this device see/send a prior user's
|
||||
* draft, so this is no longer a "by design" exemption)
|
||||
*
|
||||
* NOT swept here (by design):
|
||||
* - session credential keys → `removeFallbackSession()`
|
||||
@@ -25,9 +54,8 @@ import { clearNavToActivePathStore } from './navToActivePath';
|
||||
* bookmarks, user notes, status presets — themselves plaintext) → wiped by
|
||||
* `mx.clearStores()` on both logout paths
|
||||
* - the opt-in encrypted-search index (IndexedDB) → `deleteSearchCacheDatabase()`
|
||||
* - unsent composer drafts (`draft-msg-*`) and the presence status message
|
||||
* (`lotus-status-msg-*`) are deliberately preserved across a normal logout
|
||||
* (N98); clearing them is a separate product decision
|
||||
* - the presence status message (`lotus-status-msg-*`) is deliberately
|
||||
* preserved across a normal logout; clearing it is a separate product decision
|
||||
* - low-sensitivity UI/metadata residue (`io.lotus.mute_timers`, collapsed
|
||||
* nav/space categories, `cinny_oidc_dynamic_clients`) is treated as
|
||||
* preferences, not swept here
|
||||
@@ -39,5 +67,6 @@ export const clearPlaintextCaches = (userId?: string): void => {
|
||||
clearRecentForwardTargets();
|
||||
clearRecentGifs();
|
||||
clearRecentStickers();
|
||||
clearMsgDrafts();
|
||||
if (userId) clearNavToActivePathStore(userId);
|
||||
};
|
||||
|
||||
@@ -25,8 +25,10 @@ export const setMarkedUnread = (
|
||||
unread: boolean,
|
||||
): Promise<unknown> =>
|
||||
Promise.all([
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
mx.setRoomAccountData(roomId, AccountDataEvent.MarkedUnread as any, { unread }),
|
||||
// Best-effort mirror for older servers; never fail the primary write on it.
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
mx.setRoomAccountData(roomId, UNSTABLE_MARKED_UNREAD as any, { unread }).catch(() => undefined),
|
||||
]);
|
||||
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user