fix: preserve p2p topic for IM system notices
This commit is contained in:
+39
-10
@@ -4475,7 +4475,7 @@ func serveIMConversationMessages(wrt http.ResponseWriter, req *http.Request, pri
|
||||
writeIMRelationError(wrt, req, err)
|
||||
return
|
||||
}
|
||||
if sub == nil || !(sub.ModeGiven&sub.ModeWant).IsReader() {
|
||||
if sub == nil || !(sub.ModeGiven & sub.ModeWant).IsReader() {
|
||||
writeIMError(wrt, req, http.StatusForbidden, 30005, imReasonForbidden, "permission denied", nil)
|
||||
return
|
||||
}
|
||||
@@ -11277,10 +11277,11 @@ func broadcastIMConversationSystemMessage(tenantID types.TenantID, msg *types.Me
|
||||
timestamp = time.Now().UTC().Round(time.Millisecond)
|
||||
}
|
||||
out := &ServerComMessage{
|
||||
TenantID: tenantID,
|
||||
RcptTo: msg.Topic,
|
||||
AsUser: types.ParseUid(msg.From).UserId(),
|
||||
Timestamp: timestamp,
|
||||
TenantID: tenantID,
|
||||
RcptTo: msg.Topic,
|
||||
AsUser: types.ParseUid(msg.From).UserId(),
|
||||
Timestamp: timestamp,
|
||||
PreserveTopicName: true,
|
||||
Data: &MsgServerData{
|
||||
Topic: msg.Topic,
|
||||
From: types.ParseUid(msg.From).UserId(),
|
||||
@@ -11296,7 +11297,7 @@ func broadcastIMConversationSystemMessage(tenantID types.TenantID, msg *types.Me
|
||||
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)
|
||||
broadcastIMConversationSystemPresence(tenantID, msg, timestamp)
|
||||
}
|
||||
|
||||
func publishIMGroupInvitationNotification(tenantID types.TenantID, inv *types.GroupInvitation) {
|
||||
@@ -11335,16 +11336,15 @@ func deliverIMConversationSystemMessageToP2PSessions(tenantID types.TenantID, ms
|
||||
if _, ok := participants[session.uid]; !ok {
|
||||
return true
|
||||
}
|
||||
viewTopic, err := types.P2PNameForUser(session.uid, msg.Topic)
|
||||
if err != nil || viewTopic == "" {
|
||||
if _, err := types.P2PNameForUser(session.uid, msg.Topic); err != nil {
|
||||
return true
|
||||
}
|
||||
if session.getSub(msg.Topic) != nil || session.getSub(viewTopic) != nil {
|
||||
if session.getSub(msg.Topic) != nil {
|
||||
return true
|
||||
}
|
||||
msgCopy := out.copy()
|
||||
msgCopy.RcptTo = session.uid.UserId()
|
||||
msgCopy.Data.Topic = viewTopic
|
||||
msgCopy.Data.Topic = msg.Topic
|
||||
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())
|
||||
}
|
||||
@@ -11352,6 +11352,35 @@ func deliverIMConversationSystemMessageToP2PSessions(tenantID types.TenantID, ms
|
||||
})
|
||||
}
|
||||
|
||||
func broadcastIMConversationSystemPresence(tenantID types.TenantID, msg *types.Message, timestamp time.Time) {
|
||||
if globals.hub == nil || msg == nil || msg.SeqId <= 0 || msg.Topic == "" {
|
||||
return
|
||||
}
|
||||
uid1, uid2, err := types.ParseP2P(msg.Topic)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
for _, uid := range []types.Uid{uid1, uid2} {
|
||||
select {
|
||||
case globals.hub.routeSrv <- &ServerComMessage{
|
||||
TenantID: tenantID,
|
||||
RcptTo: uid.UserId(),
|
||||
Timestamp: timestamp,
|
||||
PreserveTopicName: true,
|
||||
Pres: &MsgServerPres{
|
||||
Topic: "me",
|
||||
What: "msg",
|
||||
Src: msg.Topic,
|
||||
SeqId: msg.SeqId,
|
||||
SkipTopic: msg.Topic,
|
||||
},
|
||||
}:
|
||||
default:
|
||||
logs.Warn.Printf("im system message: hub presence queue full topic=%s seq=%d user=%s", msg.Topic, msg.SeqId, uid.UserId())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func systemNotificationIDFromPath(path string) string {
|
||||
const marker = "/v1/im/system-notifications/"
|
||||
idx := strings.Index(path, marker)
|
||||
|
||||
Reference in New Issue
Block a user