fix: 兼容历史收藏源避免列表崩溃

This commit is contained in:
richjohnrambo
2026-09-09 17:40:11 +08:00
parent e0a6ee27bc
commit 98234db263
2 changed files with 49 additions and 3 deletions
+14 -3
View File
@@ -7912,6 +7912,12 @@ func favoritePayloadForPrincipal(principal *imPrincipal, item types.FavoriteItem
}
sourceTopic, ok := normalizeIMFavoriteSourceTopic(principal.Uid, item.SourceTopic)
if !ok {
if legacyFavoriteSnapshotOnly(item) {
if item.Availability == "" {
item.Availability = "available"
}
return favoritePayload(item), true
}
return nil, false
}
if err := requireTopicReader(principal, sourceTopic); err != nil {
@@ -7934,6 +7940,11 @@ func favoritePayloadForPrincipal(principal *imPrincipal, item types.FavoriteItem
return favoritePayload(item), true
}
func legacyFavoriteSnapshotOnly(item types.FavoriteItem) bool {
source := strings.TrimSpace(item.SourceTopic)
return strings.HasPrefix(source, "favSeed") && item.Snapshot != nil
}
func messageSearchPayload(msg types.Message, query string) map[string]any {
text := messageText(msg)
snippet := textSnippet(text, query)
@@ -9586,15 +9597,15 @@ func normalizeIMUserVisibleTopic(viewer types.Uid, topic string) (string, bool)
if len(topic) < 3 {
return "", false
}
switch types.GetTopicCat(topic) {
case types.TopicCatMe:
switch topic[:3] {
case "usr":
peer := types.ParseUserId(topic)
if peer.IsZero() {
return "", false
}
p2p := viewer.P2PName(peer)
return p2p, p2p != ""
case types.TopicCatP2P, types.TopicCatGrp, types.TopicCatSlf:
case "p2p", "grp", "slf":
return topic, true
default:
return "", false