mirror of
https://github.com/SableClient/Sable.git
synced 2026-11-28 21:06:27 -08:00
Merge branch 'dev' into feat/msc4459
This commit is contained in:
643 files changed
+7567
-6425
No files matched your search
@@ -0,0 +1,5 @@
|
||||
---
|
||||
default: fix
|
||||
---
|
||||
|
||||
Fix spam-clicking abbreviations crashing sable
|
||||
@@ -0,0 +1,5 @@
|
||||
---
|
||||
default: minor
|
||||
---
|
||||
|
||||
Add preventing url preview cards by surrounding a link in anglebrackets like <https://app.sable.moe>
|
||||
@@ -0,0 +1,5 @@
|
||||
---
|
||||
default: minor
|
||||
---
|
||||
|
||||
Reorganize Embed settings and reintroduce multiple embeds
|
||||
@@ -0,0 +1,5 @@
|
||||
---
|
||||
default: minor
|
||||
---
|
||||
|
||||
Change Misc. data styling in users profile pages
|
||||
@@ -0,0 +1,5 @@
|
||||
---
|
||||
default: patch
|
||||
---
|
||||
|
||||
Add cache-control headers in Caddyfile for assets, service worker, and index.html
|
||||
@@ -0,0 +1,13 @@
|
||||
---
|
||||
default: patch
|
||||
---
|
||||
|
||||
# Change how settings links are shared
|
||||
|
||||
Settings links copied from Sable now stay on the current client URL and include a small Sable marker in the link. That lets Sable recognize settings links copied from other Sable instances without treating unrelated third-party `/settings/...` links as Sable settings links.
|
||||
|
||||
When you send a bare settings link in the composer, Sable now rewrites it into a labeled link so it looks better on non-Sable clients too. For example: `[Settings > Account > Display Name](https://client.example/settings/account?focus=display-name&moe.sable.client.action=settings)`.
|
||||
|
||||
Invalid or malformed settings-looking links now stay normal links instead of being shown as settings chips.
|
||||
|
||||
If you previously set `settingsLinkBaseUrl` in `config.json`, remove it. Sable now derives settings links from the runtime app URL, and the old config key is no longer used.
|
||||
@@ -0,0 +1,5 @@
|
||||
---
|
||||
default: patch
|
||||
---
|
||||
|
||||
Fix the first pin event in a room looking empty
|
||||
@@ -0,0 +1,5 @@
|
||||
---
|
||||
default: info
|
||||
---
|
||||
|
||||
Update verbiage in the credits
|
||||
@@ -0,0 +1,5 @@
|
||||
---
|
||||
default: patch
|
||||
---
|
||||
|
||||
spoilered text now gets replaced with `[Spoiler]` in the plain text fallback, as per MSC4454
|
||||
@@ -0,0 +1,5 @@
|
||||
---
|
||||
default: patch
|
||||
---
|
||||
|
||||
# Hide copied settings links on dynamic rows
|
||||
@@ -0,0 +1,5 @@
|
||||
---
|
||||
default: patch
|
||||
---
|
||||
|
||||
Fix button hover background smearing in virtual list rows by suppressing transform on hover
|
||||
@@ -0,0 +1,5 @@
|
||||
---
|
||||
default: patch
|
||||
---
|
||||
|
||||
Fix Workbox precaching by removing injectionPoint override that was silently disabling all precache entries
|
||||
@@ -23,3 +23,6 @@ build.sh
|
||||
|
||||
# the following line was added with the "git ignore" tool by itsrye.dev, version 0.1.0
|
||||
.lh
|
||||
|
||||
# the following line was added with nvim by Shea because its annoying to clear every so often
|
||||
.vscode/bookmarks.json
|
||||
@@ -1,8 +0,0 @@
|
||||
dist
|
||||
node_modules
|
||||
package.json
|
||||
pnpm-lock.yaml
|
||||
LICENSE
|
||||
README.md
|
||||
CHANGELOG.md
|
||||
./changeset
|
||||
@@ -1,5 +0,0 @@
|
||||
{
|
||||
"printWidth": 100,
|
||||
"singleQuote": true,
|
||||
"trailingComma": "es5"
|
||||
}
|
||||
Vendored
+1
-1
@@ -1,3 +1,3 @@
|
||||
{
|
||||
"recommendations": ["dbaeumer.vscode-eslint", "esbenp.prettier-vscode", "webpro.vscode-knip"]
|
||||
"recommendations": ["webpro.vscode-knip", "oxc.oxc-vscode"]
|
||||
}
|
||||
Vendored
+8
-3
@@ -1,11 +1,16 @@
|
||||
{
|
||||
"editor.codeActionsOnSave": {
|
||||
"source.fixAll.oxc": "always"
|
||||
},
|
||||
"editor.formatOnSave": true,
|
||||
"editor.defaultFormatter": "esbenp.prettier-vscode",
|
||||
"editor.defaultFormatter": "oxc.oxc-vscode",
|
||||
"oxc.fmt.configPath": "oxfmt.config.ts",
|
||||
"oxc.typeAware": true,
|
||||
"typescript.tsdk": "node_modules/typescript/lib",
|
||||
"[jsonc]": {
|
||||
"editor.defaultFormatter": "esbenp.prettier-vscode"
|
||||
"editor.defaultFormatter": "oxc.oxc-vscode"
|
||||
},
|
||||
"[json]": {
|
||||
"editor.defaultFormatter": "esbenp.prettier-vscode"
|
||||
"editor.defaultFormatter": "oxc.oxc-vscode"
|
||||
}
|
||||
}
|
||||
@@ -16,6 +16,13 @@
|
||||
|
||||
try_files {path} /index.html
|
||||
|
||||
# Content-hashed assets can be cached indefinitely — the filename changes on every build.
|
||||
header /assets/* Cache-Control "public, max-age=31536000, immutable"
|
||||
# Workbox SW must be revalidated on every load so the browser picks up updates.
|
||||
header /sw.js Cache-Control "no-cache"
|
||||
# index.html must not be cached so the browser always gets the latest app shell.
|
||||
header /index.html Cache-Control "no-cache"
|
||||
|
||||
# Required for Sentry browser profiling (JS Self-Profiling API)
|
||||
header Document-Policy "js-profiling"
|
||||
}
|
||||
@@ -13,8 +13,6 @@
|
||||
"webPushAppID": "moe.sable.app.sygnal"
|
||||
},
|
||||
|
||||
"settingsLinkBaseUrl": "https://app.sable.moe",
|
||||
|
||||
"slidingSync": {
|
||||
"enabled": true
|
||||
},
|
||||
|
||||
@@ -1,143 +0,0 @@
|
||||
import path from 'node:path';
|
||||
|
||||
import { includeIgnoreFile } from '@eslint/compat';
|
||||
import js from '@eslint/js';
|
||||
import { defineConfig } from 'eslint/config';
|
||||
import { configs, helpers, plugins } from 'eslint-config-airbnb-extended';
|
||||
import { rules as prettierConfigRules } from 'eslint-config-prettier';
|
||||
import prettierPlugin from 'eslint-plugin-prettier';
|
||||
import reactPlugin from 'eslint-plugin-react';
|
||||
import globals from 'globals';
|
||||
|
||||
const gitignorePath = path.resolve('.', '.gitignore');
|
||||
const { jsFiles, tsFiles } = helpers.extensions;
|
||||
|
||||
const jsConfig = defineConfig([
|
||||
// ESLint recommended config
|
||||
{
|
||||
name: 'js/config',
|
||||
...js.configs.recommended,
|
||||
},
|
||||
// Stylistic plugin
|
||||
plugins.stylistic,
|
||||
// Import X plugin
|
||||
plugins.importX,
|
||||
// Airbnb base recommended config
|
||||
...configs.base.recommended,
|
||||
]);
|
||||
|
||||
const reactConfig = defineConfig([
|
||||
// React plugin
|
||||
plugins.react,
|
||||
// React hooks plugin
|
||||
plugins.reactHooks,
|
||||
// React JSX A11y plugin
|
||||
plugins.reactA11y,
|
||||
// Airbnb React recommended config
|
||||
...configs.react.recommended,
|
||||
// React 17+ automatic JSX runtime
|
||||
reactPlugin.configs.flat['jsx-runtime'],
|
||||
]);
|
||||
|
||||
const typescriptConfig = defineConfig([
|
||||
// TypeScript ESLint plugin
|
||||
plugins.typescriptEslint,
|
||||
// Airbnb base TypeScript config
|
||||
...configs.base.typescript,
|
||||
// Airbnb React TypeScript config
|
||||
...configs.react.typescript,
|
||||
]);
|
||||
|
||||
const prettierConfig = defineConfig([
|
||||
// Prettier plugin
|
||||
{
|
||||
name: 'prettier/plugin/config',
|
||||
plugins: {
|
||||
prettier: prettierPlugin,
|
||||
},
|
||||
},
|
||||
// Prettier config
|
||||
{
|
||||
name: 'prettier/config',
|
||||
rules: {
|
||||
...prettierConfigRules,
|
||||
'prettier/prettier': 'error',
|
||||
},
|
||||
},
|
||||
]);
|
||||
|
||||
const projectOverrides = defineConfig([
|
||||
{
|
||||
name: 'project/rule-overrides',
|
||||
files: [...jsFiles, ...tsFiles],
|
||||
languageOptions: {
|
||||
globals: {
|
||||
JSX: 'readonly',
|
||||
...globals.browser,
|
||||
},
|
||||
},
|
||||
rules: {
|
||||
'linebreak-style': 'off',
|
||||
'no-underscore-dangle': 'off',
|
||||
'no-shadow': 'off',
|
||||
'import-x/prefer-default-export': 'off',
|
||||
'import-x/extensions': 'off',
|
||||
'import-x/no-unresolved': 'off',
|
||||
'import-x/no-extraneous-dependencies': [
|
||||
'error',
|
||||
{
|
||||
devDependencies: true,
|
||||
optionalDependencies: false,
|
||||
peerDependencies: true,
|
||||
bundledDependencies: true,
|
||||
},
|
||||
],
|
||||
'react/no-unstable-nested-components': ['error', { allowAsProps: true }],
|
||||
'react/jsx-filename-extension': [
|
||||
'error',
|
||||
{
|
||||
extensions: ['.tsx', '.jsx'],
|
||||
},
|
||||
],
|
||||
// obsolete in a React 19
|
||||
'react/prop-types': 'off',
|
||||
'react/require-default-props': 'off',
|
||||
'react/jsx-props-no-spreading': 'off',
|
||||
'react-hooks/rules-of-hooks': 'error',
|
||||
'react-hooks/exhaustive-deps': 'error',
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'project/typescript-rule-overrides',
|
||||
files: tsFiles,
|
||||
rules: {
|
||||
// disabled for now to get eslint to pass
|
||||
'@typescript-eslint/consistent-type-definitions': 'off',
|
||||
'@typescript-eslint/no-unsafe-enum-comparison': 'off',
|
||||
'@typescript-eslint/only-throw-error': 'off',
|
||||
'@typescript-eslint/array-type': 'off',
|
||||
'@typescript-eslint/no-unused-vars': [
|
||||
'error',
|
||||
{
|
||||
args: 'after-used',
|
||||
enableAutofixRemoval: {
|
||||
imports: true,
|
||||
},
|
||||
ignoreRestSiblings: true,
|
||||
vars: 'all',
|
||||
},
|
||||
],
|
||||
'@typescript-eslint/no-shadow': 'error',
|
||||
'no-undef': 'off',
|
||||
},
|
||||
},
|
||||
]);
|
||||
|
||||
export default defineConfig([
|
||||
includeIgnoreFile(gitignorePath),
|
||||
...jsConfig,
|
||||
...reactConfig,
|
||||
...typescriptConfig,
|
||||
...prettierConfig,
|
||||
...projectOverrides,
|
||||
]);
|
||||
@@ -1,6 +1,7 @@
|
||||
{
|
||||
"$schema": "https://unpkg.com/knip@5/schema.json",
|
||||
"entry": ["src/sw.ts", "scripts/normalize-imports.js"],
|
||||
"ignore": ["oxlint.config.ts", "oxfmt.config.ts"],
|
||||
"ignoreExportsUsedInFile": {
|
||||
"interface": true,
|
||||
"type": true
|
||||
@@ -8,8 +9,7 @@
|
||||
"ignoreDependencies": [
|
||||
"buffer",
|
||||
"@sableclient/sable-call-embedded",
|
||||
"@matrix-org/matrix-sdk-crypto-wasm",
|
||||
"@testing-library/user-event"
|
||||
"@matrix-org/matrix-sdk-crypto-wasm"
|
||||
],
|
||||
"ignoreBinaries": ["knope"],
|
||||
"rules": {
|
||||
|
||||
+8
-4
@@ -2,8 +2,12 @@
|
||||
versioned_files = ["package.json"]
|
||||
changelog = "CHANGELOG.md"
|
||||
extra_changelog_sections = [
|
||||
{ name = "Documentation", types = ["docs"] },
|
||||
{ name = "Notes", types = ["note"] },
|
||||
{ name = "Documentation", types = [
|
||||
"docs",
|
||||
] },
|
||||
{ name = "Notes", types = [
|
||||
"note",
|
||||
] },
|
||||
]
|
||||
# assets = "marker" // TODO: add this later once we have assets
|
||||
|
||||
@@ -64,6 +68,6 @@ repo = "Sable"
|
||||
[release_notes]
|
||||
# The <!-- commit:$commit_hash --> marker is used by prepare-release.yml
|
||||
change_templates = [
|
||||
"### $summary <!-- commit:$commit_hash -->\n\n$details",
|
||||
"* $summary <!-- commit:$commit_hash -->",
|
||||
"### $summary <!-- commit:$commit_hash -->\n\n$details",
|
||||
"* $summary <!-- commit:$commit_hash -->",
|
||||
]
|
||||
@@ -0,0 +1,18 @@
|
||||
import { defineConfig } from 'oxfmt';
|
||||
|
||||
export default defineConfig({
|
||||
printWidth: 100,
|
||||
tabWidth: 2,
|
||||
singleQuote: true,
|
||||
trailingComma: 'es5',
|
||||
ignorePatterns: [
|
||||
'dist',
|
||||
'node_modules',
|
||||
'package.json',
|
||||
'pnpm-lock.yaml',
|
||||
'LICENSE',
|
||||
'README.md',
|
||||
'CHANGELOG.md',
|
||||
'./changeset',
|
||||
],
|
||||
});
|
||||
@@ -0,0 +1,62 @@
|
||||
import { defineConfig } from 'oxlint';
|
||||
|
||||
export default defineConfig({
|
||||
options: {
|
||||
typeAware: true,
|
||||
},
|
||||
plugins: ['react', 'jsx-a11y', 'typescript', 'import', 'unicorn', 'oxc', 'vitest', 'promise'],
|
||||
categories: {
|
||||
correctness: 'error',
|
||||
suspicious: 'warn',
|
||||
perf: 'warn',
|
||||
style: 'off',
|
||||
},
|
||||
env: {
|
||||
browser: true,
|
||||
builtin: true,
|
||||
},
|
||||
rules: {
|
||||
'import/no-unassigned-import': 'off',
|
||||
'import/no-named-as-default': 'off',
|
||||
'import/no-named-as-default-member': 'off',
|
||||
'no-console': ['error', { allow: ['warn', 'error'] }],
|
||||
'react/react-in-jsx-scope': 'off',
|
||||
'react/jsx-filename-extension': ['error', { extensions: ['.tsx', '.jsx'] }],
|
||||
'react/rules-of-hooks': 'error',
|
||||
'react/exhaustive-deps': 'error',
|
||||
'react/iframe-missing-sandbox': 'off',
|
||||
'jsx-a11y/no-autofocus': 'off',
|
||||
'jsx-a11y/prefer-tag-over-role': 'off',
|
||||
'typescript/no-explicit-any': 'error',
|
||||
'typescript/consistent-type-imports': 'error',
|
||||
'typescript/only-throw-error': 'error',
|
||||
'typescript/no-unsafe-type-assertion': 'off',
|
||||
'typescript/no-floating-promises': 'off',
|
||||
'typescript/no-unnecessary-type-arguments': 'off',
|
||||
'oxc/no-map-spread': 'off',
|
||||
'promise/always-return': 'off',
|
||||
},
|
||||
overrides: [
|
||||
{
|
||||
files: ['**/*.ts', '**/*.tsx', '**/*.cts', '**/*.mts'],
|
||||
rules: {
|
||||
'typescript/no-unused-vars': [
|
||||
'error',
|
||||
{
|
||||
args: 'after-used',
|
||||
ignoreRestSiblings: true,
|
||||
vars: 'all',
|
||||
},
|
||||
],
|
||||
'typescript/no-shadow': 'error',
|
||||
},
|
||||
},
|
||||
{
|
||||
files: ['**/*.test.ts', '**/*.test.tsx'],
|
||||
rules: {
|
||||
'typescript/unbound-method': 'off',
|
||||
'typescript/no-unsafe-enum-comparison': 'off',
|
||||
},
|
||||
},
|
||||
],
|
||||
});
|
||||
+7
-13
@@ -12,10 +12,10 @@
|
||||
"dev": "vite dev",
|
||||
"build": "vite build",
|
||||
"preview": "vite preview",
|
||||
"lint": "eslint .",
|
||||
"lint:fix": "eslint . --fix",
|
||||
"fmt": "prettier --write .",
|
||||
"fmt:check": "prettier --check .",
|
||||
"lint": "oxlint .",
|
||||
"lint:fix": "oxlint . --fix && oxfmt .",
|
||||
"fmt": "oxfmt .",
|
||||
"fmt:check": "oxfmt --check .",
|
||||
"typecheck": "tsc",
|
||||
"test": "vitest",
|
||||
"test:ui": "vitest --ui",
|
||||
@@ -57,7 +57,6 @@
|
||||
"dompurify": "^3.3.3",
|
||||
"emojibase": "^15.3.1",
|
||||
"emojibase-data": "^15.3.2",
|
||||
"eslint-plugin-react": "7.37.5",
|
||||
"eventemitter3": "^5.0.4",
|
||||
"file-saver": "^2.0.5",
|
||||
"focus-trap-react": "^10.3.1",
|
||||
@@ -96,8 +95,6 @@
|
||||
"devDependencies": {
|
||||
"@cloudflare/vite-plugin": "^1.26.0",
|
||||
"@esbuild-plugins/node-globals-polyfill": "^0.2.3",
|
||||
"@eslint/compat": "2.0.2",
|
||||
"@eslint/js": "9.39.3",
|
||||
"@rollup/plugin-inject": "^5.0.5",
|
||||
"@rollup/plugin-wasm": "^6.2.2",
|
||||
"@sableclient/sable-call-embedded": "v1.1.4",
|
||||
@@ -118,14 +115,11 @@
|
||||
"@vitest/ui": "^4.1.0",
|
||||
"buffer": "^6.0.3",
|
||||
"cloudflared": "^0.7.1",
|
||||
"eslint": "9.39.3",
|
||||
"eslint-config-airbnb-extended": "3.0.1",
|
||||
"eslint-config-prettier": "10.1.8",
|
||||
"eslint-plugin-prettier": "5.5.5",
|
||||
"globals": "17.3.0",
|
||||
"jsdom": "^29.0.0",
|
||||
"knip": "5.85.0",
|
||||
"prettier": "3.8.1",
|
||||
"oxfmt": "^0.45.0",
|
||||
"oxlint": "^1.60.0",
|
||||
"oxlint-tsgolint": "^0.21.0",
|
||||
"typescript": "^5.9.3",
|
||||
"vite": "^7.3.1",
|
||||
"vite-plugin-compression2": "2.5.0",
|
||||
|
||||
Generated
+496
-1676
File diff suppressed because it is too large.
Load diff
@@ -1,5 +1,5 @@
|
||||
#!/usr/bin/env node
|
||||
/* eslint-disable no-console */
|
||||
/* oxlint-disable no-console */
|
||||
|
||||
import fs from 'node:fs/promises';
|
||||
import path from 'node:path';
|
||||
@@ -212,7 +212,7 @@ function rewriteFileImports(filePath, sourceCode, aliases, projectRoot) {
|
||||
|
||||
const uniqueReplacements = Array.from(
|
||||
new Map(replacements.map((r) => [`${r.start}:${r.end}`, r])).values()
|
||||
).sort((a, b) => b.start - a.start);
|
||||
).toSorted((a, b) => b.start - a.start);
|
||||
|
||||
const updatedCode = uniqueReplacements.reduce(
|
||||
(code, replacement) =>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* eslint-disable no-console */
|
||||
/* oxlint-disable no-console */
|
||||
import process from 'node:process';
|
||||
|
||||
export const ANSI = {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { FormEventHandler, useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
||||
import type { FormEventHandler } from 'react';
|
||||
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
||||
import {
|
||||
Box,
|
||||
Text,
|
||||
@@ -14,7 +15,7 @@ import {
|
||||
Scroll,
|
||||
config,
|
||||
} from 'folds';
|
||||
import { MatrixError } from '$types/matrix-sdk';
|
||||
import type { MatrixError } from '$types/matrix-sdk';
|
||||
import { Cursor } from '$plugins/text-area';
|
||||
import { syntaxErrorPosition } from '$utils/dom';
|
||||
import { AsyncStatus, useAsyncCallback } from '$hooks/useAsyncCallback';
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { ReactNode } from 'react';
|
||||
import { AuthDict, AuthType, IAuthData, UIAFlow } from '$types/matrix-sdk';
|
||||
import type { ReactNode } from 'react';
|
||||
import type { AuthDict, IAuthData, UIAFlow } from '$types/matrix-sdk';
|
||||
import { AuthType } from '$types/matrix-sdk';
|
||||
import { getUIAFlowForStages } from '$utils/matrix-uia';
|
||||
import { useSupportedUIAFlows, useUIACompleted, useUIAFlow } from '$hooks/useUIAFlows';
|
||||
import { useMatrixClient } from '$hooks/useMatrixClient';
|
||||
@@ -34,7 +35,7 @@ export function ActionUIA({ authData, ongoingFlow, action, onCancel }: ActionUIA
|
||||
stepCount={ongoingFlow.stages.length}
|
||||
onCancel={onCancel}
|
||||
>
|
||||
{stageToComplete.type === AuthType.Password && (
|
||||
{stageToComplete.type === (AuthType.Password as string) && (
|
||||
<PasswordStage
|
||||
userId={mx.getUserId()!}
|
||||
stageData={stageToComplete}
|
||||
@@ -42,7 +43,7 @@ export function ActionUIA({ authData, ongoingFlow, action, onCancel }: ActionUIA
|
||||
submitAuthDict={action}
|
||||
/>
|
||||
)}
|
||||
{stageToComplete.type === AuthType.Sso && stageToComplete.session && (
|
||||
{stageToComplete.type === (AuthType.Sso as string) && stageToComplete.session && (
|
||||
<SSOStage
|
||||
ssoRedirectURL={mx.getFallbackAuthUrl(AuthType.Sso, stageToComplete.session)}
|
||||
stageData={stageToComplete}
|
||||
|
||||
@@ -1,14 +1,12 @@
|
||||
import { ReactNode, useCallback, useEffect, useMemo } from 'react';
|
||||
import { MatrixError, createClient } from '$types/matrix-sdk';
|
||||
import type { ReactNode } from 'react';
|
||||
import { useCallback, useEffect, useMemo } from 'react';
|
||||
import type { MatrixError } from '$types/matrix-sdk';
|
||||
import { createClient } from '$types/matrix-sdk';
|
||||
import { AsyncStatus, useAsyncCallback } from '$hooks/useAsyncCallback';
|
||||
import { useAutoDiscoveryInfo } from '$hooks/useAutoDiscoveryInfo';
|
||||
import { promiseFulfilledResult, promiseRejectedResult } from '$utils/common';
|
||||
import {
|
||||
AuthFlows,
|
||||
RegisterFlowStatus,
|
||||
RegisterFlowsResponse,
|
||||
parseRegisterErrResp,
|
||||
} from '$hooks/useAuthFlows';
|
||||
import type { AuthFlows, RegisterFlowsResponse } from '$hooks/useAuthFlows';
|
||||
import { RegisterFlowStatus, parseRegisterErrResp } from '$hooks/useAuthFlows';
|
||||
|
||||
type AuthFlowsLoaderProps = {
|
||||
fallback?: () => ReactNode;
|
||||
@@ -26,7 +24,9 @@ export function AuthFlowsLoader({ fallback, error, children }: AuthFlowsLoaderPr
|
||||
const result = await Promise.allSettled([mx.loginFlows(), mx.registerRequest({})]);
|
||||
const loginFlows = promiseFulfilledResult(result[0]);
|
||||
const registerResp = promiseRejectedResult(result[1]) as MatrixError | undefined;
|
||||
let registerFlows: RegisterFlowsResponse = { status: RegisterFlowStatus.InvalidRequest };
|
||||
let registerFlows: RegisterFlowsResponse = {
|
||||
status: RegisterFlowStatus.InvalidRequest,
|
||||
};
|
||||
|
||||
if (typeof registerResp === 'object' && registerResp.httpStatus) {
|
||||
registerFlows = parseRegisterErrResp(registerResp);
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { ReactNode, useCallback } from 'react';
|
||||
import type { ReactNode } from 'react';
|
||||
import { useCallback } from 'react';
|
||||
import { useSetAtom } from 'jotai';
|
||||
import { matchPath, useLocation, useNavigate } from 'react-router-dom';
|
||||
import {
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import { MouseEventHandler, useCallback, useState } from 'react';
|
||||
import type { MouseEventHandler } from 'react';
|
||||
import { useCallback, useState } from 'react';
|
||||
import { useAtom } from 'jotai';
|
||||
import { CryptoApi, KeyBackupInfo } from '$types/matrix-sdk';
|
||||
import type { CryptoApi, KeyBackupInfo } from '$types/matrix-sdk';
|
||||
import type { RectCords } from 'folds';
|
||||
import {
|
||||
Badge,
|
||||
Box,
|
||||
@@ -14,7 +16,6 @@ import {
|
||||
percent,
|
||||
PopOut,
|
||||
ProgressBar,
|
||||
RectCords,
|
||||
Spinner,
|
||||
Text,
|
||||
} from 'folds';
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { ReactNode, useCallback, useRef } from 'react';
|
||||
import type { ReactNode } from 'react';
|
||||
import { useCallback, useRef } from 'react';
|
||||
import { useAtomValue, useSetAtom } from 'jotai';
|
||||
import { useAutoJoinCall } from '$hooks/useAutoJoinCall';
|
||||
import {
|
||||
@@ -9,7 +10,8 @@ import {
|
||||
useCallThemeSync,
|
||||
useCallMemberSoundSync,
|
||||
} from '$hooks/useCallEmbed';
|
||||
import { CallEmbed, useClientWidgetApiEvent, ElementWidgetActions } from '$plugins/call';
|
||||
import type { CallEmbed } from '$plugins/call';
|
||||
import { useClientWidgetApiEvent, ElementWidgetActions } from '$plugins/call';
|
||||
import { callChatAtom, callEmbedAtom } from '$state/callEmbed';
|
||||
import { useSelectedRoom } from '$hooks/router/useSelectedRoom';
|
||||
import { ScreenSize, useScreenSizeContext } from '$hooks/useScreenSize';
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { ReactNode, useCallback, useEffect, useState } from 'react';
|
||||
import type { ReactNode } from 'react';
|
||||
import { useCallback, useEffect, useState } from 'react';
|
||||
import { AsyncStatus, useAsyncCallback } from '$hooks/useAsyncCallback';
|
||||
import { ClientConfig } from '$hooks/useClientConfig';
|
||||
import type { ClientConfig } from '$hooks/useClientConfig';
|
||||
import { trimTrailingSlash } from '$utils/common';
|
||||
|
||||
const getClientConfig = async (): Promise<ClientConfig> => {
|
||||
|
||||
@@ -18,7 +18,7 @@ export function ClientSideHoverFreeze({
|
||||
img.crossOrigin = 'anonymous';
|
||||
img.src = src;
|
||||
|
||||
img.onload = () => {
|
||||
const handleLoad = () => {
|
||||
if (isMounted && canvasRef.current) {
|
||||
canvasRef.current.width = img.naturalWidth || img.width;
|
||||
canvasRef.current.height = img.naturalHeight || img.height;
|
||||
@@ -27,8 +27,10 @@ export function ClientSideHoverFreeze({
|
||||
setIsCanvasReady(true);
|
||||
}
|
||||
};
|
||||
img.addEventListener('load', handleLoad);
|
||||
return () => {
|
||||
isMounted = false;
|
||||
img.removeEventListener('load', handleLoad);
|
||||
};
|
||||
}, [src]);
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { ReactNode, RefObject, useCallback, useRef, useState } from 'react';
|
||||
import type { ReactNode, RefObject } from 'react';
|
||||
import { useCallback, useRef, useState } from 'react';
|
||||
import { useDebounce } from '$hooks/useDebounce';
|
||||
|
||||
type ConfirmPasswordMatchProps = {
|
||||
|
||||
@@ -1,11 +1,7 @@
|
||||
import {
|
||||
ShowSasCallbacks,
|
||||
VerificationPhase,
|
||||
VerificationRequest,
|
||||
Verifier,
|
||||
VerificationMethod,
|
||||
} from '$types/matrix-sdk';
|
||||
import { CSSProperties, useCallback, useEffect, useState } from 'react';
|
||||
import type { ShowSasCallbacks, VerificationRequest, Verifier } from '$types/matrix-sdk';
|
||||
import { VerificationPhase, VerificationMethod } from '$types/matrix-sdk';
|
||||
import type { CSSProperties } from 'react';
|
||||
import { useCallback, useEffect, useMemo, useState } from 'react';
|
||||
import {
|
||||
Box,
|
||||
Button,
|
||||
@@ -119,6 +115,15 @@ function AutoVerificationStart({ onStart }: VerificationStartProps) {
|
||||
|
||||
function CompareEmoji({ sasData }: { sasData: ShowSasCallbacks }) {
|
||||
const [confirmState, confirm] = useAsyncCallback(useCallback(() => sasData.confirm(), [sasData]));
|
||||
const emojiEntries = useMemo<{ id: string; emoji: string; name: string }[]>(
|
||||
() =>
|
||||
(sasData.sas.emoji ?? []).map(([emoji, name], index) => ({
|
||||
id: `emoji-${index}`,
|
||||
emoji,
|
||||
name,
|
||||
})),
|
||||
[sasData]
|
||||
);
|
||||
|
||||
const confirming =
|
||||
confirmState.status === AsyncStatus.Loading || confirmState.status === AsyncStatus.Success;
|
||||
@@ -136,15 +141,8 @@ function CompareEmoji({ sasData }: { sasData: ShowSasCallbacks }) {
|
||||
wrap="Wrap"
|
||||
justifyContent="Center"
|
||||
>
|
||||
{sasData.sas.emoji?.map(([emoji, name], index) => (
|
||||
<Box
|
||||
// eslint-disable-next-line react/no-array-index-key
|
||||
key={`${emoji}${name}${index}`}
|
||||
direction="Column"
|
||||
gap="100"
|
||||
justifyContent="Center"
|
||||
alignItems="Center"
|
||||
>
|
||||
{emojiEntries.map(({ id, emoji, name }) => (
|
||||
<Box key={id} direction="Column" gap="100" justifyContent="Center" alignItems="Center">
|
||||
<Text size="H1">{emoji}</Text>
|
||||
<Text size="T200">{name}</Text>
|
||||
</Box>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { FormEventHandler, forwardRef, useCallback, useState } from 'react';
|
||||
import type { FormEventHandler } from 'react';
|
||||
import { forwardRef, useCallback, useState } from 'react';
|
||||
import {
|
||||
Dialog,
|
||||
Header,
|
||||
@@ -15,7 +16,8 @@ import {
|
||||
} from 'folds';
|
||||
import FileSaver from 'file-saver';
|
||||
import to from 'await-to-js';
|
||||
import { AuthDict, IAuthData, MatrixError, UIAuthCallback } from '$types/matrix-sdk';
|
||||
import type { AuthDict, IAuthData, UIAuthCallback } from '$types/matrix-sdk';
|
||||
import { MatrixError } from '$types/matrix-sdk';
|
||||
import { clearSecretStorageKeys } from '$client/secretStorageKeys';
|
||||
import { ContainerColor } from '$styles/ContainerColor.css';
|
||||
import { copyToClipboard } from '$utils/dom';
|
||||
@@ -42,7 +44,7 @@ function makeUIAAction<T>(
|
||||
authData: IAuthData,
|
||||
performAction: PerformAction<T>,
|
||||
resolve: (data: T) => void,
|
||||
reject: (error?: any) => void
|
||||
reject: (error?: unknown) => void
|
||||
): UIAAction<T> {
|
||||
const action: UIAAction<T> = {
|
||||
authData,
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
import { ReactNode } from 'react';
|
||||
import { CryptoApi } from '$types/matrix-sdk';
|
||||
import {
|
||||
useDeviceVerificationStatus,
|
||||
VerificationStatus,
|
||||
} from '$hooks/useDeviceVerificationStatus';
|
||||
import type { ReactNode } from 'react';
|
||||
import type { CryptoApi } from '$types/matrix-sdk';
|
||||
import type { VerificationStatus } from '$hooks/useDeviceVerificationStatus';
|
||||
import { useDeviceVerificationStatus } from '$hooks/useDeviceVerificationStatus';
|
||||
|
||||
type DeviceVerificationStatusProps = {
|
||||
crypto?: CryptoApi;
|
||||
|
||||
@@ -21,7 +21,7 @@ import { HOME_ROOM_PATH, DIRECT_ROOM_PATH, SPACE_ROOM_PATH } from '$pages/paths'
|
||||
import { getCanonicalAliasOrRoomId } from '$utils/matrix';
|
||||
import { announce } from '$utils/announce';
|
||||
import { roomIdToReplyDraftAtomFamily } from '$state/room/roomInputDrafts';
|
||||
import { Room } from 'matrix-js-sdk';
|
||||
import type { Room } from '$types/matrix-sdk';
|
||||
|
||||
export function GlobalKeyboardShortcuts() {
|
||||
const navigate = useNavigate();
|
||||
@@ -63,6 +63,10 @@ export function GlobalKeyboardShortcuts() {
|
||||
const parents = roomToParents.get(roomId);
|
||||
if (parents && parents.size > 0) {
|
||||
const spaceId = Array.from(parents)[0];
|
||||
if (!spaceId) {
|
||||
navigate(getHomeRoomPath(roomIdOrAliasToNav));
|
||||
return;
|
||||
}
|
||||
const spaceIdOrAlias = getCanonicalAliasOrRoomId(mx, spaceId);
|
||||
navigate(getSpaceRoomPath(spaceIdOrAlias, roomIdOrAliasToNav));
|
||||
} else {
|
||||
@@ -82,11 +86,11 @@ export function GlobalKeyboardShortcuts() {
|
||||
if (!isKeyHotkey('alt+n', evt)) return;
|
||||
const unreadEntries = Array.from(roomToUnread.entries())
|
||||
.filter(([id, u]) => u.total > 0 && id !== currentRoom?.roomId)
|
||||
.sort((a, b) => b[1].highlight - a[1].highlight || b[1].total - a[1].total);
|
||||
.toSorted((a, b) => b[1].highlight - a[1].highlight || b[1].total - a[1].total);
|
||||
if (unreadEntries.length === 0) return;
|
||||
evt.preventDefault();
|
||||
unreadIndexRef.current = 0;
|
||||
const [roomId] = unreadEntries[0];
|
||||
const [roomId] = unreadEntries[0]!;
|
||||
navigateToRoom(roomId, unreadEntries.length - 1);
|
||||
},
|
||||
[roomToUnread, currentRoom?.roomId, navigateToRoom]
|
||||
@@ -100,7 +104,7 @@ export function GlobalKeyboardShortcuts() {
|
||||
if (!isDown && !isUp) return;
|
||||
const unreadEntries = Array.from(roomToUnread.entries())
|
||||
.filter(([, u]) => u.total > 0)
|
||||
.sort((a, b) => b[1].highlight - a[1].highlight || b[1].total - a[1].total);
|
||||
.toSorted((a, b) => b[1].highlight - a[1].highlight || b[1].total - a[1].total);
|
||||
if (unreadEntries.length === 0) return;
|
||||
evt.preventDefault();
|
||||
if (isDown) {
|
||||
@@ -109,7 +113,9 @@ export function GlobalKeyboardShortcuts() {
|
||||
unreadIndexRef.current =
|
||||
(unreadIndexRef.current - 1 + unreadEntries.length) % unreadEntries.length;
|
||||
}
|
||||
const [roomId] = unreadEntries[unreadIndexRef.current];
|
||||
const currentEntry = unreadEntries[unreadIndexRef.current];
|
||||
if (!currentEntry) return;
|
||||
const [roomId] = currentEntry;
|
||||
navigateToRoom(roomId, unreadEntries.length - 1);
|
||||
},
|
||||
[roomToUnread, navigateToRoom]
|
||||
@@ -137,6 +143,7 @@ export function GlobalKeyboardShortcuts() {
|
||||
const currentReplyIndex = events.findIndex((e) => e.event.event_id === replyDraft.eventId);
|
||||
if (currentReplyIndex === events.length - 1 && isDown) return; // you cant go further down than that idiot
|
||||
const newTargetEvent = isUp ? events[currentReplyIndex - 1] : events[currentReplyIndex + 1];
|
||||
if (!newTargetEvent) return;
|
||||
const eventId = newTargetEvent.event.event_id;
|
||||
if (eventId === undefined) return;
|
||||
setReplyDraft({ userId: currentRoom.myUserId, eventId, body: '' });
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import FocusTrap from 'focus-trap-react';
|
||||
import { Box, Button, config, Menu, PopOut, RectCords, Text } from 'folds';
|
||||
import { MouseEventHandler, ReactNode, useState } from 'react';
|
||||
import type { RectCords } from 'folds';
|
||||
import { Box, Button, config, Menu, PopOut, Text } from 'folds';
|
||||
import type { MouseEventHandler, ReactNode } from 'react';
|
||||
import { useState } from 'react';
|
||||
import { stopPropagation } from '$utils/keyboard';
|
||||
|
||||
type HexColorPickerPopOutProps = {
|
||||
|
||||
@@ -13,6 +13,7 @@ import {
|
||||
OverlayCenter,
|
||||
OverlayBackdrop,
|
||||
} from 'folds';
|
||||
import type { Room } from '$types/matrix-sdk';
|
||||
import { useMatrixClient } from '$hooks/useMatrixClient';
|
||||
import { useRoomName } from '$hooks/useRoomMeta';
|
||||
import { getRoomAvatarUrl } from '$utils/room';
|
||||
@@ -32,7 +33,7 @@ import { RoomAvatar } from './room-avatar';
|
||||
const debugLog = createDebugLogger('IncomingCall');
|
||||
|
||||
type IncomingCallInternalProps = {
|
||||
room: any;
|
||||
room: Room;
|
||||
onClose: () => void;
|
||||
};
|
||||
|
||||
|
||||
@@ -1,18 +1,7 @@
|
||||
import { MouseEventHandler, useCallback, useMemo, useState } from 'react';
|
||||
import {
|
||||
config,
|
||||
Box,
|
||||
MenuItem,
|
||||
Text,
|
||||
Icon,
|
||||
Icons,
|
||||
IconSrc,
|
||||
RectCords,
|
||||
PopOut,
|
||||
Menu,
|
||||
Button,
|
||||
Spinner,
|
||||
} from 'folds';
|
||||
import type { MouseEventHandler } from 'react';
|
||||
import { useCallback, useMemo, useState } from 'react';
|
||||
import type { IconSrc, RectCords } from 'folds';
|
||||
import { config, Box, MenuItem, Text, Icon, Icons, PopOut, Menu, Button, Spinner } from 'folds';
|
||||
import { JoinRule } from '$types/matrix-sdk';
|
||||
import FocusTrap from 'focus-trap-react';
|
||||
import { stopPropagation } from '$utils/keyboard';
|
||||
|
||||
@@ -1,19 +1,9 @@
|
||||
import { MouseEventHandler, ReactNode, useCallback, useState } from 'react';
|
||||
import {
|
||||
Box,
|
||||
Text,
|
||||
Chip,
|
||||
Icon,
|
||||
Icons,
|
||||
RectCords,
|
||||
PopOut,
|
||||
Menu,
|
||||
config,
|
||||
MenuItem,
|
||||
color,
|
||||
} from 'folds';
|
||||
import type { MouseEventHandler, ReactNode } from 'react';
|
||||
import { useCallback, useState } from 'react';
|
||||
import type { RectCords } from 'folds';
|
||||
import { Box, Text, Chip, Icon, Icons, PopOut, Menu, config, MenuItem, color } from 'folds';
|
||||
import FocusTrap from 'focus-trap-react';
|
||||
import { SecretStorageKeyContent } from '$types/matrix/accountData';
|
||||
import type { SecretStorageKeyContent } from '$types/matrix/accountData';
|
||||
import { storePrivateKey } from '$client/secretStorageKeys';
|
||||
import { stopPropagation } from '$utils/keyboard';
|
||||
import { useMatrixClient } from '$hooks/useMatrixClient';
|
||||
|
||||
@@ -6,7 +6,7 @@ describe('Modal500', () => {
|
||||
it('does not throw when rendered without tabbable children', () => {
|
||||
expect(() =>
|
||||
render(
|
||||
<Modal500 requestClose={vi.fn()}>
|
||||
<Modal500 requestClose={vi.fn<() => void>()}>
|
||||
<div>Empty modal content</div>
|
||||
</Modal500>
|
||||
)
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { ReactNode, useRef } from 'react';
|
||||
import type { ReactNode } from 'react';
|
||||
import { useRef } from 'react';
|
||||
import FocusTrap from 'focus-trap-react';
|
||||
import { Modal, Overlay, OverlayBackdrop, OverlayCenter } from 'folds';
|
||||
import { stopPropagation } from '$utils/keyboard';
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/* eslint-disable no-param-reassign */
|
||||
|
||||
import { FormEventHandler, MouseEventHandler, useEffect, useRef, useState } from 'react';
|
||||
import type { FormEventHandler, MouseEventHandler } from 'react';
|
||||
import { useEffect, useRef, useState } from 'react';
|
||||
import classNames from 'classnames';
|
||||
import type { RectCords } from 'folds';
|
||||
import {
|
||||
Box,
|
||||
Button,
|
||||
@@ -13,7 +13,6 @@ import {
|
||||
Input,
|
||||
Menu,
|
||||
PopOut,
|
||||
RectCords,
|
||||
Scroll,
|
||||
Spinner,
|
||||
Text,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
||||
import { MsgType } from '$types/matrix-sdk';
|
||||
import { ClientConfigProvider } from '$hooks/useClientConfig';
|
||||
import { RenderMessageContent } from './RenderMessageContent';
|
||||
@@ -13,9 +13,9 @@ vi.mock('./url-preview', () => ({
|
||||
youtubeUrl: () => false,
|
||||
}));
|
||||
|
||||
function renderMessage(body: string, settingsLinkBaseUrl = 'https://app.sable.moe') {
|
||||
function renderMessage(body: string) {
|
||||
return render(
|
||||
<ClientConfigProvider value={{ settingsLinkBaseUrl }}>
|
||||
<ClientConfigProvider value={{}}>
|
||||
<RenderMessageContent
|
||||
displayName="Alice"
|
||||
msgType={MsgType.Text}
|
||||
@@ -30,19 +30,66 @@ function renderMessage(body: string, settingsLinkBaseUrl = 'https://app.sable.mo
|
||||
);
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
vi.stubGlobal('location', { origin: 'https://app.example' } as Location);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
vi.unstubAllGlobals();
|
||||
});
|
||||
|
||||
describe('RenderMessageContent', () => {
|
||||
it('does not render url previews for settings links', () => {
|
||||
renderMessage('https://app.sable.moe/settings/account?focus=status');
|
||||
renderMessage(
|
||||
'https://app.example/settings/account?focus=status&moe.sable.client.action=settings'
|
||||
);
|
||||
|
||||
expect(screen.queryByTestId('url-preview-holder')).not.toBeInTheDocument();
|
||||
expect(screen.queryByTestId('url-preview-card')).not.toBeInTheDocument();
|
||||
expect(screen.queryByTestId('client-preview')).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('still renders url previews for settings links with unknown focus ids', () => {
|
||||
renderMessage('https://app.example/settings/account?focus=display-name2');
|
||||
|
||||
expect(screen.getByTestId('url-preview-holder')).toBeInTheDocument();
|
||||
expect(screen.getByTestId('url-preview-card')).toHaveTextContent(
|
||||
'https://app.example/settings/account?focus=display-name2'
|
||||
);
|
||||
});
|
||||
|
||||
it('still renders url previews for non-settings links', () => {
|
||||
renderMessage('https://example.com');
|
||||
|
||||
expect(screen.getByTestId('url-preview-holder')).toBeInTheDocument();
|
||||
expect(screen.getByTestId('url-preview-card')).toHaveTextContent('https://example.com');
|
||||
});
|
||||
|
||||
it('render url previews for text starting with paranthesis', () => {
|
||||
renderMessage('foo (https://example.com bar');
|
||||
|
||||
expect(screen.getByTestId('url-preview-holder')).toBeInTheDocument();
|
||||
expect(screen.getByTestId('url-preview-card')).toHaveTextContent('https://example.com');
|
||||
});
|
||||
|
||||
it('include ending paranthesis into the url preview per url spec', () => {
|
||||
renderMessage('foo https://example.com) bar');
|
||||
|
||||
expect(screen.getByTestId('url-preview-holder')).toBeInTheDocument();
|
||||
expect(screen.getByTestId('url-preview-card')).toHaveTextContent('https://example.com)');
|
||||
});
|
||||
|
||||
it('exclude closing paranthesis from the url preview when it marks a []() hyperlink', () => {
|
||||
renderMessage('[foo](https://example.com) bar');
|
||||
|
||||
expect(screen.getByTestId('url-preview-holder')).toBeInTheDocument();
|
||||
expect(screen.getByTestId('url-preview-card')).toHaveTextContent('https://example.com');
|
||||
});
|
||||
|
||||
it('include inner closing paranthesis from the url preview even within []() hyperlink', () => {
|
||||
renderMessage('[foo](https://example.com)) bar');
|
||||
|
||||
expect(screen.getByTestId('url-preview-holder')).toBeInTheDocument();
|
||||
expect(screen.getByTestId('url-preview-card')).toHaveTextContent('https://example.com)');
|
||||
});
|
||||
});
|
||||
@@ -1,12 +1,13 @@
|
||||
import { memo, useMemo, useCallback } from 'react';
|
||||
import { IPreviewUrlResponse, MsgType } from '$types/matrix-sdk';
|
||||
import type { IPreviewUrlResponse } from '$types/matrix-sdk';
|
||||
import { MsgType } from '$types/matrix-sdk';
|
||||
import { parseSettingsLink } from '$features/settings/settingsLink';
|
||||
import { useSettingsLinkBaseUrl } from '$features/settings/useSettingsLinkBaseUrl';
|
||||
import { testMatrixTo } from '$plugins/matrix-to';
|
||||
import { useSetting } from '$state/hooks/settings';
|
||||
import { settingsAtom, CaptionPosition } from '$state/settings';
|
||||
import { HTMLReactParserOptions } from 'html-react-parser';
|
||||
import { Opts } from 'linkifyjs';
|
||||
import type { HTMLReactParserOptions } from 'html-react-parser';
|
||||
import type { Opts } from 'linkifyjs';
|
||||
import { Box, config } from 'folds';
|
||||
import {
|
||||
AudioContent,
|
||||
@@ -42,7 +43,7 @@ type RenderMessageContentProps = {
|
||||
msgType: string;
|
||||
ts: number;
|
||||
edited?: boolean;
|
||||
getContent: <T>() => T;
|
||||
getContent: () => unknown;
|
||||
mediaAutoLoad?: boolean;
|
||||
bundledPreview?: boolean;
|
||||
urlPreview?: boolean;
|
||||
@@ -80,10 +81,11 @@ function RenderMessageContentInternal({
|
||||
outlineAttachment,
|
||||
hideCaption,
|
||||
}: RenderMessageContentProps) {
|
||||
const content = useMemo(() => getContent<any>(), [getContent]);
|
||||
const content = useMemo(() => getContent() as Record<string, unknown>, [getContent]);
|
||||
|
||||
const [autoplayGifs] = useSetting(settingsAtom, 'autoplayGifs');
|
||||
const [captionPosition] = useSetting(settingsAtom, 'captionPosition');
|
||||
const [multiplePreviews] = useSetting(settingsAtom, 'multiplePreviews');
|
||||
const settingsLinkBaseUrl = useSettingsLinkBaseUrl();
|
||||
const captionPositionMap = {
|
||||
[CaptionPosition.Above]: 'column-reverse',
|
||||
@@ -94,9 +96,10 @@ function RenderMessageContentInternal({
|
||||
const attachmentDirection = captionPositionMap[captionPosition];
|
||||
|
||||
const renderBody = useCallback(
|
||||
(props: any) => (
|
||||
(props: Record<string, unknown>) => (
|
||||
<RenderBody
|
||||
{...props}
|
||||
body={props.body as string}
|
||||
highlightRegex={highlightRegex}
|
||||
htmlReactParserOptions={htmlReactParserOptions}
|
||||
linkifyOpts={linkifyOpts}
|
||||
@@ -116,17 +119,18 @@ function RenderMessageContentInternal({
|
||||
url,
|
||||
type: getMediaType(url),
|
||||
}));
|
||||
|
||||
const mediaLinks = analyzed.filter((item) => item.type !== null);
|
||||
const toRender = mediaLinks.length > 0 ? mediaLinks : [analyzed[0]];
|
||||
const previewCandidates = mediaLinks.length > 0 ? mediaLinks : analyzed;
|
||||
const toRender = multiplePreviews ? previewCandidates : [previewCandidates[0]!];
|
||||
return (
|
||||
<UrlPreviewHolder>
|
||||
{toRender.map(({ url, type }) => {
|
||||
{toRender.map((item) => {
|
||||
const { url, type } = item;
|
||||
if (type) {
|
||||
return <UrlPreviewCard urlPreview key={url} url={url} ts={ts} mediaType={type} />;
|
||||
}
|
||||
if (clientUrlPreview && youtubeUrl(url)) {
|
||||
return <ClientPreview url={url} />;
|
||||
return <ClientPreview key={url} url={url} />;
|
||||
}
|
||||
if (urlPreview) {
|
||||
return <UrlPreviewCard urlPreview key={url} url={url} ts={ts} mediaType={type} />;
|
||||
@@ -136,7 +140,7 @@ function RenderMessageContentInternal({
|
||||
</UrlPreviewHolder>
|
||||
);
|
||||
},
|
||||
[ts, clientUrlPreview, settingsLinkBaseUrl, urlPreview]
|
||||
[multiplePreviews, settingsLinkBaseUrl, clientUrlPreview, urlPreview, ts]
|
||||
);
|
||||
const renderBundledPreviews = useCallback(
|
||||
(bundles: IPreviewUrlResponse[]) => (
|
||||
@@ -157,9 +161,13 @@ function RenderMessageContentInternal({
|
||||
const messageBundlePreview = bundledPreview ? renderBundledPreviews : undefined;
|
||||
|
||||
const renderCaption = () => {
|
||||
const hasCaption = content.body && content.body.trim().length > 0;
|
||||
const hasCaption = content.body && (content.body as string).trim().length > 0;
|
||||
if (captionPosition === CaptionPosition.Hidden || hideCaption) return null;
|
||||
if (hasCaption && content.filename && content.filename !== content.body) {
|
||||
if (
|
||||
hasCaption &&
|
||||
(content as { filename?: string }).filename &&
|
||||
(content as { filename?: string }).filename !== content.body
|
||||
) {
|
||||
if (captionPosition !== CaptionPosition.Inline)
|
||||
return (
|
||||
<MText
|
||||
@@ -213,7 +221,7 @@ function RenderMessageContentInternal({
|
||||
const renderFile = () =>
|
||||
renderCaptionedAttachment(
|
||||
<MFile
|
||||
content={content}
|
||||
content={content as Record<string, never> & { msgtype: MsgType.File }}
|
||||
renderFileContent={({ body, mimeType, info, encInfo, url }) => (
|
||||
<FileContent
|
||||
body={body}
|
||||
@@ -244,7 +252,7 @@ function RenderMessageContentInternal({
|
||||
/>
|
||||
);
|
||||
|
||||
if (msgType === MsgType.Text) {
|
||||
if (msgType === (MsgType.Text as string)) {
|
||||
return (
|
||||
<MText
|
||||
edited={edited}
|
||||
@@ -256,13 +264,15 @@ function RenderMessageContentInternal({
|
||||
);
|
||||
}
|
||||
|
||||
if (msgType === MsgType.Emote) {
|
||||
if (content['fyi.cisnt.headpat']) {
|
||||
if (msgType === (MsgType.Emote as string)) {
|
||||
if ((content as { 'fyi.cisnt.headpat'?: boolean })['fyi.cisnt.headpat']) {
|
||||
return (
|
||||
<MCuteEvent
|
||||
content={content}
|
||||
content={(content as { body?: string }).body}
|
||||
type={CuteEventType.Headpat}
|
||||
mentionedUserIds={content?.['m.mentions']?.user_ids}
|
||||
mentionedUserIds={
|
||||
(content as { 'm.mentions'?: { user_ids?: string[] } })['m.mentions']?.user_ids
|
||||
}
|
||||
/>
|
||||
);
|
||||
}
|
||||
@@ -278,7 +288,7 @@ function RenderMessageContentInternal({
|
||||
);
|
||||
}
|
||||
|
||||
if (msgType === MsgType.Notice) {
|
||||
if (msgType === (MsgType.Notice as string)) {
|
||||
return (
|
||||
<MNotice
|
||||
edited={edited}
|
||||
@@ -290,17 +300,19 @@ function RenderMessageContentInternal({
|
||||
);
|
||||
}
|
||||
|
||||
if (msgType === MsgType.Image) {
|
||||
if (msgType === (MsgType.Image as string)) {
|
||||
const info = (content as { info?: { mimetype?: string } }).info;
|
||||
const isGif =
|
||||
content.info?.mimetype === 'image/gif' ||
|
||||
content.info?.mimetype === 'image/webp' ||
|
||||
content.body?.toLowerCase().endsWith('.gif') ||
|
||||
content.body?.toLowerCase().endsWith('.webp') ||
|
||||
(typeof content.url === 'string' && content.url.toLowerCase().includes('gif'));
|
||||
info?.mimetype === 'image/gif' ||
|
||||
info?.mimetype === 'image/webp' ||
|
||||
(content.body as string)?.toLowerCase().endsWith('.gif') ||
|
||||
(content.body as string)?.toLowerCase().endsWith('.webp') ||
|
||||
(typeof (content as { url?: string }).url === 'string' &&
|
||||
(content as { url?: string }).url?.toLowerCase().includes('gif'));
|
||||
|
||||
return renderCaptionedAttachment(
|
||||
<MImage
|
||||
content={content}
|
||||
content={content as Record<string, never> & { msgtype: MsgType.Image }}
|
||||
renderImageContent={(imageProps) => (
|
||||
<ImageContent
|
||||
{...imageProps}
|
||||
@@ -323,10 +335,10 @@ function RenderMessageContentInternal({
|
||||
);
|
||||
}
|
||||
|
||||
if (msgType === MsgType.Video) {
|
||||
if (msgType === (MsgType.Video as string)) {
|
||||
return renderCaptionedAttachment(
|
||||
<MVideo
|
||||
content={content}
|
||||
content={content as Record<string, never> & { msgtype: MsgType.Video }}
|
||||
renderAsFile={renderFile}
|
||||
renderVideoContent={({ body, info, ...videoProps }) => (
|
||||
<VideoContent
|
||||
@@ -353,10 +365,10 @@ function RenderMessageContentInternal({
|
||||
);
|
||||
}
|
||||
|
||||
if (msgType === MsgType.Audio) {
|
||||
if (msgType === (MsgType.Audio as string)) {
|
||||
return renderCaptionedAttachment(
|
||||
<MAudio
|
||||
content={content}
|
||||
content={content as Record<string, never> & { msgtype: MsgType.Audio }}
|
||||
renderAsFile={renderFile}
|
||||
renderAudioContent={(audioProps) => (
|
||||
<AudioContent {...audioProps} renderMediaControl={(p) => <MediaControl {...p} />} />
|
||||
@@ -366,29 +378,33 @@ function RenderMessageContentInternal({
|
||||
);
|
||||
}
|
||||
|
||||
if (msgType === MsgType.File) return renderFile();
|
||||
if (msgType === MsgType.Location) return <MLocation content={content} />;
|
||||
if (msgType === (MsgType.File as string)) return renderFile();
|
||||
if (msgType === (MsgType.Location as string)) return <MLocation content={content} />;
|
||||
if (msgType === 'm.bad.encrypted') return <MBadEncrypted />;
|
||||
|
||||
// cute events
|
||||
if (msgType === 'im.fluffychat.cute_event')
|
||||
return (
|
||||
<MCuteEvent
|
||||
content={content}
|
||||
type={content?.cute_type}
|
||||
mentionedUserIds={content?.['m.mentions']?.user_ids}
|
||||
content={(content as { body?: string }).body}
|
||||
type={(content as { cute_type: CuteEventType }).cute_type ?? CuteEventType.Hug}
|
||||
mentionedUserIds={
|
||||
(content as { 'm.mentions'?: { user_ids?: string[] } })['m.mentions']?.user_ids
|
||||
}
|
||||
/>
|
||||
);
|
||||
// as fallback to render older events where msgtype was set instead of m.emote with a custom property
|
||||
if (msgType === 'fyi.cisnt.headpat')
|
||||
return (
|
||||
<MCuteEvent
|
||||
content={content}
|
||||
content={(content as { body?: string }).body}
|
||||
type={CuteEventType.Headpat}
|
||||
mentionedUserIds={content?.['m.mentions']?.user_ids}
|
||||
mentionedUserIds={
|
||||
(content as { 'm.mentions'?: { user_ids?: string[] } })['m.mentions']?.user_ids
|
||||
}
|
||||
/>
|
||||
);
|
||||
return <UnsupportedContent body={content?.body} />;
|
||||
return <UnsupportedContent body={(content as { body?: string }).body ?? ''} />;
|
||||
}
|
||||
|
||||
export const RenderMessageContent = memo(RenderMessageContentInternal);
|
||||
@@ -1,17 +1,18 @@
|
||||
import { fireEvent, render, screen } from '@testing-library/react';
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest';
|
||||
import type * as RoomsNotificationPreferencesModule from '$hooks/useRoomsNotificationPreferences';
|
||||
|
||||
import { RoomNotificationMode } from '$hooks/useRoomsNotificationPreferences';
|
||||
|
||||
import { RoomNotificationModeSwitcher } from './RoomNotificationSwitcher';
|
||||
|
||||
const { mockSetMode, modeStateStatus } = vi.hoisted(() => ({
|
||||
mockSetMode: vi.fn(),
|
||||
mockSetMode: vi.fn<(mode: RoomNotificationMode, current: RoomNotificationMode) => void>(),
|
||||
modeStateStatus: { current: 'idle' as 'idle' | 'loading' },
|
||||
}));
|
||||
|
||||
vi.mock('$hooks/useRoomsNotificationPreferences', async () => {
|
||||
const actual = await vi.importActual<typeof import('$hooks/useRoomsNotificationPreferences')>(
|
||||
const actual = await vi.importActual<typeof RoomsNotificationPreferencesModule>(
|
||||
'$hooks/useRoomsNotificationPreferences'
|
||||
);
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { Box, Icon, Text } from 'folds';
|
||||
import { type MouseEventHandler, ReactNode } from 'react';
|
||||
import type { ReactNode } from 'react';
|
||||
import { type MouseEventHandler } from 'react';
|
||||
import { SettingMenuSelector, type SettingMenuOption } from '$components/setting-menu-selector';
|
||||
import {
|
||||
getRoomNotificationModeIcon,
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
import { ReactNode, useCallback, useState } from 'react';
|
||||
import { MatrixClient, Room, IHierarchyRoom } from '$types/matrix-sdk';
|
||||
import type { ReactNode } from 'react';
|
||||
import { useCallback, useState } from 'react';
|
||||
import type { MatrixClient, Room, IHierarchyRoom } from '$types/matrix-sdk';
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import { useMatrixClient } from '$hooks/useMatrixClient';
|
||||
import { LocalRoomSummary, useLocalRoomSummary } from '$hooks/useLocalRoomSummary';
|
||||
import { AsyncState, AsyncStatus } from '$hooks/useAsyncCallback';
|
||||
import type { LocalRoomSummary } from '$hooks/useLocalRoomSummary';
|
||||
import { useLocalRoomSummary } from '$hooks/useLocalRoomSummary';
|
||||
import type { AsyncState } from '$hooks/useAsyncCallback';
|
||||
import { AsyncStatus } from '$hooks/useAsyncCallback';
|
||||
|
||||
export type IRoomSummary = Awaited<ReturnType<MatrixClient['getRoomSummary']>>;
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { ReactElement } from 'react';
|
||||
import { Unread } from '$types/matrix/room';
|
||||
import type { ReactElement } from 'react';
|
||||
import type { Unread } from '$types/matrix/room';
|
||||
import { useRoomUnread, useRoomsUnread } from '$state/hooks/unread';
|
||||
import { roomToUnreadAtom } from '$state/room/roomToUnread';
|
||||
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
import { FormEventHandler, useCallback } from 'react';
|
||||
import type { FormEventHandler } from 'react';
|
||||
import { useCallback } from 'react';
|
||||
import { Box, Text, Button, Spinner, color } from 'folds';
|
||||
import { decodeRecoveryKey, deriveRecoveryKeyFromPassphrase } from '$types/matrix-sdk';
|
||||
import { SecretStorageKeyContent, SecretStoragePassphraseContent } from '$types/matrix/accountData';
|
||||
import type {
|
||||
SecretStorageKeyContent,
|
||||
SecretStoragePassphraseContent,
|
||||
} from '$types/matrix/accountData';
|
||||
import { AsyncStatus, useAsyncCallback } from '$hooks/useAsyncCallback';
|
||||
import { useMatrixClient } from '$hooks/useMatrixClient';
|
||||
import { useAlive } from '$hooks/useAlive';
|
||||
@@ -36,7 +40,7 @@ export function SecretStorageRecoveryPassphrase({
|
||||
bits
|
||||
);
|
||||
|
||||
const match = await mx.secretStorage.checkKey(decodedRecoveryKey, keyContent as any);
|
||||
const match = await mx.secretStorage.checkKey(decodedRecoveryKey, keyContent as never);
|
||||
|
||||
if (!match) {
|
||||
throw new Error('Invalid recovery passphrase.');
|
||||
@@ -128,7 +132,7 @@ export function SecretStorageRecoveryKey({
|
||||
async (recoveryKey) => {
|
||||
const decodedRecoveryKey = decodeRecoveryKey(recoveryKey);
|
||||
|
||||
const match = await mx.secretStorage.checkKey(decodedRecoveryKey, keyContent as any);
|
||||
const match = await mx.secretStorage.checkKey(decodedRecoveryKey, keyContent as never);
|
||||
|
||||
if (!match) {
|
||||
throw new Error('Invalid recovery key.');
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
import { ReactNode, useCallback, useMemo } from 'react';
|
||||
import { Capabilities, validateAuthMetadata, ValidatedAuthMetadata } from '$types/matrix-sdk';
|
||||
import type { ReactNode } from 'react';
|
||||
import { useCallback, useMemo } from 'react';
|
||||
import type { Capabilities, ValidatedAuthMetadata } from '$types/matrix-sdk';
|
||||
import { validateAuthMetadata } from '$types/matrix-sdk';
|
||||
import { AsyncStatus, useAsyncCallbackValue } from '$hooks/useAsyncCallback';
|
||||
import { useMatrixClient } from '$hooks/useMatrixClient';
|
||||
import { MediaConfig } from '$hooks/useMediaConfig';
|
||||
import type { MediaConfig } from '$hooks/useMediaConfig';
|
||||
import { promiseFulfilledResult } from '$utils/common';
|
||||
import { createLogger } from '$utils/debug';
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import { ReactNode, useCallback, useEffect, useState } from 'react';
|
||||
import type { ReactNode } from 'react';
|
||||
import { useCallback, useEffect, useState } from 'react';
|
||||
import { AsyncStatus, useAsyncCallback } from '$hooks/useAsyncCallback';
|
||||
import { SpecVersions, specVersions } from '../cs-api';
|
||||
import type { SpecVersions } from '../cs-api';
|
||||
import { specVersions } from '../cs-api';
|
||||
|
||||
type SpecVersionsLoaderProps = {
|
||||
baseUrl: string;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { ReactNode } from 'react';
|
||||
import { UIAFlow } from '$types/matrix-sdk';
|
||||
import type { ReactNode } from 'react';
|
||||
import type { UIAFlow } from '$types/matrix-sdk';
|
||||
import { useSupportedUIAFlows } from '$hooks/useUIAFlows';
|
||||
|
||||
export function SupportedUIAFlowsLoader({
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { ReactNode } from 'react';
|
||||
import type { ReactNode } from 'react';
|
||||
import { motion, useMotionValue, useSpring } from 'framer-motion';
|
||||
import { useDrag } from '@use-gesture/react';
|
||||
import { useAtomValue } from 'jotai';
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { useMotionValue, useSpring, useTransform, motion } from 'framer-motion';
|
||||
import { useDrag } from '@use-gesture/react';
|
||||
import { ReactNode, useMemo, useState } from 'react';
|
||||
import type { ReactNode } from 'react';
|
||||
import { useMemo, useState } from 'react';
|
||||
import { useAtomValue } from 'jotai';
|
||||
import { config, Icon, Icons } from 'folds';
|
||||
import { mobileOrTablet } from '$utils/user-agent';
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { ReactNode } from 'react';
|
||||
import type { ReactNode } from 'react';
|
||||
import { motion, useMotionValue, useSpring } from 'framer-motion';
|
||||
import { useDrag } from '@use-gesture/react';
|
||||
import { useAtomValue } from 'jotai';
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { ReactNode } from 'react';
|
||||
import type { ReactNode } from 'react';
|
||||
import {
|
||||
Overlay,
|
||||
OverlayBackdrop,
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { Dispatch, ReactElement, SetStateAction, useState } from 'react';
|
||||
import type { Dispatch, ReactElement, SetStateAction } from 'react';
|
||||
import { useState } from 'react';
|
||||
|
||||
type UseStateProviderProps<T> = {
|
||||
initial: T | (() => T);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { Menu, PopOut, toRem } from 'folds';
|
||||
import FocusTrap from 'focus-trap-react';
|
||||
import { useCloseUserRoomProfile, useUserRoomProfileState } from '$state/hooks/userRoomProfile';
|
||||
import { UserRoomProfileState } from '$state/userRoomProfile';
|
||||
import type { UserRoomProfileState } from '$state/userRoomProfile';
|
||||
import { useAllJoinedRoomsSet, useGetRoom } from '$hooks/useGetRoom';
|
||||
import { stopPropagation } from '$utils/keyboard';
|
||||
import { SpaceProvider } from '$hooks/useSpace';
|
||||
@@ -23,7 +23,7 @@ function UserRoomProfileContextMenu({ state }: { state: UserRoomProfileState })
|
||||
<PopOut
|
||||
anchor={cords}
|
||||
position={position ?? 'Top'}
|
||||
align="Start"
|
||||
align={cords.y > window.innerHeight / 2 ? 'End' : 'Start'}
|
||||
content={
|
||||
<FocusTrap
|
||||
focusTrapOptions={{
|
||||
|
||||
@@ -6,8 +6,9 @@ import { CodeHighlightRenderer } from '.';
|
||||
import * as css from './CodeHighlightRenderer.css';
|
||||
|
||||
const { highlightCode, useArboriumThemeStatus } = vi.hoisted(() => ({
|
||||
highlightCode: vi.fn(),
|
||||
useArboriumThemeStatus: vi.fn(),
|
||||
highlightCode:
|
||||
vi.fn<() => Promise<{ mode: 'highlighted' | 'plain'; html: string; language: string }>>(),
|
||||
useArboriumThemeStatus: vi.fn<() => { ready: boolean }>(),
|
||||
}));
|
||||
|
||||
vi.mock('$plugins/arborium', () => ({
|
||||
|
||||
@@ -74,7 +74,6 @@ export function CodeHighlightRenderer({
|
||||
}
|
||||
|
||||
return (
|
||||
// eslint-disable-next-line react/no-danger
|
||||
<code className={codeClassName} dangerouslySetInnerHTML={{ __html: currentResult.html }} />
|
||||
);
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
import type { RectCords } from 'folds';
|
||||
import {
|
||||
Box,
|
||||
Button,
|
||||
@@ -10,7 +11,6 @@ import {
|
||||
Menu,
|
||||
MenuItem,
|
||||
PopOut,
|
||||
RectCords,
|
||||
Scroll,
|
||||
Text,
|
||||
toRem,
|
||||
@@ -18,18 +18,14 @@ import {
|
||||
import { isKeyHotkey } from 'is-hotkey';
|
||||
import FocusTrap from 'focus-trap-react';
|
||||
import { getMxIdServer } from '$utils/mxIdHelper';
|
||||
import {
|
||||
ChangeEventHandler,
|
||||
KeyboardEventHandler,
|
||||
MouseEventHandler,
|
||||
useMemo,
|
||||
useState,
|
||||
} from 'react';
|
||||
import type { ChangeEventHandler, KeyboardEventHandler, MouseEventHandler } from 'react';
|
||||
import { useMemo, useState } from 'react';
|
||||
import { getMxIdLocalPart, isUserId } from '$utils/matrix';
|
||||
import { useDirectUsers } from '$hooks/useDirectUsers';
|
||||
import { useMatrixClient } from '$hooks/useMatrixClient';
|
||||
import { stopPropagation } from '$utils/keyboard';
|
||||
import { useAsyncSearch, UseAsyncSearchOptions } from '$hooks/useAsyncSearch';
|
||||
import type { UseAsyncSearchOptions } from '$hooks/useAsyncSearch';
|
||||
import { useAsyncSearch } from '$hooks/useAsyncSearch';
|
||||
import { highlightText, makeHighlightRegex } from '$plugins/react-custom-html-parser';
|
||||
import { SettingTile } from '$components/setting-tile';
|
||||
|
||||
@@ -102,7 +98,7 @@ export function AdditionalCreatorInput({
|
||||
|
||||
const suggestionUsers = result
|
||||
? result.items
|
||||
: filteredUsers.sort((a, b) => (a.toLocaleLowerCase() >= b.toLocaleLowerCase() ? 1 : -1));
|
||||
: filteredUsers.toSorted((a, b) => (a.toLocaleLowerCase() >= b.toLocaleLowerCase() ? 1 : -1));
|
||||
|
||||
const handleOpenMenu: MouseEventHandler<HTMLButtonElement> = (evt) => {
|
||||
setMenuCords(evt.currentTarget.getBoundingClientRect());
|
||||
@@ -225,7 +221,10 @@ export function AdditionalCreatorInput({
|
||||
grow="Yes"
|
||||
direction="Column"
|
||||
gap="100"
|
||||
style={{ padding: config.space.S200, paddingRight: 0 }}
|
||||
style={{
|
||||
padding: config.space.S200,
|
||||
paddingRight: 0,
|
||||
}}
|
||||
>
|
||||
{suggestionUsers.map((userId) => (
|
||||
<MenuItem
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { Box, Text, Icon, Icons, config, IconSrc } from 'folds';
|
||||
import type { IconSrc } from 'folds';
|
||||
import { Box, Text, Icon, Icons, config } from 'folds';
|
||||
import { SequenceCard } from '$components/sequence-card';
|
||||
import { SettingTile } from '$components/setting-tile';
|
||||
import { CreateRoomAccess } from './types';
|
||||
|
||||
@@ -1,17 +1,12 @@
|
||||
import {
|
||||
FormEventHandler,
|
||||
KeyboardEventHandler,
|
||||
useCallback,
|
||||
useEffect,
|
||||
useRef,
|
||||
useState,
|
||||
} from 'react';
|
||||
import type { FormEventHandler, KeyboardEventHandler } from 'react';
|
||||
import { useCallback, useEffect, useRef, useState } from 'react';
|
||||
import { MatrixError } from '$types/matrix-sdk';
|
||||
import { Box, color, Icon, Icons, Input, Spinner, Text, toRem } from 'folds';
|
||||
import { isKeyHotkey } from 'is-hotkey';
|
||||
import { useMatrixClient } from '$hooks/useMatrixClient';
|
||||
import { replaceSpaceWithDash } from '$utils/common';
|
||||
import { AsyncState, AsyncStatus, useAsync } from '$hooks/useAsyncCallback';
|
||||
import type { AsyncState } from '$hooks/useAsyncCallback';
|
||||
import { AsyncStatus, useAsync } from '$hooks/useAsyncCallback';
|
||||
import { useDebounce } from '$hooks/useDebounce';
|
||||
import { getMxIdServer } from '$utils/mxIdHelper';
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { Box, Text, Icon, Icons, config, IconSrc } from 'folds';
|
||||
import type { IconSrc } from 'folds';
|
||||
import { Box, Text, Icon, Icons, config } from 'folds';
|
||||
import { SequenceCard } from '$components/sequence-card';
|
||||
import { SettingTile } from '$components/setting-tile';
|
||||
import { BetaNoticeBadge } from '$components/BetaNoticeBadge';
|
||||
|
||||
@@ -1,17 +1,7 @@
|
||||
import { MouseEventHandler, useState } from 'react';
|
||||
import {
|
||||
Box,
|
||||
Button,
|
||||
Chip,
|
||||
config,
|
||||
Icon,
|
||||
Icons,
|
||||
Menu,
|
||||
PopOut,
|
||||
RectCords,
|
||||
Text,
|
||||
toRem,
|
||||
} from 'folds';
|
||||
import type { MouseEventHandler } from 'react';
|
||||
import { useState } from 'react';
|
||||
import type { RectCords } from 'folds';
|
||||
import { Box, Button, Chip, config, Icon, Icons, Menu, PopOut, Text, toRem } from 'folds';
|
||||
import FocusTrap from 'focus-trap-react';
|
||||
import { stopPropagation } from '$utils/keyboard';
|
||||
import { SettingTile } from '$components/setting-tile';
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
import {
|
||||
import type {
|
||||
ICreateRoomOpts,
|
||||
ICreateRoomStateEvent,
|
||||
JoinRule,
|
||||
MatrixClient,
|
||||
RestrictedAllowType,
|
||||
Room,
|
||||
RoomJoinRulesEventContent,
|
||||
} from '$types/matrix-sdk';
|
||||
import { RoomType, StateEvent } from '$types/matrix/room';
|
||||
import { JoinRule, RestrictedAllowType, EventType, RoomType } from '$types/matrix-sdk';
|
||||
|
||||
import type { StateEvents } from '$types/matrix-sdk';
|
||||
import { getViaServers } from '$plugins/via-servers';
|
||||
import { getMxIdServer } from '$utils/mxIdHelper';
|
||||
import { CreateRoomAccess } from './types';
|
||||
@@ -17,11 +17,11 @@ export const createRoomCreationContent = (
|
||||
allowFederation: boolean,
|
||||
additionalCreators: string[] | undefined
|
||||
): object => {
|
||||
const content: Record<string, any> = {};
|
||||
const content: Record<string, unknown> = {};
|
||||
if (typeof type === 'string') {
|
||||
content.type = type;
|
||||
}
|
||||
if (allowFederation === false) {
|
||||
if (!allowFederation) {
|
||||
content['m.federate'] = false;
|
||||
}
|
||||
if (Array.isArray(additionalCreators)) {
|
||||
@@ -59,14 +59,14 @@ export const createRoomJoinRulesState = (
|
||||
}
|
||||
|
||||
return {
|
||||
type: StateEvent.RoomJoinRules,
|
||||
type: EventType.RoomJoinRules,
|
||||
state_key: '',
|
||||
content,
|
||||
};
|
||||
};
|
||||
|
||||
export const createRoomParentState = (parent: Room) => ({
|
||||
type: StateEvent.SpaceParent,
|
||||
type: EventType.SpaceParent,
|
||||
state_key: parent.roomId,
|
||||
content: {
|
||||
canonical: true,
|
||||
@@ -94,7 +94,7 @@ export const createRoomCallState = () => ({
|
||||
|
||||
export const createVoiceRoomPowerLevelsOverride = () => ({
|
||||
events: {
|
||||
[StateEvent.GroupCallMemberPrefix]: 0,
|
||||
[EventType.GroupCallMemberPrefix]: 0,
|
||||
},
|
||||
});
|
||||
|
||||
@@ -122,7 +122,7 @@ export const createRoom = async (mx: MatrixClient, data: CreateRoomData): Promis
|
||||
initialState.push(createRoomParentState(data.parent));
|
||||
}
|
||||
|
||||
if (data.type === RoomType.Call) {
|
||||
if (data.type === RoomType.UnstableCall) {
|
||||
initialState.push(createRoomCallState());
|
||||
}
|
||||
|
||||
@@ -139,7 +139,7 @@ export const createRoom = async (mx: MatrixClient, data: CreateRoomData): Promis
|
||||
data.additionalCreators
|
||||
),
|
||||
power_level_content_override:
|
||||
data.type === RoomType.Call ? createVoiceRoomPowerLevelsOverride() : undefined,
|
||||
data.type === RoomType.UnstableCall ? createVoiceRoomPowerLevelsOverride() : undefined,
|
||||
initial_state: initialState,
|
||||
};
|
||||
|
||||
@@ -152,12 +152,12 @@ export const createRoom = async (mx: MatrixClient, data: CreateRoomData): Promis
|
||||
if (data.parent) {
|
||||
await mx.sendStateEvent(
|
||||
data.parent.roomId,
|
||||
StateEvent.SpaceChild as any,
|
||||
EventType.SpaceChild as keyof StateEvents,
|
||||
{
|
||||
auto_join: false,
|
||||
suggested: false,
|
||||
via: [getMxIdServer(mx.getUserId() ?? '') ?? ''],
|
||||
},
|
||||
} as StateEvents[keyof StateEvents],
|
||||
result.room_id
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { as, ContainerColor as TContainerColor } from 'folds';
|
||||
import type { ContainerColor as TContainerColor } from 'folds';
|
||||
import { as } from 'folds';
|
||||
import classNames from 'classnames';
|
||||
import { ContainerColor } from '$styles/ContainerColor.css';
|
||||
import * as css from './CutoutCard.css';
|
||||
|
||||
@@ -1,31 +1,15 @@
|
||||
/* eslint-disable no-param-reassign */
|
||||
import {
|
||||
ClipboardEventHandler,
|
||||
KeyboardEventHandler,
|
||||
ReactNode,
|
||||
forwardRef,
|
||||
useCallback,
|
||||
useEffect,
|
||||
useLayoutEffect,
|
||||
useRef,
|
||||
useState,
|
||||
} from 'react';
|
||||
import type { ClipboardEventHandler, KeyboardEventHandler, ReactNode } from 'react';
|
||||
import { forwardRef, useCallback, useEffect, useLayoutEffect, useRef, useState } from 'react';
|
||||
import { Box, Scroll, Text } from 'folds';
|
||||
import { Descendant, Editor, Node, createEditor } from 'slate';
|
||||
import {
|
||||
Slate,
|
||||
Editable,
|
||||
withReact,
|
||||
RenderLeafProps,
|
||||
RenderElementProps,
|
||||
RenderPlaceholderProps,
|
||||
ReactEditor,
|
||||
} from 'slate-react';
|
||||
import type { Descendant, Editor } from 'slate';
|
||||
import { Node, createEditor } from 'slate';
|
||||
import type { RenderLeafProps, RenderElementProps, RenderPlaceholderProps } from 'slate-react';
|
||||
import { Slate, Editable, withReact, ReactEditor } from 'slate-react';
|
||||
import { withHistory } from 'slate-history';
|
||||
import { mobileOrTablet } from '$utils/user-agent';
|
||||
import { BlockType } from './types';
|
||||
import { RenderElement, RenderLeaf } from './Elements';
|
||||
import { CustomElement } from './slate';
|
||||
import type { CustomElement } from './slate';
|
||||
import * as css from './Editor.css';
|
||||
import { toggleKeyboardShortcut } from './keyboard';
|
||||
|
||||
@@ -436,7 +420,9 @@ export const CustomEditor = forwardRef<HTMLDivElement, CustomEditorProps>(
|
||||
<Scroll
|
||||
className={`${css.EditorTextareaScroll} ${layoutIsMultiline ? css.EditorTextareaScrollMultiline : ''}`}
|
||||
variant={variant}
|
||||
style={{ maxHeight: showResponsiveAfterInFooter ? undefined : maxHeight }}
|
||||
style={{
|
||||
maxHeight: showResponsiveAfterInFooter ? undefined : maxHeight,
|
||||
}}
|
||||
size="300"
|
||||
visibility="Always"
|
||||
hideTrack
|
||||
|
||||
@@ -1,11 +1,6 @@
|
||||
import { Scroll, Text } from 'folds';
|
||||
import {
|
||||
RenderElementProps,
|
||||
RenderLeafProps,
|
||||
useFocused,
|
||||
useSelected,
|
||||
useSlate,
|
||||
} from 'slate-react';
|
||||
import type { RenderElementProps, RenderLeafProps } from 'slate-react';
|
||||
import { useFocused, useSelected, useSlate } from 'slate-react';
|
||||
import { useAtomValue } from 'jotai';
|
||||
|
||||
import * as css from '$styles/CustomHtml.css';
|
||||
@@ -15,7 +10,7 @@ import { useMediaAuthentication } from '$hooks/useMediaAuthentication';
|
||||
import { nicknamesAtom } from '$state/nicknames';
|
||||
import { BlockType } from './types';
|
||||
import { getBeginCommand } from './utils';
|
||||
import { CommandElement, EmoticonElement, LinkElement, MentionElement } from './slate';
|
||||
import type { CommandElement, EmoticonElement, LinkElement, MentionElement } from './slate';
|
||||
|
||||
// Put this at the start and end of an inline component to work around this Chromium bug:
|
||||
// https://bugs.chromium.org/p/chromium/issues/detail?id=1249405
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import FocusTrap from 'focus-trap-react';
|
||||
import type { IconSrc, RectCords } from 'folds';
|
||||
import {
|
||||
Badge,
|
||||
Box,
|
||||
@@ -6,18 +7,17 @@ import {
|
||||
Icon,
|
||||
IconButton,
|
||||
Icons,
|
||||
IconSrc,
|
||||
Line,
|
||||
Menu,
|
||||
PopOut,
|
||||
RectCords,
|
||||
Scroll,
|
||||
Text,
|
||||
Tooltip,
|
||||
TooltipProvider,
|
||||
toRem,
|
||||
} from 'folds';
|
||||
import { MouseEventHandler, ReactNode, useState } from 'react';
|
||||
import type { MouseEventHandler, ReactNode } from 'react';
|
||||
import { useState } from 'react';
|
||||
import { ReactEditor, useSlate } from 'slate-react';
|
||||
import { isMacOS } from '$utils/user-agent';
|
||||
import { KeySymbol } from '$utils/key-symbol';
|
||||
@@ -25,7 +25,7 @@ import { useSetting } from '$state/hooks/settings';
|
||||
import { settingsAtom } from '$state/settings';
|
||||
import { stopPropagation } from '$utils/keyboard';
|
||||
import { floatingToolbar } from '$styles/overrides/Composer.css';
|
||||
import { HeadingLevel } from './slate';
|
||||
import type { HeadingLevel } from './slate';
|
||||
import { BlockType, MarkType } from './types';
|
||||
import * as css from './Editor.css';
|
||||
import {
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
import { ReactNode, useEffect, useRef, useState } from 'react';
|
||||
import type { ReactNode } from 'react';
|
||||
import { useEffect, useRef, useState } from 'react';
|
||||
import FocusTrap from 'focus-trap-react';
|
||||
import { isKeyHotkey } from 'is-hotkey';
|
||||
import { Header, Menu, Scroll, config } from 'folds';
|
||||
|
||||
import { preventScrollWithArrowKey, stopPropagation } from '$utils/keyboard';
|
||||
import { useAlive } from '$hooks/useAlive';
|
||||
import { Editor } from 'slate';
|
||||
import type { Editor } from 'slate';
|
||||
import { ReactEditor } from 'slate-react';
|
||||
import * as css from './AutocompleteMenu.css';
|
||||
import { BaseAutocompleteMenu } from './BaseAutocompleteMenu';
|
||||
@@ -33,7 +34,7 @@ export function AutocompleteMenu({
|
||||
};
|
||||
const [isActive, setIsActive] = useState(true);
|
||||
useEffect(() => ReactEditor.focus(editor), [editor, isActive]);
|
||||
function handleInput(evt: any) {
|
||||
function handleInput(evt: KeyboardEvent) {
|
||||
if (!evt) return;
|
||||
if (
|
||||
isKeyHotkey('arrowdown', evt) ||
|
||||
@@ -61,7 +62,10 @@ export function AutocompleteMenu({
|
||||
escapeDeactivates: stopPropagation,
|
||||
}}
|
||||
>
|
||||
<Menu className={css.AutocompleteMenu} onKeyDown={(evt) => handleInput(evt)}>
|
||||
<Menu
|
||||
className={css.AutocompleteMenu}
|
||||
onKeyDown={(evt) => handleInput(evt as unknown as KeyboardEvent)}
|
||||
>
|
||||
<Header className={css.AutocompleteMenuHeader} size="400">
|
||||
{headerContent}
|
||||
</Header>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { ReactNode } from 'react';
|
||||
import type { ReactNode } from 'react';
|
||||
import { Header, Menu } from 'folds';
|
||||
import { BaseAutocompleteMenu } from './BaseAutocompleteMenu';
|
||||
import * as css from './AutocompleteMenu.css';
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { ReactNode } from 'react';
|
||||
import type { ReactNode } from 'react';
|
||||
import * as css from './AutocompleteMenu.css';
|
||||
|
||||
type BaseAutocompleteMenuProps = {
|
||||
|
||||
@@ -1,25 +1,29 @@
|
||||
import { KeyboardEvent as ReactKeyboardEvent, useEffect, useMemo } from 'react';
|
||||
import { Editor } from 'slate';
|
||||
import type { KeyboardEvent as ReactKeyboardEvent } from 'react';
|
||||
import { useEffect, useMemo } from 'react';
|
||||
import type { Editor } from 'slate';
|
||||
import { ReactEditor } from 'slate-react';
|
||||
import { Box, MenuItem, Text, toRem } from 'folds';
|
||||
import { Room } from '$types/matrix-sdk';
|
||||
import type { Room } from '$types/matrix-sdk';
|
||||
|
||||
import { useMatrixClient } from '$hooks/useMatrixClient';
|
||||
import { UseAsyncSearchOptions, useAsyncSearch } from '$hooks/useAsyncSearch';
|
||||
import type { UseAsyncSearchOptions } from '$hooks/useAsyncSearch';
|
||||
import { useAsyncSearch } from '$hooks/useAsyncSearch';
|
||||
import { onTabPress } from '$utils/keyboard';
|
||||
import { useRecentEmoji } from '$hooks/useRecentEmoji';
|
||||
import { useRelevantImagePacks } from '$hooks/useImagePacks';
|
||||
import { IEmoji, emojis } from '$plugins/emoji';
|
||||
import type { IEmoji } from '$plugins/emoji';
|
||||
import { emojis } from '$plugins/emoji';
|
||||
import { useKeyDown } from '$hooks/useKeyDown';
|
||||
import { mxcUrlToHttp } from '$utils/matrix';
|
||||
import { useMediaAuthentication } from '$hooks/useMediaAuthentication';
|
||||
import { ImageUsage, PackImageReader } from '$plugins/custom-emoji';
|
||||
import type { PackImageReader } from '$plugins/custom-emoji';
|
||||
import { ImageUsage } from '$plugins/custom-emoji';
|
||||
import { getEmoticonSearchStr } from '$plugins/utils';
|
||||
import { useSetting } from '$state/hooks/settings';
|
||||
import { settingsAtom } from '$state/settings';
|
||||
import { createEmoticonElement, moveCursor, replaceWithElement } from '$components/editor/utils';
|
||||
import { AutocompleteMenu } from './AutocompleteMenu';
|
||||
import { AutocompleteQuery } from './autocompleteQuery';
|
||||
import type { AutocompleteQuery } from './autocompleteQuery';
|
||||
|
||||
type EmoticonCompleteHandler = (key: string, shortcode: string) => void;
|
||||
|
||||
@@ -96,7 +100,7 @@ export function EmoticonAutocomplete({
|
||||
useKeyDown(window, (evt: KeyboardEvent) => {
|
||||
onTabPress(evt, () => {
|
||||
if (autoCompleteEmoticon.length === 0) return;
|
||||
const emoticon = autoCompleteEmoticon[0];
|
||||
const emoticon = autoCompleteEmoticon[0]!;
|
||||
const key = 'url' in emoticon ? emoticon.url : emoticon.unicode;
|
||||
handleAutocomplete(key, emoticon.shortcode);
|
||||
});
|
||||
@@ -129,7 +133,11 @@ export function EmoticonAutocomplete({
|
||||
as="img"
|
||||
src={customEmojiUrl}
|
||||
alt={emoticon.shortcode}
|
||||
style={{ width: toRem(24), height: toRem(24), objectFit: 'contain' }}
|
||||
style={{
|
||||
width: toRem(24),
|
||||
height: toRem(24),
|
||||
objectFit: 'contain',
|
||||
}}
|
||||
/>
|
||||
) : (
|
||||
<Box
|
||||
|
||||
@@ -1,14 +1,17 @@
|
||||
import { KeyboardEvent as ReactKeyboardEvent, useCallback, useEffect } from 'react';
|
||||
import { Editor } from 'slate';
|
||||
import type { KeyboardEvent as ReactKeyboardEvent } from 'react';
|
||||
import { useCallback, useEffect, useMemo } from 'react';
|
||||
import type { Editor } from 'slate';
|
||||
import { ReactEditor } from 'slate-react';
|
||||
import { Avatar, Icon, Icons, MenuItem, Text } from 'folds';
|
||||
import { JoinRule, MatrixClient } from '$types/matrix-sdk';
|
||||
import type { MatrixClient } from '$types/matrix-sdk';
|
||||
import { JoinRule } from '$types/matrix-sdk';
|
||||
import { useAtomValue } from 'jotai';
|
||||
|
||||
import { getDirectRoomAvatarUrl } from '$utils/room';
|
||||
import { useMatrixClient } from '$hooks/useMatrixClient';
|
||||
import { isRoomAlias } from '$utils/matrix';
|
||||
import { UseAsyncSearchOptions, useAsyncSearch } from '$hooks/useAsyncSearch';
|
||||
import { useAsyncSearch } from '$hooks/useAsyncSearch';
|
||||
import type { UseAsyncSearchOptions } from '$hooks/useAsyncSearch';
|
||||
import { onTabPress } from '$utils/keyboard';
|
||||
import { useKeyDown } from '$hooks/useKeyDown';
|
||||
import { mDirectAtom } from '$state/mDirectList';
|
||||
@@ -19,7 +22,7 @@ import { getViaServers } from '$plugins/via-servers';
|
||||
import { createMentionElement, moveCursor, replaceWithElement } from '$components/editor/utils';
|
||||
import { getMxIdServer } from '$utils/mxIdHelper';
|
||||
import { AutocompleteMenu } from './AutocompleteMenu';
|
||||
import { AutocompleteQuery } from './autocompleteQuery';
|
||||
import type { AutocompleteQuery } from './autocompleteQuery';
|
||||
|
||||
type MentionAutoCompleteHandler = (roomAliasOrId: string, name: string) => void;
|
||||
|
||||
@@ -81,7 +84,11 @@ export function RoomMentionAutocomplete({
|
||||
const mx = useMatrixClient();
|
||||
const mDirects = useAtomValue(mDirectAtom);
|
||||
|
||||
const allRooms = useAtomValue(allRoomsAtom).sort(factoryRoomIdByActivity(mx));
|
||||
const allRoomsFromAtom = useAtomValue(allRoomsAtom);
|
||||
const allRooms = useMemo(
|
||||
() => allRoomsFromAtom.toSorted(factoryRoomIdByActivity(mx)),
|
||||
[allRoomsFromAtom, mx]
|
||||
);
|
||||
|
||||
const [result, search, resetSearch] = useAsyncSearch(
|
||||
allRooms,
|
||||
@@ -131,7 +138,7 @@ export function RoomMentionAutocomplete({
|
||||
const rId = autoCompleteRoomIds[0];
|
||||
const r = mx.getRoom(rId);
|
||||
const name = r?.name ?? rId;
|
||||
handleAutocomplete(r?.getCanonicalAlias() ?? rId, name);
|
||||
handleAutocomplete(r?.getCanonicalAlias() ?? rId ?? '', name as string);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -1,25 +1,28 @@
|
||||
import { useEffect, KeyboardEvent as ReactKeyboardEvent } from 'react';
|
||||
import { Editor } from 'slate';
|
||||
import type { KeyboardEvent as ReactKeyboardEvent } from 'react';
|
||||
import { useEffect } from 'react';
|
||||
import type { Editor } from 'slate';
|
||||
import { ReactEditor } from 'slate-react';
|
||||
import { Avatar, Icon, Icons, MenuItem, Text } from 'folds';
|
||||
import { MatrixClient, Room, RoomMember } from '$types/matrix-sdk';
|
||||
import type { MatrixClient, Room, RoomMember } from '$types/matrix-sdk';
|
||||
|
||||
import { useRoomMembers } from '$hooks/useRoomMembers';
|
||||
import { useMatrixClient } from '$hooks/useMatrixClient';
|
||||
import { SearchItemStrGetter, UseAsyncSearchOptions, useAsyncSearch } from '$hooks/useAsyncSearch';
|
||||
import type { SearchItemStrGetter, UseAsyncSearchOptions } from '$hooks/useAsyncSearch';
|
||||
import { useAsyncSearch } from '$hooks/useAsyncSearch';
|
||||
import { onTabPress } from '$utils/keyboard';
|
||||
import { useKeyDown } from '$hooks/useKeyDown';
|
||||
import { getMxIdLocalPart, isUserId } from '$utils/matrix';
|
||||
import { getMemberDisplayName, getMemberSearchStr } from '$utils/room';
|
||||
import { UserAvatar } from '$components/user-avatar';
|
||||
import { useMediaAuthentication } from '$hooks/useMediaAuthentication';
|
||||
import { Membership } from '$types/matrix/room';
|
||||
|
||||
import { useAtomValue } from 'jotai';
|
||||
import { nicknamesAtom } from '$state/nicknames';
|
||||
import { createMentionElement, moveCursor, replaceWithElement } from '$components/editor/utils';
|
||||
import { getMxIdServer } from '$utils/mxIdHelper';
|
||||
import { AutocompleteMenu } from './AutocompleteMenu';
|
||||
import { AutocompleteQuery } from './autocompleteQuery';
|
||||
import type { AutocompleteQuery } from './autocompleteQuery';
|
||||
import { KnownMembership } from '$types/matrix-sdk';
|
||||
|
||||
type MentionAutoCompleteHandler = (userId: string, name: string) => void;
|
||||
|
||||
@@ -69,9 +72,9 @@ type UserMentionAutocompleteProps = {
|
||||
};
|
||||
|
||||
const withAllowedMembership = (member: RoomMember): boolean =>
|
||||
member.membership === Membership.Join ||
|
||||
member.membership === Membership.Invite ||
|
||||
member.membership === Membership.Knock;
|
||||
member.membership === KnownMembership.Join ||
|
||||
member.membership === KnownMembership.Invite ||
|
||||
member.membership === KnownMembership.Knock;
|
||||
|
||||
const SEARCH_OPTIONS: UseAsyncSearchOptions = {
|
||||
limit: 1000,
|
||||
@@ -138,7 +141,7 @@ export function UserMentionAutocomplete({
|
||||
handleAutocomplete(userId, userId);
|
||||
return;
|
||||
}
|
||||
const roomMember = autoCompleteMembers[0];
|
||||
const roomMember = autoCompleteMembers[0]!;
|
||||
handleAutocomplete(roomMember.userId, getName(roomMember));
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { BaseRange, Editor } from 'slate';
|
||||
import type { BaseRange } from 'slate';
|
||||
import { Editor } from 'slate';
|
||||
|
||||
export enum AutocompletePrefix {
|
||||
RoomMention = '#',
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import { Descendant, Text } from 'slate';
|
||||
import type { Descendant } from 'slate';
|
||||
import { Text } from 'slate';
|
||||
import parse from 'html-dom-parser';
|
||||
import { ChildNode, Element, isText, isTag } from 'domhandler';
|
||||
import type { ChildNode, Element } from 'domhandler';
|
||||
import { isText, isTag } from 'domhandler';
|
||||
|
||||
import { sanitizeCustomHtml } from '$utils/sanitize';
|
||||
import {
|
||||
@@ -11,7 +13,7 @@ import {
|
||||
} from '$plugins/matrix-to';
|
||||
import { escapeMarkdownInlineSequences, escapeMarkdownBlockSequences } from '$plugins/markdown';
|
||||
import { BlockType, MarkType } from './types';
|
||||
import {
|
||||
import type {
|
||||
BlockQuoteElement,
|
||||
CodeBlockElement,
|
||||
CodeLineElement,
|
||||
@@ -83,7 +85,12 @@ const getInlineMarkElement = (
|
||||
children.push({ text: mdSequence });
|
||||
return children;
|
||||
}
|
||||
return children.map((child) => (Text.isText(child) ? { ...child, [markType]: true } : child));
|
||||
return children.map((child) => {
|
||||
if (Text.isText(child)) {
|
||||
return { ...child, [markType]: true };
|
||||
}
|
||||
return child;
|
||||
});
|
||||
};
|
||||
|
||||
const getInlineNonMarkElement = (node: Element): MentionElement | EmoticonElement | undefined => {
|
||||
@@ -220,7 +227,7 @@ const parseCodeBlockNode = (node: Element): CodeBlockElement[] | ParagraphElemen
|
||||
type: BlockType.Paragraph,
|
||||
children: [{ text }],
|
||||
}));
|
||||
const childCode = node.children[0];
|
||||
const childCode = node.children[0]!;
|
||||
const className =
|
||||
isTag(childCode) && childCode.tagName === 'code' ? (childCode.attribs.class ?? '') : '';
|
||||
const prefix = { text: `${mdSequence}${className.replace('language-', '')}` };
|
||||
@@ -322,7 +329,7 @@ const parseHeadingNode = (
|
||||
|
||||
const headingMatch = node.name.match(/^h([123456])$/);
|
||||
const [, g1AsLevel] = headingMatch ?? ['h3', '3'];
|
||||
const level = Number.parseInt(g1AsLevel, 10);
|
||||
const level = Number.parseInt(g1AsLevel!, 10);
|
||||
|
||||
const mdSequence = node.attribs['data-md'];
|
||||
if (mdSequence !== undefined) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { isKeyHotkey } from 'is-hotkey';
|
||||
import { KeyboardEvent } from 'react';
|
||||
import type { KeyboardEvent } from 'react';
|
||||
import { Editor, Element as SlateElement, Range, Transforms } from 'slate';
|
||||
import { isAnyMarkActive, isBlockActive, removeAllMark, toggleBlock, toggleMark } from './utils';
|
||||
import { BlockType, MarkType } from './types';
|
||||
@@ -83,7 +83,7 @@ export const toggleKeyboardShortcut = (editor: Editor, event: KeyboardEvent): bo
|
||||
const blockToggled = BLOCK_KEYS.find((hotkey) => {
|
||||
if (isKeyHotkey(hotkey, event)) {
|
||||
event.preventDefault();
|
||||
toggleBlock(editor, BLOCK_HOTKEYS[hotkey]);
|
||||
toggleBlock(editor, BLOCK_HOTKEYS[hotkey]!);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -107,7 +107,7 @@ export const toggleKeyboardShortcut = (editor: Editor, event: KeyboardEvent): bo
|
||||
: INLINE_KEYS.find((hotkey) => {
|
||||
if (isKeyHotkey(hotkey, event)) {
|
||||
event.preventDefault();
|
||||
toggleMark(editor, INLINE_HOTKEYS[hotkey]);
|
||||
toggleMark(editor, INLINE_HOTKEYS[hotkey]!);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { Descendant, Editor, Text } from 'slate';
|
||||
import { MatrixClient } from '$types/matrix-sdk';
|
||||
import type { Descendant, Editor } from 'slate';
|
||||
import { Text } from 'slate';
|
||||
import type { MatrixClient } from '$types/matrix-sdk';
|
||||
import { sanitizeText } from '$utils/sanitize';
|
||||
import {
|
||||
parseBlockMD,
|
||||
@@ -10,7 +11,7 @@ import {
|
||||
import { findAndReplace } from '$utils/findAndReplace';
|
||||
import { sanitizeForRegex } from '$utils/regex';
|
||||
import { isUserId } from '$utils/matrix';
|
||||
import { CustomElement } from './slate';
|
||||
import type { CustomElement } from './slate';
|
||||
import { BlockType } from './types';
|
||||
|
||||
export type OutputOptions = {
|
||||
@@ -38,7 +39,7 @@ const textToCustomHtml = (node: Text, opts: OutputOptions): string => {
|
||||
if (node.spoiler) string = `<span data-mx-spoiler>${string}</span>`;
|
||||
}
|
||||
|
||||
if (opts.allowInlineMarkdown && string === sanitizeText(node.text)) {
|
||||
if (opts.allowInlineMarkdown && string === sanitizeText(node.text) && !node.code) {
|
||||
string = parseInlineMD(string);
|
||||
}
|
||||
|
||||
@@ -90,7 +91,7 @@ const elementToCustomHtml = (node: CustomElement, children: string): string => {
|
||||
)}" title="${sanitizeText(node.shortcode)}" height="32" />`
|
||||
: sanitizeText(node.key);
|
||||
case BlockType.Link:
|
||||
return `<a href="${encodeURI(node.href)}">${node.children}</a>`;
|
||||
return `<a href="${encodeURI(node.href)}">${children}</a>`;
|
||||
case BlockType.Command:
|
||||
return `/${sanitizeText(node.command)}`;
|
||||
default:
|
||||
@@ -184,7 +185,7 @@ const elementToPlainText = (node: CustomElement, children: string): string => {
|
||||
case BlockType.Emoticon:
|
||||
return node.key.startsWith('mxc://') ? `:${node.shortcode}:` : node.key;
|
||||
case BlockType.Link:
|
||||
return `[${node.children}](${node.href})`;
|
||||
return `[${children}](${node.href})`;
|
||||
case BlockType.Command:
|
||||
return `/${node.command}`;
|
||||
case BlockType.Small:
|
||||
@@ -196,6 +197,12 @@ const elementToPlainText = (node: CustomElement, children: string): string => {
|
||||
}
|
||||
};
|
||||
|
||||
const SPOILERINPUTREGEX = /\|\|.+?\|\|/g;
|
||||
const LINK_URL = `(https?:\\/\\/.[A-Za-z0-9-._~:/?#[\\]()@!$&'*+,;%=]+)`;
|
||||
export const LINKINPUTREGEX = new RegExp(`\\(?(${LINK_URL})\\)?`, 'g');
|
||||
const SPOILEREDLINKINPUTREGEX = new RegExp(`<(${LINK_URL})>`, 'g');
|
||||
const MASKEDSPOILEREDLINKINPUTREGEX = new RegExp(`\\[.+\\]\\(${LINK_URL}\\)`, 'g');
|
||||
|
||||
/**
|
||||
* convert slate internal representation to a plain text string that can be sent to the server
|
||||
* @param node the slate node
|
||||
@@ -213,8 +220,12 @@ export const toPlainText = (
|
||||
if (Array.isArray(node))
|
||||
return node.map((n) => toPlainText(n, isMarkdown, stripNickname, nickNameReplacement)).join('');
|
||||
if (Text.isText(node)) {
|
||||
let { text } = node;
|
||||
|
||||
text = text.replaceAll(SPOILERINPUTREGEX, '[Spoiler]');
|
||||
text = text.replaceAll(SPOILEREDLINKINPUTREGEX, '$1');
|
||||
|
||||
if (stripNickname && nickNameReplacement) {
|
||||
let { text } = node;
|
||||
nickNameReplacement?.keys().forEach((key) => {
|
||||
const replacement = nickNameReplacement.get(key) ?? '';
|
||||
text = text.replaceAll(key, replacement);
|
||||
@@ -224,8 +235,8 @@ export const toPlainText = (
|
||||
: text;
|
||||
}
|
||||
return isMarkdown
|
||||
? unescapeMarkdownBlockSequences(node.text, unescapeMarkdownInlineSequences)
|
||||
: node.text;
|
||||
? unescapeMarkdownBlockSequences(text, unescapeMarkdownInlineSequences)
|
||||
: text;
|
||||
}
|
||||
|
||||
const children = node.children.map((n) => toPlainText(n, isMarkdown)).join('');
|
||||
@@ -304,3 +315,58 @@ export const getMentions = (mx: MatrixClient, roomId: string, editor: Editor): M
|
||||
|
||||
return mentionData;
|
||||
};
|
||||
|
||||
export const getLinks = (serialized: Descendant | Descendant[]): string[] | undefined => {
|
||||
let finalList: string[] = [];
|
||||
let isInsideCodeBlock = false;
|
||||
const parseLinks = (node: Descendant): void => {
|
||||
if (Text.isText(node)) {
|
||||
let { text } = node;
|
||||
if (text.startsWith('```') && !text.includes(' ')) {
|
||||
isInsideCodeBlock = !isInsideCodeBlock;
|
||||
return;
|
||||
}
|
||||
if (isInsideCodeBlock) return;
|
||||
// get a list of all the urls and of the ones that are spoilered,
|
||||
// truncate the spoilered ones of their <> and then remove the items that are present in both lists
|
||||
const urlsMatch = text.match(LINKINPUTREGEX);
|
||||
let urls = urlsMatch ? [...new Set(urlsMatch)] : undefined;
|
||||
urls = urls?.map(
|
||||
(url) =>
|
||||
(url.startsWith('(') && url.endsWith(')') && url.substring(1, url.length - 1)) ||
|
||||
(url.startsWith('(') && url.substring(1)) ||
|
||||
(url.endsWith('/)') && url.substring(0, url.length - 1)) ||
|
||||
url
|
||||
);
|
||||
const spoileredUrlsMatch = text.match(SPOILEREDLINKINPUTREGEX);
|
||||
let spoileredUrls = spoileredUrlsMatch ? [...new Set(spoileredUrlsMatch)] : undefined;
|
||||
spoileredUrls = spoileredUrls?.map((spoileredUrl) => spoileredUrl.slice(1, -1));
|
||||
|
||||
const maskedSpoileredUrlsMatch = text.match(MASKEDSPOILEREDLINKINPUTREGEX);
|
||||
let maskedSpoileredUrls = maskedSpoileredUrlsMatch
|
||||
? [...new Set(maskedSpoileredUrlsMatch)]
|
||||
: undefined;
|
||||
maskedSpoileredUrls = maskedSpoileredUrls?.map((maskedSpoileredUrl) =>
|
||||
maskedSpoileredUrl?.substring(
|
||||
maskedSpoileredUrl.indexOf('](') + 2,
|
||||
maskedSpoileredUrl.lastIndexOf(')')
|
||||
)
|
||||
);
|
||||
if (maskedSpoileredUrls)
|
||||
spoileredUrls = spoileredUrls
|
||||
? [...spoileredUrls, ...maskedSpoileredUrls]
|
||||
: maskedSpoileredUrls;
|
||||
|
||||
spoileredUrls = spoileredUrls?.filter(
|
||||
(item, index) => spoileredUrls?.indexOf(item) === index
|
||||
);
|
||||
urls = urls?.filter((url) => !spoileredUrls?.includes(url));
|
||||
finalList = finalList.concat(urls ?? []);
|
||||
return;
|
||||
}
|
||||
node?.children?.forEach(parseLinks);
|
||||
};
|
||||
if (Array.isArray(serialized)) serialized.map((n) => parseLinks(n));
|
||||
else parseLinks(serialized);
|
||||
return finalList.filter((item, index) => finalList.indexOf(item) === index);
|
||||
};
|
||||
Vendored
+4
-4
@@ -1,7 +1,7 @@
|
||||
import { BaseEditor } from 'slate';
|
||||
import { ReactEditor } from 'slate-react';
|
||||
import { HistoryEditor } from 'slate-history';
|
||||
import { BlockType } from './types';
|
||||
import type { BaseEditor } from 'slate';
|
||||
import type { ReactEditor } from 'slate-react';
|
||||
import type { HistoryEditor } from 'slate-history';
|
||||
import type { BlockType } from './types';
|
||||
|
||||
export type HeadingLevel = 1 | 2 | 3;
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { BasePoint, BaseRange, Editor, Element, Point, Range, Text, Transforms } from 'slate';
|
||||
import type { BasePoint, BaseRange } from 'slate';
|
||||
import { Editor, Element, Point, Range, Text, Transforms } from 'slate';
|
||||
import { BlockType, MarkType } from './types';
|
||||
import {
|
||||
import type {
|
||||
CommandElement,
|
||||
EmoticonElement,
|
||||
FormattedText,
|
||||
@@ -63,12 +64,12 @@ export const headingLevel = (editor: Editor): HeadingLevel | undefined => {
|
||||
};
|
||||
|
||||
type BlockOption = { level: HeadingLevel };
|
||||
const NESTED_BLOCK = [
|
||||
const NESTED_BLOCK = new Set([
|
||||
BlockType.OrderedList,
|
||||
BlockType.UnorderedList,
|
||||
BlockType.BlockQuote,
|
||||
BlockType.CodeBlock,
|
||||
];
|
||||
]);
|
||||
|
||||
export const toggleBlock = (editor: Editor, format: BlockType, option?: BlockOption) => {
|
||||
Transforms.collapse(editor, {
|
||||
@@ -77,7 +78,7 @@ export const toggleBlock = (editor: Editor, format: BlockType, option?: BlockOpt
|
||||
const isActive = isBlockActive(editor, format);
|
||||
|
||||
Transforms.unwrapNodes(editor, {
|
||||
match: (node) => Element.isElement(node) && NESTED_BLOCK.includes(node.type),
|
||||
match: (node) => Element.isElement(node) && NESTED_BLOCK.has(node.type),
|
||||
split: true,
|
||||
});
|
||||
|
||||
@@ -161,7 +162,6 @@ export const resetEditor = (editor: Editor) => {
|
||||
};
|
||||
|
||||
export const resetEditorHistory = (editor: Editor) => {
|
||||
// eslint-disable-next-line no-param-reassign
|
||||
editor.history = {
|
||||
undos: [],
|
||||
redos: [],
|
||||
@@ -242,7 +242,6 @@ export const getPointUntilChar = (
|
||||
reverse: options.reverse,
|
||||
});
|
||||
|
||||
// eslint-disable-next-line no-restricted-syntax
|
||||
for (const point of pointItr) {
|
||||
if (!Point.equals(point, cursorPoint) && prevPoint) {
|
||||
char = Editor.string(editor, { anchor: point, focus: prevPoint });
|
||||
|
||||
@@ -1,39 +1,41 @@
|
||||
import {
|
||||
import type {
|
||||
ChangeEventHandler,
|
||||
FocusEventHandler,
|
||||
MouseEventHandler,
|
||||
ReactNode,
|
||||
RefObject,
|
||||
useCallback,
|
||||
useEffect,
|
||||
useMemo,
|
||||
useRef,
|
||||
} from 'react';
|
||||
import { useCallback, useEffect, useMemo, useRef } from 'react';
|
||||
import { Box, config, Icons, Scroll } from 'folds';
|
||||
import FocusTrap from 'focus-trap-react';
|
||||
import { isKeyHotkey } from 'is-hotkey';
|
||||
import { Room } from '$types/matrix-sdk';
|
||||
import { atom, PrimitiveAtom, useAtom, useSetAtom } from 'jotai';
|
||||
import type { Room } from '$types/matrix-sdk';
|
||||
import type { PrimitiveAtom } from 'jotai';
|
||||
import { atom, useAtom, useSetAtom } from 'jotai';
|
||||
import { useVirtualizer } from '@tanstack/react-virtual';
|
||||
import { IEmoji, emojiGroups, emojis } from '$plugins/emoji';
|
||||
import type { IEmoji } from '$plugins/emoji';
|
||||
import { emojiGroups, emojis } from '$plugins/emoji';
|
||||
import { preventScrollWithArrowKey, stopPropagation } from '$utils/keyboard';
|
||||
import { useRelevantImagePacks } from '$hooks/useImagePacks';
|
||||
import { useMatrixClient } from '$hooks/useMatrixClient';
|
||||
import { useRecentEmoji } from '$hooks/useRecentEmoji';
|
||||
import { isUserId, mxcUrlToHttp } from '$utils/matrix';
|
||||
import { editableActiveElement, targetFromEvent } from '$utils/dom';
|
||||
import { useAsyncSearch, UseAsyncSearchOptions } from '$hooks/useAsyncSearch';
|
||||
import type { UseAsyncSearchOptions } from '$hooks/useAsyncSearch';
|
||||
import { useAsyncSearch } from '$hooks/useAsyncSearch';
|
||||
import { useDebounce } from '$hooks/useDebounce';
|
||||
import { useThrottle } from '$hooks/useThrottle';
|
||||
import { addRecentEmoji } from '$plugins/recent-emoji';
|
||||
import { useMediaAuthentication } from '$hooks/useMediaAuthentication';
|
||||
import { ImagePack, ImageUsage, PackImageReader } from '$plugins/custom-emoji';
|
||||
import type { ImagePack, PackImageReader } from '$plugins/custom-emoji';
|
||||
import { ImageUsage } from '$plugins/custom-emoji';
|
||||
import { getEmoticonSearchStr } from '$plugins/utils';
|
||||
import { VirtualTile } from '$components/virtualizer';
|
||||
import { useSetting } from '$state/hooks/settings';
|
||||
import { settingsAtom } from '$state/settings';
|
||||
import { useEmojiGroupIcons } from './useEmojiGroupIcons';
|
||||
import { useEmojiGroupLabels } from './useEmojiGroupLabels';
|
||||
import type { PreviewData } from './components';
|
||||
import {
|
||||
SearchInput,
|
||||
EmojiBoardTabs,
|
||||
@@ -43,7 +45,6 @@ import {
|
||||
NoStickerPacks,
|
||||
createPreviewDataAtom,
|
||||
Preview,
|
||||
PreviewData,
|
||||
EmojiItem,
|
||||
StickerItem,
|
||||
CustomEmojiItem,
|
||||
@@ -97,7 +98,7 @@ const useGroups = (
|
||||
name: label ?? 'Unknown',
|
||||
items: pack
|
||||
.getImages(ImageUsage.Emoticon)
|
||||
.sort((a, b) => a.shortcode.localeCompare(b.shortcode)),
|
||||
.toSorted((a, b) => a.shortcode.localeCompare(b.shortcode)),
|
||||
});
|
||||
});
|
||||
|
||||
@@ -125,7 +126,7 @@ const useGroups = (
|
||||
name: label ?? 'Unknown',
|
||||
items: pack
|
||||
.getImages(ImageUsage.Sticker)
|
||||
.sort((a, b) => a.shortcode.localeCompare(b.shortcode)),
|
||||
.toSorted((a, b) => a.shortcode.localeCompare(b.shortcode)),
|
||||
});
|
||||
});
|
||||
|
||||
@@ -600,7 +601,7 @@ export function EmojiBoard({
|
||||
}}
|
||||
>
|
||||
{vItems.map((vItem) => {
|
||||
const group = groups[vItem.index];
|
||||
const group = groups[vItem.index]!;
|
||||
|
||||
return (
|
||||
<VirtualTile
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { as, Box, Text } from 'folds';
|
||||
import { ReactNode } from 'react';
|
||||
import type { ReactNode } from 'react';
|
||||
import classNames from 'classnames';
|
||||
import * as css from './styles.css';
|
||||
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
import { Box } from 'folds';
|
||||
import { MatrixClient } from '$types/matrix-sdk';
|
||||
import { PackImageReader } from '$plugins/custom-emoji';
|
||||
import { IEmoji } from '$plugins/emoji';
|
||||
import type { MatrixClient } from '$types/matrix-sdk';
|
||||
import type { PackImageReader } from '$plugins/custom-emoji';
|
||||
import type { IEmoji } from '$plugins/emoji';
|
||||
import { mxcUrlToHttp } from '$utils/matrix';
|
||||
import { EmojiItemInfo, EmojiType } from '$components/emoji-board/types';
|
||||
import type { EmojiItemInfo } from '$components/emoji-board/types';
|
||||
import { EmojiType } from '$components/emoji-board/types';
|
||||
import * as css from './styles.css';
|
||||
|
||||
const ANIMATED_MIME_TYPES = new Set(['image/gif', 'image/apng']);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { as, Box, Line } from 'folds';
|
||||
import { ReactNode } from 'react';
|
||||
import type { ReactNode } from 'react';
|
||||
import classNames from 'classnames';
|
||||
import * as css from './styles.css';
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { Box, Text } from 'folds';
|
||||
import { Atom, atom, useAtomValue } from 'jotai';
|
||||
import type { Atom } from 'jotai';
|
||||
import { atom, useAtomValue } from 'jotai';
|
||||
import { useMatrixClient } from '$hooks/useMatrixClient';
|
||||
import { useMediaAuthentication } from '$hooks/useMediaAuthentication';
|
||||
import { mxcUrlToHttp } from '$utils/matrix';
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { ChangeEventHandler, useRef } from 'react';
|
||||
import type { ChangeEventHandler } from 'react';
|
||||
import { useRef } from 'react';
|
||||
import { Input, Chip, Icon, Icons, Text } from 'folds';
|
||||
import { mobileOrTablet } from '$utils/user-agent';
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { ReactNode } from 'react';
|
||||
import type { ReactNode } from 'react';
|
||||
import type { IconSrc } from 'folds';
|
||||
import {
|
||||
Box,
|
||||
Scroll,
|
||||
@@ -9,7 +10,6 @@ import {
|
||||
Text,
|
||||
IconButton,
|
||||
Icon,
|
||||
IconSrc,
|
||||
Icons,
|
||||
} from 'folds';
|
||||
import classNames from 'classnames';
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { CSSProperties } from 'react';
|
||||
import type { CSSProperties } from 'react';
|
||||
import { Badge, Box, Text } from 'folds';
|
||||
import { EmojiBoardTab } from '$components/emoji-board/types';
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { useMemo } from 'react';
|
||||
import { IconSrc, Icons } from 'folds';
|
||||
import type { IconSrc } from 'folds';
|
||||
import { Icons } from 'folds';
|
||||
|
||||
import { EmojiGroupId } from '$plugins/emoji';
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ import {
|
||||
color,
|
||||
config,
|
||||
} from 'folds';
|
||||
import { IContent, MatrixEvent, Room } from '$types/matrix-sdk';
|
||||
import type { IContent, MatrixEvent, Room } from '$types/matrix-sdk';
|
||||
import { getMemberDisplayName } from '$utils/room';
|
||||
import { getMxIdLocalPart } from '$utils/matrix';
|
||||
import { useMatrixClient } from '$hooks/useMatrixClient';
|
||||
@@ -30,17 +30,18 @@ import { useSetting } from '$state/hooks/settings';
|
||||
import { settingsAtom } from '$state/settings';
|
||||
import { useCallback, useMemo, useState } from 'react';
|
||||
import { getReactCustomHtmlParser, LINKIFY_OPTS } from '$plugins/react-custom-html-parser';
|
||||
import { Opts as LinkifyOpts } from 'linkifyjs';
|
||||
import { HTMLReactParserOptions } from 'html-react-parser';
|
||||
import type { Opts as LinkifyOpts } from 'linkifyjs';
|
||||
import type { HTMLReactParserOptions } from 'html-react-parser';
|
||||
import { useSpoilerClickHandler } from '$hooks/useSpoilerClickHandler';
|
||||
import { modalAtom, ModalType } from '$state/modal';
|
||||
import { roomIdToReplyDraftAtomFamily } from '$state/room/roomInputDrafts';
|
||||
import { useRoomPermissions } from '$hooks/useRoomPermissions';
|
||||
import { useRoomCreators } from '$hooks/useRoomCreators';
|
||||
import { usePowerLevelsContext } from '$hooks/usePowerLevels';
|
||||
import { MessageEvent } from '$types/matrix/room';
|
||||
|
||||
import { useSettingsLinkBaseUrl } from '$features/settings/useSettingsLinkBaseUrl';
|
||||
import * as css from './EventHistory.css';
|
||||
import { EventType } from '$types/matrix-sdk';
|
||||
|
||||
export type EventHistoryProps = {
|
||||
room: Room;
|
||||
@@ -59,7 +60,7 @@ export const EventHistory = as<'div', EventHistoryProps>(
|
||||
const getName = (userId: string) =>
|
||||
getMemberDisplayName(room, userId, nicknames) ?? getMxIdLocalPart(userId) ?? userId;
|
||||
|
||||
const readerId = mEvents[0].event.sender ?? '';
|
||||
const readerId = mEvents[0]?.event.sender ?? '';
|
||||
const name = getName(readerId ?? '');
|
||||
const avatarMxcUrl = room.getMember(readerId ?? '')?.getMxcAvatarUrl();
|
||||
const avatarUrl = avatarMxcUrl
|
||||
@@ -73,7 +74,7 @@ export const EventHistory = as<'div', EventHistoryProps>(
|
||||
const spoilerClickHandler = useSpoilerClickHandler();
|
||||
const htmlReactParserOptions = useMemo<HTMLReactParserOptions>(
|
||||
() =>
|
||||
getReactCustomHtmlParser(mx, mEvents[0].getRoomId(), {
|
||||
getReactCustomHtmlParser(mx, mEvents[0]!.getRoomId(), {
|
||||
settingsLinkBaseUrl,
|
||||
linkifyOpts,
|
||||
useAuthentication,
|
||||
@@ -85,8 +86,8 @@ export const EventHistory = as<'div', EventHistoryProps>(
|
||||
const creators = useRoomCreators(room);
|
||||
const permissions = useRoomPermissions(creators, powerLevels);
|
||||
const canRedact = permissions.action('redact', mx.getSafeUserId());
|
||||
const canDeleteOwn = permissions.event(MessageEvent.RoomRedaction, mx.getSafeUserId());
|
||||
const canDelete = canRedact || (canDeleteOwn && mEvents[0].getSender() === mx.getUserId());
|
||||
const canDeleteOwn = permissions.event(EventType.RoomRedaction, mx.getSafeUserId());
|
||||
const canDelete = canRedact || (canDeleteOwn && mEvents[0]?.getSender() === mx.getUserId());
|
||||
|
||||
const setReplyDraft = useSetAtom(roomIdToReplyDraftAtomFamily(room.roomId));
|
||||
const triggerReply = useCallback(
|
||||
@@ -269,11 +270,16 @@ export const EventHistory = as<'div', EventHistoryProps>(
|
||||
<Scroll visibility="Hover">
|
||||
<Box className={css.Content} direction="Column">
|
||||
{mEvents.map((mEvent) => {
|
||||
if (!mEvent.event.sender) return <div />;
|
||||
if (!mEvent.event.sender) return <div key={mEvent.event.event_id} />;
|
||||
const EventContent = mEvent.getOriginalContent();
|
||||
return (
|
||||
<>
|
||||
<hr style={{ width: '100%', color: color.Surface.ContainerLine }} />
|
||||
<hr
|
||||
style={{
|
||||
width: '100%',
|
||||
color: color.Surface.ContainerLine,
|
||||
}}
|
||||
/>
|
||||
<EventItem mEvent={mEvent} EventContent={EventContent} />
|
||||
</>
|
||||
);
|
||||
|
||||
@@ -12,7 +12,7 @@ import {
|
||||
as,
|
||||
config,
|
||||
} from 'folds';
|
||||
import { Room } from '$types/matrix-sdk';
|
||||
import type { Room } from '$types/matrix-sdk';
|
||||
import { useRoomEventReaders } from '$hooks/useRoomEventReaders';
|
||||
import { getMemberDisplayName } from '$utils/room';
|
||||
import { getMxIdLocalPart } from '$utils/matrix';
|
||||
|
||||
@@ -8,12 +8,12 @@ export type ImageEditorProps = {
|
||||
requestClose: () => void;
|
||||
};
|
||||
|
||||
const handleApply = () => {
|
||||
//
|
||||
};
|
||||
|
||||
export const ImageEditor = as<'div', ImageEditorProps>(
|
||||
({ className, name, url, requestClose, ...props }, ref) => {
|
||||
const handleApply = () => {
|
||||
//
|
||||
};
|
||||
|
||||
return (
|
||||
<Box
|
||||
className={classNames(css.ImageEditor, className)}
|
||||
|
||||
Loaded 100 of 643 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user