mirror of
https://github.com/openimsdk/open-im-server.git
synced 2026-05-10 20:15:59 +08:00
Merge remote-tracking branch 'origin/tuoyun' into tuoyun
This commit is contained in:
@@ -2,14 +2,14 @@ package base_info
|
||||
|
||||
import open_im_sdk "Open_IM/pkg/proto/sdk_ws"
|
||||
|
||||
type paramsCommFriend struct {
|
||||
type ParamsCommFriend struct {
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
ToUserID string `json:"toUserID" binding:"required"`
|
||||
FromUserID string `json:"fromUserID" binding:"required"`
|
||||
}
|
||||
|
||||
type AddBlacklistReq struct {
|
||||
paramsCommFriend
|
||||
ParamsCommFriend
|
||||
}
|
||||
type AddBlacklistResp struct {
|
||||
CommResp
|
||||
@@ -26,7 +26,7 @@ type ImportFriendResp struct {
|
||||
}
|
||||
|
||||
type AddFriendReq struct {
|
||||
paramsCommFriend
|
||||
ParamsCommFriend
|
||||
ReqMsg string `json:"reqMsg"`
|
||||
}
|
||||
type AddFriendResp struct {
|
||||
@@ -34,7 +34,7 @@ type AddFriendResp struct {
|
||||
}
|
||||
|
||||
type AddFriendResponseReq struct {
|
||||
paramsCommFriend
|
||||
ParamsCommFriend
|
||||
Flag int32 `json:"flag" binding:"required"`
|
||||
HandleMsg string `json:"handleMsg"`
|
||||
}
|
||||
@@ -43,14 +43,15 @@ type AddFriendResponseResp struct {
|
||||
}
|
||||
|
||||
type DeleteFriendReq struct {
|
||||
paramsCommFriend
|
||||
ParamsCommFriend
|
||||
}
|
||||
type DeleteFriendResp struct {
|
||||
CommResp
|
||||
}
|
||||
|
||||
type GetBlackListReq struct {
|
||||
paramsCommFriend
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
FromUserID string `json:"fromUserID" binding:"required"`
|
||||
}
|
||||
type GetBlackListResp struct {
|
||||
CommResp
|
||||
@@ -69,7 +70,7 @@ type BlackUserInfo struct {
|
||||
}
|
||||
|
||||
type SetFriendCommentReq struct {
|
||||
paramsCommFriend
|
||||
ParamsCommFriend
|
||||
Remark string `json:"remark" binding:"required"`
|
||||
}
|
||||
type SetFriendCommentResp struct {
|
||||
@@ -77,14 +78,14 @@ type SetFriendCommentResp struct {
|
||||
}
|
||||
|
||||
type RemoveBlackListReq struct {
|
||||
paramsCommFriend
|
||||
ParamsCommFriend
|
||||
}
|
||||
type RemoveBlackListResp struct {
|
||||
CommResp
|
||||
}
|
||||
|
||||
type IsFriendReq struct {
|
||||
paramsCommFriend
|
||||
ParamsCommFriend
|
||||
}
|
||||
type IsFriendResp struct {
|
||||
CommResp
|
||||
@@ -92,7 +93,7 @@ type IsFriendResp struct {
|
||||
}
|
||||
|
||||
type GetFriendsInfoReq struct {
|
||||
paramsCommFriend
|
||||
ParamsCommFriend
|
||||
}
|
||||
type GetFriendsInfoResp struct {
|
||||
CommResp
|
||||
@@ -100,7 +101,7 @@ type GetFriendsInfoResp struct {
|
||||
}
|
||||
|
||||
type GetFriendListReq struct {
|
||||
paramsCommFriend
|
||||
ParamsCommFriend
|
||||
}
|
||||
type GetFriendListResp struct {
|
||||
CommResp
|
||||
@@ -108,17 +109,19 @@ type GetFriendListResp struct {
|
||||
}
|
||||
|
||||
type GetFriendApplyListReq struct {
|
||||
paramsCommFriend
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
FromUserID string `json:"fromUserID" binding:"required"`
|
||||
}
|
||||
type GetFriendApplyListResp struct {
|
||||
CommResp
|
||||
FriendRequestList open_im_sdk.FriendRequest `json:"data"`
|
||||
FriendRequestList []*open_im_sdk.FriendRequest `json:"data"`
|
||||
}
|
||||
|
||||
type GetSelfApplyListReq struct {
|
||||
paramsCommFriend
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
FromUserID string `json:"fromUserID" binding:"required"`
|
||||
}
|
||||
type GetSelfApplyListResp struct {
|
||||
CommResp
|
||||
FriendRequestList open_im_sdk.FriendRequest `json:"data"`
|
||||
FriendRequestList []*open_im_sdk.FriendRequest `json:"data"`
|
||||
}
|
||||
|
||||
@@ -3,12 +3,12 @@ package constant
|
||||
const (
|
||||
|
||||
//group admin
|
||||
OrdinaryMember = 0
|
||||
GroupOwner = 1
|
||||
Administrator = 2
|
||||
// OrdinaryMember = 0
|
||||
// GroupOwner = 1
|
||||
// Administrator = 2
|
||||
//group application
|
||||
Application = 0
|
||||
AgreeApplication = 1
|
||||
// Application = 0
|
||||
// AgreeApplication = 1
|
||||
|
||||
//friend related
|
||||
BlackListFlag = 1
|
||||
@@ -117,4 +117,16 @@ var ContentType2PushContent = map[int64]string{
|
||||
Common: "你收到一条新消息",
|
||||
}
|
||||
|
||||
const (
|
||||
AppOrdinaryUsers = 1
|
||||
AppAdmin = 2
|
||||
|
||||
GroupOrdinaryUsers = 1
|
||||
GroupOwner = 2
|
||||
GroupAdmin = 3
|
||||
|
||||
Male = 1
|
||||
Female = 2
|
||||
)
|
||||
|
||||
const FriendAcceptTip = "You have successfully become friends, so start chatting"
|
||||
|
||||
@@ -2,6 +2,7 @@ package im_mysql_model
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/db"
|
||||
"Open_IM/pkg/utils"
|
||||
"time"
|
||||
)
|
||||
|
||||
@@ -65,11 +66,12 @@ func UpdateFriendApplication(friendRequest *FriendRequest) error {
|
||||
return err
|
||||
}
|
||||
friendRequest.CreateTime = time.Now()
|
||||
err = dbConn.Table("friend_request").Where("from_user_id=? and to_user_id=?", friendRequest.FromUserID, friendRequest.ToUserID).Update(&friendRequest).Error
|
||||
if err != nil {
|
||||
return err
|
||||
if dbConn.Table("friend_request").Where("from_user_id=? and to_user_id=?",
|
||||
friendRequest.FromUserID, friendRequest.ToUserID).Update(&friendRequest).RowsAffected == 0 {
|
||||
return InsertFriendApplication(friendRequest)
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func InsertFriendApplication(friendRequest *FriendRequest) error {
|
||||
@@ -77,6 +79,12 @@ func InsertFriendApplication(friendRequest *FriendRequest) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if friendRequest.CreateTime.Unix() < 0 {
|
||||
friendRequest.CreateTime = time.Now()
|
||||
}
|
||||
if friendRequest.HandleTime.Unix() < 0 {
|
||||
friendRequest.HandleTime = utils.UnixSecondToTime(0)
|
||||
}
|
||||
err = dbConn.Table("friend_request").Create(friendRequest).Error
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package im_mysql_model
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/db"
|
||||
"time"
|
||||
)
|
||||
@@ -22,7 +23,10 @@ func InsertIntoGroupMember(toInsertInfo GroupMember) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
toInsertInfo.JoinSource = time.Now()
|
||||
toInsertInfo.JoinTime = time.Now()
|
||||
if toInsertInfo.RoleLevel == 0 {
|
||||
toInsertInfo.RoleLevel = constant.GroupOrdinaryUsers
|
||||
}
|
||||
err = dbConn.Table("group_member").Create(toInsertInfo).Error
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -138,7 +142,7 @@ func GetGroupOwnerInfoByGroupID(groupID string) (*GroupMember, error) {
|
||||
return nil, err
|
||||
}
|
||||
for _, v := range omList {
|
||||
if v.RoleLevel == 1 {
|
||||
if v.RoleLevel == constant.GroupOwner {
|
||||
return &v, nil
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package im_mysql_model
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/db"
|
||||
"time"
|
||||
)
|
||||
@@ -88,7 +89,7 @@ func GetGroupApplicationList(userID string) ([]GroupRequest, error) {
|
||||
return nil, err
|
||||
}
|
||||
for _, v := range memberList {
|
||||
if v.RoleLevel > 0 {
|
||||
if v.RoleLevel > constant.GroupOrdinaryUsers {
|
||||
list, err := GetGroupRequestByGroupID(v.GroupID)
|
||||
if err != nil {
|
||||
continue
|
||||
|
||||
@@ -95,7 +95,7 @@ type GroupMember struct {
|
||||
JoinTime time.Time `gorm:"column:join_time"`
|
||||
Nickname string `gorm:"column:nickname"`
|
||||
FaceUrl string `gorm:"user_group_face_url"`
|
||||
JoinSource time.Time `gorm:"column:join_source"`
|
||||
JoinSource int32 `gorm:"column:join_source"`
|
||||
OperatorUserID string `gorm:"column:operator_user_id"`
|
||||
Ex string `gorm:"column:ex"`
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package im_mysql_model
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/db"
|
||||
"Open_IM/pkg/utils"
|
||||
"fmt"
|
||||
@@ -15,13 +16,16 @@ func init() {
|
||||
user, err := GetUserByUserID(v)
|
||||
if err != nil {
|
||||
fmt.Println("GetUserByUserID failed ", err.Error(), v, user)
|
||||
} else {
|
||||
continue
|
||||
}
|
||||
var appMgr User
|
||||
appMgr.UserID = v
|
||||
appMgr.Nickname = "AppManager" + utils.IntToString(k+1)
|
||||
appMgr.AppMangerLevel = constant.AppAdmin
|
||||
err = UserRegister(appMgr)
|
||||
if err != nil {
|
||||
fmt.Println("AppManager insert error", err.Error())
|
||||
fmt.Println("AppManager insert error", err.Error(), appMgr, "time: ", appMgr.Birth.Unix())
|
||||
}
|
||||
|
||||
}
|
||||
@@ -33,7 +37,12 @@ func UserRegister(user User) error {
|
||||
return err
|
||||
}
|
||||
user.CreateTime = time.Now()
|
||||
|
||||
if user.AppMangerLevel == 0 {
|
||||
user.AppMangerLevel = constant.AppOrdinaryUsers
|
||||
}
|
||||
if user.Birth.Unix() < 0 {
|
||||
user.Birth = utils.UnixSecondToTime(0)
|
||||
}
|
||||
err = dbConn.Table("user").Create(&user).Error
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -1,49 +1,10 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/jinzhu/copier"
|
||||
"reflect"
|
||||
)
|
||||
|
||||
// copy a by b b->a
|
||||
func CopyStructFields(a interface{}, b interface{}, fields ...string) (err error) {
|
||||
return copier.Copy(a, b)
|
||||
|
||||
at := reflect.TypeOf(a)
|
||||
av := reflect.ValueOf(a)
|
||||
bt := reflect.TypeOf(b)
|
||||
bv := reflect.ValueOf(b)
|
||||
|
||||
if at.Kind() != reflect.Ptr {
|
||||
err = fmt.Errorf("a must be a struct pointer")
|
||||
return err
|
||||
}
|
||||
av = reflect.ValueOf(av.Interface())
|
||||
|
||||
_fields := make([]string, 0)
|
||||
if len(fields) > 0 {
|
||||
_fields = fields
|
||||
} else {
|
||||
for i := 0; i < bv.NumField(); i++ {
|
||||
_fields = append(_fields, bt.Field(i).Name)
|
||||
}
|
||||
}
|
||||
|
||||
if len(_fields) == 0 {
|
||||
err = fmt.Errorf("no fields to copy")
|
||||
return err
|
||||
}
|
||||
|
||||
for i := 0; i < len(_fields); i++ {
|
||||
name := _fields[i]
|
||||
|
||||
f := av.Elem().FieldByName(name)
|
||||
bValue := bv.FieldByName(name)
|
||||
|
||||
if f.IsValid() && f.Kind() == bValue.Kind() {
|
||||
f.Set(bValue)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user