openzca 0.1.54 → 0.1.55
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/dist/cli.js +156 -121
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -4414,6 +4414,19 @@ async function persistLiveDmContact(params) {
|
|
|
4414
4414
|
rawJson
|
|
4415
4415
|
});
|
|
4416
4416
|
}
|
|
4417
|
+
function extractGroupTitle(record) {
|
|
4418
|
+
if (!record) {
|
|
4419
|
+
return void 0;
|
|
4420
|
+
}
|
|
4421
|
+
return typeof record.name === "string" && record.name.trim() ? record.name.trim() : typeof record.groupName === "string" && record.groupName.trim() ? record.groupName.trim() : void 0;
|
|
4422
|
+
}
|
|
4423
|
+
async function findGroupDirectoryEntry(api, groupId) {
|
|
4424
|
+
const groups = await buildGroupsDetailed(api);
|
|
4425
|
+
return groups.find((item) => {
|
|
4426
|
+
const record = item;
|
|
4427
|
+
return normalizeCachedId(record.groupId ?? record.grid ?? record.threadId ?? record.id) === groupId;
|
|
4428
|
+
});
|
|
4429
|
+
}
|
|
4417
4430
|
async function hydrateUnknownLiveGroup(params) {
|
|
4418
4431
|
const existing = await getThreadInfo({
|
|
4419
4432
|
profile: params.profile,
|
|
@@ -4423,10 +4436,25 @@ async function hydrateUnknownLiveGroup(params) {
|
|
|
4423
4436
|
if (existing && (existing.title || typeof existing.memberCount === "number" && existing.memberCount > 0)) {
|
|
4424
4437
|
return;
|
|
4425
4438
|
}
|
|
4439
|
+
let group2;
|
|
4440
|
+
let title = params.fallbackTitle?.trim() || void 0;
|
|
4426
4441
|
try {
|
|
4427
4442
|
const info = await params.api.getGroupInfo(params.groupId);
|
|
4428
|
-
|
|
4429
|
-
|
|
4443
|
+
group2 = info.gridInfoMap[params.groupId];
|
|
4444
|
+
title = extractGroupTitle(group2) ?? title;
|
|
4445
|
+
} catch {
|
|
4446
|
+
}
|
|
4447
|
+
if (!group2 || !title) {
|
|
4448
|
+
try {
|
|
4449
|
+
const directoryGroup = await findGroupDirectoryEntry(params.api, params.groupId);
|
|
4450
|
+
if (directoryGroup) {
|
|
4451
|
+
group2 = group2 ?? directoryGroup;
|
|
4452
|
+
title = extractGroupTitle(directoryGroup) ?? title;
|
|
4453
|
+
}
|
|
4454
|
+
} catch {
|
|
4455
|
+
}
|
|
4456
|
+
}
|
|
4457
|
+
if (group2 || title) {
|
|
4430
4458
|
await persistThread({
|
|
4431
4459
|
profile: params.profile,
|
|
4432
4460
|
scopeThreadId: params.groupId,
|
|
@@ -4435,17 +4463,20 @@ async function hydrateUnknownLiveGroup(params) {
|
|
|
4435
4463
|
title,
|
|
4436
4464
|
rawJson: group2 ? JSON.stringify(group2) : void 0
|
|
4437
4465
|
});
|
|
4438
|
-
|
|
4439
|
-
|
|
4440
|
-
|
|
4441
|
-
await persistThread({
|
|
4442
|
-
profile: params.profile,
|
|
4443
|
-
scopeThreadId: params.groupId,
|
|
4444
|
-
rawThreadId: params.groupId,
|
|
4445
|
-
threadType: "group",
|
|
4446
|
-
title: params.fallbackTitle.trim()
|
|
4447
|
-
});
|
|
4466
|
+
try {
|
|
4467
|
+
await persistGroupMembersSnapshot(params.profile, params.groupId, params.api);
|
|
4468
|
+
} catch {
|
|
4448
4469
|
}
|
|
4470
|
+
return;
|
|
4471
|
+
}
|
|
4472
|
+
if (params.fallbackTitle?.trim()) {
|
|
4473
|
+
await persistThread({
|
|
4474
|
+
profile: params.profile,
|
|
4475
|
+
scopeThreadId: params.groupId,
|
|
4476
|
+
rawThreadId: params.groupId,
|
|
4477
|
+
threadType: "group",
|
|
4478
|
+
title: params.fallbackTitle.trim()
|
|
4479
|
+
});
|
|
4449
4480
|
}
|
|
4450
4481
|
}
|
|
4451
4482
|
async function syncDbGroupHistoryFull(params) {
|
|
@@ -4654,128 +4685,132 @@ async function syncDbChatsBestEffort(params) {
|
|
|
4654
4685
|
}
|
|
4655
4686
|
async function runDbSync(params) {
|
|
4656
4687
|
const { profile, api } = await requireApi(params.command);
|
|
4657
|
-
|
|
4658
|
-
|
|
4659
|
-
|
|
4660
|
-
|
|
4661
|
-
dbPath,
|
|
4662
|
-
params.mode === "all" || params.mode === "chats" || params.mode === "chat" ? params.count : void 0
|
|
4663
|
-
);
|
|
4664
|
-
const selfId = api.getOwnId();
|
|
4665
|
-
const selfInfo = normalizeMeInfoOutput(await api.fetchAccountInfo());
|
|
4666
|
-
await persistSelfProfile({
|
|
4667
|
-
profile,
|
|
4668
|
-
userId: selfId,
|
|
4669
|
-
displayName: typeof selfInfo.displayName === "string" && selfInfo.displayName.trim() ? selfInfo.displayName.trim() : void 0,
|
|
4670
|
-
infoJson: JSON.stringify(selfInfo)
|
|
4671
|
-
});
|
|
4672
|
-
const { pinnedIds, hiddenIds } = await collectConversationIds(api);
|
|
4673
|
-
let friendNames = /* @__PURE__ */ new Map();
|
|
4674
|
-
if (params.mode === "all" || params.mode === "friends" || params.mode === "chats") {
|
|
4675
|
-
friendNames = await syncDbFriendDirectory({
|
|
4688
|
+
try {
|
|
4689
|
+
const dbPath = await resolveDbPath(profile);
|
|
4690
|
+
params.progress?.(`starting sync for profile ${profile}`);
|
|
4691
|
+
const summary = createDbSyncSummary(
|
|
4676
4692
|
profile,
|
|
4677
|
-
|
|
4678
|
-
|
|
4679
|
-
|
|
4693
|
+
dbPath,
|
|
4694
|
+
params.mode === "all" || params.mode === "chats" || params.mode === "chat" ? params.count : void 0
|
|
4695
|
+
);
|
|
4696
|
+
const selfId = api.getOwnId();
|
|
4697
|
+
const selfInfo = normalizeMeInfoOutput(await api.fetchAccountInfo());
|
|
4698
|
+
await persistSelfProfile({
|
|
4699
|
+
profile,
|
|
4700
|
+
userId: selfId,
|
|
4701
|
+
displayName: typeof selfInfo.displayName === "string" && selfInfo.displayName.trim() ? selfInfo.displayName.trim() : void 0,
|
|
4702
|
+
infoJson: JSON.stringify(selfInfo)
|
|
4680
4703
|
});
|
|
4681
|
-
|
|
4682
|
-
|
|
4683
|
-
|
|
4684
|
-
|
|
4685
|
-
|
|
4686
|
-
|
|
4687
|
-
|
|
4688
|
-
|
|
4689
|
-
|
|
4690
|
-
|
|
4691
|
-
|
|
4692
|
-
|
|
4704
|
+
const { pinnedIds, hiddenIds } = await collectConversationIds(api);
|
|
4705
|
+
let friendNames = /* @__PURE__ */ new Map();
|
|
4706
|
+
if (params.mode === "all" || params.mode === "friends" || params.mode === "chats") {
|
|
4707
|
+
friendNames = await syncDbFriendDirectory({
|
|
4708
|
+
profile,
|
|
4709
|
+
api,
|
|
4710
|
+
summary,
|
|
4711
|
+
progress: params.progress
|
|
4712
|
+
});
|
|
4713
|
+
}
|
|
4714
|
+
if (params.mode === "all" || params.mode === "groups") {
|
|
4715
|
+
const groups = await buildGroupsDetailed(api);
|
|
4716
|
+
const targetGroupIds = /* @__PURE__ */ new Set();
|
|
4717
|
+
const titleById = /* @__PURE__ */ new Map();
|
|
4718
|
+
for (const group2 of groups) {
|
|
4719
|
+
const record = group2;
|
|
4720
|
+
const groupId = normalizeCachedId(record.groupId);
|
|
4721
|
+
if (!groupId) continue;
|
|
4722
|
+
const title = typeof record.name === "string" && record.name.trim() ? record.name.trim() : typeof record.groupName === "string" && record.groupName.trim() ? record.groupName.trim() : void 0;
|
|
4723
|
+
targetGroupIds.add(groupId);
|
|
4724
|
+
titleById.set(groupId, title);
|
|
4725
|
+
await prepareDbGroupTarget({
|
|
4726
|
+
profile,
|
|
4727
|
+
api,
|
|
4728
|
+
groupId,
|
|
4729
|
+
title,
|
|
4730
|
+
rawJson: JSON.stringify(group2),
|
|
4731
|
+
pinnedIds,
|
|
4732
|
+
hiddenIds
|
|
4733
|
+
});
|
|
4734
|
+
}
|
|
4735
|
+
await syncDbGroupHistoryFull({
|
|
4736
|
+
profile,
|
|
4737
|
+
api,
|
|
4738
|
+
selfId,
|
|
4739
|
+
targetGroupIds,
|
|
4740
|
+
titleById,
|
|
4741
|
+
summary,
|
|
4742
|
+
progress: params.progress
|
|
4743
|
+
});
|
|
4744
|
+
}
|
|
4745
|
+
if (params.mode === "group") {
|
|
4746
|
+
if (!params.groupId) {
|
|
4747
|
+
throw new Error("Missing group id for db sync group.");
|
|
4748
|
+
}
|
|
4749
|
+
const groupInfo = await api.getGroupInfo(params.groupId);
|
|
4750
|
+
const group2 = groupInfo.gridInfoMap[params.groupId];
|
|
4751
|
+
const title = typeof group2?.name === "string" && group2.name.trim() ? group2.name.trim() : void 0;
|
|
4693
4752
|
await prepareDbGroupTarget({
|
|
4694
4753
|
profile,
|
|
4695
4754
|
api,
|
|
4696
|
-
groupId,
|
|
4755
|
+
groupId: params.groupId,
|
|
4697
4756
|
title,
|
|
4698
|
-
rawJson: JSON.stringify(group2),
|
|
4757
|
+
rawJson: group2 ? JSON.stringify(group2) : void 0,
|
|
4699
4758
|
pinnedIds,
|
|
4700
4759
|
hiddenIds
|
|
4701
4760
|
});
|
|
4761
|
+
await syncDbGroupHistoryFull({
|
|
4762
|
+
profile,
|
|
4763
|
+
api,
|
|
4764
|
+
selfId,
|
|
4765
|
+
targetGroupIds: /* @__PURE__ */ new Set([params.groupId]),
|
|
4766
|
+
titleById: /* @__PURE__ */ new Map([[params.groupId, title]]),
|
|
4767
|
+
summary,
|
|
4768
|
+
progress: params.progress
|
|
4769
|
+
});
|
|
4702
4770
|
}
|
|
4703
|
-
|
|
4704
|
-
|
|
4705
|
-
|
|
4706
|
-
|
|
4707
|
-
|
|
4708
|
-
|
|
4709
|
-
|
|
4710
|
-
|
|
4711
|
-
|
|
4712
|
-
|
|
4713
|
-
|
|
4714
|
-
|
|
4715
|
-
|
|
4716
|
-
|
|
4717
|
-
|
|
4718
|
-
|
|
4719
|
-
|
|
4720
|
-
|
|
4721
|
-
|
|
4722
|
-
api,
|
|
4723
|
-
groupId: params.groupId,
|
|
4724
|
-
title,
|
|
4725
|
-
rawJson: group2 ? JSON.stringify(group2) : void 0,
|
|
4726
|
-
pinnedIds,
|
|
4727
|
-
hiddenIds
|
|
4728
|
-
});
|
|
4729
|
-
await syncDbGroupHistoryFull({
|
|
4730
|
-
profile,
|
|
4731
|
-
api,
|
|
4732
|
-
selfId,
|
|
4733
|
-
targetGroupIds: /* @__PURE__ */ new Set([params.groupId]),
|
|
4734
|
-
titleById: /* @__PURE__ */ new Map([[params.groupId, title]]),
|
|
4735
|
-
summary,
|
|
4736
|
-
progress: params.progress
|
|
4737
|
-
});
|
|
4738
|
-
}
|
|
4739
|
-
if (params.mode === "chat") {
|
|
4740
|
-
if (!params.threadId) {
|
|
4741
|
-
throw new Error("Missing chat id for db sync chat.");
|
|
4742
|
-
}
|
|
4743
|
-
if (friendNames.size === 0) {
|
|
4744
|
-
friendNames = await persistFriendDirectory(profile, api);
|
|
4771
|
+
if (params.mode === "chat") {
|
|
4772
|
+
if (!params.threadId) {
|
|
4773
|
+
throw new Error("Missing chat id for db sync chat.");
|
|
4774
|
+
}
|
|
4775
|
+
if (friendNames.size === 0) {
|
|
4776
|
+
friendNames = await persistFriendDirectory(profile, api);
|
|
4777
|
+
}
|
|
4778
|
+
await syncDbChatThread({
|
|
4779
|
+
profile,
|
|
4780
|
+
api,
|
|
4781
|
+
selfId,
|
|
4782
|
+
threadId: params.threadId,
|
|
4783
|
+
count: params.count,
|
|
4784
|
+
title: friendNames.get(params.threadId),
|
|
4785
|
+
pinnedIds,
|
|
4786
|
+
hiddenIds,
|
|
4787
|
+
summary,
|
|
4788
|
+
progress: params.progress
|
|
4789
|
+
});
|
|
4745
4790
|
}
|
|
4746
|
-
|
|
4747
|
-
|
|
4748
|
-
|
|
4749
|
-
|
|
4750
|
-
|
|
4751
|
-
|
|
4752
|
-
|
|
4753
|
-
|
|
4754
|
-
|
|
4755
|
-
|
|
4756
|
-
|
|
4757
|
-
|
|
4758
|
-
|
|
4759
|
-
|
|
4760
|
-
|
|
4761
|
-
friendNames = await persistFriendDirectory(profile, api);
|
|
4791
|
+
if (params.mode === "all" || params.mode === "chats") {
|
|
4792
|
+
if (friendNames.size === 0) {
|
|
4793
|
+
friendNames = await persistFriendDirectory(profile, api);
|
|
4794
|
+
}
|
|
4795
|
+
await syncDbChatsBestEffort({
|
|
4796
|
+
profile,
|
|
4797
|
+
api,
|
|
4798
|
+
selfId,
|
|
4799
|
+
count: params.count,
|
|
4800
|
+
titleById: friendNames,
|
|
4801
|
+
pinnedIds,
|
|
4802
|
+
hiddenIds,
|
|
4803
|
+
summary,
|
|
4804
|
+
progress: params.progress
|
|
4805
|
+
});
|
|
4762
4806
|
}
|
|
4763
|
-
|
|
4764
|
-
|
|
4765
|
-
|
|
4766
|
-
|
|
4767
|
-
|
|
4768
|
-
|
|
4769
|
-
pinnedIds,
|
|
4770
|
-
hiddenIds,
|
|
4771
|
-
summary,
|
|
4772
|
-
progress: params.progress
|
|
4773
|
-
});
|
|
4807
|
+
params.progress?.(
|
|
4808
|
+
`done: groups=${summary.groupsSynced}, groupMessages=${summary.groupMessagesImported}, friends=${summary.friendsSynced}, chats=${summary.chatsSynced}, dmMessages=${summary.dmMessagesImported}`
|
|
4809
|
+
);
|
|
4810
|
+
return summary;
|
|
4811
|
+
} finally {
|
|
4812
|
+
await closeDb(profile);
|
|
4774
4813
|
}
|
|
4775
|
-
params.progress?.(
|
|
4776
|
-
`done: groups=${summary.groupsSynced}, groupMessages=${summary.groupMessagesImported}, friends=${summary.friendsSynced}, chats=${summary.chatsSynced}, dmMessages=${summary.dmMessagesImported}`
|
|
4777
|
-
);
|
|
4778
|
-
return summary;
|
|
4779
4814
|
}
|
|
4780
4815
|
async function buildGroupsDetailed(api) {
|
|
4781
4816
|
const groups = await api.getAllGroups();
|