Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 96c196015c |
30 changed files with 2383 additions and 2308 deletions
|
|
@ -1,49 +0,0 @@
|
||||||
name: Dependency builds
|
|
||||||
|
|
||||||
on:
|
|
||||||
pull_request:
|
|
||||||
|
|
||||||
env:
|
|
||||||
NIX_CONFIG: experimental-features = nix-command flakes
|
|
||||||
FORGEJO_TOKEN: ""
|
|
||||||
GITHUB_TOKEN: ""
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
web:
|
|
||||||
if: ${{ github.actor == 'renovate' }}
|
|
||||||
name: Build web
|
|
||||||
runs-on: nixos
|
|
||||||
steps:
|
|
||||||
- run: nix profile add nixpkgs#nodejs_24
|
|
||||||
- uses: https://data.forgejo.org/actions/checkout@v4
|
|
||||||
with:
|
|
||||||
persist-credentials: false
|
|
||||||
- run: nix develop .#electron --command pnpm install --frozen-lockfile
|
|
||||||
- run: nix develop .#electron --command pnpm run build:packages
|
|
||||||
- run: nix develop .#electron --command pnpm run build:web
|
|
||||||
|
|
||||||
desktop:
|
|
||||||
if: ${{ github.actor == 'renovate' }}
|
|
||||||
name: Build desktop
|
|
||||||
runs-on: nixos
|
|
||||||
steps:
|
|
||||||
- run: nix profile add nixpkgs#nodejs_24
|
|
||||||
- uses: https://data.forgejo.org/actions/checkout@v4
|
|
||||||
with:
|
|
||||||
persist-credentials: false
|
|
||||||
- run: nix develop .#electron --command pnpm install --frozen-lockfile
|
|
||||||
- run: nix develop .#electron --command pnpm run build:packages
|
|
||||||
- run: nix develop .#electron --command pnpm run build:desktop
|
|
||||||
|
|
||||||
mobile:
|
|
||||||
if: ${{ github.actor == 'renovate' }}
|
|
||||||
name: Build mobile
|
|
||||||
runs-on: nixos
|
|
||||||
steps:
|
|
||||||
- run: nix profile add nixpkgs#nodejs_24
|
|
||||||
- uses: https://data.forgejo.org/actions/checkout@v4
|
|
||||||
with:
|
|
||||||
persist-credentials: false
|
|
||||||
- run: nix develop .#tauri --command pnpm install --frozen-lockfile
|
|
||||||
- run: nix develop .#tauri --command pnpm run build:packages
|
|
||||||
- run: nix develop .#tauri --command pnpm --dir apps/tauri run build:mobile:ci
|
|
||||||
|
|
@ -28,11 +28,12 @@
|
||||||
"validate:raw": "pnpm run build && pnpm run package:linux:raw",
|
"validate:raw": "pnpm run build && pnpm run package:linux:raw",
|
||||||
"validate": "if command -v nix >/dev/null 2>&1 && [ -z \"$IN_NIX_SHELL\" ]; then nix develop ../..#electron --command pnpm run validate:raw; else pnpm run validate:raw; fi"
|
"validate": "if command -v nix >/dev/null 2>&1 && [ -z \"$IN_NIX_SHELL\" ]; then nix develop ../..#electron --command pnpm run validate:raw; else pnpm run validate:raw; fi"
|
||||||
},
|
},
|
||||||
|
"dependencies": {},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/node": "^26.1.2",
|
"@types/node": "^25.9.1",
|
||||||
"electron": "^43.3.0",
|
"electron": "^39.2.7",
|
||||||
"electron-builder": "^26.15.3",
|
"electron-builder": "^26.0.12",
|
||||||
"esbuild": "^0.28.1",
|
"esbuild": "^0.28.0",
|
||||||
"typescript": "~6.0.3"
|
"typescript": "~6.0.3"
|
||||||
},
|
},
|
||||||
"build": {
|
"build": {
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,6 @@
|
||||||
"dev:mobile:raw": "tauri android dev --host ${TAURI_DEV_HOST:-127.0.0.1}",
|
"dev:mobile:raw": "tauri android dev --host ${TAURI_DEV_HOST:-127.0.0.1}",
|
||||||
"start-adb:mobile:raw": "adb devices",
|
"start-adb:mobile:raw": "adb devices",
|
||||||
"build:mobile:raw": "tauri android build",
|
"build:mobile:raw": "tauri android build",
|
||||||
"build:mobile:ci": "node render-version.ts && trap 'node render-version.ts --unrender' EXIT && tauri android build --debug",
|
|
||||||
"dev:mobile": "if command -v nix >/dev/null 2>&1 && [ -z \"$IN_NIX_SHELL\" ]; then nix develop ../..#tauri --command pnpm run dev:mobile:raw; else pnpm run dev:mobile:raw; fi",
|
"dev:mobile": "if command -v nix >/dev/null 2>&1 && [ -z \"$IN_NIX_SHELL\" ]; then nix develop ../..#tauri --command pnpm run dev:mobile:raw; else pnpm run dev:mobile:raw; fi",
|
||||||
"start-adb:mobile": "if command -v nix >/dev/null 2>&1 && [ -z \"$IN_NIX_SHELL\" ]; then nix develop ../..#tauri --command pnpm run start-adb:mobile:raw; else pnpm run start-adb:mobile:raw; fi",
|
"start-adb:mobile": "if command -v nix >/dev/null 2>&1 && [ -z \"$IN_NIX_SHELL\" ]; then nix develop ../..#tauri --command pnpm run start-adb:mobile:raw; else pnpm run start-adb:mobile:raw; fi",
|
||||||
"build:mobile": "node render-version.ts && trap 'node render-version.ts --unrender' EXIT && if command -v nix >/dev/null 2>&1 && [ -z \"$IN_NIX_SHELL\" ]; then nix develop ../..#tauri --command pnpm run build:mobile:raw; else pnpm run build:mobile:raw; fi",
|
"build:mobile": "node render-version.ts && trap 'node render-version.ts --unrender' EXIT && if command -v nix >/dev/null 2>&1 && [ -z \"$IN_NIX_SHELL\" ]; then nix develop ../..#tauri --command pnpm run build:mobile:raw; else pnpm run build:mobile:raw; fi",
|
||||||
|
|
@ -26,16 +25,18 @@
|
||||||
"lint": "eslint src"
|
"lint": "eslint src"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@methanium/ui": "*",
|
"@tauri-apps/api": "^2",
|
||||||
"@tauri-apps/api": "^2.11.1",
|
"@tauri-apps/plugin-barcode-scanner": "~2",
|
||||||
"@tauri-apps/plugin-barcode-scanner": "~2.4.5",
|
"@tauri-apps/plugin-deep-link": "~2",
|
||||||
"@tauri-apps/plugin-deep-link": "~2.4.9",
|
"@tauri-apps/plugin-log": "~2",
|
||||||
|
"@tauri-apps/plugin-notification": "~2",
|
||||||
"@tensamin/shared": "workspace:*",
|
"@tensamin/shared": "workspace:*",
|
||||||
"react": "^19.2.8",
|
"@methanium/ui": "*",
|
||||||
"react-dom": "^19.2.8"
|
"react": "^19.2.0",
|
||||||
|
"react-dom": "^19.2.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@tauri-apps/cli": "^2.11.4",
|
"@tauri-apps/cli": "^2",
|
||||||
"@types/node": "^26.1.2"
|
"@types/node": "^25.9.1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -923,33 +923,28 @@ mod android {
|
||||||
use std::sync::OnceLock;
|
use std::sync::OnceLock;
|
||||||
|
|
||||||
use jni::{
|
use jni::{
|
||||||
jni_sig, jni_str,
|
objects::{GlobalRef, JClass, JObject, JString, JValue},
|
||||||
objects::{Global, JClass, JObject, JString, JValue},
|
JNIEnv, JavaVM,
|
||||||
Env, EnvUnowned, JavaVM,
|
|
||||||
};
|
};
|
||||||
use serde_json::Value;
|
use serde_json::Value;
|
||||||
|
|
||||||
pub struct Host {
|
pub struct Host {
|
||||||
vm: JavaVM,
|
vm: JavaVM,
|
||||||
context: Global<JObject<'static>>,
|
context: GlobalRef,
|
||||||
bridge: Global<JObject<'static>>,
|
bridge: GlobalRef,
|
||||||
}
|
}
|
||||||
|
|
||||||
static HOST: OnceLock<Host> = OnceLock::new();
|
static HOST: OnceLock<Host> = OnceLock::new();
|
||||||
|
|
||||||
pub fn attach(env: &mut Env, context: JObject) -> Result<(), String> {
|
pub fn attach(env: &mut JNIEnv, context: JObject) -> Result<(), String> {
|
||||||
if HOST.get().is_some() {
|
if HOST.get().is_some() {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
let class = env
|
let class = env
|
||||||
.find_class(jni_str!("net/tensamin/client/NativeMtpBridge"))
|
.find_class("net/tensamin/client/NativeMtpBridge")
|
||||||
.map_err(|e| e.to_string())?;
|
.map_err(|e| e.to_string())?;
|
||||||
let bridge = env
|
let bridge = env
|
||||||
.get_static_field(
|
.get_static_field(class, "INSTANCE", "Lnet/tensamin/client/NativeMtpBridge;")
|
||||||
class,
|
|
||||||
jni_str!("INSTANCE"),
|
|
||||||
jni_sig!("Lnet/tensamin/client/NativeMtpBridge;"),
|
|
||||||
)
|
|
||||||
.and_then(|value| value.l())
|
.and_then(|value| value.l())
|
||||||
.map_err(|e| e.to_string())?;
|
.map_err(|e| e.to_string())?;
|
||||||
HOST.set(Host {
|
HOST.set(Host {
|
||||||
|
|
@ -960,11 +955,15 @@ mod android {
|
||||||
.map_err(|_| "Android MTP host is already attached".to_string())
|
.map_err(|_| "Android MTP host is already attached".to_string())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn with_env<T>(call: impl FnOnce(&mut Env, &Host) -> Result<T, String>) -> Result<T, String> {
|
fn with_env<T>(
|
||||||
|
call: impl FnOnce(&mut JNIEnv, &Host) -> Result<T, String>,
|
||||||
|
) -> Result<T, String> {
|
||||||
let host = HOST.get().ok_or("Android MTP host is not attached")?;
|
let host = HOST.get().ok_or("Android MTP host is not attached")?;
|
||||||
host.vm
|
let mut env = host
|
||||||
.attach_current_thread(|env| Ok::<_, jni::errors::Error>(call(env, host)))
|
.vm
|
||||||
.map_err(|e| e.to_string())?
|
.attach_current_thread_as_daemon()
|
||||||
|
.map_err(|e| e.to_string())?;
|
||||||
|
call(&mut env, host)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn store_config(config: &str) -> Result<(), String> {
|
pub fn store_config(config: &str) -> Result<(), String> {
|
||||||
|
|
@ -972,8 +971,8 @@ mod android {
|
||||||
let value = env.new_string(config).map_err(|e| e.to_string())?;
|
let value = env.new_string(config).map_err(|e| e.to_string())?;
|
||||||
env.call_method(
|
env.call_method(
|
||||||
host.bridge.as_obj(),
|
host.bridge.as_obj(),
|
||||||
jni_str!("storeConfig"),
|
"storeConfig",
|
||||||
jni_sig!("(Landroid/content/Context;Ljava/lang/String;)V"),
|
"(Landroid/content/Context;Ljava/lang/String;)V",
|
||||||
&[
|
&[
|
||||||
JValue::Object(host.context.as_obj()),
|
JValue::Object(host.context.as_obj()),
|
||||||
JValue::Object(&value),
|
JValue::Object(&value),
|
||||||
|
|
@ -988,8 +987,8 @@ mod android {
|
||||||
with_env(|env, host| {
|
with_env(|env, host| {
|
||||||
env.call_method(
|
env.call_method(
|
||||||
host.bridge.as_obj(),
|
host.bridge.as_obj(),
|
||||||
jni_str!("hasConfig"),
|
"hasConfig",
|
||||||
jni_sig!("(Landroid/content/Context;)Z"),
|
"(Landroid/content/Context;)Z",
|
||||||
&[JValue::Object(host.context.as_obj())],
|
&[JValue::Object(host.context.as_obj())],
|
||||||
)
|
)
|
||||||
.and_then(|value| value.z())
|
.and_then(|value| value.z())
|
||||||
|
|
@ -1001,8 +1000,8 @@ mod android {
|
||||||
with_env(|env, host| {
|
with_env(|env, host| {
|
||||||
env.call_method(
|
env.call_method(
|
||||||
host.bridge.as_obj(),
|
host.bridge.as_obj(),
|
||||||
jni_str!("setServiceEnabled"),
|
"setServiceEnabled",
|
||||||
jni_sig!("(Landroid/content/Context;Z)V"),
|
"(Landroid/content/Context;Z)V",
|
||||||
&[
|
&[
|
||||||
JValue::Object(host.context.as_obj()),
|
JValue::Object(host.context.as_obj()),
|
||||||
JValue::Bool(enabled.into()),
|
JValue::Bool(enabled.into()),
|
||||||
|
|
@ -1018,8 +1017,8 @@ mod android {
|
||||||
let status = env.new_string(status).map_err(|e| e.to_string())?;
|
let status = env.new_string(status).map_err(|e| e.to_string())?;
|
||||||
env.call_method(
|
env.call_method(
|
||||||
host.bridge.as_obj(),
|
host.bridge.as_obj(),
|
||||||
jni_str!("updateServiceStatus"),
|
"updateServiceStatus",
|
||||||
jni_sig!("(Landroid/content/Context;Ljava/lang/String;)V"),
|
"(Landroid/content/Context;Ljava/lang/String;)V",
|
||||||
&[
|
&[
|
||||||
JValue::Object(host.context.as_obj()),
|
JValue::Object(host.context.as_obj()),
|
||||||
JValue::Object(&status),
|
JValue::Object(&status),
|
||||||
|
|
@ -1044,8 +1043,8 @@ mod android {
|
||||||
.map_err(|e| e.to_string())?;
|
.map_err(|e| e.to_string())?;
|
||||||
env.call_method(
|
env.call_method(
|
||||||
host.bridge.as_obj(),
|
host.bridge.as_obj(),
|
||||||
jni_str!("postMessageNotification"),
|
"postMessageNotification",
|
||||||
jni_sig!("(Landroid/content/Context;JLjava/lang/String;Ljava/lang/String;[B)V"),
|
"(Landroid/content/Context;JLjava/lang/String;Ljava/lang/String;[B)V",
|
||||||
&[
|
&[
|
||||||
JValue::Object(host.context.as_obj()),
|
JValue::Object(host.context.as_obj()),
|
||||||
JValue::Long(sender_id as i64),
|
JValue::Long(sender_id as i64),
|
||||||
|
|
@ -1063,8 +1062,8 @@ mod android {
|
||||||
with_env(|env, host| {
|
with_env(|env, host| {
|
||||||
env.call_method(
|
env.call_method(
|
||||||
host.bridge.as_obj(),
|
host.bridge.as_obj(),
|
||||||
jni_str!("cancelMessageNotification"),
|
"cancelMessageNotification",
|
||||||
jni_sig!("(Landroid/content/Context;J)V"),
|
"(Landroid/content/Context;J)V",
|
||||||
&[
|
&[
|
||||||
JValue::Object(host.context.as_obj()),
|
JValue::Object(host.context.as_obj()),
|
||||||
JValue::Long(sender_id as i64),
|
JValue::Long(sender_id as i64),
|
||||||
|
|
@ -1079,8 +1078,8 @@ mod android {
|
||||||
with_env(|env, host| {
|
with_env(|env, host| {
|
||||||
env.call_method(
|
env.call_method(
|
||||||
host.bridge.as_obj(),
|
host.bridge.as_obj(),
|
||||||
jni_str!("isIgnoringBatteryOptimizations"),
|
"isIgnoringBatteryOptimizations",
|
||||||
jni_sig!("(Landroid/content/Context;)Z"),
|
"(Landroid/content/Context;)Z",
|
||||||
&[JValue::Object(host.context.as_obj())],
|
&[JValue::Object(host.context.as_obj())],
|
||||||
)
|
)
|
||||||
.and_then(|value| value.z())
|
.and_then(|value| value.z())
|
||||||
|
|
@ -1092,8 +1091,8 @@ mod android {
|
||||||
with_env(|env, host| {
|
with_env(|env, host| {
|
||||||
env.call_method(
|
env.call_method(
|
||||||
host.bridge.as_obj(),
|
host.bridge.as_obj(),
|
||||||
jni_str!("requestBatteryExemption"),
|
"requestBatteryExemption",
|
||||||
jni_sig!("(Landroid/content/Context;)V"),
|
"(Landroid/content/Context;)V",
|
||||||
&[JValue::Object(host.context.as_obj())],
|
&[JValue::Object(host.context.as_obj())],
|
||||||
)
|
)
|
||||||
.map_err(|e| e.to_string())?;
|
.map_err(|e| e.to_string())?;
|
||||||
|
|
@ -1102,36 +1101,32 @@ mod android {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "system" fn Java_net_tensamin_client_NativeMtpBridge_nativeAttach<'caller>(
|
pub extern "system" fn Java_net_tensamin_client_NativeMtpBridge_nativeAttach(
|
||||||
mut env: EnvUnowned<'caller>,
|
mut env: JNIEnv,
|
||||||
_class: JClass,
|
_class: JClass,
|
||||||
context: JObject<'caller>,
|
context: JObject,
|
||||||
) {
|
) {
|
||||||
let _ = env.with_env(|env| {
|
let _ =
|
||||||
let _ = attach(env, context);
|
std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| attach(&mut env, context)));
|
||||||
Ok::<_, jni::errors::Error>(())
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "system" fn Java_net_tensamin_client_NativeMtpBridge_nativeStart<'caller>(
|
pub extern "system" fn Java_net_tensamin_client_NativeMtpBridge_nativeStart(
|
||||||
mut env: EnvUnowned<'caller>,
|
mut env: JNIEnv,
|
||||||
_class: JClass,
|
_class: JClass,
|
||||||
config: JString<'caller>,
|
config: JString,
|
||||||
) {
|
) {
|
||||||
let _ = env.with_env(|env| {
|
let _ = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {
|
||||||
if let Ok(config) = config.mutf8_chars(env) {
|
let config: String = env.get_string(&config).map_err(|e| e.to_string())?.into();
|
||||||
if let Ok(config) = serde_json::from_str(config.to_str().as_ref()) {
|
let config = serde_json::from_str(&config).map_err(|e| e.to_string())?;
|
||||||
super::manager().configure_and_start(config);
|
super::manager().configure_and_start(config);
|
||||||
}
|
Ok::<_, String>(())
|
||||||
}
|
}));
|
||||||
Ok::<_, jni::errors::Error>(())
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "system" fn Java_net_tensamin_client_NativeMtpBridge_nativeStop(
|
pub extern "system" fn Java_net_tensamin_client_NativeMtpBridge_nativeStop(
|
||||||
_env: EnvUnowned,
|
_env: JNIEnv,
|
||||||
_class: JClass,
|
_class: JClass,
|
||||||
) {
|
) {
|
||||||
let _ = std::panic::catch_unwind(|| super::manager().stop());
|
let _ = std::panic::catch_unwind(|| super::manager().stop());
|
||||||
|
|
@ -1139,34 +1134,31 @@ mod android {
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "system" fn Java_net_tensamin_client_NativeMtpBridge_nativeSetUiState(
|
pub extern "system" fn Java_net_tensamin_client_NativeMtpBridge_nativeSetUiState(
|
||||||
_env: EnvUnowned,
|
_env: JNIEnv,
|
||||||
_class: JClass,
|
_class: JClass,
|
||||||
visible: jni::sys::jboolean,
|
visible: jni::sys::jboolean,
|
||||||
) {
|
) {
|
||||||
super::manager().set_ui_visible(visible);
|
super::manager().set_ui_visible(visible != 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "system" fn Java_net_tensamin_client_NativeMtpBridge_nativeLog<'caller>(
|
pub extern "system" fn Java_net_tensamin_client_NativeMtpBridge_nativeLog(
|
||||||
mut env: EnvUnowned<'caller>,
|
mut env: JNIEnv,
|
||||||
_class: JClass,
|
_class: JClass,
|
||||||
level: jni::sys::jint,
|
level: jni::sys::jint,
|
||||||
message: JString<'caller>,
|
message: JString,
|
||||||
details: JString<'caller>,
|
details: JString,
|
||||||
) {
|
) {
|
||||||
let _ = env.with_env(|env| {
|
let _ = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {
|
||||||
if let (Ok(message), Ok(details)) = (message.mutf8_chars(env), details.mutf8_chars(env))
|
let message: String = env.get_string(&message).map_err(|e| e.to_string())?.into();
|
||||||
{
|
let details: String = env.get_string(&details).map_err(|e| e.to_string())?.into();
|
||||||
let message = message.to_str();
|
|
||||||
let details = details.to_str();
|
|
||||||
super::manager().log(
|
super::manager().log(
|
||||||
level.clamp(0, 3) as u8,
|
level.clamp(0, 3) as u8,
|
||||||
message.into_owned(),
|
message,
|
||||||
(!details.is_empty()).then(|| Value::String(details.into_owned())),
|
(!details.is_empty()).then(|| Value::String(details)),
|
||||||
);
|
);
|
||||||
}
|
Ok::<_, String>(())
|
||||||
Ok::<_, jni::errors::Error>(())
|
}));
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -12,51 +12,135 @@
|
||||||
"preview": "cd dist && nix-shell -p python3 --run 'python3 -m http.server 3000' && cd .."
|
"preview": "cd dist && nix-shell -p python3 --run 'python3 -m http.server 3000' && cd .."
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@fontsource-variable/public-sans": "^5.3.0",
|
"@base-ui/react": "^1.0.0",
|
||||||
"@methanium/ui": "*",
|
"@base-ui/utils": "0.3.2",
|
||||||
"@tailwindcss/vite": "^4.3.3",
|
"@babel/runtime": "^7.29.2",
|
||||||
"@tanstack/react-router": "^1.170.21",
|
"@fontsource-variable/inter": "^5.2.8",
|
||||||
"@tanstack/react-virtual": "^3.14.9",
|
"@fontsource-variable/public-sans": "^5.2.7",
|
||||||
"@tauri-apps/api": "^2.11.1",
|
"@floating-ui/core": "^1.7.0",
|
||||||
"@tensamin/cache": "workspace:*",
|
"@floating-ui/dom": "^1.7.0",
|
||||||
|
"@floating-ui/react-dom": "^2.1.8",
|
||||||
|
"@floating-ui/utils": "^0.2.11",
|
||||||
|
"@radix-ui/primitive": "^1.1.0",
|
||||||
|
"@radix-ui/react-compose-refs": "^1.1.1",
|
||||||
|
"@radix-ui/react-context": "^1.1.4",
|
||||||
|
"@radix-ui/react-dialog": "^1.1.6",
|
||||||
|
"@radix-ui/react-dismissable-layer": "^1.1.11",
|
||||||
|
"@radix-ui/react-focus-guards": "^1.1.4",
|
||||||
|
"@radix-ui/react-focus-scope": "^1.1.11",
|
||||||
|
"@radix-ui/react-id": "^1.1.0",
|
||||||
|
"@radix-ui/react-portal": "^1.1.13",
|
||||||
|
"@radix-ui/react-presence": "^1.1.6",
|
||||||
|
"@radix-ui/react-primitive": "^2.0.2",
|
||||||
|
"@radix-ui/react-slot": "^1.1.2",
|
||||||
|
"@radix-ui/react-use-callback-ref": "^1.1.1",
|
||||||
|
"@radix-ui/react-use-controllable-state": "^1.2.3",
|
||||||
|
"@radix-ui/react-use-effect-event": "^0.0.5",
|
||||||
|
"@radix-ui/react-use-layout-effect": "^1.1.0",
|
||||||
|
"@reduxjs/toolkit": "^2.0.0",
|
||||||
|
"@tailwindcss/vite": "^4.2.4",
|
||||||
|
"@tanstack/devtools-event-client": "^0.5.0",
|
||||||
|
"@tanstack/query-core": "^5.0.0",
|
||||||
|
"@tanstack/react-router": "^1.169.1",
|
||||||
|
"@tanstack/history": "1.162.0",
|
||||||
|
"@tanstack/react-store": "^0.11.0",
|
||||||
|
"@tanstack/router-core": "^1.169.1",
|
||||||
|
"@tanstack/store": "^0.11.0",
|
||||||
|
"@tanstack/virtual-core": "^3.13.24",
|
||||||
|
"@tanstack/react-virtual": "^3.13.24",
|
||||||
|
"@tauri-apps/api": "^2",
|
||||||
"@tensamin/call": "workspace:*",
|
"@tensamin/call": "workspace:*",
|
||||||
|
"@tensamin/cache": "workspace:*",
|
||||||
"@tensamin/chat": "workspace:*",
|
"@tensamin/chat": "workspace:*",
|
||||||
"@tensamin/crypto": "workspace:*",
|
"@tensamin/crypto": "workspace:*",
|
||||||
"@tensamin/hotkeys": "workspace:*",
|
"@tensamin/hotkeys": "workspace:*",
|
||||||
"@tensamin/markdown": "workspace:*",
|
|
||||||
"@tensamin/mtp": "workspace:*",
|
|
||||||
"@tensamin/notifications": "workspace:*",
|
|
||||||
"@tensamin/onboarding": "workspace:*",
|
|
||||||
"@tensamin/settings": "workspace:*",
|
|
||||||
"@tensamin/shared": "workspace:*",
|
"@tensamin/shared": "workspace:*",
|
||||||
|
"@tensamin/settings": "workspace:*",
|
||||||
"@tensamin/storage": "workspace:*",
|
"@tensamin/storage": "workspace:*",
|
||||||
"@tensamin/tauri": "workspace:*",
|
"@tensamin/tauri": "workspace:*",
|
||||||
|
"@tensamin/mtp": "workspace:*",
|
||||||
"@tensamin/tauth": "workspace:*",
|
"@tensamin/tauth": "workspace:*",
|
||||||
|
"@tensamin/markdown": "workspace:*",
|
||||||
|
"@methanium/ui": "*",
|
||||||
"@tensamin/user": "workspace:*",
|
"@tensamin/user": "workspace:*",
|
||||||
|
"@tensamin/notifications": "workspace:*",
|
||||||
|
"@tensamin/onboarding": "workspace:*",
|
||||||
|
"aria-hidden": "^1.2.4",
|
||||||
|
"class-variance-authority": "^0.7.1",
|
||||||
|
"clsx": "^2.1.1",
|
||||||
|
"cmdk": "^1.1.1",
|
||||||
|
"cookie-es": "^3.0.0",
|
||||||
|
"d3-array": "^3.1.6",
|
||||||
|
"d3-color": "^3.1.0",
|
||||||
|
"d3-ease": "^3.0.1",
|
||||||
|
"d3-format": "^3.1.0",
|
||||||
|
"d3-interpolate": "^3.0.1",
|
||||||
|
"d3-path": "^3.0.1",
|
||||||
|
"d3-scale": "^4.0.2",
|
||||||
|
"d3-shape": "^3.1.0",
|
||||||
|
"d3-time": "^3.0.0",
|
||||||
|
"d3-time-format": "^4.1.0",
|
||||||
|
"d3-timer": "^3.0.1",
|
||||||
|
"date-fns": "^4.4.0",
|
||||||
"decimal.js-light": "^2.5.1",
|
"decimal.js-light": "^2.5.1",
|
||||||
"eventemitter3": "^5.0.4",
|
"detect-node-es": "^1.1.0",
|
||||||
"lucide-react": "^1.29.0",
|
"dijkstrajs": "^1.0.1",
|
||||||
"react": "^19.2.8",
|
"embla-carousel": "8.6.0",
|
||||||
"react-dom": "^19.2.8",
|
"embla-carousel-react": "^8.6.0",
|
||||||
"react-is": "^19.2.8",
|
"embla-carousel-reactive-utils": "8.6.0",
|
||||||
"react-redux": "^9.3.0",
|
"es-toolkit": "^1.39.3",
|
||||||
"tailwind-scrollbar-hide": "^4.0.0",
|
"eventemitter3": "^5.0.1",
|
||||||
"tailwindcss": "^4.3.3",
|
"get-nonce": "^1.0.1",
|
||||||
|
"immer": "^10.1.1",
|
||||||
|
"input-otp": "^1.4.2",
|
||||||
|
"internmap": "^2.0.3",
|
||||||
"tw-animate-css": "^1.4.0",
|
"tw-animate-css": "^1.4.0",
|
||||||
"use-sync-external-store": "^1.6.0",
|
"lucide-react": "^1.14.0",
|
||||||
"zod": "^4.4.3"
|
"next-themes": "^0.4.6",
|
||||||
|
"pngjs": "^5.0.0",
|
||||||
|
"qrcode": "^1.5.4",
|
||||||
|
"react": "^19.2.0",
|
||||||
|
"react-day-picker": "^10.0.1",
|
||||||
|
"react-dom": "^19.2.0",
|
||||||
|
"react-is": "^19.0.0",
|
||||||
|
"react-redux": "^9.0.0",
|
||||||
|
"react-remove-scroll": "^2.7.2",
|
||||||
|
"react-remove-scroll-bar": "^2.3.7",
|
||||||
|
"react-resizable-panels": "^4.11.2",
|
||||||
|
"react-style-singleton": "^2.2.3",
|
||||||
|
"recharts": "3.10.1",
|
||||||
|
"redux": "^5.0.0",
|
||||||
|
"redux-thunk": "^3.1.0",
|
||||||
|
"reselect": "5.2.0",
|
||||||
|
"scheduler": "^0.27.0",
|
||||||
|
"seroval": "^1.5.4",
|
||||||
|
"seroval-plugins": "^1.5.4",
|
||||||
|
"shadcn": "^4.11.0",
|
||||||
|
"sonner": "^2.0.7",
|
||||||
|
"tailwindcss": "^4.2.4",
|
||||||
|
"tailwind-merge": "^3.6.0",
|
||||||
|
"tailwind-scrollbar-hide": "^4.0.0",
|
||||||
|
"tiny-invariant": "^1.3.3",
|
||||||
|
"tslib": "^2.8.1",
|
||||||
|
"use-callback-ref": "^1.3.3",
|
||||||
|
"use-sidecar": "^1.1.3",
|
||||||
|
"use-sync-external-store": "^1.2.2",
|
||||||
|
"vaul": "^1.1.2",
|
||||||
|
"victory-vendor": "^37.0.2",
|
||||||
|
"yargs": "^15.3.1",
|
||||||
|
"zod": "^4.3.6"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@eslint/js": "^10.0.1",
|
"@eslint/js": "^10.0.1",
|
||||||
"@types/qrcode": "^1.5.6",
|
"@types/qrcode": "^1.5.6",
|
||||||
"@types/react": "^19.2.18",
|
"@types/react": "^19.2.2",
|
||||||
"@types/react-dom": "^19.2.4",
|
"@types/react-dom": "^19.2.2",
|
||||||
"@vitejs/plugin-react": "^6.0.5",
|
"@vitejs/plugin-react": "^6.0.1",
|
||||||
"esbuild": "^0.28.1",
|
"esbuild": "^0.28.0",
|
||||||
"eslint": "^10.8.0",
|
"eslint": "^10.0.3",
|
||||||
"globals": "^17.9.0",
|
"globals": "^17.4.0",
|
||||||
"typescript": "~6.0.3",
|
"typescript": "~6.0.3",
|
||||||
"typescript-eslint": "^8.66.0",
|
"typescript-eslint": "^8.57.0",
|
||||||
"vite": "^8.2.1"
|
"vite": "^8.0.10"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -36,19 +36,23 @@ import { useShowMobileNavbar } from "@/routes/app/useShowMobileNavbar";
|
||||||
import { Ellipsis, Check } from "lucide-react";
|
import { Ellipsis, Check } from "lucide-react";
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import type { User } from "@tensamin/user/context";
|
import type { User } from "@tensamin/user/context";
|
||||||
import { mtp, userPresencePreferenceSchema } from "@tensamin/shared/data";
|
import type z from "zod";
|
||||||
|
import { mtp } from "@tensamin/shared/data";
|
||||||
import { useMTP } from "@tensamin/mtp";
|
import { useMTP } from "@tensamin/mtp";
|
||||||
import {
|
|
||||||
onlineStatusLabels,
|
|
||||||
onlineStatusOptions,
|
|
||||||
type OnlineStatus,
|
|
||||||
} from "./status-options";
|
|
||||||
|
|
||||||
function accountPreference(status: User["OnlineStatus"]): OnlineStatus {
|
type OnlineStatus = z.infer<typeof mtp.GetUserData.response.shape.OnlineStatus>;
|
||||||
return userPresencePreferenceSchema.safeParse(status).success
|
|
||||||
? (status as OnlineStatus)
|
const onlineStatusLabels: Record<OnlineStatus, string> = {
|
||||||
: "user_online";
|
user_online: "Online",
|
||||||
}
|
user_offline: "Offline",
|
||||||
|
user_dnd: "Do not disturb",
|
||||||
|
user_idle: "Idle",
|
||||||
|
user_wc: "Away",
|
||||||
|
user_borked: "Borked",
|
||||||
|
iota_offline: "Iota offline",
|
||||||
|
iota_online: "Iota online",
|
||||||
|
iota_borked: "Iota borked",
|
||||||
|
};
|
||||||
|
|
||||||
function StatusDialog({
|
function StatusDialog({
|
||||||
user,
|
user,
|
||||||
|
|
@ -83,7 +87,7 @@ function StatusDialog({
|
||||||
onOpenChange={(nextOpen) => {
|
onOpenChange={(nextOpen) => {
|
||||||
if (!nextOpen) {
|
if (!nextOpen) {
|
||||||
setDraftStatus(user.Status ?? "");
|
setDraftStatus(user.Status ?? "");
|
||||||
setDraftOnlineStatus(accountPreference(user.OnlineStatus));
|
setDraftOnlineStatus(user.OnlineStatus);
|
||||||
setErrorMessage("");
|
setErrorMessage("");
|
||||||
setSaveSucceeded(false);
|
setSaveSucceeded(false);
|
||||||
}
|
}
|
||||||
|
|
@ -122,11 +126,10 @@ function StatusDialog({
|
||||||
</SelectValue>
|
</SelectValue>
|
||||||
</SelectTrigger>
|
</SelectTrigger>
|
||||||
<SelectContent className="p-1">
|
<SelectContent className="p-1">
|
||||||
{onlineStatusOptions.map((option) => (
|
<SelectItem value="user_online">Online</SelectItem>
|
||||||
<SelectItem key={option.value} value={option.value}>
|
<SelectItem value="user_offline">Offline</SelectItem>
|
||||||
{option.label}
|
<SelectItem value="user_idle">Idle</SelectItem>
|
||||||
</SelectItem>
|
<SelectItem value="user_dnd">Do not disturb</SelectItem>
|
||||||
))}
|
|
||||||
</SelectContent>
|
</SelectContent>
|
||||||
</Select>
|
</Select>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -137,9 +140,12 @@ function StatusDialog({
|
||||||
<DialogClose render={<Button variant="destructive">Cancel</Button>} />
|
<DialogClose render={<Button variant="destructive">Cancel</Button>} />
|
||||||
<Button
|
<Button
|
||||||
onClick={async () => {
|
onClick={async () => {
|
||||||
const payload = { UserState: draftOnlineStatus };
|
const payload = {
|
||||||
|
...(draftStatus && { status: draftStatus }),
|
||||||
|
OnlineStatus: draftOnlineStatus,
|
||||||
|
};
|
||||||
|
|
||||||
const validation = mtp.SetUserState.request.safeParse(payload);
|
const validation = mtp.ChangeUserData.request.safeParse(payload);
|
||||||
|
|
||||||
if (!validation.success) {
|
if (!validation.success) {
|
||||||
setSaveSucceeded(false);
|
setSaveSucceeded(false);
|
||||||
|
|
@ -150,17 +156,7 @@ function StatusDialog({
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await send("SetUserState", validation.data);
|
await send("ChangeUserData", validation.data);
|
||||||
const profileValidation = mtp.ChangeUserData.request.safeParse({
|
|
||||||
Status: draftStatus,
|
|
||||||
});
|
|
||||||
if (!profileValidation.success) {
|
|
||||||
throw new Error(
|
|
||||||
profileValidation.error.issues[0]?.message ??
|
|
||||||
"Invalid status data",
|
|
||||||
);
|
|
||||||
}
|
|
||||||
await send("ChangeUserData", profileValidation.data);
|
|
||||||
setSaveSucceeded(true);
|
setSaveSucceeded(true);
|
||||||
setErrorMessage("");
|
setErrorMessage("");
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|
@ -231,9 +227,7 @@ export default function Sidebar() {
|
||||||
<DropdownMenuItem
|
<DropdownMenuItem
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
setDraftStatus(user.Status ?? "");
|
setDraftStatus(user.Status ?? "");
|
||||||
setDraftOnlineStatus(
|
setDraftOnlineStatus(user.OnlineStatus);
|
||||||
accountPreference(user.OnlineStatus),
|
|
||||||
);
|
|
||||||
setStatusErrorMessage("");
|
setStatusErrorMessage("");
|
||||||
setStatusSaveSucceeded(false);
|
setStatusSaveSucceeded(false);
|
||||||
setDialogOpen(true);
|
setDialogOpen(true);
|
||||||
|
|
@ -252,9 +246,7 @@ export default function Sidebar() {
|
||||||
onOpenChange={(nextOpen) => {
|
onOpenChange={(nextOpen) => {
|
||||||
if (!nextOpen) {
|
if (!nextOpen) {
|
||||||
setDraftStatus(user.Status ?? "");
|
setDraftStatus(user.Status ?? "");
|
||||||
setDraftOnlineStatus(
|
setDraftOnlineStatus(user.OnlineStatus);
|
||||||
accountPreference(user.OnlineStatus),
|
|
||||||
);
|
|
||||||
setStatusErrorMessage("");
|
setStatusErrorMessage("");
|
||||||
setStatusSaveSucceeded(false);
|
setStatusSaveSucceeded(false);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,13 +0,0 @@
|
||||||
export const onlineStatusOptions = [
|
|
||||||
{ label: "Online", value: "user_online" },
|
|
||||||
{ label: "Idle", value: "user_idle" },
|
|
||||||
{ label: "Do not disturb", value: "user_dnd" },
|
|
||||||
{ label: "Away", value: "user_wc" },
|
|
||||||
{ label: "Offline", value: "user_invisible" },
|
|
||||||
] as const;
|
|
||||||
|
|
||||||
export type OnlineStatus = (typeof onlineStatusOptions)[number]["value"];
|
|
||||||
|
|
||||||
export const onlineStatusLabels = Object.fromEntries(
|
|
||||||
onlineStatusOptions.map((option) => [option.value, option.label]),
|
|
||||||
) as Record<OnlineStatus, string>;
|
|
||||||
|
|
@ -1 +1 @@
|
||||||
Subproject commit 486541b9483356ff49ff3ec7016f87d3ecbeaa0e
|
Subproject commit 11a1d79409857b734e948dd8c3e28e6ba721d15f
|
||||||
24
package.json
24
package.json
|
|
@ -29,21 +29,23 @@
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@eslint/js": "^10.0.1",
|
"@eslint/js": "^10.0.1",
|
||||||
"@types/node": "^26.1.2",
|
"@types/node": "^26.1.0",
|
||||||
"@types/react": "^19.2.18",
|
"@types/react": "^19.2.14",
|
||||||
"@types/react-dom": "^19.2.4",
|
"@types/react-dom": "^19.2.3",
|
||||||
"@typescript-eslint/parser": "^8.66.0",
|
"@typescript-eslint/parser": "^8.59.1",
|
||||||
"eslint": "^10.8.0",
|
"eslint": "^10.2.1",
|
||||||
"eslint-plugin-react-hooks": "^7.1.1",
|
"eslint-plugin-react-hooks": "^7.1.1",
|
||||||
"fallow": "^3.14.0",
|
"fallow": "^2.86.0",
|
||||||
"globals": "^17.9.0",
|
"globals": "^17.5.0",
|
||||||
"prettier": "^3.9.6",
|
"jsonc-parser": "^3.3.1",
|
||||||
|
"prettier": "^3.8.3",
|
||||||
"typescript": "^6.0.3",
|
"typescript": "^6.0.3",
|
||||||
"typescript-eslint": "^8.66.0",
|
"typescript-eslint": "^8.59.1",
|
||||||
"vitest": "^4.1.10"
|
"vitest": "^4.0.8",
|
||||||
|
"yaml": "^2.8.2"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@methanium/ui": "*",
|
"@methanium/ui": "https://git.methanium.net/methanium/ui/releases/download/0.0.2/methanium-ui.tgz",
|
||||||
"mtp": "*",
|
"mtp": "*",
|
||||||
"sonner": "^2.0.7"
|
"sonner": "^2.0.7"
|
||||||
}
|
}
|
||||||
|
|
|
||||||
4
packages/cache/package.json
vendored
4
packages/cache/package.json
vendored
|
|
@ -19,7 +19,7 @@
|
||||||
"@tensamin/mtp": "workspace:*",
|
"@tensamin/mtp": "workspace:*",
|
||||||
"@tensamin/shared": "workspace:*",
|
"@tensamin/shared": "workspace:*",
|
||||||
"@tensamin/storage": "workspace:*",
|
"@tensamin/storage": "workspace:*",
|
||||||
"react": "^19.2.8",
|
"react": "^19.2.0",
|
||||||
"zod": "^4.4.3"
|
"zod": "^4.3.6"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
57
packages/cache/src/sync.tsx
vendored
57
packages/cache/src/sync.tsx
vendored
|
|
@ -12,14 +12,6 @@ function isError(message: ProtocolMessage) {
|
||||||
return message.type.startsWith("Error");
|
return message.type.startsWith("Error");
|
||||||
}
|
}
|
||||||
|
|
||||||
export function removeMissingContactSnapshots<T extends { UserId: number }>(
|
|
||||||
contacts: T[],
|
|
||||||
missingUserIds: readonly number[],
|
|
||||||
): T[] {
|
|
||||||
const missing = new Set(missingUserIds);
|
|
||||||
return contacts.filter((contact) => !missing.has(contact.UserId));
|
|
||||||
}
|
|
||||||
|
|
||||||
export default function CacheSync() {
|
export default function CacheSync() {
|
||||||
const { addInterceptor, contextReady, freshContacts, subscribePush } =
|
const { addInterceptor, contextReady, freshContacts, subscribePush } =
|
||||||
useMTP();
|
useMTP();
|
||||||
|
|
@ -45,20 +37,6 @@ export default function CacheSync() {
|
||||||
[accountId],
|
[accountId],
|
||||||
);
|
);
|
||||||
|
|
||||||
const removeMissingContacts = useCallback(
|
|
||||||
async (userIds: number[]) => {
|
|
||||||
if (userIds.length === 0) return;
|
|
||||||
const cache = secureCache();
|
|
||||||
const contacts = await cache.contacts.get();
|
|
||||||
if (!contacts) return;
|
|
||||||
const remaining = removeMissingContactSnapshots(contacts, userIds);
|
|
||||||
if (remaining.length === contacts.length) return;
|
|
||||||
await cache.contacts.replace(remaining);
|
|
||||||
await cache.conversations.replaceSelected(remaining);
|
|
||||||
},
|
|
||||||
[secureCache],
|
|
||||||
);
|
|
||||||
|
|
||||||
const replaceMessage = useCallback(
|
const replaceMessage = useCallback(
|
||||||
async (
|
async (
|
||||||
partnerId: number,
|
partnerId: number,
|
||||||
|
|
@ -132,15 +110,6 @@ export default function CacheSync() {
|
||||||
const request = (data ?? {}) as Record<string, unknown>;
|
const request = (data ?? {}) as Record<string, unknown>;
|
||||||
const result = response.data as Record<string, unknown>;
|
const result = response.data as Record<string, unknown>;
|
||||||
|
|
||||||
if (type === "GetStates" && Array.isArray(result.MissingUserIds)) {
|
|
||||||
await removeMissingContacts(
|
|
||||||
result.MissingUserIds.filter(
|
|
||||||
(userId): userId is number => typeof userId === "number",
|
|
||||||
),
|
|
||||||
);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (type === "GetUserData") {
|
if (type === "GetUserData") {
|
||||||
await createCache(String(accountId)).profiles.put(
|
await createCache(String(accountId)).profiles.put(
|
||||||
result as unknown as UserProfile,
|
result as unknown as UserProfile,
|
||||||
|
|
@ -227,14 +196,7 @@ export default function CacheSync() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[
|
[accountId, insertMessage, removeMessage, replaceMessage, secureCache],
|
||||||
accountId,
|
|
||||||
insertMessage,
|
|
||||||
removeMissingContacts,
|
|
||||||
removeMessage,
|
|
||||||
replaceMessage,
|
|
||||||
secureCache,
|
|
||||||
],
|
|
||||||
);
|
);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|
@ -248,14 +210,6 @@ export default function CacheSync() {
|
||||||
async (message: ProtocolMessage) => {
|
async (message: ProtocolMessage) => {
|
||||||
if (!accountId || isError(message)) return;
|
if (!accountId || isError(message)) return;
|
||||||
const data = message.data as Record<string, unknown>;
|
const data = message.data as Record<string, unknown>;
|
||||||
if (message.type === "GetStates" && Array.isArray(data.MissingUserIds)) {
|
|
||||||
await removeMissingContacts(
|
|
||||||
data.MissingUserIds.filter(
|
|
||||||
(userId): userId is number => typeof userId === "number",
|
|
||||||
),
|
|
||||||
);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (message.type === "MessageLive") {
|
if (message.type === "MessageLive") {
|
||||||
await insertMessage(
|
await insertMessage(
|
||||||
Number(data.SenderId),
|
Number(data.SenderId),
|
||||||
|
|
@ -309,14 +263,7 @@ export default function CacheSync() {
|
||||||
await replaceMessage(partnerId, sendTime, { Reactions: reactions });
|
await replaceMessage(partnerId, sendTime, { Reactions: reactions });
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[
|
[accountId, insertMessage, removeMessage, replaceMessage, secureCache],
|
||||||
accountId,
|
|
||||||
insertMessage,
|
|
||||||
removeMessage,
|
|
||||||
removeMissingContacts,
|
|
||||||
replaceMessage,
|
|
||||||
secureCache,
|
|
||||||
],
|
|
||||||
);
|
);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|
|
||||||
|
|
@ -17,21 +17,21 @@
|
||||||
"build": "tsc -p tsconfig.json --noEmit"
|
"build": "tsc -p tsconfig.json --noEmit"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@livekit/components-react": "^2.9.23",
|
"@livekit/components-react": "^2.9.20",
|
||||||
"@methanium/ui": "*",
|
"@tanstack/react-router": "^1.169.1",
|
||||||
"@tanstack/react-router": "^1.170.21",
|
|
||||||
"@tensamin/crypto": "workspace:*",
|
"@tensamin/crypto": "workspace:*",
|
||||||
"@tensamin/mtp": "workspace:*",
|
|
||||||
"@tensamin/shared": "workspace:*",
|
"@tensamin/shared": "workspace:*",
|
||||||
"@tensamin/storage": "workspace:*",
|
"@tensamin/storage": "workspace:*",
|
||||||
|
"@tensamin/mtp": "workspace:*",
|
||||||
|
"@methanium/ui": "*",
|
||||||
"@tensamin/user": "workspace:*",
|
"@tensamin/user": "workspace:*",
|
||||||
"deepfilternet3-noise-filter": "1.3.0",
|
"deepfilternet3-noise-filter": "1.3.0",
|
||||||
"livekit-client": "^2.21.0",
|
"livekit-client": "^2.18.8",
|
||||||
"lucide-react": "^1.29.0",
|
"lucide-react": "^1.14.0",
|
||||||
"react": "^19.2.8",
|
"react": "^19.2.0",
|
||||||
"react-dom": "^19.2.8",
|
"react-dom": "^19.2.0",
|
||||||
"recharts": "^3.10.1",
|
"recharts": "^3.8.1",
|
||||||
"zod": "^4.4.3",
|
"zod": "^4.3.6",
|
||||||
"zustand": "^5.0.14"
|
"zustand": "^5.0.8"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,23 +16,23 @@
|
||||||
"build": "tsc -p tsconfig.json --noEmit"
|
"build": "tsc -p tsconfig.json --noEmit"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@methanium/ui": "*",
|
|
||||||
"@tanstack/pacer": "^0.21.1",
|
|
||||||
"@tanstack/react-query": "^5.101.4",
|
|
||||||
"@tanstack/react-router": "^1.170.21",
|
|
||||||
"@tanstack/react-virtual": "^3.14.9",
|
|
||||||
"@tensamin/cache": "workspace:*",
|
"@tensamin/cache": "workspace:*",
|
||||||
|
"@tanstack/pacer": "^0.21.1",
|
||||||
|
"@tanstack/react-query": "^5.0.0",
|
||||||
|
"@tanstack/react-router": "^1.0.0",
|
||||||
|
"@tanstack/react-virtual": "^3.0.0",
|
||||||
"@tensamin/crypto": "workspace:*",
|
"@tensamin/crypto": "workspace:*",
|
||||||
"@tensamin/hotkeys": "workspace:*",
|
"@tensamin/hotkeys": "workspace:*",
|
||||||
"@tensamin/markdown": "workspace:*",
|
"@tensamin/markdown": "workspace:*",
|
||||||
"@tensamin/mtp": "workspace:*",
|
"@tensamin/mtp": "workspace:*",
|
||||||
"@tensamin/shared": "workspace:*",
|
"@tensamin/shared": "workspace:*",
|
||||||
"@tensamin/storage": "workspace:*",
|
"@tensamin/storage": "workspace:*",
|
||||||
|
"@methanium/ui": "*",
|
||||||
"@tensamin/user": "workspace:*",
|
"@tensamin/user": "workspace:*",
|
||||||
"lucide-react": "^1.29.0",
|
"lucide-react": "^1.14.0",
|
||||||
"motion": "^13.0.0",
|
"motion": "^12.42.2",
|
||||||
"react": "^19.2.8",
|
"react": "^19.2.0",
|
||||||
"react-dom": "^19.2.8",
|
"react-dom": "^19.2.0",
|
||||||
"zod": "^4.4.3"
|
"zod": "^4.3.6"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@
|
||||||
"build": "pnpm run test && tsc -p tsconfig.json --noEmit"
|
"build": "pnpm run test && tsc -p tsconfig.json --noEmit"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"react": "^19.2.8",
|
"react": "^19.2.0",
|
||||||
"react-dom": "^19.2.8"
|
"react-dom": "^19.2.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,10 +15,10 @@
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@tanstack/react-hotkeys": "^0.10.0",
|
"@tanstack/react-hotkeys": "^0.10.0",
|
||||||
"@tensamin/storage": "workspace:*",
|
"@tensamin/storage": "workspace:*",
|
||||||
"react": "^19.2.8",
|
"react": "^19.2.0",
|
||||||
"react-dom": "^19.2.8"
|
"react-dom": "^19.2.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"vite": "^8.2.1"
|
"vite": "^8.0.10"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,15 +15,15 @@
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@codemirror/autocomplete": "^6.20.3",
|
"@codemirror/autocomplete": "^6.20.3",
|
||||||
"@codemirror/commands": "^6.10.4",
|
"@codemirror/commands": "^6.10.2",
|
||||||
"@codemirror/lang-markdown": "^6.5.2",
|
"@codemirror/lang-markdown": "^6.5.0",
|
||||||
"@codemirror/language": "^6.12.4",
|
"@codemirror/language": "^6.12.4",
|
||||||
"@codemirror/state": "^6.7.1",
|
"@codemirror/state": "^6.5.4",
|
||||||
"@codemirror/view": "^6.43.8",
|
"@codemirror/view": "^6.41.1",
|
||||||
"@methanium/ui": "*",
|
"@methanium/ui": "*",
|
||||||
"@twemoji/api": "^17.0.3",
|
"@twemoji/api": "^17.0.3",
|
||||||
"emojibase-data": "^17.0.0",
|
"emojibase-data": "^17.0.0",
|
||||||
"react": "^19.2.8",
|
"react": "^19.2.0",
|
||||||
"react-dom": "^19.2.8"
|
"react-dom": "^19.2.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,17 +12,18 @@
|
||||||
"build": "tsc -p tsconfig.json --noEmit"
|
"build": "tsc -p tsconfig.json --noEmit"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@methanium/ui": "*",
|
"@tauri-apps/api": "^2",
|
||||||
"@tauri-apps/api": "^2.11.1",
|
|
||||||
"@tensamin/crypto": "workspace:*",
|
"@tensamin/crypto": "workspace:*",
|
||||||
"@tensamin/shared": "workspace:*",
|
"@tensamin/shared": "workspace:*",
|
||||||
"@tensamin/storage": "workspace:*",
|
"@tensamin/storage": "workspace:*",
|
||||||
|
"@methanium/ui": "*",
|
||||||
|
"lucide-react": "^1.14.0",
|
||||||
"mtp": "*",
|
"mtp": "*",
|
||||||
"react": "^19.2.8",
|
"react": "^19.2.0",
|
||||||
"react-dom": "^19.2.8",
|
"react-dom": "^19.2.0",
|
||||||
"zod": "^4.4.3"
|
"zod": "^4.4.2"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"eslint": "^10.8.0"
|
"eslint": "^10.0.3"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,21 +0,0 @@
|
||||||
import { describe, expect, it } from "vitest";
|
|
||||||
|
|
||||||
import { isPushType, validateResponse } from "./context";
|
|
||||||
|
|
||||||
describe("MTP protocol dispatch", () => {
|
|
||||||
it("preserves protocol errors for the request layer", () => {
|
|
||||||
const error = validateResponse("GetStates", {
|
|
||||||
id: 12,
|
|
||||||
type: "ErrorInternal",
|
|
||||||
data: { ErrorType: "temporary" },
|
|
||||||
});
|
|
||||||
expect(error.type).toBe("ErrorInternal");
|
|
||||||
expect(error.id).toBe(12);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("recognizes initial and live presence pushes", () => {
|
|
||||||
expect(isPushType("GetStates")).toBe(true);
|
|
||||||
expect(isPushType("ClientChanged")).toBe(true);
|
|
||||||
expect(isPushType("UnknownMessage")).toBe(false);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
@ -24,7 +24,6 @@ import {
|
||||||
type MTP as Schemas,
|
type MTP as Schemas,
|
||||||
} from "@tensamin/shared/data";
|
} from "@tensamin/shared/data";
|
||||||
import { log } from "@tensamin/shared/log";
|
import { log } from "@tensamin/shared/log";
|
||||||
import { ProtocolError } from "@tensamin/shared/errors";
|
|
||||||
import { useStorage } from "@tensamin/storage/context";
|
import { useStorage } from "@tensamin/storage/context";
|
||||||
|
|
||||||
import { RECONNECT_RESET, RECONNECT_TRIES, RETRY_INTERVAL } from "./values";
|
import { RECONNECT_RESET, RECONNECT_TRIES, RETRY_INTERVAL } from "./values";
|
||||||
|
|
@ -63,30 +62,9 @@ const PUSH_TYPES = [
|
||||||
"MessageDeleteLive",
|
"MessageDeleteLive",
|
||||||
"MessageState",
|
"MessageState",
|
||||||
"CallInvite",
|
"CallInvite",
|
||||||
"GetStates",
|
|
||||||
"ClientChanged",
|
|
||||||
"ErrorNoIota",
|
"ErrorNoIota",
|
||||||
] as const;
|
] as const;
|
||||||
|
|
||||||
export function isPushType(type: string): boolean {
|
|
||||||
return (PUSH_TYPES as readonly string[]).includes(type);
|
|
||||||
}
|
|
||||||
|
|
||||||
function removeMissingContacts(
|
|
||||||
contacts: Contacts,
|
|
||||||
message: ProtocolMessage,
|
|
||||||
): Contacts {
|
|
||||||
if (message.type !== "GetStates") return contacts;
|
|
||||||
const data = message.data as { MissingUserIds?: unknown };
|
|
||||||
if (!Array.isArray(data.MissingUserIds)) return contacts;
|
|
||||||
const missing = new Set(
|
|
||||||
data.MissingUserIds.filter(
|
|
||||||
(userId): userId is number => typeof userId === "number",
|
|
||||||
),
|
|
||||||
);
|
|
||||||
return contacts.filter((contact) => !missing.has(contact.UserId));
|
|
||||||
}
|
|
||||||
|
|
||||||
export type MTPExchange = {
|
export type MTPExchange = {
|
||||||
type: keyof Schemas & string;
|
type: keyof Schemas & string;
|
||||||
data: unknown;
|
data: unknown;
|
||||||
|
|
@ -132,7 +110,7 @@ function getProtocolErrorDetails(error: unknown) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Zod schema validation
|
// Zod schema validation
|
||||||
export function validateResponse<T extends keyof Schemas & string>(
|
function validateResponse<T extends keyof Schemas & string>(
|
||||||
type: T,
|
type: T,
|
||||||
message: { id?: number; type: string; data: unknown },
|
message: { id?: number; type: string; data: unknown },
|
||||||
): ProtocolMessage<T> {
|
): ProtocolMessage<T> {
|
||||||
|
|
@ -164,26 +142,15 @@ export function validateResponse<T extends keyof Schemas & string>(
|
||||||
function useMessageHandlers() {
|
function useMessageHandlers() {
|
||||||
const interceptorsRef = useRef(new Set<MTPInterceptor>());
|
const interceptorsRef = useRef(new Set<MTPInterceptor>());
|
||||||
const pushHandlersRef = useRef(new Set<PushHandler>());
|
const pushHandlersRef = useRef(new Set<PushHandler>());
|
||||||
const lastInitialStateRef = useRef<ProtocolMessage | null>(null);
|
|
||||||
const subscribePush = useCallback((handler: PushHandler) => {
|
const subscribePush = useCallback((handler: PushHandler) => {
|
||||||
pushHandlersRef.current.add(handler);
|
pushHandlersRef.current.add(handler);
|
||||||
const initialState = lastInitialStateRef.current;
|
|
||||||
if (initialState?.type === "GetStates") {
|
|
||||||
void Promise.resolve(handler(initialState)).catch(() => undefined);
|
|
||||||
}
|
|
||||||
return () => pushHandlersRef.current.delete(handler);
|
return () => pushHandlersRef.current.delete(handler);
|
||||||
}, []);
|
}, []);
|
||||||
const addInterceptor = useCallback((interceptor: MTPInterceptor) => {
|
const addInterceptor = useCallback((interceptor: MTPInterceptor) => {
|
||||||
interceptorsRef.current.add(interceptor);
|
interceptorsRef.current.add(interceptor);
|
||||||
return () => interceptorsRef.current.delete(interceptor);
|
return () => interceptorsRef.current.delete(interceptor);
|
||||||
}, []);
|
}, []);
|
||||||
return {
|
return { addInterceptor, interceptorsRef, pushHandlersRef, subscribePush };
|
||||||
addInterceptor,
|
|
||||||
interceptorsRef,
|
|
||||||
lastInitialStateRef,
|
|
||||||
pushHandlersRef,
|
|
||||||
subscribePush,
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function BrowserProvider(props: {
|
function BrowserProvider(props: {
|
||||||
|
|
@ -205,13 +172,8 @@ function BrowserProvider(props: {
|
||||||
const clientRef = useRef<Awaited<ReturnType<typeof MTPClient.create>> | null>(
|
const clientRef = useRef<Awaited<ReturnType<typeof MTPClient.create>> | null>(
|
||||||
null,
|
null,
|
||||||
);
|
);
|
||||||
const {
|
const { addInterceptor, interceptorsRef, pushHandlersRef, subscribePush } =
|
||||||
addInterceptor,
|
useMessageHandlers();
|
||||||
interceptorsRef,
|
|
||||||
lastInitialStateRef,
|
|
||||||
pushHandlersRef,
|
|
||||||
subscribePush,
|
|
||||||
} = useMessageHandlers();
|
|
||||||
|
|
||||||
const connected = readyState === ConnectionState.Connected;
|
const connected = readyState === ConnectionState.Connected;
|
||||||
|
|
||||||
|
|
@ -235,20 +197,7 @@ function BrowserProvider(props: {
|
||||||
(data ?? {}) as Record<string, unknown>,
|
(data ?? {}) as Record<string, unknown>,
|
||||||
options,
|
options,
|
||||||
);
|
);
|
||||||
const response = validateResponse(type, message);
|
return validateResponse(type, message);
|
||||||
setFreshContacts((contacts) => removeMissingContacts(contacts, response));
|
|
||||||
if (response.type.startsWith("Error")) {
|
|
||||||
const errorData = response.data as Record<string, unknown>;
|
|
||||||
throw new ProtocolError({
|
|
||||||
type: response.type,
|
|
||||||
requestId: response.id,
|
|
||||||
errorType:
|
|
||||||
typeof errorData.ErrorType === "string"
|
|
||||||
? errorData.ErrorType
|
|
||||||
: undefined,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return response;
|
|
||||||
},
|
},
|
||||||
[],
|
[],
|
||||||
);
|
);
|
||||||
|
|
@ -469,9 +418,6 @@ function BrowserProvider(props: {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
setFreshContacts((contacts) =>
|
|
||||||
removeMissingContacts(contacts, validated),
|
|
||||||
);
|
|
||||||
for (const handler of [...pushHandlersRef.current]) {
|
for (const handler of [...pushHandlersRef.current]) {
|
||||||
void Promise.resolve()
|
void Promise.resolve()
|
||||||
.then(() => handler(validated))
|
.then(() => handler(validated))
|
||||||
|
|
@ -479,9 +425,6 @@ function BrowserProvider(props: {
|
||||||
log(1, "mtp", "red", "Push handler failed", error, { type });
|
log(1, "mtp", "red", "Push handler failed", error, { type });
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (validated.type === "GetStates") {
|
|
||||||
lastInitialStateRef.current = validated;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
setReadyState(activeClient.state);
|
setReadyState(activeClient.state);
|
||||||
|
|
@ -594,13 +537,7 @@ function BrowserProvider(props: {
|
||||||
setIdentifying(false);
|
setIdentifying(false);
|
||||||
sonnerToast.dismiss("mtp-connection-toast");
|
sonnerToast.dismiss("mtp-connection-toast");
|
||||||
};
|
};
|
||||||
}, [
|
}, [mtpUrl, props.blockConnection, load, pushHandlersRef]);
|
||||||
lastInitialStateRef,
|
|
||||||
mtpUrl,
|
|
||||||
props.blockConnection,
|
|
||||||
load,
|
|
||||||
pushHandlersRef,
|
|
||||||
]);
|
|
||||||
|
|
||||||
// No Iota check
|
// No Iota check
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|
@ -707,13 +644,8 @@ function TauriProvider(props: {
|
||||||
const [freshCommunities, setFreshCommunities] = useState<Communities>([]);
|
const [freshCommunities, setFreshCommunities] = useState<Communities>([]);
|
||||||
const [freshCalls, setFreshCalls] = useState<Calls>([]);
|
const [freshCalls, setFreshCalls] = useState<Calls>([]);
|
||||||
const generationRef = useRef(0);
|
const generationRef = useRef(0);
|
||||||
const {
|
const { addInterceptor, interceptorsRef, pushHandlersRef, subscribePush } =
|
||||||
addInterceptor,
|
useMessageHandlers();
|
||||||
interceptorsRef,
|
|
||||||
lastInitialStateRef,
|
|
||||||
pushHandlersRef,
|
|
||||||
subscribePush,
|
|
||||||
} = useMessageHandlers();
|
|
||||||
const subscriptionsRef = useRef(
|
const subscriptionsRef = useRef(
|
||||||
new Map<string, Set<(message: ProtocolMessage) => void>>(),
|
new Map<string, Set<(message: ProtocolMessage) => void>>(),
|
||||||
);
|
);
|
||||||
|
|
@ -754,10 +686,7 @@ function TauriProvider(props: {
|
||||||
[]) {
|
[]) {
|
||||||
handler(validated);
|
handler(validated);
|
||||||
}
|
}
|
||||||
if (!isPushType(validated.type)) return;
|
if (!(PUSH_TYPES as readonly string[]).includes(validated.type)) return;
|
||||||
setFreshContacts((contacts) =>
|
|
||||||
removeMissingContacts(contacts, validated),
|
|
||||||
);
|
|
||||||
for (const handler of [...pushHandlersRef.current]) {
|
for (const handler of [...pushHandlersRef.current]) {
|
||||||
void Promise.resolve(handler(validated)).catch((error) => {
|
void Promise.resolve(handler(validated)).catch((error) => {
|
||||||
log(1, "mtp", "red", "Native MTP push handler failed", error, {
|
log(1, "mtp", "red", "Native MTP push handler failed", error, {
|
||||||
|
|
@ -765,11 +694,8 @@ function TauriProvider(props: {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (validated.type === "GetStates") {
|
|
||||||
lastInitialStateRef.current = validated;
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
[lastInitialStateRef, pushHandlersRef],
|
[pushHandlersRef],
|
||||||
);
|
);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|
@ -844,20 +770,6 @@ function TauriProvider(props: {
|
||||||
id: options?.id,
|
id: options?.id,
|
||||||
});
|
});
|
||||||
const validated = validateResponse(type, response);
|
const validated = validateResponse(type, response);
|
||||||
setFreshContacts((contacts) =>
|
|
||||||
removeMissingContacts(contacts, validated),
|
|
||||||
);
|
|
||||||
if (validated.type.startsWith("Error")) {
|
|
||||||
const errorData = validated.data as Record<string, unknown>;
|
|
||||||
throw new ProtocolError({
|
|
||||||
type: validated.type,
|
|
||||||
requestId: validated.id,
|
|
||||||
errorType:
|
|
||||||
typeof errorData.ErrorType === "string"
|
|
||||||
? errorData.ErrorType
|
|
||||||
: undefined,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
for (const interceptor of interceptorsRef.current) {
|
for (const interceptor of interceptorsRef.current) {
|
||||||
void Promise.resolve(
|
void Promise.resolve(
|
||||||
interceptor({ type, data, response: validated as ProtocolMessage }),
|
interceptor({ type, data, response: validated as ProtocolMessage }),
|
||||||
|
|
|
||||||
|
|
@ -12,18 +12,19 @@
|
||||||
"build": "tsc -p tsconfig.json --noEmit"
|
"build": "tsc -p tsconfig.json --noEmit"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@methanium/ui": "*",
|
"@tanstack/react-router": "^1.169.1",
|
||||||
"@tanstack/react-router": "^1.170.21",
|
"@tauri-apps/api": "^2.11.0",
|
||||||
"@tauri-apps/api": "^2.11.1",
|
"@tauri-apps/plugin-notification": "~2",
|
||||||
"@tauri-apps/plugin-notification": "~2.3.3",
|
|
||||||
"@tensamin/chat": "workspace:*",
|
|
||||||
"@tensamin/crypto": "workspace:*",
|
"@tensamin/crypto": "workspace:*",
|
||||||
"@tensamin/mtp": "workspace:*",
|
|
||||||
"@tensamin/shared": "workspace:*",
|
"@tensamin/shared": "workspace:*",
|
||||||
|
"@tensamin/chat": "workspace:*",
|
||||||
"@tensamin/storage": "workspace:*",
|
"@tensamin/storage": "workspace:*",
|
||||||
|
"@tensamin/mtp": "workspace:*",
|
||||||
|
"@methanium/ui": "*",
|
||||||
"@tensamin/user": "workspace:*",
|
"@tensamin/user": "workspace:*",
|
||||||
"react": "^19.2.8",
|
"react": "^19.2.0",
|
||||||
"react-dom": "^19.2.8",
|
"react-dom": "^19.2.0",
|
||||||
"sonner": "^2.0.7"
|
"sonner": "^2.0.7",
|
||||||
|
"zod": "^4.3.6"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,14 +12,14 @@
|
||||||
"build": "tsc -p tsconfig.json --noEmit"
|
"build": "tsc -p tsconfig.json --noEmit"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@methanium/ui": "*",
|
"@tauri-apps/api": "^2",
|
||||||
"@tauri-apps/api": "^2.11.1",
|
"@tauri-apps/plugin-notification": "~2",
|
||||||
"@tauri-apps/plugin-notification": "~2.3.3",
|
|
||||||
"@tensamin/shared": "workspace:*",
|
"@tensamin/shared": "workspace:*",
|
||||||
"@tensamin/storage": "workspace:*",
|
"@tensamin/storage": "workspace:*",
|
||||||
"lucide-react": "^1.29.0",
|
"@methanium/ui": "*",
|
||||||
"react": "^19.2.8",
|
"lucide-react": "^1.14.0",
|
||||||
"react-dom": "^19.2.8",
|
"react": "^19.2.0",
|
||||||
"zod": "^4.4.3"
|
"react-dom": "^19.2.0",
|
||||||
|
"zod": "^4.3.6"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,20 +12,20 @@
|
||||||
"build": "tsc -p tsconfig.json --noEmit"
|
"build": "tsc -p tsconfig.json --noEmit"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@methanium/ui": "*",
|
"@tanstack/react-router": "^1.169.1",
|
||||||
"@tanstack/react-router": "^1.170.21",
|
|
||||||
"@tensamin/cache": "workspace:*",
|
"@tensamin/cache": "workspace:*",
|
||||||
"@tensamin/hotkeys": "workspace:*",
|
"@tensamin/hotkeys": "workspace:*",
|
||||||
"@tensamin/markdown": "workspace:*",
|
"@tensamin/markdown": "workspace:*",
|
||||||
"@tensamin/mtp": "workspace:*",
|
"@tensamin/mtp": "workspace:*",
|
||||||
"@tensamin/shared": "workspace:*",
|
"@tensamin/shared": "workspace:*",
|
||||||
"@tensamin/storage": "workspace:*",
|
"@tensamin/storage": "workspace:*",
|
||||||
|
"@methanium/ui": "*",
|
||||||
"@tensamin/user": "workspace:*",
|
"@tensamin/user": "workspace:*",
|
||||||
"lucide-react": "^1.29.0",
|
"lucide-react": "^1.14.0",
|
||||||
"react": "^19.2.8",
|
"react": "^19.2.0",
|
||||||
"react-dom": "^19.2.8"
|
"react-dom": "^19.2.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"vite": "^8.2.1"
|
"vite": "^8.0.10"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,6 @@
|
||||||
"exports": {
|
"exports": {
|
||||||
"./asyncQueue": "./src/asyncQueue.ts",
|
"./asyncQueue": "./src/asyncQueue.ts",
|
||||||
"./code": "./src/code.ts",
|
"./code": "./src/code.ts",
|
||||||
"./errors": "./src/errors.ts",
|
|
||||||
"./data": "./src/data.ts",
|
"./data": "./src/data.ts",
|
||||||
"./desktopMedia": "./src/desktopMedia.tsx",
|
"./desktopMedia": "./src/desktopMedia.tsx",
|
||||||
"./log": "./src/log.tsx",
|
"./log": "./src/log.tsx",
|
||||||
|
|
@ -23,9 +22,9 @@
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@methanium/ui": "*",
|
"@methanium/ui": "*",
|
||||||
"lucide-react": "^1.29.0",
|
"lucide-react": "^1.14.0",
|
||||||
"react": "^19.2.8",
|
"react": "^19.2.0",
|
||||||
"react-dom": "^19.2.8",
|
"react-dom": "^19.2.0",
|
||||||
"zod": "^4.4.3"
|
"zod": "^4.3.6"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -143,71 +143,34 @@ export type Contacts = z.infer<typeof authPayload.shape.Contacts>;
|
||||||
export type Communities = z.infer<typeof authPayload.shape.Communities>;
|
export type Communities = z.infer<typeof authPayload.shape.Communities>;
|
||||||
export type Calls = z.infer<typeof authPayload.shape.Calls>;
|
export type Calls = z.infer<typeof authPayload.shape.Calls>;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// MTP
|
// MTP
|
||||||
const userFields = {
|
const user = z.object({
|
||||||
About: z.string().max(255).optional(),
|
About: z.string().max(255).optional(),
|
||||||
Avatar: z.string().optional(),
|
Avatar: z.string().optional(),
|
||||||
Display: z.string().min(1).max(15),
|
Display: z.string().min(1).max(15),
|
||||||
IotaId: z.number(),
|
IotaId: z.number(),
|
||||||
OmikronConnections: z.array(z.number()),
|
OmikronConnections: z.array(z.number()),
|
||||||
OmikronId: z.number().optional(),
|
OmikronId: z.number().optional(),
|
||||||
|
OnlineStatus: z.enum([
|
||||||
|
"user_offline",
|
||||||
|
"user_online",
|
||||||
|
"user_dnd",
|
||||||
|
"user_idle",
|
||||||
|
"user_wc",
|
||||||
|
"user_borked",
|
||||||
|
"iota_offline",
|
||||||
|
"iota_online",
|
||||||
|
"iota_borked",
|
||||||
|
]),
|
||||||
PublicKey: z.base64(),
|
PublicKey: z.base64(),
|
||||||
Status: z.string().max(15).optional(),
|
Status: z.string().max(15).optional(),
|
||||||
SubEnd: z.number(),
|
SubEnd: z.number(),
|
||||||
SubLevel: z.number(),
|
SubLevel: z.number(),
|
||||||
UserId: z.number(),
|
UserId: z.number(),
|
||||||
Username: z.string().min(1).max(15),
|
Username: z.string().min(1).max(15),
|
||||||
};
|
|
||||||
|
|
||||||
export const publicUserStateSchema = z.enum([
|
|
||||||
"user_online",
|
|
||||||
"user_idle",
|
|
||||||
"user_dnd",
|
|
||||||
"user_wc",
|
|
||||||
"user_offline",
|
|
||||||
"iota_offline",
|
|
||||||
]);
|
|
||||||
|
|
||||||
export const userPresencePreferenceSchema = z.enum([
|
|
||||||
"user_online",
|
|
||||||
"user_idle",
|
|
||||||
"user_dnd",
|
|
||||||
"user_wc",
|
|
||||||
"user_invisible",
|
|
||||||
]);
|
|
||||||
|
|
||||||
export const clientUserStateSchema = z.union([
|
|
||||||
publicUserStateSchema,
|
|
||||||
userPresencePreferenceSchema,
|
|
||||||
]);
|
|
||||||
|
|
||||||
export const publicUserSchema = z.object({
|
|
||||||
...userFields,
|
|
||||||
OnlineStatus: z.enum([
|
|
||||||
"user_online",
|
|
||||||
"user_idle",
|
|
||||||
"user_dnd",
|
|
||||||
"user_wc",
|
|
||||||
"user_offline",
|
|
||||||
"iota_offline",
|
|
||||||
"user_borked",
|
|
||||||
"iota_online",
|
|
||||||
"iota_borked",
|
|
||||||
]),
|
|
||||||
});
|
});
|
||||||
|
|
||||||
export const accountUserSchema = z.object({
|
|
||||||
...userFields,
|
|
||||||
OnlineStatus: userPresencePreferenceSchema,
|
|
||||||
});
|
|
||||||
|
|
||||||
export const userSchema = z.union([publicUserSchema, accountUserSchema]);
|
|
||||||
|
|
||||||
export const userStateEntrySchema = z.object({
|
|
||||||
UserId: z.number().int().positive(),
|
|
||||||
UserState: publicUserStateSchema,
|
|
||||||
});
|
|
||||||
|
|
||||||
export const mtp = {
|
export const mtp = {
|
||||||
IdentificationResponse: {
|
IdentificationResponse: {
|
||||||
request: z.object({}).optional(),
|
request: z.object({}).optional(),
|
||||||
|
|
@ -238,47 +201,10 @@ export const mtp = {
|
||||||
UserId: z.number().optional(),
|
UserId: z.number().optional(),
|
||||||
Username: z.string().optional(),
|
Username: z.string().optional(),
|
||||||
}),
|
}),
|
||||||
response: userSchema,
|
response: user,
|
||||||
},
|
|
||||||
GetStates: {
|
|
||||||
request: z.object({
|
|
||||||
SessionId: z.number().int().positive(),
|
|
||||||
UserIds: z.array(z.number().int().positive()),
|
|
||||||
}),
|
|
||||||
response: z.object({
|
|
||||||
SessionId: z.number().int().positive(),
|
|
||||||
// Keep valid entries when one entry in a server snapshot is malformed.
|
|
||||||
UserStates: z.array(userStateEntrySchema.nullable().catch(null)),
|
|
||||||
MissingUserIds: z.array(z.number().int().positive()).optional(),
|
|
||||||
}),
|
|
||||||
},
|
|
||||||
ClientChanged: {
|
|
||||||
request: z.object({}).optional(),
|
|
||||||
response: z.object({
|
|
||||||
SessionId: z.number().int().positive(),
|
|
||||||
UserId: z.number().int().positive(),
|
|
||||||
UserState: clientUserStateSchema,
|
|
||||||
}),
|
|
||||||
},
|
|
||||||
SetUserState: {
|
|
||||||
request: z.object({
|
|
||||||
UserState: userPresencePreferenceSchema,
|
|
||||||
}),
|
|
||||||
response: z.object({
|
|
||||||
UserState: userPresencePreferenceSchema,
|
|
||||||
}),
|
|
||||||
},
|
},
|
||||||
ChangeUserData: {
|
ChangeUserData: {
|
||||||
request: z
|
request: user.partial(),
|
||||||
.object({
|
|
||||||
About: userFields.About,
|
|
||||||
Avatar: userFields.Avatar,
|
|
||||||
Display: userFields.Display,
|
|
||||||
PublicKey: userFields.PublicKey,
|
|
||||||
Status: userFields.Status,
|
|
||||||
Username: userFields.Username,
|
|
||||||
})
|
|
||||||
.partial(),
|
|
||||||
response: z.object({}),
|
response: z.object({}),
|
||||||
},
|
},
|
||||||
MessageDelete: {
|
MessageDelete: {
|
||||||
|
|
@ -659,9 +585,7 @@ export const storageDefaults: Storage = {
|
||||||
|
|
||||||
// User Status
|
// User Status
|
||||||
export function getStatusColor(
|
export function getStatusColor(
|
||||||
status:
|
status: z.infer<typeof mtp.GetUserData.response.shape.OnlineStatus>,
|
||||||
| z.infer<typeof publicUserSchema.shape.OnlineStatus>
|
|
||||||
| z.infer<typeof userPresencePreferenceSchema>,
|
|
||||||
) {
|
) {
|
||||||
switch (status) {
|
switch (status) {
|
||||||
case "user_online":
|
case "user_online":
|
||||||
|
|
|
||||||
|
|
@ -1,25 +0,0 @@
|
||||||
export class ProtocolError extends Error {
|
|
||||||
readonly type: string;
|
|
||||||
readonly id: number | undefined;
|
|
||||||
readonly communicationType: string;
|
|
||||||
readonly requestId: number | undefined;
|
|
||||||
readonly errorType: string | undefined;
|
|
||||||
|
|
||||||
constructor(options: {
|
|
||||||
type: string;
|
|
||||||
requestId?: number;
|
|
||||||
errorType?: string;
|
|
||||||
}) {
|
|
||||||
super(
|
|
||||||
options.errorType
|
|
||||||
? `${options.type}: ${options.errorType}`
|
|
||||||
: options.type,
|
|
||||||
);
|
|
||||||
this.name = "ProtocolError";
|
|
||||||
this.type = options.type;
|
|
||||||
this.id = options.requestId;
|
|
||||||
this.communicationType = options.type;
|
|
||||||
this.requestId = options.requestId;
|
|
||||||
this.errorType = options.errorType;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -14,12 +14,12 @@
|
||||||
"build": "tsc -p tsconfig.json --noEmit"
|
"build": "tsc -p tsconfig.json --noEmit"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@methanium/ui": "*",
|
"@tauri-apps/api": "^2",
|
||||||
"@tauri-apps/api": "^2.11.1",
|
|
||||||
"@tensamin/cache": "workspace:*",
|
"@tensamin/cache": "workspace:*",
|
||||||
"@tensamin/mtp": "workspace:*",
|
|
||||||
"@tensamin/shared": "workspace:*",
|
"@tensamin/shared": "workspace:*",
|
||||||
"react": "^19.2.8",
|
"@tensamin/mtp": "workspace:*",
|
||||||
"react-dom": "^19.2.8"
|
"@methanium/ui": "*",
|
||||||
|
"react": "^19.2.0",
|
||||||
|
"react-dom": "^19.2.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,15 +12,17 @@
|
||||||
"build": "tsc -p tsconfig.json --noEmit"
|
"build": "tsc -p tsconfig.json --noEmit"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@methanium/ui": "*",
|
"@tanstack/react-router": "^1.0.0",
|
||||||
"@tanstack/react-router": "^1.170.21",
|
"@tauri-apps/api": "^2.10.1",
|
||||||
"@tensamin/crypto": "workspace:*",
|
"@tensamin/crypto": "workspace:*",
|
||||||
"@tensamin/mtp": "workspace:*",
|
|
||||||
"@tensamin/shared": "workspace:*",
|
"@tensamin/shared": "workspace:*",
|
||||||
"@tensamin/storage": "workspace:*",
|
"@tensamin/storage": "workspace:*",
|
||||||
"@tensamin/tauri": "workspace:*",
|
"@tensamin/tauri": "workspace:*",
|
||||||
|
"@tensamin/mtp": "workspace:*",
|
||||||
|
"@methanium/ui": "*",
|
||||||
"@tensamin/user": "workspace:*",
|
"@tensamin/user": "workspace:*",
|
||||||
"react": "^19.2.8",
|
"lucide-react": "^1.8.0",
|
||||||
"react-dom": "^19.2.8"
|
"react": "^19.2.0",
|
||||||
|
"react-dom": "^19.2.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,8 +18,8 @@
|
||||||
"@tensamin/mtp": "workspace:*",
|
"@tensamin/mtp": "workspace:*",
|
||||||
"@tensamin/shared": "workspace:*",
|
"@tensamin/shared": "workspace:*",
|
||||||
"@tensamin/storage": "workspace:*",
|
"@tensamin/storage": "workspace:*",
|
||||||
"react": "^19.2.8",
|
"react": "^19.2.0",
|
||||||
"react-dom": "^19.2.8",
|
"react-dom": "^19.2.0",
|
||||||
"zod": "^4.4.3"
|
"zod": "^4.3.6"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,29 +7,15 @@ import {
|
||||||
useRef,
|
useRef,
|
||||||
useState,
|
useState,
|
||||||
} from "react";
|
} from "react";
|
||||||
import { useMTP, type ProtocolMessage } from "@tensamin/mtp";
|
import { useMTP } from "@tensamin/mtp";
|
||||||
|
|
||||||
import {
|
import { mtp as schemas } from "@tensamin/shared/data";
|
||||||
clientUserStateSchema,
|
|
||||||
mtp as schemas,
|
|
||||||
publicUserStateSchema,
|
|
||||||
userStateEntrySchema,
|
|
||||||
} from "@tensamin/shared/data";
|
|
||||||
import type z from "zod";
|
import type z from "zod";
|
||||||
import { createCache } from "@tensamin/cache";
|
import { createCache } from "@tensamin/cache";
|
||||||
import { useStorage } from "@tensamin/storage/context";
|
import { useStorage } from "@tensamin/storage/context";
|
||||||
import { useSession } from "@tensamin/storage/session";
|
import { useSession } from "@tensamin/storage/session";
|
||||||
|
|
||||||
export type User = z.infer<typeof schemas.GetUserData.response>;
|
export type User = z.infer<typeof schemas.GetUserData.response>;
|
||||||
type ClientUserState = z.infer<typeof clientUserStateSchema>;
|
|
||||||
|
|
||||||
export function mergeTransientPresence<T extends { UserId: number }>(
|
|
||||||
user: T,
|
|
||||||
presence: ReadonlyMap<number, ClientUserState>,
|
|
||||||
): T {
|
|
||||||
const state = presence.get(user.UserId);
|
|
||||||
return state === undefined ? user : ({ ...user, OnlineStatus: state } as T);
|
|
||||||
}
|
|
||||||
|
|
||||||
const USER_CACHE_MAX_AGE = 5 * 60 * 1000;
|
const USER_CACHE_MAX_AGE = 5 * 60 * 1000;
|
||||||
|
|
||||||
|
|
@ -49,105 +35,19 @@ export default function UserProvider(props: { children: ReactNode }) {
|
||||||
const storageRef = useRef<Record<number, User>>({});
|
const storageRef = useRef<Record<number, User>>({});
|
||||||
const pendingRef = useRef<Record<number, Promise<User> | undefined>>({});
|
const pendingRef = useRef<Record<number, Promise<User> | undefined>>({});
|
||||||
const checkedAtRef = useRef<Record<number, number>>({});
|
const checkedAtRef = useRef<Record<number, number>>({});
|
||||||
const presenceRef = useRef(new Map<number, ClientUserState>());
|
|
||||||
const durableProfileRef = useRef<Record<number, User>>({});
|
|
||||||
|
|
||||||
const { send, subscribePush } = useMTP();
|
const { send } = useMTP();
|
||||||
const { load } = useStorage();
|
const { load } = useStorage();
|
||||||
const { contacts } = useSession();
|
const { contacts } = useSession();
|
||||||
const [accountId, setAccountId] = useState<number | null>(null);
|
const [accountId, setAccountId] = useState<number | null>(null);
|
||||||
const [cacheVersion, setCacheVersion] = useState(0);
|
const [cacheVersion, setCacheVersion] = useState(0);
|
||||||
const [sessionId, setSessionId] = useState<number | null>(null);
|
|
||||||
const contactsRef = useRef(contacts);
|
|
||||||
const initialStatesRef = useRef(
|
|
||||||
new Map<number, z.infer<typeof publicUserStateSchema>>(),
|
|
||||||
);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
contactsRef.current = contacts;
|
|
||||||
}, [contacts]);
|
|
||||||
|
|
||||||
const mergeUserPresence = useCallback((user: User): User => {
|
|
||||||
return mergeTransientPresence(user, presenceRef.current);
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
const applyUserState = useCallback(
|
|
||||||
(userId: number, state: ClientUserState, privateState = false) => {
|
|
||||||
const known =
|
|
||||||
userId === accountId ||
|
|
||||||
contactsRef.current.some((contact) => contact.UserId === userId);
|
|
||||||
if (!known) return false;
|
|
||||||
|
|
||||||
if (state === "user_invisible" && userId !== accountId) return false;
|
|
||||||
if (userId === accountId && !privateState) return false;
|
|
||||||
|
|
||||||
presenceRef.current.set(userId, state);
|
|
||||||
const current = storageRef.current[userId];
|
|
||||||
if (current) storageRef.current[userId] = mergeUserPresence(current);
|
|
||||||
setCacheVersion((version) => version + 1);
|
|
||||||
return true;
|
|
||||||
},
|
|
||||||
[accountId, mergeUserPresence],
|
|
||||||
);
|
|
||||||
|
|
||||||
const removePresence = useCallback((userId: number) => {
|
|
||||||
presenceRef.current.delete(userId);
|
|
||||||
initialStatesRef.current.delete(userId);
|
|
||||||
delete checkedAtRef.current[userId];
|
|
||||||
setCacheVersion((version) => version + 1);
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
const handleStatePush = useCallback(
|
|
||||||
async (message: ProtocolMessage) => {
|
|
||||||
if (!accountId || !sessionId) return;
|
|
||||||
const data = message.data as Record<string, unknown>;
|
|
||||||
if (message.type === "GetStates") {
|
|
||||||
if (Number(data.SessionId) !== sessionId) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (Array.isArray(data.MissingUserIds)) {
|
|
||||||
for (const userId of data.MissingUserIds) {
|
|
||||||
if (typeof userId === "number") removePresence(userId);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!Array.isArray(data.UserStates)) return;
|
|
||||||
for (const entry of data.UserStates) {
|
|
||||||
const parsed = userStateEntrySchema.safeParse(entry);
|
|
||||||
if (!parsed.success) continue;
|
|
||||||
if (parsed.data.UserId === accountId) continue;
|
|
||||||
initialStatesRef.current.set(
|
|
||||||
parsed.data.UserId,
|
|
||||||
parsed.data.UserState,
|
|
||||||
);
|
|
||||||
if (applyUserState(parsed.data.UserId, parsed.data.UserState)) {
|
|
||||||
initialStatesRef.current.delete(parsed.data.UserId);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (message.type !== "ClientChanged") return;
|
|
||||||
if (Number(data.SessionId) !== sessionId) return;
|
|
||||||
const parsed = schemas.ClientChanged.response.safeParse(data);
|
|
||||||
if (!parsed.success) return;
|
|
||||||
applyUserState(parsed.data.UserId, parsed.data.UserState, true);
|
|
||||||
},
|
|
||||||
[accountId, applyUserState, removePresence, sessionId],
|
|
||||||
);
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
void load("user_id").then((accountId) => {
|
void load("user_id").then((accountId) => {
|
||||||
setAccountId(accountId);
|
setAccountId(accountId);
|
||||||
});
|
});
|
||||||
void load("session_id").then((value) => {
|
|
||||||
setSessionId(value);
|
|
||||||
});
|
|
||||||
}, [load]);
|
}, [load]);
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (!accountId || !sessionId) return;
|
|
||||||
return subscribePush(handleStatePush);
|
|
||||||
}, [accountId, handleStatePush, sessionId, subscribePush]);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Executes get.
|
* Executes get.
|
||||||
* @param userId Parameter userId.
|
* @param userId Parameter userId.
|
||||||
|
|
@ -173,20 +73,17 @@ export default function UserProvider(props: { children: ReactNode }) {
|
||||||
schemas.GetUserData.response.safeParse(cachedValue);
|
schemas.GetUserData.response.safeParse(cachedValue);
|
||||||
const cached = cachedResult.success ? cachedResult.data : undefined;
|
const cached = cachedResult.success ? cachedResult.data : undefined;
|
||||||
if (cached) {
|
if (cached) {
|
||||||
durableProfileRef.current[userId] = cached;
|
storageRef.current[userId] = cached;
|
||||||
const merged = mergeUserPresence(cached);
|
|
||||||
storageRef.current[userId] = merged;
|
|
||||||
const checkedAt = checkedAtRef.current[userId];
|
const checkedAt = checkedAtRef.current[userId];
|
||||||
if (!checkedAt || Date.now() - checkedAt < USER_CACHE_MAX_AGE) {
|
if (!checkedAt || Date.now() - checkedAt < USER_CACHE_MAX_AGE) {
|
||||||
checkedAtRef.current[userId] = Date.now();
|
checkedAtRef.current[userId] = Date.now();
|
||||||
return merged;
|
return cached;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
const userData = await send("GetUserData", { UserId: userId });
|
const userData = await send("GetUserData", { UserId: userId });
|
||||||
if (userData.type === "ErrorNotFound" || userData.data.UserId === 0) {
|
if (userData.type === "ErrorNotFound" || userData.data.UserId === 0) {
|
||||||
delete storageRef.current[userId];
|
delete storageRef.current[userId];
|
||||||
delete durableProfileRef.current[userId];
|
|
||||||
delete checkedAtRef.current[userId];
|
delete checkedAtRef.current[userId];
|
||||||
await cache.profiles.delete(userId);
|
await cache.profiles.delete(userId);
|
||||||
throw new Error("GetUserData failed: user not found");
|
throw new Error("GetUserData failed: user not found");
|
||||||
|
|
@ -194,15 +91,14 @@ export default function UserProvider(props: { children: ReactNode }) {
|
||||||
if (userData.type.startsWith("Error")) {
|
if (userData.type.startsWith("Error")) {
|
||||||
throw new Error(`GetUserData failed: ${userData.type}`);
|
throw new Error(`GetUserData failed: ${userData.type}`);
|
||||||
}
|
}
|
||||||
const user = mergeUserPresence(userData.data);
|
const user = userData.data;
|
||||||
durableProfileRef.current[userId] = userData.data;
|
|
||||||
storageRef.current[userId] = user;
|
storageRef.current[userId] = user;
|
||||||
checkedAtRef.current[userId] = Date.now();
|
checkedAtRef.current[userId] = Date.now();
|
||||||
return user;
|
return user;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (cached && storageRef.current[userId]) {
|
if (cached && storageRef.current[userId]) {
|
||||||
checkedAtRef.current[userId] = Date.now();
|
checkedAtRef.current[userId] = Date.now();
|
||||||
return storageRef.current[userId];
|
return cached;
|
||||||
}
|
}
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
|
|
@ -216,48 +112,23 @@ export default function UserProvider(props: { children: ReactNode }) {
|
||||||
delete pendingRef.current[userId];
|
delete pendingRef.current[userId];
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[accountId, cacheVersion, mergeUserPresence, send],
|
[accountId, cacheVersion, send],
|
||||||
);
|
);
|
||||||
|
|
||||||
const update = useCallback(
|
const update = useCallback(
|
||||||
async (user: User) => {
|
async (user: User) => {
|
||||||
const durableProfile = {
|
await createCache(String(accountId ?? user.UserId)).profiles.put(user);
|
||||||
...user,
|
storageRef.current[user.UserId] = user;
|
||||||
OnlineStatus:
|
|
||||||
durableProfileRef.current[user.UserId]?.OnlineStatus ??
|
|
||||||
user.OnlineStatus,
|
|
||||||
} as User;
|
|
||||||
await createCache(String(accountId ?? user.UserId)).profiles.put(
|
|
||||||
durableProfile,
|
|
||||||
);
|
|
||||||
durableProfileRef.current[user.UserId] = durableProfile;
|
|
||||||
storageRef.current[user.UserId] = mergeUserPresence(durableProfile);
|
|
||||||
checkedAtRef.current[user.UserId] = Date.now();
|
checkedAtRef.current[user.UserId] = Date.now();
|
||||||
setCacheVersion((version) => version + 1);
|
setCacheVersion((version) => version + 1);
|
||||||
},
|
},
|
||||||
[accountId, mergeUserPresence],
|
[accountId],
|
||||||
);
|
);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!accountId) return;
|
if (!accountId) return;
|
||||||
void (async () => {
|
for (const contact of contacts) void get(contact.UserId);
|
||||||
const userIds = [
|
}, [accountId, contacts, get]);
|
||||||
accountId,
|
|
||||||
...contacts.map((contact) => contact.UserId),
|
|
||||||
].filter((userId, index, all) => all.indexOf(userId) === index);
|
|
||||||
for (const userId of userIds) {
|
|
||||||
try {
|
|
||||||
await get(userId);
|
|
||||||
const state = initialStatesRef.current.get(userId);
|
|
||||||
if (state && applyUserState(userId, state)) {
|
|
||||||
initialStatesRef.current.delete(userId);
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
// The normal user loading path reports profile failures to its caller.
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})();
|
|
||||||
}, [accountId, applyUserState, contacts, get]);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<UserContext.Provider value={{ get, update }}>
|
<UserContext.Provider value={{ get, update }}>
|
||||||
|
|
|
||||||
3548
pnpm-lock.yaml
generated
3548
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue