@fabianactor/dsh-lil-whale-group-ui 1.11.0 → 1.12.0

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/lib/client.js CHANGED
@@ -1863,7 +1863,19 @@ const Bubble = React.memo(function Bubble({ config, message, onMention, animate
1863
1863
  if (composingRef.current) return
1864
1864
  draftValueRef.current = value
1865
1865
  if (draftTimerRef.current) clearTimeout(draftTimerRef.current)
1866
- draftTimerRef.current = setTimeout(() => writeDraft(GROUP_DRAFT_KEY, value), 300)
1866
+ draftTimerRef.current = setTimeout(() => {
1867
+ draftTimerRef.current = null
1868
+ writeDraft(GROUP_DRAFT_KEY, value)
1869
+ }, 300)
1870
+ }, [])
1871
+ // 切 tab 不会卸载这个页面组件,只卸载输入框 —— 页面级的卸载清理够不着,
1872
+ // 所以切走时自己把还没落盘的那 300ms 写掉(2026-11-19 草稿复活 bug 的其中一半)。
1873
+ const flushGroupDraft = useCallback(() => {
1874
+ if (draftTimerRef.current) {
1875
+ clearTimeout(draftTimerRef.current)
1876
+ draftTimerRef.current = null
1877
+ }
1878
+ writeDraft(GROUP_DRAFT_KEY, draftValueRef.current)
1867
1879
  }, [])
1868
1880
  // 卸载(切 tab / 关面板)时把还没落盘的那 300ms 存掉,别让人刚打的字随组件一起消失。
1869
1881
  useEffect(() => () => {
@@ -1900,6 +1912,7 @@ const Bubble = React.memo(function Bubble({ config, message, onMention, animate
1900
1912
  const switchTab = useCallback((key) => {
1901
1913
  if (key === tab) return
1902
1914
  if (key !== 'group') {
1915
+ flushGroupDraft()
1903
1916
  setTab(key)
1904
1917
  return
1905
1918
  }
@@ -1912,8 +1925,20 @@ const Bubble = React.memo(function Bubble({ config, message, onMention, animate
1912
1925
  setTab('group')
1913
1926
  tabSplashTimer.current = setTimeout(() => setTabSplash(false), 420)
1914
1927
  })
1915
- }, [tab])
1928
+ }, [tab, flushGroupDraft])
1916
1929
  useEffect(() => () => { if (tabSplashTimer.current) clearTimeout(tabSplashTimer.current) }, [])
1930
+ // 从私聊/鱼塘切回来时,输入框是新建的:defaultValue 用的是页面挂载那一刻的草稿,
1931
+ // 之后再改、再删都不在它里面。按"现在存的那份"重放一次,删掉的草稿就不会回来
1932
+ // (2026-11-19 他报的 bug:删掉输入框、切去私聊、再回群聊,旧字又出现)。
1933
+ useEffect(() => {
1934
+ if (tab !== 'group') return
1935
+ const el = inputRef.current
1936
+ if (!el) return
1937
+ const stored = readDraft(GROUP_DRAFT_KEY)
1938
+ el.value = stored
1939
+ setHasText(stored.trim() !== '')
1940
+ }, [tab])
1941
+
1917
1942
  const [unread, setUnread] = useState({ group: 0, dm: {}, total: 0 })
1918
1943
  // 群聊"上次看到哪儿":进这一页时冻结一次,线不跟着新消息往下跑。
1919
1944
  const seenGroupRef = useRef(null)
@@ -3775,7 +3800,7 @@ const Bubble = React.memo(function Bubble({ config, message, onMention, animate
3775
3800
  inject: ['slots'],
3776
3801
  apply(ctx) {
3777
3802
  // 一行"我跑的是哪一版"的自报,方便判断浏览器是不是还在用旧 bundle
3778
- console.info('[dsh-lil-whale-group-ui] client build v52 · line-cite:', Object.keys(MARKDOWN_LABELS).join(','))
3803
+ console.info('[dsh-lil-whale-group-ui] client build v53 · presence-draft:', Object.keys(MARKDOWN_LABELS).join(','))
3779
3804
  // 「正在回复…」那三个点的呼吸动画 + 过场转圈。只在浏览器里注入一次。
3780
3805
  if (typeof document !== 'undefined' && !document.getElementById('dsh-lil-whale-group-keyframes')) {
3781
3806
  const style = document.createElement('style')
package/lib/index.js CHANGED
@@ -14,6 +14,7 @@ import { fileURLToPath } from 'node:url'
14
14
  import { createRequire } from 'node:module'
15
15
  import { config } from './config.js'
16
16
  import { parseMessageLines } from './messages-core.js'
17
+ import { presenceReasonOf } from './presence-core.js'
17
18
 
18
19
  export const name = '@fabianactor/dsh-lil-whale-group-ui'
19
20
  export const inject = ['webServer', 'agents']
@@ -45,8 +46,8 @@ const PINS = join(GROUP_DIR, 'pins.json')
45
46
  const POOL_STATE = config().poolStateDir || join(GROUP_DIR, '..', 'state')
46
47
  const PRESENCE_DIR = join(POOL_STATE, 'presence')
47
48
  const PRESENCE_FRESH_MS = 20_000
48
- // 群唤醒之后多久之内还算「在回群里」。要比一次长回合宽:首 token 几十秒到几分钟。
49
- const GROUP_WAKE_TTL_MS = 10 * 60_000
49
+ // 「这一轮从哪条通道被叫起来」的保鲜期(读取规则在 presence-core.js)。
50
+ // 要比一次长回合宽:首 token 几十秒到几分钟。
50
51
 
51
52
  // 头像照片:一个人一张,文件名固定 `<成员>.<扩展名>`,换一张就覆盖旧的。
52
53
  // 上限 1.5 MB —— 够一张头像了;再大就是有人把整张截图塞进来,不该让群目录跟着长胖。
@@ -1091,20 +1092,12 @@ export function apply(ctx) {
1091
1092
  const beat = JSON.parse(readFileSync(join(PRESENCE_DIR, `${member}.json`), 'utf8'))
1092
1093
  const at = Number(beat?.at) || 0
1093
1094
  if (Date.now() - at <= PRESENCE_FRESH_MS) {
1094
- // reason 是"这一轮从哪来",不是"这句话回谁":
1095
- // 群唤醒会留 groupWakeAt,十分钟内算群里的;其余一律算"在别处忙",
1096
- // 因为宿主这里根本没有更细的信息,宁可含糊也不要编。
1097
- // 2026-11-13:分三档。原来只有 groupWakeAt,私聊唤醒没留痕,
1098
- // 于是"在回私聊"被一律显示成「正在忙」(他报的 bug)。
1099
- const wakeAt = Number(beat?.wakeAt) || 0
1100
- const kind = String(beat?.wakeKind ?? '')
1101
- const fresh = wakeAt > 0 && Date.now() - wakeAt <= GROUP_WAKE_TTL_MS
1102
- // 兼容旧心跳:只有 groupWakeAt 的那些进程。
1103
- const legacyAt = Number(beat?.groupWakeAt) || 0
1104
- const legacyFresh = legacyAt > 0 && Date.now() - legacyAt <= GROUP_WAKE_TTL_MS
1095
+ // reason 回答"这一轮从哪来",不是"这句话回谁"——规则在 presence-core.js。
1096
+ // 2026-11-19:心跳曾经把 wakeKind/wakeAt 洗掉,于是只剩「十分钟内从群叫醒」
1097
+ // 这一条线索,两种忙态总显示在错的一边;写入端已改成整条合并,这里只负责读。
1105
1098
  members[member] = {
1106
1099
  status: beat?.status === 'idle' ? 'idle' : 'working',
1107
- reason: fresh ? (kind === 'dm' ? 'dm' : 'group') : (legacyFresh ? 'group' : 'self'),
1100
+ reason: presenceReasonOf(beat, Date.now()),
1108
1101
  }
1109
1102
  }
1110
1103
  } catch {
@@ -1120,7 +1113,9 @@ export function apply(ctx) {
1120
1113
  const busy = agent?.status !== 'idle'
1121
1114
  if (busy) {
1122
1115
  const prev = members[member]
1123
- members[member] = { status: 'working', reason: prev?.reason === 'group' ? 'group' : 'self' }
1116
+ // 本进程只知道"忙不忙",不知道"为什么忙"——只改 status,别动 reason
1117
+ // (尤其别把 dm 压成 self:那会让私聊页把"正在回你"读成"正在忙")。
1118
+ members[member] = { ...(prev ?? {}), status: 'working', ...(prev?.reason ? {} : { reason: 'self' }) }
1124
1119
  }
1125
1120
  }
1126
1121
  } catch {
@@ -0,0 +1,33 @@
1
+ /**
2
+ * 面板怎么读一条 presence 心跳(2026-11-19 抽出)。
3
+ *
4
+ * `reason` 回答的是「这一轮从哪条通道被叫起来」,不是「这句话回谁」——
5
+ * 宿主那边没有更细的信息,宁可含糊也不要编。
6
+ *
7
+ * 2026-11-19 他报的 bug:LeeaCP 在回私聊时,群内显示「正在回复」、私聊显示「正在忙」。
8
+ * 根因不在读取端,在写入端:心跳把 wakeKind/wakeAt 抹掉了,只剩旧 groupWakeAt;
9
+ * 于是十分钟内一律读成 'group',群聊页按「在回这一段」显示、私聊页按「在别处忙」显示。
10
+ * 读取端这层规则本身是对的,抽出来是为了让"三种输入 → 三种结果"可以被断言。
11
+ */
12
+
13
+ export const WAKE_REASON_TTL_MS = 10 * 60_000
14
+
15
+ /**
16
+ * @param {{ wakeKind?: string, wakeAt?: number, groupWakeAt?: number } | null | undefined} beat
17
+ * @param {number} now
18
+ * @param {number} ttlMs
19
+ * @returns {'group' | 'dm' | 'self'}
20
+ */
21
+ export function presenceReasonOf(beat, now, ttlMs = WAKE_REASON_TTL_MS) {
22
+ const at = Number(now) || 0
23
+ const ttl = Number.isFinite(ttlMs) && ttlMs > 0 ? ttlMs : WAKE_REASON_TTL_MS
24
+ const fresh = (value) => Number(value) > 0 && at - Number(value) <= ttl
25
+
26
+ const wakeAt = beat?.wakeAt
27
+ if (fresh(wakeAt)) return String(beat?.wakeKind ?? '') === 'dm' ? 'dm' : 'group'
28
+
29
+ // 兼容旧心跳:只有 groupWakeAt 的那些进程。它只可能是群,不可能是私聊。
30
+ if (fresh(beat?.groupWakeAt)) return 'group'
31
+
32
+ return 'self'
33
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fabianactor/dsh-lil-whale-group-ui",
3
- "version": "1.11.0",
3
+ "version": "1.12.0",
4
4
  "type": "module",
5
5
  "description": "群聊页面:侧边栏一个图标,点开是三条鱼的群(读写 lil-whale\\group\\messages.jsonl)",
6
6
  "author": "Fabian",