fix: deliver friendship system notices live
This commit is contained in:
+68
-2
@@ -10771,7 +10771,7 @@ func publishIMConversationSystemNotice(tenantID types.TenantID, topic, msgType,
|
||||
content["extra"] = extra
|
||||
}
|
||||
now := time.Now().UTC().Round(time.Millisecond)
|
||||
_, err = store.Messages.Save(tenantID, &types.Message{
|
||||
msg := &types.Message{
|
||||
ObjHeader: types.ObjHeader{CreatedAt: now, UpdatedAt: now},
|
||||
TenantID: tenantID,
|
||||
SeqId: topicRecord.SeqId + 1,
|
||||
@@ -10784,10 +10784,76 @@ func publishIMConversationSystemNotice(tenantID types.TenantID, topic, msgType,
|
||||
"x-im-from": "system",
|
||||
},
|
||||
Content: content,
|
||||
}, nil, false)
|
||||
}
|
||||
_, err = store.Messages.Save(tenantID, msg, nil, false)
|
||||
if err != nil && !errors.Is(err, types.ErrDuplicate) {
|
||||
logs.Warn.Printf("im system message: failed to save %s for topic %s: %v", template, topic, err)
|
||||
return
|
||||
}
|
||||
broadcastIMConversationSystemMessage(tenantID, msg, now)
|
||||
}
|
||||
|
||||
func broadcastIMConversationSystemMessage(tenantID types.TenantID, msg *types.Message, timestamp time.Time) {
|
||||
if globals.hub == nil || msg == nil || msg.SeqId <= 0 || strings.TrimSpace(msg.Topic) == "" {
|
||||
return
|
||||
}
|
||||
if timestamp.IsZero() {
|
||||
timestamp = time.Now().UTC().Round(time.Millisecond)
|
||||
}
|
||||
out := &ServerComMessage{
|
||||
TenantID: tenantID,
|
||||
RcptTo: msg.Topic,
|
||||
AsUser: types.ParseUid(msg.From).UserId(),
|
||||
Timestamp: timestamp,
|
||||
Data: &MsgServerData{
|
||||
Topic: msg.Topic,
|
||||
From: types.ParseUid(msg.From).UserId(),
|
||||
Timestamp: timestamp,
|
||||
SeqId: msg.SeqId,
|
||||
Head: msg.Head,
|
||||
Content: msg.Content,
|
||||
},
|
||||
}
|
||||
select {
|
||||
case globals.hub.routeSrv <- out:
|
||||
default:
|
||||
logs.Warn.Printf("im system message: hub route queue full topic=%s seq=%d", msg.Topic, msg.SeqId)
|
||||
}
|
||||
deliverIMConversationSystemMessageToP2PSessions(tenantID, msg, out)
|
||||
broadcastHTTPForwardPresence(tenantID, msg, timestamp)
|
||||
}
|
||||
|
||||
func deliverIMConversationSystemMessageToP2PSessions(tenantID types.TenantID, msg *types.Message, out *ServerComMessage) {
|
||||
if globals.sessionStore == nil || msg == nil || out == nil || out.Data == nil {
|
||||
return
|
||||
}
|
||||
uid1, uid2, err := types.ParseP2P(msg.Topic)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
participants := map[types.Uid]struct{}{uid1: {}, uid2: {}}
|
||||
globals.sessionStore.Range(func(_ string, session *Session) bool {
|
||||
if session == nil || session.tenantID != tenantID {
|
||||
return true
|
||||
}
|
||||
if _, ok := participants[session.uid]; !ok {
|
||||
return true
|
||||
}
|
||||
viewTopic, err := types.P2PNameForUser(session.uid, msg.Topic)
|
||||
if err != nil || viewTopic == "" {
|
||||
return true
|
||||
}
|
||||
if session.getSub(msg.Topic) != nil || session.getSub(viewTopic) != nil {
|
||||
return true
|
||||
}
|
||||
msgCopy := out.copy()
|
||||
msgCopy.RcptTo = session.uid.UserId()
|
||||
msgCopy.Data.Topic = viewTopic
|
||||
if !session.queueOut(msgCopy) {
|
||||
logs.Warn.Printf("im system message: session queue full topic=%s seq=%d user=%s", msg.Topic, msg.SeqId, session.uid.UserId())
|
||||
}
|
||||
return true
|
||||
})
|
||||
}
|
||||
|
||||
func systemNotificationIDFromPath(path string) string {
|
||||
|
||||
Reference in New Issue
Block a user