You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Open-IM-Server/pkg/common/utils/utils.go

106 lines
3.0 KiB

3 years ago
package utils
import (
3 years ago
db "Open_IM/pkg/common/db"
3 years ago
imdb "Open_IM/pkg/common/db/mysql_model/im_mysql_model"
"Open_IM/pkg/common/token_verify"
open_im_sdk "Open_IM/pkg/proto/sdk_ws"
"Open_IM/pkg/utils"
"math/rand"
"strconv"
"time"
)
func OperationIDGenerator() string {
return strconv.FormatInt(time.Now().UnixNano()+int64(rand.Uint32()), 10)
}
3 years ago
func FriendOpenIMCopyDB(dst *db.Friend, src *open_im_sdk.FriendInfo) {
3 years ago
utils.CopyStructFields(dst, src)
dst.FriendUserID = src.FriendUser.UserID
}
3 years ago
func FriendDBCopyOpenIM(dst *open_im_sdk.FriendInfo, src *db.Friend) {
3 years ago
utils.CopyStructFields(dst, src)
user, _ := imdb.GetUserByUserID(src.FriendUserID)
if user != nil {
utils.CopyStructFields(dst.FriendUser, user)
}
3 years ago
dst.CreateTime = uint32(src.CreateTime.Unix())
3 years ago
dst.FriendUser.CreateTime = uint32(user.CreateTime.Unix())
3 years ago
}
//
3 years ago
func FriendRequestOpenIMCopyDB(dst *db.FriendRequest, src *open_im_sdk.FriendRequest) {
3 years ago
utils.CopyStructFields(dst, src)
}
3 years ago
func FriendRequestDBCopyOpenIM(dst *open_im_sdk.FriendRequest, src *db.FriendRequest) {
3 years ago
utils.CopyStructFields(dst, src)
3 years ago
dst.CreateTime = uint32(src.CreateTime.Unix())
dst.HandleTime = uint32(src.HandleTime.Unix())
3 years ago
}
3 years ago
func GroupOpenIMCopyDB(dst *db.Group, src *open_im_sdk.GroupInfo) {
3 years ago
utils.CopyStructFields(dst, src)
}
3 years ago
func GroupDBCopyOpenIM(dst *open_im_sdk.GroupInfo, src *db.Group) {
3 years ago
utils.CopyStructFields(dst, src)
user, _ := imdb.GetGroupOwnerInfoByGroupID(src.GroupID)
if user != nil {
dst.OwnerUserID = user.UserID
}
dst.MemberCount = imdb.GetGroupMemberNumByGroupID(src.GroupID)
3 years ago
dst.CreateTime = uint32(src.CreateTime.Unix())
3 years ago
}
3 years ago
func GroupMemberOpenIMCopyDB(dst *db.GroupMember, src *open_im_sdk.GroupMemberFullInfo) {
3 years ago
utils.CopyStructFields(dst, src)
}
3 years ago
func GroupMemberDBCopyOpenIM(dst *open_im_sdk.GroupMemberFullInfo, src *db.GroupMember) {
3 years ago
utils.CopyStructFields(dst, src)
if token_verify.IsMangerUserID(src.UserID) {
u, _ := imdb.GetUserByUserID(src.UserID)
if u != nil {
utils.CopyStructFields(dst, u)
}
dst.AppMangerLevel = 1
}
3 years ago
dst.JoinTime = src.JoinTime.Unix()
3 years ago
}
3 years ago
func GroupRequestOpenIMCopyDB(dst *db.GroupRequest, src *open_im_sdk.GroupRequest) {
3 years ago
utils.CopyStructFields(dst, src)
}
3 years ago
func GroupRequestDBCopyOpenIM(dst *open_im_sdk.GroupRequest, src *db.GroupRequest) {
3 years ago
utils.CopyStructFields(dst, src)
3 years ago
dst.ReqTime = uint32(src.ReqTime.Unix())
dst.HandleTime = uint32(src.HandledTime.Unix())
3 years ago
}
3 years ago
func UserOpenIMCopyDB(dst *db.User, src *open_im_sdk.UserInfo) {
3 years ago
utils.CopyStructFields(dst, src)
}
3 years ago
func UserDBCopyOpenIM(dst *open_im_sdk.UserInfo, src *db.User) {
3 years ago
utils.CopyStructFields(dst, src)
3 years ago
dst.CreateTime = uint32(src.CreateTime.Unix())
3 years ago
}
3 years ago
func BlackOpenIMCopyDB(dst *db.Black, src *open_im_sdk.BlackInfo) {
3 years ago
utils.CopyStructFields(dst, src)
dst.BlockUserID = src.BlackUserInfo.UserID
}
3 years ago
func BlackDBCopyOpenIM(dst *open_im_sdk.BlackInfo, src *db.Black) {
3 years ago
utils.CopyStructFields(dst, src)
3 years ago
dst.CreateTime = uint32(src.CreateTime.Unix())
3 years ago
user, _ := imdb.GetUserByUserID(src.BlockUserID)
if user != nil {
utils.CopyStructFields(dst.BlackUserInfo, user)
}
}