diff --git a/internal/api/msg.go b/internal/api/msg.go index f149c1031..aa7096340 100644 --- a/internal/api/msg.go +++ b/internal/api/msg.go @@ -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 } diff --git a/pkg/common/db/controller/msg.go b/pkg/common/db/controller/msg.go index 9b25afc7c..b950b7cd3 100644 --- a/pkg/common/db/controller/msg.go +++ b/pkg/common/db/controller/msg.go @@ -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 diff --git a/pkg/rpcclient/msg.go b/pkg/rpcclient/msg.go index 4a7ea8894..b5cdaafff 100644 --- a/pkg/rpcclient/msg.go +++ b/pkg/rpcclient/msg.go @@ -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 diff --git a/pkg/utils/strings.go b/pkg/utils/strings.go index 8b4229fcd..5c985d724 100644 --- a/pkg/utils/strings.go +++ b/pkg/utils/strings.go @@ -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) } diff --git a/pkg/utils/utils.go b/pkg/utils/utils.go index d70b84200..7336fa22e 100644 --- a/pkg/utils/utils.go +++ b/pkg/utils/utils.go @@ -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_") +}