mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-06-03 22:39:28 +08:00
errcode
This commit is contained in:
parent
26ed14d1d3
commit
67c082ab7b
@ -1,7 +1,7 @@
|
||||
package apiAuth
|
||||
|
||||
import (
|
||||
api "Open_IM/pkg/base_info"
|
||||
api "Open_IM/pkg/api_struct"
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/log"
|
||||
|
@ -1,7 +1,7 @@
|
||||
package clientInit
|
||||
|
||||
import (
|
||||
api "Open_IM/pkg/base_info"
|
||||
api "Open_IM/pkg/api_struct"
|
||||
imdb "Open_IM/pkg/common/db/mysql_model/im_mysql_model"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/common/token_verify"
|
||||
|
@ -1,7 +1,7 @@
|
||||
package conversation
|
||||
|
||||
import (
|
||||
api "Open_IM/pkg/base_info"
|
||||
api "Open_IM/pkg/api_struct"
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/getcdv3"
|
||||
|
@ -2,7 +2,7 @@ package friend
|
||||
|
||||
//import (
|
||||
// jsonData "Open_IM/internal/utils"
|
||||
// api "Open_IM/pkg/base_info"
|
||||
// api "Open_IM/pkg/api_struct"
|
||||
// "Open_IM/pkg/common/config"
|
||||
// "Open_IM/pkg/common/log"
|
||||
// "Open_IM/pkg/common/token_verify"
|
||||
|
@ -2,7 +2,7 @@ package friend
|
||||
|
||||
import (
|
||||
common "Open_IM/internal/api_to_rpc"
|
||||
api "Open_IM/pkg/base_info"
|
||||
api "Open_IM/pkg/api_struct"
|
||||
"Open_IM/pkg/common/config"
|
||||
rpc "Open_IM/pkg/proto/friend"
|
||||
"github.com/gin-gonic/gin"
|
||||
|
@ -2,7 +2,7 @@ package group
|
||||
|
||||
import (
|
||||
common "Open_IM/internal/api_to_rpc"
|
||||
api "Open_IM/pkg/base_info"
|
||||
api "Open_IM/pkg/api_struct"
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/log"
|
||||
|
@ -2,7 +2,7 @@ package group
|
||||
|
||||
import (
|
||||
jsonData "Open_IM/internal/utils"
|
||||
api "Open_IM/pkg/base_info"
|
||||
api "Open_IM/pkg/api_struct"
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/common/token_verify"
|
||||
|
@ -7,7 +7,7 @@
|
||||
package manage
|
||||
|
||||
import (
|
||||
api "Open_IM/pkg/base_info"
|
||||
api "Open_IM/pkg/api_struct"
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/db/mysql_model/im_mysql_model"
|
||||
|
@ -7,7 +7,7 @@
|
||||
package manage
|
||||
|
||||
import (
|
||||
api "Open_IM/pkg/base_info"
|
||||
api "Open_IM/pkg/api_struct"
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/log"
|
||||
|
@ -1,7 +1,7 @@
|
||||
package msg
|
||||
|
||||
import (
|
||||
api "Open_IM/pkg/base_info"
|
||||
api "Open_IM/pkg/api_struct"
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/log"
|
||||
|
@ -1,7 +1,7 @@
|
||||
package msg
|
||||
|
||||
import (
|
||||
api "Open_IM/pkg/base_info"
|
||||
api "Open_IM/pkg/api_struct"
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/log"
|
||||
|
@ -1,7 +1,7 @@
|
||||
package office
|
||||
|
||||
import (
|
||||
api "Open_IM/pkg/base_info"
|
||||
api "Open_IM/pkg/api_struct"
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/common/token_verify"
|
||||
|
@ -1,7 +1,7 @@
|
||||
package office
|
||||
|
||||
import (
|
||||
api "Open_IM/pkg/base_info"
|
||||
api "Open_IM/pkg/api_struct"
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/common/token_verify"
|
||||
|
@ -1,7 +1,7 @@
|
||||
package apiThird
|
||||
|
||||
import (
|
||||
api "Open_IM/pkg/base_info"
|
||||
api "Open_IM/pkg/api_struct"
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/log"
|
||||
|
@ -1,7 +1,7 @@
|
||||
package apiThird
|
||||
|
||||
import (
|
||||
api "Open_IM/pkg/base_info"
|
||||
api "Open_IM/pkg/api_struct"
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/log"
|
||||
|
@ -1,7 +1,7 @@
|
||||
package apiThird
|
||||
|
||||
import (
|
||||
api "Open_IM/pkg/base_info"
|
||||
api "Open_IM/pkg/api_struct"
|
||||
"Open_IM/pkg/common/db"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/common/token_verify"
|
||||
|
@ -1,7 +1,7 @@
|
||||
package apiThird
|
||||
|
||||
import (
|
||||
api "Open_IM/pkg/base_info"
|
||||
api "Open_IM/pkg/api_struct"
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/constant"
|
||||
imdb "Open_IM/pkg/common/db/mysql_model/im_mysql_model"
|
||||
|
@ -1,7 +1,7 @@
|
||||
package apiThird
|
||||
|
||||
import (
|
||||
api "Open_IM/pkg/base_info"
|
||||
api "Open_IM/pkg/api_struct"
|
||||
"Open_IM/pkg/common/db"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/common/token_verify"
|
||||
|
@ -1,7 +1,7 @@
|
||||
package apiThird
|
||||
|
||||
import (
|
||||
api "Open_IM/pkg/base_info"
|
||||
api "Open_IM/pkg/api_struct"
|
||||
"Open_IM/pkg/common/db"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/common/token_verify"
|
||||
|
@ -1,7 +1,7 @@
|
||||
package apiThird
|
||||
|
||||
import (
|
||||
api "Open_IM/pkg/base_info"
|
||||
api "Open_IM/pkg/api_struct"
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/log"
|
||||
|
@ -2,7 +2,7 @@ package user
|
||||
|
||||
import (
|
||||
jsonData "Open_IM/internal/utils"
|
||||
api "Open_IM/pkg/base_info"
|
||||
api "Open_IM/pkg/api_struct"
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/log"
|
||||
|
@ -1,6 +1,7 @@
|
||||
package common
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/common/tracelog"
|
||||
"Open_IM/pkg/getcdv3"
|
||||
@ -8,7 +9,10 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/gin-gonic/gin"
|
||||
"google.golang.org/grpc/status"
|
||||
"net/http"
|
||||
"reflect"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func ApiToRpc(c *gin.Context, apiReq, apiResp interface{}, rpcName string, rpcClientFunc interface{}, rpcFuncName string) {
|
||||
@ -16,16 +20,16 @@ func ApiToRpc(c *gin.Context, apiReq, apiResp interface{}, rpcName string, rpcCl
|
||||
rpcName = utils2.GetFuncName(1)
|
||||
}
|
||||
logFuncName := fmt.Sprintf("[ApiToRpc: %s]%s", utils2.GetFuncName(1), rpcFuncName)
|
||||
ctx := tracelog.NewCtx1(c, rpcFuncName)
|
||||
ctx := tracelog.NewCtx(c, rpcFuncName)
|
||||
defer log.ShowLog(ctx)
|
||||
if err := c.BindJSON(apiReq); err != nil {
|
||||
tracelog.WriteErrorResponse(ctx, "BindJSON", err)
|
||||
WriteErrorResponse(ctx, "BindJSON", err)
|
||||
return
|
||||
}
|
||||
tracelog.SetCtxInfo(ctx, logFuncName, nil, "apiReq", apiReq)
|
||||
etcdConn, err := getcdv3.GetConn(ctx, rpcName)
|
||||
if err != nil {
|
||||
tracelog.WriteErrorResponse(ctx, "GetConn", err)
|
||||
WriteErrorResponse(ctx, "GetConn", err)
|
||||
return
|
||||
}
|
||||
rpcClient := reflect.ValueOf(rpcClientFunc).Call([]reflect.Value{
|
||||
@ -40,7 +44,7 @@ func ApiToRpc(c *gin.Context, apiReq, apiResp interface{}, rpcName string, rpcCl
|
||||
}) // respArr => (apiResp, error)
|
||||
if !respArr[1].IsNil() { // rpcClient err != nil
|
||||
err := respArr[1].Interface().(error)
|
||||
tracelog.WriteErrorResponse(ctx, rpcFuncName, err, "callRpcResp", "error")
|
||||
WriteErrorResponse(ctx, rpcFuncName, err, "callRpcResp", "error")
|
||||
return
|
||||
}
|
||||
rpcResp := respArr[0].Elem()
|
||||
@ -48,7 +52,7 @@ func ApiToRpc(c *gin.Context, apiReq, apiResp interface{}, rpcName string, rpcCl
|
||||
if apiResp != nil {
|
||||
CopyAny(rpcResp.Interface(), apiResp)
|
||||
}
|
||||
tracelog.SetSuccess(ctx, rpcFuncName, apiResp)
|
||||
SetSuccess(ctx, rpcFuncName, apiResp)
|
||||
}
|
||||
|
||||
func rpcString(v interface{}) string {
|
||||
@ -57,3 +61,43 @@ func rpcString(v interface{}) string {
|
||||
}
|
||||
return fmt.Sprintf("%+v", v)
|
||||
}
|
||||
|
||||
type baseResp struct {
|
||||
ErrCode int32 `json:"errCode"`
|
||||
ErrMsg string `json:"errMsg"`
|
||||
ErrDtl string `json:"errDtl"`
|
||||
Data interface{} `json:"data"`
|
||||
}
|
||||
|
||||
func WriteErrorResponse(ctx context.Context, funcName string, err error, args ...interface{}) {
|
||||
tracelog.SetCtxInfo(ctx, funcName, err, args)
|
||||
e := tracelog.Unwrap(err)
|
||||
switch t := e.(type) {
|
||||
case *constant.ErrInfo:
|
||||
ctx.Value(tracelog.TraceLogKey).(*tracelog.ApiInfo).GinCtx.JSON(http.StatusOK, baseResp{ErrCode: t.ErrCode, ErrMsg: t.ErrMsg, ErrDtl: t.DetailErrMsg})
|
||||
//ctx.Value(TraceLogKey).(*ApiInfo).GinCtx.JSON(http.StatusOK, gin.H{"errCode": t.ErrCode, "errMsg": t.ErrMsg, "errDtl": t.DetailErrMsg})
|
||||
return
|
||||
default:
|
||||
s, ok := status.FromError(e)
|
||||
if !ok {
|
||||
ctx.Value(tracelog.TraceLogKey).(*tracelog.ApiInfo).GinCtx.JSON(http.StatusOK, &baseResp{ErrCode: constant.ErrDefaultOther.ErrCode, ErrMsg: err.Error(), ErrDtl: fmt.Sprintf("%+v", err)})
|
||||
//ctx.Value(TraceLogKey).(*ApiInfo).GinCtx.JSON(http.StatusOK, gin.H{"errCode": constant.ErrDefaultOther.ErrCode, "errMsg": err.Error(), "errDtl": fmt.Sprintf("%+v", err)})
|
||||
return
|
||||
}
|
||||
var details []string
|
||||
if err != e {
|
||||
details = append(details, fmt.Sprintf("%+v", err))
|
||||
}
|
||||
for _, s := range s.Details() {
|
||||
details = append(details, fmt.Sprintf("%+v", s))
|
||||
}
|
||||
ctx.Value(tracelog.TraceLogKey).(*tracelog.ApiInfo).GinCtx.JSON(http.StatusOK, &baseResp{ErrCode: int32(s.Code()), ErrMsg: s.Message(), ErrDtl: strings.Join(details, "\n")})
|
||||
//ctx.Value(TraceLogKey).(*ApiInfo).GinCtx.JSON(http.StatusOK, gin.H{"errCode": s.Code(), "errMsg": s.Message(), "errDtl": strings.Join(details, "\n")})
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func SetSuccess(ctx context.Context, funcName string, data interface{}) {
|
||||
tracelog.SetCtxInfo(ctx, funcName, nil, "data", data)
|
||||
ctx.Value(tracelog.TraceLogKey).(*tracelog.ApiInfo).GinCtx.JSON(http.StatusOK, gin.H{"errCode": 0, "errMsg": "", "errDtl": "", "data": data})
|
||||
}
|
||||
|
@ -126,95 +126,3 @@ func AdminLogin(c *gin.Context) {
|
||||
resp.Token = respPb.Token
|
||||
c.JSON(http.StatusOK, gin.H{"errCode": respPb.CommonResp.ErrCode, "errMsg": respPb.CommonResp.ErrMsg, "data": resp})
|
||||
}
|
||||
|
||||
func AddUserRegisterAddFriendIDList(c *gin.Context) {
|
||||
var (
|
||||
req apiStruct.AddUserRegisterAddFriendIDListRequest
|
||||
// resp apiStruct.AddUserRegisterAddFriendIDListResponse
|
||||
)
|
||||
if err := c.BindJSON(&req); err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req:", req)
|
||||
etcdConn := getcdv3.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImAdminCMSName, req.OperationID)
|
||||
if etcdConn == nil {
|
||||
errMsg := req.OperationID + "getcdv3.GetConn == nil"
|
||||
log.NewError(req.OperationID, errMsg)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
|
||||
return
|
||||
}
|
||||
client := pbAdmin.NewAdminCMSClient(etcdConn)
|
||||
respPb, err := client.AddUserRegisterAddFriendIDList(context.Background(), &pbAdmin.AddUserRegisterAddFriendIDListReq{OperationID: req.OperationID, UserIDList: req.UserIDList})
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "rpc failed", err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 500, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp:", respPb.String())
|
||||
c.JSON(http.StatusOK, gin.H{"errCode": respPb.CommonResp.ErrCode, "errMsg": respPb.CommonResp.ErrMsg})
|
||||
}
|
||||
|
||||
func ReduceUserRegisterAddFriendIDList(c *gin.Context) {
|
||||
var (
|
||||
req apiStruct.ReduceUserRegisterAddFriendIDListRequest
|
||||
// resp apiStruct.ReduceUserRegisterAddFriendIDListResponse
|
||||
)
|
||||
if err := c.BindJSON(&req); err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), req)
|
||||
etcdConn := getcdv3.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImAdminCMSName, req.OperationID)
|
||||
if etcdConn == nil {
|
||||
errMsg := req.OperationID + "getcdv3.GetConn == nil"
|
||||
log.NewError(req.OperationID, errMsg)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
|
||||
return
|
||||
}
|
||||
client := pbAdmin.NewAdminCMSClient(etcdConn)
|
||||
respPb, err := client.ReduceUserRegisterAddFriendIDList(context.Background(), &pbAdmin.ReduceUserRegisterAddFriendIDListReq{OperationID: req.OperationID, UserIDList: req.UserIDList, Operation: req.Operation})
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "rpc failed", err.Error())
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{"errCode": respPb.CommonResp.ErrCode, "errMsg": respPb.CommonResp.ErrMsg})
|
||||
}
|
||||
|
||||
func GetUserRegisterAddFriendIDList(c *gin.Context) {
|
||||
var (
|
||||
req apiStruct.GetUserRegisterAddFriendIDListRequest
|
||||
resp apiStruct.GetUserRegisterAddFriendIDListResponse
|
||||
)
|
||||
if err := c.BindJSON(&req); err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), req)
|
||||
etcdConn := getcdv3.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImAdminCMSName, req.OperationID)
|
||||
if etcdConn == nil {
|
||||
errMsg := req.OperationID + "getcdv3.GetConn == nil"
|
||||
log.NewError(req.OperationID, errMsg)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
|
||||
return
|
||||
}
|
||||
client := pbAdmin.NewAdminCMSClient(etcdConn)
|
||||
respPb, err := client.GetUserRegisterAddFriendIDList(context.Background(), &pbAdmin.GetUserRegisterAddFriendIDListReq{OperationID: req.OperationID, Pagination: &pbCommon.RequestPagination{
|
||||
PageNumber: int32(req.PageNumber),
|
||||
ShowNumber: int32(req.ShowNumber),
|
||||
}})
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "rpc failed", err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 500, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
resp.Users = respPb.UserInfoList
|
||||
resp.ShowNumber = int(respPb.Pagination.ShowNumber)
|
||||
resp.CurrentPage = int(respPb.Pagination.CurrentPage)
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), resp)
|
||||
c.JSON(http.StatusOK, gin.H{"errCode": respPb.CommonResp.ErrCode, "errMsg": respPb.CommonResp.ErrMsg, "data": resp})
|
||||
}
|
||||
|
@ -17,8 +17,8 @@ import (
|
||||
|
||||
func GetUserFriends(c *gin.Context) {
|
||||
var (
|
||||
req cms_api_struct.GetFriendsReq
|
||||
resp cms_api_struct.GetFriendsResp
|
||||
req cms_struct.GetFriendsReq
|
||||
resp cms_struct.GetFriendsResp
|
||||
reqPb pbAdmin.GetUserFriendsReq
|
||||
)
|
||||
if err := c.BindJSON(&req); err != nil {
|
||||
@ -49,7 +49,7 @@ func GetUserFriends(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
for _, v := range respPb.FriendInfoList {
|
||||
friend := &cms_api_struct.FriendInfo{}
|
||||
friend := &cms_struct.FriendInfo{}
|
||||
utils.CopyStructFields(friend, v)
|
||||
friend.Nickname = v.FriendUser.Nickname
|
||||
friend.UserID = v.FriendUser.UserID
|
||||
|
@ -18,8 +18,8 @@ import (
|
||||
|
||||
func GetGroups(c *gin.Context) {
|
||||
var (
|
||||
req cms_api_struct.GetGroupsRequest
|
||||
resp cms_api_struct.GetGroupsResponse
|
||||
req cms_struct.GetGroupsRequest
|
||||
resp cms_struct.GetGroupsResponse
|
||||
reqPb pbGroup.GetGroupsReq
|
||||
)
|
||||
if err := c.BindJSON(&req); err != nil {
|
||||
@ -48,7 +48,7 @@ func GetGroups(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
for _, v := range respPb.CMSGroups {
|
||||
groupResp := cms_api_struct.GroupResponse{}
|
||||
groupResp := cms_struct.GroupResponse{}
|
||||
utils.CopyStructFields(&groupResp, v.GroupInfo)
|
||||
groupResp.GroupOwnerName = v.GroupOwnerUserName
|
||||
groupResp.GroupOwnerID = v.GroupOwnerUserID
|
||||
@ -63,9 +63,9 @@ func GetGroups(c *gin.Context) {
|
||||
|
||||
func GetGroupMembers(c *gin.Context) {
|
||||
var (
|
||||
req cms_api_struct.GetGroupMembersRequest
|
||||
req cms_struct.GetGroupMembersRequest
|
||||
reqPb pbGroup.GetGroupMembersCMSReq
|
||||
resp cms_api_struct.GetGroupMembersResponse
|
||||
resp cms_struct.GetGroupMembersResponse
|
||||
)
|
||||
if err := c.BindJSON(&req); err != nil {
|
||||
log.NewError(reqPb.OperationID, utils.GetSelfFuncName(), "BindJSON failed ", err.Error())
|
||||
@ -94,13 +94,13 @@ func GetGroupMembers(c *gin.Context) {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
resp.ResponsePagination = cms_api_struct.ResponsePagination{
|
||||
resp.ResponsePagination = cms_struct.ResponsePagination{
|
||||
CurrentPage: int(respPb.Pagination.CurrentPage),
|
||||
ShowNumber: int(respPb.Pagination.ShowNumber),
|
||||
}
|
||||
resp.MemberNums = int(respPb.MemberNums)
|
||||
for _, groupMember := range respPb.Members {
|
||||
memberResp := cms_api_struct.GroupMemberResponse{}
|
||||
memberResp := cms_struct.GroupMemberResponse{}
|
||||
utils.CopyStructFields(&memberResp, groupMember)
|
||||
resp.GroupMembers = append(resp.GroupMembers, memberResp)
|
||||
}
|
||||
|
@ -17,8 +17,8 @@ import (
|
||||
|
||||
func GetChatLogs(c *gin.Context) {
|
||||
var (
|
||||
req cms_api_struct.GetChatLogsReq
|
||||
resp cms_api_struct.GetChatLogsResp
|
||||
req cms_struct.GetChatLogsReq
|
||||
resp cms_struct.GetChatLogsResp
|
||||
reqPb pbAdminCMS.GetChatLogsReq
|
||||
)
|
||||
if err := c.Bind(&req); err != nil {
|
||||
@ -47,7 +47,7 @@ func GetChatLogs(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
for _, v := range respPb.ChatLogs {
|
||||
chatLog := cms_api_struct.ChatLog{}
|
||||
chatLog := cms_struct.ChatLog{}
|
||||
utils.CopyStructFields(&chatLog, v)
|
||||
resp.ChatLogs = append(resp.ChatLogs, &chatLog)
|
||||
}
|
||||
|
@ -1,14 +0,0 @@
|
||||
package cms_api
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/prometheus/client_golang/prometheus/promhttp"
|
||||
)
|
||||
|
||||
func prometheusHandler() gin.HandlerFunc {
|
||||
h := promhttp.Handler()
|
||||
|
||||
return func(c *gin.Context) {
|
||||
h.ServeHTTP(c.Writer, c.Request)
|
||||
}
|
||||
}
|
@ -8,7 +8,6 @@ import (
|
||||
"Open_IM/internal/cms_api/middleware"
|
||||
"Open_IM/internal/cms_api/statistics"
|
||||
"Open_IM/internal/cms_api/user"
|
||||
"Open_IM/internal/demo/register"
|
||||
"Open_IM/pkg/common/config"
|
||||
|
||||
promePkg "Open_IM/pkg/common/prometheus"
|
||||
@ -30,22 +29,6 @@ func NewGinRouter() *gin.Engine {
|
||||
adminRouterGroup.POST("/login", admin.AdminLogin)
|
||||
adminRouterGroup.Use(middleware.JWTAuth())
|
||||
adminRouterGroup.POST("/get_user_token", admin.GetUserToken)
|
||||
|
||||
adminRouterGroup.POST("/add_user_register_add_friend_id", admin.AddUserRegisterAddFriendIDList)
|
||||
adminRouterGroup.POST("/reduce_user_register_reduce_friend_id", admin.ReduceUserRegisterAddFriendIDList)
|
||||
adminRouterGroup.POST("/get_user_register_reduce_friend_id_list", admin.GetUserRegisterAddFriendIDList)
|
||||
|
||||
adminRouterGroup.POST("/generate_invitation_code", register.GenerateInvitationCode)
|
||||
adminRouterGroup.POST("/query_invitation_code", register.QueryInvitationCode)
|
||||
adminRouterGroup.POST("/get_invitation_codes", register.GetInvitationCodes)
|
||||
|
||||
adminRouterGroup.POST("/query_user_ip_limit_login", register.QueryUserIDLimitLogin)
|
||||
adminRouterGroup.POST("/add_user_ip_limit_login", register.AddUserIPLimitLogin)
|
||||
adminRouterGroup.POST("/remove_user_ip_limit_login", register.RemoveUserIPLimitLogin)
|
||||
|
||||
adminRouterGroup.POST("/query_ip_register", register.QueryIPRegister)
|
||||
adminRouterGroup.POST("/add_ip_limit", register.AddIPLimit)
|
||||
adminRouterGroup.POST("/remove_ip_Limit", register.RemoveIPLimit)
|
||||
}
|
||||
r2 := router.Group("")
|
||||
r2.Use(middleware.JWTAuth())
|
||||
|
@ -17,8 +17,8 @@ import (
|
||||
|
||||
func GetMessagesStatistics(c *gin.Context) {
|
||||
var (
|
||||
req cms_api_struct.GetMessageStatisticsRequest
|
||||
resp cms_api_struct.GetMessageStatisticsResponse
|
||||
req cms_struct.GetMessageStatisticsRequest
|
||||
resp cms_struct.GetMessageStatisticsResponse
|
||||
reqPb admin.GetMessageStatisticsReq
|
||||
)
|
||||
reqPb.StatisticsReq = &admin.StatisticsReq{}
|
||||
@ -73,8 +73,8 @@ func GetMessagesStatistics(c *gin.Context) {
|
||||
|
||||
func GetUserStatistics(c *gin.Context) {
|
||||
var (
|
||||
req cms_api_struct.GetUserStatisticsRequest
|
||||
resp cms_api_struct.GetUserStatisticsResponse
|
||||
req cms_struct.GetUserStatisticsRequest
|
||||
resp cms_struct.GetUserStatisticsResponse
|
||||
reqPb admin.GetUserStatisticsReq
|
||||
)
|
||||
reqPb.StatisticsReq = &admin.StatisticsReq{}
|
||||
@ -138,8 +138,8 @@ func GetUserStatistics(c *gin.Context) {
|
||||
|
||||
func GetGroupStatistics(c *gin.Context) {
|
||||
var (
|
||||
req cms_api_struct.GetGroupStatisticsRequest
|
||||
resp cms_api_struct.GetGroupStatisticsResponse
|
||||
req cms_struct.GetGroupStatisticsRequest
|
||||
resp cms_struct.GetGroupStatisticsResponse
|
||||
reqPb admin.GetGroupStatisticsReq
|
||||
)
|
||||
reqPb.StatisticsReq = &admin.StatisticsReq{}
|
||||
@ -197,8 +197,8 @@ func GetGroupStatistics(c *gin.Context) {
|
||||
|
||||
func GetActiveUser(c *gin.Context) {
|
||||
var (
|
||||
req cms_api_struct.GetActiveUserRequest
|
||||
resp cms_api_struct.GetActiveUserResponse
|
||||
req cms_struct.GetActiveUserRequest
|
||||
resp cms_struct.GetActiveUserResponse
|
||||
reqPb admin.GetActiveUserReq
|
||||
)
|
||||
reqPb.StatisticsReq = &admin.StatisticsReq{}
|
||||
@ -233,8 +233,8 @@ func GetActiveUser(c *gin.Context) {
|
||||
|
||||
func GetActiveGroup(c *gin.Context) {
|
||||
var (
|
||||
req cms_api_struct.GetActiveGroupRequest
|
||||
resp cms_api_struct.GetActiveGroupResponse
|
||||
req cms_struct.GetActiveGroupRequest
|
||||
resp cms_struct.GetActiveGroupResponse
|
||||
reqPb admin.GetActiveGroupReq
|
||||
)
|
||||
reqPb.StatisticsReq = &admin.StatisticsReq{}
|
||||
|
@ -18,7 +18,7 @@ import (
|
||||
|
||||
func AddUser(c *gin.Context) {
|
||||
var (
|
||||
req cms_api_struct.AddUserRequest
|
||||
req cms_struct.AddUserRequest
|
||||
reqPb pb.AddUserReq
|
||||
)
|
||||
if err := c.BindJSON(&req); err != nil {
|
||||
@ -48,7 +48,7 @@ func AddUser(c *gin.Context) {
|
||||
|
||||
func BlockUser(c *gin.Context) {
|
||||
var (
|
||||
req cms_api_struct.BlockUserRequest
|
||||
req cms_struct.BlockUserRequest
|
||||
reqPb pb.BlockUserReq
|
||||
)
|
||||
if err := c.BindJSON(&req); err != nil {
|
||||
@ -78,8 +78,8 @@ func BlockUser(c *gin.Context) {
|
||||
|
||||
func UnblockUser(c *gin.Context) {
|
||||
var (
|
||||
req cms_api_struct.UnblockUserRequest
|
||||
resp cms_api_struct.UnBlockUserResponse
|
||||
req cms_struct.UnblockUserRequest
|
||||
resp cms_struct.UnBlockUserResponse
|
||||
reqPb pb.UnBlockUserReq
|
||||
)
|
||||
if err := c.BindJSON(&req); err != nil {
|
||||
@ -110,8 +110,8 @@ func UnblockUser(c *gin.Context) {
|
||||
|
||||
func GetBlockUsers(c *gin.Context) {
|
||||
var (
|
||||
req cms_api_struct.GetBlockUsersRequest
|
||||
resp cms_api_struct.GetBlockUsersResponse
|
||||
req cms_struct.GetBlockUsersRequest
|
||||
resp cms_struct.GetBlockUsersResponse
|
||||
reqPb pb.GetBlockUsersReq
|
||||
respPb *pb.GetBlockUsersResp
|
||||
)
|
||||
@ -140,8 +140,8 @@ func GetBlockUsers(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
for _, v := range respPb.BlockUsers {
|
||||
resp.BlockUsers = append(resp.BlockUsers, cms_api_struct.BlockUser{
|
||||
UserResponse: cms_api_struct.UserResponse{
|
||||
resp.BlockUsers = append(resp.BlockUsers, cms_struct.BlockUser{
|
||||
UserResponse: cms_struct.UserResponse{
|
||||
UserID: v.UserInfo.UserID,
|
||||
FaceURL: v.UserInfo.FaceURL,
|
||||
Nickname: v.UserInfo.Nickname,
|
||||
@ -162,8 +162,8 @@ func GetBlockUsers(c *gin.Context) {
|
||||
|
||||
func GetUserIDByEmailAndPhoneNumber(c *gin.Context) {
|
||||
var (
|
||||
req cms_api_struct.GetUserIDByEmailAndPhoneNumberRequest
|
||||
resp cms_api_struct.GetUserIDByEmailAndPhoneNumberResponse
|
||||
req cms_struct.GetUserIDByEmailAndPhoneNumberRequest
|
||||
resp cms_struct.GetUserIDByEmailAndPhoneNumberResponse
|
||||
reqPb pbAdminCms.GetUserIDByEmailAndPhoneNumberReq
|
||||
respPb *pbAdminCms.GetUserIDByEmailAndPhoneNumberResp
|
||||
)
|
||||
|
@ -44,13 +44,16 @@ func StartCronTask(userID, workingGroupID string) {
|
||||
}
|
||||
}
|
||||
|
||||
type CronTask struct {
|
||||
}
|
||||
|
||||
func getCronTaskOperationID() string {
|
||||
return cronTaskOperationID + utils.OperationIDGenerator()
|
||||
}
|
||||
|
||||
func ClearAll() {
|
||||
operationID := getCronTaskOperationID()
|
||||
log.NewInfo(operationID, "====================== start del cron task ======================")
|
||||
log.NewInfo(operationID, "========================= start del cron task =========================")
|
||||
var err error
|
||||
userIDList, err := im_mysql_model.SelectAllUserID()
|
||||
if err == nil {
|
||||
@ -67,7 +70,7 @@ func ClearAll() {
|
||||
log.NewError(operationID, utils.GetSelfFuncName(), err.Error())
|
||||
}
|
||||
|
||||
log.NewInfo(operationID, "====================== start del cron finished ======================")
|
||||
log.NewInfo(operationID, "========================= start del cron finished =========================")
|
||||
}
|
||||
|
||||
func StartClearMsg(operationID string, userIDList []string) {
|
||||
|
@ -1,7 +1,7 @@
|
||||
package register
|
||||
|
||||
import (
|
||||
api "Open_IM/pkg/base_info"
|
||||
api "Open_IM/pkg/api_struct"
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/db/mysql_model/im_mysql_model"
|
||||
|
@ -1,7 +1,7 @@
|
||||
package register
|
||||
|
||||
import (
|
||||
api "Open_IM/pkg/base_info"
|
||||
api "Open_IM/pkg/api_struct"
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/db"
|
||||
|
@ -1,7 +1,7 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/base_info"
|
||||
"Open_IM/pkg/api_struct"
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/db"
|
||||
@ -61,7 +61,7 @@ func (mmc *ModifyMsgConsumerHandler) ModifyMsg(cMsg *sarama.ConsumerMessage, msg
|
||||
continue
|
||||
}
|
||||
if msgDataToMQ.MsgData.ContentType == constant.ReactionMessageModifier {
|
||||
notification := &base_info.ReactionMessageModifierNotification{}
|
||||
notification := &api_struct.ReactionMessageModifierNotification{}
|
||||
if err := json.Unmarshal(msgDataToMQ.MsgData.Content, notification); err != nil {
|
||||
continue
|
||||
}
|
||||
@ -104,7 +104,7 @@ func (mmc *ModifyMsgConsumerHandler) ModifyMsg(cMsg *sarama.ConsumerMessage, msg
|
||||
}
|
||||
}
|
||||
} else if msgDataToMQ.MsgData.ContentType == constant.ReactionMessageDeleter {
|
||||
notification := &base_info.ReactionMessageDeleteNotification{}
|
||||
notification := &api_struct.ReactionMessageDeleteNotification{}
|
||||
if err := json.Unmarshal(msgDataToMQ.MsgData.Content, notification); err != nil {
|
||||
continue
|
||||
}
|
||||
@ -116,7 +116,7 @@ func (mmc *ModifyMsgConsumerHandler) ModifyMsg(cMsg *sarama.ConsumerMessage, msg
|
||||
|
||||
}
|
||||
|
||||
func UnMarshallSetReactionMsgContent(content []byte) (notification *base_info.ReactionMessageModifierNotification, err error) {
|
||||
func UnMarshallSetReactionMsgContent(content []byte) (notification *api_struct.ReactionMessageModifierNotification, err error) {
|
||||
|
||||
return notification, nil
|
||||
}
|
||||
|
@ -8,7 +8,6 @@ package logic
|
||||
|
||||
import (
|
||||
"Open_IM/internal/push"
|
||||
utils2 "Open_IM/internal/utils"
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/db"
|
||||
@ -172,7 +171,7 @@ func MsgToSuperGroupUser(pushMsg *pbPush.PushMsgReq) {
|
||||
log.NewDebug(pushMsg.OperationID, utils.GetSelfFuncName(), "callback userIDList Resp", pushToUserIDList)
|
||||
}
|
||||
if len(pushToUserIDList) == 0 {
|
||||
userIDList, err := utils2.GetGroupMemberUserIDList(context.Background(), pushMsg.MsgData.GroupID, pushMsg.OperationID)
|
||||
userIDList, err := utils.GetGroupMemberUserIDList(context.Background(), pushMsg.MsgData.GroupID, pushMsg.OperationID)
|
||||
if err != nil {
|
||||
log.Error(pushMsg.OperationID, "GetGroupMemberUserIDList failed ", err.Error(), pushMsg.MsgData.GroupID)
|
||||
return
|
||||
|
@ -4,13 +4,10 @@ import (
|
||||
chat "Open_IM/internal/rpc/msg"
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/db/model"
|
||||
"Open_IM/pkg/common/db/mysql"
|
||||
"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"
|
||||
"Open_IM/pkg/common/tracelog"
|
||||
"Open_IM/pkg/getcdv3"
|
||||
pbFriend "Open_IM/pkg/proto/friend"
|
||||
@ -114,7 +111,7 @@ func (s *friendServer) AddBlacklist(ctx context.Context, req *pbFriend.AddBlackl
|
||||
if err := token_verify.CheckAccessV3(ctx, req.FromUserID); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
black := relation.Black{OwnerUserID: req.FromUserID, BlockUserID: req.ToUserID, OperatorUserID: tools.OpUserID(ctx)}
|
||||
black := relation.Black{OwnerUserID: req.FromUserID, BlockUserID: req.ToUserID, OperatorUserID: utils.OpUserID(ctx)}
|
||||
if err := s.blackModel.Create(ctx, []*relation.Black{&black}); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -222,7 +219,7 @@ func (s *friendServer) AddFriendResponse(ctx context.Context, req *pbFriend.AddF
|
||||
friendRequest.HandleResult = req.HandleResult
|
||||
friendRequest.HandleTime = time.Now()
|
||||
friendRequest.HandleMsg = req.HandleMsg
|
||||
friendRequest.HandlerUserID = tools.OpUserID(ctx)
|
||||
friendRequest.HandlerUserID = utils.OpUserID(ctx)
|
||||
err = relation.UpdateFriendApplication(friendRequest)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -233,10 +230,10 @@ func (s *friendServer) AddFriendResponse(ctx context.Context, req *pbFriend.AddF
|
||||
//Establish friendship after find friend relationship not exists
|
||||
_, err := s.friendModel.Take(ctx, req.FromUserID, req.ToUserID)
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
if err := s.friendModel.Create(ctx, []*relation.Friend{{OwnerUserID: req.FromUserID, FriendUserID: req.ToUserID, OperatorUserID: tools.OpUserID(ctx)}}); err != nil {
|
||||
if err := s.friendModel.Create(ctx, []*relation.Friend{{OwnerUserID: req.FromUserID, FriendUserID: req.ToUserID, OperatorUserID: utils.OpUserID(ctx)}}); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
chat.FriendAddedNotification(tools.OperationID(ctx), tools.OpUserID(ctx), req.FromUserID, req.ToUserID)
|
||||
chat.FriendAddedNotification(utils.OperationID(ctx), utils.OpUserID(ctx), req.FromUserID, req.ToUserID)
|
||||
} else if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -292,7 +289,7 @@ func (s *friendServer) SetFriendRemark(ctx context.Context, req *pbFriend.SetFri
|
||||
if err := s.friendModel.UpdateRemark(ctx, req.FromUserID, req.ToUserID, req.Remark); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
chat.FriendRemarkSetNotification(tools.OperationID(ctx), tools.OpUserID(ctx), req.FromUserID, req.ToUserID)
|
||||
chat.FriendRemarkSetNotification(utils.OperationID(ctx), utils.OpUserID(ctx), req.FromUserID, req.ToUserID)
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
|
@ -3,7 +3,6 @@ package group
|
||||
import (
|
||||
"Open_IM/pkg/common/constant"
|
||||
relation "Open_IM/pkg/common/db/mysql"
|
||||
"Open_IM/pkg/common/tools"
|
||||
pbGroup "Open_IM/pkg/proto/group"
|
||||
sdk_ws "Open_IM/pkg/proto/sdk_ws"
|
||||
"Open_IM/pkg/utils"
|
||||
@ -17,7 +16,7 @@ func getDBGroupRequest(ctx context.Context, req *pbGroup.GroupApplicationRespons
|
||||
dbGroupRequest = &relation.GroupRequest{}
|
||||
utils.CopyStructFields(&dbGroupRequest, req)
|
||||
dbGroupRequest.UserID = req.FromUserID
|
||||
dbGroupRequest.HandleUserID = tools.OpUserID(ctx)
|
||||
dbGroupRequest.HandleUserID = utils.OpUserID(ctx)
|
||||
dbGroupRequest.HandledTime = time.Now()
|
||||
return dbGroupRequest
|
||||
}
|
||||
@ -29,7 +28,7 @@ func getDBGroupMember(ctx context.Context, groupID, userID string) (dbGroupMembe
|
||||
member.GroupID = groupID
|
||||
member.UserID = userID
|
||||
member.RoleLevel = constant.GroupOrdinaryUsers
|
||||
member.OperatorUserID = tools.OpUserID(ctx)
|
||||
member.OperatorUserID = utils.OpUserID(ctx)
|
||||
|
||||
member.FaceURL = user.FaceURL
|
||||
member.Nickname = user.Nickname
|
||||
@ -60,7 +59,7 @@ func genGroupID(ctx context.Context, groupID string) string {
|
||||
if groupID != "" {
|
||||
return groupID
|
||||
}
|
||||
groupID = utils.Md5(tools.OperationID(ctx) + strconv.FormatInt(time.Now().UnixNano(), 10))
|
||||
groupID = utils.Md5(utils.OperationID(ctx) + strconv.FormatInt(time.Now().UnixNano(), 10))
|
||||
bi := big.NewInt(0)
|
||||
bi.SetString(groupID[0:8], 16)
|
||||
groupID = bi.String()
|
||||
|
@ -13,7 +13,6 @@ import (
|
||||
"Open_IM/pkg/common/middleware"
|
||||
promePkg "Open_IM/pkg/common/prometheus"
|
||||
"Open_IM/pkg/common/token_verify"
|
||||
"Open_IM/pkg/common/tools"
|
||||
"Open_IM/pkg/common/tracelog"
|
||||
|
||||
cp "Open_IM/internal/utils"
|
||||
@ -180,12 +179,12 @@ func (s *groupServer) CreateGroup(ctx context.Context, req *pbGroup.CreateGroupR
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
opUserID := tools.OpUserID(ctx)
|
||||
opUserID := utils.OpUserID(ctx)
|
||||
joinGroup := func(userID string, roleLevel int32) error {
|
||||
user := userMap[userID]
|
||||
groupMember := &relation.GroupMember{GroupID: group.GroupID, RoleLevel: roleLevel, OperatorUserID: opUserID, JoinSource: constant.JoinByInvitation, InviterUserID: opUserID}
|
||||
utils.CopyStructFields(&groupMember, user)
|
||||
if err := CallbackBeforeMemberJoinGroup(ctx, tools.OperationID(ctx), groupMember, group.Ex); err != nil {
|
||||
if err := CallbackBeforeMemberJoinGroup(ctx, utils.OperationID(ctx), groupMember, group.Ex); err != nil {
|
||||
return err
|
||||
}
|
||||
groupMembers = append(groupMembers, groupMember)
|
||||
@ -213,11 +212,11 @@ func (s *groupServer) CreateGroup(ctx context.Context, req *pbGroup.CreateGroupR
|
||||
if req.GroupInfo.GroupType == constant.SuperGroup {
|
||||
go func() {
|
||||
for _, userID := range userIDs {
|
||||
chat.SuperGroupNotification(tools.OperationID(ctx), userID, userID)
|
||||
chat.SuperGroupNotification(utils.OperationID(ctx), userID, userID)
|
||||
}
|
||||
}()
|
||||
} else {
|
||||
chat.GroupCreatedNotification(tools.OperationID(ctx), tools.OpUserID(ctx), group.GroupID, userIDs)
|
||||
chat.GroupCreatedNotification(utils.OperationID(ctx), utils.OpUserID(ctx), group.GroupID, userIDs)
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
@ -301,7 +300,7 @@ func (s *groupServer) InviteUserToGroup(ctx context.Context, req *pbGroup.Invite
|
||||
}
|
||||
if group.NeedVerification == constant.AllNeedVerification {
|
||||
if !token_verify.IsAppManagerUid(ctx) {
|
||||
opUserID := tools.OpUserID(ctx)
|
||||
opUserID := utils.OpUserID(ctx)
|
||||
member, ok := memberMap[opUserID]
|
||||
if ok {
|
||||
return nil, constant.ErrNoPermission.Wrap("not in group")
|
||||
@ -336,7 +335,7 @@ func (s *groupServer) InviteUserToGroup(ctx context.Context, req *pbGroup.Invite
|
||||
return nil, err
|
||||
}
|
||||
for _, userID := range req.InvitedUserIDList {
|
||||
chat.SuperGroupNotification(tools.OperationID(ctx), userID, userID)
|
||||
chat.SuperGroupNotification(utils.OperationID(ctx), userID, userID)
|
||||
}
|
||||
} else {
|
||||
var groupMembers []*relation.GroupMember
|
||||
@ -346,10 +345,10 @@ func (s *groupServer) InviteUserToGroup(ctx context.Context, req *pbGroup.Invite
|
||||
utils.CopyStructFields(&member, user)
|
||||
member.GroupID = req.GroupID
|
||||
member.RoleLevel = constant.GroupOrdinaryUsers
|
||||
member.OperatorUserID = tools.OpUserID(ctx)
|
||||
member.InviterUserID = tools.OpUserID(ctx)
|
||||
member.OperatorUserID = utils.OpUserID(ctx)
|
||||
member.InviterUserID = utils.OpUserID(ctx)
|
||||
member.JoinSource = constant.JoinByInvitation
|
||||
if err := CallbackBeforeMemberJoinGroup(ctx, tools.OperationID(ctx), &member, group.Ex); err != nil {
|
||||
if err := CallbackBeforeMemberJoinGroup(ctx, utils.OperationID(ctx), &member, group.Ex); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
groupMembers = append(groupMembers, &member)
|
||||
@ -357,7 +356,7 @@ func (s *groupServer) InviteUserToGroup(ctx context.Context, req *pbGroup.Invite
|
||||
if err := s.GroupInterface.CreateGroupMember(ctx, groupMembers); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
chat.MemberInvitedNotification(tools.OperationID(ctx), req.GroupID, tools.OpUserID(ctx), req.Reason, req.InvitedUserIDList)
|
||||
chat.MemberInvitedNotification(utils.OperationID(ctx), req.GroupID, utils.OpUserID(ctx), req.Reason, req.InvitedUserIDList)
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
@ -436,8 +435,8 @@ func (s *groupServer) KickGroupMember(ctx context.Context, req *pbGroup.KickGrou
|
||||
var okUserIDList []string
|
||||
if groupInfo.GroupType != constant.SuperGroup {
|
||||
opFlag := 0
|
||||
if !token_verify.IsManagerUserID(tools.OpUserID(ctx)) {
|
||||
opInfo, err := rocksCache.GetGroupMemberInfoFromCache(ctx, req.GroupID, tools.OpUserID(ctx))
|
||||
if !token_verify.IsManagerUserID(utils.OpUserID(ctx)) {
|
||||
opInfo, err := rocksCache.GetGroupMemberInfoFromCache(ctx, req.GroupID, utils.OpUserID(ctx))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -484,7 +483,7 @@ func (s *groupServer) KickGroupMember(ctx context.Context, req *pbGroup.KickGrou
|
||||
err = relation.DeleteGroupMemberByGroupIDAndUserID(req.GroupID, v)
|
||||
tracelog.SetCtxInfo(ctx, "RemoveGroupMember", err, "groupID", req.GroupID, "userID", v)
|
||||
if err != nil {
|
||||
log.NewError(tools.OperationID(ctx), "RemoveGroupMember failed ", err.Error(), req.GroupID, v)
|
||||
log.NewError(utils.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})
|
||||
@ -494,7 +493,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 = tools.OperationID(ctx)
|
||||
reqPb.OperationID = utils.OperationID(ctx)
|
||||
c.OwnerUserID = v
|
||||
c.ConversationID = utils.GetConversationIDBySessionType(req.GroupID, constant.GroupChatType)
|
||||
c.ConversationType = constant.GroupChatType
|
||||
@ -531,7 +530,7 @@ func (s *groupServer) KickGroupMember(ctx context.Context, req *pbGroup.KickGrou
|
||||
}
|
||||
go func() {
|
||||
for _, v := range req.KickedUserIDList {
|
||||
chat.SuperGroupNotification(tools.OperationID(ctx), v, v)
|
||||
chat.SuperGroupNotification(utils.OperationID(ctx), v, v)
|
||||
}
|
||||
}()
|
||||
|
||||
@ -587,7 +586,7 @@ func (s *groupServer) GetGroupApplicationList(ctx context.Context, req *pbGroup.
|
||||
tracelog.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(tools.OperationID(ctx), v.GroupID, node.GroupInfo)
|
||||
err := FillGroupInfoByGroupID(utils.OperationID(ctx), v.GroupID, node.GroupInfo)
|
||||
if err != nil {
|
||||
if !errors.Is(errors.Unwrap(err), constant.ErrDismissedAlready) {
|
||||
errResult = err
|
||||
@ -595,7 +594,7 @@ func (s *groupServer) GetGroupApplicationList(ctx context.Context, req *pbGroup.
|
||||
continue
|
||||
}
|
||||
tracelog.SetCtxInfo(ctx, "FillGroupInfoByGroupID ", nil, " groupID: ", v.GroupID, " groupInfo: ", node.GroupInfo)
|
||||
err = FillPublicUserInfoByUserID(tools.OperationID(ctx), v.UserID, node.UserInfo)
|
||||
err = FillPublicUserInfoByUserID(utils.OperationID(ctx), v.UserID, node.UserInfo)
|
||||
if err != nil {
|
||||
errResult = err
|
||||
continue
|
||||
@ -640,7 +639,7 @@ 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, tools.OpUserID(ctx)); err != nil {
|
||||
if err := CheckPermission(ctx, req.GroupID, utils.OpUserID(ctx)); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
groupRequest := getDBGroupRequest(ctx, req)
|
||||
@ -656,7 +655,7 @@ func (s *groupServer) GroupApplicationResponse(ctx context.Context, req *pbGroup
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = CallbackBeforeMemberJoinGroup(ctx, tools.OperationID(ctx), member, groupInfo.Ex)
|
||||
err = CallbackBeforeMemberJoinGroup(ctx, utils.OperationID(ctx), member, groupInfo.Ex)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -664,12 +663,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, tools.OperationID(ctx))
|
||||
etcdCacheConn, err := fault_tolerant.GetDefaultConn(config.Config.RpcRegisterName.OpenImCacheName, utils.OperationID(ctx))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
cacheClient := pbCache.NewCacheClient(etcdCacheConn)
|
||||
cacheResp, err := cacheClient.DelGroupMemberIDListFromCache(context.Background(), &pbCache.DelGroupMemberIDListFromCacheReq{OperationID: tools.OperationID(ctx), GroupID: req.GroupID})
|
||||
cacheResp, err := cacheClient.DelGroupMemberIDListFromCache(context.Background(), &pbCache.DelGroupMemberIDListFromCacheReq{OperationID: utils.OperationID(ctx), GroupID: req.GroupID})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -696,7 +695,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 := relation.GetUserByUserID(tools.OpUserID(ctx)); err != nil {
|
||||
if _, err := relation.GetUserByUserID(utils.OpUserID(ctx)); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
groupInfo, err := rocksCache.GetGroupInfoFromCache(ctx, req.GroupID)
|
||||
@ -709,17 +708,17 @@ func (s *groupServer) JoinGroup(ctx context.Context, req *pbGroup.JoinGroupReq)
|
||||
|
||||
if groupInfo.NeedVerification == constant.Directly {
|
||||
if groupInfo.GroupType != constant.SuperGroup {
|
||||
us, err := relation.GetUserByUserID(tools.OpUserID(ctx))
|
||||
us, err := relation.GetUserByUserID(utils.OpUserID(ctx))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
//to group member
|
||||
groupMember := relation.GroupMember{GroupID: req.GroupID, RoleLevel: constant.GroupOrdinaryUsers, OperatorUserID: tools.OpUserID(ctx)}
|
||||
groupMember := relation.GroupMember{GroupID: req.GroupID, RoleLevel: constant.GroupOrdinaryUsers, OperatorUserID: utils.OpUserID(ctx)}
|
||||
utils.CopyStructFields(&groupMember, us)
|
||||
if err := CallbackBeforeMemberJoinGroup(ctx, tools.OperationID(ctx), &groupMember, groupInfo.Ex); err != nil {
|
||||
if err := CallbackBeforeMemberJoinGroup(ctx, utils.OperationID(ctx), &groupMember, groupInfo.Ex); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := s.DelGroupAndUserCache(ctx, req.GroupID, []string{tools.OpUserID(ctx)}); err != nil {
|
||||
if err := s.DelGroupAndUserCache(ctx, req.GroupID, []string{utils.OpUserID(ctx)}); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = relation.InsertIntoGroupMember(groupMember)
|
||||
@ -735,8 +734,8 @@ func (s *groupServer) JoinGroup(ctx context.Context, req *pbGroup.JoinGroupReq)
|
||||
}
|
||||
var reqPb pbUser.SetConversationReq
|
||||
var c pbConversation.Conversation
|
||||
reqPb.OperationID = tools.OperationID(ctx)
|
||||
c.OwnerUserID = tools.OpUserID(ctx)
|
||||
reqPb.OperationID = utils.OperationID(ctx)
|
||||
c.OwnerUserID = utils.OpUserID(ctx)
|
||||
c.ConversationID = utils.GetConversationIDBySessionType(req.GroupID, sessionType)
|
||||
c.ConversationType = int32(sessionType)
|
||||
c.GroupID = req.GroupID
|
||||
@ -750,7 +749,7 @@ func (s *groupServer) JoinGroup(ctx context.Context, req *pbGroup.JoinGroupReq)
|
||||
client := pbUser.NewUserClient(etcdConn)
|
||||
respPb, err := client.SetConversation(context.Background(), &reqPb)
|
||||
tracelog.SetCtxInfo(ctx, "SetConversation", err, "req", reqPb, "resp", respPb)
|
||||
chat.MemberEnterDirectlyNotification(req.GroupID, tools.OpUserID(ctx), tools.OperationID(ctx))
|
||||
chat.MemberEnterDirectlyNotification(req.GroupID, utils.OpUserID(ctx), utils.OperationID(ctx))
|
||||
return resp, nil
|
||||
} else {
|
||||
constant.SetErrorForResp(constant.ErrGroupTypeNotSupport, resp.CommonResp)
|
||||
@ -758,7 +757,7 @@ func (s *groupServer) JoinGroup(ctx context.Context, req *pbGroup.JoinGroupReq)
|
||||
}
|
||||
}
|
||||
var groupRequest relation.GroupRequest
|
||||
groupRequest.UserID = tools.OpUserID(ctx)
|
||||
groupRequest.UserID = utils.OpUserID(ctx)
|
||||
groupRequest.ReqMsg = req.ReqMessage
|
||||
groupRequest.GroupID = req.GroupID
|
||||
groupRequest.JoinSource = req.JoinSource
|
||||
@ -778,31 +777,31 @@ func (s *groupServer) QuitGroup(ctx context.Context, req *pbGroup.QuitGroupReq)
|
||||
return nil, err
|
||||
}
|
||||
if groupInfo.GroupType != constant.SuperGroup {
|
||||
_, err = rocksCache.GetGroupMemberInfoFromCache(ctx, req.GroupID, tools.OpUserID(ctx))
|
||||
_, err = rocksCache.GetGroupMemberInfoFromCache(ctx, req.GroupID, utils.OpUserID(ctx))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := s.DelGroupAndUserCache(ctx, req.GroupID, []string{tools.OpUserID(ctx)}); err != nil {
|
||||
if err := s.DelGroupAndUserCache(ctx, req.GroupID, []string{utils.OpUserID(ctx)}); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = relation.DeleteGroupMemberByGroupIDAndUserID(req.GroupID, tools.OpUserID(ctx))
|
||||
err = relation.DeleteGroupMemberByGroupIDAndUserID(req.GroupID, utils.OpUserID(ctx))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
okUserIDList := []string{tools.OpUserID(ctx)}
|
||||
okUserIDList := []string{utils.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, tools.OpUserID(ctx))
|
||||
_ = rocksCache.DelGroupMemberInfoFromCache(ctx, req.GroupID, utils.OpUserID(ctx))
|
||||
chat.MemberQuitNotification(req)
|
||||
} else {
|
||||
_ = rocksCache.DelJoinedSuperGroupIDListFromCache(ctx, tools.OpUserID(ctx))
|
||||
_ = rocksCache.DelJoinedSuperGroupIDListFromCache(ctx, utils.OpUserID(ctx))
|
||||
_ = rocksCache.DelGroupMemberListHashFromCache(ctx, req.GroupID)
|
||||
chat.SuperGroupNotification(tools.OperationID(ctx), tools.OpUserID(ctx), tools.OpUserID(ctx))
|
||||
chat.SuperGroupNotification(utils.OperationID(ctx), utils.OpUserID(ctx), utils.OpUserID(ctx))
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
@ -871,7 +870,7 @@ func (s *groupServer) SetGroupInfo(ctx context.Context, req *pbGroup.SetGroupInf
|
||||
var groupInfo relation.Group
|
||||
utils.CopyStructFields(&groupInfo, req.GroupInfoForSet)
|
||||
if req.GroupInfoForSet.Notification != "" {
|
||||
groupInfo.NotificationUserID = tools.OpUserID(ctx)
|
||||
groupInfo.NotificationUserID = utils.OpUserID(ctx)
|
||||
groupInfo.NotificationUpdateTime = time.Now()
|
||||
}
|
||||
if err := rocksCache.DelGroupInfoFromCache(ctx, req.GroupInfoForSet.GroupID); err != nil {
|
||||
@ -882,11 +881,11 @@ func (s *groupServer) SetGroupInfo(ctx context.Context, req *pbGroup.SetGroupInf
|
||||
return nil, err
|
||||
}
|
||||
if changedType != 0 {
|
||||
chat.GroupInfoSetNotification(tools.OperationID(ctx), tools.OpUserID(ctx), req.GroupInfoForSet.GroupID, groupName, notification, introduction, faceURL, req.GroupInfoForSet.NeedVerification)
|
||||
chat.GroupInfoSetNotification(utils.OperationID(ctx), utils.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: tools.OperationID(ctx), GroupID: req.GroupInfoForSet.GroupID}
|
||||
getGroupMemberIDListFromCacheReq := &pbCache.GetGroupMemberIDListFromCacheReq{OperationID: utils.OperationID(ctx), GroupID: req.GroupInfoForSet.GroupID}
|
||||
etcdConn, err := getcdv3.GetConn(ctx, config.Config.RpcRegisterName.OpenImCacheName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -901,13 +900,13 @@ func (s *groupServer) SetGroupInfo(ctx context.Context, req *pbGroup.SetGroupInf
|
||||
}
|
||||
var conversationReq pbConversation.ModifyConversationFieldReq
|
||||
conversation := pbConversation.Conversation{
|
||||
OwnerUserID: tools.OpUserID(ctx),
|
||||
OwnerUserID: utils.OpUserID(ctx),
|
||||
ConversationID: utils.GetConversationIDBySessionType(req.GroupInfoForSet.GroupID, constant.GroupChatType),
|
||||
ConversationType: constant.GroupChatType,
|
||||
GroupID: req.GroupInfoForSet.GroupID,
|
||||
}
|
||||
conversationReq.Conversation = &conversation
|
||||
conversationReq.OperationID = tools.OperationID(ctx)
|
||||
conversationReq.OperationID = utils.OperationID(ctx)
|
||||
conversationReq.FieldType = constant.FieldGroupAtType
|
||||
conversation.GroupAtType = constant.GroupNotification
|
||||
conversationReq.UserIDList = cacheResp.UserIDList
|
||||
@ -1020,7 +1019,7 @@ func (s *groupServer) GetGroupMembersCMS(ctx context.Context, req *pbGroup.GetGr
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
log.NewInfo(tools.OperationID(ctx), groupMembersCount)
|
||||
log.NewInfo(utils.OperationID(ctx), groupMembersCount)
|
||||
resp.MemberNums = int32(groupMembersCount)
|
||||
for _, groupMember := range groupMembers {
|
||||
member := open_im_sdk.GroupMemberFullInfo{}
|
||||
@ -1065,7 +1064,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(tools.OpUserID(ctx)) && !relation.IsGroupOwnerAdmin(req.GroupID, tools.OpUserID(ctx)) {
|
||||
if !token_verify.IsManagerUserID(utils.OpUserID(ctx)) && !relation.IsGroupOwnerAdmin(req.GroupID, utils.OpUserID(ctx)) {
|
||||
return nil, utils.Wrap(constant.ErrIdentity, "")
|
||||
}
|
||||
|
||||
@ -1093,7 +1092,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 = tools.OperationID(ctx)
|
||||
reqPb.OperationID = utils.OperationID(ctx)
|
||||
c.OwnerUserID = v.UserID
|
||||
c.ConversationID = utils.GetConversationIDBySessionType(req.GroupID, constant.GroupChatType)
|
||||
c.ConversationType = constant.GroupChatType
|
||||
@ -1122,7 +1121,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, tools.OpUserID(ctx))
|
||||
opFlag, err := s.getGroupUserLevel(req.GroupID, utils.OpUserID(ctx))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -1150,14 +1149,14 @@ func (s *groupServer) MuteGroupMember(ctx context.Context, req *pbGroup.MuteGrou
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
chat.GroupMemberMutedNotification(tools.OperationID(ctx), tools.OpUserID(ctx), req.GroupID, req.UserID, req.MutedSeconds)
|
||||
chat.GroupMemberMutedNotification(utils.OperationID(ctx), utils.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, tools.OpUserID(ctx))
|
||||
opFlag, err := s.getGroupUserLevel(req.GroupID, utils.OpUserID(ctx))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -1185,14 +1184,14 @@ func (s *groupServer) CancelMuteGroupMember(ctx context.Context, req *pbGroup.Ca
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
chat.GroupMemberCancelMutedNotification(tools.OperationID(ctx), tools.OpUserID(ctx), req.GroupID, req.UserID)
|
||||
chat.GroupMemberCancelMutedNotification(utils.OperationID(ctx), utils.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, tools.OpUserID(ctx))
|
||||
opFlag, err := s.getGroupUserLevel(req.GroupID, utils.OpUserID(ctx))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -1225,14 +1224,14 @@ func (s *groupServer) MuteGroup(ctx context.Context, req *pbGroup.MuteGroupReq)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
chat.GroupMutedNotification(tools.OperationID(ctx), tools.OpUserID(ctx), req.GroupID)
|
||||
chat.GroupMutedNotification(utils.OperationID(ctx), utils.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, tools.OpUserID(ctx))
|
||||
opFlag, err := s.getGroupUserLevel(req.GroupID, utils.OpUserID(ctx))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -1252,7 +1251,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(tools.OperationID(ctx), "UpdateGroupInfoDefaultZero ", req.GroupID, map[string]interface{}{"status": constant.GroupOk})
|
||||
log.Debug(utils.OperationID(ctx), "UpdateGroupInfoDefaultZero ", req.GroupID, map[string]interface{}{"status": constant.GroupOk})
|
||||
if err := rocksCache.DelGroupInfoFromCache(ctx, req.GroupID); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -1260,14 +1259,14 @@ func (s *groupServer) CancelMuteGroup(ctx context.Context, req *pbGroup.CancelMu
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
chat.GroupCancelMutedNotification(tools.OperationID(ctx), tools.OpUserID(ctx), req.GroupID)
|
||||
chat.GroupCancelMutedNotification(utils.OperationID(ctx), utils.OpUserID(ctx), req.GroupID)
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (s *groupServer) SetGroupMemberNickname(ctx context.Context, req *pbGroup.SetGroupMemberNicknameReq) (*pbGroup.SetGroupMemberNicknameResp, error) {
|
||||
resp := &pbGroup.SetGroupMemberNicknameResp{}
|
||||
|
||||
if tools.OpUserID(ctx) != req.UserID && !token_verify.IsManagerUserID(tools.OpUserID(ctx)) {
|
||||
if utils.OpUserID(ctx) != req.UserID && !token_verify.IsManagerUserID(utils.OpUserID(ctx)) {
|
||||
return nil, utils.Wrap(constant.ErrIdentity, "")
|
||||
}
|
||||
cbReq := &pbGroup.SetGroupMemberInfoReq{
|
||||
@ -1299,7 +1298,7 @@ func (s *groupServer) SetGroupMemberNickname(ctx context.Context, req *pbGroup.S
|
||||
if err := relation.UpdateGroupMemberInfo(groupMemberInfo); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
chat.GroupMemberInfoSetNotification(tools.OperationID(ctx), tools.OpUserID(ctx), req.GroupID, req.UserID)
|
||||
chat.GroupMemberInfoSetNotification(utils.OperationID(ctx), utils.OpUserID(ctx), req.GroupID, req.UserID)
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
@ -1338,13 +1337,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(tools.OperationID(ctx), tools.OpUserID(ctx), req.GroupID, req.UserID)
|
||||
chat.GroupMemberInfoSetNotification(utils.OperationID(ctx), utils.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(tools.OperationID(ctx), tools.OpUserID(ctx), req.GroupID, req.UserID)
|
||||
chat.GroupMemberInfoSetNotification(utils.OperationID(ctx), utils.OpUserID(ctx), req.GroupID, req.UserID)
|
||||
}
|
||||
} else {
|
||||
chat.GroupMemberInfoSetNotification(tools.OperationID(ctx), tools.OpUserID(ctx), req.GroupID, req.UserID)
|
||||
chat.GroupMemberInfoSetNotification(utils.OperationID(ctx), utils.OpUserID(ctx), req.GroupID, req.UserID)
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
package msg
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/base_info"
|
||||
"Open_IM/pkg/api_struct"
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/log"
|
||||
@ -14,7 +14,7 @@ import (
|
||||
|
||||
func ExtendMessageUpdatedNotification(operationID, sendID string, sourceID string, sessionType int32,
|
||||
req *msg.SetMessageReactionExtensionsReq, resp *msg.SetMessageReactionExtensionsResp, isHistory bool, isReactionFromCache bool) {
|
||||
var m base_info.ReactionMessageModifierNotification
|
||||
var m api_struct.ReactionMessageModifierNotification
|
||||
m.SourceID = req.SourceID
|
||||
m.OpUserID = req.OpUserID
|
||||
m.SessionType = req.SessionType
|
||||
@ -37,7 +37,7 @@ func ExtendMessageUpdatedNotification(operationID, sendID string, sourceID strin
|
||||
}
|
||||
func ExtendMessageDeleteNotification(operationID, sendID string, sourceID string, sessionType int32,
|
||||
req *msg.DeleteMessageListReactionExtensionsReq, resp *msg.DeleteMessageListReactionExtensionsResp, isHistory bool, isReactionFromCache bool) {
|
||||
var m base_info.ReactionMessageDeleteNotification
|
||||
var m api_struct.ReactionMessageDeleteNotification
|
||||
m.SourceID = req.SourceID
|
||||
m.OpUserID = req.OpUserID
|
||||
m.SessionType = req.SessionType
|
||||
|
@ -6,7 +6,6 @@ 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"
|
||||
@ -389,23 +388,23 @@ func JoinGroupApplicationNotification(ctx context.Context, req *pbGroup.JoinGrou
|
||||
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(tools.OperationID(ctx), "setGroupInfo failed ", err.Error(), req.GroupID)
|
||||
log.Error(utils.OperationID(ctx), "setGroupInfo failed ", err.Error(), req.GroupID)
|
||||
return
|
||||
}
|
||||
if err = setPublicUserInfo(tools.OpUserID(ctx), JoinGroupApplicationTips.Applicant); err != nil {
|
||||
log.Error(tools.OperationID(ctx), "setPublicUserInfo failed ", err.Error(), tools.OpUserID(ctx))
|
||||
if err = setPublicUserInfo(utils.OpUserID(ctx), JoinGroupApplicationTips.Applicant); err != nil {
|
||||
log.Error(utils.OperationID(ctx), "setPublicUserInfo failed ", err.Error(), utils.OpUserID(ctx))
|
||||
return
|
||||
}
|
||||
JoinGroupApplicationTips.ReqMsg = req.ReqMessage
|
||||
|
||||
managerList, err := imdb.GetOwnerManagerByGroupID(req.GroupID)
|
||||
if err != nil {
|
||||
log.NewError(tools.OperationID(ctx), "GetOwnerManagerByGroupId failed ", err.Error(), req.GroupID)
|
||||
log.NewError(utils.OperationID(ctx), "GetOwnerManagerByGroupId failed ", err.Error(), req.GroupID)
|
||||
return
|
||||
}
|
||||
for _, v := range managerList {
|
||||
groupNotification(constant.JoinGroupApplicationNotification, &JoinGroupApplicationTips, tools.OpUserID(ctx), "", v.UserID, tools.OperationID(ctx))
|
||||
log.NewInfo(tools.OperationID(ctx), "Notification ", v)
|
||||
groupNotification(constant.JoinGroupApplicationNotification, &JoinGroupApplicationTips, utils.OpUserID(ctx), "", v.UserID, utils.OperationID(ctx))
|
||||
log.NewInfo(utils.OperationID(ctx), "Notification ", v)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,6 @@
|
||||
package msg
|
||||
|
||||
import (
|
||||
utils2 "Open_IM/internal/utils"
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/db"
|
||||
@ -177,7 +176,7 @@ func (rpc *rpcChat) messageVerification(ctx context.Context, data *pbChat.SendMs
|
||||
return true, 0, "", nil
|
||||
}
|
||||
case constant.GroupChatType:
|
||||
userIDList, err := utils2.GetGroupMemberUserIDList(ctx, data.MsgData.GroupID, data.OperationID)
|
||||
userIDList, err := utils.GetGroupMemberUserIDList(ctx, data.MsgData.GroupID, data.OperationID)
|
||||
if err != nil {
|
||||
errMsg := data.OperationID + err.Error()
|
||||
log.NewError(data.OperationID, errMsg)
|
||||
@ -251,7 +250,7 @@ func (rpc *rpcChat) messageVerification(ctx context.Context, data *pbChat.SendMs
|
||||
if groupInfo.GroupType == constant.SuperGroup {
|
||||
return true, 0, "", nil
|
||||
} else {
|
||||
userIDList, err := utils2.GetGroupMemberUserIDList(ctx, data.MsgData.GroupID, data.OperationID)
|
||||
userIDList, err := utils.GetGroupMemberUserIDList(ctx, data.MsgData.GroupID, data.OperationID)
|
||||
if err != nil {
|
||||
errMsg := data.OperationID + err.Error()
|
||||
log.NewError(data.OperationID, errMsg)
|
||||
|
@ -9,7 +9,6 @@ import (
|
||||
"Open_IM/pkg/common/log"
|
||||
promePkg "Open_IM/pkg/common/prometheus"
|
||||
"Open_IM/pkg/common/token_verify"
|
||||
"Open_IM/pkg/common/tools"
|
||||
"Open_IM/pkg/getcdv3"
|
||||
pbFriend "Open_IM/pkg/proto/friend"
|
||||
pbGroup "Open_IM/pkg/proto/group"
|
||||
@ -23,7 +22,6 @@ import (
|
||||
|
||||
grpcPrometheus "github.com/grpc-ecosystem/go-grpc-prometheus"
|
||||
|
||||
utils2 "Open_IM/internal/utils"
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
|
||||
@ -173,7 +171,7 @@ func (s *userServer) GetUsersInfo(ctx context.Context, req *pbUser.GetUsersInfoR
|
||||
return nil, err
|
||||
}
|
||||
for _, v := range users {
|
||||
n, err := utils2.NewDBUser(v).Convert()
|
||||
n, err := utils.NewDBUser(v).Convert()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -196,7 +194,7 @@ func (s *userServer) UpdateUserInfo(ctx context.Context, req *pbUser.UpdateUserI
|
||||
}
|
||||
oldNickname = u.Nickname
|
||||
}
|
||||
user, err := utils2.NewPBUser(req.UserInfo).Convert()
|
||||
user, err := utils.NewPBUser(req.UserInfo).Convert()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -216,16 +214,16 @@ func (s *userServer) UpdateUserInfo(ctx context.Context, req *pbUser.UpdateUserI
|
||||
}
|
||||
go func() {
|
||||
for _, v := range rpcResp.FriendInfoList {
|
||||
chat.FriendInfoUpdatedNotification(tools.OperationID(ctx), req.UserInfo.UserID, v.FriendUser.UserID, tools.OpUserID(ctx))
|
||||
chat.FriendInfoUpdatedNotification(utils.OperationID(ctx), req.UserInfo.UserID, v.FriendUser.UserID, utils.OpUserID(ctx))
|
||||
}
|
||||
}()
|
||||
|
||||
chat.UserInfoUpdatedNotification(tools.OperationID(ctx), tools.OpUserID(ctx), req.UserInfo.UserID)
|
||||
chat.UserInfoUpdatedNotification(utils.OperationID(ctx), utils.OpUserID(ctx), req.UserInfo.UserID)
|
||||
if req.UserInfo.FaceURL != "" {
|
||||
s.SyncJoinedGroupMemberFaceURL(ctx, req.UserInfo.UserID, req.UserInfo.FaceURL, tools.OperationID(ctx), tools.OpUserID(ctx))
|
||||
s.SyncJoinedGroupMemberFaceURL(ctx, req.UserInfo.UserID, req.UserInfo.FaceURL, utils.OperationID(ctx), utils.OpUserID(ctx))
|
||||
}
|
||||
if req.UserInfo.Nickname != "" {
|
||||
s.SyncJoinedGroupMemberNickname(ctx, req.UserInfo.UserID, req.UserInfo.Nickname, oldNickname, tools.OperationID(ctx), tools.OpUserID(ctx))
|
||||
s.SyncJoinedGroupMemberNickname(ctx, req.UserInfo.UserID, req.UserInfo.Nickname, oldNickname, utils.OperationID(ctx), utils.OpUserID(ctx))
|
||||
}
|
||||
return &resp, nil
|
||||
}
|
||||
@ -238,13 +236,13 @@ func (s *userServer) SetGlobalRecvMessageOpt(ctx context.Context, req *pbUser.Se
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
chat.UserInfoUpdatedNotification(tools.OperationID(ctx), req.UserID, req.UserID)
|
||||
chat.UserInfoUpdatedNotification(utils.OperationID(ctx), req.UserID, req.UserID)
|
||||
return &resp, nil
|
||||
}
|
||||
|
||||
func (s *userServer) AccountCheck(ctx context.Context, req *pbUser.AccountCheckReq) (*pbUser.AccountCheckResp, error) {
|
||||
resp := pbUser.AccountCheckResp{}
|
||||
err := token_verify.CheckManagerUserID(ctx, tools.OpUserID(ctx))
|
||||
err := token_verify.CheckManagerUserID(ctx, utils.OpUserID(ctx))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -279,7 +277,7 @@ func (s *userServer) GetUsers(ctx context.Context, req *pbUser.GetUsersReq) (*pb
|
||||
return nil, err
|
||||
}
|
||||
resp.Total = 1
|
||||
u1, err := utils2.NewDBUser(u).Convert()
|
||||
u1, err := utils.NewDBUser(u).Convert()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -294,7 +292,7 @@ func (s *userServer) GetUsers(ctx context.Context, req *pbUser.GetUsersReq) (*pb
|
||||
}
|
||||
resp.Total = int32(total)
|
||||
for _, v := range usersDB {
|
||||
u1, err := utils2.NewDBUser(v).Convert()
|
||||
u1, err := utils.NewDBUser(v).Convert()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -308,7 +306,7 @@ func (s *userServer) GetUsers(ctx context.Context, req *pbUser.GetUsersReq) (*pb
|
||||
}
|
||||
resp.Total = int32(total)
|
||||
for _, v := range usersDB {
|
||||
u1, err := utils2.NewDBUser(v).Convert()
|
||||
u1, err := utils.NewDBUser(v).Convert()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -325,7 +323,7 @@ func (s *userServer) GetUsers(ctx context.Context, req *pbUser.GetUsersReq) (*pb
|
||||
resp.Total = int32(total)
|
||||
|
||||
for _, userDB := range usersDB {
|
||||
u, err := utils2.NewDBUser(userDB).Convert()
|
||||
u, err := utils.NewDBUser(userDB).Convert()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -1 +0,0 @@
|
||||
package utils
|
@ -1,49 +0,0 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/golang/protobuf/jsonpb"
|
||||
"github.com/golang/protobuf/proto"
|
||||
"reflect"
|
||||
)
|
||||
|
||||
func JsonDataList(resp interface{}) []map[string]interface{} {
|
||||
var list []proto.Message
|
||||
if reflect.TypeOf(resp).Kind() == reflect.Slice {
|
||||
s := reflect.ValueOf(resp)
|
||||
for i := 0; i < s.Len(); i++ {
|
||||
ele := s.Index(i)
|
||||
list = append(list, ele.Interface().(proto.Message))
|
||||
}
|
||||
}
|
||||
|
||||
result := make([]map[string]interface{}, 0)
|
||||
for _, v := range list {
|
||||
m := ProtoToMap(v, false)
|
||||
result = append(result, m)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func JsonDataOne(pb proto.Message) map[string]interface{} {
|
||||
return ProtoToMap(pb, false)
|
||||
}
|
||||
|
||||
func ProtoToMap(pb proto.Message, idFix bool) map[string]interface{} {
|
||||
marshaler := jsonpb.Marshaler{
|
||||
OrigName: true,
|
||||
EnumsAsInts: false,
|
||||
EmitDefaults: false,
|
||||
}
|
||||
|
||||
s, _ := marshaler.MarshalToString(pb)
|
||||
out := make(map[string]interface{})
|
||||
json.Unmarshal([]byte(s), &out)
|
||||
if idFix {
|
||||
if _, ok := out["id"]; ok {
|
||||
out["_id"] = out["id"]
|
||||
delete(out, "id")
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package base_info
|
||||
package api_struct
|
||||
|
||||
//UserID string `protobuf:"bytes,1,opt,name=UserID" json:"UserID,omitempty"`
|
||||
// Nickname string `protobuf:"bytes,2,opt,name=Nickname" json:"Nickname,omitempty"`
|
@ -1,4 +1,4 @@
|
||||
package base_info
|
||||
package api_struct
|
||||
|
||||
type AwsStorageCredentialReq struct {
|
||||
OperationID string `json:"operationID"`
|
@ -1,4 +1,4 @@
|
||||
package base_info
|
||||
package api_struct
|
||||
|
||||
type SetClientInitConfigReq struct {
|
||||
OperationID string `json:"operationID" binding:"required"`
|
@ -1,4 +1,4 @@
|
||||
package base_info
|
||||
package api_struct
|
||||
|
||||
type RequestPagination struct {
|
||||
PageNumber int `json:"pageNumber" binding:"required"`
|
@ -1,4 +1,4 @@
|
||||
package base_info
|
||||
package api_struct
|
||||
|
||||
type OptResult struct {
|
||||
ConversationID string `json:"conversationID"`
|
@ -1,4 +1,4 @@
|
||||
package base_info
|
||||
package api_struct
|
||||
|
||||
import sts "github.com/tencentyun/qcloud-cos-sts-sdk/go"
|
||||
|
@ -1,4 +1,4 @@
|
||||
package base_info
|
||||
package api_struct
|
||||
|
||||
//type ParamsCommFriend struct {
|
||||
// OperationID string `json:"operationID" binding:"required"`
|
@ -1,4 +1,4 @@
|
||||
package base_info
|
||||
package api_struct
|
||||
|
||||
import (
|
||||
open_im_sdk "Open_IM/pkg/proto/sdk_ws"
|
@ -1,4 +1,4 @@
|
||||
package base_info
|
||||
package api_struct
|
||||
|
||||
import (
|
||||
pbRelay "Open_IM/pkg/proto/relay"
|
@ -1,4 +1,4 @@
|
||||
package base_info
|
||||
package api_struct
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/proto/msg"
|
@ -1,4 +1,4 @@
|
||||
package base_info
|
||||
package api_struct
|
||||
|
||||
import (
|
||||
pbOffice "Open_IM/pkg/proto/office"
|
@ -1,4 +1,4 @@
|
||||
package base_info
|
||||
package api_struct
|
||||
|
||||
import open_im_sdk "Open_IM/pkg/proto/sdk_ws"
|
||||
|
@ -1,4 +1,4 @@
|
||||
package base_info
|
||||
package api_struct
|
||||
|
||||
type OSSCredentialReq struct {
|
||||
OperationID string `json:"operationID"`
|
@ -1,4 +1,4 @@
|
||||
package base_info
|
||||
package api_struct
|
||||
|
||||
type Pagination struct {
|
||||
PageNumber int32 `json:"pageNumber" binding:"required"`
|
@ -1,4 +1,4 @@
|
||||
package base_info
|
||||
package api_struct
|
||||
|
||||
import (
|
||||
"net/http"
|
@ -1,4 +1,4 @@
|
||||
package base_info
|
||||
package api_struct
|
||||
|
||||
type GetJoinedSuperGroupListReq struct {
|
||||
GetJoinedGroupListReq
|
@ -1,4 +1,4 @@
|
||||
package base_info
|
||||
package api_struct
|
||||
|
||||
type Swagger400Resp struct {
|
||||
ErrCode int32 `json:"errCode" example:"400"`
|
@ -1,4 +1,4 @@
|
||||
package base_info
|
||||
package api_struct
|
||||
|
||||
import "mime/multipart"
|
||||
|
@ -1,4 +1,4 @@
|
||||
package base_info
|
||||
package api_struct
|
||||
|
||||
import (
|
||||
open_im_sdk "Open_IM/pkg/proto/sdk_ws"
|
@ -1,4 +1,4 @@
|
||||
package base_info
|
||||
package api_struct
|
||||
|
||||
import "Open_IM/pkg/proto/office"
|
||||
|
@ -1,7 +1,7 @@
|
||||
package cms_api_struct
|
||||
package cms_struct
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/base_info"
|
||||
"Open_IM/pkg/api_struct"
|
||||
server_api_params "Open_IM/pkg/proto/sdk_ws"
|
||||
)
|
||||
|
||||
@ -47,10 +47,10 @@ type ReduceUserRegisterAddFriendIDListResponse struct {
|
||||
|
||||
type GetUserRegisterAddFriendIDListRequest struct {
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
base_info.RequestPagination
|
||||
api_struct.RequestPagination
|
||||
}
|
||||
|
||||
type GetUserRegisterAddFriendIDListResponse struct {
|
||||
Users []*server_api_params.UserInfo `json:"users"`
|
||||
base_info.ResponsePagination
|
||||
api_struct.ResponsePagination
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package cms_api_struct
|
||||
package cms_struct
|
||||
|
||||
type RequestPagination struct {
|
||||
PageNumber int `json:"pageNumber" binding:"required"`
|
@ -1,4 +1,4 @@
|
||||
package cms_api_struct
|
||||
package cms_struct
|
||||
|
||||
type GetFriendsReq struct {
|
||||
OperationID string `json:"operationID"`
|
@ -1,4 +1,4 @@
|
||||
package cms_api_struct
|
||||
package cms_struct
|
||||
|
||||
type GroupResponse struct {
|
||||
GroupOwnerName string `json:"GroupOwnerName"`
|
@ -1,4 +1,4 @@
|
||||
package cms_api_struct
|
||||
package cms_struct
|
||||
|
||||
import (
|
||||
pbCommon "Open_IM/pkg/proto/sdk_ws"
|
@ -1,4 +1,4 @@
|
||||
package cms_api_struct
|
||||
package cms_struct
|
||||
|
||||
type GetStatisticsRequest struct {
|
||||
From string `json:"from" binding:"required"`
|
@ -1,4 +1,4 @@
|
||||
package cms_api_struct
|
||||
package cms_struct
|
||||
|
||||
type UserResponse struct {
|
||||
FaceURL string `json:"faceURL"`
|
@ -10,11 +10,6 @@ func GetContent(msg *server_api_params.MsgData) string {
|
||||
if msg.ContentType >= constant.NotificationBegin && msg.ContentType <= constant.NotificationEnd {
|
||||
var tips server_api_params.TipsComm
|
||||
_ = proto.Unmarshal(msg.Content, &tips)
|
||||
//marshaler := jsonpb.Marshaler{
|
||||
// OrigName: true,
|
||||
// EnumsAsInts: false,
|
||||
// EmitDefaults: false,
|
||||
//}
|
||||
content := tips.JsonDetail
|
||||
return content
|
||||
} else {
|
||||
|
@ -5,7 +5,6 @@ import (
|
||||
"Open_IM/pkg/common/constant"
|
||||
commonDB "Open_IM/pkg/common/db"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/common/tools"
|
||||
"Open_IM/pkg/common/tracelog"
|
||||
"Open_IM/pkg/utils"
|
||||
"context"
|
||||
@ -160,7 +159,7 @@ func CheckAccess(ctx context.Context, OpUserID string, OwnerUserID string) bool
|
||||
}
|
||||
|
||||
func CheckAccessV3(ctx context.Context, ownerUserID string) (err error) {
|
||||
opUserID := tools.OpUserID(ctx)
|
||||
opUserID := utils.OpUserID(ctx)
|
||||
defer func() {
|
||||
tracelog.SetCtxInfo(ctx, utils.GetFuncName(1), err, "OpUserID", opUserID, "ownerUserID", ownerUserID)
|
||||
}()
|
||||
@ -174,11 +173,11 @@ func CheckAccessV3(ctx context.Context, ownerUserID string) (err error) {
|
||||
}
|
||||
|
||||
func IsAppManagerUid(ctx context.Context) bool {
|
||||
return utils.IsContain(tools.OpUserID(ctx), config.Config.Manager.AppManagerUid)
|
||||
return utils.IsContain(utils.OpUserID(ctx), config.Config.Manager.AppManagerUid)
|
||||
}
|
||||
|
||||
func CheckAdmin(ctx context.Context) error {
|
||||
if utils.IsContain(tools.OpUserID(ctx), config.Config.Manager.AppManagerUid) {
|
||||
if utils.IsContain(utils.OpUserID(ctx), config.Config.Manager.AppManagerUid) {
|
||||
return nil
|
||||
}
|
||||
return constant.ErrIdentity.Wrap()
|
||||
|
@ -1,13 +0,0 @@
|
||||
package tools
|
||||
|
||||
import "context"
|
||||
|
||||
func OperationID(ctx context.Context) string {
|
||||
s, _ := ctx.Value("operationID").(string)
|
||||
return s
|
||||
}
|
||||
|
||||
func OpUserID(ctx context.Context) string {
|
||||
s, _ := ctx.Value("opUserID").(string)
|
||||
return s
|
||||
}
|
@ -1,28 +1,20 @@
|
||||
package tracelog
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/utils"
|
||||
"context"
|
||||
"github.com/sirupsen/logrus"
|
||||
"google.golang.org/grpc/status"
|
||||
"runtime"
|
||||
"strings"
|
||||
|
||||
//"errors"
|
||||
"fmt"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
const TraceLogKey = "tracelog"
|
||||
|
||||
func NewCtx(c *gin.Context, api string) context.Context {
|
||||
req := &ApiInfo{ApiName: api, GinCtx: c, Funcs: &[]FuncInfo{}}
|
||||
return context.WithValue(c, TraceLogKey, req)
|
||||
}
|
||||
|
||||
func NewCtx1(c *gin.Context, api string) context.Context {
|
||||
req := &ApiInfo{ApiName: api, GinCtx: c, OperationID: c.GetHeader("operationID"), Funcs: &[]FuncInfo{}}
|
||||
return context.WithValue(c, TraceLogKey, req)
|
||||
}
|
||||
@ -42,77 +34,11 @@ func GetOperationID(ctx context.Context) string {
|
||||
return ctx.Value(TraceLogKey).(*ApiInfo).OperationID
|
||||
}
|
||||
|
||||
//func ShowLog(ctx context.Context) {
|
||||
// t := ctx.Value(TraceLogKey).(*ApiInfo)
|
||||
// if ctx.Value(TraceLogKey).(*ApiInfo).GinCtx != nil {
|
||||
// log.Info(t.OperationID, "api: ", t.ApiName)
|
||||
// } else {
|
||||
// log.Info(t.OperationID, "rpc: ", t.ApiName)
|
||||
// }
|
||||
// for _, v := range *t.Funcs {
|
||||
// if v.Err != nil {
|
||||
// log.Error(t.OperationID, "func: ", v.FuncName, " args: ", v.Args, v.Err.Error())
|
||||
// } else {
|
||||
// switch v.LogLevel {
|
||||
// case logrus.InfoLevel:
|
||||
// log.Info(t.OperationID, "func: ", v.FuncName, " args: ", v.Args)
|
||||
// case logrus.DebugLevel:
|
||||
// log.Debug(t.OperationID, "func: ", v.FuncName, " args: ", v.Args)
|
||||
// case logrus.WarnLevel:
|
||||
// log.Debug(t.OperationID, "func: ", v.FuncName, " args: ", v.Args)
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
|
||||
func WriteErrorResponse(ctx context.Context, funcName string, err error, args ...interface{}) {
|
||||
SetCtxInfo(ctx, funcName, err, args)
|
||||
e := Unwrap(err)
|
||||
switch t := e.(type) {
|
||||
case *constant.ErrInfo:
|
||||
ctx.Value(TraceLogKey).(*ApiInfo).GinCtx.JSON(http.StatusOK, baseResp{ErrCode: t.ErrCode, ErrMsg: t.ErrMsg, ErrDtl: t.DetailErrMsg})
|
||||
//ctx.Value(TraceLogKey).(*ApiInfo).GinCtx.JSON(http.StatusOK, gin.H{"errCode": t.ErrCode, "errMsg": t.ErrMsg, "errDtl": t.DetailErrMsg})
|
||||
return
|
||||
default:
|
||||
s, ok := status.FromError(e)
|
||||
if !ok {
|
||||
ctx.Value(TraceLogKey).(*ApiInfo).GinCtx.JSON(http.StatusOK, &baseResp{ErrCode: constant.ErrDefaultOther.ErrCode, ErrMsg: err.Error(), ErrDtl: fmt.Sprintf("%+v", err)})
|
||||
//ctx.Value(TraceLogKey).(*ApiInfo).GinCtx.JSON(http.StatusOK, gin.H{"errCode": constant.ErrDefaultOther.ErrCode, "errMsg": err.Error(), "errDtl": fmt.Sprintf("%+v", err)})
|
||||
return
|
||||
}
|
||||
var details []string
|
||||
if err != e {
|
||||
details = append(details, fmt.Sprintf("%+v", err))
|
||||
}
|
||||
for _, s := range s.Details() {
|
||||
details = append(details, fmt.Sprintf("%+v", s))
|
||||
}
|
||||
ctx.Value(TraceLogKey).(*ApiInfo).GinCtx.JSON(http.StatusOK, &baseResp{ErrCode: int32(s.Code()), ErrMsg: s.Message(), ErrDtl: strings.Join(details, "\n")})
|
||||
//ctx.Value(TraceLogKey).(*ApiInfo).GinCtx.JSON(http.StatusOK, gin.H{"errCode": s.Code(), "errMsg": s.Message(), "errDtl": strings.Join(details, "\n")})
|
||||
return
|
||||
}
|
||||
func GetOpUserID(ctx context.Context) string {
|
||||
s, _ := ctx.Value("opUserID").(string)
|
||||
return s
|
||||
}
|
||||
|
||||
type baseResp struct {
|
||||
ErrCode int32 `json:"errCode"`
|
||||
ErrMsg string `json:"errMsg"`
|
||||
ErrDtl string `json:"errDtl"`
|
||||
Data interface{} `json:"data"`
|
||||
}
|
||||
|
||||
//func WriteErrorResponse(ctx context.Context, funcName string, err error, args ...interface{}) {
|
||||
// SetCtxInfo(ctx, funcName, err, args)
|
||||
// e := new(constant.ErrInfo)
|
||||
// switch {
|
||||
// case errors.As(err, &e):
|
||||
// ctx.Value(TraceLogKey).(*ApiInfo).GinCtx.JSON(http.StatusOK, gin.H{"errCode": e.ErrCode, "errMsg": e.ErrMsg})
|
||||
// return
|
||||
// default:
|
||||
// ctx.Value(TraceLogKey).(*ApiInfo).GinCtx.JSON(http.StatusOK, gin.H{"errCode": constant.ErrDefaultOther.ErrCode, "errMsg": constant.ErrDefaultOther.ErrMsg, "errDtl": err.Error()})
|
||||
// return
|
||||
// }
|
||||
//}
|
||||
|
||||
func Unwrap(err error) error {
|
||||
for err != nil {
|
||||
unwrap, ok := err.(interface {
|
||||
@ -211,11 +137,6 @@ func SetRpcRespInfo(ctx context.Context, funcName string, resp string) {
|
||||
*t.Funcs = append(*t.Funcs, funcInfo)
|
||||
}
|
||||
|
||||
func SetSuccess(ctx context.Context, funcName string, data interface{}) {
|
||||
SetCtxInfo(ctx, funcName, nil, "data", data)
|
||||
ctx.Value(TraceLogKey).(*ApiInfo).GinCtx.JSON(http.StatusOK, gin.H{"errCode": 0, "errMsg": "", "errDtl": "", "data": data})
|
||||
}
|
||||
|
||||
func argsHandle(args []interface{}, fields map[string]interface{}) {
|
||||
for i := 0; i < len(args); i += 2 {
|
||||
if i+1 < len(args) {
|
||||
|
@ -3,7 +3,6 @@ package utils
|
||||
import (
|
||||
"Open_IM/pkg/common/db/relation"
|
||||
sdk "Open_IM/pkg/proto/sdk_ws"
|
||||
utils2 "Open_IM/pkg/utils"
|
||||
utils "github.com/OpenIMSDK/open_utils"
|
||||
"time"
|
||||
)
|
@ -1,7 +1,6 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/utils"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
@ -36,7 +35,7 @@ func performRequestWithHeaders(r http.Handler, method, origin string, header htt
|
||||
|
||||
func newTestRouter() *gin.Engine {
|
||||
router := gin.New()
|
||||
router.Use(utils.CorsHandler())
|
||||
router.Use(CorsHandler())
|
||||
router.GET("/", func(c *gin.Context) {
|
||||
c.String(http.StatusOK, "get")
|
||||
})
|
@ -1,7 +1,6 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/utils"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"testing"
|
||||
@ -17,12 +16,12 @@ var (
|
||||
|
||||
func Test_GenSmallImage(t *testing.T) {
|
||||
println(Root)
|
||||
err := utils.GenSmallImage(Root+"/docs/open-im-logo.png", Root+"/out-test/open-im-logo-test.png")
|
||||
err := GenSmallImage(Root+"/docs/open-im-logo.png", Root+"/out-test/open-im-logo-test.png")
|
||||
assert.Nil(t, err)
|
||||
|
||||
err = utils.GenSmallImage(Root+"/docs/open-im-logo.png", "out-test/open-im-logo-test.png")
|
||||
err = GenSmallImage(Root+"/docs/open-im-logo.png", "out-test/open-im-logo-test.png")
|
||||
assert.Nil(t, err)
|
||||
|
||||
err = utils.GenSmallImage(Root+"/docs/Architecture.jpg", "out-test/Architecture-test.jpg")
|
||||
err = GenSmallImage(Root+"/docs/Architecture.jpg", "out-test/Architecture-test.jpg")
|
||||
assert.Nil(t, err)
|
||||
}
|
@ -6,7 +6,6 @@ import (
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/getcdv3"
|
||||
pbCache "Open_IM/pkg/proto/cache"
|
||||
"Open_IM/pkg/utils"
|
||||
"context"
|
||||
"errors"
|
||||
"sync"
|
||||
@ -27,7 +26,7 @@ func GetGroupMemberUserIDList(ctx context.Context, groupID string, operationID s
|
||||
defer CacheGroupMtx.Unlock()
|
||||
delete(CacheGroupMemberUserIDList, groupID)
|
||||
log.Error(operationID, "GetGroupMemberUserIDListHashFromRemote failed ", err.Error(), groupID)
|
||||
return nil, utils.Wrap(err, groupID)
|
||||
return nil, Wrap(err, groupID)
|
||||
}
|
||||
|
||||
CacheGroupMtx.Lock()
|
||||
@ -48,7 +47,7 @@ func GetGroupMemberUserIDList(ctx context.Context, groupID string, operationID s
|
||||
memberUserIDListRemote, err := GetGroupMemberUserIDListFromRemote(groupID, operationID)
|
||||
if err != nil {
|
||||
log.Error(operationID, "GetGroupMemberUserIDListFromRemote failed ", err.Error(), groupID)
|
||||
return nil, utils.Wrap(err, groupID)
|
||||
return nil, Wrap(err, groupID)
|
||||
}
|
||||
CacheGroupMemberUserIDList[groupID] = &GroupMemberUserIDListHash{MemberListHash: groupHashRemote, UserIDList: memberUserIDListRemote}
|
||||
return memberUserIDListRemote, nil
|
||||
@ -68,7 +67,7 @@ func GetGroupMemberUserIDListFromRemote(groupID string, operationID string) ([]s
|
||||
cacheResp, err := client.GetGroupMemberIDListFromCache(context.Background(), getGroupMemberIDListFromCacheReq)
|
||||
if err != nil {
|
||||
log.NewError(operationID, "GetGroupMemberIDListFromCache rpc call failed ", err.Error())
|
||||
return nil, utils.Wrap(err, "GetGroupMemberIDListFromCache rpc call failed")
|
||||
return nil, Wrap(err, "GetGroupMemberIDListFromCache rpc call failed")
|
||||
}
|
||||
if cacheResp.CommonResp.ErrCode != 0 {
|
||||
errMsg := operationID + "GetGroupMemberIDListFromCache rpc logic call failed " + cacheResp.CommonResp.ErrMsg
|
@ -1,16 +1,15 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/utils"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func Test_Md5(t *testing.T) {
|
||||
result := utils.Md5("go")
|
||||
result := Md5("go")
|
||||
assert.Equal(t, result, "34d1f91fb2e514b8576fab1a75a89a6b")
|
||||
|
||||
result2 := utils.Md5("go")
|
||||
result2 := Md5("go")
|
||||
assert.Equal(t, result, result2)
|
||||
}
|
@ -8,6 +8,7 @@ import (
|
||||
"github.com/jinzhu/copier"
|
||||
"github.com/pkg/errors"
|
||||
"math/rand"
|
||||
"reflect"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"strings"
|
||||
@ -166,6 +167,7 @@ func Map2Pb(m map[string]string) (pb proto.Message, err error) {
|
||||
}
|
||||
return pb, nil
|
||||
}
|
||||
|
||||
func Pb2Map(pb proto.Message) (map[string]interface{}, error) {
|
||||
_buffer := bytes.Buffer{}
|
||||
jsonbMarshaller := &jsonpb.Marshaler{
|
||||
@ -179,3 +181,44 @@ func Pb2Map(pb proto.Message) (map[string]interface{}, error) {
|
||||
err := json.Unmarshal(jsonCnt, &out)
|
||||
return out, err
|
||||
}
|
||||
|
||||
func JsonDataList(resp interface{}) []map[string]interface{} {
|
||||
var list []proto.Message
|
||||
if reflect.TypeOf(resp).Kind() == reflect.Slice {
|
||||
s := reflect.ValueOf(resp)
|
||||
for i := 0; i < s.Len(); i++ {
|
||||
ele := s.Index(i)
|
||||
list = append(list, ele.Interface().(proto.Message))
|
||||
}
|
||||
}
|
||||
|
||||
result := make([]map[string]interface{}, 0)
|
||||
for _, v := range list {
|
||||
m := ProtoToMap(v, false)
|
||||
result = append(result, m)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func JsonDataOne(pb proto.Message) map[string]interface{} {
|
||||
return ProtoToMap(pb, false)
|
||||
}
|
||||
|
||||
func ProtoToMap(pb proto.Message, idFix bool) map[string]interface{} {
|
||||
marshaler := jsonpb.Marshaler{
|
||||
OrigName: true,
|
||||
EnumsAsInts: false,
|
||||
EmitDefaults: false,
|
||||
}
|
||||
|
||||
s, _ := marshaler.MarshalToString(pb)
|
||||
out := make(map[string]interface{})
|
||||
json.Unmarshal([]byte(s), &out)
|
||||
if idFix {
|
||||
if _, ok := out["id"]; ok {
|
||||
out["_id"] = out["id"]
|
||||
delete(out, "id")
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user