dsh-world 0.7.0 → 0.7.1
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/CHANGELOG.md +18 -0
- package/INSTALL.md +314 -314
- package/LICENSE +21 -21
- package/NOTES.md +14 -3
- package/README.md +5 -4
- package/client/index.js +47 -2
- package/cordis.patch.yml +6 -6
- package/lib/archive.d.ts +3 -1
- package/lib/archive.js +6 -4
- package/lib/console/routes.d.ts +5 -0
- package/lib/console/routes.js +15 -4
- package/lib/console/snapshot.d.ts +5 -0
- package/lib/console/snapshot.js +2 -1
- package/lib/ecosystem/qq/route.d.ts +2 -1
- package/lib/ecosystem/qq/route.js +10 -2
- package/lib/ecosystem/qq-native/batch.d.ts +2 -0
- package/lib/ecosystem/qq-native/batch.js +3 -1
- package/lib/ecosystem/qq-native/index.d.ts +2 -0
- package/lib/ecosystem/qq-native/index.js +4 -0
- package/lib/ecosystem/qq-native/replies.d.ts +6 -1
- package/lib/ecosystem/qq-native/replies.js +19 -1
- package/lib/ecosystem/shared/context.d.ts +1 -1
- package/lib/ecosystem/shared/context.js +1 -1
- package/lib/ecosystem/shared/identity.d.ts +12 -0
- package/lib/ecosystem/shared/identity.js +17 -1
- package/lib/ecosystem/shared/turn.d.ts +8 -5
- package/lib/ecosystem/shared/turn.js +16 -17
- package/lib/ecosystem/wechat/archive.d.ts +2 -0
- package/lib/ecosystem/wechat/archive.js +3 -1
- package/lib/ecosystem/wechat/home.js +9 -4
- package/lib/ecosystem/wechat/messages.d.ts +11 -0
- package/lib/ecosystem/wechat/messages.js +9 -1
- package/lib/ecosystem/wechat/sending.js +36 -9
- package/lib/ecosystem/wechat/supervisor.d.ts +11 -2
- package/lib/ecosystem/wechat/supervisor.js +90 -9
- package/lib/history.d.ts +6 -4
- package/lib/history.js +61 -12
- package/lib/index.js +7 -5
- package/lib/life/activity.d.ts +2 -0
- package/lib/life/activity.js +1 -1
- package/lib/life/alarm.d.ts +12 -4
- package/lib/life/alarm.js +21 -6
- package/lib/life/diary.d.ts +6 -0
- package/lib/life/diary.js +23 -2
- package/lib/life/runtime.d.ts +1 -0
- package/lib/life/runtime.js +57 -9
- package/lib/life/toolRegistry.d.ts +4 -3
- package/lib/life/toolRegistry.js +13 -3
- package/lib/life/types.d.ts +6 -1
- package/lib/memory.js +1 -4
- package/lib/memoryFiles.d.ts +1 -4
- package/lib/memoryFiles.js +18 -43
- package/lib/memoryStore.d.ts +1 -3
- package/lib/memoryStore.js +1 -1
- package/lib/memoryTools.js +2 -2
- package/lib/runtime.js +44 -89
- package/lib/sourceArchive.js +3 -4
- package/lib/store.d.ts +1 -1
- package/lib/store.js +1 -1
- package/lib/types.d.ts +1 -4
- package/lib/worldPrompt.js +1 -1
- package/lib/worldSwitch.d.ts +9 -1
- package/lib/worldSwitch.js +14 -1
- package/package.json +1 -1
- package/scripts/compact-home.mjs +29 -29
- package/scripts/enable-tool-free-compaction.ps1 +33 -33
- package/scripts/import-stickers.mjs +17 -17
- package/scripts/update-world.mjs +2 -2
- package/src/ecosystem/wechat/windows/README.md +2 -2
- package/src/ecosystem/wechat/windows/adapter.py +6 -0
- package/src/ecosystem/wechat/windows/engine/build.ps1 +8 -2
- package/src/ecosystem/wechat/windows/engine/profiles.json +114 -114
- package/src/ecosystem/wechat/windows/presence.py +109 -109
- package/src/ecosystem/wechat/windows/sender.py +17 -5
- package/templates/alarm.md +1 -1
|
@@ -1,33 +1,33 @@
|
|
|
1
|
-
param(
|
|
2
|
-
[Parameter(Mandatory = $true)]
|
|
3
|
-
[string] $profilePath
|
|
4
|
-
)
|
|
5
|
-
|
|
6
|
-
$ErrorActionPreference = 'Stop'
|
|
7
|
-
try {
|
|
8
|
-
$resolvedProfile = (Resolve-Path -LiteralPath $profilePath).Path
|
|
9
|
-
$packagePath = Join-Path $resolvedProfile 'package.json'
|
|
10
|
-
$patchPath = Join-Path $resolvedProfile 'cordis.patch.yml'
|
|
11
|
-
$package = Get-Content -LiteralPath $packagePath -Raw | ConvertFrom-Json
|
|
12
|
-
if (-not $package.dependencies.'dsh-world') {
|
|
13
|
-
throw 'Install the built dsh-world package in this profile before enabling its compaction backend.'
|
|
14
|
-
}
|
|
15
|
-
$content = [System.IO.File]::ReadAllText($patchPath)
|
|
16
|
-
if ($content -match '(?m)^\s*name:\s*[''"'']?dsh-world/compaction[''"'']?\s*$') {
|
|
17
|
-
Write-Output 'Tool-free compaction is already configured.'
|
|
18
|
-
return
|
|
19
|
-
}
|
|
20
|
-
$pattern = '(?m)^(\s*name:\s*)([''"'']?)@deepseek-ai/dsh-compaction-basic\2([ \t]*(?:#.*)?\r?)$'
|
|
21
|
-
$matchesFound = [regex]::Matches($content, $pattern)
|
|
22
|
-
if ($matchesFound.Count -ne 1) {
|
|
23
|
-
throw "Expected exactly one explicit compaction-basic entry in cordis.patch.yml; found $($matchesFound.Count). No configuration was changed."
|
|
24
|
-
}
|
|
25
|
-
$updated = [regex]::Replace($content, $pattern, '${1}''dsh-world/compaction''${3}')
|
|
26
|
-
$backupPath = "$patchPath.dsh-world.$([Guid]::NewGuid().ToString('N')).bak"
|
|
27
|
-
$temporaryPath = "$patchPath.$([Guid]::NewGuid().ToString('N')).tmp"
|
|
28
|
-
[System.IO.File]::WriteAllText($temporaryPath, $updated, [System.Text.UTF8Encoding]::new($false))
|
|
29
|
-
[System.IO.File]::Replace($temporaryPath, $patchPath, $backupPath)
|
|
30
|
-
Write-Output "Configured tool-free compaction. Restart this DSH profile to load it. Backup: $backupPath"
|
|
31
|
-
} catch {
|
|
32
|
-
throw "Cannot configure dsh-world compaction: $($_.Exception.Message)"
|
|
33
|
-
}
|
|
1
|
+
param(
|
|
2
|
+
[Parameter(Mandatory = $true)]
|
|
3
|
+
[string] $profilePath
|
|
4
|
+
)
|
|
5
|
+
|
|
6
|
+
$ErrorActionPreference = 'Stop'
|
|
7
|
+
try {
|
|
8
|
+
$resolvedProfile = (Resolve-Path -LiteralPath $profilePath).Path
|
|
9
|
+
$packagePath = Join-Path $resolvedProfile 'package.json'
|
|
10
|
+
$patchPath = Join-Path $resolvedProfile 'cordis.patch.yml'
|
|
11
|
+
$package = Get-Content -LiteralPath $packagePath -Raw | ConvertFrom-Json
|
|
12
|
+
if (-not $package.dependencies.'dsh-world') {
|
|
13
|
+
throw 'Install the built dsh-world package in this profile before enabling its compaction backend.'
|
|
14
|
+
}
|
|
15
|
+
$content = [System.IO.File]::ReadAllText($patchPath)
|
|
16
|
+
if ($content -match '(?m)^\s*name:\s*[''"'']?dsh-world/compaction[''"'']?\s*$') {
|
|
17
|
+
Write-Output 'Tool-free compaction is already configured.'
|
|
18
|
+
return
|
|
19
|
+
}
|
|
20
|
+
$pattern = '(?m)^(\s*name:\s*)([''"'']?)@deepseek-ai/dsh-compaction-basic\2([ \t]*(?:#.*)?\r?)$'
|
|
21
|
+
$matchesFound = [regex]::Matches($content, $pattern)
|
|
22
|
+
if ($matchesFound.Count -ne 1) {
|
|
23
|
+
throw "Expected exactly one explicit compaction-basic entry in cordis.patch.yml; found $($matchesFound.Count). No configuration was changed."
|
|
24
|
+
}
|
|
25
|
+
$updated = [regex]::Replace($content, $pattern, '${1}''dsh-world/compaction''${3}')
|
|
26
|
+
$backupPath = "$patchPath.dsh-world.$([Guid]::NewGuid().ToString('N')).bak"
|
|
27
|
+
$temporaryPath = "$patchPath.$([Guid]::NewGuid().ToString('N')).tmp"
|
|
28
|
+
[System.IO.File]::WriteAllText($temporaryPath, $updated, [System.Text.UTF8Encoding]::new($false))
|
|
29
|
+
[System.IO.File]::Replace($temporaryPath, $patchPath, $backupPath)
|
|
30
|
+
Write-Output "Configured tool-free compaction. Restart this DSH profile to load it. Backup: $backupPath"
|
|
31
|
+
} catch {
|
|
32
|
+
throw "Cannot configure dsh-world compaction: $($_.Exception.Message)"
|
|
33
|
+
}
|
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
// One-time import of the older sticker plugin's library (catalog.json + assets/) into the world's own sticker library.
|
|
2
|
-
// Usage: node scripts/import-stickers.mjs <older library folder, e.g. ~/.dsh/memes> <world folder, e.g. ~/.dsh/worlds/<id>>
|
|
3
|
-
// Ids, names and tags carry over; packs and long meanings do not. Running it again adds nothing. The older folder is only read.
|
|
4
|
-
import { join, resolve } from 'node:path';
|
|
5
|
-
import { pathToFileURL, fileURLToPath } from 'node:url';
|
|
6
|
-
|
|
7
|
-
const [legacy, world] = process.argv.slice(2);
|
|
8
|
-
if (!legacy || !world) {
|
|
9
|
-
console.error('用法:node scripts/import-stickers.mjs <旧表情包目录> <世界目录>');
|
|
10
|
-
process.exit(2);
|
|
11
|
-
}
|
|
12
|
-
const modulePath = join(fileURLToPath(new URL('..', import.meta.url)), 'lib', 'ecosystem', 'wechat', 'stickerLibrary.js');
|
|
13
|
-
const { createStickerLibrary, importLegacyStickers } = await import(pathToFileURL(modulePath).href);
|
|
14
|
-
const library = createStickerLibrary(join(resolve(world), 'stickers'));
|
|
15
|
-
const report = await importLegacyStickers(resolve(legacy), library);
|
|
16
|
-
console.log(`导入 ${report.imported} 张,已在库里的 ${report.duplicates} 张,跳过 ${report.skipped.length} 张;表情库现有 ${(await library.list()).length} 张。`);
|
|
17
|
-
for (const line of report.skipped) console.log(` 跳过 ${line}`);
|
|
1
|
+
// One-time import of the older sticker plugin's library (catalog.json + assets/) into the world's own sticker library.
|
|
2
|
+
// Usage: node scripts/import-stickers.mjs <older library folder, e.g. ~/.dsh/memes> <world folder, e.g. ~/.dsh/worlds/<id>>
|
|
3
|
+
// Ids, names and tags carry over; packs and long meanings do not. Running it again adds nothing. The older folder is only read.
|
|
4
|
+
import { join, resolve } from 'node:path';
|
|
5
|
+
import { pathToFileURL, fileURLToPath } from 'node:url';
|
|
6
|
+
|
|
7
|
+
const [legacy, world] = process.argv.slice(2);
|
|
8
|
+
if (!legacy || !world) {
|
|
9
|
+
console.error('用法:node scripts/import-stickers.mjs <旧表情包目录> <世界目录>');
|
|
10
|
+
process.exit(2);
|
|
11
|
+
}
|
|
12
|
+
const modulePath = join(fileURLToPath(new URL('..', import.meta.url)), 'lib', 'ecosystem', 'wechat', 'stickerLibrary.js');
|
|
13
|
+
const { createStickerLibrary, importLegacyStickers } = await import(pathToFileURL(modulePath).href);
|
|
14
|
+
const library = createStickerLibrary(join(resolve(world), 'stickers'));
|
|
15
|
+
const report = await importLegacyStickers(resolve(legacy), library);
|
|
16
|
+
console.log(`导入 ${report.imported} 张,已在库里的 ${report.duplicates} 张,跳过 ${report.skipped.length} 张;表情库现有 ${(await library.list()).length} 张。`);
|
|
17
|
+
for (const line of report.skipped) console.log(` 跳过 ${line}`);
|
package/scripts/update-world.mjs
CHANGED
|
@@ -7,8 +7,8 @@ import { fileURLToPath } from 'node:url';
|
|
|
7
7
|
import { isDeepStrictEqual, parseArgs, promisify } from 'node:util';
|
|
8
8
|
|
|
9
9
|
const execute = promisify(execFile);
|
|
10
|
-
const command = (file, args, options = {}) => execute(file, args, { windowsHide: true, maxBuffer: 16 * 1024 * 1024, ...options });
|
|
11
|
-
// GNU tar (the one Git Bash puts first) reads the `C:` of an archive path as a remote host; naming the archive from its own folder works with every tar.
|
|
10
|
+
const command = (file, args, options = {}) => execute(file, args, { windowsHide: true, maxBuffer: 16 * 1024 * 1024, ...options });
|
|
11
|
+
// GNU tar (the one Git Bash puts first) reads the `C:` of an archive path as a remote host; naming the archive from its own folder works with every tar.
|
|
12
12
|
const readArchive = (run, archive, args, options = {}) => run('tar', [args[0], basename(archive), ...args.slice(1)], { ...options, cwd: dirname(archive) });
|
|
13
13
|
const json = async file => JSON.parse((await readFile(file, 'utf8')).replace(/^\uFEFF/, ''));
|
|
14
14
|
async function exists(file) {
|
|
@@ -142,8 +142,8 @@ node <dsh-world 包目录>scriptsimport-stickers.mjs C:Usersyou.dshmemes C:Users
|
|
|
142
142
|
|
|
143
143
|
这不是微信官方 API。版本变更需重新校准,锁屏和群聊等实际条件必须分别验证。`engine/` 基于第三方原生 ABI 研究定制,保留独立的非商业许可与来源说明;该目录不适用仓库根目录的 MIT 许可。
|
|
144
144
|
|
|
145
|
-
4.1.15.56 的指纹与 19 个原生地址映射来自 [helper 的版本表](https://github.com/Prometheus-first/helper/blob/main/native/core_version.h)。两版沿用相同请求 ABI、账号核对和消息对象字段布局;版本表选择、地址编码及未知构建拒绝由离线测试覆盖。上游已实测新版文字收发及桥接加载卸载,媒体未逐项重做真实网络操作,详见其 [验证范围](https://github.com/Prometheus-first/helper/blob/main/native/README.md);本项目实测范围见下方日期记录。本次仅更新 Python 和版本表,无须重新编译未改动的 C++ 桥;新增构建或结构发生变化时仍需校准并实测。
|
|
146
|
-
|
|
145
|
+
4.1.15.56 的指纹与 19 个原生地址映射来自 [helper 的版本表](https://github.com/Prometheus-first/helper/blob/main/native/core_version.h)。两版沿用相同请求 ABI、账号核对和消息对象字段布局;版本表选择、地址编码及未知构建拒绝由离线测试覆盖。上游已实测新版文字收发及桥接加载卸载,媒体未逐项重做真实网络操作,详见其 [验证范围](https://github.com/Prometheus-first/helper/blob/main/native/README.md);本项目实测范围见下方日期记录。本次仅更新 Python 和版本表,无须重新编译未改动的 C++ 桥;新增构建或结构发生变化时仍需校准并实测。
|
|
146
|
+
|
|
147
147
|
4.2.0.11 与 4.2.0.12 的指纹和地址同样取自 helper 的版本表(按同一方法推出的 4.1.15.56 地址与已实测的配置逐项一致)。上游 4.2 只映射了文字、撤回和图片收发路径,原生 GIF 表情的 5 个地址没有映射,上游自己的表情发送在 4.2 上也直接拒绝;所以这两个构建的这 5 项为 null,原生桥只在发表情包时要求它们,文字和图片照常发送。在 4.2 上发表情包时,适配器把 GIF 转成一张静态 PNG 按图片发送:取第一帧,第一帧完全透明或只有一种颜色时改取最后一帧。**本项目没有 4.2 实机,以上未经真实微信验证**;首次使用请先向测试私聊各发一次文字、图片和表情包核对。原生桥源码因此改动,升级后需要重新运行 `wechat.ps1 Build`,否则适配器会以“原生桥源码已变化”拒绝加载。
|
|
148
148
|
|
|
149
149
|
2026-10-25 已在绑定的专用账号私聊中确认两条独立文字及一条原生表情(类型 47),并在选定家庭群补发确认一张原生表情和一条文字;均核对服务器消息编号,媒体内容同时核对 MD5。首次群会话的技能目录误判已修复并有回归测试。2026-10-26 已确认家庭群真实 @ 触发时读取两张缓存图片、模型描述图片并回群发送成功,附件引用保存在群会话日志,该群共享归档记录数仍为 0。该轮未测独立图片发送和锁屏运行。
|
|
@@ -17,6 +17,7 @@ from snapshot import NotSent, SnapshotBusy
|
|
|
17
17
|
from groups import DEFAULT_CONTEXT_MESSAGES, mentionedIds, recentContext
|
|
18
18
|
from incoming import ImageUnavailable, admitReference
|
|
19
19
|
from binding import WechatOffline
|
|
20
|
+
from sender import BuildStale
|
|
20
21
|
from messages import messageKey, messageOrder, normalizeMessage, messageNormalizer, messageEntry, displayMessage
|
|
21
22
|
from quotes import MessageContentError, isAppMessage
|
|
22
23
|
from reading import readHistory
|
|
@@ -32,6 +33,8 @@ CONTROL_TIMEOUT_SECONDS = 5
|
|
|
32
33
|
REPLY_TIMEOUT_SECONDS = 190
|
|
33
34
|
# Exit code for "a person must check WeChat and run acknowledge"; the plugin stops restarting the adapter on it.
|
|
34
35
|
EXIT_NEEDS_HUMAN = 2
|
|
36
|
+
# Exit code for "the native bridge must be built again"; the plugin builds it and starts the adapter again.
|
|
37
|
+
EXIT_NEEDS_BUILD = 3
|
|
35
38
|
# A reply whose send never started (no stable snapshot of the chat) is handed out again this many times in all.
|
|
36
39
|
SEND_ATTEMPTS = 3
|
|
37
40
|
|
|
@@ -682,6 +685,9 @@ if __name__ == '__main__':
|
|
|
682
685
|
except NeedsHuman as error:
|
|
683
686
|
print(f'微信适配器停止:{error}', file=sys.stderr)
|
|
684
687
|
sys.exit(EXIT_NEEDS_HUMAN)
|
|
688
|
+
except BuildStale as error:
|
|
689
|
+
print(f'微信适配器停止:{error}', file=sys.stderr)
|
|
690
|
+
sys.exit(EXIT_NEEDS_BUILD)
|
|
685
691
|
except Exception as error:
|
|
686
692
|
print(f'微信适配器停止:{error}', file=sys.stderr)
|
|
687
693
|
sys.exit(1)
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
# OutDir: where the adapter looks for the build (the `engine` folder beside its config.json); the repo's own by default.
|
|
2
|
+
param([string]$OutDir)
|
|
3
|
+
$ErrorActionPreference = 'Stop'
|
|
2
4
|
$workspaceRoot = [IO.Path]::GetFullPath((Join-Path $PSScriptRoot '../../../../..'))
|
|
3
|
-
$runtimeDir = Join-Path $workspaceRoot '.host\wechat\engine'
|
|
5
|
+
$runtimeDir = if ($OutDir) { [IO.Path]::GetFullPath($OutDir) } else { Join-Path $workspaceRoot '.host\wechat\engine' }
|
|
4
6
|
$source = Join-Path $PSScriptRoot 'bridge.cpp'
|
|
5
7
|
$sourceHash = (Get-FileHash -LiteralPath $source -Algorithm SHA256).Hash.ToLowerInvariant()
|
|
6
8
|
$outputDir = Join-Path $runtimeDir $sourceHash.Substring(0,12)
|
|
@@ -16,4 +18,8 @@ $buildScript = Join-Path $outputDir 'build.cmd'
|
|
|
16
18
|
& $env:ComSpec /d /c $buildScript
|
|
17
19
|
if ($LASTEXITCODE -ne 0) { throw '原生桥构建失败' }
|
|
18
20
|
@{file=$dll; sha256=(Get-FileHash -LiteralPath $dll -Algorithm SHA256).Hash.ToLowerInvariant(); sourceSha256=$sourceHash} | ConvertTo-Json | Set-Content -LiteralPath (Join-Path $runtimeDir 'current.json') -Encoding utf8
|
|
21
|
+
# Older builds are never loaded again (current.json names only this one); one WeChat still holds open is left for next time.
|
|
22
|
+
Get-ChildItem -LiteralPath $runtimeDir -Directory | Where-Object { $_.Name -match '^[0-9a-f]{12}$' -and $_.FullName -ne $outputDir } | ForEach-Object {
|
|
23
|
+
try { Remove-Item -LiteralPath $_.FullName -Recurse -Force -ErrorAction Stop } catch { Write-Output "旧构建暂时删不掉,下次再删:$($_.Exception.Message)" }
|
|
24
|
+
}
|
|
19
25
|
Write-Output $dll
|
|
@@ -1,114 +1,114 @@
|
|
|
1
|
-
[
|
|
2
|
-
{
|
|
3
|
-
"version": "4.1.15.13",
|
|
4
|
-
"size": 201552944,
|
|
5
|
-
"sha256": "10f8e995453e2da46d4f2b5080cd6da1f13cc5147746adc119ceae38cb039de5",
|
|
6
|
-
"timestamp": 1789961080,
|
|
7
|
-
"imageSize": 202039296,
|
|
8
|
-
"addresses": {
|
|
9
|
-
"application": 285968,
|
|
10
|
-
"scheduler": 291600,
|
|
11
|
-
"schedule": 3125264,
|
|
12
|
-
"context": 291360,
|
|
13
|
-
"provider": 3589952,
|
|
14
|
-
"manager": 7294352,
|
|
15
|
-
"text": 88802032,
|
|
16
|
-
"image": 64608656,
|
|
17
|
-
"emoticon": 29340096,
|
|
18
|
-
"copyWide": 636368,
|
|
19
|
-
"validateGif": 15182048,
|
|
20
|
-
"probeGif": 5441984,
|
|
21
|
-
"releaseProbe": 5137248,
|
|
22
|
-
"send": 24703232,
|
|
23
|
-
"allocate": 122337436,
|
|
24
|
-
"free": 122337504,
|
|
25
|
-
"accountRoot": 194061968,
|
|
26
|
-
"contextVtable": 148890360,
|
|
27
|
-
"emoticonVtable": 151891960
|
|
28
|
-
}
|
|
29
|
-
},
|
|
30
|
-
{
|
|
31
|
-
"version": "4.1.15.56",
|
|
32
|
-
"size": 204305968,
|
|
33
|
-
"sha256": "e0428a7b691853de496532523c2c09aa095f90941c37c9f4cfb3f137f3c66556",
|
|
34
|
-
"timestamp": 1792050120,
|
|
35
|
-
"imageSize": 204795904,
|
|
36
|
-
"addresses": {
|
|
37
|
-
"application": 285968,
|
|
38
|
-
"scheduler": 291600,
|
|
39
|
-
"schedule": 3208272,
|
|
40
|
-
"context": 291360,
|
|
41
|
-
"provider": 3679184,
|
|
42
|
-
"manager": 7377536,
|
|
43
|
-
"text": 90112896,
|
|
44
|
-
"image": 65154416,
|
|
45
|
-
"emoticon": 29436416,
|
|
46
|
-
"copyWide": 636384,
|
|
47
|
-
"validateGif": 15343584,
|
|
48
|
-
"probeGif": 5528896,
|
|
49
|
-
"releaseProbe": 5224160,
|
|
50
|
-
"send": 24788000,
|
|
51
|
-
"allocate": 122993884,
|
|
52
|
-
"free": 122993952,
|
|
53
|
-
"accountRoot": 196685728,
|
|
54
|
-
"contextVtable": 150803560,
|
|
55
|
-
"emoticonVtable": 153824520
|
|
56
|
-
}
|
|
57
|
-
},
|
|
58
|
-
{
|
|
59
|
-
"version": "4.2.0.11",
|
|
60
|
-
"size": 205929008,
|
|
61
|
-
"sha256": "745cdf2955fa5128cdb00c056c97571156a5f107406a9bb15ac0754f3246b201",
|
|
62
|
-
"timestamp": 1793108177,
|
|
63
|
-
"imageSize": 206422016,
|
|
64
|
-
"addresses": {
|
|
65
|
-
"application": 285968,
|
|
66
|
-
"scheduler": 291600,
|
|
67
|
-
"schedule": 3217808,
|
|
68
|
-
"context": 291360,
|
|
69
|
-
"provider": 3688240,
|
|
70
|
-
"manager": 7456256,
|
|
71
|
-
"text": 91356448,
|
|
72
|
-
"image": 65819968,
|
|
73
|
-
"emoticon": null,
|
|
74
|
-
"copyWide": 636384,
|
|
75
|
-
"validateGif": null,
|
|
76
|
-
"probeGif": null,
|
|
77
|
-
"releaseProbe": null,
|
|
78
|
-
"send": 24965648,
|
|
79
|
-
"allocate": 124404668,
|
|
80
|
-
"free": 124404736,
|
|
81
|
-
"accountRoot": 198233648,
|
|
82
|
-
"contextVtable": 151867272,
|
|
83
|
-
"emoticonVtable": null
|
|
84
|
-
}
|
|
85
|
-
},
|
|
86
|
-
{
|
|
87
|
-
"version": "4.2.0.12",
|
|
88
|
-
"size": 205932072,
|
|
89
|
-
"sha256": "2b3677c3f932daaa4ef84c8b2acd0aee12cbe5a779ff9e740c370761e5c291ce",
|
|
90
|
-
"timestamp": 1793275655,
|
|
91
|
-
"imageSize": 206417920,
|
|
92
|
-
"addresses": {
|
|
93
|
-
"application": 285968,
|
|
94
|
-
"scheduler": 291600,
|
|
95
|
-
"schedule": 3217808,
|
|
96
|
-
"context": 291360,
|
|
97
|
-
"provider": 3688240,
|
|
98
|
-
"manager": 7451520,
|
|
99
|
-
"text": 91361344,
|
|
100
|
-
"image": 65824848,
|
|
101
|
-
"emoticon": null,
|
|
102
|
-
"copyWide": 636384,
|
|
103
|
-
"validateGif": null,
|
|
104
|
-
"probeGif": null,
|
|
105
|
-
"releaseProbe": null,
|
|
106
|
-
"send": 24962240,
|
|
107
|
-
"allocate": 124408764,
|
|
108
|
-
"free": 124408832,
|
|
109
|
-
"accountRoot": 198233648,
|
|
110
|
-
"contextVtable": 151871336,
|
|
111
|
-
"emoticonVtable": null
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
]
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"version": "4.1.15.13",
|
|
4
|
+
"size": 201552944,
|
|
5
|
+
"sha256": "10f8e995453e2da46d4f2b5080cd6da1f13cc5147746adc119ceae38cb039de5",
|
|
6
|
+
"timestamp": 1789961080,
|
|
7
|
+
"imageSize": 202039296,
|
|
8
|
+
"addresses": {
|
|
9
|
+
"application": 285968,
|
|
10
|
+
"scheduler": 291600,
|
|
11
|
+
"schedule": 3125264,
|
|
12
|
+
"context": 291360,
|
|
13
|
+
"provider": 3589952,
|
|
14
|
+
"manager": 7294352,
|
|
15
|
+
"text": 88802032,
|
|
16
|
+
"image": 64608656,
|
|
17
|
+
"emoticon": 29340096,
|
|
18
|
+
"copyWide": 636368,
|
|
19
|
+
"validateGif": 15182048,
|
|
20
|
+
"probeGif": 5441984,
|
|
21
|
+
"releaseProbe": 5137248,
|
|
22
|
+
"send": 24703232,
|
|
23
|
+
"allocate": 122337436,
|
|
24
|
+
"free": 122337504,
|
|
25
|
+
"accountRoot": 194061968,
|
|
26
|
+
"contextVtable": 148890360,
|
|
27
|
+
"emoticonVtable": 151891960
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
"version": "4.1.15.56",
|
|
32
|
+
"size": 204305968,
|
|
33
|
+
"sha256": "e0428a7b691853de496532523c2c09aa095f90941c37c9f4cfb3f137f3c66556",
|
|
34
|
+
"timestamp": 1792050120,
|
|
35
|
+
"imageSize": 204795904,
|
|
36
|
+
"addresses": {
|
|
37
|
+
"application": 285968,
|
|
38
|
+
"scheduler": 291600,
|
|
39
|
+
"schedule": 3208272,
|
|
40
|
+
"context": 291360,
|
|
41
|
+
"provider": 3679184,
|
|
42
|
+
"manager": 7377536,
|
|
43
|
+
"text": 90112896,
|
|
44
|
+
"image": 65154416,
|
|
45
|
+
"emoticon": 29436416,
|
|
46
|
+
"copyWide": 636384,
|
|
47
|
+
"validateGif": 15343584,
|
|
48
|
+
"probeGif": 5528896,
|
|
49
|
+
"releaseProbe": 5224160,
|
|
50
|
+
"send": 24788000,
|
|
51
|
+
"allocate": 122993884,
|
|
52
|
+
"free": 122993952,
|
|
53
|
+
"accountRoot": 196685728,
|
|
54
|
+
"contextVtable": 150803560,
|
|
55
|
+
"emoticonVtable": 153824520
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
"version": "4.2.0.11",
|
|
60
|
+
"size": 205929008,
|
|
61
|
+
"sha256": "745cdf2955fa5128cdb00c056c97571156a5f107406a9bb15ac0754f3246b201",
|
|
62
|
+
"timestamp": 1793108177,
|
|
63
|
+
"imageSize": 206422016,
|
|
64
|
+
"addresses": {
|
|
65
|
+
"application": 285968,
|
|
66
|
+
"scheduler": 291600,
|
|
67
|
+
"schedule": 3217808,
|
|
68
|
+
"context": 291360,
|
|
69
|
+
"provider": 3688240,
|
|
70
|
+
"manager": 7456256,
|
|
71
|
+
"text": 91356448,
|
|
72
|
+
"image": 65819968,
|
|
73
|
+
"emoticon": null,
|
|
74
|
+
"copyWide": 636384,
|
|
75
|
+
"validateGif": null,
|
|
76
|
+
"probeGif": null,
|
|
77
|
+
"releaseProbe": null,
|
|
78
|
+
"send": 24965648,
|
|
79
|
+
"allocate": 124404668,
|
|
80
|
+
"free": 124404736,
|
|
81
|
+
"accountRoot": 198233648,
|
|
82
|
+
"contextVtable": 151867272,
|
|
83
|
+
"emoticonVtable": null
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
"version": "4.2.0.12",
|
|
88
|
+
"size": 205932072,
|
|
89
|
+
"sha256": "2b3677c3f932daaa4ef84c8b2acd0aee12cbe5a779ff9e740c370761e5c291ce",
|
|
90
|
+
"timestamp": 1793275655,
|
|
91
|
+
"imageSize": 206417920,
|
|
92
|
+
"addresses": {
|
|
93
|
+
"application": 285968,
|
|
94
|
+
"scheduler": 291600,
|
|
95
|
+
"schedule": 3217808,
|
|
96
|
+
"context": 291360,
|
|
97
|
+
"provider": 3688240,
|
|
98
|
+
"manager": 7451520,
|
|
99
|
+
"text": 91361344,
|
|
100
|
+
"image": 65824848,
|
|
101
|
+
"emoticon": null,
|
|
102
|
+
"copyWide": 636384,
|
|
103
|
+
"validateGif": null,
|
|
104
|
+
"probeGif": null,
|
|
105
|
+
"releaseProbe": null,
|
|
106
|
+
"send": 24962240,
|
|
107
|
+
"allocate": 124408764,
|
|
108
|
+
"free": 124408832,
|
|
109
|
+
"accountRoot": 198233648,
|
|
110
|
+
"contextVtable": 151871336,
|
|
111
|
+
"emoticonVtable": null
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
]
|
|
@@ -1,109 +1,109 @@
|
|
|
1
|
-
"""One durable metadata row per account/group; no message body, wake or model call."""
|
|
2
|
-
from datetime import datetime, timezone
|
|
3
|
-
import json
|
|
4
|
-
from messages import messageKey, messageOrder, recentEntries
|
|
5
|
-
from snapshot import SnapshotBusy
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
class GroupPresence:
|
|
9
|
-
def __init__(self, db):
|
|
10
|
-
self.db = db
|
|
11
|
-
db.execute('''CREATE TABLE IF NOT EXISTS groupPresence(
|
|
12
|
-
accountId TEXT, chatId TEXT, count INTEGER NOT NULL,
|
|
13
|
-
seq INTEGER, shard TEXT, localId INTEGER, lastAt TEXT, speaker TEXT, self INTEGER,
|
|
14
|
-
readSeq INTEGER NOT NULL DEFAULT 0, readShard TEXT NOT NULL DEFAULT '', readId INTEGER NOT NULL DEFAULT 0,
|
|
15
|
-
seen TEXT NOT NULL DEFAULT '[]', readSeen TEXT NOT NULL DEFAULT '[]',
|
|
16
|
-
PRIMARY KEY(accountId,chatId))''')
|
|
17
|
-
|
|
18
|
-
def _get(self, account, chat):
|
|
19
|
-
return self.db.execute('SELECT count,seq,shard,localId,lastAt,speaker,self,readSeq,readShard,readId,seen,readSeen '
|
|
20
|
-
'FROM groupPresence WHERE accountId=? AND chatId=? LIMIT 1', (account, chat)).fetchone()
|
|
21
|
-
|
|
22
|
-
def observe(self, account, chat, row, speaker, *, unread=True):
|
|
23
|
-
if row['type'] == '系统消息': return
|
|
24
|
-
if not row.get('sender_username'): raise ValueError('群动态缺少真实发言人')
|
|
25
|
-
order = messageOrder(row)
|
|
26
|
-
previous = self._get(account, chat)
|
|
27
|
-
if previous and order[0] < previous[1]: return
|
|
28
|
-
sameSeq = bool(previous and order[0] == previous[1])
|
|
29
|
-
seen = set(json.loads(previous[10])) if sameSeq else set()
|
|
30
|
-
key = messageKey(row)
|
|
31
|
-
if key in seen: return
|
|
32
|
-
seen.add(key)
|
|
33
|
-
read = tuple(previous[7:10]) if previous else (0, '', 0)
|
|
34
|
-
own = row['sender_username'] == account
|
|
35
|
-
count = (previous[0] if previous else 0) + int(unread and not own and (order > read or (sameSeq and order[0] == read[0])))
|
|
36
|
-
at = datetime.fromtimestamp(int(row['create_time']), timezone.utc).isoformat()
|
|
37
|
-
metadata = (at, str(speaker)[:80], int(own))
|
|
38
|
-
if sameSeq and order < tuple(previous[1:4]):
|
|
39
|
-
order, metadata = tuple(previous[1:4]), tuple(previous[4:7])
|
|
40
|
-
with self.db:
|
|
41
|
-
self.db.execute('INSERT INTO groupPresence VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?) '
|
|
42
|
-
'ON CONFLICT(accountId,chatId) DO UPDATE SET count=excluded.count,seq=excluded.seq,'
|
|
43
|
-
'shard=excluded.shard,localId=excluded.localId,lastAt=excluded.lastAt,speaker=excluded.speaker,self=excluded.self,seen=excluded.seen',
|
|
44
|
-
(account, chat, count, *order, *metadata, *read, json.dumps(sorted(seen)), previous[11] if previous else '[]'))
|
|
45
|
-
|
|
46
|
-
def markRead(self, account, chat, through, countRemaining=None, seenKeys=()):
|
|
47
|
-
previous = self._get(account, chat)
|
|
48
|
-
boundary = tuple(through)
|
|
49
|
-
if not previous:
|
|
50
|
-
with self.db:
|
|
51
|
-
self.db.execute('INSERT INTO groupPresence(accountId,chatId,count,seq,shard,localId,readSeq,readShard,readId,readSeen) VALUES (?,?,0,0,\'\',0,?,?,?,?)', (account, chat, *boundary, json.dumps(sorted(seenKeys))))
|
|
52
|
-
return
|
|
53
|
-
read = max(tuple(previous[7:10]), boundary)
|
|
54
|
-
seen = set(json.loads(previous[10]))
|
|
55
|
-
if boundary[0] == previous[1]: seen.update(seenKeys)
|
|
56
|
-
readSeen = set(json.loads(previous[11])) if boundary[0] == previous[7] else set()
|
|
57
|
-
if boundary < tuple(previous[7:10]) or (boundary == tuple(previous[7:10]) and not set(seenKeys) - readSeen): return
|
|
58
|
-
readSeen.update(seenKeys)
|
|
59
|
-
remaining = 0
|
|
60
|
-
if boundary < tuple(previous[1:4]):
|
|
61
|
-
if countRemaining is None: raise ValueError('旧读取结果需要核对尚未读到的群消息')
|
|
62
|
-
remaining = min(previous[0], countRemaining(boundary, tuple(previous[1:4])))
|
|
63
|
-
with self.db:
|
|
64
|
-
self.db.execute('UPDATE groupPresence SET count=?,readSeq=?,readShard=?,readId=?,seen=?,readSeen=? WHERE accountId=? AND chatId=?',
|
|
65
|
-
(remaining, *read, json.dumps(sorted(seen)), json.dumps(sorted(readSeen)), account, chat))
|
|
66
|
-
|
|
67
|
-
def snapshot(self, config):
|
|
68
|
-
groups = []
|
|
69
|
-
for chat in config['chats']:
|
|
70
|
-
if not chat['id'].endswith('@chatroom'): continue
|
|
71
|
-
row = self._get(config['selfId'], chat['id'])
|
|
72
|
-
if row and row[4]:
|
|
73
|
-
groups.append(dict(chatId=chat['id'], count=min(100, row[0]), lastAt=row[4], lastSpeaker=row[5], lastSelf=bool(row[6])))
|
|
74
|
-
# Keep the existing control poll bounded even with many configured groups.
|
|
75
|
-
return sorted(groups, key=lambda item: (item['count'] > 0, item['lastAt']), reverse=True)[:8]
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
def speakerName(database, config, row):
|
|
79
|
-
sender = row.get('sender_username')
|
|
80
|
-
if not sender: raise ValueError('群动态缺少真实发言人')
|
|
81
|
-
return config.get('people', {}).get(sender) or database.get_nickname(sender) or sender
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
def seedPresence(database, store, config, chat):
|
|
85
|
-
presence = store.presence
|
|
86
|
-
previous = presence._get(config['selfId'], chat['id'])
|
|
87
|
-
if not chat['id'].endswith('@chatroom') or (previous and previous[4]): return
|
|
88
|
-
cursor = store.cursor(chat['id'])
|
|
89
|
-
if cursor is None: return
|
|
90
|
-
found = recentEntries(database, chat['id'], lambda row: row if int(row['sort_seq']) <= cursor and row['type'] != '系统消息' else None,
|
|
91
|
-
config.get('pageSize', 50), 1)
|
|
92
|
-
if found:
|
|
93
|
-
latest = next(reversed(found.values()))
|
|
94
|
-
presence.observe(config['selfId'], chat['id'], latest, speakerName(database, config, latest), unread=False)
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
def unreadAfter(database, config, chat, after, until):
|
|
98
|
-
offset, size, found = 0, config.get('pageSize', 50), set()
|
|
99
|
-
while True:
|
|
100
|
-
rows = database.get_messages(chat, limit=size, offset=offset)
|
|
101
|
-
if offset == 0 and (not rows or max(int(row['sort_seq']) for row in rows) < until[0]):
|
|
102
|
-
raise SnapshotBusy('群消息快照落后于已观察位置,保留未读等待重读')
|
|
103
|
-
for row in rows:
|
|
104
|
-
order = messageOrder(row)
|
|
105
|
-
if after < order <= until and row['type'] != '系统消息':
|
|
106
|
-
if not row.get('sender_username'): raise ValueError('群动态缺少真实发言人')
|
|
107
|
-
if row['sender_username'] != config['selfId']: found.add(order)
|
|
108
|
-
if len(rows) < size or any(int(row['sort_seq']) < after[0] for row in rows): return len(found)
|
|
109
|
-
offset += len(rows)
|
|
1
|
+
"""One durable metadata row per account/group; no message body, wake or model call."""
|
|
2
|
+
from datetime import datetime, timezone
|
|
3
|
+
import json
|
|
4
|
+
from messages import messageKey, messageOrder, recentEntries
|
|
5
|
+
from snapshot import SnapshotBusy
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class GroupPresence:
|
|
9
|
+
def __init__(self, db):
|
|
10
|
+
self.db = db
|
|
11
|
+
db.execute('''CREATE TABLE IF NOT EXISTS groupPresence(
|
|
12
|
+
accountId TEXT, chatId TEXT, count INTEGER NOT NULL,
|
|
13
|
+
seq INTEGER, shard TEXT, localId INTEGER, lastAt TEXT, speaker TEXT, self INTEGER,
|
|
14
|
+
readSeq INTEGER NOT NULL DEFAULT 0, readShard TEXT NOT NULL DEFAULT '', readId INTEGER NOT NULL DEFAULT 0,
|
|
15
|
+
seen TEXT NOT NULL DEFAULT '[]', readSeen TEXT NOT NULL DEFAULT '[]',
|
|
16
|
+
PRIMARY KEY(accountId,chatId))''')
|
|
17
|
+
|
|
18
|
+
def _get(self, account, chat):
|
|
19
|
+
return self.db.execute('SELECT count,seq,shard,localId,lastAt,speaker,self,readSeq,readShard,readId,seen,readSeen '
|
|
20
|
+
'FROM groupPresence WHERE accountId=? AND chatId=? LIMIT 1', (account, chat)).fetchone()
|
|
21
|
+
|
|
22
|
+
def observe(self, account, chat, row, speaker, *, unread=True):
|
|
23
|
+
if row['type'] == '系统消息': return
|
|
24
|
+
if not row.get('sender_username'): raise ValueError('群动态缺少真实发言人')
|
|
25
|
+
order = messageOrder(row)
|
|
26
|
+
previous = self._get(account, chat)
|
|
27
|
+
if previous and order[0] < previous[1]: return
|
|
28
|
+
sameSeq = bool(previous and order[0] == previous[1])
|
|
29
|
+
seen = set(json.loads(previous[10])) if sameSeq else set()
|
|
30
|
+
key = messageKey(row)
|
|
31
|
+
if key in seen: return
|
|
32
|
+
seen.add(key)
|
|
33
|
+
read = tuple(previous[7:10]) if previous else (0, '', 0)
|
|
34
|
+
own = row['sender_username'] == account
|
|
35
|
+
count = (previous[0] if previous else 0) + int(unread and not own and (order > read or (sameSeq and order[0] == read[0])))
|
|
36
|
+
at = datetime.fromtimestamp(int(row['create_time']), timezone.utc).isoformat()
|
|
37
|
+
metadata = (at, str(speaker)[:80], int(own))
|
|
38
|
+
if sameSeq and order < tuple(previous[1:4]):
|
|
39
|
+
order, metadata = tuple(previous[1:4]), tuple(previous[4:7])
|
|
40
|
+
with self.db:
|
|
41
|
+
self.db.execute('INSERT INTO groupPresence VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?) '
|
|
42
|
+
'ON CONFLICT(accountId,chatId) DO UPDATE SET count=excluded.count,seq=excluded.seq,'
|
|
43
|
+
'shard=excluded.shard,localId=excluded.localId,lastAt=excluded.lastAt,speaker=excluded.speaker,self=excluded.self,seen=excluded.seen',
|
|
44
|
+
(account, chat, count, *order, *metadata, *read, json.dumps(sorted(seen)), previous[11] if previous else '[]'))
|
|
45
|
+
|
|
46
|
+
def markRead(self, account, chat, through, countRemaining=None, seenKeys=()):
|
|
47
|
+
previous = self._get(account, chat)
|
|
48
|
+
boundary = tuple(through)
|
|
49
|
+
if not previous:
|
|
50
|
+
with self.db:
|
|
51
|
+
self.db.execute('INSERT INTO groupPresence(accountId,chatId,count,seq,shard,localId,readSeq,readShard,readId,readSeen) VALUES (?,?,0,0,\'\',0,?,?,?,?)', (account, chat, *boundary, json.dumps(sorted(seenKeys))))
|
|
52
|
+
return
|
|
53
|
+
read = max(tuple(previous[7:10]), boundary)
|
|
54
|
+
seen = set(json.loads(previous[10]))
|
|
55
|
+
if boundary[0] == previous[1]: seen.update(seenKeys)
|
|
56
|
+
readSeen = set(json.loads(previous[11])) if boundary[0] == previous[7] else set()
|
|
57
|
+
if boundary < tuple(previous[7:10]) or (boundary == tuple(previous[7:10]) and not set(seenKeys) - readSeen): return
|
|
58
|
+
readSeen.update(seenKeys)
|
|
59
|
+
remaining = 0
|
|
60
|
+
if boundary < tuple(previous[1:4]):
|
|
61
|
+
if countRemaining is None: raise ValueError('旧读取结果需要核对尚未读到的群消息')
|
|
62
|
+
remaining = min(previous[0], countRemaining(boundary, tuple(previous[1:4])))
|
|
63
|
+
with self.db:
|
|
64
|
+
self.db.execute('UPDATE groupPresence SET count=?,readSeq=?,readShard=?,readId=?,seen=?,readSeen=? WHERE accountId=? AND chatId=?',
|
|
65
|
+
(remaining, *read, json.dumps(sorted(seen)), json.dumps(sorted(readSeen)), account, chat))
|
|
66
|
+
|
|
67
|
+
def snapshot(self, config):
|
|
68
|
+
groups = []
|
|
69
|
+
for chat in config['chats']:
|
|
70
|
+
if not chat['id'].endswith('@chatroom'): continue
|
|
71
|
+
row = self._get(config['selfId'], chat['id'])
|
|
72
|
+
if row and row[4]:
|
|
73
|
+
groups.append(dict(chatId=chat['id'], count=min(100, row[0]), lastAt=row[4], lastSpeaker=row[5], lastSelf=bool(row[6])))
|
|
74
|
+
# Keep the existing control poll bounded even with many configured groups.
|
|
75
|
+
return sorted(groups, key=lambda item: (item['count'] > 0, item['lastAt']), reverse=True)[:8]
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def speakerName(database, config, row):
|
|
79
|
+
sender = row.get('sender_username')
|
|
80
|
+
if not sender: raise ValueError('群动态缺少真实发言人')
|
|
81
|
+
return config.get('people', {}).get(sender) or database.get_nickname(sender) or sender
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
def seedPresence(database, store, config, chat):
|
|
85
|
+
presence = store.presence
|
|
86
|
+
previous = presence._get(config['selfId'], chat['id'])
|
|
87
|
+
if not chat['id'].endswith('@chatroom') or (previous and previous[4]): return
|
|
88
|
+
cursor = store.cursor(chat['id'])
|
|
89
|
+
if cursor is None: return
|
|
90
|
+
found = recentEntries(database, chat['id'], lambda row: row if int(row['sort_seq']) <= cursor and row['type'] != '系统消息' else None,
|
|
91
|
+
config.get('pageSize', 50), 1)
|
|
92
|
+
if found:
|
|
93
|
+
latest = next(reversed(found.values()))
|
|
94
|
+
presence.observe(config['selfId'], chat['id'], latest, speakerName(database, config, latest), unread=False)
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
def unreadAfter(database, config, chat, after, until):
|
|
98
|
+
offset, size, found = 0, config.get('pageSize', 50), set()
|
|
99
|
+
while True:
|
|
100
|
+
rows = database.get_messages(chat, limit=size, offset=offset)
|
|
101
|
+
if offset == 0 and (not rows or max(int(row['sort_seq']) for row in rows) < until[0]):
|
|
102
|
+
raise SnapshotBusy('群消息快照落后于已观察位置,保留未读等待重读')
|
|
103
|
+
for row in rows:
|
|
104
|
+
order = messageOrder(row)
|
|
105
|
+
if after < order <= until and row['type'] != '系统消息':
|
|
106
|
+
if not row.get('sender_username'): raise ValueError('群动态缺少真实发言人')
|
|
107
|
+
if row['sender_username'] != config['selfId']: found.add(order)
|
|
108
|
+
if len(rows) < size or any(int(row['sort_seq']) < after[0] for row in rows): return len(found)
|
|
109
|
+
offset += len(rows)
|