fix: stabilize me subscription sync metadata
This commit is contained in:
@@ -3301,6 +3301,7 @@ func (a *adapter) TopicsForUser(uid t.Uid, keepDeleted bool, opts *t.QueryOpt) (
|
|||||||
limit = a.maxResults
|
limit = a.maxResults
|
||||||
}
|
}
|
||||||
|
|
||||||
|
q += " ORDER BY topic ASC, deletedat IS NULL DESC, updatedat DESC, id DESC"
|
||||||
if limit > 0 {
|
if limit > 0 {
|
||||||
q += " LIMIT ?"
|
q += " LIMIT ?"
|
||||||
args = append(args, limit)
|
args = append(args, limit)
|
||||||
@@ -3329,7 +3330,12 @@ func (a *adapter) TopicsForUser(uid t.Uid, keepDeleted bool, opts *t.QueryOpt) (
|
|||||||
}
|
}
|
||||||
tname := sub.Topic
|
tname := sub.Topic
|
||||||
sub.User = uid.String()
|
sub.User = uid.String()
|
||||||
|
if !t.ParseUserId(tname).IsZero() {
|
||||||
|
// Legacy self-user subscriptions are not conversation entries.
|
||||||
|
continue
|
||||||
|
}
|
||||||
tcat := t.GetTopicCat(tname)
|
tcat := t.GetTopicCat(tname)
|
||||||
|
peerID := ""
|
||||||
|
|
||||||
if tcat == t.TopicCatMe || tcat == t.TopicCatFnd {
|
if tcat == t.TopicCatMe || tcat == t.TopicCatFnd {
|
||||||
// One of 'me', 'fnd' subscriptions, skip.
|
// One of 'me', 'fnd' subscriptions, skip.
|
||||||
@@ -3341,19 +3347,27 @@ func (a *adapter) TopicsForUser(uid t.Uid, keepDeleted bool, opts *t.QueryOpt) (
|
|||||||
p2pResolved[tname] = false
|
p2pResolved[tname] = false
|
||||||
if uid1 == uid {
|
if uid1 == uid {
|
||||||
usrq = append(usrq, store.DecodeUid(uid2))
|
usrq = append(usrq, store.DecodeUid(uid2))
|
||||||
sub.SetWith(uid2.UserId())
|
peerID = uid2.UserId()
|
||||||
|
sub.SetWith(peerID)
|
||||||
} else {
|
} else {
|
||||||
usrq = append(usrq, store.DecodeUid(uid1))
|
usrq = append(usrq, store.DecodeUid(uid1))
|
||||||
sub.SetWith(uid1.UserId())
|
peerID = uid1.UserId()
|
||||||
|
sub.SetWith(peerID)
|
||||||
}
|
}
|
||||||
} else if tcat == t.TopicCatGrp {
|
} else if tcat == t.TopicCatGrp {
|
||||||
// Maybe convert channel name to group topic name.
|
// Maybe convert channel name to group topic name.
|
||||||
tname = t.ChnToGrp(tname)
|
tname = t.ChnToGrp(tname)
|
||||||
}
|
}
|
||||||
|
if _, exists := join[tname]; exists {
|
||||||
|
continue
|
||||||
|
}
|
||||||
// No special handling needed for 'slf', 'sys' subscriptions.
|
// No special handling needed for 'slf', 'sys' subscriptions.
|
||||||
|
|
||||||
topq = append(topq, tname)
|
topq = append(topq, tname)
|
||||||
sub.Private = common.FromJSON(sub.Private)
|
sub.Private = common.FromJSON(sub.Private)
|
||||||
|
if tcat == t.TopicCatP2P {
|
||||||
|
sub.Private = ensureP2PPrivatePeer(sub.Private, peerID)
|
||||||
|
}
|
||||||
join[tname] = sub
|
join[tname] = sub
|
||||||
}
|
}
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
|||||||
@@ -150,6 +150,20 @@ func profilePublicFromFields(base any, nickname, avatarFileID, signature, gender
|
|||||||
return public
|
return public
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ensureP2PPrivatePeer(private any, peerID string) any {
|
||||||
|
if strings.TrimSpace(peerID) == "" {
|
||||||
|
return private
|
||||||
|
}
|
||||||
|
data, _ := private.(map[string]any)
|
||||||
|
if data == nil {
|
||||||
|
data = map[string]any{}
|
||||||
|
}
|
||||||
|
if _, ok := data["peer"]; !ok {
|
||||||
|
data["peer"] = peerID
|
||||||
|
}
|
||||||
|
return data
|
||||||
|
}
|
||||||
|
|
||||||
func clearProfilePublicFields(public map[string]any) {
|
func clearProfilePublicFields(public map[string]any) {
|
||||||
for _, key := range []string{"display_name", "nickname", "fn", "name", "avatar_file_id", "photo", "avatar", "signature", "gender", "region", "public_account"} {
|
for _, key := range []string{"display_name", "nickname", "fn", "name", "avatar_file_id", "photo", "avatar", "signature", "gender", "region", "public_account"} {
|
||||||
delete(public, key)
|
delete(public, key)
|
||||||
@@ -929,6 +943,7 @@ func (a *adapter) TenantTopicsForUser(id t.TenantID, uid t.Uid, keepDeleted bool
|
|||||||
} else {
|
} else {
|
||||||
limit = a.maxResults
|
limit = a.maxResults
|
||||||
}
|
}
|
||||||
|
q += " ORDER BY topic ASC, deletedat IS NULL DESC, updatedat DESC, id DESC"
|
||||||
if limit > 0 {
|
if limit > 0 {
|
||||||
q += " LIMIT ?"
|
q += " LIMIT ?"
|
||||||
args = append(args, limit)
|
args = append(args, limit)
|
||||||
@@ -952,6 +967,10 @@ func (a *adapter) TenantTopicsForUser(id t.TenantID, uid t.Uid, keepDeleted bool
|
|||||||
}
|
}
|
||||||
tname := sub.Topic
|
tname := sub.Topic
|
||||||
sub.User = uid.String()
|
sub.User = uid.String()
|
||||||
|
if !t.ParseUserId(tname).IsZero() {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
peerID := ""
|
||||||
switch t.GetTopicCat(tname) {
|
switch t.GetTopicCat(tname) {
|
||||||
case t.TopicCatMe, t.TopicCatFnd:
|
case t.TopicCatMe, t.TopicCatFnd:
|
||||||
continue
|
continue
|
||||||
@@ -960,16 +979,24 @@ func (a *adapter) TenantTopicsForUser(id t.TenantID, uid t.Uid, keepDeleted bool
|
|||||||
p2pResolved[tname] = false
|
p2pResolved[tname] = false
|
||||||
if uid1 == uid {
|
if uid1 == uid {
|
||||||
usrq = append(usrq, decodeUID(uid2))
|
usrq = append(usrq, decodeUID(uid2))
|
||||||
sub.SetWith(uid2.UserId())
|
peerID = uid2.UserId()
|
||||||
|
sub.SetWith(peerID)
|
||||||
} else {
|
} else {
|
||||||
usrq = append(usrq, decodeUID(uid1))
|
usrq = append(usrq, decodeUID(uid1))
|
||||||
sub.SetWith(uid1.UserId())
|
peerID = uid1.UserId()
|
||||||
|
sub.SetWith(peerID)
|
||||||
}
|
}
|
||||||
case t.TopicCatGrp:
|
case t.TopicCatGrp:
|
||||||
tname = t.ChnToGrp(tname)
|
tname = t.ChnToGrp(tname)
|
||||||
}
|
}
|
||||||
|
if _, exists := join[tname]; exists {
|
||||||
|
continue
|
||||||
|
}
|
||||||
topq = append(topq, tname)
|
topq = append(topq, tname)
|
||||||
sub.Private = common.FromJSON(sub.Private)
|
sub.Private = common.FromJSON(sub.Private)
|
||||||
|
if t.GetTopicCat(sub.Topic) == t.TopicCatP2P {
|
||||||
|
sub.Private = ensureP2PPrivatePeer(sub.Private, peerID)
|
||||||
|
}
|
||||||
join[tname] = sub
|
join[tname] = sub
|
||||||
}
|
}
|
||||||
err = rows.Err()
|
err = rows.Err()
|
||||||
|
|||||||
Reference in New Issue
Block a user