mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-04-06 04:15:46 +08:00
tidy code
This commit is contained in:
parent
38542f9888
commit
b6944c4308
@ -26,12 +26,12 @@ func main() {
|
||||
{
|
||||
userRouterGroup.POST("/update_user_info", user.UpdateUserInfo)
|
||||
userRouterGroup.POST("/get_user_info", user.GetUserInfo)
|
||||
userRouterGroup.POST("/get_users_online_status", user.GetUsersOnlineStatus)
|
||||
//userRouterGroup.POST("/get_users_online_status", user.GetUsersOnlineStatus)
|
||||
}
|
||||
//friend routing group
|
||||
friendRouterGroup := r.Group("/friend")
|
||||
{
|
||||
friendRouterGroup.POST("/get_friends_info", friend.GetFriendsInfo)
|
||||
// friendRouterGroup.POST("/get_friends_info", friend.GetFriendsInfo)
|
||||
friendRouterGroup.POST("/add_friend", friend.AddFriend)
|
||||
friendRouterGroup.POST("/get_friend_apply_list", friend.GetFriendApplyList)
|
||||
friendRouterGroup.POST("/get_self_apply_list", friend.GetSelfApplyList)
|
||||
@ -87,15 +87,15 @@ func main() {
|
||||
{
|
||||
managementGroup.POST("/delete_user", manage.DeleteUser)
|
||||
managementGroup.POST("/send_msg", manage.ManagementSendMsg)
|
||||
managementGroup.POST("/get_all_users_uid", manage.GetAllUsersUid)
|
||||
managementGroup.POST("/account_check", manage.AccountCheck)
|
||||
managementGroup.POST("/get_users_online_status", manage.GetUsersOnlineStatus)
|
||||
// managementGroup.POST("/get_all_users_uid", manage.GetAllUsersUid)
|
||||
// managementGroup.POST("/account_check", manage.AccountCheck)
|
||||
// managementGroup.POST("/get_users_online_status", manage.GetUsersOnlineStatus)
|
||||
}
|
||||
//Conversation
|
||||
conversationGroup := r.Group("/conversation")
|
||||
{
|
||||
conversationGroup.POST("/set_receive_message_opt", conversation.SetReceiveMessageOpt)
|
||||
conversationGroup.POST("/get_receive_message_opt", conversation.GetReceiveMessageOpt)
|
||||
// conversationGroup.POST("/get_receive_message_opt", conversation.GetReceiveMessageOpt)
|
||||
conversationGroup.POST("/get_all_conversation_message_opt", conversation.GetAllConversationMessageOpt)
|
||||
}
|
||||
|
||||
|
@ -1,194 +1,192 @@
|
||||
package conversation
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/common/token_verify"
|
||||
"Open_IM/pkg/grpc-etcdv3/getcdv3"
|
||||
"Open_IM/pkg/proto/user"
|
||||
"Open_IM/pkg/utils"
|
||||
"context"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
import "github.com/gin-gonic/gin"
|
||||
|
||||
type paramsSetReceiveMessageOpt struct {
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
Option *int32 `json:"option" binding:"required"`
|
||||
ConversationIdList []string `json:"conversationIdList" binding:"required"`
|
||||
}
|
||||
|
||||
type OptResult struct {
|
||||
ConversationId string `json:"conversationId" binding:"required"`
|
||||
Result int32 `json:"result" binding:"required"`
|
||||
}
|
||||
|
||||
type SetReceiveMessageOptResp struct {
|
||||
ErrCode int32 `json:"errCode"`
|
||||
ErrMsg string `json:"errMsg"`
|
||||
Data []OptResult `json:"data"`
|
||||
}
|
||||
|
||||
type paramGetReceiveMessageOpt struct {
|
||||
ConversationIdList []string `json:"conversationIdList" binding:"required"`
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
}
|
||||
|
||||
type GetReceiveMessageOptResp struct {
|
||||
SetReceiveMessageOptResp
|
||||
}
|
||||
|
||||
type paramGetAllConversationMessageOpt struct {
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
}
|
||||
|
||||
type GetAllConversationMessageOptResp struct {
|
||||
SetReceiveMessageOptResp
|
||||
}
|
||||
|
||||
//CopyStructFields
|
||||
//
|
||||
//type paramsSetReceiveMessageOpt struct {
|
||||
// OperationID string `json:"operationID" binding:"required"`
|
||||
// Option *int32 `json:"option" binding:"required"`
|
||||
// ConversationIdList []string `json:"conversationIdList" binding:"required"`
|
||||
//}
|
||||
//
|
||||
//type OptResult struct {
|
||||
// ConversationId string `json:"conversationId" binding:"required"`
|
||||
// Result int32 `json:"result" binding:"required"`
|
||||
//}
|
||||
//
|
||||
//type SetReceiveMessageOptResp struct {
|
||||
// ErrCode int32 `json:"errCode"`
|
||||
// ErrMsg string `json:"errMsg"`
|
||||
// Data []OptResult `json:"data"`
|
||||
//}
|
||||
//
|
||||
//type paramGetReceiveMessageOpt struct {
|
||||
// ConversationIdList []string `json:"conversationIdList" binding:"required"`
|
||||
// OperationID string `json:"operationID" binding:"required"`
|
||||
//}
|
||||
//
|
||||
//type GetReceiveMessageOptResp struct {
|
||||
// SetReceiveMessageOptResp
|
||||
//}
|
||||
//
|
||||
//type paramGetAllConversationMessageOpt struct {
|
||||
// OperationID string `json:"operationID" binding:"required"`
|
||||
//}
|
||||
//
|
||||
//type GetAllConversationMessageOptResp struct {
|
||||
// SetReceiveMessageOptResp
|
||||
//}
|
||||
//
|
||||
////CopyStructFields
|
||||
|
||||
func GetAllConversationMessageOpt(c *gin.Context) {
|
||||
params := paramGetAllConversationMessageOpt{}
|
||||
if err := c.BindJSON(¶ms); err != nil {
|
||||
log.NewError(params.OperationID, "bind json failed ", err.Error(), c)
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": "bind json failed " + err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
claims, err := token_verify.ParseToken(c.Request.Header.Get("token"))
|
||||
if err != nil {
|
||||
log.NewError(params.OperationID, "ParseToken failed, ", err.Error(), c.Request.Header.Get("token"))
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 401, "errMsg": "ParseToken failed, " + err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
req := &user.GetAllConversationMsgOptReq{
|
||||
UId: claims.UID,
|
||||
OperationID: params.OperationID,
|
||||
}
|
||||
log.NewInfo(req.OperationID, "GetAllConversationMsgOpt req: ", req)
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImUserName)
|
||||
client := user.NewUserClient(etcdConn)
|
||||
resp, err := client.GetAllConversationMsgOpt(context.Background(), req)
|
||||
if err != nil {
|
||||
log.NewError(params.OperationID, "GetAllConversationMsgOpt rpc failed, ", req, err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 401, "errMsg": "GetAllConversationMsgOpt rpc failed, " + err.Error()})
|
||||
return
|
||||
}
|
||||
var ginResp GetAllConversationMessageOptResp
|
||||
ginResp.ErrCode = resp.ErrCode
|
||||
ginResp.ErrMsg = resp.ErrMsg
|
||||
for _, v := range resp.ConversationOptResult {
|
||||
var opt OptResult
|
||||
err := utils.CopyStructFields(&opt, *v, "ConversationId", "Result")
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "CopyStructFields failed ", err.Error())
|
||||
continue
|
||||
}
|
||||
ginResp.Data = append(ginResp.Data, opt)
|
||||
}
|
||||
log.NewInfo(req.OperationID, "GetAllConversationMsgOpt resp: ", ginResp, req)
|
||||
c.JSON(http.StatusOK, ginResp)
|
||||
}
|
||||
|
||||
func GetReceiveMessageOpt(c *gin.Context) {
|
||||
params := paramGetReceiveMessageOpt{}
|
||||
if err := c.BindJSON(¶ms); err != nil {
|
||||
log.NewError(params.OperationID, "bind json failed ", err.Error(), c)
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": "bind json failed " + err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
claims, err := token_verify.ParseToken(c.Request.Header.Get("token"))
|
||||
if err != nil {
|
||||
log.NewError(params.OperationID, "ParseToken failed, ", err.Error(), c.Request.Header.Get("token"))
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 401, "errMsg": "ParseToken failed, " + err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
req := &user.GetReceiveMessageOptReq{
|
||||
UId: claims.UID,
|
||||
ConversationId: params.ConversationIdList,
|
||||
OperationID: params.OperationID,
|
||||
}
|
||||
log.NewInfo(req.OperationID, "GetReceiveMessageOptReq req: ", req)
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImUserName)
|
||||
client := user.NewUserClient(etcdConn)
|
||||
resp, err := client.GetReceiveMessageOpt(context.Background(), req)
|
||||
if err != nil {
|
||||
log.NewError(params.OperationID, "GetReceiveMessageOpt rpc failed, ", req, err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 401, "errMsg": "GetReceiveMessageOpt rpc failed, " + err.Error()})
|
||||
return
|
||||
}
|
||||
log.NewInfo(req.OperationID, "GetReceiveMessageOptReq req: ", req, resp)
|
||||
var ginResp GetReceiveMessageOptResp
|
||||
ginResp.ErrCode = resp.ErrCode
|
||||
ginResp.ErrMsg = resp.ErrMsg
|
||||
|
||||
for _, v := range resp.ConversationOptResult {
|
||||
var opt OptResult
|
||||
log.NewInfo("CopyStructFields begin ", v, req.OperationID)
|
||||
err := utils.CopyStructFields(&opt, *v, "ConversationId", "Result")
|
||||
log.NewInfo("CopyStructFields end ", v, req.OperationID)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "CopyStructFields failed ", err.Error())
|
||||
continue
|
||||
}
|
||||
ginResp.Data = append(ginResp.Data, opt)
|
||||
}
|
||||
log.NewInfo(req.OperationID, "GetReceiveMessageOpt resp: ", ginResp)
|
||||
c.JSON(http.StatusOK, ginResp)
|
||||
}
|
||||
|
||||
//func GetAllConversationMessageOpt(c *gin.Context) {
|
||||
// params := paramGetAllConversationMessageOpt{}
|
||||
// if err := c.BindJSON(¶ms); err != nil {
|
||||
// log.NewError(params.OperationID, "bind json failed ", err.Error(), c)
|
||||
// c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": "bind json failed " + err.Error()})
|
||||
// return
|
||||
// }
|
||||
//
|
||||
// claims, err := token_verify.ParseToken(c.Request.Header.Get("token"))
|
||||
// if err != nil {
|
||||
// log.NewError(params.OperationID, "ParseToken failed, ", err.Error(), c.Request.Header.Get("token"))
|
||||
// c.JSON(http.StatusBadRequest, gin.H{"errCode": 401, "errMsg": "ParseToken failed, " + err.Error()})
|
||||
// return
|
||||
// }
|
||||
//
|
||||
// req := &user.GetAllConversationMsgOptReq{
|
||||
// UId: claims.UID,
|
||||
// OperationID: params.OperationID,
|
||||
// }
|
||||
// log.NewInfo(req.OperationID, "GetAllConversationMsgOpt req: ", req)
|
||||
// etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImUserName)
|
||||
// client := user.NewUserClient(etcdConn)
|
||||
// resp, err := client.GetAllConversationMsgOpt(context.Background(), req)
|
||||
// if err != nil {
|
||||
// log.NewError(params.OperationID, "GetAllConversationMsgOpt rpc failed, ", req, err.Error())
|
||||
// c.JSON(http.StatusBadRequest, gin.H{"errCode": 401, "errMsg": "GetAllConversationMsgOpt rpc failed, " + err.Error()})
|
||||
// return
|
||||
// }
|
||||
// var ginResp GetAllConversationMessageOptResp
|
||||
// ginResp.ErrCode = resp.ErrCode
|
||||
// ginResp.ErrMsg = resp.ErrMsg
|
||||
// for _, v := range resp.ConversationOptResult {
|
||||
// var opt OptResult
|
||||
// err := utils.CopyStructFields(&opt, *v, "ConversationId", "Result")
|
||||
// if err != nil {
|
||||
// log.NewError(req.OperationID, "CopyStructFields failed ", err.Error())
|
||||
// continue
|
||||
// }
|
||||
// ginResp.Data = append(ginResp.Data, opt)
|
||||
// }
|
||||
// log.NewInfo(req.OperationID, "GetAllConversationMsgOpt resp: ", ginResp, req)
|
||||
// c.JSON(http.StatusOK, ginResp)
|
||||
//}
|
||||
//
|
||||
//func GetReceiveMessageOpt(c *gin.Context) {
|
||||
// params := paramGetReceiveMessageOpt{}
|
||||
// if err := c.BindJSON(¶ms); err != nil {
|
||||
// log.NewError(params.OperationID, "bind json failed ", err.Error(), c)
|
||||
// c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": "bind json failed " + err.Error()})
|
||||
// return
|
||||
// }
|
||||
//
|
||||
// claims, err := token_verify.ParseToken(c.Request.Header.Get("token"))
|
||||
// if err != nil {
|
||||
// log.NewError(params.OperationID, "ParseToken failed, ", err.Error(), c.Request.Header.Get("token"))
|
||||
// c.JSON(http.StatusBadRequest, gin.H{"errCode": 401, "errMsg": "ParseToken failed, " + err.Error()})
|
||||
// return
|
||||
// }
|
||||
//
|
||||
// req := &user.GetReceiveMessageOptReq{
|
||||
// UId: claims.UID,
|
||||
// ConversationId: params.ConversationIdList,
|
||||
// OperationID: params.OperationID,
|
||||
// }
|
||||
// log.NewInfo(req.OperationID, "GetReceiveMessageOptReq req: ", req)
|
||||
// etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImUserName)
|
||||
// client := user.NewUserClient(etcdConn)
|
||||
// resp, err := client.GetReceiveMessageOpt(context.Background(), req)
|
||||
// if err != nil {
|
||||
// log.NewError(params.OperationID, "GetReceiveMessageOpt rpc failed, ", req, err.Error())
|
||||
// c.JSON(http.StatusBadRequest, gin.H{"errCode": 401, "errMsg": "GetReceiveMessageOpt rpc failed, " + err.Error()})
|
||||
// return
|
||||
// }
|
||||
// log.NewInfo(req.OperationID, "GetReceiveMessageOptReq req: ", req, resp)
|
||||
// var ginResp GetReceiveMessageOptResp
|
||||
// ginResp.ErrCode = resp.ErrCode
|
||||
// ginResp.ErrMsg = resp.ErrMsg
|
||||
//
|
||||
// for _, v := range resp.ConversationOptResult {
|
||||
// var opt OptResult
|
||||
// log.NewInfo("CopyStructFields begin ", v, req.OperationID)
|
||||
// err := utils.CopyStructFields(&opt, *v, "ConversationId", "Result")
|
||||
// log.NewInfo("CopyStructFields end ", v, req.OperationID)
|
||||
// if err != nil {
|
||||
// log.NewError(req.OperationID, "CopyStructFields failed ", err.Error())
|
||||
// continue
|
||||
// }
|
||||
// ginResp.Data = append(ginResp.Data, opt)
|
||||
// }
|
||||
// log.NewInfo(req.OperationID, "GetReceiveMessageOpt resp: ", ginResp)
|
||||
// c.JSON(http.StatusOK, ginResp)
|
||||
//}
|
||||
//
|
||||
func SetReceiveMessageOpt(c *gin.Context) {
|
||||
params := paramsSetReceiveMessageOpt{}
|
||||
if err := c.BindJSON(¶ms); err != nil {
|
||||
log.NewError(params.OperationID, "bind json failed ", err.Error(), c)
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": "bind json failed " + err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
claims, err := token_verify.ParseToken(c.Request.Header.Get("token"))
|
||||
if err != nil {
|
||||
log.NewError(params.OperationID, "ParseToken failed, ", err.Error(), c.Request.Header.Get("token"))
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 401, "errMsg": "ParseToken failed, " + err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
req := &user.SetReceiveMessageOptReq{
|
||||
UId: claims.UID,
|
||||
Opt: *params.Option,
|
||||
ConversationId: params.ConversationIdList,
|
||||
OperationID: params.OperationID,
|
||||
}
|
||||
log.NewInfo(req.OperationID, "SetReceiveMessageOpt req: ", req)
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImUserName)
|
||||
client := user.NewUserClient(etcdConn)
|
||||
resp, err := client.SetReceiveMessageOpt(context.Background(), req)
|
||||
if err != nil {
|
||||
log.NewError(params.OperationID, "SetReceiveMessageOpt rpc failed, ", req, err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 401, "errMsg": "SetReceiveMessageOpt rpc failed, " + err.Error()})
|
||||
return
|
||||
}
|
||||
log.NewInfo(req.OperationID, "SetReceiveMessageOpt req: ", req, resp)
|
||||
ginResp := SetReceiveMessageOptResp{
|
||||
ErrCode: resp.ErrCode,
|
||||
ErrMsg: resp.ErrMsg,
|
||||
}
|
||||
|
||||
for _, v := range resp.OptResult {
|
||||
var opt OptResult
|
||||
log.NewDebug("CopyStructFields begin ", v, req.OperationID)
|
||||
err := utils.CopyStructFields(&opt, *v, "ConversationId", "Result")
|
||||
log.NewDebug("CopyStructFields end ", v, req.OperationID)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "CopyStructFields failed ", err.Error())
|
||||
continue
|
||||
}
|
||||
ginResp.Data = append(ginResp.Data, opt)
|
||||
}
|
||||
log.NewInfo(req.OperationID, "SetReceiveMessageOpt resp: ", ginResp)
|
||||
c.JSON(http.StatusOK, ginResp)
|
||||
}
|
||||
|
||||
//func SetReceiveMessageOpt(c *gin.Context) {
|
||||
// params := paramsSetReceiveMessageOpt{}
|
||||
// if err := c.BindJSON(¶ms); err != nil {
|
||||
// log.NewError(params.OperationID, "bind json failed ", err.Error(), c)
|
||||
// c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": "bind json failed " + err.Error()})
|
||||
// return
|
||||
// }
|
||||
//
|
||||
// claims, err := token_verify.ParseToken(c.Request.Header.Get("token"))
|
||||
// if err != nil {
|
||||
// log.NewError(params.OperationID, "ParseToken failed, ", err.Error(), c.Request.Header.Get("token"))
|
||||
// c.JSON(http.StatusBadRequest, gin.H{"errCode": 401, "errMsg": "ParseToken failed, " + err.Error()})
|
||||
// return
|
||||
// }
|
||||
//
|
||||
// req := &user.SetReceiveMessageOptReq{
|
||||
// UId: claims.UID,
|
||||
// Opt: *params.Option,
|
||||
// ConversationId: params.ConversationIdList,
|
||||
// OperationID: params.OperationID,
|
||||
// }
|
||||
// log.NewInfo(req.OperationID, "SetReceiveMessageOpt req: ", req)
|
||||
// etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImUserName)
|
||||
// client := user.NewUserClient(etcdConn)
|
||||
// resp, err := client.SetReceiveMessageOpt(context.Background(), req)
|
||||
// if err != nil {
|
||||
// log.NewError(params.OperationID, "SetReceiveMessageOpt rpc failed, ", req, err.Error())
|
||||
// c.JSON(http.StatusBadRequest, gin.H{"errCode": 401, "errMsg": "SetReceiveMessageOpt rpc failed, " + err.Error()})
|
||||
// return
|
||||
// }
|
||||
// log.NewInfo(req.OperationID, "SetReceiveMessageOpt req: ", req, resp)
|
||||
// ginResp := SetReceiveMessageOptResp{
|
||||
// ErrCode: resp.ErrCode,
|
||||
// ErrMsg: resp.ErrMsg,
|
||||
// }
|
||||
//
|
||||
// for _, v := range resp.OptResult {
|
||||
// var opt OptResult
|
||||
// log.NewDebug("CopyStructFields begin ", v, req.OperationID)
|
||||
// err := utils.CopyStructFields(&opt, *v, "ConversationId", "Result")
|
||||
// log.NewDebug("CopyStructFields end ", v, req.OperationID)
|
||||
// if err != nil {
|
||||
// log.NewError(req.OperationID, "CopyStructFields failed ", err.Error())
|
||||
// continue
|
||||
// }
|
||||
// ginResp.Data = append(ginResp.Data, opt)
|
||||
// }
|
||||
// log.NewInfo(req.OperationID, "SetReceiveMessageOpt resp: ", ginResp)
|
||||
// c.JSON(http.StatusOK, ginResp)
|
||||
//}
|
||||
|
@ -6,251 +6,164 @@
|
||||
*/
|
||||
package manage
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/common/token_verify"
|
||||
"Open_IM/pkg/grpc-etcdv3/getcdv3"
|
||||
pbChat "Open_IM/pkg/proto/chat"
|
||||
"Open_IM/pkg/proto/sdk_ws"
|
||||
"Open_IM/pkg/utils"
|
||||
"context"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/go-playground/validator/v10"
|
||||
"github.com/mitchellh/mapstructure"
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
import "github.com/gin-gonic/gin"
|
||||
|
||||
var validate *validator.Validate
|
||||
|
||||
type paramsManagementSendMsg struct {
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
SendID string `json:"sendID" binding:"required"`
|
||||
RecvID string `json:"recvID" `
|
||||
GroupID string `json:"groupID" `
|
||||
SenderNickName string `json:"senderNickName" `
|
||||
SenderFaceURL string `json:"senderFaceURL" `
|
||||
SenderPlatformID int32 `json:"senderPlatformID"`
|
||||
ForceList []string `json:"forceList" `
|
||||
Content map[string]interface{} `json:"content" binding:"required"`
|
||||
ContentType int32 `json:"contentType" binding:"required"`
|
||||
SessionType int32 `json:"sessionType" binding:"required"`
|
||||
IsOnlineOnly bool `json:"isOnlineOnly"`
|
||||
OfflinePushInfo *open_im_sdk.OfflinePushInfo `json:"offlinePushInfo"`
|
||||
}
|
||||
|
||||
func newUserSendMsgReq(params *paramsManagementSendMsg) *pbChat.SendMsgReq {
|
||||
var newContent string
|
||||
switch params.ContentType {
|
||||
case constant.Text:
|
||||
newContent = params.Content["text"].(string)
|
||||
case constant.Picture:
|
||||
fallthrough
|
||||
case constant.Custom:
|
||||
fallthrough
|
||||
case constant.Voice:
|
||||
fallthrough
|
||||
case constant.File:
|
||||
newContent = utils.StructToJsonString(params.Content)
|
||||
default:
|
||||
}
|
||||
options := make(map[string]bool, 2)
|
||||
if params.IsOnlineOnly {
|
||||
utils.SetSwitchFromOptions(options, constant.IsOfflinePush, false)
|
||||
utils.SetSwitchFromOptions(options, constant.IsHistory, false)
|
||||
utils.SetSwitchFromOptions(options, constant.IsPersistent, false)
|
||||
}
|
||||
pbData := pbChat.SendMsgReq{
|
||||
OperationID: params.OperationID,
|
||||
MsgData: &open_im_sdk.MsgData{
|
||||
SendID: params.SendID,
|
||||
RecvID: params.RecvID,
|
||||
GroupID: params.GroupID,
|
||||
ClientMsgID: utils.GetMsgID(params.SendID),
|
||||
SenderPlatformID: params.SenderPlatformID,
|
||||
SenderNickName: params.SenderNickName,
|
||||
SenderFaceURL: params.SenderFaceURL,
|
||||
SessionType: params.SessionType,
|
||||
MsgFrom: constant.SysMsgType,
|
||||
ContentType: params.ContentType,
|
||||
Content: []byte(newContent),
|
||||
ForceList: params.ForceList,
|
||||
CreateTime: utils.GetCurrentTimestampByNano(),
|
||||
Options: options,
|
||||
OfflinePushInfo: params.OfflinePushInfo,
|
||||
},
|
||||
}
|
||||
return &pbData
|
||||
}
|
||||
func init() {
|
||||
validate = validator.New()
|
||||
}
|
||||
//
|
||||
//var validate *validator.Validate
|
||||
//
|
||||
//
|
||||
//func newUserSendMsgReq(params *paramsManagementSendMsg) *pbChat.SendMsgReq {
|
||||
// var newContent string
|
||||
// switch params.ContentType {
|
||||
// case constant.Text:
|
||||
// newContent = params.Content["text"].(string)
|
||||
// case constant.Picture:
|
||||
// fallthrough
|
||||
// case constant.Custom:
|
||||
// fallthrough
|
||||
// case constant.Voice:
|
||||
// fallthrough
|
||||
// case constant.File:
|
||||
// newContent = utils.StructToJsonString(params.Content)
|
||||
// default:
|
||||
// }
|
||||
// options := make(map[string]bool, 2)
|
||||
// if params.IsOnlineOnly {
|
||||
// utils.SetSwitchFromOptions(options, constant.IsOfflinePush, false)
|
||||
// utils.SetSwitchFromOptions(options, constant.IsHistory, false)
|
||||
// utils.SetSwitchFromOptions(options, constant.IsPersistent, false)
|
||||
// }
|
||||
// pbData := pbChat.SendMsgReq{
|
||||
// OperationID: params.OperationID,
|
||||
// MsgData: &open_im_sdk.MsgData{
|
||||
// SendID: params.SendID,
|
||||
// RecvID: params.RecvID,
|
||||
// GroupID: params.GroupID,
|
||||
// ClientMsgID: utils.GetMsgID(params.SendID),
|
||||
// SenderPlatformID: params.SenderPlatformID,
|
||||
// SenderNickName: params.SenderNickName,
|
||||
// SenderFaceURL: params.SenderFaceURL,
|
||||
// SessionType: params.SessionType,
|
||||
// MsgFrom: constant.SysMsgType,
|
||||
// ContentType: params.ContentType,
|
||||
// Content: []byte(newContent),
|
||||
// ForceList: params.ForceList,
|
||||
// CreateTime: utils.GetCurrentTimestampByNano(),
|
||||
// Options: options,
|
||||
// OfflinePushInfo: params.OfflinePushInfo,
|
||||
// },
|
||||
// }
|
||||
// return &pbData
|
||||
//}
|
||||
//func init() {
|
||||
// validate = validator.New()
|
||||
//}
|
||||
func ManagementSendMsg(c *gin.Context) {
|
||||
var data interface{}
|
||||
params := paramsManagementSendMsg{}
|
||||
if err := c.BindJSON(¶ms); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||
log.ErrorByKv("json unmarshal err", c.PostForm("operationID"), "err", err.Error(), "content", c.PostForm("content"))
|
||||
return
|
||||
}
|
||||
switch params.ContentType {
|
||||
case constant.Text:
|
||||
data = TextElem{}
|
||||
case constant.Picture:
|
||||
data = PictureElem{}
|
||||
case constant.Voice:
|
||||
data = SoundElem{}
|
||||
case constant.Video:
|
||||
data = VideoElem{}
|
||||
case constant.File:
|
||||
data = FileElem{}
|
||||
//case constant.AtText:
|
||||
// data = AtElem{}
|
||||
//case constant.Merger:
|
||||
// data =
|
||||
//case constant.Card:
|
||||
//case constant.Location:
|
||||
case constant.Custom:
|
||||
data = CustomElem{}
|
||||
//case constant.Revoke:
|
||||
//case constant.HasReadReceipt:
|
||||
//case constant.Typing:
|
||||
//case constant.Quote:
|
||||
default:
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 404, "errMsg": "contentType err"})
|
||||
log.ErrorByKv("contentType err", c.PostForm("operationID"), "content", c.PostForm("content"))
|
||||
return
|
||||
}
|
||||
if err := mapstructure.WeakDecode(params.Content, &data); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 401, "errMsg": err.Error()})
|
||||
log.ErrorByKv("content to Data struct err", "", "err", err.Error())
|
||||
return
|
||||
} else if err := validate.Struct(data); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 403, "errMsg": err.Error()})
|
||||
log.ErrorByKv("data args validate err", "", "err", err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
token := c.Request.Header.Get("token")
|
||||
claims, err := token_verify.ParseToken(token)
|
||||
if err != nil {
|
||||
log.NewError(params.OperationID, "parse token failed", err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": "parse token failed", "sendTime": 0, "MsgID": ""})
|
||||
}
|
||||
if !utils.IsContain(claims.UID, config.Config.Manager.AppManagerUid) {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": "not authorized", "sendTime": 0, "MsgID": ""})
|
||||
return
|
||||
|
||||
}
|
||||
switch params.SessionType {
|
||||
case constant.SingleChatType:
|
||||
if len(params.RecvID) == 0 {
|
||||
log.NewError(params.OperationID, "recvID is a null string")
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 405, "errMsg": "recvID is a null string", "sendTime": 0, "MsgID": ""})
|
||||
}
|
||||
case constant.GroupChatType:
|
||||
if len(params.GroupID) == 0 {
|
||||
log.NewError(params.OperationID, "groupID is a null string")
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 405, "errMsg": "groupID is a null string", "sendTime": 0, "MsgID": ""})
|
||||
}
|
||||
|
||||
}
|
||||
log.InfoByKv("Ws call success to ManagementSendMsgReq", params.OperationID, "Parameters", params)
|
||||
|
||||
pbData := newUserSendMsgReq(¶ms)
|
||||
log.Info("", "", "api ManagementSendMsg call start..., [data: %s]", pbData.String())
|
||||
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImOfflineMessageName)
|
||||
client := pbChat.NewChatClient(etcdConn)
|
||||
|
||||
log.Info("", "", "api ManagementSendMsg call, api call rpc...")
|
||||
|
||||
reply, err := client.SendMsg(context.Background(), pbData)
|
||||
if err != nil {
|
||||
log.NewError(params.OperationID, "call delete UserSendMsg rpc server failed", err.Error())
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "call UserSendMsg rpc server failed"})
|
||||
return
|
||||
}
|
||||
log.Info("", "", "api ManagementSendMsg call end..., [data: %s] [reply: %s]", pbData.String(), reply.String())
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"errCode": reply.ErrCode,
|
||||
"errMsg": reply.ErrMsg,
|
||||
"sendTime": reply.SendTime,
|
||||
"msgID": reply.ClientMsgID,
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
type PictureBaseInfo struct {
|
||||
UUID string `mapstructure:"uuid"`
|
||||
Type string `mapstructure:"type" validate:"required"`
|
||||
Size int64 `mapstructure:"size" validate:"required"`
|
||||
Width int32 `mapstructure:"width" validate:"required"`
|
||||
Height int32 `mapstructure:"height" validate:"required"`
|
||||
Url string `mapstructure:"url" validate:"required"`
|
||||
}
|
||||
|
||||
type PictureElem struct {
|
||||
SourcePath string `mapstructure:"sourcePath"`
|
||||
SourcePicture PictureBaseInfo `mapstructure:"sourcePicture" validate:"required"`
|
||||
BigPicture PictureBaseInfo `mapstructure:"bigPicture" `
|
||||
SnapshotPicture PictureBaseInfo `mapstructure:"snapshotPicture"`
|
||||
}
|
||||
type SoundElem struct {
|
||||
UUID string `mapstructure:"uuid"`
|
||||
SoundPath string `mapstructure:"soundPath"`
|
||||
SourceURL string `mapstructure:"sourceUrl"`
|
||||
DataSize int64 `mapstructure:"dataSize"`
|
||||
Duration int64 `mapstructure:"duration"`
|
||||
}
|
||||
type VideoElem struct {
|
||||
VideoPath string `mapstructure:"videoPath"`
|
||||
VideoUUID string `mapstructure:"videoUUID"`
|
||||
VideoURL string `mapstructure:"videoUrl"`
|
||||
VideoType string `mapstructure:"videoType"`
|
||||
VideoSize int64 `mapstructure:"videoSize"`
|
||||
Duration int64 `mapstructure:"duration"`
|
||||
SnapshotPath string `mapstructure:"snapshotPath"`
|
||||
SnapshotUUID string `mapstructure:"snapshotUUID"`
|
||||
SnapshotSize int64 `mapstructure:"snapshotSize"`
|
||||
SnapshotURL string `mapstructure:"snapshotUrl"`
|
||||
SnapshotWidth int32 `mapstructure:"snapshotWidth"`
|
||||
SnapshotHeight int32 `mapstructure:"snapshotHeight"`
|
||||
}
|
||||
type FileElem struct {
|
||||
FilePath string `mapstructure:"filePath"`
|
||||
UUID string `mapstructure:"uuid"`
|
||||
SourceURL string `mapstructure:"sourceUrl"`
|
||||
FileName string `mapstructure:"fileName"`
|
||||
FileSize int64 `mapstructure:"fileSize"`
|
||||
}
|
||||
//func ManagementSendMsg(c *gin.Context) {
|
||||
// var data interface{}
|
||||
// params := paramsManagementSendMsg{}
|
||||
// if err := c.BindJSON(¶ms); err != nil {
|
||||
// c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||
// log.ErrorByKv("json unmarshal err", c.PostForm("operationID"), "err", err.Error(), "content", c.PostForm("content"))
|
||||
// return
|
||||
// }
|
||||
// switch params.ContentType {
|
||||
// case constant.Text:
|
||||
// data = TextElem{}
|
||||
// case constant.Picture:
|
||||
// data = PictureElem{}
|
||||
// case constant.Voice:
|
||||
// data = SoundElem{}
|
||||
// case constant.Video:
|
||||
// data = VideoElem{}
|
||||
// case constant.File:
|
||||
// data = FileElem{}
|
||||
// //case constant.AtText:
|
||||
// // data = AtElem{}
|
||||
// //case constant.Merger:
|
||||
// // data =
|
||||
// //case constant.Card:
|
||||
// //case constant.Location:
|
||||
// case constant.Custom:
|
||||
// data = CustomElem{}
|
||||
// //case constant.Revoke:
|
||||
// //case constant.HasReadReceipt:
|
||||
// //case constant.Typing:
|
||||
// //case constant.Quote:
|
||||
// default:
|
||||
// c.JSON(http.StatusBadRequest, gin.H{"errCode": 404, "errMsg": "contentType err"})
|
||||
// log.ErrorByKv("contentType err", c.PostForm("operationID"), "content", c.PostForm("content"))
|
||||
// return
|
||||
// }
|
||||
// if err := mapstructure.WeakDecode(params.Content, &data); err != nil {
|
||||
// c.JSON(http.StatusBadRequest, gin.H{"errCode": 401, "errMsg": err.Error()})
|
||||
// log.ErrorByKv("content to Data struct err", "", "err", err.Error())
|
||||
// return
|
||||
// } else if err := validate.Struct(data); err != nil {
|
||||
// c.JSON(http.StatusBadRequest, gin.H{"errCode": 403, "errMsg": err.Error()})
|
||||
// log.ErrorByKv("data args validate err", "", "err", err.Error())
|
||||
// return
|
||||
// }
|
||||
//
|
||||
// token := c.Request.Header.Get("token")
|
||||
// claims, err := token_verify.ParseToken(token)
|
||||
// if err != nil {
|
||||
// log.NewError(params.OperationID, "parse token failed", err.Error())
|
||||
// c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": "parse token failed", "sendTime": 0, "MsgID": ""})
|
||||
// }
|
||||
// if !utils.IsContain(claims.UID, config.Config.Manager.AppManagerUid) {
|
||||
// c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": "not authorized", "sendTime": 0, "MsgID": ""})
|
||||
// return
|
||||
//
|
||||
// }
|
||||
// switch params.SessionType {
|
||||
// case constant.SingleChatType:
|
||||
// if len(params.RecvID) == 0 {
|
||||
// log.NewError(params.OperationID, "recvID is a null string")
|
||||
// c.JSON(http.StatusBadRequest, gin.H{"errCode": 405, "errMsg": "recvID is a null string", "sendTime": 0, "MsgID": ""})
|
||||
// }
|
||||
// case constant.GroupChatType:
|
||||
// if len(params.GroupID) == 0 {
|
||||
// log.NewError(params.OperationID, "groupID is a null string")
|
||||
// c.JSON(http.StatusBadRequest, gin.H{"errCode": 405, "errMsg": "groupID is a null string", "sendTime": 0, "MsgID": ""})
|
||||
// }
|
||||
//
|
||||
// }
|
||||
// log.InfoByKv("Ws call success to ManagementSendMsgReq", params.OperationID, "Parameters", params)
|
||||
//
|
||||
// pbData := newUserSendMsgReq(¶ms)
|
||||
// log.Info("", "", "api ManagementSendMsg call start..., [data: %s]", pbData.String())
|
||||
//
|
||||
// etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImOfflineMessageName)
|
||||
// client := pbChat.NewChatClient(etcdConn)
|
||||
//
|
||||
// log.Info("", "", "api ManagementSendMsg call, api call rpc...")
|
||||
//
|
||||
// reply, err := client.SendMsg(context.Background(), pbData)
|
||||
// if err != nil {
|
||||
// log.NewError(params.OperationID, "call delete UserSendMsg rpc server failed", err.Error())
|
||||
// c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "call UserSendMsg rpc server failed"})
|
||||
// return
|
||||
// }
|
||||
// log.Info("", "", "api ManagementSendMsg call end..., [data: %s] [reply: %s]", pbData.String(), reply.String())
|
||||
//
|
||||
// c.JSON(http.StatusOK, gin.H{
|
||||
// "errCode": reply.ErrCode,
|
||||
// "errMsg": reply.ErrMsg,
|
||||
// "sendTime": reply.SendTime,
|
||||
// "msgID": reply.ClientMsgID,
|
||||
// })
|
||||
//
|
||||
//}
|
||||
|
||||
//type MergeElem struct {
|
||||
// Title string `json:"title"`
|
||||
// AbstractList []string `json:"abstractList"`
|
||||
// MultiMessage []*MsgStruct `json:"multiMessage"`
|
||||
//}
|
||||
type AtElem struct {
|
||||
Text string `mapstructure:"text"`
|
||||
AtUserList []string `mapstructure:"atUserList"`
|
||||
IsAtSelf bool `mapstructure:"isAtSelf"`
|
||||
}
|
||||
type LocationElem struct {
|
||||
Description string `mapstructure:"description"`
|
||||
Longitude float64 `mapstructure:"longitude"`
|
||||
Latitude float64 `mapstructure:"latitude"`
|
||||
}
|
||||
type CustomElem struct {
|
||||
Data string `mapstructure:"data" validate:"required"`
|
||||
Description string `mapstructure:"description"`
|
||||
Extension string `mapstructure:"extension"`
|
||||
}
|
||||
type TextElem struct {
|
||||
Text string `mapstructure:"text" validate:"required"`
|
||||
}
|
||||
|
||||
//type QuoteElem struct {
|
||||
// Text string `json:"text"`
|
||||
|
@ -6,178 +6,154 @@
|
||||
*/
|
||||
package manage
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/common/token_verify"
|
||||
"Open_IM/pkg/grpc-etcdv3/getcdv3"
|
||||
pbRelay "Open_IM/pkg/proto/relay"
|
||||
pbUser "Open_IM/pkg/proto/user"
|
||||
"Open_IM/pkg/utils"
|
||||
"context"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type paramsDeleteUsers struct {
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
DeleteUidList []string `json:"deleteUidList" binding:"required"`
|
||||
}
|
||||
type paramsGetAllUsersUid struct {
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
}
|
||||
type paramsGetUsersOnlineStatus struct {
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
UserIDList []string `json:"userIDList" binding:"required,lte=200"`
|
||||
}
|
||||
type paramsAccountCheck struct {
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
UserIDList []string `json:"userIDList" binding:"required,lte=100"`
|
||||
}
|
||||
import "github.com/gin-gonic/gin"
|
||||
|
||||
func DeleteUser(c *gin.Context) {
|
||||
params := paramsDeleteUsers{}
|
||||
if err := c.BindJSON(¶ms); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
log.InfoByKv("DeleteUser req come here", params.OperationID, "DeleteUidList", params.DeleteUidList)
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImUserName)
|
||||
client := pbUser.NewUserClient(etcdConn)
|
||||
//defer etcdConn.Close()
|
||||
|
||||
req := &pbUser.DeleteUsersReq{
|
||||
OperationID: params.OperationID,
|
||||
DeleteUidList: params.DeleteUidList,
|
||||
Token: c.Request.Header.Get("token"),
|
||||
}
|
||||
RpcResp, err := client.DeleteUsers(context.Background(), req)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "call delete users rpc server failed", err.Error())
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "call delete users rpc server failed"})
|
||||
return
|
||||
}
|
||||
failedUidList := make([]string, 0)
|
||||
for _, v := range RpcResp.FailedUidList {
|
||||
failedUidList = append(failedUidList, v)
|
||||
}
|
||||
log.InfoByKv("call delete user rpc server is success", params.OperationID, "resp args", RpcResp.String())
|
||||
resp := gin.H{"errCode": RpcResp.CommonResp.ErrorCode, "errMsg": RpcResp.CommonResp.ErrorMsg, "failedUidList": RpcResp.FailedUidList}
|
||||
c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
func GetAllUsersUid(c *gin.Context) {
|
||||
params := paramsGetAllUsersUid{}
|
||||
if err := c.BindJSON(¶ms); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
log.InfoByKv("GetAllUsersUid req come here", params.OperationID)
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImUserName)
|
||||
client := pbUser.NewUserClient(etcdConn)
|
||||
//defer etcdConn.Close()
|
||||
|
||||
req := &pbUser.GetAllUsersUidReq{
|
||||
OperationID: params.OperationID,
|
||||
Token: c.Request.Header.Get("token"),
|
||||
}
|
||||
RpcResp, err := client.GetAllUsersUid(context.Background(), req)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": err.Error(), "uidList": []string{}})
|
||||
return
|
||||
}
|
||||
log.InfoByKv("call GetAllUsersUid rpc server is success", params.OperationID, "resp args", RpcResp.String())
|
||||
resp := gin.H{"errCode": RpcResp.CommonResp.ErrorCode, "errMsg": RpcResp.CommonResp.ErrorMsg, "uidList": RpcResp.UidList}
|
||||
c.JSON(http.StatusOK, resp)
|
||||
|
||||
}
|
||||
func AccountCheck(c *gin.Context) {
|
||||
params := paramsAccountCheck{}
|
||||
if err := c.BindJSON(¶ms); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
log.InfoByKv("AccountCheck req come here", params.OperationID, params.UserIDList)
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImUserName)
|
||||
client := pbUser.NewUserClient(etcdConn)
|
||||
//defer etcdConn.Close()
|
||||
|
||||
req := &pbUser.AccountCheckReq{
|
||||
OperationID: params.OperationID,
|
||||
Token: c.Request.Header.Get("token"),
|
||||
UidList: params.UserIDList,
|
||||
}
|
||||
RpcResp, err := client.AccountCheck(context.Background(), req)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
log.InfoByKv("call AccountCheck rpc server is success", params.OperationID, "resp args", RpcResp.String())
|
||||
resp := gin.H{"errCode": RpcResp.CommonResp.ErrorCode, "errMsg": RpcResp.CommonResp.ErrorMsg, "result": RpcResp.Result}
|
||||
c.JSON(http.StatusOK, resp)
|
||||
|
||||
}
|
||||
func GetUsersOnlineStatus(c *gin.Context) {
|
||||
params := paramsGetUsersOnlineStatus{}
|
||||
if err := c.BindJSON(¶ms); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
claims, err := token_verify.ParseToken(c.Request.Header.Get("token"))
|
||||
if err != nil {
|
||||
log.ErrorByKv("parse token failed", params.OperationID, "err", err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 401, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
if !utils.IsContain(claims.UID, config.Config.Manager.AppManagerUid) {
|
||||
log.ErrorByKv(" Authentication failed", params.OperationID, "args", c)
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 402, "errMsg": "not authorized"})
|
||||
return
|
||||
}
|
||||
req := &pbRelay.GetUsersOnlineStatusReq{
|
||||
OperationID: params.OperationID,
|
||||
UserIDList: params.UserIDList,
|
||||
}
|
||||
var wsResult []*pbRelay.GetUsersOnlineStatusResp_SuccessResult
|
||||
var respResult []*pbRelay.GetUsersOnlineStatusResp_SuccessResult
|
||||
flag := false
|
||||
log.NewDebug(params.OperationID, "GetUsersOnlineStatus req come here", params.UserIDList)
|
||||
grpcCons := getcdv3.GetConn4Unique(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImOnlineMessageRelayName)
|
||||
for _, v := range grpcCons {
|
||||
client := pbRelay.NewOnlineMessageRelayServiceClient(v)
|
||||
reply, err := client.GetUsersOnlineStatus(context.Background(), req)
|
||||
if err != nil {
|
||||
log.NewError(params.OperationID, "GetUsersOnlineStatus rpc err", req.String(), err.Error())
|
||||
continue
|
||||
} else {
|
||||
if reply.ErrCode == 0 {
|
||||
wsResult = append(wsResult, reply.SuccessResult...)
|
||||
}
|
||||
}
|
||||
}
|
||||
log.NewDebug(params.OperationID, "call GetUsersOnlineStatus rpc server is success", wsResult)
|
||||
//Online data merge of each node
|
||||
for _, v1 := range params.UserIDList {
|
||||
flag = false
|
||||
temp := new(pbRelay.GetUsersOnlineStatusResp_SuccessResult)
|
||||
for _, v2 := range wsResult {
|
||||
if v2.UserID == v1 {
|
||||
flag = true
|
||||
temp.UserID = v1
|
||||
temp.Status = constant.OnlineStatus
|
||||
temp.DetailPlatformStatus = append(temp.DetailPlatformStatus, v2.DetailPlatformStatus...)
|
||||
}
|
||||
|
||||
}
|
||||
if !flag {
|
||||
temp.UserID = v1
|
||||
temp.Status = constant.OfflineStatus
|
||||
}
|
||||
respResult = append(respResult, temp)
|
||||
}
|
||||
log.NewDebug(params.OperationID, "Finished merged data", respResult)
|
||||
resp := gin.H{"errCode": 0, "errMsg": "", "successResult": respResult}
|
||||
c.JSON(http.StatusOK, resp)
|
||||
|
||||
}
|
||||
//
|
||||
//func DeleteUser(c *gin.Context) {
|
||||
// params := paramsDeleteUsers{}
|
||||
// if err := c.BindJSON(¶ms); err != nil {
|
||||
// c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||
// return
|
||||
// }
|
||||
// log.InfoByKv("DeleteUser req come here", params.OperationID, "DeleteUidList", params.DeleteUidList)
|
||||
// etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImUserName)
|
||||
// client := pbUser.NewUserClient(etcdConn)
|
||||
// //defer etcdConn.Close()
|
||||
//
|
||||
// req := &pbUser.DeleteUsersReq{
|
||||
// OperationID: params.OperationID,
|
||||
// DeleteUidList: params.DeleteUidList,
|
||||
// Token: c.Request.Header.Get("token"),
|
||||
// }
|
||||
// RpcResp, err := client.DeleteUsers(context.Background(), req)
|
||||
// if err != nil {
|
||||
// log.NewError(req.OperationID, "call delete users rpc server failed", err.Error())
|
||||
// c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "call delete users rpc server failed"})
|
||||
// return
|
||||
// }
|
||||
// failedUidList := make([]string, 0)
|
||||
// for _, v := range RpcResp.FailedUidList {
|
||||
// failedUidList = append(failedUidList, v)
|
||||
// }
|
||||
// log.InfoByKv("call delete user rpc server is success", params.OperationID, "resp args", RpcResp.String())
|
||||
// resp := gin.H{"errCode": RpcResp.CommonResp.ErrorCode, "errMsg": RpcResp.CommonResp.ErrorMsg, "failedUidList": RpcResp.FailedUidList}
|
||||
// c.JSON(http.StatusOK, resp)
|
||||
//}
|
||||
//func GetAllUsersUid(c *gin.Context) {
|
||||
// params := paramsGetAllUsersUid{}
|
||||
// if err := c.BindJSON(¶ms); err != nil {
|
||||
// c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||
// return
|
||||
// }
|
||||
// log.InfoByKv("GetAllUsersUid req come here", params.OperationID)
|
||||
// etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImUserName)
|
||||
// client := pbUser.NewUserClient(etcdConn)
|
||||
// //defer etcdConn.Close()
|
||||
//
|
||||
// req := &pbUser.GetAllUsersUidReq{
|
||||
// OperationID: params.OperationID,
|
||||
// Token: c.Request.Header.Get("token"),
|
||||
// }
|
||||
// RpcResp, err := client.GetAllUsersUid(context.Background(), req)
|
||||
// if err != nil {
|
||||
// c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": err.Error(), "uidList": []string{}})
|
||||
// return
|
||||
// }
|
||||
// log.InfoByKv("call GetAllUsersUid rpc server is success", params.OperationID, "resp args", RpcResp.String())
|
||||
// resp := gin.H{"errCode": RpcResp.CommonResp.ErrorCode, "errMsg": RpcResp.CommonResp.ErrorMsg, "uidList": RpcResp.UidList}
|
||||
// c.JSON(http.StatusOK, resp)
|
||||
//
|
||||
//}
|
||||
//func AccountCheck(c *gin.Context) {
|
||||
// params := paramsAccountCheck{}
|
||||
// if err := c.BindJSON(¶ms); err != nil {
|
||||
// c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||
// return
|
||||
// }
|
||||
// log.InfoByKv("AccountCheck req come here", params.OperationID, params.UserIDList)
|
||||
// etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImUserName)
|
||||
// client := pbUser.NewUserClient(etcdConn)
|
||||
// //defer etcdConn.Close()
|
||||
//
|
||||
// req := &pbUser.AccountCheckReq{
|
||||
// OperationID: params.OperationID,
|
||||
// Token: c.Request.Header.Get("token"),
|
||||
// UidList: params.UserIDList,
|
||||
// }
|
||||
// RpcResp, err := client.AccountCheck(context.Background(), req)
|
||||
// if err != nil {
|
||||
// c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": err.Error()})
|
||||
// return
|
||||
// }
|
||||
// log.InfoByKv("call AccountCheck rpc server is success", params.OperationID, "resp args", RpcResp.String())
|
||||
// resp := gin.H{"errCode": RpcResp.CommonResp.ErrorCode, "errMsg": RpcResp.CommonResp.ErrorMsg, "result": RpcResp.Result}
|
||||
// c.JSON(http.StatusOK, resp)
|
||||
//
|
||||
//}
|
||||
//func GetUsersOnlineStatus(c *gin.Context) {
|
||||
// params := paramsGetUsersOnlineStatus{}
|
||||
// if err := c.BindJSON(¶ms); err != nil {
|
||||
// c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||
// return
|
||||
// }
|
||||
// claims, err := token_verify.ParseToken(c.Request.Header.Get("token"))
|
||||
// if err != nil {
|
||||
// log.ErrorByKv("parse token failed", params.OperationID, "err", err.Error())
|
||||
// c.JSON(http.StatusBadRequest, gin.H{"errCode": 401, "errMsg": err.Error()})
|
||||
// return
|
||||
// }
|
||||
// if !utils.IsContain(claims.UID, config.Config.Manager.AppManagerUid) {
|
||||
// log.ErrorByKv(" Authentication failed", params.OperationID, "args", c)
|
||||
// c.JSON(http.StatusBadRequest, gin.H{"errCode": 402, "errMsg": "not authorized"})
|
||||
// return
|
||||
// }
|
||||
// req := &pbRelay.GetUsersOnlineStatusReq{
|
||||
// OperationID: params.OperationID,
|
||||
// UserIDList: params.UserIDList,
|
||||
// }
|
||||
// var wsResult []*pbRelay.GetUsersOnlineStatusResp_SuccessResult
|
||||
// var respResult []*pbRelay.GetUsersOnlineStatusResp_SuccessResult
|
||||
// flag := false
|
||||
// log.NewDebug(params.OperationID, "GetUsersOnlineStatus req come here", params.UserIDList)
|
||||
// grpcCons := getcdv3.GetConn4Unique(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImOnlineMessageRelayName)
|
||||
// for _, v := range grpcCons {
|
||||
// client := pbRelay.NewOnlineMessageRelayServiceClient(v)
|
||||
// reply, err := client.GetUsersOnlineStatus(context.Background(), req)
|
||||
// if err != nil {
|
||||
// log.NewError(params.OperationID, "GetUsersOnlineStatus rpc err", req.String(), err.Error())
|
||||
// continue
|
||||
// } else {
|
||||
// if reply.ErrCode == 0 {
|
||||
// wsResult = append(wsResult, reply.SuccessResult...)
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// log.NewDebug(params.OperationID, "call GetUsersOnlineStatus rpc server is success", wsResult)
|
||||
// //Online data merge of each node
|
||||
// for _, v1 := range params.UserIDList {
|
||||
// flag = false
|
||||
// temp := new(pbRelay.GetUsersOnlineStatusResp_SuccessResult)
|
||||
// for _, v2 := range wsResult {
|
||||
// if v2.UserID == v1 {
|
||||
// flag = true
|
||||
// temp.UserID = v1
|
||||
// temp.Status = constant.OnlineStatus
|
||||
// temp.DetailPlatformStatus = append(temp.DetailPlatformStatus, v2.DetailPlatformStatus...)
|
||||
// }
|
||||
//
|
||||
// }
|
||||
// if !flag {
|
||||
// temp.UserID = v1
|
||||
// temp.Status = constant.OfflineStatus
|
||||
// }
|
||||
// respResult = append(respResult, temp)
|
||||
// }
|
||||
// log.NewDebug(params.OperationID, "Finished merged data", respResult)
|
||||
// resp := gin.H{"errCode": 0, "errMsg": "", "successResult": respResult}
|
||||
// c.JSON(http.StatusOK, resp)
|
||||
//
|
||||
//}
|
||||
|
@ -7,6 +7,7 @@ import (
|
||||
imdb "Open_IM/pkg/common/db/mysql_model/im_mysql_model"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/common/token_verify"
|
||||
cp "Open_IM/pkg/common/utils"
|
||||
"Open_IM/pkg/grpc-etcdv3/getcdv3"
|
||||
pbFriend "Open_IM/pkg/proto/friend"
|
||||
sdkws "Open_IM/pkg/proto/sdk_ws"
|
||||
@ -16,6 +17,7 @@ import (
|
||||
"net"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
type friendServer struct {
|
||||
@ -226,6 +228,7 @@ func (s *friendServer) AddFriendResponse(ctx context.Context, req *pbFriend.AddF
|
||||
}
|
||||
friendRequest.HandleResult = req.Flag
|
||||
friendRequest.HandleTime = time.Now()
|
||||
//friendRequest.HandleTime.Unix()
|
||||
friendRequest.HandleMsg = req.HandleMsg
|
||||
friendRequest.HandlerUserID = req.CommID.OpUserID
|
||||
err = imdb.UpdateFriendApplication(friendRequest)
|
||||
@ -454,7 +457,7 @@ func (s *friendServer) GetSelfApplyList(ctx context.Context, req *pbFriend.GetSe
|
||||
var selfApplyOtherUserList []*sdkws.FriendRequest
|
||||
for _, selfApplyOtherUserInfo := range usersInfo {
|
||||
var userInfo sdkws.FriendRequest // pbFriend.ApplyUserInfo
|
||||
utils.FriendRequestDBCopyOpenIM(&userInfo, selfApplyOtherUserInfo)
|
||||
cp.FriendRequestDBCopyOpenIM(&userInfo, selfApplyOtherUserInfo)
|
||||
selfApplyOtherUserList = append(selfApplyOtherUserList, &userInfo)
|
||||
}
|
||||
log.NewInfo(req.CommID.OperationID, "rpc GetSelfApplyList ok", pbFriend.GetSelfApplyListResp{FriendRequestList: selfApplyOtherUserList})
|
||||
|
@ -171,7 +171,7 @@ func (s *groupServer) GetJoinedGroupList(ctx context.Context, req *pbGroup.GetJo
|
||||
group, err := imdb.GetGroupInfoByGroupID(v)
|
||||
if num > 0 && owner != nil && err2 == nil && group != nil && err == nil {
|
||||
utils.CopyStructFields(&groupNode, group)
|
||||
groupNode.CreateTime = group.CreateTime
|
||||
groupNode.CreateTime = group.CreateTime.Unix()
|
||||
groupNode.MemberCount = uint32(num)
|
||||
groupNode.OwnerUserID = owner.UserID
|
||||
resp.GroupList = append(resp.GroupList, &groupNode)
|
||||
@ -379,7 +379,7 @@ func (s *groupServer) GetGroupMembersInfo(ctx context.Context, req *pbGroup.GetG
|
||||
continue
|
||||
} else {
|
||||
utils.CopyStructFields(&memberNode, memberInfo)
|
||||
memberNode.JoinTime = memberInfo.JoinTime
|
||||
memberNode.JoinTime = memberInfo.JoinTime.Unix()
|
||||
resp.MemberList = append(resp.MemberList, &memberNode)
|
||||
}
|
||||
}
|
||||
@ -416,7 +416,7 @@ func (s *groupServer) GetGroupsInfo(ctx context.Context, req *pbGroup.GetGroupsI
|
||||
}
|
||||
var groupInfo open_im_sdk.GroupInfo
|
||||
utils.CopyStructFields(&groupInfo, groupInfoFromMysql)
|
||||
groupInfo.CreateTime = groupInfoFromMysql.CreateTime
|
||||
groupInfo.CreateTime = groupInfoFromMysql.CreateTime.Unix()
|
||||
groupsInfoList = append(groupsInfoList, &groupInfo)
|
||||
}
|
||||
|
||||
@ -451,7 +451,7 @@ func (s *groupServer) GroupApplicationResponse(_ context.Context, req *pbGroup.G
|
||||
|
||||
func (s *groupServer) JoinGroup(ctx context.Context, req *pbGroup.JoinGroupReq) (*pbGroup.JoinGroupResp, error) {
|
||||
log.NewInfo(req.OperationID, "JoinGroup args ", req.String())
|
||||
applicationUserInfo, err := imdb.GetUserByUserID(req.OpUserID)
|
||||
_, err := imdb.GetUserByUserID(req.OpUserID)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "FindUserByUID failed ", err.Error(), req.OpUserID)
|
||||
return &pbGroup.JoinGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
|
||||
@ -516,6 +516,7 @@ func hasAccess(req *pbGroup.SetGroupInfoReq) bool {
|
||||
if groupUserInfo.RoleLevel == constant.OrdinaryMember {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (s *groupServer) SetGroupInfo(ctx context.Context, req *pbGroup.SetGroupInfoReq) (*pbGroup.SetGroupInfoResp, error) {
|
||||
|
@ -1,6 +1,7 @@
|
||||
package msg
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/constant"
|
||||
imdb "Open_IM/pkg/common/db/mysql_model/im_mysql_model"
|
||||
"Open_IM/pkg/common/log"
|
||||
@ -20,6 +21,7 @@ import (
|
||||
//} creator->group
|
||||
|
||||
func setOpUserInfo(operationID, opUserID, groupID string, groupMemberInfo *open_im_sdk.GroupMemberFullInfo) {
|
||||
return
|
||||
if token_verify.IsMangerUserID(opUserID) {
|
||||
u, err := imdb.GetUserByUserID(opUserID)
|
||||
if err != nil {
|
||||
@ -39,6 +41,7 @@ func setOpUserInfo(operationID, opUserID, groupID string, groupMemberInfo *open_
|
||||
}
|
||||
|
||||
func setGroupInfo(operationID, groupID string, groupInfo *open_im_sdk.GroupInfo, ownerUserID string) {
|
||||
return
|
||||
group, err := imdb.GetGroupInfoByGroupID(groupID)
|
||||
if err != nil {
|
||||
log.NewError(operationID, "FindGroupInfoByGroupId failed ", err.Error(), groupID)
|
||||
@ -53,6 +56,7 @@ func setGroupInfo(operationID, groupID string, groupInfo *open_im_sdk.GroupInfo,
|
||||
}
|
||||
|
||||
func setGroupMemberInfo(operationID, groupID, userID string, groupMemberInfo *open_im_sdk.GroupMemberFullInfo) {
|
||||
return
|
||||
group, err := imdb.GetGroupMemberInfoByGroupIDAndUserID(groupID, userID)
|
||||
if err != nil {
|
||||
log.NewError(operationID, "FindGroupMemberInfoByGroupIdAndUserId failed ", err.Error(), groupID, userID)
|
||||
@ -72,6 +76,7 @@ func setGroupMemberInfo(operationID, groupID, userID string, groupMemberInfo *op
|
||||
|
||||
//创建群后调用
|
||||
func GroupCreatedNotification(operationID, opUserID, OwnerUserID, groupID string, initMemberList []string) {
|
||||
return
|
||||
var n NotificationMsg
|
||||
n.SendID = opUserID
|
||||
n.RecvID = groupID
|
||||
@ -109,6 +114,7 @@ func GroupCreatedNotification(operationID, opUserID, OwnerUserID, groupID string
|
||||
// OperationID string `protobuf:"bytes,4,opt,name=OperationID" json:"OperationID,omitempty"`
|
||||
//申请进群后调用
|
||||
func JoinApplicationNotification(req *pbGroup.JoinGroupReq) {
|
||||
return
|
||||
managerList, err := imdb.GetOwnerManagerByGroupID(req.GroupID)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "GetOwnerManagerByGroupId failed ", err.Error(), req.GroupID)
|
||||
@ -151,6 +157,7 @@ func JoinApplicationNotification(req *pbGroup.JoinGroupReq) {
|
||||
//}
|
||||
//处理进群请求后调用
|
||||
func ApplicationProcessedNotification(req *pbGroup.GroupApplicationResponseReq) {
|
||||
return
|
||||
var n NotificationMsg
|
||||
n.SendID = req.OpUserID
|
||||
n.ContentType = constant.ApplicationProcessedNotification
|
||||
@ -181,6 +188,7 @@ func ApplicationProcessedNotification(req *pbGroup.GroupApplicationResponseReq)
|
||||
//}
|
||||
//被邀请进群后调用
|
||||
func MemberInvitedNotification(operationID, groupID, opUserID, reason string, invitedUserIDList []string) {
|
||||
return
|
||||
var n NotificationMsg
|
||||
n.SendID = opUserID
|
||||
n.ContentType = constant.MemberInvitedNotification
|
||||
@ -212,6 +220,7 @@ func MemberInvitedNotification(operationID, groupID, opUserID, reason string, in
|
||||
//}
|
||||
//被踢后调用
|
||||
func MemberKickedNotification(req *pbGroup.KickGroupMemberReq, kickedUserIDList []string) {
|
||||
return
|
||||
var n NotificationMsg
|
||||
n.SendID = req.OpUserID
|
||||
n.ContentType = constant.MemberKickedNotification
|
||||
@ -249,6 +258,7 @@ func MemberKickedNotification(req *pbGroup.KickGroupMemberReq, kickedUserIDList
|
||||
|
||||
//群信息改变后掉用
|
||||
func GroupInfoChangedNotification(operationID, opUserID, groupID string, changedType int32) {
|
||||
return
|
||||
var n NotificationMsg
|
||||
n.SendID = opUserID
|
||||
n.ContentType = constant.GroupInfoChangedNotification
|
||||
@ -301,6 +311,7 @@ func GroupInfoChangedNotification(operationID string, changedType int32, group *
|
||||
|
||||
//群成员退群后调用
|
||||
func MemberLeaveNotification(req *pbGroup.QuitGroupReq) {
|
||||
return
|
||||
var n NotificationMsg
|
||||
n.SendID = req.OpUserID
|
||||
n.ContentType = constant.MemberLeaveNotification
|
||||
@ -331,6 +342,7 @@ func MemberLeaveNotification(req *pbGroup.QuitGroupReq) {
|
||||
//}
|
||||
//群成员主动申请进群,管理员同意后调用,
|
||||
func MemberEnterNotification(req *pbGroup.GroupApplicationResponseReq) {
|
||||
return
|
||||
var n NotificationMsg
|
||||
n.SendID = req.OpUserID
|
||||
n.ContentType = constant.MemberEnterNotification
|
||||
@ -369,6 +381,7 @@ func MemberEnterNotification(req *pbGroup.GroupApplicationResponseReq) {
|
||||
//}
|
||||
|
||||
func getFromToUserNickname(operationID, fromUserID, toUserID string) (string, string) {
|
||||
return
|
||||
from, err1 := imdb.GetUserByUserID(fromUserID)
|
||||
to, err2 := imdb.GetUserByUserID(toUserID)
|
||||
if err1 != nil || err2 != nil {
|
||||
@ -385,6 +398,7 @@ func getFromToUserNickname(operationID, fromUserID, toUserID string) (string, st
|
||||
}
|
||||
|
||||
func FriendApplicationAddedNotification(req *pbFriend.AddFriendReq) {
|
||||
return
|
||||
var n NotificationMsg
|
||||
n.SendID = req.CommID.FromUserID
|
||||
n.RecvID = req.CommID.ToUserID
|
||||
@ -405,6 +419,7 @@ func FriendApplicationAddedNotification(req *pbFriend.AddFriendReq) {
|
||||
}
|
||||
|
||||
func FriendApplicationProcessedNotification(req *pbFriend.AddFriendResponseReq) {
|
||||
return
|
||||
var n NotificationMsg
|
||||
n.SendID = req.CommID.FromUserID
|
||||
n.RecvID = req.CommID.ToUserID
|
||||
@ -425,6 +440,7 @@ func FriendApplicationProcessedNotification(req *pbFriend.AddFriendResponseReq)
|
||||
}
|
||||
|
||||
func FriendAddedNotification(operationID, opUserID, fromUserID, toUserID string) {
|
||||
return
|
||||
var n NotificationMsg
|
||||
n.SendID = fromUserID
|
||||
n.RecvID = toUserID
|
||||
@ -478,6 +494,7 @@ func FriendAddedNotification(operationID, opUserID, fromUserID, toUserID string)
|
||||
// FriendInfo Friend = 1;
|
||||
//}
|
||||
func FriendDeletedNotification(req *pbFriend.DeleteFriendReq) {
|
||||
return
|
||||
var n NotificationMsg
|
||||
n.SendID = req.CommID.FromUserID
|
||||
n.RecvID = req.CommID.ToUserID
|
||||
@ -503,6 +520,7 @@ func FriendDeletedNotification(req *pbFriend.DeleteFriendReq) {
|
||||
// uint64 OperationTime = 3;
|
||||
//}
|
||||
func FriendInfoChangedNotification(operationID, opUserID, fromUserID, toUserID string) {
|
||||
return
|
||||
var n NotificationMsg
|
||||
n.SendID = fromUserID
|
||||
n.RecvID = toUserID
|
||||
@ -523,6 +541,7 @@ func FriendInfoChangedNotification(operationID, opUserID, fromUserID, toUserID s
|
||||
}
|
||||
|
||||
func BlackAddedNotification(req *pbFriend.AddBlacklistReq) {
|
||||
return
|
||||
var n NotificationMsg
|
||||
n.SendID = req.CommID.FromUserID
|
||||
n.RecvID = req.CommID.ToUserID
|
||||
@ -546,6 +565,7 @@ func BlackAddedNotification(req *pbFriend.AddBlacklistReq) {
|
||||
// BlackInfo Black = 1;
|
||||
//}
|
||||
func BlackDeletedNotification(req *pbFriend.RemoveBlacklistReq) {
|
||||
return
|
||||
var n NotificationMsg
|
||||
n.SendID = req.CommID.FromUserID
|
||||
n.RecvID = req.CommID.ToUserID
|
||||
@ -571,6 +591,7 @@ func BlackDeletedNotification(req *pbFriend.RemoveBlacklistReq) {
|
||||
// uint64 OperationTime = 3;
|
||||
//}
|
||||
func SelfInfoUpdatedNotification(operationID, userID string) {
|
||||
return
|
||||
var n NotificationMsg
|
||||
n.SendID = userID
|
||||
n.RecvID = userID
|
||||
|
@ -10,6 +10,7 @@ import (
|
||||
"Open_IM/pkg/common/token_verify"
|
||||
"Open_IM/pkg/grpc-etcdv3/getcdv3"
|
||||
pbFriend "Open_IM/pkg/proto/friend"
|
||||
sdkws "Open_IM/pkg/proto/sdk_ws"
|
||||
pbUser "Open_IM/pkg/proto/user"
|
||||
"Open_IM/pkg/utils"
|
||||
"context"
|
||||
@ -17,7 +18,6 @@ import (
|
||||
"net"
|
||||
"strconv"
|
||||
"strings"
|
||||
sdkws "Open_IM/pkg/proto/sdk_ws"
|
||||
)
|
||||
|
||||
type userServer struct {
|
||||
@ -27,6 +27,16 @@ type userServer struct {
|
||||
etcdAddr []string
|
||||
}
|
||||
|
||||
func NewUserServer(port int) *userServer {
|
||||
log.NewPrivateLog("user")
|
||||
return &userServer{
|
||||
rpcPort: port,
|
||||
rpcRegisterName: config.Config.RpcRegisterName.OpenImUserName,
|
||||
etcdSchema: config.Config.Etcd.EtcdSchema,
|
||||
etcdAddr: config.Config.Etcd.EtcdAddr,
|
||||
}
|
||||
}
|
||||
|
||||
func (s *userServer) Run() {
|
||||
log.NewInfo("0", "", "rpc user start...")
|
||||
|
||||
@ -38,7 +48,7 @@ func (s *userServer) Run() {
|
||||
log.NewError("0", "listen network failed ", err.Error(), registerAddress)
|
||||
return
|
||||
}
|
||||
log.NewInfo("0", "listen network success, address ", registerAddress, listener)
|
||||
log.NewInfo("0", "listen network success, address ", registerAddress, listener)
|
||||
defer listener.Close()
|
||||
//grpc server
|
||||
srv := grpc.NewServer()
|
||||
@ -55,7 +65,7 @@ func (s *userServer) Run() {
|
||||
log.NewError("0", "Serve failed ", err.Error())
|
||||
return
|
||||
}
|
||||
log.NewInfo("0", "rpc user success")
|
||||
log.NewInfo("0", "rpc user success")
|
||||
}
|
||||
|
||||
func (s *userServer) GetUserInfo(ctx context.Context, req *pbUser.GetUserInfoReq) (*pbUser.GetUserInfoResp, error) {
|
||||
@ -76,12 +86,10 @@ func (s *userServer) GetUserInfo(ctx context.Context, req *pbUser.GetUserInfoReq
|
||||
|
||||
return &pbUser.GetUserInfoResp{CommonResp: &pbUser.CommonResp{ErrCode: constant.ErrArgs.ErrCode, ErrMsg: constant.ErrArgs.ErrMsg}}, nil
|
||||
}
|
||||
log.NewInfo(req.OperationID, "GetUserInfo rpc return ", pbUser.GetUserInfoResp{CommonResp: &pbUser.CommonResp{}, UserInfoList:userInfoList})
|
||||
return &pbUser.GetUserInfoResp{CommonResp: &pbUser.CommonResp{}, UserInfoList:userInfoList}, nil
|
||||
log.NewInfo(req.OperationID, "GetUserInfo rpc return ", pbUser.GetUserInfoResp{CommonResp: &pbUser.CommonResp{}, UserInfoList: userInfoList})
|
||||
return &pbUser.GetUserInfoResp{CommonResp: &pbUser.CommonResp{}, UserInfoList: userInfoList}, nil
|
||||
}
|
||||
|
||||
|
||||
|
||||
func (s *userServer) SetReceiveMessageOpt(ctx context.Context, req *pbUser.SetReceiveMessageOptReq) (*pbUser.SetReceiveMessageOptResp, error) {
|
||||
log.NewInfo(req.OperationID, "SetReceiveMessageOpt args ", req.String())
|
||||
m := make(map[string]int, len(req.ConversationIDList))
|
||||
@ -132,10 +140,9 @@ func (s *userServer) GetAllConversationMsgOpt(ctx context.Context, req *pbUser.G
|
||||
return &resp, nil
|
||||
}
|
||||
|
||||
|
||||
func (s *userServer) DeleteUsers(_ context.Context, req *pbUser.DeleteUsersReq) (*pbUser.DeleteUsersResp, error) {
|
||||
log.NewInfo(req.OperationID, "DeleteUsers args ", req.String())
|
||||
if token_verify.IsMangerUserID(req.OpUserID){
|
||||
if token_verify.IsMangerUserID(req.OpUserID) {
|
||||
log.NewError(req.OperationID, "IsMangerUserID false ", req.OpUserID)
|
||||
return &pbUser.DeleteUsersResp{CommonResp: &pbUser.CommonResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: constant.ErrAccess.ErrMsg}, FailedUserIDList: req.DeleteUserIDList}, nil
|
||||
}
|
||||
@ -154,8 +161,8 @@ func (s *userServer) DeleteUsers(_ context.Context, req *pbUser.DeleteUsersReq)
|
||||
}
|
||||
|
||||
func (s *userServer) GetAllUserID(_ context.Context, req *pbUser.GetAllUserIDReq) (*pbUser.GetAllUserIDResp, error) {
|
||||
log.NewInfo(req.OperationID,"GetAllUserID args ", req.String())
|
||||
if token_verify.IsMangerUserID(req.OpUserID){
|
||||
log.NewInfo(req.OperationID, "GetAllUserID args ", req.String())
|
||||
if token_verify.IsMangerUserID(req.OpUserID) {
|
||||
log.NewError(req.OperationID, "IsMangerUserID false ", req.OpUserID)
|
||||
return &pbUser.GetAllUserIDResp{CommonResp: &pbUser.CommonResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: constant.ErrAccess.ErrMsg}}, nil
|
||||
}
|
||||
@ -169,10 +176,9 @@ func (s *userServer) GetAllUserID(_ context.Context, req *pbUser.GetAllUserIDReq
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func (s *userServer) AccountCheck(_ context.Context, req *pbUser.AccountCheckReq) (*pbUser.AccountCheckResp, error) {
|
||||
log.NewInfo(req.OperationID,"AccountCheck args ", req.String())
|
||||
if token_verify.IsMangerUserID(req.OpUserID){
|
||||
log.NewInfo(req.OperationID, "AccountCheck args ", req.String())
|
||||
if token_verify.IsMangerUserID(req.OpUserID) {
|
||||
log.NewError(req.OperationID, "IsMangerUserID false ", req.OpUserID)
|
||||
return &pbUser.AccountCheckResp{CommonResp: &pbUser.CommonResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: constant.ErrAccess.ErrMsg}}, nil
|
||||
}
|
||||
@ -199,12 +205,9 @@ func (s *userServer) AccountCheck(_ context.Context, req *pbUser.AccountCheckReq
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
func (s *userServer) UpdateUserInfo(ctx context.Context, req *pbUser.UpdateUserInfoReq) (*pbUser.UpdateUserInfoResp, error) {
|
||||
log.NewInfo(req.OperationID,"UpdateUserInfo args ", req.String())
|
||||
if !token_verify.CheckAccess(req.OpUserID, req.UserInfo.UserID){
|
||||
log.NewInfo(req.OperationID, "UpdateUserInfo args ", req.String())
|
||||
if !token_verify.CheckAccess(req.OpUserID, req.UserInfo.UserID) {
|
||||
log.NewError(req.OperationID, "CheckAccess false ", req.OpUserID, req.UserInfo.UserID)
|
||||
return &pbUser.UpdateUserInfoResp{CommonResp: &pbUser.CommonResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: constant.ErrAccess.ErrMsg}}, nil
|
||||
}
|
||||
@ -219,7 +222,7 @@ func (s *userServer) UpdateUserInfo(ctx context.Context, req *pbUser.UpdateUserI
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImFriendName)
|
||||
client := pbFriend.NewFriendClient(etcdConn)
|
||||
newReq := &pbFriend.GetFriendListReq{
|
||||
CommID: &pbFriend.CommID{OperationID: req.OperationID, FromUserID: req.UserInfo.UserID, OpUserID: req.OpUserID}
|
||||
CommID: &pbFriend.CommID{OperationID: req.OperationID, FromUserID: req.UserInfo.UserID, OpUserID: req.OpUserID},
|
||||
}
|
||||
|
||||
RpcResp, err := client.GetFriendList(context.Background(), newReq)
|
||||
@ -227,12 +230,9 @@ func (s *userServer) UpdateUserInfo(ctx context.Context, req *pbUser.UpdateUserI
|
||||
log.NewError(req.OperationID, "GetFriendList failed ", err.Error(), newReq)
|
||||
return &pbUser.UpdateUserInfoResp{CommonResp: &pbUser.CommonResp{}}, nil
|
||||
}
|
||||
for _, v := range RpcResp.FriendInfoList{
|
||||
for _, v := range RpcResp.FriendInfoList {
|
||||
chat.FriendInfoChangedNotification(req.OperationID, req.OpUserID, req.UserInfo.UserID, v.FriendUser.UserID)
|
||||
}
|
||||
chat.SelfInfoUpdatedNotification(req.OperationID, req.UserInfo.UserID)
|
||||
return &pbUser.UpdateUserInfoResp{CommonResp: &pbUser.CommonResp{}}, nil
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
1
pkg/base_info/conversation_api_struct.go
Normal file
1
pkg/base_info/conversation_api_struct.go
Normal file
@ -0,0 +1 @@
|
||||
package base_info
|
98
pkg/base_info/manage_api_struct.go
Normal file
98
pkg/base_info/manage_api_struct.go
Normal file
@ -0,0 +1,98 @@
|
||||
package base_info
|
||||
|
||||
import open_im_sdk "Open_IM/pkg/proto/sdk_ws"
|
||||
|
||||
type paramsManagementSendMsg struct {
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
SendID string `json:"sendID" binding:"required"`
|
||||
RecvID string `json:"recvID" `
|
||||
GroupID string `json:"groupID" `
|
||||
SenderNickName string `json:"senderNickName" `
|
||||
SenderFaceURL string `json:"senderFaceURL" `
|
||||
SenderPlatformID int32 `json:"senderPlatformID"`
|
||||
ForceList []string `json:"forceList" `
|
||||
Content map[string]interface{} `json:"content" binding:"required"`
|
||||
ContentType int32 `json:"contentType" binding:"required"`
|
||||
SessionType int32 `json:"sessionType" binding:"required"`
|
||||
IsOnlineOnly bool `json:"isOnlineOnly"`
|
||||
OfflinePushInfo *open_im_sdk.OfflinePushInfo `json:"offlinePushInfo"`
|
||||
}
|
||||
|
||||
type PictureBaseInfo struct {
|
||||
UUID string `mapstructure:"uuid"`
|
||||
Type string `mapstructure:"type" validate:"required"`
|
||||
Size int64 `mapstructure:"size" validate:"required"`
|
||||
Width int32 `mapstructure:"width" validate:"required"`
|
||||
Height int32 `mapstructure:"height" validate:"required"`
|
||||
Url string `mapstructure:"url" validate:"required"`
|
||||
}
|
||||
|
||||
type PictureElem struct {
|
||||
SourcePath string `mapstructure:"sourcePath"`
|
||||
SourcePicture PictureBaseInfo `mapstructure:"sourcePicture" validate:"required"`
|
||||
BigPicture PictureBaseInfo `mapstructure:"bigPicture" `
|
||||
SnapshotPicture PictureBaseInfo `mapstructure:"snapshotPicture"`
|
||||
}
|
||||
type SoundElem struct {
|
||||
UUID string `mapstructure:"uuid"`
|
||||
SoundPath string `mapstructure:"soundPath"`
|
||||
SourceURL string `mapstructure:"sourceUrl"`
|
||||
DataSize int64 `mapstructure:"dataSize"`
|
||||
Duration int64 `mapstructure:"duration"`
|
||||
}
|
||||
type VideoElem struct {
|
||||
VideoPath string `mapstructure:"videoPath"`
|
||||
VideoUUID string `mapstructure:"videoUUID"`
|
||||
VideoURL string `mapstructure:"videoUrl"`
|
||||
VideoType string `mapstructure:"videoType"`
|
||||
VideoSize int64 `mapstructure:"videoSize"`
|
||||
Duration int64 `mapstructure:"duration"`
|
||||
SnapshotPath string `mapstructure:"snapshotPath"`
|
||||
SnapshotUUID string `mapstructure:"snapshotUUID"`
|
||||
SnapshotSize int64 `mapstructure:"snapshotSize"`
|
||||
SnapshotURL string `mapstructure:"snapshotUrl"`
|
||||
SnapshotWidth int32 `mapstructure:"snapshotWidth"`
|
||||
SnapshotHeight int32 `mapstructure:"snapshotHeight"`
|
||||
}
|
||||
type FileElem struct {
|
||||
FilePath string `mapstructure:"filePath"`
|
||||
UUID string `mapstructure:"uuid"`
|
||||
SourceURL string `mapstructure:"sourceUrl"`
|
||||
FileName string `mapstructure:"fileName"`
|
||||
FileSize int64 `mapstructure:"fileSize"`
|
||||
}
|
||||
|
||||
type paramsDeleteUsers struct {
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
DeleteUidList []string `json:"deleteUidList" binding:"required"`
|
||||
}
|
||||
type paramsGetAllUsersUid struct {
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
}
|
||||
type paramsGetUsersOnlineStatus struct {
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
UserIDList []string `json:"userIDList" binding:"required,lte=200"`
|
||||
}
|
||||
type paramsAccountCheck struct {
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
UserIDList []string `json:"userIDList" binding:"required,lte=100"`
|
||||
}
|
||||
|
||||
type AtElem struct {
|
||||
Text string `mapstructure:"text"`
|
||||
AtUserList []string `mapstructure:"atUserList"`
|
||||
IsAtSelf bool `mapstructure:"isAtSelf"`
|
||||
}
|
||||
type LocationElem struct {
|
||||
Description string `mapstructure:"description"`
|
||||
Longitude float64 `mapstructure:"longitude"`
|
||||
Latitude float64 `mapstructure:"latitude"`
|
||||
}
|
||||
type CustomElem struct {
|
||||
Data string `mapstructure:"data" validate:"required"`
|
||||
Description string `mapstructure:"description"`
|
||||
Extension string `mapstructure:"extension"`
|
||||
}
|
||||
type TextElem struct {
|
||||
Text string `mapstructure:"text" validate:"required"`
|
||||
}
|
@ -2,6 +2,7 @@ package im_mysql_model
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/db"
|
||||
"time"
|
||||
)
|
||||
|
||||
//type FriendRequest struct {
|
||||
|
@ -2,6 +2,7 @@ package im_mysql_model
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/db"
|
||||
"time"
|
||||
)
|
||||
|
||||
//type GroupMember struct {
|
||||
@ -61,7 +62,7 @@ func GetGroupMemberListByGroupIDAndRoleLevel(groupID string, roleLevel int32) ([
|
||||
return nil, err
|
||||
}
|
||||
var groupMemberList []GroupMember
|
||||
err = dbConn.Table("group_member").Where("group_id=? and role_level=?", groupID, role_level).Find(&groupMemberList).Error
|
||||
err = dbConn.Table("group_member").Where("group_id=? and role_level=?", groupID, roleLevel).Find(&groupMemberList).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -2,8 +2,6 @@ package im_mysql_model
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/db"
|
||||
"Open_IM/pkg/proto/group"
|
||||
"errors"
|
||||
"time"
|
||||
)
|
||||
|
||||
|
@ -2,8 +2,6 @@ package im_mysql_model
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/db"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/proto/group"
|
||||
"time"
|
||||
)
|
||||
|
||||
|
@ -95,7 +95,7 @@ type GroupMember struct {
|
||||
JoinTime time.Time `gorm:"column:join_time"`
|
||||
Nickname string `gorm:"column:nickname"`
|
||||
FaceUrl string `gorm:"user_group_face_url"`
|
||||
JoinSource int32 `gorm:"column:join_source"`
|
||||
JoinSource time.Time `gorm:"column:join_source"`
|
||||
OperatorUserID string `gorm:"column:operator_user_id"`
|
||||
Ex string `gorm:"column:ex"`
|
||||
}
|
||||
|
95
pkg/common/utils/utils.go
Normal file
95
pkg/common/utils/utils.go
Normal file
@ -0,0 +1,95 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
imdb "Open_IM/pkg/common/db/mysql_model/im_mysql_model"
|
||||
"Open_IM/pkg/common/token_verify"
|
||||
open_im_sdk "Open_IM/pkg/proto/sdk_ws"
|
||||
"Open_IM/pkg/utils"
|
||||
"math/rand"
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
|
||||
func OperationIDGenerator() string {
|
||||
return strconv.FormatInt(time.Now().UnixNano()+int64(rand.Uint32()), 10)
|
||||
}
|
||||
|
||||
func FriendOpenIMCopyDB(dst *imdb.Friend, src open_im_sdk.FriendInfo) {
|
||||
utils.CopyStructFields(dst, src)
|
||||
dst.FriendUserID = src.FriendUser.UserID
|
||||
}
|
||||
|
||||
func FriendDBCopyOpenIM(dst *open_im_sdk.FriendInfo, src imdb.Friend) {
|
||||
utils.CopyStructFields(dst, src)
|
||||
user, _ := imdb.GetUserByUserID(src.FriendUserID)
|
||||
if user != nil {
|
||||
utils.CopyStructFields(dst.FriendUser, user)
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
func FriendRequestOpenIMCopyDB(dst *imdb.FriendRequest, src open_im_sdk.FriendRequest) {
|
||||
utils.CopyStructFields(dst, src)
|
||||
}
|
||||
|
||||
func FriendRequestDBCopyOpenIM(dst *open_im_sdk.FriendRequest, src imdb.FriendRequest) {
|
||||
utils.CopyStructFields(dst, src)
|
||||
}
|
||||
|
||||
func GroupOpenIMCopyDB(dst *imdb.Group, src open_im_sdk.GroupInfo) {
|
||||
utils.CopyStructFields(dst, src)
|
||||
}
|
||||
|
||||
func GroupDBCopyOpenIM(dst *open_im_sdk.GroupInfo, src imdb.Group) {
|
||||
utils.CopyStructFields(dst, src)
|
||||
user, _ := imdb.GetGroupOwnerInfoByGroupID(src.GroupID)
|
||||
if user != nil {
|
||||
dst.OwnerUserID = user.UserID
|
||||
}
|
||||
dst.MemberCount = imdb.GetGroupMemberNumByGroupID(src.GroupID)
|
||||
}
|
||||
|
||||
func GroupMemberOpenIMCopyDB(dst *imdb.GroupMember, src open_im_sdk.GroupMemberFullInfo) {
|
||||
utils.CopyStructFields(dst, src)
|
||||
}
|
||||
|
||||
func GroupMemberDBCopyOpenIM(dst *open_im_sdk.GroupMemberFullInfo, src imdb.GroupMember) {
|
||||
utils.CopyStructFields(dst, src)
|
||||
if token_verify.IsMangerUserID(src.UserID) {
|
||||
u, _ := imdb.GetUserByUserID(src.UserID)
|
||||
if u != nil {
|
||||
utils.CopyStructFields(dst, u)
|
||||
}
|
||||
dst.AppMangerLevel = 1
|
||||
}
|
||||
}
|
||||
|
||||
func GroupRequestOpenIMCopyDB(dst *imdb.GroupRequest, src open_im_sdk.GroupRequest) {
|
||||
utils.CopyStructFields(dst, src)
|
||||
}
|
||||
|
||||
func GroupRequestDBCopyOpenIM(dst *open_im_sdk.GroupRequest, src imdb.GroupRequest) {
|
||||
utils.CopyStructFields(dst, src)
|
||||
}
|
||||
|
||||
func UserOpenIMCopyDB(dst *imdb.User, src open_im_sdk.UserInfo) {
|
||||
utils.CopyStructFields(dst, src)
|
||||
}
|
||||
|
||||
func UserDBCopyOpenIM(dst *open_im_sdk.UserInfo, src imdb.User) {
|
||||
utils.CopyStructFields(dst, src)
|
||||
}
|
||||
|
||||
func BlackOpenIMCopyDB(dst *imdb.Black, src open_im_sdk.BlackInfo) {
|
||||
utils.CopyStructFields(dst, src)
|
||||
dst.BlockUserID = src.BlackUserInfo.UserID
|
||||
}
|
||||
|
||||
func BlackDBCopyOpenIM(dst *open_im_sdk.BlackInfo, src imdb.Black) {
|
||||
utils.CopyStructFields(dst, src)
|
||||
dst.CreateTime = src.CreateTime.Unix()
|
||||
user, _ := imdb.GetUserByUserID(src.BlockUserID)
|
||||
if user != nil {
|
||||
utils.CopyStructFields(dst.BlackUserInfo, user)
|
||||
}
|
||||
}
|
@ -1,14 +1,8 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
imdb "Open_IM/pkg/common/db/mysql_model/im_mysql_model"
|
||||
"Open_IM/pkg/common/token_verify"
|
||||
open_im_sdk "Open_IM/pkg/proto/sdk_ws"
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"reflect"
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
|
||||
// copy a by b b->a
|
||||
@ -49,86 +43,3 @@ func CopyStructFields(a interface{}, b interface{}, fields ...string) (err error
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func OperationIDGenerator() string {
|
||||
return strconv.FormatInt(time.Now().UnixNano()+int64(rand.Uint32()), 10)
|
||||
}
|
||||
|
||||
func FriendOpenIMCopyDB(dst *imdb.Friend, src open_im_sdk.FriendInfo) {
|
||||
CopyStructFields(dst, src)
|
||||
dst.FriendUserID = src.FriendUser.UserID
|
||||
}
|
||||
|
||||
func FriendDBCopyOpenIM(dst *open_im_sdk.FriendInfo, src imdb.Friend) {
|
||||
CopyStructFields(dst, src)
|
||||
user, _ := imdb.GetUserByUserID(src.FriendUserID)
|
||||
if user != nil {
|
||||
CopyStructFields(dst.FriendUser, user)
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
func FriendRequestOpenIMCopyDB(dst *imdb.FriendRequest, src open_im_sdk.FriendRequest) {
|
||||
CopyStructFields(dst, src)
|
||||
}
|
||||
|
||||
func FriendRequestDBCopyOpenIM(dst *open_im_sdk.FriendRequest, src imdb.FriendRequest) {
|
||||
CopyStructFields(dst, src)
|
||||
}
|
||||
|
||||
func GroupOpenIMCopyDB(dst *imdb.Group, src open_im_sdk.GroupInfo) {
|
||||
CopyStructFields(dst, src)
|
||||
}
|
||||
|
||||
func GroupDBCopyOpenIM(dst *open_im_sdk.GroupInfo, src imdb.Group) {
|
||||
CopyStructFields(dst, src)
|
||||
user, _ := imdb.GetGroupOwnerInfoByGroupID(src.GroupID)
|
||||
if user != nil {
|
||||
dst.OwnerUserID = user.UserID
|
||||
}
|
||||
dst.MemberCount = imdb.GetGroupMemberNumByGroupID(src.GroupID)
|
||||
}
|
||||
|
||||
func GroupMemberOpenIMCopyDB(dst *imdb.GroupMember, src open_im_sdk.GroupMemberFullInfo) {
|
||||
CopyStructFields(dst, src)
|
||||
}
|
||||
|
||||
func GroupMemberDBCopyOpenIM(dst *open_im_sdk.GroupMemberFullInfo, src imdb.GroupMember) {
|
||||
CopyStructFields(dst, src)
|
||||
if token_verify.IsMangerUserID(src.UserID) {
|
||||
u, _ := imdb.GetUserByUserID(src.UserID)
|
||||
if u != nil {
|
||||
CopyStructFields(dst, u)
|
||||
}
|
||||
dst.AppMangerLevel = 1
|
||||
}
|
||||
}
|
||||
|
||||
func GroupRequestOpenIMCopyDB(dst *imdb.GroupRequest, src open_im_sdk.GroupRequest) {
|
||||
CopyStructFields(dst, src)
|
||||
}
|
||||
|
||||
func GroupRequestDBCopyOpenIM(dst *open_im_sdk.GroupRequest, src imdb.GroupRequest) {
|
||||
CopyStructFields(dst, src)
|
||||
}
|
||||
|
||||
func UserOpenIMCopyDB(dst *imdb.User, src open_im_sdk.UserInfo) {
|
||||
CopyStructFields(dst, src)
|
||||
}
|
||||
|
||||
func UserDBCopyOpenIM(dst *open_im_sdk.UserInfo, src imdb.User) {
|
||||
CopyStructFields(dst, src)
|
||||
}
|
||||
|
||||
func BlackOpenIMCopyDB(dst *imdb.Black, src open_im_sdk.BlackInfo) {
|
||||
CopyStructFields(dst, src)
|
||||
dst.BlockUserID = src.BlackUserInfo.UserID
|
||||
}
|
||||
|
||||
func BlackDBCopyOpenIM(dst *open_im_sdk.BlackInfo, src imdb.Black) {
|
||||
CopyStructFields(dst, src)
|
||||
user, _ := imdb.GetUserByUserID(src.BlockUserID)
|
||||
if user != nil {
|
||||
CopyStructFields(dst.BlackUserInfo, user)
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user