agent-loft 0.2.94 → 0.2.95
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/channels/web/push.ts +15 -3
- package/web/lib/shell.js +3 -2
- package/web/views/messages.js +25 -9
package/package.json
CHANGED
package/src/channels/web/push.ts
CHANGED
|
@@ -40,6 +40,8 @@ export type RelayInfo = {
|
|
|
40
40
|
server: string;
|
|
41
41
|
/** 外壳列表里这台的图标和名字,加在通知标题前面 */
|
|
42
42
|
label: string;
|
|
43
|
+
/** 单独的服务器名:苹果设备的通知不带图标;旧订阅可能没有 */
|
|
44
|
+
name?: string;
|
|
43
45
|
};
|
|
44
46
|
|
|
45
47
|
/** 按订阅的主人筛选:拿到的是订阅里记的 userId(可能没有) */
|
|
@@ -237,7 +239,7 @@ export function addRelaySubscription(
|
|
|
237
239
|
const sub = input.subscription;
|
|
238
240
|
if (!validSubscription(sub)) throw new Error("订阅信息不完整");
|
|
239
241
|
if (!validVapid(input.vapid)) throw new Error("推送密钥不对");
|
|
240
|
-
const via = (input.via ?? {}) as { origin?: unknown; server?: unknown; label?: unknown };
|
|
242
|
+
const via = (input.via ?? {}) as { origin?: unknown; server?: unknown; label?: unknown; name?: unknown };
|
|
241
243
|
const origin = String(via.origin ?? "");
|
|
242
244
|
if (!embedders.includes(origin)) throw new Error(`这台没有允许 ${origin || "这个地址"} 嵌入,收不了它转来的通知订阅`);
|
|
243
245
|
const server = String(via.server ?? "");
|
|
@@ -255,6 +257,7 @@ export function addRelaySubscription(
|
|
|
255
257
|
origin,
|
|
256
258
|
server,
|
|
257
259
|
label: clip(via.label, 60),
|
|
260
|
+
...(typeof via.name === "string" ? { name: clip(via.name, 40) } : {}),
|
|
258
261
|
},
|
|
259
262
|
};
|
|
260
263
|
s.subscriptions = [...s.subscriptions.filter((x) => x.endpoint !== sub.endpoint), record];
|
|
@@ -289,6 +292,11 @@ export function hasSubscriptions(): boolean {
|
|
|
289
292
|
|
|
290
293
|
const prefixed = (label: string, title: string) => (label ? `${label} · ${title}` : title);
|
|
291
294
|
|
|
295
|
+
function isAppleDevice(sub: PushSubscriptionRecord): boolean {
|
|
296
|
+
// Mac 上的 Chrome / Firefox 使用各自的推送服务,要同时看订阅时记下的设备类型。
|
|
297
|
+
return /^(?:iPhone|iPad|Mac)(?: ·|$)/.test(sub.label) || new URL(sub.endpoint).hostname.endsWith(".push.apple.com");
|
|
298
|
+
}
|
|
299
|
+
|
|
292
300
|
/**
|
|
293
301
|
* 真正推出去的内容。加了别的服务器(这台是外壳)时标题前面带上这台的名字,好分清是哪台的;
|
|
294
302
|
* 外壳转来的订阅带上外壳列表里这台的名字,tag 加上这台的 id(各台的会话 key 可能撞上),
|
|
@@ -296,16 +304,20 @@ const prefixed = (label: string, title: string) => (label ? `${label} · ${title
|
|
|
296
304
|
*/
|
|
297
305
|
export function payloadFor(sub: PushSubscriptionRecord, payload: PushPayload): PushPayload {
|
|
298
306
|
const relay = sub.relay;
|
|
307
|
+
const apple = isAppleDevice(sub);
|
|
299
308
|
if (!relay) {
|
|
300
309
|
const servers = config().servers;
|
|
301
310
|
if (!servers.list.length) return payload;
|
|
302
|
-
|
|
311
|
+
const label = apple ? selfName(servers) : `${servers.selfIcon} ${selfName(servers)}`.trim();
|
|
312
|
+
return { ...payload, title: prefixed(label, payload.title) };
|
|
303
313
|
}
|
|
314
|
+
// 旧外壳只传合并后的 label,兼容去掉开头的 emoji 图标;新外壳直接传名字。
|
|
315
|
+
const label = apple ? relay.name ?? relay.label.replace(/^[^\s]*[\p{Extended_Pictographic}\p{Regional_Indicator}][^\s]*\s+/u, "") : relay.label;
|
|
304
316
|
const url = new URL(payload.url ?? "/", "http://relay");
|
|
305
317
|
url.searchParams.set("srv", relay.server);
|
|
306
318
|
return {
|
|
307
319
|
...payload,
|
|
308
|
-
title: prefixed(
|
|
320
|
+
title: prefixed(label, payload.title),
|
|
309
321
|
...(payload.tag ? { tag: `srv:${relay.server}:${payload.tag}` } : {}),
|
|
310
322
|
url: `${url.pathname}${url.search}${url.hash}`,
|
|
311
323
|
};
|
package/web/lib/shell.js
CHANGED
|
@@ -502,13 +502,14 @@ function applyRelayPush() {
|
|
|
502
502
|
if (SH.role !== "guest" || !SH.push || !S.user || relayStopped) return;
|
|
503
503
|
const me = SH.servers.find((s) => s.id === SH.self);
|
|
504
504
|
const label = me ? `${me.icon} ${me.name}`.trim() : "";
|
|
505
|
-
const
|
|
505
|
+
const name = me?.name || "";
|
|
506
|
+
const mark = JSON.stringify([S.user.id, SH.push.subscription.endpoint, SH.self, label, name]);
|
|
506
507
|
if (relayed === mark) return;
|
|
507
508
|
relayed = mark;
|
|
508
509
|
const body = {
|
|
509
510
|
subscription: SH.push.subscription,
|
|
510
511
|
vapid: SH.push.vapid,
|
|
511
|
-
via: { origin: SH.hostOrigin, server: SH.self, label },
|
|
512
|
+
via: { origin: SH.hostOrigin, server: SH.self, label, name },
|
|
512
513
|
};
|
|
513
514
|
relayWork = relayWork.catch(() => {}).then(() => api("/api/push/relay", {
|
|
514
515
|
method: "POST",
|
package/web/views/messages.js
CHANGED
|
@@ -370,7 +370,10 @@ export function bindScrollWatch() {
|
|
|
370
370
|
}
|
|
371
371
|
});
|
|
372
372
|
// 消息区变高(发送后输入框清空变矮)、内容变高都要重算留白;窗口 resize 管不到元素自己变尺寸
|
|
373
|
-
const ro = new ResizeObserver(() =>
|
|
373
|
+
const ro = new ResizeObserver(() => {
|
|
374
|
+
clampLongUsers(S.items);
|
|
375
|
+
afterLayout();
|
|
376
|
+
});
|
|
374
377
|
ro.observe(m);
|
|
375
378
|
ro.observe(ui.msgInner);
|
|
376
379
|
}
|
|
@@ -525,14 +528,25 @@ const USER_CLAMP = 260;
|
|
|
525
528
|
|
|
526
529
|
/** 太长的用户消息收起来,下面放「展开显示」。先把高度都量完再统一改,只排版一次 */
|
|
527
530
|
function clampLongUsers(items) {
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
531
|
+
// 隐藏的服务器页面暂时没有可用宽度,等显示后再量;宽度没变时不重复量每条消息。
|
|
532
|
+
const width = ui.msgInner.clientWidth;
|
|
533
|
+
if (!width) return;
|
|
534
|
+
const measured = [];
|
|
535
|
+
for (const it of items) {
|
|
536
|
+
if (it.type !== "user" || !it.bubble || it.clampWidth === width) continue;
|
|
537
|
+
it.clampWidth = width;
|
|
538
|
+
measured.push({ it, long: it.bubble.scrollHeight > USER_CLAMP + 60 });
|
|
539
|
+
}
|
|
540
|
+
for (const { it, long } of measured) {
|
|
534
541
|
const bubble = it.bubble;
|
|
535
|
-
|
|
542
|
+
if (!long) {
|
|
543
|
+
bubble.classList.remove("clamped");
|
|
544
|
+
it.clampButton?.remove();
|
|
545
|
+
it.clampButton = null;
|
|
546
|
+
continue;
|
|
547
|
+
}
|
|
548
|
+
if (it.clampButton) continue;
|
|
549
|
+
bubble.classList.toggle("clamped", !it.clampExpanded);
|
|
536
550
|
const btn = h(
|
|
537
551
|
"button",
|
|
538
552
|
{
|
|
@@ -541,13 +555,15 @@ function clampLongUsers(items) {
|
|
|
541
555
|
// 自己展开 / 收起:别被自动滚动拉回底部
|
|
542
556
|
userScrolled();
|
|
543
557
|
const open = !bubble.classList.toggle("clamped");
|
|
558
|
+
it.clampExpanded = open;
|
|
544
559
|
btn.textContent = open ? "收起" : "展开显示";
|
|
545
560
|
// 收起后按钮可能跑到视口上面去了:拉回来
|
|
546
561
|
if (!open) btn.scrollIntoView({ block: "nearest" });
|
|
547
562
|
},
|
|
548
563
|
},
|
|
549
|
-
"展开显示",
|
|
564
|
+
it.clampExpanded ? "收起" : "展开显示",
|
|
550
565
|
);
|
|
566
|
+
it.clampButton = btn;
|
|
551
567
|
bubble.after(btn);
|
|
552
568
|
}
|
|
553
569
|
}
|