|
|
|
@ -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_")
|
|
|
|
|
}
|
|
|
|
|