Compact imported single-thread conversation copy

This commit is contained in:
kris
2026-04-07 12:49:53 +08:00
parent c5223c7c16
commit a43bb92f3c
4 changed files with 122 additions and 8 deletions

View File

@@ -59,7 +59,9 @@ public final class WechatSurfaceMapper {
JSONObject avatar = source.optJSONObject("avatar");
boolean isGroup = source.optBoolean("isGroup", groupAvatarMembers.size() > 1);
String conversationType = source.optString("conversationType", "");
String threadTitle = source.optString("threadTitle", source.optString("title", source.optString("projectTitle", "")));
String threadTitle = trimLocalWorkspacePrefix(
source.optString("threadTitle", source.optString("title", source.optString("projectTitle", "")))
);
if ("folder_archive".equals(conversationType)) {
threadTitle = source.optString(
"projectTitle",
@@ -70,7 +72,7 @@ public final class WechatSurfaceMapper {
return new ConversationRow(
threadTitle,
source.optString("folderLabel", ""),
source.optString("lastMessagePreview", source.optString("preview", "")),
compactImportedThreadPreview(source.optString("lastMessagePreview", source.optString("preview", ""))),
source.optString("timeLabel", source.optString("latestReplyLabel", "")),
source.optInt("unreadCount", 0),
pinnedLabel,
@@ -408,7 +410,7 @@ public final class WechatSurfaceMapper {
);
putIfNotEmpty(folder, "projectTitle", projectTitle);
putIfNotEmpty(folder, "threadTitle", projectTitle);
String recentThread = latest.optString("threadTitle", "").trim();
String recentThread = trimLocalWorkspacePrefix(latest.optString("threadTitle", "").trim());
putIfNotEmpty(
folder,
"folderLabel",
@@ -422,11 +424,16 @@ public final class WechatSurfaceMapper {
safePut(folder, "searchAliases", searchAliases);
safePut(folder, "searchTargetProjectIds", searchTargetProjectIds);
}
putIfNotEmpty(folder, "preview", firstNonBlank(latest.optString("preview", ""), latest.optString("lastMessagePreview", "")));
String compactPreview = compactImportedThreadPreview(
firstNonBlank(latest.optString("preview", ""), latest.optString("lastMessagePreview", ""))
);
putIfNotEmpty(folder, "preview", compactPreview);
putIfNotEmpty(
folder,
"lastMessagePreview",
firstNonBlank(latest.optString("lastMessagePreview", ""), latest.optString("preview", ""))
compactImportedThreadPreview(
firstNonBlank(latest.optString("lastMessagePreview", ""), latest.optString("preview", ""))
)
);
safePut(folder, "activityIconCount", Math.max(0, Math.min(4, sumInt(items, "activityIconCount"))));
if (hasPinnedLabel(items)) {
@@ -637,6 +644,26 @@ public final class WechatSurfaceMapper {
}
}
private static String compactImportedThreadPreview(String value) {
String preview = value == null ? "" : value.trim();
if (preview.matches("^已从设备.+导入线程《.+》[。.]?$")) {
return "已导入线程";
}
return preview;
}
private static String trimLocalWorkspacePrefix(String value) {
String label = value == null ? "" : value.trim();
if (label.isEmpty()) {
return "";
}
String normalized = label.replace('\\', '/');
return normalized
.replaceFirst("^/Users/[^/]+/code/", "")
.replaceFirst("^/home/[^/]+/code/", "")
.replaceFirst("^[A-Za-z]:/Users/[^/]+/code/", "");
}
private static String firstNonBlank(String... values) {
if (values == null) {
return "";