|
|
@ -441,6 +441,25 @@ func (db *commonMsgDatabase) getMsgBySeqsRange(ctx context.Context, userID strin
|
|
|
|
return seqMsgs, nil
|
|
|
|
return seqMsgs, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// GetMsgBySeqsRange In the context of group chat, we have the following parameters:
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// "maxSeq" of a conversation: It represents the maximum value of messages in the group conversation.
|
|
|
|
|
|
|
|
// "minSeq" of a conversation (default: 1): It represents the minimum value of messages in the group conversation.
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// For a user's perspective regarding the group conversation, we have the following parameters:
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// "userMaxSeq": It represents the user's upper limit for message retrieval in the group. If not set (default: 0),
|
|
|
|
|
|
|
|
// it means the upper limit is the same as the conversation's "maxSeq".
|
|
|
|
|
|
|
|
// "userMinSeq": It represents the user's starting point for message retrieval in the group. If not set (default: 0),
|
|
|
|
|
|
|
|
// it means the starting point is the same as the conversation's "minSeq".
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// The scenarios for these parameters are as follows:
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// For users who have been kicked out of the group, "userMaxSeq" can be set as the maximum value they had before
|
|
|
|
|
|
|
|
// being kicked out. This limits their ability to retrieve messages up to a certain point.
|
|
|
|
|
|
|
|
// For new users joining the group, if they don't need to receive old messages,
|
|
|
|
|
|
|
|
// "userMinSeq" can be set as the same value as the conversation's "maxSeq" at the moment they join the group.
|
|
|
|
|
|
|
|
// This ensures that their message retrieval starts from the point they joined.
|
|
|
|
func (db *commonMsgDatabase) GetMsgBySeqsRange(ctx context.Context, userID string, conversationID string, begin, end, num, userMaxSeq int64) (int64, int64, []*sdkws.MsgData, error) {
|
|
|
|
func (db *commonMsgDatabase) GetMsgBySeqsRange(ctx context.Context, userID string, conversationID string, begin, end, num, userMaxSeq int64) (int64, int64, []*sdkws.MsgData, error) {
|
|
|
|
userMinSeq, err := db.cache.GetConversationUserMinSeq(ctx, conversationID, userID)
|
|
|
|
userMinSeq, err := db.cache.GetConversationUserMinSeq(ctx, conversationID, userID)
|
|
|
|
if err != nil && errs.Unwrap(err) != redis.Nil {
|
|
|
|
if err != nil && errs.Unwrap(err) != redis.Nil {
|
|
|
@ -453,6 +472,7 @@ func (db *commonMsgDatabase) GetMsgBySeqsRange(ctx context.Context, userID strin
|
|
|
|
if userMinSeq > minSeq {
|
|
|
|
if userMinSeq > minSeq {
|
|
|
|
minSeq = userMinSeq
|
|
|
|
minSeq = userMinSeq
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//"minSeq" represents the startSeq value that the user can retrieve.
|
|
|
|
if minSeq > end {
|
|
|
|
if minSeq > end {
|
|
|
|
log.ZInfo(ctx, "minSeq > end", "minSeq", minSeq, "end", end)
|
|
|
|
log.ZInfo(ctx, "minSeq > end", "minSeq", minSeq, "end", end)
|
|
|
|
return 0, 0, nil, nil
|
|
|
|
return 0, 0, nil, nil
|
|
|
@ -467,23 +487,41 @@ func (db *commonMsgDatabase) GetMsgBySeqsRange(ctx context.Context, userID strin
|
|
|
|
maxSeq = userMaxSeq
|
|
|
|
maxSeq = userMaxSeq
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//"maxSeq" represents the endSeq value that the user can retrieve.
|
|
|
|
|
|
|
|
|
|
|
|
if begin < minSeq {
|
|
|
|
if begin < minSeq {
|
|
|
|
begin = minSeq
|
|
|
|
begin = minSeq
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if end > maxSeq {
|
|
|
|
if end > maxSeq {
|
|
|
|
end = maxSeq
|
|
|
|
end = maxSeq
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//"begin" and "end" represent the actual startSeq and endSeq values that the user can retrieve.
|
|
|
|
if end < begin {
|
|
|
|
if end < begin {
|
|
|
|
return 0, 0, nil, errs.ErrArgs.Wrap("seq end < begin")
|
|
|
|
return 0, 0, nil, errs.ErrArgs.Wrap("seq end < begin")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
var seqs []int64
|
|
|
|
var seqs []int64
|
|
|
|
for i := end; i > end-num; i-- {
|
|
|
|
if end-begin+1 <= num {
|
|
|
|
if i >= begin {
|
|
|
|
for i := begin; i <= end; i++ {
|
|
|
|
seqs = append([]int64{i}, seqs...)
|
|
|
|
seqs = append(seqs, i)
|
|
|
|
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
break
|
|
|
|
for i := end - num + 1; i <= end; i++ {
|
|
|
|
|
|
|
|
seqs = append(seqs, i)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//167 178 10
|
|
|
|
|
|
|
|
//if end-num < {
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
//var seqs []int64
|
|
|
|
|
|
|
|
//for i := end; i > end-num; i-- {
|
|
|
|
|
|
|
|
// if i >= begin {
|
|
|
|
|
|
|
|
// seqs = append([]int64{i}, seqs...)
|
|
|
|
|
|
|
|
// } else {
|
|
|
|
|
|
|
|
// break
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
//}
|
|
|
|
if len(seqs) == 0 {
|
|
|
|
if len(seqs) == 0 {
|
|
|
|
return 0, 0, nil, nil
|
|
|
|
return 0, 0, nil, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -551,7 +589,7 @@ func (db *commonMsgDatabase) GetMsgBySeqsRange(ctx context.Context, userID strin
|
|
|
|
return 0, 0, nil, err
|
|
|
|
return 0, 0, nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
prome.Add(prome.MsgPullFromMongoSuccessCounter, len(mongoMsgs))
|
|
|
|
prome.Add(prome.MsgPullFromMongoSuccessCounter, len(mongoMsgs))
|
|
|
|
successMsgs = append(successMsgs, mongoMsgs...)
|
|
|
|
successMsgs = append(mongoMsgs, successMsgs...)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return minSeq, maxSeq, successMsgs, nil
|
|
|
|
return minSeq, maxSeq, successMsgs, nil
|
|
|
|