fix: reserve seq for p2p system messages
This commit is contained in:
+7
-1
@@ -10726,11 +10726,17 @@ func publishIMConversationSystemNotice(tenantID types.TenantID, topic, msgType,
|
||||
},
|
||||
Content: content,
|
||||
}
|
||||
_, err = store.Messages.Save(tenantID, msg, nil, false)
|
||||
saved, err := saveMessageMaybeKafka(context.Background(), 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
|
||||
}
|
||||
if saved != nil && saved.SeqId > 0 {
|
||||
msg.SeqId = saved.SeqId
|
||||
}
|
||||
if saved != nil && saved.Duplicate {
|
||||
return
|
||||
}
|
||||
broadcastIMConversationSystemMessage(tenantID, msg, now)
|
||||
sendPushForStoredGroupMessage(tenantID, msg)
|
||||
}
|
||||
|
||||
+15
-11
@@ -3397,18 +3397,20 @@ func (messagesMapper) PreparePersist(tenantID types.TenantID, msg *types.Message
|
||||
msg.InitTimes()
|
||||
fromUid := types.ParseUid(msg.From)
|
||||
isGroupMessage := types.GetTopicCat(msg.Topic) == types.TopicCatGrp
|
||||
if isGroupMessage && groupMsgRuntime != nil {
|
||||
if groupMsgRuntime != nil {
|
||||
if clientMsgID != "" {
|
||||
claim, claimed, err := groupMsgRuntime.Claim(tenantID, msg.Topic, fromUid, clientMsgID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if !claimed {
|
||||
if claim != nil && claim.Status == "done" && claim.Seq > 0 {
|
||||
msg.SeqId = claim.Seq
|
||||
return &types.MessageSaveResult{SeqId: claim.Seq, Duplicate: true}, nil
|
||||
if isGroupMessage {
|
||||
claim, claimed, err := groupMsgRuntime.Claim(tenantID, msg.Topic, fromUid, clientMsgID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if !claimed {
|
||||
if claim != nil && claim.Status == "done" && claim.Seq > 0 {
|
||||
msg.SeqId = claim.Seq
|
||||
return &types.MessageSaveResult{SeqId: claim.Seq, Duplicate: true}, nil
|
||||
}
|
||||
return nil, types.ErrDuplicate
|
||||
}
|
||||
return nil, types.ErrDuplicate
|
||||
}
|
||||
}
|
||||
seq, shardMonth, err := nextMessageSeqWithFloor(tenantID, msg.Topic, msg.SeqId-1, msg.CreatedAt.UTC().Format("200601"))
|
||||
@@ -3419,7 +3421,9 @@ func (messagesMapper) PreparePersist(tenantID types.TenantID, msg *types.Message
|
||||
return nil, err
|
||||
}
|
||||
msg.SeqId = seq
|
||||
msg.ShardMonth = shardMonth
|
||||
if isGroupMessage {
|
||||
msg.ShardMonth = shardMonth
|
||||
}
|
||||
}
|
||||
if isGroupMessage && msg.ShardMonth == "" {
|
||||
msg.ShardMonth = msg.CreatedAt.UTC().Format("200601")
|
||||
|
||||
Reference in New Issue
Block a user