notification

This commit is contained in:
wangchuxiao 2023-05-06 10:52:29 +08:00
parent a94ef2c290
commit 7df211ca18
5 changed files with 60 additions and 48 deletions

View File

@ -104,7 +104,6 @@ func (m Message) newUserSendMsgReq(c *gin.Context, params *apistruct.ManagementS
log.Error(mcontext.GetOperationID(c), "Marshal failed ", err.Error(), tips.String())
}
}
utils.GetConversationIDBySessionType()
return &pbData
}

View File

@ -467,7 +467,7 @@ func (db *msgDatabase) getMsgBySeqsRange(ctx context.Context, conversationID str
for int64(len(seqMsg)) != num {
for docID, value := range m {
beginSeq, endSeq := db.msg.GetSeqsBeginEnd(value)
msgs, seqs, err := db.msgDocDatabase.GetMsgBySeqIndexIn1Doc(ctx, docID, beginSeq, endSeq)
msgs, _, err := db.msgDocDatabase.GetMsgBySeqIndexIn1Doc(ctx, docID, beginSeq, endSeq)
if err != nil {
log.ZError(ctx, "GetMsgBySeqIndexIn1Doc error", err, "docID", docID, "beginSeq", beginSeq, "endSeq", endSeq)
continue

View File

@ -156,8 +156,6 @@ func (c *MsgClient) Notification(ctx context.Context, sendID, recvID string, con
msg.CreateTime = utils.GetCurrentTimestampByMill()
msg.ClientMsgID = utils.GetMsgID(sendID)
// msg.Options = make(map[string]bool, 7)
// todo notification get sender name and face url
// msg.SenderNickname, msg.SenderFaceURL, err = c.getFaceURLAndName(sendID)
options := config.GetOptionsByNotification(c.contentTypeConf[contentType])
options = utils.WithOptions(options, opts...)
msg.Options = options

View File

@ -9,11 +9,7 @@ package utils
import (
"encoding/json"
"math/rand"
"sort"
"strconv"
"strings"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/constant"
)
func IntToString(i int) string {
@ -94,46 +90,6 @@ func GetMsgID(sendID string) string {
return Md5(t + sendID + int64ToString(rand.Int63n(GetCurrentTimestampByNano())))
}
func GetConversationIDBySessionType(sessionType int, ids ...string) string {
sort.Strings(ids)
if len(ids) > 2 || len(ids) < 1 {
return ""
}
switch sessionType {
case constant.SingleChatType:
return "si_" + strings.Join(ids, "_") // single chat
case constant.GroupChatType:
return "g_" + ids[0] // group chat
case constant.SuperGroupChatType:
return "sg_" + ids[0] // super group chat
case constant.NotificationChatType:
return "sn_" + ids[0] // server notification chat
}
return ""
}
func GetNotificationConversationIDBySessionType(sessionType int, ids ...string) string {
sort.Strings(ids)
if len(ids) > 2 || len(ids) < 1 {
return ""
}
switch sessionType {
case constant.SingleChatType:
return "n_" + strings.Join(ids, "_") // single chat
case constant.GroupChatType:
return "n_" + ids[0] // group chat
case constant.SuperGroupChatType:
return "n_" + ids[0] // super group chat
case constant.NotificationChatType:
return "n_" + ids[0] // server notification chat
}
return ""
}
func IsNotification(conversationID string) bool {
return strings.HasPrefix(conversationID, "n_")
}
func int64ToString(i int64) string {
return strconv.FormatInt(i, 10)
}

View File

@ -4,10 +4,13 @@ import (
"hash/crc32"
"math/rand"
"runtime"
"sort"
"strconv"
"strings"
"time"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/constant"
sdkws "github.com/OpenIMSDK/Open-IM-Server/pkg/proto/sdkws"
"github.com/jinzhu/copier"
"github.com/pkg/errors"
"google.golang.org/protobuf/proto"
@ -166,3 +169,59 @@ func String2Pb(s string, pb proto.Message) error {
func GetHashCode(s string) uint32 {
return crc32.ChecksumIEEE([]byte(s))
}
func GetConversationIDByMsg(msg *sdkws.MsgData) string {
switch msg.SessionType {
case constant.SingleChatType:
l := []string{msg.SendID, msg.RecvID}
sort.Strings(l)
return "n_" + strings.Join(l, "_") // single chat
case constant.GroupChatType:
return "n_" + msg.GroupID // group chat
case constant.SuperGroupChatType:
return "sg_" + msg.GroupID // super group chat
case constant.NotificationChatType:
return "sn_" + msg.SendID + "_" + msg.RecvID // server notification chat
}
return ""
}
func GetConversationIDBySessionType(sessionType int, ids ...string) string {
sort.Strings(ids)
if len(ids) > 2 || len(ids) < 1 {
return ""
}
switch sessionType {
case constant.SingleChatType:
return "si_" + strings.Join(ids, "_") // single chat
case constant.GroupChatType:
return "g_" + ids[0] // group chat
case constant.SuperGroupChatType:
return "sg_" + ids[0] // super group chat
case constant.NotificationChatType:
return "sn_" + ids[0] // server notification chat
}
return ""
}
func GetNotificationConversationIDBySessionType(sessionType int, ids ...string) string {
sort.Strings(ids)
if len(ids) > 2 || len(ids) < 1 {
return ""
}
switch sessionType {
case constant.SingleChatType:
return "n_" + strings.Join(ids, "_") // single chat
case constant.GroupChatType:
return "n_" + ids[0] // group chat
case constant.SuperGroupChatType:
return "n_" + ids[0] // super group chat
case constant.NotificationChatType:
return "n_" + ids[0] // server notification chat
}
return ""
}
func IsNotification(conversationID string) bool {
return strings.HasPrefix(conversationID, "n_")
}