You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Open-IM-Server/pkg/common/db/table/unrelation/msg.go

80 lines
1.9 KiB

2 years ago
package unrelation
import "strconv"
const (
singleGocMsgNum = 5000
CChat = "msg"
)
2 years ago
type UserMsgDocModel struct {
DocID string `bson:"uid"`
Msg []MsgInfoModel `bson:"msg"`
2 years ago
}
type MsgInfoModel struct {
SendTime int64 `bson:"sendtime"`
Msg []byte `bson:"msg"`
}
2 years ago
func (UserMsgDocModel) TableName() string {
2 years ago
return CChat
}
2 years ago
func (UserMsgDocModel) GetSingleDocMsgNum() int {
2 years ago
return singleGocMsgNum
}
2 years ago
func (u UserMsgDocModel) getSeqUid(uid string, seq uint32) string {
2 years ago
seqSuffix := seq / singleGocMsgNum
return u.indexGen(uid, seqSuffix)
}
2 years ago
func (u UserMsgDocModel) getSeqUserIDList(userID string, maxSeq uint32) []string {
2 years ago
seqMaxSuffix := maxSeq / singleGocMsgNum
var seqUserIDList []string
for i := 0; i <= int(seqMaxSuffix); i++ {
seqUserID := u.indexGen(userID, uint32(i))
seqUserIDList = append(seqUserIDList, seqUserID)
}
return seqUserIDList
}
2 years ago
func (UserMsgDocModel) getSeqSuperGroupID(groupID string, seq uint32) string {
2 years ago
seqSuffix := seq / singleGocMsgNum
return superGroupIndexGen(groupID, seqSuffix)
}
2 years ago
func (u UserMsgDocModel) GetSeqUid(uid string, seq uint32) string {
2 years ago
return u.getSeqUid(uid, seq)
}
2 years ago
func (u UserMsgDocModel) GetDocIDSeqsMap(uid string, seqs []uint32) map[string][]uint32 {
t := make(map[string][]uint32)
for i := 0; i < len(seqs); i++ {
seqUid := u.getSeqUid(uid, seqs[i])
if value, ok := t[seqUid]; !ok {
var temp []uint32
t[seqUid] = append(temp, seqs[i])
} else {
t[seqUid] = append(value, seqs[i])
}
}
return t
}
2 years ago
func (UserMsgDocModel) getMsgIndex(seq uint32) int {
2 years ago
seqSuffix := seq / singleGocMsgNum
var index uint32
if seqSuffix == 0 {
index = (seq - seqSuffix*singleGocMsgNum) - 1
} else {
index = seq - seqSuffix*singleGocMsgNum
}
return int(index)
}
2 years ago
func (UserMsgDocModel) indexGen(uid string, seqSuffix uint32) string {
2 years ago
return uid + ":" + strconv.FormatInt(int64(seqSuffix), 10)
}