mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-04-06 04:15:46 +08:00
Merge branch 'errcode' of github.com:OpenIMSDK/Open-IM-Server into errcode
This commit is contained in:
commit
80b22e0e0e
@ -7,7 +7,6 @@ import (
|
||||
utils2 "Open_IM/pkg/utils"
|
||||
"context"
|
||||
"fmt"
|
||||
utils "github.com/OpenIMSDK/open_utils"
|
||||
"github.com/gin-gonic/gin"
|
||||
"reflect"
|
||||
)
|
||||
@ -31,10 +30,11 @@ func ApiToRpc(c *gin.Context, apiReq, apiResp interface{}, rpcName string, rpcCl
|
||||
reflect.ValueOf(etcdConn),
|
||||
})[0].MethodByName(rpcFuncName) // rpc func
|
||||
rpcReqPtr := reflect.New(rpc.Type().In(1).Elem()) // *req参数
|
||||
if err := utils.CopyStructFields(rpcReqPtr.Interface(), apiReq); err != nil {
|
||||
trace_log.WriteErrorResponse(nCtx, "CopyStructFields_RpcReq", err)
|
||||
return
|
||||
}
|
||||
//if err := utils.CopyStructFields(rpcReqPtr.Interface(), apiReq); err != nil {
|
||||
// trace_log.WriteErrorResponse(nCtx, "CopyStructFields_RpcReq", err)
|
||||
// return
|
||||
//}
|
||||
CopyAny(apiReq, rpcReqPtr.Interface())
|
||||
trace_log.SetCtxInfo(nCtx, logFuncName, nil, "opUserID", c.GetString("opUserID"), "callRpcReq", rpcString(rpcReqPtr.Elem().Interface()))
|
||||
respArr := rpc.Call([]reflect.Value{
|
||||
reflect.ValueOf(context.Context(c)), // context.Context
|
||||
@ -48,9 +48,10 @@ func ApiToRpc(c *gin.Context, apiReq, apiResp interface{}, rpcName string, rpcCl
|
||||
rpcResp := respArr[0].Elem()
|
||||
trace_log.SetCtxInfo(nCtx, rpcFuncName, nil, "callRpcResp", rpcString(rpcResp.Interface()))
|
||||
if apiResp != nil {
|
||||
if err := utils.CopyStructFields(apiResp, rpcResp.Interface()); err != nil {
|
||||
trace_log.SetCtxInfo(nCtx, "CopyStructFields_RpcResp", err, "apiResp", fmt.Sprintf("%T", apiResp), "rpcResp", fmt.Sprintf("%T", rpcResp.Interface()))
|
||||
}
|
||||
//if err := utils.CopyStructFields(apiResp, rpcResp.Interface()); err != nil {
|
||||
// trace_log.SetCtxInfo(nCtx, "CopyStructFields_RpcResp", err, "apiResp", fmt.Sprintf("%T", apiResp), "rpcResp", fmt.Sprintf("%T", rpcResp.Interface()))
|
||||
//}
|
||||
CopyAny(rpcResp.Interface(), apiResp)
|
||||
}
|
||||
trace_log.SetSuccess(nCtx, rpcFuncName, apiResp)
|
||||
}
|
||||
|
250
internal/api_to_rpc/copy.go
Normal file
250
internal/api_to_rpc/copy.go
Normal file
@ -0,0 +1,250 @@
|
||||
package common
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"google.golang.org/protobuf/types/known/wrapperspb"
|
||||
"reflect"
|
||||
)
|
||||
|
||||
func setBaseValue(from, to reflect.Value) {
|
||||
if isBaseNil(from) {
|
||||
return
|
||||
}
|
||||
var l int
|
||||
t := to.Type()
|
||||
for t.Kind() == reflect.Ptr {
|
||||
l++
|
||||
t = t.Elem()
|
||||
}
|
||||
v := baseValue(from)
|
||||
for i := 0; i < l; i++ {
|
||||
t := reflect.New(v.Type())
|
||||
t.Elem().Set(v)
|
||||
v = t
|
||||
}
|
||||
to.Set(v)
|
||||
}
|
||||
|
||||
func CopyAny(from, to interface{}) {
|
||||
t := reflect.ValueOf(to)
|
||||
if t.Kind() == reflect.Ptr {
|
||||
t = t.Elem()
|
||||
}
|
||||
if !t.CanSet() {
|
||||
return
|
||||
}
|
||||
f := reflect.ValueOf(from)
|
||||
if isBaseNil(f) {
|
||||
return
|
||||
}
|
||||
copyAny(f, t)
|
||||
}
|
||||
|
||||
func copyAny(from, to reflect.Value) {
|
||||
if !to.CanSet() {
|
||||
return
|
||||
}
|
||||
if isBaseNil(from) {
|
||||
return
|
||||
}
|
||||
if isBaseNil(to) {
|
||||
to.Set(getBaseZeroValue(to.Type()))
|
||||
}
|
||||
btfrom := baseType(from.Type())
|
||||
btto := baseType(to.Type())
|
||||
if typeEq(btfrom, btto) {
|
||||
setBaseValue(from, to)
|
||||
return
|
||||
}
|
||||
if _, ok := wrapType[btto.String()]; ok { // string -> wrapperspb.StringValue
|
||||
val := reflect.New(btto).Elem()
|
||||
copyAny(from, val.FieldByName("Value"))
|
||||
setBaseValue(val, to)
|
||||
return
|
||||
}
|
||||
if _, ok := wrapType[btfrom.String()]; ok { // wrapperspb.StringValue -> string
|
||||
copyAny(baseValue(from).FieldByName("Value"), to)
|
||||
return
|
||||
}
|
||||
if btfrom.Kind() == reflect.Struct && btto.Kind() == reflect.Struct {
|
||||
copyStruct(baseValue(from), baseValue(to))
|
||||
return
|
||||
}
|
||||
if btfrom.Kind() == reflect.Slice && btto.Kind() == reflect.Slice {
|
||||
copySlice(baseValue(from), baseValue(to))
|
||||
return
|
||||
}
|
||||
if btto.Kind() == reflect.String {
|
||||
if isBaseNil(to) {
|
||||
to.Set(getBaseZeroValue(baseType(to.Type())))
|
||||
}
|
||||
setBaseValue(reflect.ValueOf(toString(from)), to)
|
||||
return
|
||||
}
|
||||
if toNumber(from, to) {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func getBaseZeroValue(t reflect.Type) reflect.Value {
|
||||
var l int
|
||||
for t.Kind() == reflect.Ptr {
|
||||
l++
|
||||
t = t.Elem()
|
||||
}
|
||||
v := reflect.Zero(t)
|
||||
for i := 0; i < l; i++ {
|
||||
t := reflect.New(v.Type())
|
||||
t.Elem().Set(v)
|
||||
v = t
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
func isBaseNil(v reflect.Value) bool {
|
||||
for {
|
||||
switch v.Kind() {
|
||||
case reflect.Ptr:
|
||||
v = v.Elem()
|
||||
case reflect.Invalid:
|
||||
return true
|
||||
default:
|
||||
return isNil(v)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func baseType(t reflect.Type) reflect.Type {
|
||||
for t.Kind() == reflect.Ptr {
|
||||
t = t.Elem()
|
||||
}
|
||||
return t
|
||||
}
|
||||
|
||||
func baseLayer(t reflect.Type) int {
|
||||
var layer int
|
||||
for t.Kind() == reflect.Ptr {
|
||||
layer++
|
||||
t = t.Elem()
|
||||
}
|
||||
return layer
|
||||
}
|
||||
|
||||
func typeEq(t1, t2 reflect.Type) bool {
|
||||
return t1.String() == t2.String()
|
||||
}
|
||||
|
||||
func isNil(value reflect.Value) bool {
|
||||
switch value.Kind() {
|
||||
case reflect.Chan, reflect.Func, reflect.Map, reflect.Pointer, reflect.UnsafePointer, reflect.Interface, reflect.Slice:
|
||||
return value.IsNil()
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func baseValue(value reflect.Value) reflect.Value {
|
||||
for value.Kind() == reflect.Ptr {
|
||||
value = value.Elem()
|
||||
}
|
||||
return value
|
||||
}
|
||||
|
||||
func copyStruct(from, to reflect.Value) {
|
||||
toType := to.Type()
|
||||
fromType := from.Type()
|
||||
n := to.NumField()
|
||||
for i := 0; i < n; i++ {
|
||||
toFieldType := toType.Field(i)
|
||||
if _, found := fromType.FieldByName(toFieldType.Name); !found {
|
||||
continue
|
||||
}
|
||||
copyAny(from.FieldByName(toFieldType.Name), to.Field(i))
|
||||
}
|
||||
}
|
||||
|
||||
func copySlice(from, to reflect.Value) {
|
||||
size := from.Len()
|
||||
temp := reflect.MakeSlice(to.Type(), 0, size)
|
||||
elemTo := to.Type().Elem()
|
||||
for i := 0; i < size; i++ {
|
||||
itemTo := getBaseZeroValue(elemTo)
|
||||
copyAny(from.Index(i), itemTo)
|
||||
temp = reflect.Append(temp, itemTo)
|
||||
}
|
||||
to.Set(temp)
|
||||
}
|
||||
|
||||
func toString(value reflect.Value) string {
|
||||
if value.Kind() == reflect.Slice {
|
||||
switch value.Type().String() {
|
||||
case "[]uint8":
|
||||
return string(value.Interface().([]uint8))
|
||||
case "[]int32":
|
||||
return string(value.Interface().([]int32))
|
||||
}
|
||||
}
|
||||
return fmt.Sprint(value.Interface())
|
||||
}
|
||||
|
||||
func toNumber(from1, to1 reflect.Value) bool {
|
||||
if isBaseNil(to1) {
|
||||
to1.Set(getBaseZeroValue(to1.Type()))
|
||||
}
|
||||
from := baseValue(from1)
|
||||
to := baseValue(to1)
|
||||
switch from.Kind() {
|
||||
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
|
||||
switch to.Kind() {
|
||||
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
|
||||
to.SetInt(from.Int())
|
||||
return true
|
||||
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
|
||||
to.SetUint(uint64(from.Int()))
|
||||
return true
|
||||
case reflect.Float64, reflect.Float32:
|
||||
to.SetFloat(float64(from.Int()))
|
||||
return true
|
||||
}
|
||||
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
|
||||
switch to.Kind() {
|
||||
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
|
||||
to.SetInt(int64(from.Uint()))
|
||||
return true
|
||||
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
|
||||
to.SetInt(int64(from.Uint()))
|
||||
return true
|
||||
case reflect.Float64, reflect.Float32:
|
||||
to.SetFloat(float64(from.Uint()))
|
||||
return true
|
||||
}
|
||||
case reflect.Float64, reflect.Float32:
|
||||
switch to.Kind() {
|
||||
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
|
||||
to.SetInt(int64(from.Float()))
|
||||
return true
|
||||
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
|
||||
to.SetUint(uint64(from.Float()))
|
||||
return true
|
||||
case reflect.Float64, reflect.Float32:
|
||||
to.SetFloat(from.Float())
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func typeName(v interface{}) string {
|
||||
return reflect.TypeOf(v).String()
|
||||
}
|
||||
|
||||
var wrapType = map[string]struct{}{
|
||||
typeName(wrapperspb.DoubleValue{}): {},
|
||||
typeName(wrapperspb.FloatValue{}): {},
|
||||
typeName(wrapperspb.Int64Value{}): {},
|
||||
typeName(wrapperspb.UInt64Value{}): {},
|
||||
typeName(wrapperspb.Int32Value{}): {},
|
||||
typeName(wrapperspb.UInt32Value{}): {},
|
||||
typeName(wrapperspb.BoolValue{}): {},
|
||||
typeName(wrapperspb.StringValue{}): {},
|
||||
typeName(wrapperspb.BytesValue{}): {},
|
||||
}
|
@ -12,6 +12,17 @@ import (
|
||||
http2 "net/http"
|
||||
)
|
||||
|
||||
func callbackBeforeAddFriendV1(req *pbFriend.AddFriendReq) error {
|
||||
resp := callbackBeforeAddFriend(req)
|
||||
if resp.ErrCode != 0 {
|
||||
return (&constant.ErrInfo{
|
||||
ErrCode: resp.ErrCode,
|
||||
ErrMsg: resp.ErrMsg,
|
||||
}).Wrap()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func callbackBeforeAddFriend(req *pbFriend.AddFriendReq) cbApi.CommonCallbackResp {
|
||||
callbackResp := cbApi.CommonCallbackResp{OperationID: req.CommID.OperationID}
|
||||
if !config.Config.Callback.CallbackBeforeAddFriend.Enable {
|
||||
|
@ -7,17 +7,17 @@ import (
|
||||
imdb "Open_IM/pkg/common/db/mysql_model/im_mysql_model"
|
||||
rocksCache "Open_IM/pkg/common/db/rocks_cache"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/common/middleware"
|
||||
promePkg "Open_IM/pkg/common/prometheus"
|
||||
"Open_IM/pkg/common/token_verify"
|
||||
"Open_IM/pkg/common/tools"
|
||||
cp "Open_IM/pkg/common/utils"
|
||||
"Open_IM/pkg/getcdv3"
|
||||
pbCache "Open_IM/pkg/proto/cache"
|
||||
pbFriend "Open_IM/pkg/proto/friend"
|
||||
sdkws "Open_IM/pkg/proto/sdk_ws"
|
||||
"Open_IM/pkg/utils"
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/OpenIMSDK/getcdv3"
|
||||
"net"
|
||||
"strconv"
|
||||
"strings"
|
||||
@ -29,19 +29,25 @@ import (
|
||||
)
|
||||
|
||||
type friendServer struct {
|
||||
rpcPort int
|
||||
rpcRegisterName string
|
||||
etcdSchema string
|
||||
etcdAddr []string
|
||||
rpcPort int
|
||||
rpcRegisterName string
|
||||
etcdSchema string
|
||||
etcdAddr []string
|
||||
friendModel *imdb.Friend
|
||||
friendRequestModel *imdb.FriendRequest
|
||||
blackModel *imdb.Black
|
||||
}
|
||||
|
||||
func NewFriendServer(port int) *friendServer {
|
||||
log.NewPrivateLog(constant.LogFileName)
|
||||
return &friendServer{
|
||||
rpcPort: port,
|
||||
rpcRegisterName: config.Config.RpcRegisterName.OpenImFriendName,
|
||||
etcdSchema: config.Config.Etcd.EtcdSchema,
|
||||
etcdAddr: config.Config.Etcd.EtcdAddr,
|
||||
rpcPort: port,
|
||||
rpcRegisterName: config.Config.RpcRegisterName.OpenImFriendName,
|
||||
etcdSchema: config.Config.Etcd.EtcdSchema,
|
||||
etcdAddr: config.Config.Etcd.EtcdAddr,
|
||||
friendModel: imdb.NewFriend(nil),
|
||||
friendRequestModel: imdb.NewFriendRequest(nil),
|
||||
blackModel: imdb.NewBlack(nil),
|
||||
}
|
||||
}
|
||||
|
||||
@ -65,6 +71,7 @@ func (s *friendServer) Run() {
|
||||
defer listener.Close()
|
||||
//grpc server
|
||||
var grpcOpts []grpc.ServerOption
|
||||
grpcOpts = append(grpcOpts, grpc.UnaryInterceptor(middleware.RpcServerInterceptor))
|
||||
if config.Config.Prometheus.Enable {
|
||||
promePkg.NewGrpcRequestCounter()
|
||||
promePkg.NewGrpcRequestFailedCounter()
|
||||
@ -100,67 +107,43 @@ 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(ctx, req.CommID.OpUserID, req.CommID.FromUserID)
|
||||
if !ok {
|
||||
return &pbFriend.AddBlacklistResp{CommonResp: constant.Error2CommResp(ctx, constant.ErrNoPermission, "accress")}, nil
|
||||
resp := &pbFriend.AddBlacklistResp{}
|
||||
if err := token_verify.CheckAccessV3(ctx, req.CommID.FromUserID); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
black := imdb.Black{OwnerUserID: req.CommID.FromUserID, BlockUserID: req.CommID.ToUserID, OperatorUserID: req.CommID.OpUserID}
|
||||
err := imdb.InsertInToUserBlackList(ctx, black)
|
||||
if err := s.blackModel.Create(ctx, []*imdb.Black{&black}); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
etcdConn, err := getcdv3.GetConn(ctx, config.Config.RpcRegisterName.OpenImCacheName)
|
||||
if err != nil {
|
||||
return &pbFriend.AddBlacklistResp{CommonResp: constant.Error2CommResp(ctx, constant.ErrDatabase, err.Error())}, nil
|
||||
return nil, err
|
||||
}
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImCacheName, req.CommID.OperationID, config.Config.Etcd.UserName, config.Config.Etcd.Password)
|
||||
if etcdConn == nil {
|
||||
return &pbFriend.AddBlacklistResp{CommonResp: constant.Error2CommResp(ctx, constant.ErrInternalServer, "conn is nil")}, nil
|
||||
}
|
||||
cacheClient := pbCache.NewCacheClient(etcdConn)
|
||||
cacheResp, err := cacheClient.DelBlackIDListFromCache(ctx, &pbCache.DelBlackIDListFromCacheReq{UserID: req.CommID.FromUserID, OperationID: req.CommID.OperationID})
|
||||
_, err = pbCache.NewCacheClient(etcdConn).DelBlackIDListFromCache(ctx, &pbCache.DelBlackIDListFromCacheReq{UserID: req.CommID.FromUserID, OperationID: req.CommID.OperationID})
|
||||
if 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))
|
||||
return &pbFriend.AddBlacklistResp{CommonResp: constant.Error2CommResp(ctx, constant.ErrInternalServer, err.Error())}, nil
|
||||
return nil, err
|
||||
}
|
||||
chat.BlackAddedNotification(req)
|
||||
return &pbFriend.AddBlacklistResp{CommonResp: constant.Error2CommResp(ctx, constant.ErrNone, "")}, nil
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (s *friendServer) AddFriend(ctx context.Context, req *pbFriend.AddFriendReq) (*pbFriend.AddFriendResp, error) {
|
||||
log.NewInfo(req.CommID.OperationID, "AddFriend args ", req.String())
|
||||
ok := token_verify.CheckAccess(ctx, req.CommID.OpUserID, req.CommID.FromUserID)
|
||||
if !ok {
|
||||
log.NewError(req.CommID.OperationID, "CheckAccess false ", req.CommID.OpUserID, req.CommID.FromUserID)
|
||||
return &pbFriend.AddFriendResp{CommonResp: &sdkws.CommonResp{ErrCode: constant.ErrNoPermission.ErrCode, ErrMsg: constant.ErrNoPermission.ErrMsg}}, nil
|
||||
resp := &pbFriend.AddFriendResp{}
|
||||
if err := token_verify.CheckAccessV3(ctx, req.CommID.FromUserID); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
callbackResp := callbackBeforeAddFriend(req)
|
||||
if callbackResp.ErrCode != 0 {
|
||||
log.NewError(req.CommID.OperationID, utils.GetSelfFuncName(), "callbackBeforeSendSingleMsg resp: ", callbackResp)
|
||||
if err := callbackBeforeAddFriendV1(req); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if callbackResp.ActionCode != constant.ActionAllow {
|
||||
if callbackResp.ErrCode == 0 {
|
||||
callbackResp.ErrCode = 201
|
||||
}
|
||||
log.NewDebug(req.CommID.OperationID, utils.GetSelfFuncName(), "callbackBeforeSendSingleMsg result", "end rpc and return", callbackResp)
|
||||
return &pbFriend.AddFriendResp{CommonResp: &sdkws.CommonResp{
|
||||
ErrCode: int32(callbackResp.ErrCode),
|
||||
ErrMsg: callbackResp.ErrMsg,
|
||||
}}, nil
|
||||
}
|
||||
var isSend = true
|
||||
userIDList, err := rocksCache.GetFriendIDListFromCache(ctx, req.CommID.ToUserID)
|
||||
if err != nil {
|
||||
log.NewError(req.CommID.OperationID, "GetFriendIDListFromCache failed ", err.Error(), req.CommID.ToUserID)
|
||||
return &pbFriend.AddFriendResp{CommonResp: &sdkws.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: err.Error()}}, nil
|
||||
return nil, err
|
||||
}
|
||||
userIDList2, err := rocksCache.GetFriendIDListFromCache(ctx, req.CommID.FromUserID)
|
||||
if err != nil {
|
||||
log.NewError(req.CommID.OperationID, "GetUserByUserID failed ", err.Error(), req.CommID.FromUserID)
|
||||
return &pbFriend.AddFriendResp{CommonResp: &sdkws.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: err.Error()}}, nil
|
||||
return nil, err
|
||||
}
|
||||
log.NewDebug(req.CommID.OperationID, "toUserID", userIDList, "fromUserID", userIDList2)
|
||||
var isSend = true
|
||||
for _, v := range userIDList {
|
||||
if v == req.CommID.FromUserID {
|
||||
for _, v2 := range userIDList2 {
|
||||
@ -176,85 +159,73 @@ func (s *friendServer) AddFriend(ctx context.Context, req *pbFriend.AddFriendReq
|
||||
//Cannot add non-existent users
|
||||
|
||||
if isSend {
|
||||
if _, err := imdb.GetUserByUserID(req.CommID.ToUserID); err != nil {
|
||||
log.NewError(req.CommID.OperationID, "GetUserByUserID failed ", err.Error(), req.CommID.ToUserID)
|
||||
return &pbFriend.AddFriendResp{CommonResp: &sdkws.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
|
||||
if _, err := GetUserInfo(ctx, req.CommID.ToUserID); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
friendRequest := imdb.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 }]
|
||||
log.NewDebug(req.CommID.OperationID, "UpdateFriendApplication args ", friendRequest)
|
||||
//err := imdb.InsertFriendApplication(&friendRequest)
|
||||
err := imdb.InsertFriendApplication(&friendRequest,
|
||||
map[string]interface{}{"handle_result": 0, "req_msg": friendRequest.ReqMsg, "create_time": friendRequest.CreateTime,
|
||||
"handler_user_id": "", "handle_msg": "", "handle_time": utils.UnixSecondToTime(0), "ex": ""})
|
||||
if err != nil {
|
||||
log.NewError(req.CommID.OperationID, "UpdateFriendApplication failed ", err.Error(), friendRequest)
|
||||
return &pbFriend.AddFriendResp{CommonResp: &sdkws.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
|
||||
FromUserID: req.CommID.FromUserID,
|
||||
ToUserID: req.CommID.ToUserID,
|
||||
HandleResult: 0,
|
||||
ReqMsg: req.ReqMsg,
|
||||
CreateTime: time.Now(),
|
||||
}
|
||||
if err := s.friendRequestModel.Create(ctx, []*imdb.FriendRequest{&friendRequest}); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
chat.FriendApplicationNotification(req)
|
||||
}
|
||||
//Establish a latest relationship in the friend request table
|
||||
|
||||
return &pbFriend.AddFriendResp{CommonResp: &sdkws.CommonResp{}}, nil
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (s *friendServer) ImportFriend(ctx context.Context, req *pbFriend.ImportFriendReq) (*pbFriend.ImportFriendResp, error) {
|
||||
log.NewInfo(req.OperationID, "ImportFriend args ", req.String())
|
||||
resp := pbFriend.ImportFriendResp{CommonResp: &sdkws.CommonResp{}}
|
||||
var c sdkws.CommonResp
|
||||
|
||||
if !utils.IsContain(req.OpUserID, config.Config.Manager.AppManagerUid) {
|
||||
log.NewError(req.OperationID, "not authorized", req.OpUserID, config.Config.Manager.AppManagerUid)
|
||||
c.ErrCode = constant.ErrNoPermission.ErrCode
|
||||
c.ErrMsg = constant.ErrNoPermission.ErrMsg
|
||||
for _, v := range req.FriendUserIDList {
|
||||
resp.UserIDResultList = append(resp.UserIDResultList, &pbFriend.UserIDResult{UserID: v, Result: -1})
|
||||
}
|
||||
resp.CommonResp = &c
|
||||
return &resp, nil
|
||||
resp := &pbFriend.ImportFriendResp{}
|
||||
//var c sdkws.CommonResp
|
||||
if !utils.IsContain(tools.OpUserID(ctx), config.Config.Manager.AppManagerUid) {
|
||||
//log.NewError(req.OperationID, "not authorized", req.OpUserID, config.Config.Manager.AppManagerUid)
|
||||
//c.ErrCode = constant.ErrNoPermission.ErrCode
|
||||
//c.ErrMsg = constant.ErrNoPermission.ErrMsg
|
||||
//for _, userID := range req.FriendUserIDList {
|
||||
// resp.UserIDResultList = append(resp.UserIDResultList, &pbFriend.UserIDResult{UserID: userID, Result: -1})
|
||||
//}
|
||||
return nil, constant.ErrNoPermission.Wrap()
|
||||
}
|
||||
if _, err := imdb.GetUserByUserID(req.FromUserID); err != nil {
|
||||
log.NewError(req.OperationID, "GetUserByUserID failed ", err.Error(), req.FromUserID)
|
||||
c.ErrCode = constant.ErrDB.ErrCode
|
||||
c.ErrMsg = "this user not exists,cant not add friend"
|
||||
for _, v := range req.FriendUserIDList {
|
||||
resp.UserIDResultList = append(resp.UserIDResultList, &pbFriend.UserIDResult{UserID: v, Result: -1})
|
||||
}
|
||||
resp.CommonResp = &c
|
||||
return &resp, nil
|
||||
if _, err := GetUserInfo(ctx, req.FromUserID); err != nil {
|
||||
//log.NewError(req.OperationID, "GetUserByUserID failed ", err.Error(), req.FromUserID)
|
||||
//c.ErrCode = constant.ErrDB.ErrCode
|
||||
//c.ErrMsg = "this user not exists,cant not add friend"
|
||||
//for _, userID := range req.FriendUserIDList {
|
||||
// resp.UserIDResultList = append(resp.UserIDResultList, &pbFriend.UserIDResult{UserID: userID, Result: -1})
|
||||
//}
|
||||
//resp.CommonResp = &c
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for _, v := range req.FriendUserIDList {
|
||||
log.NewDebug(req.OperationID, "FriendUserIDList ", v)
|
||||
if _, fErr := imdb.GetUserByUserID(v); fErr != nil {
|
||||
log.NewError(req.OperationID, "GetUserByUserID failed ", fErr.Error(), v)
|
||||
resp.UserIDResultList = append(resp.UserIDResultList, &pbFriend.UserIDResult{UserID: v, Result: -1})
|
||||
for _, userID := range req.FriendUserIDList {
|
||||
if _, fErr := GetUserInfo(ctx, userID); fErr != nil {
|
||||
resp.UserIDResultList = append(resp.UserIDResultList, &pbFriend.UserIDResult{UserID: userID, Result: -1})
|
||||
} else {
|
||||
if _, err := imdb.GetFriendRelationshipFromFriend(req.FromUserID, v); err != nil {
|
||||
if _, err := imdb.GetFriendRelationshipFromFriend(req.FromUserID, userID); err != nil {
|
||||
//Establish two single friendship
|
||||
toInsertFollow := imdb.Friend{OwnerUserID: req.FromUserID, FriendUserID: v}
|
||||
toInsertFollow := imdb.Friend{OwnerUserID: req.FromUserID, FriendUserID: userID}
|
||||
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})
|
||||
resp.UserIDResultList = append(resp.UserIDResultList, &pbFriend.UserIDResult{UserID: userID, Result: -1})
|
||||
continue
|
||||
}
|
||||
toInsertFollow = imdb.Friend{OwnerUserID: v, FriendUserID: req.FromUserID}
|
||||
toInsertFollow = imdb.Friend{OwnerUserID: userID, FriendUserID: req.FromUserID}
|
||||
err2 := imdb.InsertToFriend(&toInsertFollow)
|
||||
if err2 != nil {
|
||||
log.NewError(req.OperationID, "InsertToFriend failed ", err2.Error(), toInsertFollow)
|
||||
resp.UserIDResultList = append(resp.UserIDResultList, &pbFriend.UserIDResult{UserID: v, Result: -1})
|
||||
resp.UserIDResultList = append(resp.UserIDResultList, &pbFriend.UserIDResult{UserID: userID, Result: -1})
|
||||
continue
|
||||
}
|
||||
resp.UserIDResultList = append(resp.UserIDResultList, &pbFriend.UserIDResult{UserID: v, Result: 0})
|
||||
resp.UserIDResultList = append(resp.UserIDResultList, &pbFriend.UserIDResult{UserID: userID, Result: 0})
|
||||
log.NewDebug(req.OperationID, "UserIDResultList ", resp.UserIDResultList)
|
||||
chat.FriendAddedNotification(req.OperationID, req.OpUserID, req.FromUserID, v)
|
||||
chat.FriendAddedNotification(req.OperationID, req.OpUserID, req.FromUserID, userID)
|
||||
} else {
|
||||
log.NewWarn(req.OperationID, "GetFriendRelationshipFromFriend ok", req.FromUserID, v)
|
||||
resp.UserIDResultList = append(resp.UserIDResultList, &pbFriend.UserIDResult{UserID: v, Result: 0})
|
||||
log.NewWarn(req.OperationID, "GetFriendRelationshipFromFriend ok", req.FromUserID, userID)
|
||||
resp.UserIDResultList = append(resp.UserIDResultList, &pbFriend.UserIDResult{UserID: userID, Result: 0})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
10
internal/rpc/friend/other.go
Normal file
10
internal/rpc/friend/other.go
Normal file
@ -0,0 +1,10 @@
|
||||
package friend
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
)
|
||||
|
||||
func GetUserInfo(ctx context.Context, userID string) (interface{}, error) {
|
||||
return nil, errors.New("TODO:GetUserInfo")
|
||||
}
|
42
internal/rpc/group/g.go
Normal file
42
internal/rpc/group/g.go
Normal file
@ -0,0 +1,42 @@
|
||||
package group
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/constant"
|
||||
imdb "Open_IM/pkg/common/db/mysql_model/im_mysql_model"
|
||||
"Open_IM/pkg/common/tools"
|
||||
pbGroup "Open_IM/pkg/proto/group"
|
||||
"Open_IM/pkg/utils"
|
||||
"context"
|
||||
"time"
|
||||
)
|
||||
|
||||
func getDBGroupRequest(ctx context.Context, req *pbGroup.GroupApplicationResponseReq) (dbGroupRequest *imdb.GroupRequest) {
|
||||
dbGroupRequest = &imdb.GroupRequest{}
|
||||
utils.CopyStructFields(&dbGroupRequest, req)
|
||||
dbGroupRequest.UserID = req.FromUserID
|
||||
dbGroupRequest.HandleUserID = tools.OpUserID(ctx)
|
||||
dbGroupRequest.HandledTime = time.Now()
|
||||
return dbGroupRequest
|
||||
}
|
||||
|
||||
func getDBGroupMember(ctx context.Context, req *pbGroup.GroupApplicationResponseReq) (dbGroupMember *imdb.GroupMember) {
|
||||
dbGroupMember = &imdb.GroupMember{}
|
||||
utils.CopyStructFields(&dbGroupRequest, req)
|
||||
dbGroupRequest.UserID = req.FromUserID
|
||||
dbGroupRequest.HandleUserID = tools.OpUserID(ctx)
|
||||
dbGroupRequest.HandledTime = time.Now()
|
||||
|
||||
member := imdb.GroupMember{}
|
||||
member.GroupID = req.GroupID
|
||||
member.UserID = req.FromUserID
|
||||
member.RoleLevel = constant.GroupOrdinaryUsers
|
||||
member.OperatorUserID = tools.OpUserID(ctx)
|
||||
|
||||
member.FaceURL = user.FaceURL
|
||||
member.Nickname = user.Nickname
|
||||
member.JoinSource = request.JoinSource
|
||||
member.InviterUserID = request.InviterUserID
|
||||
member.MuteEndTime = time.Unix(int64(time.Now().Second()), 0)
|
||||
|
||||
return dbGroupRequest
|
||||
}
|
@ -134,17 +134,17 @@ func (s *groupServer) CreateGroup(ctx context.Context, req *pbGroup.CreateGroupR
|
||||
userIDs = append(userIDs, req.OwnerUserID)
|
||||
}
|
||||
if groupOwnerNum != 1 {
|
||||
return nil, utils.Wrap(constant.ErrArgs, "")
|
||||
return nil, constant.ErrArgs.Wrap("groupOwnerNum != 1")
|
||||
}
|
||||
if utils.IsRepeatStringSlice(userIDs) {
|
||||
return nil, utils.Wrap(constant.ErrArgs, "")
|
||||
return nil, constant.ErrArgs.Wrap("group member is repeated")
|
||||
}
|
||||
users, err := rocksCache.GetUserInfoFromCacheBatch(ctx, userIDs)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(users) != len(userIDs) {
|
||||
return nil, utils.Wrap(constant.ErrArgs, "")
|
||||
return nil, constant.ErrDatabase.Wrap("len(users from cache) != len(userIDs)")
|
||||
}
|
||||
userMap := make(map[string]*imdb.User)
|
||||
for i, user := range users {
|
||||
@ -158,14 +158,14 @@ func (s *groupServer) CreateGroup(ctx context.Context, req *pbGroup.CreateGroupR
|
||||
}
|
||||
groupId := req.GroupInfo.GroupID
|
||||
if groupId == "" {
|
||||
groupId = utils.Md5(req.OperationID + strconv.FormatInt(time.Now().UnixNano(), 10))
|
||||
groupId = utils.Md5(tools.OperationID(ctx) + strconv.FormatInt(time.Now().UnixNano(), 10))
|
||||
bi := big.NewInt(0)
|
||||
bi.SetString(groupId[0:8], 16)
|
||||
groupId = bi.String()
|
||||
}
|
||||
groupInfo := imdb.Group{}
|
||||
utils.CopyStructFields(&groupInfo, req.GroupInfo)
|
||||
groupInfo.CreatorUserID = req.OpUserID
|
||||
groupInfo.CreatorUserID = tools.OpUserID(ctx)
|
||||
groupInfo.GroupID = groupId
|
||||
groupInfo.CreateTime = time.Now()
|
||||
if groupInfo.NotificationUpdateTime.Unix() < 0 {
|
||||
@ -174,10 +174,10 @@ func (s *groupServer) CreateGroup(ctx context.Context, req *pbGroup.CreateGroupR
|
||||
if req.GroupInfo.GroupType != constant.SuperGroup {
|
||||
var groupMembers []*imdb.GroupMember
|
||||
joinGroup := func(userID string, roleLevel int32) error {
|
||||
groupMember := &imdb.GroupMember{GroupID: groupId, RoleLevel: roleLevel, OperatorUserID: req.OpUserID, JoinSource: constant.JoinByInvitation, InviterUserID: req.OpUserID}
|
||||
groupMember := &imdb.GroupMember{GroupID: groupId, RoleLevel: roleLevel, OperatorUserID: tools.OpUserID(ctx), JoinSource: constant.JoinByInvitation, InviterUserID: tools.OpUserID(ctx)}
|
||||
user := userMap[userID]
|
||||
utils.CopyStructFields(&groupMember, user)
|
||||
if err := CallbackBeforeMemberJoinGroup(ctx, req.OperationID, groupMember, groupInfo.Ex); err != nil {
|
||||
if err := CallbackBeforeMemberJoinGroup(ctx, tools.OperationID(ctx), groupMember, groupInfo.Ex); err != nil {
|
||||
return err
|
||||
}
|
||||
groupMembers = append(groupMembers, groupMember)
|
||||
@ -207,7 +207,7 @@ func (s *groupServer) CreateGroup(ctx context.Context, req *pbGroup.CreateGroupR
|
||||
utils.CopyStructFields(resp.GroupInfo, groupInfo)
|
||||
resp.GroupInfo.MemberCount = uint32(len(userIDs))
|
||||
if req.GroupInfo.GroupType != constant.SuperGroup {
|
||||
chat.GroupCreatedNotification(req.OperationID, req.OpUserID, groupId, userIDs)
|
||||
chat.GroupCreatedNotification(tools.OperationID(ctx), tools.OpUserID(ctx), groupId, userIDs)
|
||||
} else {
|
||||
for _, userID := range userIDs {
|
||||
if err := rocksCache.DelJoinedSuperGroupIDListFromCache(ctx, userID); err != nil {
|
||||
@ -216,7 +216,7 @@ func (s *groupServer) CreateGroup(ctx context.Context, req *pbGroup.CreateGroupR
|
||||
}
|
||||
go func() {
|
||||
for _, v := range userIDs {
|
||||
chat.SuperGroupNotification(req.OperationID, v, v)
|
||||
chat.SuperGroupNotification(tools.OperationID(ctx), v, v)
|
||||
}
|
||||
}()
|
||||
}
|
||||
@ -237,7 +237,7 @@ func (s *groupServer) GetJoinedGroupList(ctx context.Context, req *pbGroup.GetJo
|
||||
var groupNode open_im_sdk.GroupInfo
|
||||
num, err := rocksCache.GetGroupMemberNumFromCache(ctx, groupID)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), groupID)
|
||||
log.NewError(tools.OperationID(ctx), utils.GetSelfFuncName(), err.Error(), groupID)
|
||||
continue
|
||||
}
|
||||
owner, err := (*imdb.GroupMember)(nil).TakeOwnerInfo(ctx, groupID)
|
||||
@ -285,14 +285,14 @@ func (s *groupServer) InviteUserToGroup(ctx context.Context, req *pbGroup.Invite
|
||||
return nil, utils.Wrap(constant.ErrDismissedAlready, "")
|
||||
}
|
||||
if groupInfo.NeedVerification == constant.AllNeedVerification &&
|
||||
!imdb.IsGroupOwnerAdmin(req.GroupID, req.OpUserID) && !token_verify.IsManagerUserID(req.OpUserID) {
|
||||
!imdb.IsGroupOwnerAdmin(req.GroupID, tools.OpUserID(ctx)) && !token_verify.IsManagerUserID(tools.OpUserID(ctx)) {
|
||||
joinReq := pbGroup.JoinGroupReq{}
|
||||
for _, v := range req.InvitedUserIDList {
|
||||
var groupRequest imdb.GroupRequest
|
||||
groupRequest.UserID = v
|
||||
groupRequest.GroupID = req.GroupID
|
||||
groupRequest.JoinSource = constant.JoinByInvitation
|
||||
groupRequest.InviterUserID = req.OpUserID
|
||||
groupRequest.InviterUserID = tools.OpUserID(ctx)
|
||||
err = imdb.InsertIntoGroupRequest(groupRequest)
|
||||
if err != nil {
|
||||
var resultNode pbGroup.Id2Result
|
||||
@ -306,10 +306,8 @@ func (s *groupServer) InviteUserToGroup(ctx context.Context, req *pbGroup.Invite
|
||||
resultNode.UserID = v
|
||||
resp.Id2ResultList = append(resp.Id2ResultList, &resultNode)
|
||||
joinReq.GroupID = req.GroupID
|
||||
joinReq.OperationID = req.OperationID
|
||||
joinReq.OpUserID = v
|
||||
resp.Id2ResultList = append(resp.Id2ResultList, &resultNode)
|
||||
chat.JoinGroupApplicationNotification(&joinReq)
|
||||
chat.JoinGroupApplicationNotification(ctx, &joinReq)
|
||||
}
|
||||
}
|
||||
return resp, nil
|
||||
@ -343,10 +341,10 @@ func (s *groupServer) InviteUserToGroup(ctx context.Context, req *pbGroup.Invite
|
||||
utils.CopyStructFields(&toInsertInfo, toUserInfo)
|
||||
toInsertInfo.GroupID = req.GroupID
|
||||
toInsertInfo.RoleLevel = constant.GroupOrdinaryUsers
|
||||
toInsertInfo.OperatorUserID = req.OpUserID
|
||||
toInsertInfo.InviterUserID = req.OpUserID
|
||||
toInsertInfo.OperatorUserID = tools.OpUserID(ctx)
|
||||
toInsertInfo.InviterUserID = tools.OpUserID(ctx)
|
||||
toInsertInfo.JoinSource = constant.JoinByInvitation
|
||||
if err := CallbackBeforeMemberJoinGroup(ctx, req.OperationID, &toInsertInfo, groupInfo.Ex); err != nil {
|
||||
if err := CallbackBeforeMemberJoinGroup(ctx, tools.OperationID(ctx), &toInsertInfo, groupInfo.Ex); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = imdb.InsertIntoGroupMember(toInsertInfo)
|
||||
@ -371,7 +369,7 @@ func (s *groupServer) InviteUserToGroup(ctx context.Context, req *pbGroup.Invite
|
||||
}
|
||||
|
||||
if groupInfo.GroupType != constant.SuperGroup {
|
||||
chat.MemberInvitedNotification(req.OperationID, req.GroupID, req.OpUserID, req.Reason, okUserIDList)
|
||||
chat.MemberInvitedNotification(tools.OperationID(ctx), req.GroupID, tools.OpUserID(ctx), req.Reason, okUserIDList)
|
||||
} else {
|
||||
for _, userID := range req.InvitedUserIDList {
|
||||
if err := rocksCache.DelJoinedSuperGroupIDListFromCache(ctx, userID); err != nil {
|
||||
@ -379,7 +377,7 @@ func (s *groupServer) InviteUserToGroup(ctx context.Context, req *pbGroup.Invite
|
||||
}
|
||||
}
|
||||
for _, v := range req.InvitedUserIDList {
|
||||
chat.SuperGroupNotification(req.OperationID, v, v)
|
||||
chat.SuperGroupNotification(tools.OperationID(ctx), v, v)
|
||||
}
|
||||
}
|
||||
return resp, nil
|
||||
@ -458,10 +456,9 @@ func (s *groupServer) KickGroupMember(ctx context.Context, req *pbGroup.KickGrou
|
||||
var okUserIDList []string
|
||||
if groupInfo.GroupType != constant.SuperGroup {
|
||||
opFlag := 0
|
||||
if !token_verify.IsManagerUserID(req.OpUserID) {
|
||||
opInfo, err := rocksCache.GetGroupMemberInfoFromCache(ctx, req.GroupID, req.OpUserID)
|
||||
if !token_verify.IsManagerUserID(tools.OpUserID(ctx)) {
|
||||
opInfo, err := rocksCache.GetGroupMemberInfoFromCache(ctx, req.GroupID, tools.OpUserID(ctx))
|
||||
if err != nil {
|
||||
constant.SetErrorForResp(err, resp.CommonResp)
|
||||
return nil, err
|
||||
}
|
||||
if opInfo.RoleLevel == constant.GroupOrdinaryUsers {
|
||||
@ -507,7 +504,7 @@ func (s *groupServer) KickGroupMember(ctx context.Context, req *pbGroup.KickGrou
|
||||
err = imdb.DeleteGroupMemberByGroupIDAndUserID(req.GroupID, v)
|
||||
trace_log.SetCtxInfo(ctx, "RemoveGroupMember", err, "groupID", req.GroupID, "userID", v)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "RemoveGroupMember failed ", err.Error(), req.GroupID, v)
|
||||
log.NewError(tools.OperationID(ctx), "RemoveGroupMember failed ", err.Error(), req.GroupID, v)
|
||||
resp.Id2ResultList = append(resp.Id2ResultList, &pbGroup.Id2Result{UserID: v, Result: -1})
|
||||
} else {
|
||||
resp.Id2ResultList = append(resp.Id2ResultList, &pbGroup.Id2Result{UserID: v, Result: 0})
|
||||
@ -517,7 +514,7 @@ func (s *groupServer) KickGroupMember(ctx context.Context, req *pbGroup.KickGrou
|
||||
var reqPb pbUser.SetConversationReq
|
||||
var c pbConversation.Conversation
|
||||
for _, v := range okUserIDList {
|
||||
reqPb.OperationID = req.OperationID
|
||||
reqPb.OperationID = tools.OperationID(ctx)
|
||||
c.OwnerUserID = v
|
||||
c.ConversationID = utils.GetConversationIDBySessionType(req.GroupID, constant.GroupChatType)
|
||||
c.ConversationType = constant.GroupChatType
|
||||
@ -554,7 +551,7 @@ func (s *groupServer) KickGroupMember(ctx context.Context, req *pbGroup.KickGrou
|
||||
}
|
||||
go func() {
|
||||
for _, v := range req.KickedUserIDList {
|
||||
chat.SuperGroupNotification(req.OperationID, v, v)
|
||||
chat.SuperGroupNotification(tools.OperationID(ctx), v, v)
|
||||
}
|
||||
}()
|
||||
|
||||
@ -611,7 +608,7 @@ func (s *groupServer) GetGroupApplicationList(ctx context.Context, req *pbGroup.
|
||||
trace_log.SetCtxInfo(ctx, "GetRecvGroupApplicationList", nil, " FromUserID: ", req.FromUserID, "GroupApplicationList: ", reply)
|
||||
for _, v := range reply {
|
||||
node := open_im_sdk.GroupRequest{UserInfo: &open_im_sdk.PublicUserInfo{}, GroupInfo: &open_im_sdk.GroupInfo{}}
|
||||
err := FillGroupInfoByGroupID(req.OperationID, v.GroupID, node.GroupInfo)
|
||||
err := FillGroupInfoByGroupID(tools.OperationID(ctx), v.GroupID, node.GroupInfo)
|
||||
if err != nil {
|
||||
if !errors.Is(errors.Unwrap(err), constant.ErrDismissedAlready) {
|
||||
errResult = err
|
||||
@ -619,7 +616,7 @@ func (s *groupServer) GetGroupApplicationList(ctx context.Context, req *pbGroup.
|
||||
continue
|
||||
}
|
||||
trace_log.SetCtxInfo(ctx, "FillGroupInfoByGroupID ", nil, " groupID: ", v.GroupID, " groupInfo: ", node.GroupInfo)
|
||||
err = FillPublicUserInfoByUserID(req.OperationID, v.UserID, node.UserInfo)
|
||||
err = FillPublicUserInfoByUserID(tools.OperationID(ctx), v.UserID, node.UserInfo)
|
||||
if err != nil {
|
||||
errResult = err
|
||||
continue
|
||||
@ -640,7 +637,6 @@ func (s *groupServer) GetGroupsInfo(ctx context.Context, req *pbGroup.GetGroupsI
|
||||
for _, groupID := range req.GroupIDList {
|
||||
groupInfoFromRedis, err := rocksCache.GetGroupInfoFromCache(ctx, groupID)
|
||||
if err != nil {
|
||||
constant.SetErrorForResp(err, resp.CommonResp)
|
||||
continue
|
||||
}
|
||||
var groupInfo open_im_sdk.GroupInfo
|
||||
@ -665,15 +661,11 @@ func CheckPermission(ctx context.Context, groupID string, userID string) (err er
|
||||
func (s *groupServer) GroupApplicationResponse(ctx context.Context, req *pbGroup.GroupApplicationResponseReq) (*pbGroup.GroupApplicationResponseResp, error) {
|
||||
resp := &pbGroup.GroupApplicationResponseResp{}
|
||||
|
||||
if err := CheckPermission(ctx, req.GroupID, req.OpUserID); err != nil {
|
||||
if err := CheckPermission(ctx, req.GroupID, tools.OpUserID(ctx)); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
groupRequest := imdb.GroupRequest{}
|
||||
utils.CopyStructFields(&groupRequest, req)
|
||||
groupRequest.UserID = req.FromUserID
|
||||
groupRequest.HandleUserID = req.OpUserID
|
||||
groupRequest.HandledTime = time.Now()
|
||||
if err := (&imdb.GroupRequest{}).Update(ctx, []*imdb.GroupRequest{&groupRequest}); err != nil {
|
||||
groupRequest := getDBGroupRequest(ctx, req)
|
||||
if err := (&imdb.GroupRequest{}).Update(ctx, []*imdb.GroupRequest{groupRequest}); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
groupInfo, err := rocksCache.GetGroupInfoFromCache(ctx, req.GroupID)
|
||||
@ -693,13 +685,13 @@ func (s *groupServer) GroupApplicationResponse(ctx context.Context, req *pbGroup
|
||||
member.GroupID = req.GroupID
|
||||
member.UserID = req.FromUserID
|
||||
member.RoleLevel = constant.GroupOrdinaryUsers
|
||||
member.OperatorUserID = req.OpUserID
|
||||
member.OperatorUserID = tools.OpUserID(ctx)
|
||||
member.FaceURL = user.FaceURL
|
||||
member.Nickname = user.Nickname
|
||||
member.JoinSource = request.JoinSource
|
||||
member.InviterUserID = request.InviterUserID
|
||||
member.MuteEndTime = time.Unix(int64(time.Now().Second()), 0)
|
||||
err = CallbackBeforeMemberJoinGroup(ctx, req.OperationID, &member, groupInfo.Ex)
|
||||
err = CallbackBeforeMemberJoinGroup(ctx, tools.OperationID(ctx), &member, groupInfo.Ex)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -708,12 +700,12 @@ func (s *groupServer) GroupApplicationResponse(ctx context.Context, req *pbGroup
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
etcdCacheConn, err := fault_tolerant.GetDefaultConn(config.Config.RpcRegisterName.OpenImCacheName, req.OperationID)
|
||||
etcdCacheConn, err := fault_tolerant.GetDefaultConn(config.Config.RpcRegisterName.OpenImCacheName, tools.OperationID(ctx))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
cacheClient := pbCache.NewCacheClient(etcdCacheConn)
|
||||
cacheResp, err := cacheClient.DelGroupMemberIDListFromCache(context.Background(), &pbCache.DelGroupMemberIDListFromCacheReq{OperationID: req.OperationID, GroupID: req.GroupID})
|
||||
cacheResp, err := cacheClient.DelGroupMemberIDListFromCache(context.Background(), &pbCache.DelGroupMemberIDListFromCacheReq{OperationID: tools.OperationID(ctx), GroupID: req.GroupID})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -740,7 +732,7 @@ func (s *groupServer) GroupApplicationResponse(ctx context.Context, req *pbGroup
|
||||
func (s *groupServer) JoinGroup(ctx context.Context, req *pbGroup.JoinGroupReq) (*pbGroup.JoinGroupResp, error) {
|
||||
resp := &pbGroup.JoinGroupResp{}
|
||||
|
||||
if _, err := imdb.GetUserByUserID(req.OpUserID); err != nil {
|
||||
if _, err := imdb.GetUserByUserID(tools.OpUserID(ctx)); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
groupInfo, err := rocksCache.GetGroupInfoFromCache(ctx, req.GroupID)
|
||||
@ -748,23 +740,22 @@ func (s *groupServer) JoinGroup(ctx context.Context, req *pbGroup.JoinGroupReq)
|
||||
return nil, err
|
||||
}
|
||||
if groupInfo.Status == constant.GroupStatusDismissed {
|
||||
constant.SetErrorForResp(constant.ErrDismissedAlready, resp.CommonResp)
|
||||
return nil, utils.Wrap(constant.ErrDismissedAlready, "")
|
||||
}
|
||||
|
||||
if groupInfo.NeedVerification == constant.Directly {
|
||||
if groupInfo.GroupType != constant.SuperGroup {
|
||||
us, err := imdb.GetUserByUserID(req.OpUserID)
|
||||
us, err := imdb.GetUserByUserID(tools.OpUserID(ctx))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
//to group member
|
||||
groupMember := imdb.GroupMember{GroupID: req.GroupID, RoleLevel: constant.GroupOrdinaryUsers, OperatorUserID: req.OpUserID}
|
||||
groupMember := imdb.GroupMember{GroupID: req.GroupID, RoleLevel: constant.GroupOrdinaryUsers, OperatorUserID: tools.OpUserID(ctx)}
|
||||
utils.CopyStructFields(&groupMember, us)
|
||||
if err := CallbackBeforeMemberJoinGroup(ctx, req.OperationID, &groupMember, groupInfo.Ex); err != nil {
|
||||
if err := CallbackBeforeMemberJoinGroup(ctx, tools.OperationID(ctx), &groupMember, groupInfo.Ex); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := s.DelGroupAndUserCache(ctx, req.GroupID, []string{req.OpUserID}); err != nil {
|
||||
if err := s.DelGroupAndUserCache(ctx, req.GroupID, []string{tools.OpUserID(ctx)}); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = imdb.InsertIntoGroupMember(groupMember)
|
||||
@ -780,8 +771,8 @@ func (s *groupServer) JoinGroup(ctx context.Context, req *pbGroup.JoinGroupReq)
|
||||
}
|
||||
var reqPb pbUser.SetConversationReq
|
||||
var c pbConversation.Conversation
|
||||
reqPb.OperationID = req.OperationID
|
||||
c.OwnerUserID = req.OpUserID
|
||||
reqPb.OperationID = tools.OperationID(ctx)
|
||||
c.OwnerUserID = tools.OpUserID(ctx)
|
||||
c.ConversationID = utils.GetConversationIDBySessionType(req.GroupID, sessionType)
|
||||
c.ConversationType = int32(sessionType)
|
||||
c.GroupID = req.GroupID
|
||||
@ -795,7 +786,7 @@ func (s *groupServer) JoinGroup(ctx context.Context, req *pbGroup.JoinGroupReq)
|
||||
client := pbUser.NewUserClient(etcdConn)
|
||||
respPb, err := client.SetConversation(context.Background(), &reqPb)
|
||||
trace_log.SetCtxInfo(ctx, "SetConversation", err, "req", reqPb, "resp", respPb)
|
||||
chat.MemberEnterDirectlyNotification(req.GroupID, req.OpUserID, req.OperationID)
|
||||
chat.MemberEnterDirectlyNotification(req.GroupID, tools.OpUserID(ctx), tools.OperationID(ctx))
|
||||
return resp, nil
|
||||
} else {
|
||||
constant.SetErrorForResp(constant.ErrGroupTypeNotSupport, resp.CommonResp)
|
||||
@ -803,7 +794,7 @@ func (s *groupServer) JoinGroup(ctx context.Context, req *pbGroup.JoinGroupReq)
|
||||
}
|
||||
}
|
||||
var groupRequest imdb.GroupRequest
|
||||
groupRequest.UserID = req.OpUserID
|
||||
groupRequest.UserID = tools.OpUserID(ctx)
|
||||
groupRequest.ReqMsg = req.ReqMessage
|
||||
groupRequest.GroupID = req.GroupID
|
||||
groupRequest.JoinSource = req.JoinSource
|
||||
@ -811,7 +802,7 @@ func (s *groupServer) JoinGroup(ctx context.Context, req *pbGroup.JoinGroupReq)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
chat.JoinGroupApplicationNotification(req)
|
||||
chat.JoinGroupApplicationNotification(ctx, req)
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
@ -823,50 +814,35 @@ func (s *groupServer) QuitGroup(ctx context.Context, req *pbGroup.QuitGroupReq)
|
||||
return nil, err
|
||||
}
|
||||
if groupInfo.GroupType != constant.SuperGroup {
|
||||
_, err = rocksCache.GetGroupMemberInfoFromCache(ctx, req.GroupID, req.OpUserID)
|
||||
_, err = rocksCache.GetGroupMemberInfoFromCache(ctx, req.GroupID, tools.OpUserID(ctx))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := s.DelGroupAndUserCache(ctx, req.GroupID, []string{req.OpUserID}); err != nil {
|
||||
if err := s.DelGroupAndUserCache(ctx, req.GroupID, []string{tools.OpUserID(ctx)}); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = imdb.DeleteGroupMemberByGroupIDAndUserID(req.GroupID, req.OpUserID)
|
||||
err = imdb.DeleteGroupMemberByGroupIDAndUserID(req.GroupID, tools.OpUserID(ctx))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
okUserIDList := []string{req.OpUserID}
|
||||
okUserIDList := []string{tools.OpUserID(ctx)}
|
||||
if err := db.DB.RemoverUserFromSuperGroup(req.GroupID, okUserIDList); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
if groupInfo.GroupType != constant.SuperGroup {
|
||||
_ = rocksCache.DelGroupMemberInfoFromCache(ctx, req.GroupID, req.OpUserID)
|
||||
_ = rocksCache.DelGroupMemberInfoFromCache(ctx, req.GroupID, tools.OpUserID(ctx))
|
||||
chat.MemberQuitNotification(req)
|
||||
} else {
|
||||
_ = rocksCache.DelJoinedSuperGroupIDListFromCache(ctx, req.OpUserID)
|
||||
_ = rocksCache.DelJoinedSuperGroupIDListFromCache(ctx, tools.OpUserID(ctx))
|
||||
_ = rocksCache.DelGroupMemberListHashFromCache(ctx, req.GroupID)
|
||||
chat.SuperGroupNotification(req.OperationID, req.OpUserID, req.OpUserID)
|
||||
chat.SuperGroupNotification(tools.OperationID(ctx), tools.OpUserID(ctx), tools.OpUserID(ctx))
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func hasAccess(req *pbGroup.SetGroupInfoReq) bool {
|
||||
if utils.IsContain(req.OpUserID, config.Config.Manager.AppManagerUid) {
|
||||
return true
|
||||
}
|
||||
groupUserInfo, err := imdb.GetGroupMemberInfoByGroupIDAndUserID(req.GroupInfoForSet.GroupID, req.OpUserID)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "GetGroupMemberInfoByGroupIDAndUserID failed, ", err.Error(), req.GroupInfoForSet.GroupID, req.OpUserID)
|
||||
return false
|
||||
}
|
||||
if groupUserInfo.RoleLevel == constant.GroupOwner || groupUserInfo.RoleLevel == constant.GroupAdmin {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (s *groupServer) SetGroupInfo(ctx context.Context, req *pbGroup.SetGroupInfoReq) (*pbGroup.SetGroupInfoResp, error) {
|
||||
resp := &pbGroup.SetGroupInfoResp{}
|
||||
|
||||
@ -931,7 +907,7 @@ func (s *groupServer) SetGroupInfo(ctx context.Context, req *pbGroup.SetGroupInf
|
||||
var groupInfo imdb.Group
|
||||
utils.CopyStructFields(&groupInfo, req.GroupInfoForSet)
|
||||
if req.GroupInfoForSet.Notification != "" {
|
||||
groupInfo.NotificationUserID = req.OpUserID
|
||||
groupInfo.NotificationUserID = tools.OpUserID(ctx)
|
||||
groupInfo.NotificationUpdateTime = time.Now()
|
||||
}
|
||||
if err := rocksCache.DelGroupInfoFromCache(ctx, req.GroupInfoForSet.GroupID); err != nil {
|
||||
@ -942,11 +918,11 @@ func (s *groupServer) SetGroupInfo(ctx context.Context, req *pbGroup.SetGroupInf
|
||||
return nil, err
|
||||
}
|
||||
if changedType != 0 {
|
||||
chat.GroupInfoSetNotification(req.OperationID, req.OpUserID, req.GroupInfoForSet.GroupID, groupName, notification, introduction, faceURL, req.GroupInfoForSet.NeedVerification)
|
||||
chat.GroupInfoSetNotification(tools.OperationID(ctx), tools.OpUserID(ctx), req.GroupInfoForSet.GroupID, groupName, notification, introduction, faceURL, req.GroupInfoForSet.NeedVerification)
|
||||
}
|
||||
if req.GroupInfoForSet.Notification != "" {
|
||||
//get group member user id
|
||||
getGroupMemberIDListFromCacheReq := &pbCache.GetGroupMemberIDListFromCacheReq{OperationID: req.OperationID, GroupID: req.GroupInfoForSet.GroupID}
|
||||
getGroupMemberIDListFromCacheReq := &pbCache.GetGroupMemberIDListFromCacheReq{OperationID: tools.OperationID(ctx), GroupID: req.GroupInfoForSet.GroupID}
|
||||
etcdConn, err := getcdv3.GetConn(ctx, config.Config.RpcRegisterName.OpenImCacheName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -961,13 +937,13 @@ func (s *groupServer) SetGroupInfo(ctx context.Context, req *pbGroup.SetGroupInf
|
||||
}
|
||||
var conversationReq pbConversation.ModifyConversationFieldReq
|
||||
conversation := pbConversation.Conversation{
|
||||
OwnerUserID: req.OpUserID,
|
||||
OwnerUserID: tools.OpUserID(ctx),
|
||||
ConversationID: utils.GetConversationIDBySessionType(req.GroupInfoForSet.GroupID, constant.GroupChatType),
|
||||
ConversationType: constant.GroupChatType,
|
||||
GroupID: req.GroupInfoForSet.GroupID,
|
||||
}
|
||||
conversationReq.Conversation = &conversation
|
||||
conversationReq.OperationID = req.OperationID
|
||||
conversationReq.OperationID = tools.OperationID(ctx)
|
||||
conversationReq.FieldType = constant.FieldGroupAtType
|
||||
conversation.GroupAtType = constant.GroupNotification
|
||||
conversationReq.UserIDList = cacheResp.UserIDList
|
||||
@ -1080,7 +1056,7 @@ func (s *groupServer) GetGroupMembersCMS(ctx context.Context, req *pbGroup.GetGr
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
log.NewInfo(req.OperationID, groupMembersCount)
|
||||
log.NewInfo(tools.OperationID(ctx), groupMembersCount)
|
||||
resp.MemberNums = int32(groupMembersCount)
|
||||
for _, groupMember := range groupMembers {
|
||||
member := open_im_sdk.GroupMemberFullInfo{}
|
||||
@ -1125,7 +1101,7 @@ func (s *groupServer) GetUserReqApplicationList(ctx context.Context, req *pbGrou
|
||||
func (s *groupServer) DismissGroup(ctx context.Context, req *pbGroup.DismissGroupReq) (*pbGroup.DismissGroupResp, error) {
|
||||
resp := &pbGroup.DismissGroupResp{}
|
||||
|
||||
if !token_verify.IsManagerUserID(req.OpUserID) && !imdb.IsGroupOwnerAdmin(req.GroupID, req.OpUserID) {
|
||||
if !token_verify.IsManagerUserID(tools.OpUserID(ctx)) && !imdb.IsGroupOwnerAdmin(req.GroupID, tools.OpUserID(ctx)) {
|
||||
return nil, utils.Wrap(constant.ErrIdentity, "")
|
||||
}
|
||||
|
||||
@ -1153,7 +1129,7 @@ func (s *groupServer) DismissGroup(ctx context.Context, req *pbGroup.DismissGrou
|
||||
var reqPb pbUser.SetConversationReq
|
||||
var c pbConversation.Conversation
|
||||
for _, v := range memberList {
|
||||
reqPb.OperationID = req.OperationID
|
||||
reqPb.OperationID = tools.OperationID(ctx)
|
||||
c.OwnerUserID = v.UserID
|
||||
c.ConversationID = utils.GetConversationIDBySessionType(req.GroupID, constant.GroupChatType)
|
||||
c.ConversationType = constant.GroupChatType
|
||||
@ -1182,7 +1158,7 @@ func (s *groupServer) DismissGroup(ctx context.Context, req *pbGroup.DismissGrou
|
||||
func (s *groupServer) MuteGroupMember(ctx context.Context, req *pbGroup.MuteGroupMemberReq) (*pbGroup.MuteGroupMemberResp, error) {
|
||||
resp := &pbGroup.MuteGroupMemberResp{}
|
||||
|
||||
opFlag, err := s.getGroupUserLevel(req.GroupID, req.OpUserID)
|
||||
opFlag, err := s.getGroupUserLevel(req.GroupID, tools.OpUserID(ctx))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -1210,14 +1186,14 @@ func (s *groupServer) MuteGroupMember(ctx context.Context, req *pbGroup.MuteGrou
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
chat.GroupMemberMutedNotification(req.OperationID, req.OpUserID, req.GroupID, req.UserID, req.MutedSeconds)
|
||||
chat.GroupMemberMutedNotification(tools.OperationID(ctx), tools.OpUserID(ctx), req.GroupID, req.UserID, req.MutedSeconds)
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (s *groupServer) CancelMuteGroupMember(ctx context.Context, req *pbGroup.CancelMuteGroupMemberReq) (*pbGroup.CancelMuteGroupMemberResp, error) {
|
||||
resp := &pbGroup.CancelMuteGroupMemberResp{}
|
||||
|
||||
opFlag, err := s.getGroupUserLevel(req.GroupID, req.OpUserID)
|
||||
opFlag, err := s.getGroupUserLevel(req.GroupID, tools.OpUserID(ctx))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -1245,14 +1221,14 @@ func (s *groupServer) CancelMuteGroupMember(ctx context.Context, req *pbGroup.Ca
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
chat.GroupMemberCancelMutedNotification(req.OperationID, req.OpUserID, req.GroupID, req.UserID)
|
||||
chat.GroupMemberCancelMutedNotification(tools.OperationID(ctx), tools.OpUserID(ctx), req.GroupID, req.UserID)
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (s *groupServer) MuteGroup(ctx context.Context, req *pbGroup.MuteGroupReq) (*pbGroup.MuteGroupResp, error) {
|
||||
resp := &pbGroup.MuteGroupResp{}
|
||||
|
||||
opFlag, err := s.getGroupUserLevel(req.GroupID, req.OpUserID)
|
||||
opFlag, err := s.getGroupUserLevel(req.GroupID, tools.OpUserID(ctx))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -1285,14 +1261,14 @@ func (s *groupServer) MuteGroup(ctx context.Context, req *pbGroup.MuteGroupReq)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
chat.GroupMutedNotification(req.OperationID, req.OpUserID, req.GroupID)
|
||||
chat.GroupMutedNotification(tools.OperationID(ctx), tools.OpUserID(ctx), req.GroupID)
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (s *groupServer) CancelMuteGroup(ctx context.Context, req *pbGroup.CancelMuteGroupReq) (*pbGroup.CancelMuteGroupResp, error) {
|
||||
resp := &pbGroup.CancelMuteGroupResp{}
|
||||
|
||||
opFlag, err := s.getGroupUserLevel(req.GroupID, req.OpUserID)
|
||||
opFlag, err := s.getGroupUserLevel(req.GroupID, tools.OpUserID(ctx))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -1312,7 +1288,7 @@ func (s *groupServer) CancelMuteGroup(ctx context.Context, req *pbGroup.CancelMu
|
||||
// errMsg := req.OperationID + " mutedInfo.RoleLevel == constant.GroupAdmin " + req.GroupID + req.OpUserID + err.Error()
|
||||
// return &pbGroup.CancelMuteGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: errMsg}}, nil
|
||||
//}
|
||||
log.Debug(req.OperationID, "UpdateGroupInfoDefaultZero ", req.GroupID, map[string]interface{}{"status": constant.GroupOk})
|
||||
log.Debug(tools.OperationID(ctx), "UpdateGroupInfoDefaultZero ", req.GroupID, map[string]interface{}{"status": constant.GroupOk})
|
||||
if err := rocksCache.DelGroupInfoFromCache(ctx, req.GroupID); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -1320,22 +1296,20 @@ func (s *groupServer) CancelMuteGroup(ctx context.Context, req *pbGroup.CancelMu
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
chat.GroupCancelMutedNotification(req.OperationID, req.OpUserID, req.GroupID)
|
||||
chat.GroupCancelMutedNotification(tools.OperationID(ctx), tools.OpUserID(ctx), req.GroupID)
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (s *groupServer) SetGroupMemberNickname(ctx context.Context, req *pbGroup.SetGroupMemberNicknameReq) (*pbGroup.SetGroupMemberNicknameResp, error) {
|
||||
resp := &pbGroup.SetGroupMemberNicknameResp{}
|
||||
|
||||
if req.OpUserID != req.UserID && !token_verify.IsManagerUserID(req.OpUserID) {
|
||||
if tools.OpUserID(ctx) != req.UserID && !token_verify.IsManagerUserID(tools.OpUserID(ctx)) {
|
||||
return nil, utils.Wrap(constant.ErrIdentity, "")
|
||||
}
|
||||
cbReq := &pbGroup.SetGroupMemberInfoReq{
|
||||
GroupID: req.GroupID,
|
||||
UserID: req.UserID,
|
||||
OperationID: req.OperationID,
|
||||
OpUserID: req.OpUserID,
|
||||
Nickname: &wrapperspb.StringValue{Value: req.Nickname},
|
||||
GroupID: req.GroupID,
|
||||
UserID: req.UserID,
|
||||
Nickname: &wrapperspb.StringValue{Value: req.Nickname},
|
||||
}
|
||||
if err := CallbackBeforeSetGroupMemberInfo(ctx, cbReq); err != nil {
|
||||
return nil, err
|
||||
@ -1361,7 +1335,7 @@ func (s *groupServer) SetGroupMemberNickname(ctx context.Context, req *pbGroup.S
|
||||
if err := imdb.UpdateGroupMemberInfo(groupMemberInfo); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
chat.GroupMemberInfoSetNotification(req.OperationID, req.OpUserID, req.GroupID, req.UserID)
|
||||
chat.GroupMemberInfoSetNotification(tools.OperationID(ctx), tools.OpUserID(ctx), req.GroupID, req.UserID)
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
@ -1400,13 +1374,13 @@ func (s *groupServer) SetGroupMemberInfo(ctx context.Context, req *pbGroup.SetGr
|
||||
switch req.RoleLevel.Value {
|
||||
case constant.GroupOrdinaryUsers:
|
||||
//msg.GroupMemberRoleLevelChangeNotification(req.OperationID, req.OpUserID, req.GroupID, req.UserID, constant.GroupMemberSetToOrdinaryUserNotification)
|
||||
chat.GroupMemberInfoSetNotification(req.OperationID, req.OpUserID, req.GroupID, req.UserID)
|
||||
chat.GroupMemberInfoSetNotification(tools.OperationID(ctx), tools.OpUserID(ctx), req.GroupID, req.UserID)
|
||||
case constant.GroupAdmin, constant.GroupOwner:
|
||||
//msg.GroupMemberRoleLevelChangeNotification(req.OperationID, req.OpUserID, req.GroupID, req.UserID, constant.GroupMemberSetToAdminNotification)
|
||||
chat.GroupMemberInfoSetNotification(req.OperationID, req.OpUserID, req.GroupID, req.UserID)
|
||||
chat.GroupMemberInfoSetNotification(tools.OperationID(ctx), tools.OpUserID(ctx), req.GroupID, req.UserID)
|
||||
}
|
||||
} else {
|
||||
chat.GroupMemberInfoSetNotification(req.OperationID, req.OpUserID, req.GroupID, req.UserID)
|
||||
chat.GroupMemberInfoSetNotification(tools.OperationID(ctx), tools.OpUserID(ctx), req.GroupID, req.UserID)
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
@ -6,10 +6,12 @@ import (
|
||||
imdb "Open_IM/pkg/common/db/mysql_model/im_mysql_model"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/common/token_verify"
|
||||
"Open_IM/pkg/common/tools"
|
||||
utils2 "Open_IM/pkg/common/utils"
|
||||
pbGroup "Open_IM/pkg/proto/group"
|
||||
open_im_sdk "Open_IM/pkg/proto/sdk_ws"
|
||||
"Open_IM/pkg/utils"
|
||||
"context"
|
||||
"github.com/golang/protobuf/jsonpb"
|
||||
"github.com/golang/protobuf/proto"
|
||||
"google.golang.org/protobuf/types/known/wrapperspb"
|
||||
@ -208,7 +210,7 @@ func groupNotification(contentType int32, m proto.Message, sendID, groupID, recv
|
||||
Notification(&n)
|
||||
}
|
||||
|
||||
//创建群后调用
|
||||
// 创建群后调用
|
||||
func GroupCreatedNotification(operationID, opUserID, groupID string, initMemberList []string) {
|
||||
GroupCreatedTips := open_im_sdk.GroupCreatedTips{Group: &open_im_sdk.GroupInfo{},
|
||||
OpUser: &open_im_sdk.GroupMemberFullInfo{}, GroupOwnerUser: &open_im_sdk.GroupMemberFullInfo{}}
|
||||
@ -240,8 +242,9 @@ func GroupCreatedNotification(operationID, opUserID, groupID string, initMemberL
|
||||
groupNotification(constant.GroupCreatedNotification, &GroupCreatedTips, opUserID, groupID, "", operationID)
|
||||
}
|
||||
|
||||
//群信息改变后掉用
|
||||
//groupName := ""
|
||||
// 群信息改变后掉用
|
||||
// groupName := ""
|
||||
//
|
||||
// notification := ""
|
||||
// introduction := ""
|
||||
// faceURL := ""
|
||||
@ -371,36 +374,38 @@ func GroupMemberCancelMutedNotification(operationID, opUserID, groupID, groupMem
|
||||
groupNotification(constant.GroupMemberCancelMutedNotification, &tips, opUserID, groupID, "", operationID)
|
||||
}
|
||||
|
||||
//message ReceiveJoinApplicationTips{
|
||||
// GroupInfo Group = 1;
|
||||
// PublicUserInfo Applicant = 2;
|
||||
// string Reason = 3;
|
||||
//} apply->all managers GroupID string `protobuf:"bytes,1,opt,name=GroupID" json:"GroupID,omitempty"`
|
||||
// message ReceiveJoinApplicationTips{
|
||||
// GroupInfo Group = 1;
|
||||
// PublicUserInfo Applicant = 2;
|
||||
// string Reason = 3;
|
||||
// } apply->all managers GroupID string `protobuf:"bytes,1,opt,name=GroupID" json:"GroupID,omitempty"`
|
||||
//
|
||||
// ReqMessage string `protobuf:"bytes,2,opt,name=ReqMessage" json:"ReqMessage,omitempty"`
|
||||
// OpUserID string `protobuf:"bytes,3,opt,name=OpUserID" json:"OpUserID,omitempty"`
|
||||
// OperationID string `protobuf:"bytes,4,opt,name=OperationID" json:"OperationID,omitempty"`
|
||||
//申请进群后调用
|
||||
func JoinGroupApplicationNotification(req *pbGroup.JoinGroupReq) {
|
||||
//
|
||||
// 申请进群后调用
|
||||
func JoinGroupApplicationNotification(ctx context.Context, req *pbGroup.JoinGroupReq) {
|
||||
JoinGroupApplicationTips := open_im_sdk.JoinGroupApplicationTips{Group: &open_im_sdk.GroupInfo{}, Applicant: &open_im_sdk.PublicUserInfo{}}
|
||||
err := setGroupInfo(req.GroupID, JoinGroupApplicationTips.Group)
|
||||
if err != nil {
|
||||
log.Error(req.OperationID, "setGroupInfo failed ", err.Error(), req.GroupID)
|
||||
log.Error(tools.OperationID(ctx), "setGroupInfo failed ", err.Error(), req.GroupID)
|
||||
return
|
||||
}
|
||||
if err = setPublicUserInfo(req.OpUserID, JoinGroupApplicationTips.Applicant); err != nil {
|
||||
log.Error(req.OperationID, "setPublicUserInfo failed ", err.Error(), req.OpUserID)
|
||||
if err = setPublicUserInfo(tools.OpUserID(ctx), JoinGroupApplicationTips.Applicant); err != nil {
|
||||
log.Error(tools.OperationID(ctx), "setPublicUserInfo failed ", err.Error(), tools.OpUserID(ctx))
|
||||
return
|
||||
}
|
||||
JoinGroupApplicationTips.ReqMsg = req.ReqMessage
|
||||
|
||||
managerList, err := imdb.GetOwnerManagerByGroupID(req.GroupID)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "GetOwnerManagerByGroupId failed ", err.Error(), req.GroupID)
|
||||
log.NewError(tools.OperationID(ctx), "GetOwnerManagerByGroupId failed ", err.Error(), req.GroupID)
|
||||
return
|
||||
}
|
||||
for _, v := range managerList {
|
||||
groupNotification(constant.JoinGroupApplicationNotification, &JoinGroupApplicationTips, req.OpUserID, "", v.UserID, req.OperationID)
|
||||
log.NewInfo(req.OperationID, "Notification ", v)
|
||||
groupNotification(constant.JoinGroupApplicationNotification, &JoinGroupApplicationTips, tools.OpUserID(ctx), "", v.UserID, tools.OperationID(ctx))
|
||||
log.NewInfo(tools.OperationID(ctx), "Notification ", v)
|
||||
}
|
||||
}
|
||||
|
||||
@ -418,13 +423,14 @@ func MemberQuitNotification(req *pbGroup.QuitGroupReq) {
|
||||
groupNotification(constant.MemberQuitNotification, &MemberQuitTips, req.OpUserID, req.GroupID, "", req.OperationID)
|
||||
}
|
||||
|
||||
//message ApplicationProcessedTips{
|
||||
// GroupInfo Group = 1;
|
||||
// GroupMemberFullInfo OpUser = 2;
|
||||
// int32 Result = 3;
|
||||
// string Reason = 4;
|
||||
//}
|
||||
//处理进群请求后调用
|
||||
// message ApplicationProcessedTips{
|
||||
// GroupInfo Group = 1;
|
||||
// GroupMemberFullInfo OpUser = 2;
|
||||
// int32 Result = 3;
|
||||
// string Reason = 4;
|
||||
// }
|
||||
//
|
||||
// 处理进群请求后调用
|
||||
func GroupApplicationAcceptedNotification(req *pbGroup.GroupApplicationResponseReq) {
|
||||
GroupApplicationAcceptedTips := open_im_sdk.GroupApplicationAcceptedTips{Group: &open_im_sdk.GroupInfo{}, OpUser: &open_im_sdk.GroupMemberFullInfo{}, HandleMsg: req.HandledMsg}
|
||||
if err := setGroupInfo(req.GroupID, GroupApplicationAcceptedTips.Group); err != nil {
|
||||
@ -506,13 +512,14 @@ func GroupDismissedNotification(req *pbGroup.DismissGroupReq) {
|
||||
groupNotification(constant.GroupDismissedNotification, &tips, req.OpUserID, req.GroupID, "", req.OperationID)
|
||||
}
|
||||
|
||||
//message MemberKickedTips{
|
||||
// GroupInfo Group = 1;
|
||||
// GroupMemberFullInfo OpUser = 2;
|
||||
// GroupMemberFullInfo KickedUser = 3;
|
||||
// uint64 OperationTime = 4;
|
||||
//}
|
||||
//被踢后调用
|
||||
// message MemberKickedTips{
|
||||
// GroupInfo Group = 1;
|
||||
// GroupMemberFullInfo OpUser = 2;
|
||||
// GroupMemberFullInfo KickedUser = 3;
|
||||
// uint64 OperationTime = 4;
|
||||
// }
|
||||
//
|
||||
// 被踢后调用
|
||||
func MemberKickedNotification(req *pbGroup.KickGroupMemberReq, kickedUserIDList []string) {
|
||||
MemberKickedTips := open_im_sdk.MemberKickedTips{Group: &open_im_sdk.GroupInfo{}, OpUser: &open_im_sdk.GroupMemberFullInfo{}}
|
||||
if err := setGroupInfo(req.GroupID, MemberKickedTips.Group); err != nil {
|
||||
@ -538,13 +545,14 @@ func MemberKickedNotification(req *pbGroup.KickGroupMemberReq, kickedUserIDList
|
||||
//}
|
||||
}
|
||||
|
||||
//message MemberInvitedTips{
|
||||
// GroupInfo Group = 1;
|
||||
// GroupMemberFullInfo OpUser = 2;
|
||||
// GroupMemberFullInfo InvitedUser = 3;
|
||||
// uint64 OperationTime = 4;
|
||||
//}
|
||||
//被邀请进群后调用
|
||||
// message MemberInvitedTips{
|
||||
// GroupInfo Group = 1;
|
||||
// GroupMemberFullInfo OpUser = 2;
|
||||
// GroupMemberFullInfo InvitedUser = 3;
|
||||
// uint64 OperationTime = 4;
|
||||
// }
|
||||
//
|
||||
// 被邀请进群后调用
|
||||
func MemberInvitedNotification(operationID, groupID, opUserID, reason string, invitedUserIDList []string) {
|
||||
MemberInvitedTips := open_im_sdk.MemberInvitedTips{Group: &open_im_sdk.GroupInfo{}, OpUser: &open_im_sdk.GroupMemberFullInfo{}}
|
||||
if err := setGroupInfo(groupID, MemberInvitedTips.Group); err != nil {
|
||||
@ -580,12 +588,13 @@ func MemberInvitedNotification(operationID, groupID, opUserID, reason string, in
|
||||
|
||||
//群成员退群后调用
|
||||
|
||||
//message MemberEnterTips{
|
||||
// GroupInfo Group = 1;
|
||||
// GroupMemberFullInfo EntrantUser = 2;
|
||||
// uint64 OperationTime = 3;
|
||||
//}
|
||||
//群成员主动申请进群,管理员同意后调用,
|
||||
// message MemberEnterTips{
|
||||
// GroupInfo Group = 1;
|
||||
// GroupMemberFullInfo EntrantUser = 2;
|
||||
// uint64 OperationTime = 3;
|
||||
// }
|
||||
//
|
||||
// 群成员主动申请进群,管理员同意后调用,
|
||||
func MemberEnterNotification(req *pbGroup.GroupApplicationResponseReq) {
|
||||
MemberEnterTips := open_im_sdk.MemberEnterTips{Group: &open_im_sdk.GroupInfo{}, EntrantUser: &open_im_sdk.GroupMemberFullInfo{}}
|
||||
if err := setGroupInfo(req.GroupID, MemberEnterTips.Group); err != nil {
|
||||
|
@ -16,6 +16,14 @@ type ErrInfo struct {
|
||||
DetailErrMsg string
|
||||
}
|
||||
|
||||
func NewErrInfo(code int32, msg, detail string) *ErrInfo {
|
||||
return &ErrInfo{
|
||||
ErrCode: code,
|
||||
ErrMsg: msg,
|
||||
DetailErrMsg: detail,
|
||||
}
|
||||
}
|
||||
|
||||
func (e *ErrInfo) Error() string {
|
||||
return "errMsg: " + e.ErrMsg + " detail errMsg: " + e.DetailErrMsg
|
||||
}
|
||||
|
@ -8,8 +8,6 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
var FriendDB *gorm.DB
|
||||
|
||||
type Friend struct {
|
||||
OwnerUserID string `gorm:"column:owner_user_id;primary_key;size:64"`
|
||||
FriendUserID string `gorm:"column:friend_user_id;primary_key;size:64"`
|
||||
@ -18,49 +16,54 @@ type Friend struct {
|
||||
AddSource int32 `gorm:"column:add_source"`
|
||||
OperatorUserID string `gorm:"column:operator_user_id;size:64"`
|
||||
Ex string `gorm:"column:ex;size:1024"`
|
||||
db *gorm.DB `gorm:"-"`
|
||||
}
|
||||
|
||||
func (*Friend) Create(ctx context.Context, friends []*Friend) (err error) {
|
||||
func NewFriend(db *gorm.DB) *Friend {
|
||||
return &Friend{db: db}
|
||||
}
|
||||
|
||||
func (f *Friend) Create(ctx context.Context, friends []*Friend) (err error) {
|
||||
defer func() {
|
||||
trace_log.SetCtxDebug(ctx, utils.GetSelfFuncName(), err, "friends", friends)
|
||||
}()
|
||||
err = utils.Wrap(FriendDB.Create(&friends).Error, "")
|
||||
err = utils.Wrap(f.db.Create(&friends).Error, "")
|
||||
return err
|
||||
}
|
||||
|
||||
func (*Friend) Delete(ctx context.Context, ownerUserID string, friendUserIDs []string) (err error) {
|
||||
func (f *Friend) Delete(ctx context.Context, ownerUserID string, friendUserIDs []string) (err error) {
|
||||
defer func() {
|
||||
trace_log.SetCtxDebug(ctx, utils.GetSelfFuncName(), err, "ownerUserID", ownerUserID, "friendUserIDs", friendUserIDs)
|
||||
}()
|
||||
err = utils.Wrap(FriendDB.Where("owner_user_id = ? and friend_user_id in (?)", ownerUserID, friendUserIDs).Delete(&Friend{}).Error, "")
|
||||
err = utils.Wrap(f.db.Where("owner_user_id = ? and friend_user_id in (?)", ownerUserID, friendUserIDs).Delete(&Friend{}).Error, "")
|
||||
return err
|
||||
}
|
||||
|
||||
func (*Friend) UpdateByMap(ctx context.Context, ownerUserID string, args map[string]interface{}) (err error) {
|
||||
func (f *Friend) UpdateByMap(ctx context.Context, ownerUserID string, args map[string]interface{}) (err error) {
|
||||
defer func() {
|
||||
trace_log.SetCtxDebug(ctx, utils.GetSelfFuncName(), err, "ownerUserID", ownerUserID, "args", args)
|
||||
}()
|
||||
return utils.Wrap(FriendDB.Where("owner_user_id = ?", ownerUserID).Updates(args).Error, "")
|
||||
return utils.Wrap(f.db.Where("owner_user_id = ?", ownerUserID).Updates(args).Error, "")
|
||||
}
|
||||
|
||||
func (*Friend) Update(ctx context.Context, friends []*Friend) (err error) {
|
||||
func (f *Friend) Update(ctx context.Context, friends []*Friend) (err error) {
|
||||
defer func() {
|
||||
trace_log.SetCtxDebug(ctx, utils.GetSelfFuncName(), err, "friends", friends)
|
||||
}()
|
||||
return utils.Wrap(FriendDB.Updates(&friends).Error, "")
|
||||
return utils.Wrap(f.db.Updates(&friends).Error, "")
|
||||
}
|
||||
|
||||
func (*Friend) Find(ctx context.Context, ownerUserID string) (friends []*Friend, err error) {
|
||||
func (f *Friend) Find(ctx context.Context, ownerUserID string) (friends []*Friend, err error) {
|
||||
defer func() {
|
||||
trace_log.SetCtxDebug(ctx, utils.GetSelfFuncName(), err, "ownerUserID", ownerUserID, "friends", friends)
|
||||
}()
|
||||
err = utils.Wrap(FriendDB.Where("owner_user_id = ?", ownerUserID).Find(&friends).Error, "")
|
||||
err = utils.Wrap(f.db.Where("owner_user_id = ?", ownerUserID).Find(&friends).Error, "")
|
||||
return friends, err
|
||||
}
|
||||
|
||||
func (*Friend) Take(ctx context.Context, ownerUserID, friendUserID string) (group *Group, err error) {
|
||||
group = &Group{}
|
||||
defer trace_log.SetCtxDebug(ctx, utils.GetSelfFuncName(), err, "ownerUserID", ownerUserID, "friendUserID", friendUserID, "group", *group)
|
||||
err = utils.Wrap(FriendDB.Where("owner_user_id = ? and friend_user_id", ownerUserID, friendUserID).Take(group).Error, "")
|
||||
return group, err
|
||||
func (f *Friend) Take(ctx context.Context, ownerUserID, friendUserID string) (friend *Friend, err error) {
|
||||
friend = &Friend{}
|
||||
defer trace_log.SetCtxDebug(ctx, utils.GetSelfFuncName(), err, "ownerUserID", ownerUserID, "friendUserID", friendUserID, "group", *friend)
|
||||
err = utils.Wrap(f.db.Where("owner_user_id = ? and friend_user_id", ownerUserID, friendUserID).Take(friend).Error, "")
|
||||
return friend, err
|
||||
}
|
||||
|
@ -1,7 +1,9 @@
|
||||
package im_mysql_model
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/trace_log"
|
||||
"Open_IM/pkg/utils"
|
||||
"context"
|
||||
"gorm.io/gorm"
|
||||
"time"
|
||||
)
|
||||
@ -18,10 +20,56 @@ type FriendRequest struct {
|
||||
HandleMsg string `gorm:"column:handle_msg;size:255"`
|
||||
HandleTime time.Time `gorm:"column:handle_time"`
|
||||
Ex string `gorm:"column:ex;size:1024"`
|
||||
db *gorm.DB `gorm:"-"`
|
||||
}
|
||||
|
||||
func (FriendRequest) TableName() string {
|
||||
return "friend_requests"
|
||||
func NewFriendRequest(db *gorm.DB) *FriendRequest {
|
||||
return &FriendRequest{db: db}
|
||||
}
|
||||
|
||||
func (f *FriendRequest) Create(ctx context.Context, friends []*FriendRequest) (err error) {
|
||||
defer func() {
|
||||
trace_log.SetCtxDebug(ctx, utils.GetSelfFuncName(), err, "friends", friends)
|
||||
}()
|
||||
err = utils.Wrap(f.db.Create(&friends).Error, "")
|
||||
return err
|
||||
}
|
||||
|
||||
func (f *FriendRequest) Delete(ctx context.Context, fromUserID, toUserID string) (err error) {
|
||||
defer func() {
|
||||
trace_log.SetCtxDebug(ctx, utils.GetSelfFuncName(), err, "fromUserID", fromUserID, "toUserID", toUserID)
|
||||
}()
|
||||
err = utils.Wrap(f.db.Where("from_user_id = ? and to_user_id = ?", fromUserID, toUserID).Delete(&FriendRequest{}).Error, "")
|
||||
return err
|
||||
}
|
||||
|
||||
func (f *FriendRequest) UpdateByMap(ctx context.Context, ownerUserID string, args map[string]interface{}) (err error) {
|
||||
defer func() {
|
||||
trace_log.SetCtxDebug(ctx, utils.GetSelfFuncName(), err, "ownerUserID", ownerUserID, "args", args)
|
||||
}()
|
||||
return utils.Wrap(f.db.Where("owner_user_id = ?", ownerUserID).Updates(args).Error, "")
|
||||
}
|
||||
|
||||
func (f *FriendRequest) Update(ctx context.Context, friends []*FriendRequest) (err error) {
|
||||
defer func() {
|
||||
trace_log.SetCtxDebug(ctx, utils.GetSelfFuncName(), err, "friends", friends)
|
||||
}()
|
||||
return utils.Wrap(f.db.Updates(&friends).Error, "")
|
||||
}
|
||||
|
||||
func (f *FriendRequest) Find(ctx context.Context, ownerUserID string) (friends []*FriendRequest, err error) {
|
||||
defer func() {
|
||||
trace_log.SetCtxDebug(ctx, utils.GetSelfFuncName(), err, "ownerUserID", ownerUserID, "friends", friends)
|
||||
}()
|
||||
err = utils.Wrap(f.db.Where("owner_user_id = ?", ownerUserID).Find(&friends).Error, "")
|
||||
return friends, err
|
||||
}
|
||||
|
||||
func (f *FriendRequest) Take(ctx context.Context, ownerUserID, friendUserID string) (friend *FriendRequest, err error) {
|
||||
friend = &FriendRequest{}
|
||||
defer trace_log.SetCtxDebug(ctx, utils.GetSelfFuncName(), err, "ownerUserID", ownerUserID, "friendUserID", friendUserID, "group", *friend)
|
||||
err = utils.Wrap(f.db.Where("owner_user_id = ? and friend_user_id", ownerUserID, friendUserID).Take(friend).Error, "")
|
||||
return friend, err
|
||||
}
|
||||
|
||||
// who apply to add me
|
||||
|
@ -57,12 +57,12 @@ func (*Group) Update(ctx context.Context, groups []*Group) (err error) {
|
||||
return utils.Wrap(GroupDB.Updates(&groups).Error, "")
|
||||
}
|
||||
|
||||
func (*Group) Find(ctx context.Context, groupIDs []string) (groupList []*Group, err error) {
|
||||
func (*Group) Find(ctx context.Context, groupIDs []string) (groups []*Group, err error) {
|
||||
defer func() {
|
||||
trace_log.SetCtxDebug(ctx, utils.GetFuncName(1), err, "groupIDList", groupIDs, "groupList", groupList)
|
||||
trace_log.SetCtxDebug(ctx, utils.GetFuncName(1), err, "groupIDs", groupIDs, "groups", groups)
|
||||
}()
|
||||
err = utils.Wrap(GroupDB.Where("group_id in (?)", groupIDs).Find(&groupList).Error, "")
|
||||
return groupList, err
|
||||
err = utils.Wrap(GroupDB.Where("group_id in (?)", groupIDs).Find(&groups).Error, "")
|
||||
return groups, err
|
||||
}
|
||||
|
||||
func (*Group) Take(ctx context.Context, groupID string) (group *Group, err error) {
|
||||
|
@ -1,24 +1,13 @@
|
||||
package im_mysql_model
|
||||
|
||||
//type GroupRequest struct {
|
||||
// UserID string `gorm:"column:user_id;primaryKey;"`
|
||||
// GroupID string `gorm:"column:group_id;primaryKey;"`
|
||||
// HandleResult int32 `gorm:"column:handle_result"`
|
||||
// ReqMsg string `gorm:"column:req_msg"`
|
||||
// HandledMsg string `gorm:"column:handled_msg"`
|
||||
// ReqTime time.Time `gorm:"column:req_time"`
|
||||
// HandleUserID string `gorm:"column:handle_user_id"`
|
||||
// HandledTime time.Time `gorm:"column:handle_time"`
|
||||
// Ex string `gorm:"column:ex"`
|
||||
//}
|
||||
|
||||
//
|
||||
//func UpdateGroupRequest(groupRequest GroupRequest) error {
|
||||
// if groupRequest.HandledTime.Unix() < 0 {
|
||||
// groupRequest.HandledTime = utils.UnixSecondToTime(0)
|
||||
// }
|
||||
// return db.DB.MysqlDB.DefaultGormDB().Table("group_requests").Where("group_id=? and user_id=?", groupRequest.GroupID, groupRequest.UserID).Updates(&groupRequest).Error
|
||||
//}
|
||||
|
||||
//
|
||||
//func InsertIntoGroupRequest(toInsertInfo GroupRequest) error {
|
||||
// DelGroupRequestByGroupIDAndUserID(toInsertInfo.GroupID, toInsertInfo.UserID)
|
||||
// if toInsertInfo.HandledTime.Unix() < 0 {
|
||||
@ -40,7 +29,7 @@ package im_mysql_model
|
||||
// }
|
||||
// return nil
|
||||
//}
|
||||
|
||||
//
|
||||
//func GetGroupRequestByGroupIDAndUserID(groupID, userID string) (*GroupRequest, error) {
|
||||
// var groupRequest GroupRequest
|
||||
// err := db.DB.MysqlDB.DefaultGormDB().Table("group_requests").Where("user_id=? and group_id=?", userID, groupID).Take(&groupRequest).Error
|
||||
@ -49,7 +38,7 @@ package im_mysql_model
|
||||
// }
|
||||
// return &groupRequest, nil
|
||||
//}
|
||||
|
||||
//
|
||||
//func DelGroupRequestByGroupIDAndUserID(groupID, userID string) error {
|
||||
// return db.DB.MysqlDB.DefaultGormDB().Table("group_requests").Where("group_id=? and user_id=?", groupID, userID).Delete(GroupRequest{}).Error
|
||||
//}
|
||||
@ -62,8 +51,8 @@ package im_mysql_model
|
||||
// }
|
||||
// return groupRequestList, nil
|
||||
//}
|
||||
|
||||
// received
|
||||
//
|
||||
//received
|
||||
//func GetRecvGroupApplicationList(userID string) ([]GroupRequest, error) {
|
||||
// var groupRequestList []GroupRequest
|
||||
// memberList, err := GetGroupMemberListByUserID(userID)
|
||||
@ -87,7 +76,7 @@ package im_mysql_model
|
||||
// err := db.DB.MysqlDB.DefaultGormDB().Table("group_requests").Where("user_id=?", userID).Find(&groupRequestList).Error
|
||||
// return groupRequestList, err
|
||||
//}
|
||||
|
||||
//
|
||||
//
|
||||
//func GroupApplicationResponse(pb *group.GroupApplicationResponseReq) (*group.CommonResp, error) {
|
||||
//
|
||||
@ -149,7 +138,7 @@ package im_mysql_model
|
||||
//
|
||||
// return &group.GroupApplicationResponseResp{}, nil
|
||||
//}
|
||||
|
||||
//
|
||||
//func FindGroupBeInvitedRequestInfoByUidAndGroupID(groupId, uid string) (*GroupRequest, error) {
|
||||
// dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
// if err != nil {
|
||||
@ -163,7 +152,7 @@ package im_mysql_model
|
||||
// return &beInvitedRequestUserInfo, nil
|
||||
//
|
||||
//}
|
||||
|
||||
//
|
||||
//func InsertGroupRequest(groupId, fromUser, fromUserNickName, fromUserFaceUrl, toUser, requestMsg, handledMsg string, handleStatus int) error {
|
||||
// return nil
|
||||
//}
|
||||
|
@ -1,7 +1,6 @@
|
||||
package im_mysql_model
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/trace_log"
|
||||
"Open_IM/pkg/utils"
|
||||
"context"
|
||||
@ -31,35 +30,35 @@ func (GroupRequest) TableName() string {
|
||||
|
||||
func (*GroupRequest) Create(ctx context.Context, groupRequests []*GroupRequest) (err error) {
|
||||
defer func() {
|
||||
trace_log.SetCtxDebug(ctx, utils.GetSelfFuncName(), err, "groupRequests", groupRequests)
|
||||
trace_log.SetCtxDebug(ctx, utils.GetFuncName(1), err, "groupRequests", groupRequests)
|
||||
}()
|
||||
return utils.Wrap(GroupRequestDB.Create(&groupRequests).Error, utils.GetSelfFuncName())
|
||||
}
|
||||
|
||||
func (*GroupRequest) Delete(ctx context.Context, groupRequests []*GroupRequest) (err error) {
|
||||
defer func() {
|
||||
trace_log.SetCtxDebug(ctx, utils.GetSelfFuncName(), err, "groupRequests", groupRequests)
|
||||
trace_log.SetCtxDebug(ctx, utils.GetFuncName(1), err, "groupRequests", groupRequests)
|
||||
}()
|
||||
return utils.Wrap(GroupRequestDB.Delete(&groupRequests).Error, utils.GetSelfFuncName())
|
||||
}
|
||||
|
||||
func (*GroupRequest) UpdateByMap(ctx context.Context, groupID string, userID string, args map[string]interface{}) (err error) {
|
||||
defer func() {
|
||||
trace_log.SetCtxDebug(ctx, utils.GetSelfFuncName(), err, "groupID", groupID, "userID", userID, "args", args)
|
||||
trace_log.SetCtxDebug(ctx, utils.GetFuncName(1), err, "groupID", groupID, "userID", userID, "args", args)
|
||||
}()
|
||||
return utils.Wrap(GroupRequestDB.Where("group_id = ? and user_id = ? ", groupID, userID).Updates(args).Error, utils.GetSelfFuncName())
|
||||
}
|
||||
|
||||
func (*GroupRequest) Update(ctx context.Context, groupRequests []*GroupRequest) (err error) {
|
||||
defer func() {
|
||||
trace_log.SetCtxDebug(ctx, utils.GetSelfFuncName(), err, "groupRequests", groupRequests)
|
||||
trace_log.SetCtxDebug(ctx, utils.GetFuncName(1), err, "groupRequests", groupRequests)
|
||||
}()
|
||||
return utils.Wrap(GroupRequestDB.Updates(&groupRequests).Error, utils.GetSelfFuncName())
|
||||
}
|
||||
|
||||
func (*GroupRequest) Find(ctx context.Context, groupRequests []*GroupRequest) (resultGroupRequests []*GroupRequest, err error) {
|
||||
defer func() {
|
||||
trace_log.SetCtxDebug(ctx, utils.GetSelfFuncName(), err, "groupRequests", groupRequests, "resultGroupRequests", resultGroupRequests)
|
||||
trace_log.SetCtxDebug(ctx, utils.GetFuncName(1), err, "groupRequests", groupRequests, "resultGroupRequests", resultGroupRequests)
|
||||
}()
|
||||
var where [][]interface{}
|
||||
for _, groupMember := range groupRequests {
|
||||
@ -71,163 +70,7 @@ func (*GroupRequest) Find(ctx context.Context, groupRequests []*GroupRequest) (r
|
||||
func (*GroupRequest) Take(ctx context.Context, groupID string, userID string) (groupRequest *GroupRequest, err error) {
|
||||
groupRequest = &GroupRequest{}
|
||||
defer func() {
|
||||
trace_log.SetCtxDebug(ctx, utils.GetSelfFuncName(), err, "groupID", groupID, "userID", userID, "groupRequest", *groupRequest)
|
||||
trace_log.SetCtxDebug(ctx, utils.GetFuncName(1), err, "groupID", groupID, "userID", userID, "groupRequest", *groupRequest)
|
||||
}()
|
||||
return groupRequest, utils.Wrap(GroupRequestDB.Where("group_id = ? and user_id = ? ", groupID, userID).Take(groupRequest).Error, utils.GetSelfFuncName())
|
||||
}
|
||||
|
||||
//func UpdateGroupRequest(groupRequest GroupRequest) error {
|
||||
// if groupRequest.HandledTime.Unix() < 0 {
|
||||
// groupRequest.HandledTime = utils.UnixSecondToTime(0)
|
||||
// }
|
||||
// return db.DB.MysqlDB.DefaultGormDB().Table("group_requests").Where("group_id=? and user_id=?", groupRequest.GroupID, groupRequest.UserID).Updates(&groupRequest).Error
|
||||
//}
|
||||
|
||||
func InsertIntoGroupRequest(toInsertInfo GroupRequest) error {
|
||||
DelGroupRequestByGroupIDAndUserID(toInsertInfo.GroupID, toInsertInfo.UserID)
|
||||
if toInsertInfo.HandledTime.Unix() < 0 {
|
||||
toInsertInfo.HandledTime = utils.UnixSecondToTime(0)
|
||||
}
|
||||
u := GroupRequestDB.Table("group_requests").Where("group_id=? and user_id=?", toInsertInfo.GroupID, toInsertInfo.UserID).Updates(&toInsertInfo)
|
||||
if u.RowsAffected != 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
toInsertInfo.ReqTime = time.Now()
|
||||
if toInsertInfo.HandledTime.Unix() < 0 {
|
||||
toInsertInfo.HandledTime = utils.UnixSecondToTime(0)
|
||||
}
|
||||
|
||||
err := GroupRequestDB.Create(&toInsertInfo).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func GetGroupRequestByGroupIDAndUserID(groupID, userID string) (*GroupRequest, error) {
|
||||
var groupRequest GroupRequest
|
||||
err := GroupRequestDB.Where("user_id=? and group_id=?", userID, groupID).Take(&groupRequest).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &groupRequest, nil
|
||||
}
|
||||
|
||||
func DelGroupRequestByGroupIDAndUserID(groupID, userID string) error {
|
||||
return GroupRequestDB.Table("group_requests").Where("group_id=? and user_id=?", groupID, userID).Delete(GroupRequest{}).Error
|
||||
}
|
||||
|
||||
func GetGroupRequestByGroupID(groupID string) ([]GroupRequest, error) {
|
||||
var groupRequestList []GroupRequest
|
||||
err := GroupRequestDB.Table("group_requests").Where("group_id=?", groupID).Find(&groupRequestList).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return groupRequestList, nil
|
||||
}
|
||||
|
||||
// received
|
||||
func GetRecvGroupApplicationList(userID string) ([]GroupRequest, error) {
|
||||
var groupRequestList []GroupRequest
|
||||
memberList, err := GetGroupMemberListByUserID(userID)
|
||||
if err != nil {
|
||||
return nil, utils.Wrap(err, utils.GetSelfFuncName())
|
||||
}
|
||||
for _, v := range memberList {
|
||||
if v.RoleLevel > constant.GroupOrdinaryUsers {
|
||||
list, err := GetGroupRequestByGroupID(v.GroupID)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
groupRequestList = append(groupRequestList, list...)
|
||||
}
|
||||
}
|
||||
return groupRequestList, nil
|
||||
}
|
||||
|
||||
func GetUserReqGroupByUserID(userID string) ([]GroupRequest, error) {
|
||||
var groupRequestList []GroupRequest
|
||||
err := GroupRequestDB.Table("group_requests").Where("user_id=?", userID).Find(&groupRequestList).Error
|
||||
return groupRequestList, err
|
||||
}
|
||||
|
||||
//
|
||||
//func GroupApplicationResponse(pb *group.GroupApplicationResponseReq) (*group.CommonResp, error) {
|
||||
//
|
||||
// ownerUser, err := FindGroupMemberInfoByGroupIdAndUserId(pb.GroupID, pb.OwnerID)
|
||||
// if err != nil {
|
||||
// log.ErrorByKv("FindGroupMemberInfoByGroupIdAndUserId failed", pb.OperationID, "groupId", pb.GroupID, "ownerID", pb.OwnerID)
|
||||
// return nil, err
|
||||
// }
|
||||
// if ownerUser.AdministratorLevel <= 0 {
|
||||
// return nil, errors.New("insufficient permissions")
|
||||
// }
|
||||
//
|
||||
// dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
// if err != nil {
|
||||
// return nil, err
|
||||
// }
|
||||
// var groupRequest GroupRequest
|
||||
// err = dbConn.Raw("select * from `group_request` where handled_user = ? and group_id = ? and from_user_id = ? and to_user_id = ?",
|
||||
// "", pb.GroupID, pb.FromUserID, pb.ToUserID).Scan(&groupRequest).Error
|
||||
// if err != nil {
|
||||
// log.ErrorByKv("find group_request info failed", pb.OperationID, "groupId", pb.GroupID, "fromUserId", pb.FromUserID, "toUserId", pb.OwnerID)
|
||||
// return nil, err
|
||||
// }
|
||||
//
|
||||
// if groupRequest.Flag != 0 {
|
||||
// return nil, errors.New("application has already handle")
|
||||
// }
|
||||
//
|
||||
// var saveFlag int
|
||||
// if pb.HandleResult == 0 {
|
||||
// saveFlag = -1
|
||||
// } else if pb.HandleResult == 1 {
|
||||
// saveFlag = 1
|
||||
// } else {
|
||||
// return nil, errors.New("parma HandleResult error")
|
||||
// }
|
||||
// err = dbConn.Exec("update `group_request` set flag = ?, handled_msg = ?, handled_user = ? where group_id = ? and from_user_id = ? and to_user_id = ?",
|
||||
// saveFlag, pb.HandledMsg, pb.OwnerID, groupRequest.GroupID, groupRequest.FromUserID, groupRequest.ToUserID).Error
|
||||
// if err != nil {
|
||||
// log.ErrorByKv("update group request failed", pb.OperationID, "groupID", pb.GroupID, "flag", saveFlag, "ownerId", pb.OwnerID, "fromUserId", pb.FromUserID, "toUserID", pb.ToUserID)
|
||||
// return nil, err
|
||||
// }
|
||||
//
|
||||
// if saveFlag == 1 {
|
||||
// if groupRequest.ToUserID == "0" {
|
||||
// err = InsertIntoGroupMember(pb.GroupID, pb.FromUserID, groupRequest.FromUserNickname, groupRequest.FromUserFaceUrl, 0)
|
||||
// if err != nil {
|
||||
// log.ErrorByKv("InsertIntoGroupMember failed", pb.OperationID, "groupID", pb.GroupID, "fromUserId", pb.FromUserID)
|
||||
// return nil, err
|
||||
// }
|
||||
// } else {
|
||||
// err = InsertIntoGroupMember(pb.GroupID, pb.ToUserID, groupRequest.ToUserNickname, groupRequest.ToUserFaceUrl, 0)
|
||||
// if err != nil {
|
||||
// log.ErrorByKv("InsertIntoGroupMember failed", pb.OperationID, "groupID", pb.GroupID, "fromUserId", pb.FromUserID)
|
||||
// return nil, err
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// return &group.GroupApplicationResponseResp{}, nil
|
||||
//}
|
||||
|
||||
//func FindGroupBeInvitedRequestInfoByUidAndGroupID(groupId, uid string) (*GroupRequest, error) {
|
||||
// dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
// if err != nil {
|
||||
// return nil, err
|
||||
// }
|
||||
// var beInvitedRequestUserInfo GroupRequest
|
||||
// err = dbConn.Table("group_request").Where("to_user_id=? and group_id=?", uid, groupId).Find(&beInvitedRequestUserInfo).Error
|
||||
// if err != nil {
|
||||
// return nil, err
|
||||
// }
|
||||
// return &beInvitedRequestUserInfo, nil
|
||||
//
|
||||
//}
|
||||
|
||||
//func InsertGroupRequest(groupId, fromUser, fromUserNickName, fromUserFaceUrl, toUser, requestMsg, handledMsg string, handleStatus int) error {
|
||||
// return nil
|
||||
//}
|
||||
|
@ -8,8 +8,6 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
var BlackDB *gorm.DB
|
||||
|
||||
type Black struct {
|
||||
OwnerUserID string `gorm:"column:owner_user_id;primary_key;size:64"`
|
||||
BlockUserID string `gorm:"column:block_user_id;primary_key;size:64"`
|
||||
@ -17,6 +15,65 @@ type Black struct {
|
||||
AddSource int32 `gorm:"column:add_source"`
|
||||
OperatorUserID string `gorm:"column:operator_user_id;size:64"`
|
||||
Ex string `gorm:"column:ex;size:1024"`
|
||||
db *gorm.DB `gorm:"-"`
|
||||
}
|
||||
|
||||
func NewBlack(db *gorm.DB) *Black {
|
||||
return &Black{db: db}
|
||||
}
|
||||
|
||||
func (b *Black) Create(ctx context.Context, blacks []*Black) (err error) {
|
||||
defer func() {
|
||||
trace_log.SetCtxDebug(ctx, utils.GetFuncName(1), err, "blacks", blacks)
|
||||
}()
|
||||
return utils.Wrap(b.db.Create(&blacks).Error, "")
|
||||
}
|
||||
|
||||
func (b *Black) Delete(ctx context.Context, blacks []*Black) (err error) {
|
||||
defer func() {
|
||||
trace_log.SetCtxDebug(ctx, utils.GetFuncName(1), err, "blacks", blacks)
|
||||
}()
|
||||
return utils.Wrap(GroupMemberDB.Delete(blacks).Error, "")
|
||||
}
|
||||
|
||||
func (b *Black) UpdateByMap(ctx context.Context, ownerUserID, blockUserID string, args map[string]interface{}) (err error) {
|
||||
defer func() {
|
||||
trace_log.SetCtxDebug(ctx, utils.GetFuncName(1), err, "ownerUserID", ownerUserID, "blockUserID", blockUserID, "args", args)
|
||||
}()
|
||||
return utils.Wrap(b.db.Where("block_user_id = ? and block_user_id = ?", ownerUserID, blockUserID).Updates(args).Error, "")
|
||||
}
|
||||
|
||||
func (b *Black) Update(ctx context.Context, blacks []*Black) (err error) {
|
||||
defer func() {
|
||||
trace_log.SetCtxDebug(ctx, utils.GetFuncName(1), err, "blacks", blacks)
|
||||
}()
|
||||
return utils.Wrap(b.db.Updates(&blacks).Error, "")
|
||||
}
|
||||
|
||||
func (b *Black) Find(ctx context.Context, blacks []Black) (blackList []*Black, err error) {
|
||||
defer func() {
|
||||
trace_log.SetCtxDebug(ctx, utils.GetFuncName(1), err, "blacks", blacks, "blackList", blackList)
|
||||
}()
|
||||
var where [][]interface{}
|
||||
for _, black := range blacks {
|
||||
where = append(where, []interface{}{black.OwnerUserID, black.BlockUserID})
|
||||
}
|
||||
return blackList, utils.Wrap(GroupMemberDB.Where("(owner_user_id, block_user_id) in ?", where).Find(&blackList).Error, "")
|
||||
}
|
||||
|
||||
func (b *Black) Take(ctx context.Context, blackID string) (black *Black, err error) {
|
||||
black = &Black{}
|
||||
defer func() {
|
||||
trace_log.SetCtxDebug(ctx, utils.GetFuncName(1), err, "blackID", blackID, "black", *black)
|
||||
}()
|
||||
return black, utils.Wrap(b.db.Where("black_id = ?", blackID).Take(black).Error, "")
|
||||
}
|
||||
|
||||
func (b *Black) FindByOwnerUserID(ctx context.Context, ownerUserID string) (blackList []*Black, err error) {
|
||||
defer func() {
|
||||
trace_log.SetCtxDebug(ctx, utils.GetFuncName(1), err, "ownerUserID", ownerUserID, "blackList", blackList)
|
||||
}()
|
||||
return blackList, utils.Wrap(GroupMemberDB.Where("owner_user_id = ?", ownerUserID).Find(&blackList).Error, "")
|
||||
}
|
||||
|
||||
func InsertInToUserBlackList(ctx context.Context, black Black) (err error) {
|
||||
@ -47,7 +104,7 @@ func GetBlackListByUserID(ownerUserID string) ([]Black, error) {
|
||||
|
||||
func GetBlackIDListByUserID(ownerUserID string) ([]string, error) {
|
||||
var blackIDList []string
|
||||
err := BlackDB.Where("owner_user_id=?", ownerUserID).Pluck("block_user_id", &blackIDList).Error
|
||||
err := b.db.Where("owner_user_id=?", ownerUserID).Pluck("block_user_id", &blackIDList).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -20,22 +20,6 @@ type BlackList struct {
|
||||
EndDisableTime time.Time `gorm:"column:end_disable_time"`
|
||||
}
|
||||
|
||||
type User struct {
|
||||
UserID string `gorm:"column:user_id;primary_key;size:64"`
|
||||
Nickname string `gorm:"column:name;size:255"`
|
||||
FaceURL string `gorm:"column:face_url;size:255"`
|
||||
Gender int32 `gorm:"column:gender"`
|
||||
PhoneNumber string `gorm:"column:phone_number;size:32"`
|
||||
Birth time.Time `gorm:"column:birth"`
|
||||
Email string `gorm:"column:email;size:64"`
|
||||
Ex string `gorm:"column:ex;size:1024"`
|
||||
CreateTime time.Time `gorm:"column:create_time;index:create_time"`
|
||||
AppMangerLevel int32 `gorm:"column:app_manger_level"`
|
||||
GlobalRecvMsgOpt int32 `gorm:"column:global_recv_msg_opt"`
|
||||
|
||||
status int32 `gorm:"column:status"`
|
||||
}
|
||||
|
||||
func UserRegister(user User) error {
|
||||
user.CreateTime = time.Now()
|
||||
if user.AppMangerLevel == 0 {
|
||||
|
66
pkg/common/db/mysql_model/im_mysql_model/user_model_k.go
Normal file
66
pkg/common/db/mysql_model/im_mysql_model/user_model_k.go
Normal file
@ -0,0 +1,66 @@
|
||||
package im_mysql_model
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/trace_log"
|
||||
"Open_IM/pkg/utils"
|
||||
"context"
|
||||
"gorm.io/gorm"
|
||||
"time"
|
||||
)
|
||||
|
||||
var userDB *gorm.DB
|
||||
|
||||
type User struct {
|
||||
UserID string `gorm:"column:user_id;primary_key;size:64"`
|
||||
Nickname string `gorm:"column:name;size:255"`
|
||||
FaceURL string `gorm:"column:face_url;size:255"`
|
||||
Gender int32 `gorm:"column:gender"`
|
||||
PhoneNumber string `gorm:"column:phone_number;size:32"`
|
||||
Birth time.Time `gorm:"column:birth"`
|
||||
Email string `gorm:"column:email;size:64"`
|
||||
Ex string `gorm:"column:ex;size:1024"`
|
||||
CreateTime time.Time `gorm:"column:create_time;index:create_time"`
|
||||
AppMangerLevel int32 `gorm:"column:app_manger_level"`
|
||||
GlobalRecvMsgOpt int32 `gorm:"column:global_recv_msg_opt"`
|
||||
|
||||
status int32 `gorm:"column:status"`
|
||||
}
|
||||
|
||||
func (*User) Create(ctx context.Context, users []*User) (err error) {
|
||||
defer func() {
|
||||
trace_log.SetCtxDebug(ctx, utils.GetFuncName(1), err, "users", users)
|
||||
}()
|
||||
err = utils.Wrap(userDB.Create(&users).Error, "")
|
||||
return err
|
||||
}
|
||||
|
||||
func (*User) UpdateByMap(ctx context.Context, userID string, args map[string]interface{}) (err error) {
|
||||
defer func() {
|
||||
trace_log.SetCtxDebug(ctx, utils.GetFuncName(1), err, "userID", userID, "args", args)
|
||||
}()
|
||||
return utils.Wrap(userDB.Where("user_id = ?", userID).Updates(args).Error, "")
|
||||
}
|
||||
|
||||
func (*User) Update(ctx context.Context, users []*User) (err error) {
|
||||
defer func() {
|
||||
trace_log.SetCtxDebug(ctx, utils.GetFuncName(1), err, "users", users)
|
||||
}()
|
||||
return utils.Wrap(userDB.Updates(&users).Error, "")
|
||||
}
|
||||
|
||||
func (*User) Find(ctx context.Context, userIDs []string) (users []*User, err error) {
|
||||
defer func() {
|
||||
trace_log.SetCtxDebug(ctx, utils.GetFuncName(1), err, "userIDs", userIDs, "users", users)
|
||||
}()
|
||||
err = utils.Wrap(userDB.Where("user_id in (?)", userIDs).Find(&users).Error, "")
|
||||
return users, err
|
||||
}
|
||||
|
||||
func (*User) Take(ctx context.Context, userID string) (user *User, err error) {
|
||||
user = &User{}
|
||||
defer func() {
|
||||
trace_log.SetCtxDebug(ctx, utils.GetFuncName(1), err, "userID", userID, "user", *user)
|
||||
}()
|
||||
err = utils.Wrap(userDB.Where("user_id = ?", userID).Take(&user).Error, "")
|
||||
return user, err
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@ -13,57 +13,44 @@ message GroupAddMemberInfo{
|
||||
message CreateGroupReq{
|
||||
repeated GroupAddMemberInfo initMemberList = 1;
|
||||
server_api_params.GroupInfo groupInfo = 2;
|
||||
string operationID = 3;
|
||||
string opUserID = 4; //app manager or group owner
|
||||
string ownerUserID = 5; //owner
|
||||
|
||||
|
||||
}
|
||||
message CreateGroupResp{
|
||||
server_api_params.CommonResp commonResp = 1;
|
||||
server_api_params.GroupInfo groupInfo = 3;
|
||||
}
|
||||
|
||||
|
||||
message GetGroupsInfoReq{
|
||||
repeated string groupIDList = 1;
|
||||
string operationID = 2;
|
||||
string opUserID = 3; //No verification permission
|
||||
}
|
||||
message GetGroupsInfoResp{
|
||||
server_api_params.CommonResp commonResp = 1;
|
||||
repeated server_api_params.GroupInfo groupInfoList = 3;
|
||||
}
|
||||
|
||||
|
||||
message SetGroupInfoReq{
|
||||
server_api_params.GroupInfoForSet groupInfoForSet = 1;
|
||||
string opUserID = 2; //app manager or group owner
|
||||
string operationID = 3;
|
||||
}
|
||||
message SetGroupInfoResp{
|
||||
server_api_params.CommonResp commonResp = 1;
|
||||
}
|
||||
|
||||
|
||||
message GetGroupApplicationListReq {
|
||||
string opUserID = 1; //app manager or group owner(manager)
|
||||
string operationID = 2;
|
||||
string fromUserID = 3; //owner or manager
|
||||
server_api_params.RequestPagination pagination = 1;
|
||||
string fromUserID = 3; //owner or admin
|
||||
}
|
||||
message GetGroupApplicationListResp {
|
||||
server_api_params.CommonResp commonResp = 1;
|
||||
int32 total = 1;
|
||||
repeated server_api_params.GroupRequest groupRequestList = 3;
|
||||
}
|
||||
|
||||
message GetUserReqApplicationListReq{
|
||||
string userID = 1;
|
||||
string opUserID = 2;
|
||||
string operationID = 3;
|
||||
server_api_params.RequestPagination pagination = 2;
|
||||
}
|
||||
|
||||
message GetUserReqApplicationListResp{
|
||||
server_api_params.CommonResp commonResp = 1;
|
||||
int32 total = 1;
|
||||
repeated server_api_params.GroupRequest groupRequestList = 2;
|
||||
}
|
||||
|
||||
@ -72,76 +59,59 @@ message TransferGroupOwnerReq {
|
||||
string groupID = 1;
|
||||
string oldOwnerUserID = 2;
|
||||
string newOwnerUserID = 3;
|
||||
string operationID = 4;
|
||||
string opUserID = 5; //app manager or group owner
|
||||
}
|
||||
message TransferGroupOwnerResp{
|
||||
server_api_params.CommonResp commonResp = 1;
|
||||
|
||||
}
|
||||
|
||||
message JoinGroupReq{
|
||||
string groupID = 1;
|
||||
string reqMessage = 2;
|
||||
string opUserID = 3;
|
||||
string operationID = 4;
|
||||
int32 joinSource = 5;
|
||||
string inviterUserID = 6;
|
||||
|
||||
}
|
||||
message JoinGroupResp{
|
||||
server_api_params.CommonResp commonResp = 1;
|
||||
}
|
||||
|
||||
|
||||
message GroupApplicationResponseReq{
|
||||
string operationID = 1;
|
||||
string opUserID = 2;
|
||||
string groupID = 3;
|
||||
string fromUserID = 4; //
|
||||
string handledMsg = 5;
|
||||
int32 handleResult = 6;
|
||||
}
|
||||
message GroupApplicationResponseResp{
|
||||
server_api_params.CommonResp commonResp = 1;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
message QuitGroupReq{
|
||||
string groupID = 1;
|
||||
string operationID = 2;
|
||||
string opUserID = 3;
|
||||
}
|
||||
message QuitGroupResp{
|
||||
server_api_params.CommonResp commonResp = 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
message GetGroupMemberListReq {
|
||||
string groupID = 1;
|
||||
string opUserID = 2; //No verification permission
|
||||
string operationID = 3;
|
||||
int32 filter = 4;
|
||||
int32 nextSeq = 5;
|
||||
server_api_params.RequestPagination pagination = 2;
|
||||
}
|
||||
|
||||
message GetGroupMemberListResp {
|
||||
server_api_params.CommonResp commonResp = 1;
|
||||
int32 total = 1;
|
||||
repeated server_api_params.GroupMemberFullInfo memberList = 3;
|
||||
int32 nextSeq = 4;
|
||||
}
|
||||
|
||||
|
||||
message GetGroupMembersInfoReq {
|
||||
string groupID = 1;
|
||||
repeated string memberList = 2;
|
||||
string opUserID = 3; //No verification permission
|
||||
string operationID = 4;
|
||||
}
|
||||
|
||||
message GetGroupMembersInfoResp {
|
||||
server_api_params.CommonResp commonResp = 1;
|
||||
repeated server_api_params.GroupMemberFullInfo memberList = 3;
|
||||
}
|
||||
|
||||
@ -149,8 +119,6 @@ message KickGroupMemberReq {
|
||||
string groupID = 1;
|
||||
repeated string kickedUserIDList = 2;
|
||||
string reason = 3;
|
||||
string operationID = 5;
|
||||
string opUserID = 6; //app manger or group manager
|
||||
}
|
||||
|
||||
message Id2Result {
|
||||
@ -159,44 +127,36 @@ message Id2Result {
|
||||
}
|
||||
|
||||
message KickGroupMemberResp {
|
||||
server_api_params.CommonResp commonResp = 1;
|
||||
repeated Id2Result id2ResultList = 3;
|
||||
}
|
||||
|
||||
|
||||
message GetJoinedGroupListReq {
|
||||
string fromUserID = 1;
|
||||
string operationID = 2;
|
||||
string opUserID = 3; //app manager or FromUserID
|
||||
server_api_params.RequestPagination pagination = 2;
|
||||
}
|
||||
message GetJoinedGroupListResp{
|
||||
server_api_params.CommonResp commonResp = 1;
|
||||
int32 total = 1;
|
||||
repeated server_api_params.GroupInfo groupList = 3;
|
||||
}
|
||||
|
||||
|
||||
message InviteUserToGroupReq {
|
||||
string operationID = 2;
|
||||
string groupID = 3;
|
||||
string reason = 4;
|
||||
repeated string invitedUserIDList = 5;
|
||||
string opUserID = 6; //group member or app manager
|
||||
}
|
||||
message InviteUserToGroupResp {
|
||||
server_api_params.CommonResp commonResp = 1;
|
||||
repeated Id2Result id2ResultList = 3; // 0 ok, -1 error
|
||||
}
|
||||
|
||||
|
||||
message GetGroupAllMemberReq {
|
||||
string groupID = 1;
|
||||
string opUserID = 2; //No verification permission
|
||||
string operationID = 3;
|
||||
int32 offset = 4;
|
||||
int32 count = 5;
|
||||
}
|
||||
message GetGroupAllMemberResp {
|
||||
server_api_params.CommonResp commonResp = 1;
|
||||
repeated server_api_params.GroupMemberFullInfo memberList = 3;
|
||||
}
|
||||
|
||||
@ -208,95 +168,74 @@ message CMSGroup {
|
||||
|
||||
|
||||
message GetGroupsReq {
|
||||
server_api_params.RequestPagination pagination = 1;
|
||||
string groupName = 2;
|
||||
string groupID = 3;
|
||||
string operationID = 4;
|
||||
server_api_params.RequestPagination pagination = 1;
|
||||
string groupName = 2;
|
||||
string groupID = 3;
|
||||
}
|
||||
|
||||
message GetGroupsResp {
|
||||
repeated CMSGroup groups = 1;
|
||||
server_api_params.ResponsePagination pagination = 2;
|
||||
int32 GroupNum = 3;
|
||||
server_api_params.CommonResp commonResp = 4;
|
||||
}
|
||||
|
||||
message GetGroupMemberReq {
|
||||
string groupID = 1;
|
||||
string operationID = 2;
|
||||
}
|
||||
|
||||
message GetGroupMembersCMSReq {
|
||||
string groupID = 1;
|
||||
string userName = 2;
|
||||
server_api_params.RequestPagination pagination = 3;
|
||||
string operationID = 4;
|
||||
}
|
||||
|
||||
message GetGroupMembersCMSResp {
|
||||
repeated server_api_params.GroupMemberFullInfo members = 1;
|
||||
server_api_params.ResponsePagination pagination = 2;
|
||||
int32 memberNums = 3;
|
||||
server_api_params.CommonResp commonResp = 4;
|
||||
}
|
||||
|
||||
message DismissGroupReq{
|
||||
string opUserID = 1; //group or app manager
|
||||
string operationID = 2;
|
||||
string groupID = 3;
|
||||
}
|
||||
|
||||
message DismissGroupResp{
|
||||
server_api_params.CommonResp commonResp = 1;
|
||||
}
|
||||
|
||||
|
||||
message MuteGroupMemberReq{
|
||||
string opUserID = 1; //group or app manager
|
||||
string operationID = 2;
|
||||
string groupID = 3;
|
||||
string userID = 4;
|
||||
uint32 mutedSeconds = 5;
|
||||
}
|
||||
|
||||
message MuteGroupMemberResp{
|
||||
server_api_params.CommonResp commonResp = 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
message CancelMuteGroupMemberReq{
|
||||
string opUserID = 1; //group or app manager
|
||||
string operationID = 2;
|
||||
string groupID = 3;
|
||||
string userID = 4;
|
||||
}
|
||||
|
||||
message CancelMuteGroupMemberResp{
|
||||
server_api_params.CommonResp commonResp = 1;
|
||||
}
|
||||
|
||||
|
||||
message MuteGroupReq{
|
||||
string opUserID = 1; //group or app manager
|
||||
string operationID = 2;
|
||||
string groupID = 3;
|
||||
}
|
||||
|
||||
message MuteGroupResp{
|
||||
server_api_params.CommonResp commonResp = 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
message CancelMuteGroupReq{
|
||||
string opUserID = 1; //group or app manager
|
||||
string operationID = 2;
|
||||
string groupID = 3;
|
||||
}
|
||||
|
||||
message CancelMuteGroupResp{
|
||||
server_api_params.CommonResp commonResp = 1;
|
||||
}
|
||||
|
||||
|
||||
@ -305,41 +244,32 @@ message CancelMuteGroupResp{
|
||||
message SetGroupMemberNicknameReq{
|
||||
string groupID = 1;
|
||||
string nickname = 2;
|
||||
string opUserID = 3;
|
||||
string operationID = 4;
|
||||
string userID = 5;
|
||||
}
|
||||
message SetGroupMemberNicknameResp{
|
||||
server_api_params.CommonResp commonResp = 1;
|
||||
}
|
||||
|
||||
message GetJoinedSuperGroupListReq {
|
||||
string operationID = 1;
|
||||
server_api_params.RequestPagination pagination = 1;
|
||||
string userID = 2;
|
||||
string opUserID = 3;
|
||||
}
|
||||
|
||||
message GetJoinedSuperGroupListResp {
|
||||
server_api_params.CommonResp commonResp = 1;
|
||||
int32 total = 1;
|
||||
repeated server_api_params.GroupInfo groupList = 3;
|
||||
}
|
||||
|
||||
message GetSuperGroupsInfoReq {
|
||||
repeated string groupIDList = 1;
|
||||
string operationID = 2;
|
||||
string opUserID = 3; //No verification permission
|
||||
}
|
||||
|
||||
message GetSuperGroupsInfoResp {
|
||||
server_api_params.CommonResp commonResp = 1;
|
||||
repeated server_api_params.GroupInfo groupInfoList = 3;
|
||||
}
|
||||
|
||||
message SetGroupMemberInfoReq{
|
||||
string groupID = 1;
|
||||
string userID = 2;
|
||||
string opUserID = 3;
|
||||
string operationID = 4;
|
||||
google.protobuf.StringValue nickname = 5;
|
||||
google.protobuf.StringValue faceURL = 6;
|
||||
google.protobuf.Int32Value roleLevel = 7;
|
||||
@ -347,53 +277,77 @@ message SetGroupMemberInfoReq{
|
||||
}
|
||||
|
||||
message SetGroupMemberInfoResp{
|
||||
server_api_params.CommonResp commonResp = 1;
|
||||
|
||||
}
|
||||
|
||||
message GetGroupAbstractInfoReq{
|
||||
string groupID = 1;
|
||||
string opUserID = 2;
|
||||
string operationID = 3;
|
||||
repeated string groupIDs = 1;
|
||||
}
|
||||
|
||||
message GetGroupAbstractInfoResp{
|
||||
server_api_params.CommonResp commonResp = 1;
|
||||
message GroupAbstractInfo{
|
||||
string groupID = 1;
|
||||
int32 groupMemberNumber = 2;
|
||||
uint64 groupMemberListHash = 3;
|
||||
}
|
||||
|
||||
message GetGroupAbstractInfoResp{
|
||||
repeated GroupAbstractInfo groupAbstractInfos = 1;
|
||||
}
|
||||
|
||||
|
||||
service group{
|
||||
//创建群
|
||||
rpc createGroup(CreateGroupReq) returns(CreateGroupResp);
|
||||
//申请加群
|
||||
rpc joinGroup(JoinGroupReq) returns(JoinGroupResp);
|
||||
//退出群
|
||||
rpc quitGroup(QuitGroupReq) returns(QuitGroupResp);
|
||||
//获取指定群信息
|
||||
rpc getGroupsInfo(GetGroupsInfoReq) returns(GetGroupsInfoResp);
|
||||
//设置群信息
|
||||
rpc setGroupInfo(SetGroupInfoReq) returns(SetGroupInfoResp);
|
||||
//(以管理员或群主身份)获取群的加群申请
|
||||
rpc getGroupApplicationList(GetGroupApplicationListReq) returns(GetGroupApplicationListResp);
|
||||
//获取用户自己的主动加群申请
|
||||
rpc getUserReqApplicationList(GetUserReqApplicationListReq) returns(GetUserReqApplicationListResp);
|
||||
//转让群主
|
||||
rpc transferGroupOwner(TransferGroupOwnerReq) returns(TransferGroupOwnerResp);
|
||||
//群主或管理员处理进群申请
|
||||
rpc groupApplicationResponse(GroupApplicationResponseReq) returns(GroupApplicationResponseResp);
|
||||
//获取某个群的群成员
|
||||
rpc getGroupMemberList(GetGroupMemberListReq) returns(GetGroupMemberListResp);
|
||||
//获取某个群的指定群成员
|
||||
rpc getGroupMembersInfo(GetGroupMembersInfoReq) returns(GetGroupMembersInfoResp);
|
||||
//踢出群
|
||||
rpc kickGroupMember(KickGroupMemberReq) returns (KickGroupMemberResp);
|
||||
//获取某个人已加入群
|
||||
rpc getJoinedGroupList(GetJoinedGroupListReq) returns (GetJoinedGroupListResp);
|
||||
//邀请某些人进群
|
||||
rpc inviteUserToGroup(InviteUserToGroupReq) returns (InviteUserToGroupResp);
|
||||
rpc getGroupAllMember(GetGroupAllMemberReq) returns(GetGroupAllMemberResp);
|
||||
|
||||
rpc GetGroups(GetGroupsReq) returns(GetGroupsResp);
|
||||
rpc GetGroupMembersCMS(GetGroupMembersCMSReq) returns(GetGroupMembersCMSResp);
|
||||
|
||||
|
||||
//解散群
|
||||
rpc DismissGroup(DismissGroupReq) returns(DismissGroupResp);
|
||||
//对某个群成员禁言
|
||||
rpc MuteGroupMember(MuteGroupMemberReq) returns(MuteGroupMemberResp);
|
||||
//对某个群成员取消禁言
|
||||
rpc CancelMuteGroupMember(CancelMuteGroupMemberReq) returns(CancelMuteGroupMemberResp);
|
||||
//对某个群禁言
|
||||
rpc MuteGroup(MuteGroupReq) returns(MuteGroupResp);
|
||||
//对某个群取消禁言
|
||||
rpc CancelMuteGroup(CancelMuteGroupReq) returns(CancelMuteGroupResp);
|
||||
|
||||
rpc SetGroupMemberNickname(SetGroupMemberNicknameReq) returns (SetGroupMemberNicknameResp);
|
||||
//获取某个用户加入的超级群
|
||||
rpc GetJoinedSuperGroupList(GetJoinedSuperGroupListReq) returns (GetJoinedSuperGroupListResp);
|
||||
//获取指定的超级群信息
|
||||
rpc GetSuperGroupsInfo(GetSuperGroupsInfoReq) returns (GetSuperGroupsInfoResp);
|
||||
//设置群成员昵称
|
||||
rpc SetGroupMemberNickname(SetGroupMemberNicknameReq) returns (SetGroupMemberNicknameResp);
|
||||
//设置群成员信息
|
||||
rpc SetGroupMemberInfo(SetGroupMemberInfoReq) returns (SetGroupMemberInfoResp);
|
||||
//获取群信息hash值
|
||||
rpc GetGroupAbstractInfo(GetGroupAbstractInfoReq) returns (GetGroupAbstractInfoResp);
|
||||
}
|
||||
|
||||
|
@ -519,10 +519,6 @@ message RequestPagination {
|
||||
int32 showNumber = 2;
|
||||
}
|
||||
|
||||
message ResponsePagination {
|
||||
int32 CurrentPage = 5;
|
||||
int32 ShowNumber = 6;
|
||||
}
|
||||
|
||||
|
||||
///////////////////signal//////////////
|
||||
|
Loading…
x
Reference in New Issue
Block a user