mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-06-03 06:01:30 +08:00
Merge remote-tracking branch 'origin/errcode' into errcode
# Conflicts: # internal/rpc/friend/friend.go # pkg/common/db/mysql_model/im_mysql_model/user_black_list_model.go
This commit is contained in:
commit
64b4e5570c
@ -4,6 +4,7 @@ import (
|
||||
chat "Open_IM/internal/rpc/msg"
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/db"
|
||||
imdb "Open_IM/pkg/common/db/mysql_model/im_mysql_model"
|
||||
rocksCache "Open_IM/pkg/common/db/rocks_cache"
|
||||
"Open_IM/pkg/common/log"
|
||||
@ -101,41 +102,30 @@ func (s *friendServer) Run() {
|
||||
|
||||
func (s *friendServer) AddBlacklist(ctx context.Context, req *pbFriend.AddBlacklistReq) (*pbFriend.AddBlacklistResp, error) {
|
||||
log.NewInfo(req.CommID.OperationID, "AddBlacklist args ", req.String())
|
||||
ok := token_verify.CheckAccess(req.CommID.OpUserID, req.CommID.FromUserID)
|
||||
ok := token_verify.CheckAccess(ctx, req.CommID.OpUserID, req.CommID.FromUserID)
|
||||
if !ok {
|
||||
err := errors.New("CheckAccess false")
|
||||
log.NewError(req.CommID.OperationID, err.Error(), req.CommID.OpUserID, req.CommID.FromUserID)
|
||||
return &pbFriend.AddBlacklistResp{CommonResp: constant.Error2CommResp(constant.ErrNoPermission, err)}, nil
|
||||
return &pbFriend.AddBlacklistResp{CommonResp: constant.Error2CommResp(ctx, constant.ErrNoPermission, "accress")}, nil
|
||||
}
|
||||
black := imdb.Black{OwnerUserID: req.CommID.FromUserID, BlockUserID: req.CommID.ToUserID, OperatorUserID: req.CommID.OpUserID}
|
||||
|
||||
err := imdb.InsertInToUserBlackList(black)
|
||||
black := db.Black{OwnerUserID: req.CommID.FromUserID, BlockUserID: req.CommID.ToUserID, OperatorUserID: req.CommID.OpUserID}
|
||||
err := imdb.InsertInToUserBlackList(ctx, black)
|
||||
if err != nil {
|
||||
log.NewError(req.CommID.OperationID, "InsertInToUserBlackList failed ", err.Error())
|
||||
return &pbFriend.AddBlacklistResp{CommonResp: constant.Error2CommResp(constant.ErrDatabase, err)}, nil
|
||||
return &pbFriend.AddBlacklistResp{CommonResp: constant.Error2CommResp(ctx, constant.ErrDatabase, err.Error())}, nil
|
||||
}
|
||||
log.NewInfo(req.CommID.OperationID, "AddBlacklist rpc ok ", req.CommID.FromUserID, req.CommID.ToUserID)
|
||||
|
||||
etcdConn := getcdv3.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImCacheName, req.CommID.OperationID)
|
||||
etcdConn := getcdv3.GetDefaultConn(ctx, config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImCacheName, req.CommID.OperationID)
|
||||
if etcdConn == nil {
|
||||
errMsg := req.CommID.OperationID + "getcdv3.GetDefaultConn == nil"
|
||||
log.NewError(req.CommID.OperationID, errMsg)
|
||||
return &pbFriend.AddBlacklistResp{CommonResp: constant.Error2CommResp(constant.ErrInternalServer, err)}, nil
|
||||
return &pbFriend.AddBlacklistResp{CommonResp: constant.Error2CommResp(ctx, constant.ErrInternalServer, "conn is nil")}, nil
|
||||
}
|
||||
cacheClient := pbCache.NewCacheClient(etcdConn)
|
||||
cacheResp, err := cacheClient.DelBlackIDListFromCache(context.Background(), &pbCache.DelBlackIDListFromCacheReq{UserID: req.CommID.FromUserID, OperationID: req.CommID.OperationID})
|
||||
cacheResp, err := cacheClient.DelBlackIDListFromCache(ctx, &pbCache.DelBlackIDListFromCacheReq{UserID: req.CommID.FromUserID, OperationID: req.CommID.OperationID})
|
||||
if err != nil {
|
||||
log.NewError(req.CommID.OperationID, "DelBlackIDListFromCache rpc call failed ", err.Error())
|
||||
return &pbFriend.AddBlacklistResp{CommonResp: constant.Error2CommResp(constant.ErrInternalServer, err)}, nil
|
||||
return &pbFriend.AddBlacklistResp{CommonResp: constant.Error2CommResp(ctx, constant.ErrInternalServer, err.Error())}, nil
|
||||
}
|
||||
if cacheResp.CommonResp.ErrCode != 0 {
|
||||
err = errors.New(fmt.Sprintf("call DelBlackIDListFromCache rpc failed code is %d, err is %s, args is %s", cacheResp.CommonResp.ErrCode, cacheResp.CommonResp.ErrMsg, req.CommID.FromUserID))
|
||||
log.NewError(req.CommID.OperationID, "DelBlackIDListFromCache rpc logic call failed ", cacheResp.String())
|
||||
return &pbFriend.AddBlacklistResp{CommonResp: constant.Error2CommResp(constant.ErrInternalServer, err)}, nil
|
||||
return &pbFriend.AddBlacklistResp{CommonResp: constant.Error2CommResp(ctx, constant.ErrInternalServer, err.Error())}, nil
|
||||
}
|
||||
|
||||
chat.BlackAddedNotification(req)
|
||||
return &pbFriend.AddBlacklistResp{CommonResp: constant.Error2CommResp(constant.ErrNone, nil)}, nil
|
||||
return &pbFriend.AddBlacklistResp{CommonResp: constant.Error2CommResp(ctx, constant.ErrNone, "")}, nil
|
||||
}
|
||||
|
||||
func (s *friendServer) AddFriend(ctx context.Context, req *pbFriend.AddFriendReq) (*pbFriend.AddFriendResp, error) {
|
||||
@ -191,7 +181,7 @@ func (s *friendServer) AddFriend(ctx context.Context, req *pbFriend.AddFriendReq
|
||||
log.NewError(req.CommID.OperationID, "GetUserByUserID failed ", err.Error(), req.CommID.ToUserID)
|
||||
return &pbFriend.AddFriendResp{CommonResp: &pbFriend.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
|
||||
}
|
||||
friendRequest := imdb.FriendRequest{
|
||||
friendRequest := db.FriendRequest{
|
||||
HandleResult: 0, ReqMsg: req.ReqMsg, CreateTime: time.Now()}
|
||||
utils.CopyStructFields(&friendRequest, req.CommID)
|
||||
// {openIM001 openIM002 0 test add friend 0001-01-01 00:00:00 +0000 UTC 0001-01-01 00:00:00 +0000 UTC }]
|
||||
@ -246,14 +236,14 @@ func (s *friendServer) ImportFriend(ctx context.Context, req *pbFriend.ImportFri
|
||||
} else {
|
||||
if _, err := imdb.GetFriendRelationshipFromFriend(req.FromUserID, v); err != nil {
|
||||
//Establish two single friendship
|
||||
toInsertFollow := imdb.Friend{OwnerUserID: req.FromUserID, FriendUserID: v}
|
||||
toInsertFollow := db.Friend{OwnerUserID: req.FromUserID, FriendUserID: v}
|
||||
err1 := imdb.InsertToFriend(&toInsertFollow)
|
||||
if err1 != nil {
|
||||
log.NewError(req.OperationID, "InsertToFriend failed ", err1.Error(), toInsertFollow)
|
||||
resp.UserIDResultList = append(resp.UserIDResultList, &pbFriend.UserIDResult{UserID: v, Result: -1})
|
||||
continue
|
||||
}
|
||||
toInsertFollow = imdb.Friend{OwnerUserID: v, FriendUserID: req.FromUserID}
|
||||
toInsertFollow = db.Friend{OwnerUserID: v, FriendUserID: req.FromUserID}
|
||||
err2 := imdb.InsertToFriend(&toInsertFollow)
|
||||
if err2 != nil {
|
||||
log.NewError(req.OperationID, "InsertToFriend failed ", err2.Error(), toInsertFollow)
|
||||
@ -319,7 +309,7 @@ func (s *friendServer) ImportFriend(ctx context.Context, req *pbFriend.ImportFri
|
||||
return &resp, nil
|
||||
}
|
||||
|
||||
// process Friend application
|
||||
//process Friend application
|
||||
func (s *friendServer) AddFriendResponse(ctx context.Context, req *pbFriend.AddFriendResponseReq) (*pbFriend.AddFriendResponseResp, error) {
|
||||
log.NewInfo(req.CommID.OperationID, "AddFriendResponse args ", req.String())
|
||||
if !token_verify.CheckAccess(req.CommID.OpUserID, req.CommID.FromUserID) {
|
||||
@ -354,7 +344,7 @@ func (s *friendServer) AddFriendResponse(ctx context.Context, req *pbFriend.AddF
|
||||
log.NewWarn(req.CommID.OperationID, "GetFriendRelationshipFromFriend exist", req.CommID.FromUserID, req.CommID.ToUserID)
|
||||
} else {
|
||||
//Establish two single friendship
|
||||
toInsertFollow := imdb.Friend{OwnerUserID: req.CommID.FromUserID, FriendUserID: req.CommID.ToUserID, OperatorUserID: req.CommID.OpUserID}
|
||||
toInsertFollow := db.Friend{OwnerUserID: req.CommID.FromUserID, FriendUserID: req.CommID.ToUserID, OperatorUserID: req.CommID.OpUserID}
|
||||
err = imdb.InsertToFriend(&toInsertFollow)
|
||||
if err != nil {
|
||||
log.NewError(req.CommID.OperationID, "InsertToFriend failed ", err.Error(), toInsertFollow)
|
||||
@ -367,7 +357,7 @@ func (s *friendServer) AddFriendResponse(ctx context.Context, req *pbFriend.AddF
|
||||
if err == nil {
|
||||
log.NewWarn(req.CommID.OperationID, "GetFriendRelationshipFromFriend exist", req.CommID.ToUserID, req.CommID.FromUserID)
|
||||
} else {
|
||||
toInsertFollow := imdb.Friend{OwnerUserID: req.CommID.ToUserID, FriendUserID: req.CommID.FromUserID, OperatorUserID: req.CommID.OpUserID}
|
||||
toInsertFollow := db.Friend{OwnerUserID: req.CommID.ToUserID, FriendUserID: req.CommID.FromUserID, OperatorUserID: req.CommID.OpUserID}
|
||||
err = imdb.InsertToFriend(&toInsertFollow)
|
||||
if err != nil {
|
||||
log.NewError(req.CommID.OperationID, "InsertToFriend failed ", err.Error(), toInsertFollow)
|
||||
@ -618,7 +608,7 @@ func (s *friendServer) GetFriendList(ctx context.Context, req *pbFriend.GetFrien
|
||||
return &pbFriend.GetFriendListResp{FriendInfoList: userInfoList}, nil
|
||||
}
|
||||
|
||||
// received
|
||||
//received
|
||||
func (s *friendServer) GetFriendApplyList(ctx context.Context, req *pbFriend.GetFriendApplyListReq) (*pbFriend.GetFriendApplyListResp, error) {
|
||||
log.NewInfo(req.CommID.OperationID, "GetFriendApplyList args ", req.String())
|
||||
//Parse token, to find current user information
|
||||
|
@ -2,8 +2,10 @@ package constant
|
||||
|
||||
import (
|
||||
sdkws "Open_IM/pkg/proto/sdk_ws"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
@ -83,13 +85,13 @@ func ToAPIErrWithErr(err error) ErrInfo {
|
||||
return ErrDefaultOther
|
||||
}
|
||||
|
||||
func Error2CommResp(info ErrInfo, detailErr error) *sdkws.CommonResp {
|
||||
func Error2CommResp(ctx context.Context, info ErrInfo, detailErrMsg string) *sdkws.CommonResp {
|
||||
err := &sdkws.CommonResp{
|
||||
ErrCode: info.ErrCode,
|
||||
ErrMsg: info.ErrMsg,
|
||||
}
|
||||
if detailErr != nil {
|
||||
err.DetailErrMsg = detailErr.Error()
|
||||
if detailErrMsg != "" {
|
||||
err.DetailErrMsg = detailErrMsg
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
57
pkg/common/db/group_chao.go
Normal file
57
pkg/common/db/group_chao.go
Normal file
@ -0,0 +1,57 @@
|
||||
package db
|
||||
|
||||
import (
|
||||
"gorm.io/gorm"
|
||||
"time"
|
||||
)
|
||||
|
||||
type GroupChao struct {
|
||||
GroupID string `gorm:"column:group_id;primary_key;size:64" json:"groupID" binding:"required"`
|
||||
GroupName string `gorm:"column:name;size:255" json:"groupName"`
|
||||
Notification string `gorm:"column:notification;size:255" json:"notification"`
|
||||
Introduction string `gorm:"column:introduction;size:255" json:"introduction"`
|
||||
FaceURL string `gorm:"column:face_url;size:255" json:"faceURL"`
|
||||
CreateTime time.Time `gorm:"column:create_time;index:create_time"`
|
||||
Ex string `gorm:"column:ex" json:"ex;size:1024" json:"ex"`
|
||||
Status int32 `gorm:"column:status"`
|
||||
CreatorUserID string `gorm:"column:creator_user_id;size:64"`
|
||||
GroupType int32 `gorm:"column:group_type"`
|
||||
NeedVerification int32 `gorm:"column:need_verification"`
|
||||
LookMemberInfo int32 `gorm:"column:look_member_info" json:"lookMemberInfo"`
|
||||
ApplyMemberFriend int32 `gorm:"column:apply_member_friend" json:"applyMemberFriend"`
|
||||
NotificationUpdateTime time.Time `gorm:"column:notification_update_time"`
|
||||
NotificationUserID string `gorm:"column:notification_user_id;size:64"`
|
||||
DB *gorm.DB `group:"-" json:"-"`
|
||||
}
|
||||
|
||||
func (tb *GroupChao) FindBy(groupID string) (*GroupChao, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (tb *GroupChao) FindIn(groupIDList []string) ([]GroupChao, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (tb *GroupChao) Create(m *GroupChao) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (tb *GroupChao) CreateList(m []GroupChao) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (tb *GroupChao) Update(m *GroupChao) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (tb *GroupChao) UpdateBy(groupID string, data map[string]interface{}) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (tb *GroupChao) DeleteBy(groupID string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (tb *GroupChao) DeleteIn(groupID []string) error {
|
||||
return nil
|
||||
}
|
55
pkg/common/db/mysql_model/im_mysql_model/group_model_k.go
Normal file
55
pkg/common/db/mysql_model/im_mysql_model/group_model_k.go
Normal file
@ -0,0 +1,55 @@
|
||||
package im_mysql_model
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/db"
|
||||
"Open_IM/pkg/utils"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Group struct {
|
||||
//`json:"operationID" binding:"required"`
|
||||
//`protobuf:"bytes,1,opt,name=GroupID" json:"GroupID,omitempty"` `json:"operationID" binding:"required"`
|
||||
GroupID string `gorm:"column:group_id;primary_key;size:64" json:"groupID" binding:"required"`
|
||||
GroupName string `gorm:"column:name;size:255" json:"groupName"`
|
||||
Notification string `gorm:"column:notification;size:255" json:"notification"`
|
||||
Introduction string `gorm:"column:introduction;size:255" json:"introduction"`
|
||||
FaceURL string `gorm:"column:face_url;size:255" json:"faceURL"`
|
||||
CreateTime time.Time `gorm:"column:create_time;index:create_time"`
|
||||
Ex string `gorm:"column:ex" json:"ex;size:1024" json:"ex"`
|
||||
Status int32 `gorm:"column:status"`
|
||||
CreatorUserID string `gorm:"column:creator_user_id;size:64"`
|
||||
GroupType int32 `gorm:"column:group_type"`
|
||||
NeedVerification int32 `gorm:"column:need_verification"`
|
||||
LookMemberInfo int32 `gorm:"column:look_member_info" json:"lookMemberInfo"`
|
||||
ApplyMemberFriend int32 `gorm:"column:apply_member_friend" json:"applyMemberFriend"`
|
||||
NotificationUpdateTime time.Time `gorm:"column:notification_update_time"`
|
||||
NotificationUserID string `gorm:"column:notification_user_id;size:64"`
|
||||
}
|
||||
|
||||
func (*Group) Create(groupList []*Group) error {
|
||||
return utils.Wrap(db.DB.MysqlDB.DefaultGormDB().Create(&groupList).Error, "")
|
||||
}
|
||||
|
||||
func (*Group) Delete(groupList []*Group) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (*Group) Update(groupList []*Group) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (*Group) UpdateByMap(args map[*Group]map[string]interface{}) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (*Group) Find(group []*Group) ([]*Group, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (*Group) Take(group *Group) (*Group, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (*Group) Count(group *Group) (int64, error) {
|
||||
return 0, nil
|
||||
}
|
@ -2,11 +2,14 @@ package im_mysql_model
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/db"
|
||||
"Open_IM/pkg/common/trace_log"
|
||||
"Open_IM/pkg/utils"
|
||||
"context"
|
||||
"time"
|
||||
)
|
||||
|
||||
func InsertInToUserBlackList(black Black) error {
|
||||
func InsertInToUserBlackList(ctx context.Context, black db.Black) error {
|
||||
defer trace_log.SetContextInfo(ctx)
|
||||
black.CreateTime = time.Now()
|
||||
return db.DB.MysqlDB.DefaultGormDB().Table("blacks").Create(black).Error
|
||||
}
|
||||
@ -21,17 +24,17 @@ func InsertInToUserBlackList(black Black) error {
|
||||
// }
|
||||
|
||||
func CheckBlack(ownerUserID, blockUserID string) error {
|
||||
var black Black
|
||||
var black db.Black
|
||||
return db.DB.MysqlDB.DefaultGormDB().Table("blacks").Where("owner_user_id=? and block_user_id=?", ownerUserID, blockUserID).Find(&black).Error
|
||||
}
|
||||
|
||||
func RemoveBlackList(ownerUserID, blockUserID string) error {
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Table("blacks").Where("owner_user_id=? and block_user_id=?", ownerUserID, blockUserID).Delete(Black{}).Error
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Table("blacks").Where("owner_user_id=? and block_user_id=?", ownerUserID, blockUserID).Delete(db.Black{}).Error
|
||||
return utils.Wrap(err, "RemoveBlackList failed")
|
||||
}
|
||||
|
||||
func GetBlackListByUserID(ownerUserID string) ([]Black, error) {
|
||||
var blackListUsersInfo []Black
|
||||
func GetBlackListByUserID(ownerUserID string) ([]db.Black, error) {
|
||||
var blackListUsersInfo []db.Black
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Table("blacks").Where("owner_user_id=?", ownerUserID).Find(&blackListUsersInfo).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -6,6 +6,7 @@ import (
|
||||
commonDB "Open_IM/pkg/common/db"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/utils"
|
||||
"context"
|
||||
"time"
|
||||
|
||||
go_redis "github.com/go-redis/redis/v8"
|
||||
@ -139,7 +140,7 @@ func IsManagerUserID(OpUserID string) bool {
|
||||
}
|
||||
}
|
||||
|
||||
func CheckAccess(OpUserID string, OwnerUserID string) bool {
|
||||
func CheckAccess(ctx context.Context, OpUserID string, OwnerUserID string) bool {
|
||||
if utils.IsContain(OpUserID, config.Config.Manager.AppManagerUid) {
|
||||
return true
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package trace_log
|
||||
import (
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/utils"
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
@ -76,7 +77,7 @@ func SetContextInfo(ctx context.Context, funcName string, err error, args ...int
|
||||
var funcInfo FuncInfo
|
||||
funcInfo.Args = make(map[string]interface{})
|
||||
argsHandle(args, funcInfo.Args)
|
||||
funcInfo.FuncName = funcName
|
||||
funcInfo.FuncName = utils.GetSelfFuncName()
|
||||
funcInfo.Err = err
|
||||
*t.Funcs = append(*t.Funcs, funcInfo)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user