复制项目
This commit is contained in:
61
pkg/util/conversationutil/conversationutil.go
Normal file
61
pkg/util/conversationutil/conversationutil.go
Normal file
@@ -0,0 +1,61 @@
|
||||
package conversationutil
|
||||
|
||||
import (
|
||||
"sort"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func GenConversationIDForSingle(sendID, recvID string) string {
|
||||
l := []string{sendID, recvID}
|
||||
sort.Strings(l)
|
||||
return "si_" + strings.Join(l, "_")
|
||||
}
|
||||
|
||||
func GenConversationUniqueKeyForGroup(groupID string) string {
|
||||
return groupID
|
||||
}
|
||||
|
||||
func GenGroupConversationID(groupID string) string {
|
||||
return "sg_" + groupID
|
||||
}
|
||||
|
||||
func IsGroupConversationID(conversationID string) bool {
|
||||
return strings.HasPrefix(conversationID, "sg_")
|
||||
}
|
||||
|
||||
func GetGroupIDFromConversationID(conversationID string) string {
|
||||
if strings.HasPrefix(conversationID, "sg_") {
|
||||
return strings.TrimPrefix(conversationID, "sg_")
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func IsNotificationConversationID(conversationID string) bool {
|
||||
return strings.HasPrefix(conversationID, "n_")
|
||||
}
|
||||
|
||||
func GenConversationUniqueKeyForSingle(sendID, recvID string) string {
|
||||
l := []string{sendID, recvID}
|
||||
sort.Strings(l)
|
||||
return strings.Join(l, "_")
|
||||
}
|
||||
|
||||
func GetNotificationConversationIDByConversationID(conversationID string) string {
|
||||
l := strings.Split(conversationID, "_")
|
||||
if len(l) > 1 {
|
||||
l[0] = "n"
|
||||
return strings.Join(l, "_")
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func GetSelfNotificationConversationID(userID string) string {
|
||||
return "n_" + userID + "_" + userID
|
||||
}
|
||||
|
||||
func GetSeqsBeginEnd(seqs []int64) (int64, int64) {
|
||||
if len(seqs) == 0 {
|
||||
return 0, 0
|
||||
}
|
||||
return seqs[0], seqs[len(seqs)-1]
|
||||
}
|
||||
1
pkg/util/conversationutil/doc.go
Normal file
1
pkg/util/conversationutil/doc.go
Normal file
@@ -0,0 +1 @@
|
||||
package conversationutil // import "git.imall.cloud/openim/open-im-server-deploy/pkg/util/conversationutil"
|
||||
16
pkg/util/hashutil/id.go
Normal file
16
pkg/util/hashutil/id.go
Normal file
@@ -0,0 +1,16 @@
|
||||
package hashutil
|
||||
|
||||
import (
|
||||
"crypto/md5"
|
||||
"encoding/binary"
|
||||
"encoding/json"
|
||||
)
|
||||
|
||||
func IdHash(ids []string) uint64 {
|
||||
if len(ids) == 0 {
|
||||
return 0
|
||||
}
|
||||
data, _ := json.Marshal(ids)
|
||||
sum := md5.Sum(data)
|
||||
return binary.BigEndian.Uint64(sum[:])
|
||||
}
|
||||
27
pkg/util/useronline/split.go
Normal file
27
pkg/util/useronline/split.go
Normal file
@@ -0,0 +1,27 @@
|
||||
package useronline
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func ParseUserOnlineStatus(payload string) (string, []int32, error) {
|
||||
arr := strings.Split(payload, ":")
|
||||
if len(arr) == 0 {
|
||||
return "", nil, errors.New("invalid data")
|
||||
}
|
||||
userID := arr[len(arr)-1]
|
||||
if userID == "" {
|
||||
return "", nil, errors.New("userID is empty")
|
||||
}
|
||||
platformIDs := make([]int32, len(arr)-1)
|
||||
for i := range platformIDs {
|
||||
platformID, err := strconv.Atoi(arr[i])
|
||||
if err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
platformIDs[i] = int32(platformID)
|
||||
}
|
||||
return userID, platformIDs, nil
|
||||
}
|
||||
Reference in New Issue
Block a user