mirror of
https://github.com/openimsdk/open-im-server.git
synced 2026-05-01 07:35:58 +08:00
notification
This commit is contained in:
@@ -1,28 +1,133 @@
|
||||
package unrelation
|
||||
|
||||
import "github.com/OpenIMSDK/Open-IM-Server/pkg/proto/sdkws"
|
||||
import (
|
||||
"context"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/constant"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/proto/sdkws"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type MsgModel struct {
|
||||
SendID string `bson:"send_id"`
|
||||
RecvID string `bson:"recv_id"`
|
||||
GroupID string `bson:"group_id"`
|
||||
ClientMsgID string `bson:"client_msg_id"` // 客户端消息ID
|
||||
ServerMsgID string `bson:"server_msg_id"` // 服务端消息ID
|
||||
SenderPlatformID int32 `bson:"sender_platform_id"`
|
||||
SenderNickname string `bson:"sender_nickname"`
|
||||
SenderFaceURL string `bson:"sender_face_url"`
|
||||
SessionType int32 `bson:"session_type"`
|
||||
MsgFrom int32 `bson:"msg_from"`
|
||||
ContentType int32 `bson:"contentType"`
|
||||
Content []byte `bson:"content"`
|
||||
Seq int64 `bson:"seq"`
|
||||
SendTime int64 `bson:"sendTime"`
|
||||
CreateTime int64 `bson:"createTime"`
|
||||
Status int32 `bson:"status"`
|
||||
Options map[string]bool `bson:"options"`
|
||||
OfflinePushInfo *sdkws.OfflinePushInfo `bson:"offlinePushInfo"`
|
||||
AtUserIDList []string `bson:"atUserIDList"`
|
||||
MsgDataList []byte `bson:"msgDataList"`
|
||||
AttachedInfo string `bson:"attachedInfo"`
|
||||
Ex string `bson:"ex"`
|
||||
const (
|
||||
singleGocMsgNum = 5000
|
||||
Msg = "msg"
|
||||
OldestList = 0
|
||||
NewestList = -1
|
||||
)
|
||||
|
||||
type MsgDocModel struct {
|
||||
DocID string `bson:"uid"`
|
||||
Msg []MsgInfoModel `bson:"msg"`
|
||||
}
|
||||
|
||||
type MsgInfoModel struct {
|
||||
SendTime int64 `bson:"sendtime"`
|
||||
Msg []byte `bson:"msg"`
|
||||
}
|
||||
|
||||
type MsgDocModelInterface interface {
|
||||
PushMsgsToDoc(ctx context.Context, docID string, msgsToMongo []MsgInfoModel) error
|
||||
Create(ctx context.Context, model *MsgDocModel) error
|
||||
UpdateMsgStatusByIndexInOneDoc(ctx context.Context, docID string, msg *sdkws.MsgData, seqIndex int, status int32) error
|
||||
FindOneByDocID(ctx context.Context, docID string) (*MsgDocModel, error)
|
||||
GetNewestMsg(ctx context.Context, sourceID string) (*MsgInfoModel, error)
|
||||
GetOldestMsg(ctx context.Context, sourceID string) (*MsgInfoModel, error)
|
||||
Delete(ctx context.Context, docIDs []string) error
|
||||
GetMsgsByIndex(ctx context.Context, sourceID string, index int64) (*MsgDocModel, error)
|
||||
UpdateOneDoc(ctx context.Context, msg *MsgDocModel) error
|
||||
}
|
||||
|
||||
func (MsgDocModel) TableName() string {
|
||||
return Msg
|
||||
}
|
||||
|
||||
func (MsgDocModel) GetSingleGocMsgNum() int64 {
|
||||
return singleGocMsgNum
|
||||
}
|
||||
|
||||
func (m *MsgDocModel) IsFull() bool {
|
||||
index, _ := strconv.Atoi(strings.Split(m.DocID, ":")[1])
|
||||
if index == 0 {
|
||||
if len(m.Msg) >= singleGocMsgNum-1 {
|
||||
return true
|
||||
}
|
||||
}
|
||||
if len(m.Msg) >= singleGocMsgNum {
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
func (m MsgDocModel) GetDocID(sourceID string, seq int64) string {
|
||||
seqSuffix := seq / singleGocMsgNum
|
||||
return m.indexGen(sourceID, seqSuffix)
|
||||
}
|
||||
|
||||
func (m MsgDocModel) GetSeqDocIDList(userID string, maxSeq int64) []string {
|
||||
seqMaxSuffix := maxSeq / singleGocMsgNum
|
||||
var seqUserIDs []string
|
||||
for i := 0; i <= int(seqMaxSuffix); i++ {
|
||||
seqUserID := m.indexGen(userID, int64(i))
|
||||
seqUserIDs = append(seqUserIDs, seqUserID)
|
||||
}
|
||||
return seqUserIDs
|
||||
}
|
||||
|
||||
func (m MsgDocModel) getSeqSuperGroupID(groupID string, seq int64) string {
|
||||
seqSuffix := seq / singleGocMsgNum
|
||||
return m.superGroupIndexGen(groupID, seqSuffix)
|
||||
}
|
||||
|
||||
func (m MsgDocModel) superGroupIndexGen(groupID string, seqSuffix int64) string {
|
||||
return "super_group_" + groupID + ":" + strconv.FormatInt(int64(seqSuffix), 10)
|
||||
}
|
||||
|
||||
func (m MsgDocModel) GetDocIDSeqsMap(sourceID string, seqs []int64) map[string][]int64 {
|
||||
t := make(map[string][]int64)
|
||||
for i := 0; i < len(seqs); i++ {
|
||||
docID := m.GetDocID(sourceID, seqs[i])
|
||||
if value, ok := t[docID]; !ok {
|
||||
var temp []int64
|
||||
t[docID] = append(temp, seqs[i])
|
||||
} else {
|
||||
t[docID] = append(value, seqs[i])
|
||||
}
|
||||
}
|
||||
return t
|
||||
}
|
||||
|
||||
func (m MsgDocModel) getMsgIndex(seq uint32) int {
|
||||
seqSuffix := seq / singleGocMsgNum
|
||||
var index uint32
|
||||
if seqSuffix == 0 {
|
||||
index = (seq - seqSuffix*singleGocMsgNum) - 1
|
||||
} else {
|
||||
index = seq - seqSuffix*singleGocMsgNum
|
||||
}
|
||||
return int(index)
|
||||
}
|
||||
|
||||
func (m MsgDocModel) indexGen(sourceID string, seqSuffix int64) string {
|
||||
return sourceID + ":" + strconv.FormatInt(seqSuffix, 10)
|
||||
}
|
||||
|
||||
func (MsgDocModel) GenExceptionMessageBySeqs(seqs []int64) (exceptionMsg []*sdkws.MsgData) {
|
||||
for _, v := range seqs {
|
||||
msg := new(sdkws.MsgData)
|
||||
msg.Seq = v
|
||||
exceptionMsg = append(exceptionMsg, msg)
|
||||
}
|
||||
return exceptionMsg
|
||||
}
|
||||
|
||||
func (MsgDocModel) GenExceptionSuperGroupMessageBySeqs(seqs []int64, groupID string) (exceptionMsg []*sdkws.MsgData) {
|
||||
for _, v := range seqs {
|
||||
msg := new(sdkws.MsgData)
|
||||
msg.Seq = v
|
||||
msg.GroupID = groupID
|
||||
msg.SessionType = constant.SuperGroupChatType
|
||||
exceptionMsg = append(exceptionMsg, msg)
|
||||
}
|
||||
return exceptionMsg
|
||||
}
|
||||
|
||||
@@ -9,63 +9,63 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
singleGocMsgNum = 5000
|
||||
Msg = "msg"
|
||||
OldestList = 0
|
||||
NewestList = -1
|
||||
singleGocNotificationNum = 5000
|
||||
Notification = "notification"
|
||||
//OldestList = 0
|
||||
//NewestList = -1
|
||||
)
|
||||
|
||||
type MsgDocModel struct {
|
||||
DocID string `bson:"uid"`
|
||||
Msg []MsgInfoModel `bson:"msg"`
|
||||
type NotificationDocModel struct {
|
||||
DocID string `bson:"uid"`
|
||||
Msg []NotificationInfoModel `bson:"msg"`
|
||||
}
|
||||
|
||||
type MsgInfoModel struct {
|
||||
type NotificationInfoModel struct {
|
||||
SendTime int64 `bson:"sendtime"`
|
||||
Msg []byte `bson:"msg"`
|
||||
}
|
||||
|
||||
type MsgDocModelInterface interface {
|
||||
PushMsgsToDoc(ctx context.Context, docID string, msgsToMongo []MsgInfoModel) error
|
||||
Create(ctx context.Context, model *MsgDocModel) error
|
||||
type NotificationDocModelInterface interface {
|
||||
PushMsgsToDoc(ctx context.Context, docID string, msgsToMongo []NotificationInfoModel) error
|
||||
Create(ctx context.Context, model *NotificationDocModel) error
|
||||
UpdateMsgStatusByIndexInOneDoc(ctx context.Context, docID string, msg *sdkws.MsgData, seqIndex int, status int32) error
|
||||
FindOneByDocID(ctx context.Context, docID string) (*MsgDocModel, error)
|
||||
GetNewestMsg(ctx context.Context, sourceID string) (*MsgInfoModel, error)
|
||||
GetOldestMsg(ctx context.Context, sourceID string) (*MsgInfoModel, error)
|
||||
FindOneByDocID(ctx context.Context, docID string) (*NotificationDocModel, error)
|
||||
GetNewestMsg(ctx context.Context, sourceID string) (*NotificationInfoModel, error)
|
||||
GetOldestMsg(ctx context.Context, sourceID string) (*NotificationInfoModel, error)
|
||||
Delete(ctx context.Context, docIDs []string) error
|
||||
GetMsgsByIndex(ctx context.Context, sourceID string, index int64) (*MsgDocModel, error)
|
||||
UpdateOneDoc(ctx context.Context, msg *MsgDocModel) error
|
||||
GetMsgsByIndex(ctx context.Context, sourceID string, index int64) (*NotificationDocModel, error)
|
||||
UpdateOneDoc(ctx context.Context, msg *NotificationDocModel) error
|
||||
}
|
||||
|
||||
func (MsgDocModel) TableName() string {
|
||||
return Msg
|
||||
func (NotificationDocModel) TableName() string {
|
||||
return Notification
|
||||
}
|
||||
|
||||
func (MsgDocModel) GetSingleGocMsgNum() int64 {
|
||||
return singleGocMsgNum
|
||||
func (NotificationDocModel) GetsingleGocNotificationNum() int64 {
|
||||
return singleGocNotificationNum
|
||||
}
|
||||
|
||||
func (m *MsgDocModel) IsFull() bool {
|
||||
func (m *NotificationDocModel) IsFull() bool {
|
||||
index, _ := strconv.Atoi(strings.Split(m.DocID, ":")[1])
|
||||
if index == 0 {
|
||||
if len(m.Msg) >= singleGocMsgNum-1 {
|
||||
if len(m.Msg) >= singleGocNotificationNum-1 {
|
||||
return true
|
||||
}
|
||||
}
|
||||
if len(m.Msg) >= singleGocMsgNum {
|
||||
if len(m.Msg) >= singleGocNotificationNum {
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
func (m MsgDocModel) GetDocID(sourceID string, seq int64) string {
|
||||
seqSuffix := seq / singleGocMsgNum
|
||||
func (m NotificationDocModel) GetDocID(sourceID string, seq int64) string {
|
||||
seqSuffix := seq / singleGocNotificationNum
|
||||
return m.indexGen(sourceID, seqSuffix)
|
||||
}
|
||||
|
||||
func (m MsgDocModel) GetSeqDocIDList(userID string, maxSeq int64) []string {
|
||||
seqMaxSuffix := maxSeq / singleGocMsgNum
|
||||
func (m NotificationDocModel) GetSeqDocIDList(userID string, maxSeq int64) []string {
|
||||
seqMaxSuffix := maxSeq / singleGocNotificationNum
|
||||
var seqUserIDs []string
|
||||
for i := 0; i <= int(seqMaxSuffix); i++ {
|
||||
seqUserID := m.indexGen(userID, int64(i))
|
||||
@@ -74,16 +74,16 @@ func (m MsgDocModel) GetSeqDocIDList(userID string, maxSeq int64) []string {
|
||||
return seqUserIDs
|
||||
}
|
||||
|
||||
func (m MsgDocModel) getSeqSuperGroupID(groupID string, seq int64) string {
|
||||
seqSuffix := seq / singleGocMsgNum
|
||||
func (m NotificationDocModel) getSeqSuperGroupID(groupID string, seq int64) string {
|
||||
seqSuffix := seq / singleGocNotificationNum
|
||||
return m.superGroupIndexGen(groupID, seqSuffix)
|
||||
}
|
||||
|
||||
func (m MsgDocModel) superGroupIndexGen(groupID string, seqSuffix int64) string {
|
||||
func (m NotificationDocModel) superGroupIndexGen(groupID string, seqSuffix int64) string {
|
||||
return "super_group_" + groupID + ":" + strconv.FormatInt(int64(seqSuffix), 10)
|
||||
}
|
||||
|
||||
func (m MsgDocModel) GetDocIDSeqsMap(sourceID string, seqs []int64) map[string][]int64 {
|
||||
func (m NotificationDocModel) GetDocIDSeqsMap(sourceID string, seqs []int64) map[string][]int64 {
|
||||
t := make(map[string][]int64)
|
||||
for i := 0; i < len(seqs); i++ {
|
||||
docID := m.GetDocID(sourceID, seqs[i])
|
||||
@@ -97,22 +97,22 @@ func (m MsgDocModel) GetDocIDSeqsMap(sourceID string, seqs []int64) map[string][
|
||||
return t
|
||||
}
|
||||
|
||||
func (m MsgDocModel) getMsgIndex(seq uint32) int {
|
||||
seqSuffix := seq / singleGocMsgNum
|
||||
func (m NotificationDocModel) getMsgIndex(seq uint32) int {
|
||||
seqSuffix := seq / singleGocNotificationNum
|
||||
var index uint32
|
||||
if seqSuffix == 0 {
|
||||
index = (seq - seqSuffix*singleGocMsgNum) - 1
|
||||
index = (seq - seqSuffix*singleGocNotificationNum) - 1
|
||||
} else {
|
||||
index = seq - seqSuffix*singleGocMsgNum
|
||||
index = seq - seqSuffix*singleGocNotificationNum
|
||||
}
|
||||
return int(index)
|
||||
}
|
||||
|
||||
func (m MsgDocModel) indexGen(sourceID string, seqSuffix int64) string {
|
||||
func (m NotificationDocModel) indexGen(sourceID string, seqSuffix int64) string {
|
||||
return sourceID + ":" + strconv.FormatInt(seqSuffix, 10)
|
||||
}
|
||||
|
||||
func (MsgDocModel) GenExceptionMessageBySeqs(seqs []int64) (exceptionMsg []*sdkws.MsgData) {
|
||||
func (NotificationDocModel) GenExceptionMessageBySeqs(seqs []int64) (exceptionMsg []*sdkws.MsgData) {
|
||||
for _, v := range seqs {
|
||||
msg := new(sdkws.MsgData)
|
||||
msg.Seq = v
|
||||
@@ -121,7 +121,7 @@ func (MsgDocModel) GenExceptionMessageBySeqs(seqs []int64) (exceptionMsg []*sdkw
|
||||
return exceptionMsg
|
||||
}
|
||||
|
||||
func (MsgDocModel) GenExceptionSuperGroupMessageBySeqs(seqs []int64, groupID string) (exceptionMsg []*sdkws.MsgData) {
|
||||
func (NotificationDocModel) GenExceptionSuperGroupMessageBySeqs(seqs []int64, groupID string) (exceptionMsg []*sdkws.MsgData) {
|
||||
for _, v := range seqs {
|
||||
msg := new(sdkws.MsgData)
|
||||
msg.Seq = v
|
||||
|
||||
Reference in New Issue
Block a user