mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-04-24 18:36:19 +08:00
api
This commit is contained in:
parent
7050b64b19
commit
6150419842
@ -19,26 +19,26 @@ type Auth struct {
|
||||
zk *openKeeper.ZkClient
|
||||
}
|
||||
|
||||
func (a *Auth) getGroupClient() (auth.AuthClient, error) {
|
||||
conn, err := a.zk.GetConn(config.Config.RpcRegisterName.OpenImGroupName)
|
||||
func (o *Auth) client() (auth.AuthClient, error) {
|
||||
conn, err := o.zk.GetConn(config.Config.RpcRegisterName.OpenImGroupName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return auth.NewAuthClient(conn), nil
|
||||
}
|
||||
|
||||
func (a *Auth) UserRegister(c *gin.Context) {
|
||||
a2r.Call(auth.AuthClient.UserRegister, a.getGroupClient, c)
|
||||
func (o *Auth) UserRegister(c *gin.Context) {
|
||||
a2r.Call(auth.AuthClient.UserRegister, o.client, c)
|
||||
}
|
||||
|
||||
func (a *Auth) UserToken(c *gin.Context) {
|
||||
a2r.Call(auth.AuthClient.UserToken, a.getGroupClient, c)
|
||||
func (o *Auth) UserToken(c *gin.Context) {
|
||||
a2r.Call(auth.AuthClient.UserToken, o.client, c)
|
||||
}
|
||||
|
||||
func (a *Auth) ParseToken(c *gin.Context) {
|
||||
a2r.Call(auth.AuthClient.ParseToken, a.getGroupClient, c)
|
||||
func (o *Auth) ParseToken(c *gin.Context) {
|
||||
a2r.Call(auth.AuthClient.ParseToken, o.client, c)
|
||||
}
|
||||
|
||||
func (a *Auth) ForceLogout(c *gin.Context) {
|
||||
a2r.Call(auth.AuthClient.ForceLogout, a.getGroupClient, c)
|
||||
func (o *Auth) ForceLogout(c *gin.Context) {
|
||||
a2r.Call(auth.AuthClient.ForceLogout, o.client, c)
|
||||
}
|
||||
|
56
internal/api/conversation.go
Normal file
56
internal/api/conversation.go
Normal file
@ -0,0 +1,56 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"OpenIM/internal/api/a2r"
|
||||
"OpenIM/pkg/common/config"
|
||||
"OpenIM/pkg/proto/conversation"
|
||||
"context"
|
||||
"github.com/OpenIMSDK/openKeeper"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
var _ context.Context // 解决goland编辑器bug
|
||||
|
||||
func NewConversation(zk *openKeeper.ZkClient) *Conversation {
|
||||
return &Conversation{zk: zk}
|
||||
}
|
||||
|
||||
type Conversation struct {
|
||||
zk *openKeeper.ZkClient
|
||||
}
|
||||
|
||||
func (o *Conversation) client() (conversation.ConversationClient, error) {
|
||||
conn, err := o.zk.GetConn(config.Config.RpcRegisterName.OpenImGroupName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return conversation.NewConversationClient(conn), nil
|
||||
}
|
||||
|
||||
func (o *Conversation) GetAllConversations(c *gin.Context) {
|
||||
a2r.Call(conversation.ConversationClient.GetAllConversations, o.client, c)
|
||||
}
|
||||
|
||||
func (o *Conversation) GetConversation(c *gin.Context) {
|
||||
a2r.Call(conversation.ConversationClient.GetConversation, o.client, c)
|
||||
}
|
||||
|
||||
func (o *Conversation) GetConversations(c *gin.Context) {
|
||||
a2r.Call(conversation.ConversationClient.GetConversations, o.client, c)
|
||||
}
|
||||
|
||||
func (o *Conversation) SetConversation(c *gin.Context) {
|
||||
a2r.Call(conversation.ConversationClient.SetConversation, o.client, c)
|
||||
}
|
||||
|
||||
func (o *Conversation) BatchSetConversations(c *gin.Context) {
|
||||
a2r.Call(conversation.ConversationClient.BatchSetConversations, o.client, c)
|
||||
}
|
||||
|
||||
func (o *Conversation) SetRecvMsgOpt(c *gin.Context) {
|
||||
a2r.Call(conversation.ConversationClient.SetRecvMsgOpt, o.client, c)
|
||||
}
|
||||
|
||||
func (o *Conversation) ModifyConversationField(c *gin.Context) {
|
||||
a2r.Call(conversation.ConversationClient.ModifyConversationField, o.client, c)
|
||||
}
|
@ -1,327 +0,0 @@
|
||||
package conversation
|
||||
|
||||
import (
|
||||
api "OpenIM/pkg/apistruct"
|
||||
"OpenIM/pkg/common/config"
|
||||
"OpenIM/pkg/common/log"
|
||||
pbConversation "OpenIM/pkg/proto/conversation"
|
||||
pbUser "OpenIM/pkg/proto/user"
|
||||
"OpenIM/pkg/utils"
|
||||
"context"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func SetConversation(c *gin.Context) {
|
||||
var (
|
||||
req api.SetConversationReq
|
||||
resp api.SetConversationResp
|
||||
reqPb pbUser.SetConversationReq
|
||||
)
|
||||
if err := c.BindJSON(&req); err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "bind json failed", err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": "bind json failed " + err.Error()})
|
||||
return
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req)
|
||||
reqPb.Conversation = &pbConversation.Conversation{}
|
||||
err := utils.CopyStructFields(&reqPb, req)
|
||||
err = utils.CopyStructFields(reqPb.Conversation, req.Conversation)
|
||||
if err != nil {
|
||||
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "CopyStructFields failed", err.Error())
|
||||
}
|
||||
etcdConn := rpc.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImUserName, req.OperationID)
|
||||
if etcdConn == nil {
|
||||
errMsg := req.OperationID + "getcdv3.GetDefaultConn == nil"
|
||||
log.NewError(req.OperationID, errMsg)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
|
||||
return
|
||||
}
|
||||
client := pbUser.NewUserClient(etcdConn)
|
||||
respPb, err := client.SetConversation(context.Background(), &reqPb)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "SetConversation rpc failed, ", reqPb.String(), err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 500, "errMsg": "GetAllConversationMsgOpt rpc failed, " + err.Error()})
|
||||
return
|
||||
}
|
||||
resp.ErrMsg = respPb.CommonResp.ErrMsg
|
||||
resp.ErrCode = respPb.CommonResp.ErrCode
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp)
|
||||
c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
func ModifyConversationField(c *gin.Context) {
|
||||
var (
|
||||
req api.ModifyConversationFieldReq
|
||||
resp api.ModifyConversationFieldResp
|
||||
reqPb pbConversation.ModifyConversationFieldReq
|
||||
)
|
||||
if err := c.BindJSON(&req); err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "bind json failed", err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": "bind json failed " + err.Error()})
|
||||
return
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req)
|
||||
reqPb.Conversation = &pbConversation.Conversation{}
|
||||
err := utils.CopyStructFields(&reqPb, req)
|
||||
err = utils.CopyStructFields(reqPb.Conversation, req.Conversation)
|
||||
if err != nil {
|
||||
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "CopyStructFields failed", err.Error())
|
||||
}
|
||||
etcdConn := rpc.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImConversationName, req.OperationID)
|
||||
if etcdConn == nil {
|
||||
errMsg := req.OperationID + "getcdv3.GetDefaultConn == nil"
|
||||
log.NewError(req.OperationID, errMsg)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
|
||||
return
|
||||
}
|
||||
client := pbConversation.NewConversationClient(etcdConn)
|
||||
respPb, err := client.ModifyConversationField(context.Background(), &reqPb)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "SetConversation rpc failed, ", reqPb.String(), err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 500, "errMsg": "GetAllConversationMsgOpt rpc failed, " + err.Error()})
|
||||
return
|
||||
}
|
||||
resp.ErrMsg = respPb.CommonResp.ErrMsg
|
||||
resp.ErrCode = respPb.CommonResp.ErrCode
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp)
|
||||
c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
|
||||
func BatchSetConversations(c *gin.Context) {
|
||||
var (
|
||||
req api.BatchSetConversationsReq
|
||||
resp api.BatchSetConversationsResp
|
||||
reqPb pbUser.BatchSetConversationsReq
|
||||
)
|
||||
if err := c.BindJSON(&req); err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "bind json failed", err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": "bind json failed " + err.Error()})
|
||||
return
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req)
|
||||
if err := utils.CopyStructFields(&reqPb, req); err != nil {
|
||||
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "CopyStructFields failed", err.Error())
|
||||
}
|
||||
etcdConn := rpc.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImUserName, req.OperationID)
|
||||
if etcdConn == nil {
|
||||
errMsg := req.OperationID + "getcdv3.GetDefaultConn == nil"
|
||||
log.NewError(req.OperationID, errMsg)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
|
||||
return
|
||||
}
|
||||
client := pbUser.NewUserClient(etcdConn)
|
||||
respPb, err := client.BatchSetConversations(context.Background(), &reqPb)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "SetConversation rpc failed, ", reqPb.String(), err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 500, "errMsg": "GetAllConversationMsgOpt rpc failed, " + err.Error()})
|
||||
return
|
||||
}
|
||||
if err := utils.CopyStructFields(&resp.Data, respPb); err != nil {
|
||||
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "CopyStructFields failed", err.Error())
|
||||
}
|
||||
resp.ErrMsg = respPb.CommonResp.ErrMsg
|
||||
resp.ErrCode = respPb.CommonResp.ErrCode
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp)
|
||||
c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
|
||||
// @Summary 获取用户所有会话
|
||||
// @Description 获取用户所有会话
|
||||
// @Tags 会话相关
|
||||
// @ID GetAllConversations
|
||||
// @Accept json
|
||||
// @Param token header string true "im token"
|
||||
// @Param req body api.GetAllConversationsReq true "ownerUserID为要获取的用户ID"
|
||||
// @Produce json
|
||||
// @Success 0 {object} api.GetAllConversationsResp
|
||||
// @Failure 500 {object} api.Swagger500Resp "errCode为500 一般为服务器内部错误"
|
||||
// @Failure 400 {object} api.Swagger400Resp "errCode为400 一般为参数输入错误, token未带上等"
|
||||
// @Router /msg/get_all_conversations [post]
|
||||
func GetAllConversations(c *gin.Context) {
|
||||
var (
|
||||
req api.GetAllConversationsReq
|
||||
resp api.GetAllConversationsResp
|
||||
reqPb pbUser.GetAllConversationsReq
|
||||
)
|
||||
if err := c.BindJSON(&req); err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "bind json failed", err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": "bind json failed " + err.Error()})
|
||||
return
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req)
|
||||
if err := utils.CopyStructFields(&reqPb, req); err != nil {
|
||||
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "CopyStructFields failed", err.Error())
|
||||
}
|
||||
etcdConn := rpc.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImUserName, req.OperationID)
|
||||
if etcdConn == nil {
|
||||
errMsg := req.OperationID + "getcdv3.GetDefaultConn == nil"
|
||||
log.NewError(req.OperationID, errMsg)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
|
||||
return
|
||||
}
|
||||
client := pbUser.NewUserClient(etcdConn)
|
||||
respPb, err := client.GetAllConversations(context.Background(), &reqPb)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "SetConversation rpc failed, ", reqPb.String(), err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 500, "errMsg": "GetAllConversationMsgOpt rpc failed, " + err.Error()})
|
||||
return
|
||||
}
|
||||
resp.ErrMsg = respPb.CommonResp.ErrMsg
|
||||
resp.ErrCode = respPb.CommonResp.ErrCode
|
||||
if err := utils.CopyStructFields(&resp.Conversations, respPb.Conversations); err != nil {
|
||||
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "CopyStructFields failed, ", err.Error())
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp)
|
||||
c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
|
||||
// @Summary 根据会话ID获取会话
|
||||
// @Description 根据会话ID获取会话
|
||||
// @Tags 会话相关
|
||||
// @ID GetConversation
|
||||
// @Accept json
|
||||
// @Param token header string true "im token"
|
||||
// @Param req body api.GetConversationReq true "ownerUserID为要获取的用户ID<br>conversationID为要获取的会话ID"
|
||||
// @Produce json
|
||||
// @Success 0 {object} api.GetConversationResp
|
||||
// @Failure 500 {object} api.Swagger500Resp "errCode为500 一般为服务器内部错误"
|
||||
// @Failure 400 {object} api.Swagger400Resp "errCode为400 一般为参数输入错误, token未带上等"
|
||||
// @Router /msg/get_conversation [post]
|
||||
func GetConversation(c *gin.Context) {
|
||||
var (
|
||||
req api.GetConversationReq
|
||||
resp api.GetConversationResp
|
||||
reqPb pbUser.GetConversationReq
|
||||
)
|
||||
if err := c.BindJSON(&req); err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "bind json failed", err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": "bind json failed " + err.Error()})
|
||||
return
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req)
|
||||
if err := utils.CopyStructFields(&reqPb, req); err != nil {
|
||||
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "CopyStructFields failed", err.Error())
|
||||
}
|
||||
etcdConn := rpc.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImUserName, req.OperationID)
|
||||
if etcdConn == nil {
|
||||
errMsg := req.OperationID + "getcdv3.GetDefaultConn == nil"
|
||||
log.NewError(req.OperationID, errMsg)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
|
||||
return
|
||||
}
|
||||
client := pbUser.NewUserClient(etcdConn)
|
||||
respPb, err := client.GetConversation(context.Background(), &reqPb)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetConversation rpc failed, ", reqPb.String(), err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 500, "errMsg": "GetAllConversationMsgOpt rpc failed, " + err.Error()})
|
||||
return
|
||||
}
|
||||
resp.ErrMsg = respPb.CommonResp.ErrMsg
|
||||
resp.ErrCode = respPb.CommonResp.ErrCode
|
||||
if err := utils.CopyStructFields(&resp.Conversation, respPb.Conversation); err != nil {
|
||||
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "CopyStructFields failed", err.Error())
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp)
|
||||
c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
|
||||
// @Summary 根据会话ID列表获取会话
|
||||
// @Description 根据会话ID列表获取会话
|
||||
// @Tags 会话相关
|
||||
// @ID GetConversations
|
||||
// @Accept json
|
||||
// @Param token header string true "im token"
|
||||
// @Param req body api.GetConversationsReq true "ownerUserID为要获取的用户ID<br>conversationIDs为要获取的会话ID列表"
|
||||
// @Produce json
|
||||
// @Success 0 {object} api.GetConversationsResp
|
||||
// @Failure 500 {object} api.Swagger500Resp "errCode为500 一般为服务器内部错误"
|
||||
// @Failure 400 {object} api.Swagger400Resp "errCode为400 一般为参数输入错误, token未带上等"
|
||||
// @Router /msg/get_conversations [post]
|
||||
func GetConversations(c *gin.Context) {
|
||||
var (
|
||||
req api.GetConversationsReq
|
||||
resp api.GetConversationsResp
|
||||
reqPb pbUser.GetConversationsReq
|
||||
)
|
||||
if err := c.BindJSON(&req); err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "bind json failed", err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": "bind json failed " + err.Error()})
|
||||
return
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req)
|
||||
if err := utils.CopyStructFields(&reqPb, req); err != nil {
|
||||
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "CopyStructFields failed", err.Error())
|
||||
}
|
||||
etcdConn := rpc.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImUserName, req.OperationID)
|
||||
if etcdConn == nil {
|
||||
errMsg := req.OperationID + "getcdv3.GetDefaultConn == nil"
|
||||
log.NewError(req.OperationID, errMsg)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
|
||||
return
|
||||
}
|
||||
client := pbUser.NewUserClient(etcdConn)
|
||||
respPb, err := client.GetConversations(context.Background(), &reqPb)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "SetConversation rpc failed, ", reqPb.String(), err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 500, "errMsg": "GetAllConversationMsgOpt rpc failed, " + err.Error()})
|
||||
return
|
||||
}
|
||||
resp.ErrMsg = respPb.CommonResp.ErrMsg
|
||||
resp.ErrCode = respPb.CommonResp.ErrCode
|
||||
if err := utils.CopyStructFields(&resp.Conversations, respPb.Conversations); err != nil {
|
||||
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "CopyStructFields failed", err.Error())
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp)
|
||||
c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
|
||||
func SetRecvMsgOpt(c *gin.Context) {
|
||||
var (
|
||||
req api.SetRecvMsgOptReq
|
||||
resp api.SetRecvMsgOptResp
|
||||
reqPb pbUser.SetRecvMsgOptReq
|
||||
)
|
||||
if err := c.BindJSON(&req); err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "bind json failed", err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": "bind json failed " + err.Error()})
|
||||
return
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req)
|
||||
if err := utils.CopyStructFields(&reqPb, req); err != nil {
|
||||
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "CopyStructFields failed", err.Error())
|
||||
}
|
||||
etcdConn := rpc.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImUserName, req.OperationID)
|
||||
if etcdConn == nil {
|
||||
errMsg := req.OperationID + "getcdv3.GetDefaultConn == nil"
|
||||
log.NewError(req.OperationID, errMsg)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
|
||||
return
|
||||
}
|
||||
client := pbUser.NewUserClient(etcdConn)
|
||||
respPb, err := client.SetRecvMsgOpt(context.Background(), &reqPb)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "SetRecvMsgOpt rpc failed, ", reqPb.String(), err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 500, "errMsg": "GetAllConversationMsgOpt rpc failed, " + err.Error()})
|
||||
return
|
||||
}
|
||||
resp.ErrMsg = respPb.CommonResp.ErrMsg
|
||||
resp.ErrCode = respPb.CommonResp.ErrCode
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp)
|
||||
c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
|
||||
// Deprecated
|
||||
func SetReceiveMessageOpt(c *gin.Context) {
|
||||
|
||||
}
|
||||
|
||||
// Deprecated
|
||||
func GetReceiveMessageOpt(c *gin.Context) {
|
||||
|
||||
}
|
||||
|
||||
// Deprecated
|
||||
func GetAllConversationMessageOpt(c *gin.Context) {
|
||||
|
||||
}
|
@ -19,58 +19,58 @@ type Friend struct {
|
||||
zk *openKeeper.ZkClient
|
||||
}
|
||||
|
||||
func (f *Friend) getGroupClient() (friend.FriendClient, error) {
|
||||
conn, err := f.zk.GetConn(config.Config.RpcRegisterName.OpenImGroupName)
|
||||
func (o *Friend) client() (friend.FriendClient, error) {
|
||||
conn, err := o.zk.GetConn(config.Config.RpcRegisterName.OpenImGroupName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return friend.NewFriendClient(conn), nil
|
||||
}
|
||||
|
||||
func (f *Friend) AddFriend(c *gin.Context) {
|
||||
a2r.Call(friend.FriendClient.AddFriend, f.getGroupClient, c)
|
||||
func (o *Friend) ApplyToAddFriend(c *gin.Context) {
|
||||
a2r.Call(friend.FriendClient.ApplyToAddFriend, o.client, c)
|
||||
}
|
||||
|
||||
func (f *Friend) DeleteFriend(c *gin.Context) {
|
||||
a2r.Call(friend.FriendClient.DeleteFriend, f.getGroupClient, c)
|
||||
func (o *Friend) DeleteFriend(c *gin.Context) {
|
||||
a2r.Call(friend.FriendClient.DeleteFriend, o.client, c)
|
||||
}
|
||||
|
||||
func (f *Friend) GetFriendApplyList(c *gin.Context) {
|
||||
a2r.Call(friend.FriendClient.GetFriendApplyList, f.getGroupClient, c)
|
||||
func (o *Friend) GetFriendApplyList(c *gin.Context) {
|
||||
a2r.Call(friend.FriendClient.GetPaginationFriendsApplyFrom, o.client, c)
|
||||
}
|
||||
|
||||
func (f *Friend) GetSelfApplyList(c *gin.Context) {
|
||||
a2r.Call(friend.FriendClient.GetSelfApplyList, f.getGroupClient, c)
|
||||
func (o *Friend) GetSelfApplyList(c *gin.Context) {
|
||||
a2r.Call(friend.FriendClient.GetPaginationFriendsApplyFrom, o.client, c)
|
||||
}
|
||||
|
||||
func (f *Friend) GetFriendList(c *gin.Context) {
|
||||
a2r.Call(friend.FriendClient.GetFriendList, f.getGroupClient, c)
|
||||
func (o *Friend) GetFriendList(c *gin.Context) {
|
||||
a2r.Call(friend.FriendClient.GetDesignatedFriends, o.client, c)
|
||||
}
|
||||
|
||||
func (f *Friend) AddFriendResponse(c *gin.Context) {
|
||||
a2r.Call(friend.FriendClient.AddFriendResponse, f.getGroupClient, c)
|
||||
func (o *Friend) RespondFriendApply(c *gin.Context) {
|
||||
a2r.Call(friend.FriendClient.RespondFriendApply, o.client, c)
|
||||
}
|
||||
|
||||
func (f *Friend) SetFriendRemark(c *gin.Context) {
|
||||
a2r.Call(friend.FriendClient.SetFriendRemark, f.getGroupClient, c)
|
||||
func (o *Friend) SetFriendRemark(c *gin.Context) {
|
||||
a2r.Call(friend.FriendClient.SetFriendRemark, o.client, c)
|
||||
}
|
||||
|
||||
func (f *Friend) AddBlack(c *gin.Context) {
|
||||
a2r.Call(friend.FriendClient.AddBlack, f.getGroupClient, c)
|
||||
func (o *Friend) AddBlack(c *gin.Context) {
|
||||
a2r.Call(friend.FriendClient.AddBlack, o.client, c)
|
||||
}
|
||||
|
||||
func (f *Friend) GetBlacklist(c *gin.Context) {
|
||||
a2r.Call(friend.FriendClient.GetBlacklist, f.getGroupClient, c)
|
||||
func (o *Friend) GetPaginationBlacks(c *gin.Context) {
|
||||
a2r.Call(friend.FriendClient.GetPaginationBlacks, o.client, c)
|
||||
}
|
||||
|
||||
func (f *Friend) RemoveBlacklist(c *gin.Context) {
|
||||
a2r.Call(friend.FriendClient.RemoveBlacklist, f.getGroupClient, c)
|
||||
func (o *Friend) RemoveBlack(c *gin.Context) {
|
||||
a2r.Call(friend.FriendClient.RemoveBlack, o.client, c)
|
||||
}
|
||||
|
||||
func (f *Friend) ImportFriend(c *gin.Context) {
|
||||
a2r.Call(friend.FriendClient.ImportFriend, f.getGroupClient, c)
|
||||
func (o *Friend) ImportFriends(c *gin.Context) {
|
||||
a2r.Call(friend.FriendClient.ImportFriends, o.client, c)
|
||||
}
|
||||
|
||||
func (f *Friend) IsFriend(c *gin.Context) {
|
||||
a2r.Call(friend.FriendClient.IsFriend, f.getGroupClient, c)
|
||||
func (o *Friend) IsFriend(c *gin.Context) {
|
||||
a2r.Call(friend.FriendClient.IsFriend, o.client, c)
|
||||
}
|
||||
|
@ -19,106 +19,106 @@ type Group struct {
|
||||
zk *openKeeper.ZkClient
|
||||
}
|
||||
|
||||
func (g *Group) getGroupClient() (group.GroupClient, error) {
|
||||
conn, err := g.zk.GetConn(config.Config.RpcRegisterName.OpenImGroupName)
|
||||
func (o *Group) client() (group.GroupClient, error) {
|
||||
conn, err := o.zk.GetConn(config.Config.RpcRegisterName.OpenImGroupName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return group.NewGroupClient(conn), nil
|
||||
}
|
||||
|
||||
func (g *Group) NewCreateGroup(c *gin.Context) {
|
||||
a2r.Call(group.GroupClient.CreateGroup, g.getGroupClient, c)
|
||||
func (o *Group) NewCreateGroup(c *gin.Context) {
|
||||
a2r.Call(group.GroupClient.CreateGroup, o.client, c)
|
||||
}
|
||||
|
||||
func (g *Group) NewSetGroupInfo(c *gin.Context) {
|
||||
a2r.Call(group.GroupClient.SetGroupInfo, g.getGroupClient, c)
|
||||
func (o *Group) NewSetGroupInfo(c *gin.Context) {
|
||||
a2r.Call(group.GroupClient.SetGroupInfo, o.client, c)
|
||||
}
|
||||
|
||||
func (g *Group) JoinGroup(c *gin.Context) {
|
||||
a2r.Call(group.GroupClient.JoinGroup, g.getGroupClient, c)
|
||||
func (o *Group) JoinGroup(c *gin.Context) {
|
||||
a2r.Call(group.GroupClient.JoinGroup, o.client, c)
|
||||
}
|
||||
|
||||
func (g *Group) QuitGroup(c *gin.Context) {
|
||||
a2r.Call(group.GroupClient.QuitGroup, g.getGroupClient, c)
|
||||
func (o *Group) QuitGroup(c *gin.Context) {
|
||||
a2r.Call(group.GroupClient.QuitGroup, o.client, c)
|
||||
}
|
||||
|
||||
func (g *Group) ApplicationGroupResponse(c *gin.Context) {
|
||||
a2r.Call(group.GroupClient.GroupApplicationResponse, g.getGroupClient, c)
|
||||
func (o *Group) ApplicationGroupResponse(c *gin.Context) {
|
||||
a2r.Call(group.GroupClient.GroupApplicationResponse, o.client, c)
|
||||
}
|
||||
|
||||
func (g *Group) TransferGroupOwner(c *gin.Context) {
|
||||
a2r.Call(group.GroupClient.TransferGroupOwner, g.getGroupClient, c)
|
||||
func (o *Group) TransferGroupOwner(c *gin.Context) {
|
||||
a2r.Call(group.GroupClient.TransferGroupOwner, o.client, c)
|
||||
}
|
||||
|
||||
func (g *Group) GetRecvGroupApplicationList(c *gin.Context) {
|
||||
a2r.Call(group.GroupClient.GetGroupApplicationList, g.getGroupClient, c)
|
||||
func (o *Group) GetRecvGroupApplicationList(c *gin.Context) {
|
||||
a2r.Call(group.GroupClient.GetGroupApplicationList, o.client, c)
|
||||
}
|
||||
|
||||
func (g *Group) GetUserReqGroupApplicationList(c *gin.Context) {
|
||||
a2r.Call(group.GroupClient.GetUserReqApplicationList, g.getGroupClient, c)
|
||||
func (o *Group) GetUserReqGroupApplicationList(c *gin.Context) {
|
||||
a2r.Call(group.GroupClient.GetUserReqApplicationList, o.client, c)
|
||||
}
|
||||
|
||||
func (g *Group) GetGroupsInfo(c *gin.Context) {
|
||||
a2r.Call(group.GroupClient.GetGroupsInfo, g.getGroupClient, c)
|
||||
func (o *Group) GetGroupsInfo(c *gin.Context) {
|
||||
a2r.Call(group.GroupClient.GetGroupsInfo, o.client, c)
|
||||
}
|
||||
|
||||
func (g *Group) KickGroupMember(c *gin.Context) {
|
||||
a2r.Call(group.GroupClient.KickGroupMember, g.getGroupClient, c)
|
||||
func (o *Group) KickGroupMember(c *gin.Context) {
|
||||
a2r.Call(group.GroupClient.KickGroupMember, o.client, c)
|
||||
}
|
||||
|
||||
func (g *Group) GetGroupMembersInfo(c *gin.Context) {
|
||||
a2r.Call(group.GroupClient.GetGroupMembersInfo, g.getGroupClient, c)
|
||||
func (o *Group) GetGroupMembersInfo(c *gin.Context) {
|
||||
a2r.Call(group.GroupClient.GetGroupMembersInfo, o.client, c)
|
||||
}
|
||||
|
||||
func (g *Group) InviteUserToGroup(c *gin.Context) {
|
||||
a2r.Call(group.GroupClient.InviteUserToGroup, g.getGroupClient, c)
|
||||
func (o *Group) InviteUserToGroup(c *gin.Context) {
|
||||
a2r.Call(group.GroupClient.InviteUserToGroup, o.client, c)
|
||||
}
|
||||
|
||||
func (g *Group) GetJoinedGroupList(c *gin.Context) {
|
||||
a2r.Call(group.GroupClient.GetJoinedGroupList, g.getGroupClient, c)
|
||||
func (o *Group) GetJoinedGroupList(c *gin.Context) {
|
||||
a2r.Call(group.GroupClient.GetJoinedGroupList, o.client, c)
|
||||
}
|
||||
|
||||
func (g *Group) DismissGroup(c *gin.Context) {
|
||||
a2r.Call(group.GroupClient.DismissGroup, g.getGroupClient, c)
|
||||
func (o *Group) DismissGroup(c *gin.Context) {
|
||||
a2r.Call(group.GroupClient.DismissGroup, o.client, c)
|
||||
}
|
||||
|
||||
func (g *Group) MuteGroupMember(c *gin.Context) {
|
||||
a2r.Call(group.GroupClient.MuteGroupMember, g.getGroupClient, c)
|
||||
func (o *Group) MuteGroupMember(c *gin.Context) {
|
||||
a2r.Call(group.GroupClient.MuteGroupMember, o.client, c)
|
||||
}
|
||||
|
||||
func (g *Group) CancelMuteGroupMember(c *gin.Context) {
|
||||
a2r.Call(group.GroupClient.CancelMuteGroupMember, g.getGroupClient, c)
|
||||
func (o *Group) CancelMuteGroupMember(c *gin.Context) {
|
||||
a2r.Call(group.GroupClient.CancelMuteGroupMember, o.client, c)
|
||||
}
|
||||
|
||||
func (g *Group) MuteGroup(c *gin.Context) {
|
||||
a2r.Call(group.GroupClient.MuteGroup, g.getGroupClient, c)
|
||||
func (o *Group) MuteGroup(c *gin.Context) {
|
||||
a2r.Call(group.GroupClient.MuteGroup, o.client, c)
|
||||
}
|
||||
|
||||
func (g *Group) CancelMuteGroup(c *gin.Context) {
|
||||
a2r.Call(group.GroupClient.CancelMuteGroup, g.getGroupClient, c)
|
||||
func (o *Group) CancelMuteGroup(c *gin.Context) {
|
||||
a2r.Call(group.GroupClient.CancelMuteGroup, o.client, c)
|
||||
}
|
||||
|
||||
func (g *Group) SetGroupMemberInfo(c *gin.Context) {
|
||||
a2r.Call(group.GroupClient.SetGroupMemberInfo, g.getGroupClient, c)
|
||||
func (o *Group) SetGroupMemberInfo(c *gin.Context) {
|
||||
a2r.Call(group.GroupClient.SetGroupMemberInfo, o.client, c)
|
||||
}
|
||||
|
||||
func (g *Group) GetGroupAbstractInfo(c *gin.Context) {
|
||||
a2r.Call(group.GroupClient.GetGroupAbstractInfo, g.getGroupClient, c)
|
||||
func (o *Group) GetGroupAbstractInfo(c *gin.Context) {
|
||||
a2r.Call(group.GroupClient.GetGroupAbstractInfo, o.client, c)
|
||||
}
|
||||
|
||||
//func (g *Group) SetGroupMemberNickname(c *gin.Context) {
|
||||
// a2r.Call(group.GroupClient.SetGroupMemberNickname, g.getGroupClient, c)
|
||||
// a2r.Call(group.GroupClient.SetGroupMemberNickname, g.client, c)
|
||||
//}
|
||||
//
|
||||
//func (g *Group) GetGroupAllMemberList(c *gin.Context) {
|
||||
// a2r.Call(group.GroupClient.GetGroupAllMember, g.getGroupClient, c)
|
||||
// a2r.Call(group.GroupClient.GetGroupAllMember, g.client, c)
|
||||
//}
|
||||
|
||||
func (g *Group) GetJoinedSuperGroupList(c *gin.Context) {
|
||||
a2r.Call(group.GroupClient.GetJoinedSuperGroupList, g.getGroupClient, c)
|
||||
func (o *Group) GetJoinedSuperGroupList(c *gin.Context) {
|
||||
a2r.Call(group.GroupClient.GetJoinedSuperGroupList, o.client, c)
|
||||
}
|
||||
|
||||
func (g *Group) GetSuperGroupsInfo(c *gin.Context) {
|
||||
a2r.Call(group.GroupClient.GetSuperGroupsInfo, g.getGroupClient, c)
|
||||
func (o *Group) GetSuperGroupsInfo(c *gin.Context) {
|
||||
a2r.Call(group.GroupClient.GetSuperGroupsInfo, o.client, c)
|
||||
}
|
||||
|
84
internal/api/msg.go
Normal file
84
internal/api/msg.go
Normal file
@ -0,0 +1,84 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"OpenIM/internal/api/a2r"
|
||||
"OpenIM/pkg/common/config"
|
||||
"OpenIM/pkg/proto/msg"
|
||||
"context"
|
||||
"github.com/OpenIMSDK/openKeeper"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
var _ context.Context // 解决goland编辑器bug
|
||||
|
||||
func NewMsg(zk *openKeeper.ZkClient) *Conversation {
|
||||
return &Conversation{zk: zk}
|
||||
}
|
||||
|
||||
type Msg struct {
|
||||
zk *openKeeper.ZkClient
|
||||
}
|
||||
|
||||
func (o *Msg) client() (msg.MsgClient, error) {
|
||||
conn, err := o.zk.GetConn(config.Config.RpcRegisterName.OpenImMsgName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return msg.NewMsgClient(conn), nil
|
||||
}
|
||||
|
||||
func (o *Msg) GetSeq(c *gin.Context) {
|
||||
a2r.Call(msg.MsgClient.GetSeq, o.client, c)
|
||||
}
|
||||
|
||||
func (o *Msg) SendMsg(c *gin.Context) {
|
||||
a2r.Call(msg.MsgClient.SendMsg, o.client, c)
|
||||
}
|
||||
|
||||
func (o *Msg) PullMsgBySeqList(c *gin.Context) {
|
||||
a2r.Call(msg.MsgClient.PullMsgBySeqList, o.client, c)
|
||||
}
|
||||
|
||||
func (o *Msg) DelMsg(c *gin.Context) {
|
||||
a2r.Call(msg.MsgClient.DelMsg, o.client, c)
|
||||
}
|
||||
|
||||
func (o *Msg) DelSuperGroupMsg(c *gin.Context) {
|
||||
a2r.Call(msg.MsgClient.DelSuperGroupMsg, o.client, c)
|
||||
}
|
||||
|
||||
func (o *Msg) ClearMsg(c *gin.Context) {
|
||||
a2r.Call(msg.MsgClient.ClearMsg, o.client, c)
|
||||
}
|
||||
|
||||
func (o *Msg) SetMsgMinSeq(c *gin.Context) {
|
||||
a2r.Call(msg.MsgClient.SetMsgMinSeq, o.client, c)
|
||||
}
|
||||
|
||||
func (o *Msg) SetMessageReactionExtensions(c *gin.Context) {
|
||||
a2r.Call(msg.MsgClient.SetMessageReactionExtensions, o.client, c)
|
||||
}
|
||||
|
||||
func (o *Msg) GetMessageListReactionExtensions(c *gin.Context) {
|
||||
a2r.Call(msg.MsgClient.GetMessageListReactionExtensions, o.client, c)
|
||||
}
|
||||
|
||||
func (o *Msg) AddMessageReactionExtensions(c *gin.Context) {
|
||||
a2r.Call(msg.MsgClient.AddMessageReactionExtensions, o.client, c)
|
||||
}
|
||||
|
||||
func (o *Msg) DeleteMessageReactionExtensions(c *gin.Context) {
|
||||
a2r.Call(msg.MsgClient.DeleteMessageReactionExtensions, o.client, c)
|
||||
}
|
||||
|
||||
func (o *Msg) ManagementSendMsg(c *gin.Context) {
|
||||
a2r.Call(msg.MsgClient.ManagementSendMsg, o.client, c)
|
||||
}
|
||||
|
||||
func (o *Msg) ManagementBatchSendMsg(c *gin.Context) {
|
||||
a2r.Call(msg.MsgClient.ManagementBatchSendMsg, o.client, c)
|
||||
}
|
||||
|
||||
func (o *Msg) CheckMsgIsSendSuccess(c *gin.Context) {
|
||||
a2r.Call(msg.MsgClient.CheckMsgIsSendSuccess, o.client, c)
|
||||
}
|
@ -1,273 +0,0 @@
|
||||
package msg
|
||||
|
||||
import (
|
||||
api "OpenIM/pkg/apistruct"
|
||||
"OpenIM/pkg/common/config"
|
||||
"OpenIM/pkg/common/constant"
|
||||
"OpenIM/pkg/common/log"
|
||||
"OpenIM/pkg/common/tokenverify"
|
||||
rpc "OpenIM/pkg/proto/msg"
|
||||
pbCommon "OpenIM/pkg/proto/sdkws"
|
||||
"OpenIM/pkg/utils"
|
||||
"context"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/golang/protobuf/proto"
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// @Summary 根据seq列表删除消息
|
||||
// @Description 根据seq列表删除消息
|
||||
// @Tags 消息相关
|
||||
// @ID DelMsg
|
||||
// @Accept json
|
||||
// @Param token header string true "im token"
|
||||
// @Param req body api.DelMsgReq true "userID为要删除的用户ID <br> seqList为seq列表"
|
||||
// @Produce json
|
||||
// @Success 0 {object} api.DelMsgResp
|
||||
// @Failure 500 {object} api.Swagger500Resp "errCode为500 一般为服务器内部错误"
|
||||
// @Failure 400 {object} api.Swagger400Resp "errCode为400 一般为参数输入错误, token未带上等"
|
||||
// @Router /msg/del_msg [post]
|
||||
func DelMsg(c *gin.Context) {
|
||||
var (
|
||||
req api.DelMsgReq
|
||||
resp api.DelMsgResp
|
||||
reqPb pbCommon.DelMsgListReq
|
||||
)
|
||||
if err := c.BindJSON(&req); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req:", req)
|
||||
if err := utils.CopyStructFields(&reqPb, &req); err != nil {
|
||||
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "CopyStructFields", err.Error())
|
||||
}
|
||||
|
||||
var ok bool
|
||||
var errInfo string
|
||||
ok, reqPb.OpUserID, errInfo = tokenverify.GetUserIDFromToken(c.Request.Header.Get("token"), req.OperationID)
|
||||
if !ok {
|
||||
errMsg := req.OperationID + " " + "GetUserIDFromToken failed " + errInfo + " token:" + c.Request.Header.Get("token")
|
||||
log.NewError(req.OperationID, errMsg)
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 500, "errMsg": errMsg})
|
||||
return
|
||||
}
|
||||
|
||||
grpcConn := rpc.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImMsgName, req.OperationID)
|
||||
if grpcConn == nil {
|
||||
errMsg := req.OperationID + " getcdv3.GetDefaultConn == nil"
|
||||
log.NewError(req.OperationID, errMsg)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
|
||||
return
|
||||
}
|
||||
msgClient := rpc.NewMsgClient(grpcConn)
|
||||
respPb, err := msgClient.DelMsgList(context.Background(), &reqPb)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "DelMsgList failed", err.Error(), reqPb)
|
||||
c.JSON(http.StatusOK, gin.H{"errCode": constant.ErrServer.ErrCode, "errMsg": constant.ErrServer.ErrMsg + err.Error()})
|
||||
return
|
||||
}
|
||||
resp.ErrCode = respPb.ErrCode
|
||||
resp.ErrMsg = respPb.ErrMsg
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), resp)
|
||||
c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
func DelSuperGroupMsg(c *gin.Context) {
|
||||
var (
|
||||
req api.DelSuperGroupMsgReq
|
||||
resp api.DelSuperGroupMsgResp
|
||||
)
|
||||
rpcReq := &rpc.DelSuperGroupMsgReq{}
|
||||
if err := c.BindJSON(&req); err != nil {
|
||||
log.NewError("", "args err:", err.Error())
|
||||
c.JSON(http.StatusOK, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
utils.CopyStructFields(rpcReq, &req)
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req:", req)
|
||||
var ok bool
|
||||
var errInfo string
|
||||
ok, rpcReq.OpUserID, errInfo = tokenverify.GetUserIDFromToken(c.Request.Header.Get("token"), req.OperationID)
|
||||
if !ok {
|
||||
errMsg := req.OperationID + " " + rpcReq.OpUserID + " " + "GetUserIDFromToken failed " + errInfo + " token:" + c.Request.Header.Get("token")
|
||||
log.NewError(req.OperationID, errMsg)
|
||||
c.JSON(http.StatusOK, gin.H{"errCode": 500, "errMsg": errMsg})
|
||||
return
|
||||
}
|
||||
options := make(map[string]bool, 5)
|
||||
utils.SetSwitchFromOptions(options, constant.IsConversationUpdate, false)
|
||||
utils.SetSwitchFromOptions(options, constant.IsSenderConversationUpdate, false)
|
||||
utils.SetSwitchFromOptions(options, constant.IsUnreadCount, false)
|
||||
utils.SetSwitchFromOptions(options, constant.IsOfflinePush, false)
|
||||
pbData := rpc.SendMsgReq{
|
||||
OperationID: req.OperationID,
|
||||
MsgData: &pbCommon.MsgData{
|
||||
SendID: req.UserID,
|
||||
RecvID: req.UserID,
|
||||
ClientMsgID: utils.GetMsgID(req.UserID),
|
||||
SessionType: constant.SingleChatType,
|
||||
MsgFrom: constant.SysMsgType,
|
||||
ContentType: constant.MsgDeleteNotification,
|
||||
// ForceList: params.ForceList,
|
||||
CreateTime: utils.GetCurrentTimestampByMill(),
|
||||
Options: options,
|
||||
},
|
||||
}
|
||||
var tips pbCommon.TipsComm
|
||||
deleteMsg := api.MsgDeleteNotificationElem{
|
||||
GroupID: req.GroupID,
|
||||
IsAllDelete: req.IsAllDelete,
|
||||
SeqList: req.SeqList,
|
||||
}
|
||||
tips.JsonDetail = utils.StructToJsonString(deleteMsg)
|
||||
var err error
|
||||
pbData.MsgData.Content, err = proto.Marshal(&tips)
|
||||
if err != nil {
|
||||
log.Error(req.OperationID, "Marshal failed ", err.Error(), tips.String())
|
||||
resp.ErrCode = 400
|
||||
resp.ErrMsg = err.Error()
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), resp)
|
||||
c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
log.Info(req.OperationID, "", "api DelSuperGroupMsg call start..., [data: %s]", pbData.String())
|
||||
etcdConn := rpc.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImMsgName, req.OperationID)
|
||||
if etcdConn == nil {
|
||||
errMsg := req.OperationID + "getcdv3.GetDefaultConn == nil"
|
||||
log.NewError(req.OperationID, errMsg)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
|
||||
return
|
||||
}
|
||||
client := rpc.NewMsgClient(etcdConn)
|
||||
|
||||
log.Info(req.OperationID, "", "api DelSuperGroupMsg call, api call rpc...")
|
||||
if req.IsAllDelete {
|
||||
RpcResp, err := client.DelSuperGroupMsg(context.Background(), rpcReq)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "call delete DelSuperGroupMsg rpc server failed", err.Error())
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "call DelSuperGroupMsg rpc server failed"})
|
||||
return
|
||||
}
|
||||
log.Info(req.OperationID, "", "api DelSuperGroupMsg call end..., [data: %s] [reply: %s]", pbData.String(), RpcResp.String())
|
||||
resp.ErrCode = RpcResp.ErrCode
|
||||
resp.ErrMsg = RpcResp.ErrMsg
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), resp)
|
||||
c.JSON(http.StatusOK, resp)
|
||||
} else {
|
||||
RpcResp, err := client.SendMsg(context.Background(), &pbData)
|
||||
if err != nil {
|
||||
log.NewError(req.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(req.OperationID, "", "api DelSuperGroupMsg call end..., [data: %s] [reply: %s]", pbData.String(), RpcResp.String())
|
||||
resp.ErrCode = RpcResp.ErrCode
|
||||
resp.ErrMsg = RpcResp.ErrMsg
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), resp)
|
||||
c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// @Summary 清空用户消息
|
||||
// @Description 清空用户消息
|
||||
// @Tags 消息相关
|
||||
// @ID ClearMsg
|
||||
// @Accept json
|
||||
// @Param token header string true "im token"
|
||||
// @Param req body api.CleanUpMsgReq true "userID为要清空的用户ID"
|
||||
// @Produce json
|
||||
// @Success 0 {object} api.CleanUpMsgResp
|
||||
// @Failure 500 {object} api.Swagger500Resp "errCode为500 一般为服务器内部错误"
|
||||
// @Failure 400 {object} api.Swagger400Resp "errCode为400 一般为参数输入错误, token未带上等"
|
||||
// @Router /msg/clear_msg [post]
|
||||
func ClearMsg(c *gin.Context) {
|
||||
params := api.CleanUpMsgReq{}
|
||||
if err := c.BindJSON(¶ms); err != nil {
|
||||
log.NewError("0", "BindJSON failed ", err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
//
|
||||
req := &rpc.ClearMsgReq{}
|
||||
utils.CopyStructFields(req, ¶ms)
|
||||
|
||||
var ok bool
|
||||
var errInfo string
|
||||
ok, req.OpUserID, errInfo = tokenverify.GetUserIDFromToken(c.Request.Header.Get("token"), req.OperationID)
|
||||
if !ok {
|
||||
errMsg := req.OperationID + " " + "GetUserIDFromToken failed " + errInfo + " token:" + c.Request.Header.Get("token")
|
||||
log.NewError(req.OperationID, errMsg)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
|
||||
return
|
||||
}
|
||||
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), " api args ", req.String())
|
||||
|
||||
etcdConn := rpc.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImMsgName, req.OperationID)
|
||||
if etcdConn == nil {
|
||||
errMsg := req.OperationID + " getcdv3.GetDefaultConn == nil"
|
||||
log.NewError(req.OperationID, errMsg)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
|
||||
return
|
||||
}
|
||||
client := rpc.NewMsgClient(etcdConn)
|
||||
RpcResp, err := client.ClearMsg(context.Background(), req)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, " CleanUpMsg failed ", err.Error(), req.String(), RpcResp.ErrMsg)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": RpcResp.ErrMsg})
|
||||
return
|
||||
}
|
||||
|
||||
resp := api.CleanUpMsgResp{CommResp: api.CommResp{ErrCode: RpcResp.ErrCode, ErrMsg: RpcResp.ErrMsg}}
|
||||
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), " api return ", resp)
|
||||
c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
|
||||
// @Summary 设置用户最小seq
|
||||
// @Description 设置用户最小seq,以及用户相关读扩散群组最小seq
|
||||
// @Tags 消息相关
|
||||
// @ID SetMsgMinSeq
|
||||
// @Accept json
|
||||
// @Param token header string true "im token"
|
||||
func SetMsgMinSeq(c *gin.Context) {
|
||||
params := api.SetMsgMinSeqReq{}
|
||||
if err := c.BindJSON(¶ms); err != nil {
|
||||
log.NewError("0", "BindJSON failed ", err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
//
|
||||
req := &rpc.SetMsgMinSeqReq{}
|
||||
utils.CopyStructFields(req, ¶ms)
|
||||
|
||||
var ok bool
|
||||
var errInfo string
|
||||
ok, req.OpUserID, errInfo = tokenverify.GetUserIDFromToken(c.Request.Header.Get("token"), req.OperationID)
|
||||
if !ok {
|
||||
errMsg := req.OperationID + " " + "GetUserIDFromToken failed " + errInfo + " token:" + c.Request.Header.Get("token")
|
||||
log.NewError(req.OperationID, errMsg)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
|
||||
return
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), " api args ", req.String())
|
||||
etcdConn := rpc.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImMsgName, req.OperationID)
|
||||
if etcdConn == nil {
|
||||
errMsg := req.OperationID + " getcdv3.GetDefaultConn == nil"
|
||||
log.NewError(req.OperationID, errMsg)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
|
||||
return
|
||||
}
|
||||
client := rpc.NewMsgClient(etcdConn)
|
||||
RpcResp, err := client.SetMsgMinSeq(context.Background(), req)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, " SetMsgMinSeq failed ", err.Error(), req.String(), RpcResp.ErrMsg)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": RpcResp.ErrMsg})
|
||||
return
|
||||
}
|
||||
|
||||
resp := api.SetMsgMinSeqResp{CommResp: api.CommResp{ErrCode: RpcResp.ErrCode, ErrMsg: RpcResp.ErrMsg}}
|
||||
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), " api return ", resp)
|
||||
c.JSON(http.StatusOK, resp)
|
||||
}
|
@ -1,202 +0,0 @@
|
||||
package msg
|
||||
|
||||
import (
|
||||
api "OpenIM/pkg/apistruct"
|
||||
"OpenIM/pkg/common/config"
|
||||
"OpenIM/pkg/common/constant"
|
||||
"OpenIM/pkg/common/log"
|
||||
"OpenIM/pkg/common/tokenverify"
|
||||
rpc "OpenIM/pkg/proto/msg"
|
||||
"OpenIM/pkg/utils"
|
||||
"context"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func SetMessageReactionExtensions(c *gin.Context) {
|
||||
var (
|
||||
req api.SetMessageReactionExtensionsCallbackReq
|
||||
resp api.SetMessageReactionExtensionsCallbackResp
|
||||
reqPb rpc.SetMessageReactionExtensionsReq
|
||||
)
|
||||
|
||||
if err := c.BindJSON(&req); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req:", req)
|
||||
|
||||
if err := utils.CopyStructFields(&reqPb, &req); err != nil {
|
||||
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "CopyStructFields", err.Error())
|
||||
}
|
||||
var ok bool
|
||||
var errInfo string
|
||||
ok, reqPb.OpUserID, errInfo = tokenverify.GetUserIDFromToken(c.Request.Header.Get("token"), req.OperationID)
|
||||
if !ok {
|
||||
errMsg := req.OperationID + " " + "GetUserIDFromToken failed " + errInfo + " token:" + c.Request.Header.Get("token")
|
||||
log.NewError(req.OperationID, errMsg)
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 500, "errMsg": errMsg})
|
||||
return
|
||||
}
|
||||
|
||||
grpcConn := rpc.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImMsgName, req.OperationID)
|
||||
if grpcConn == nil {
|
||||
errMsg := req.OperationID + " getcdv3.GetDefaultConn == nil"
|
||||
log.NewError(req.OperationID, errMsg)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
|
||||
return
|
||||
}
|
||||
msgClient := rpc.NewMsgClient(grpcConn)
|
||||
respPb, err := msgClient.SetMessageReactionExtensions(context.Background(), &reqPb)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "DelMsgList failed", err.Error(), reqPb)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": constant.ErrServer.ErrCode, "errMsg": constant.ErrServer.ErrMsg + err.Error()})
|
||||
return
|
||||
}
|
||||
resp.ErrCode = respPb.ErrCode
|
||||
resp.ErrMsg = respPb.ErrMsg
|
||||
resp.Data.ResultKeyValue = respPb.Result
|
||||
resp.Data.MsgFirstModifyTime = reqPb.MsgFirstModifyTime
|
||||
resp.Data.IsReact = reqPb.IsReact
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), resp)
|
||||
c.JSON(http.StatusOK, resp)
|
||||
|
||||
}
|
||||
|
||||
func GetMessageListReactionExtensions(c *gin.Context) {
|
||||
var (
|
||||
req api.GetMessageListReactionExtensionsReq
|
||||
resp api.GetMessageListReactionExtensionsResp
|
||||
reqPb rpc.GetMessageListReactionExtensionsReq
|
||||
)
|
||||
if err := c.BindJSON(&req); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req:", req)
|
||||
|
||||
if err := utils.CopyStructFields(&reqPb, &req); err != nil {
|
||||
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "CopyStructFields", err.Error())
|
||||
}
|
||||
var ok bool
|
||||
var errInfo string
|
||||
ok, reqPb.OpUserID, errInfo = tokenverify.GetUserIDFromToken(c.Request.Header.Get("token"), req.OperationID)
|
||||
if !ok {
|
||||
errMsg := req.OperationID + " " + "GetUserIDFromToken failed " + errInfo + " token:" + c.Request.Header.Get("token")
|
||||
log.NewError(req.OperationID, errMsg)
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 500, "errMsg": errMsg})
|
||||
return
|
||||
}
|
||||
|
||||
grpcConn := rpc.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImMsgName, req.OperationID)
|
||||
if grpcConn == nil {
|
||||
errMsg := req.OperationID + " getcdv3.GetDefaultConn == nil"
|
||||
log.NewError(req.OperationID, errMsg)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
|
||||
return
|
||||
}
|
||||
msgClient := rpc.NewMsgClient(grpcConn)
|
||||
respPb, err := msgClient.GetMessageListReactionExtensions(context.Background(), &reqPb)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "DelMsgList failed", err.Error(), reqPb)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": constant.ErrServer.ErrCode, "errMsg": constant.ErrServer.ErrMsg + err.Error()})
|
||||
return
|
||||
}
|
||||
resp.ErrCode = respPb.ErrCode
|
||||
resp.ErrMsg = respPb.ErrMsg
|
||||
resp.Data = respPb.SingleMessageResult
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), resp)
|
||||
c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
|
||||
func AddMessageReactionExtensions(c *gin.Context) {
|
||||
var (
|
||||
req api.AddMessageReactionExtensionsReq
|
||||
resp api.AddMessageReactionExtensionsResp
|
||||
reqPb rpc.ModifyMessageReactionExtensionsReq
|
||||
)
|
||||
if err := c.BindJSON(&req); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req:", req)
|
||||
|
||||
if err := utils.CopyStructFields(&reqPb, &req); err != nil {
|
||||
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "CopyStructFields", err.Error())
|
||||
}
|
||||
var ok bool
|
||||
var errInfo string
|
||||
ok, reqPb.OpUserID, errInfo = tokenverify.GetUserIDFromToken(c.Request.Header.Get("token"), req.OperationID)
|
||||
if !ok {
|
||||
errMsg := req.OperationID + " " + "GetUserIDFromToken failed " + errInfo + " token:" + c.Request.Header.Get("token")
|
||||
log.NewError(req.OperationID, errMsg)
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 500, "errMsg": errMsg})
|
||||
return
|
||||
}
|
||||
|
||||
grpcConn := rpc.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImMsgName, req.OperationID)
|
||||
if grpcConn == nil {
|
||||
errMsg := req.OperationID + " getcdv3.GetDefaultConn == nil"
|
||||
log.NewError(req.OperationID, errMsg)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
|
||||
return
|
||||
}
|
||||
msgClient := rpc.NewMsgClient(grpcConn)
|
||||
respPb, err := msgClient.AddMessageReactionExtensions(context.Background(), &reqPb)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "DelMsgList failed", err.Error(), reqPb)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": constant.ErrServer.ErrCode, "errMsg": constant.ErrServer.ErrMsg + err.Error()})
|
||||
return
|
||||
}
|
||||
resp.ErrCode = respPb.ErrCode
|
||||
resp.ErrMsg = respPb.ErrMsg
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), resp)
|
||||
c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
|
||||
func DeleteMessageReactionExtensions(c *gin.Context) {
|
||||
var (
|
||||
req api.DeleteMessageReactionExtensionsReq
|
||||
resp api.DeleteMessageReactionExtensionsResp
|
||||
reqPb rpc.DeleteMessageListReactionExtensionsReq
|
||||
)
|
||||
if err := c.BindJSON(&req); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req:", req)
|
||||
|
||||
if err := utils.CopyStructFields(&reqPb, &req); err != nil {
|
||||
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "CopyStructFields", err.Error())
|
||||
}
|
||||
var ok bool
|
||||
var errInfo string
|
||||
ok, reqPb.OpUserID, errInfo = tokenverify.GetUserIDFromToken(c.Request.Header.Get("token"), req.OperationID)
|
||||
if !ok {
|
||||
errMsg := req.OperationID + " " + "GetUserIDFromToken failed " + errInfo + " token:" + c.Request.Header.Get("token")
|
||||
log.NewError(req.OperationID, errMsg)
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 500, "errMsg": errMsg})
|
||||
return
|
||||
}
|
||||
|
||||
grpcConn := rpc.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImMsgName, req.OperationID)
|
||||
if grpcConn == nil {
|
||||
errMsg := req.OperationID + " getcdv3.GetDefaultConn == nil"
|
||||
log.NewError(req.OperationID, errMsg)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
|
||||
return
|
||||
}
|
||||
msgClient := rpc.NewMsgClient(grpcConn)
|
||||
respPb, err := msgClient.DeleteMessageReactionExtensions(context.Background(), &reqPb)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "DelMsgList failed", err.Error(), reqPb)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": constant.ErrServer.ErrCode, "errMsg": constant.ErrServer.ErrMsg + err.Error()})
|
||||
return
|
||||
}
|
||||
resp.ErrCode = respPb.ErrCode
|
||||
resp.ErrMsg = respPb.ErrMsg
|
||||
resp.Data = respPb.Result
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), resp)
|
||||
c.JSON(http.StatusOK, resp)
|
||||
}
|
@ -1,64 +0,0 @@
|
||||
package msg
|
||||
|
||||
import (
|
||||
"OpenIM/pkg/common/config"
|
||||
"OpenIM/pkg/common/log"
|
||||
"OpenIM/pkg/common/tokenverify"
|
||||
pbChat "OpenIM/pkg/proto/msg"
|
||||
sdkws "OpenIM/pkg/proto/sdkws"
|
||||
"context"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type paramsUserNewestSeq struct {
|
||||
ReqIdentifier int `json:"reqIdentifier" binding:"required"`
|
||||
SendID string `json:"sendID" binding:"required"`
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
MsgIncr int `json:"msgIncr" binding:"required"`
|
||||
}
|
||||
|
||||
func GetSeq(c *gin.Context) {
|
||||
params := paramsUserNewestSeq{}
|
||||
if err := c.BindJSON(¶ms); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
token := c.Request.Header.Get("token")
|
||||
if ok, err := tokenverify.VerifyToken(token, params.SendID); !ok {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": "token validate err" + err.Error()})
|
||||
return
|
||||
}
|
||||
pbData := sdkws.GetMaxAndMinSeqReq{}
|
||||
pbData.UserID = params.SendID
|
||||
pbData.OperationID = params.OperationID
|
||||
grpcConn := rpc.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImMsgName, pbData.OperationID)
|
||||
if grpcConn == nil {
|
||||
errMsg := pbData.OperationID + " getcdv3.GetDefaultConn == nil"
|
||||
log.NewError(pbData.OperationID, errMsg)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
|
||||
return
|
||||
}
|
||||
|
||||
msgClient := pbChat.NewMsgClient(grpcConn)
|
||||
reply, err := msgClient.GetMaxAndMinSeq(context.Background(), &pbData)
|
||||
if err != nil {
|
||||
log.NewError(params.OperationID, "UserGetSeq rpc failed, ", params, err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 401, "errMsg": "UserGetSeq rpc failed, " + err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"errCode": reply.ErrCode,
|
||||
"errMsg": reply.ErrMsg,
|
||||
"msgIncr": params.MsgIncr,
|
||||
"reqIdentifier": params.ReqIdentifier,
|
||||
"data": gin.H{
|
||||
"maxSeq": reply.MaxSeq,
|
||||
"minSeq": reply.MinSeq,
|
||||
},
|
||||
})
|
||||
|
||||
}
|
@ -1,73 +0,0 @@
|
||||
package msg
|
||||
|
||||
import (
|
||||
"OpenIM/pkg/common/config"
|
||||
"OpenIM/pkg/common/log"
|
||||
"OpenIM/pkg/common/tokenverify"
|
||||
"OpenIM/pkg/proto/msg"
|
||||
sdkws "OpenIM/pkg/proto/sdkws"
|
||||
"OpenIM/pkg/utils"
|
||||
"context"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type paramsUserPullMsg struct {
|
||||
ReqIdentifier *int `json:"reqIdentifier" binding:"required"`
|
||||
SendID string `json:"sendID" binding:"required"`
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
Data struct {
|
||||
SeqBegin *int64 `json:"seqBegin" binding:"required"`
|
||||
SeqEnd *int64 `json:"seqEnd" binding:"required"`
|
||||
}
|
||||
}
|
||||
|
||||
type paramsUserPullMsgBySeqList struct {
|
||||
ReqIdentifier int `json:"reqIdentifier" binding:"required"`
|
||||
SendID string `json:"sendID" binding:"required"`
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
SeqList []uint32 `json:"seqList"`
|
||||
}
|
||||
|
||||
func PullMsgBySeqList(c *gin.Context) {
|
||||
params := paramsUserPullMsgBySeqList{}
|
||||
if err := c.BindJSON(¶ms); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
token := c.Request.Header.Get("token")
|
||||
if ok, err := tokenverify.VerifyToken(token, params.SendID); !ok {
|
||||
if err != nil {
|
||||
log.NewError(params.OperationID, utils.GetSelfFuncName(), err.Error(), token, params.SendID)
|
||||
}
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": "token validate err"})
|
||||
return
|
||||
}
|
||||
pbData := sdkws.PullMessageBySeqListReq{}
|
||||
pbData.UserID = params.SendID
|
||||
pbData.OperationID = params.OperationID
|
||||
pbData.SeqList = params.SeqList
|
||||
|
||||
grpcConn := rpc.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImMsgName, pbData.OperationID)
|
||||
if grpcConn == nil {
|
||||
errMsg := pbData.OperationID + "getcdv3.GetDefaultConn == nil"
|
||||
log.NewError(pbData.OperationID, errMsg)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
|
||||
return
|
||||
}
|
||||
msgClient := msg.NewMsgClient(grpcConn)
|
||||
reply, err := msgClient.PullMessageBySeqList(context.Background(), &pbData)
|
||||
if err != nil {
|
||||
log.Error(pbData.OperationID, "PullMessageBySeqList error", err.Error())
|
||||
return
|
||||
}
|
||||
log.NewInfo(pbData.OperationID, "rpc call success to PullMessageBySeqList", reply.String(), len(reply.List))
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"errCode": reply.ErrCode,
|
||||
"errMsg": reply.ErrMsg,
|
||||
"reqIdentifier": params.ReqIdentifier,
|
||||
"data": reply.List,
|
||||
})
|
||||
}
|
@ -1,102 +0,0 @@
|
||||
package msg
|
||||
|
||||
import (
|
||||
"OpenIM/pkg/common/config"
|
||||
"OpenIM/pkg/common/log"
|
||||
pbChat "OpenIM/pkg/proto/msg"
|
||||
sdkws "OpenIM/pkg/proto/sdkws"
|
||||
"context"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type paramsUserSendMsg struct {
|
||||
SenderPlatformID int32 `json:"senderPlatformID" binding:"required"`
|
||||
SendID string `json:"sendID" binding:"required"`
|
||||
SenderNickName string `json:"senderNickName"`
|
||||
SenderFaceURL string `json:"senderFaceUrl"`
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
Data struct {
|
||||
SessionType int32 `json:"sessionType" binding:"required"`
|
||||
MsgFrom int32 `json:"msgFrom" binding:"required"`
|
||||
ContentType int32 `json:"contentType" binding:"required"`
|
||||
RecvID string `json:"recvID" `
|
||||
GroupID string `json:"groupID" `
|
||||
ForceList []string `json:"forceList"`
|
||||
Content []byte `json:"content" binding:"required"`
|
||||
Options map[string]bool `json:"options" `
|
||||
ClientMsgID string `json:"clientMsgID" binding:"required"`
|
||||
CreateTime int64 `json:"createTime" binding:"required"`
|
||||
OffLineInfo *sdkws.OfflinePushInfo `json:"offlineInfo" `
|
||||
}
|
||||
}
|
||||
|
||||
func newUserSendMsgReq(token string, params *paramsUserSendMsg) *pbChat.SendMsgReq {
|
||||
pbData := pbChat.SendMsgReq{
|
||||
Token: token,
|
||||
OperationID: params.OperationID,
|
||||
MsgData: &sdkws.MsgData{
|
||||
SendID: params.SendID,
|
||||
RecvID: params.Data.RecvID,
|
||||
GroupID: params.Data.GroupID,
|
||||
ClientMsgID: params.Data.ClientMsgID,
|
||||
SenderPlatformID: params.SenderPlatformID,
|
||||
SenderNickname: params.SenderNickName,
|
||||
SenderFaceURL: params.SenderFaceURL,
|
||||
SessionType: params.Data.SessionType,
|
||||
MsgFrom: params.Data.MsgFrom,
|
||||
ContentType: params.Data.ContentType,
|
||||
Content: params.Data.Content,
|
||||
CreateTime: params.Data.CreateTime,
|
||||
Options: params.Data.Options,
|
||||
OfflinePushInfo: params.Data.OffLineInfo,
|
||||
},
|
||||
}
|
||||
return &pbData
|
||||
}
|
||||
|
||||
func SendMsg(c *gin.Context) {
|
||||
params := paramsUserSendMsg{}
|
||||
if err := c.BindJSON(¶ms); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||
log.Error("0", "BindJSON failed ", err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
token := c.Request.Header.Get("token")
|
||||
log.NewInfo(params.OperationID, "api call success to sendMsgReq", params)
|
||||
pbData := newUserSendMsgReq(token, ¶ms)
|
||||
log.Info(params.OperationID, "", "api SendMsg call start..., [data: %s]", pbData.String())
|
||||
|
||||
etcdConn := rpc.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImMsgName, params.OperationID)
|
||||
if etcdConn == nil {
|
||||
errMsg := params.OperationID + "getcdv3.GetDefaultConn == nil"
|
||||
log.NewError(params.OperationID, errMsg)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
|
||||
return
|
||||
}
|
||||
client := pbChat.NewMsgClient(etcdConn)
|
||||
|
||||
log.Info(params.OperationID, "", "api SendMsg call, api call rpc...")
|
||||
|
||||
reply, err := client.SendMsg(context.Background(), pbData)
|
||||
if err != nil {
|
||||
log.NewError(params.OperationID, "SendMsg rpc failed, ", params, err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 401, "errMsg": "SendMsg rpc failed, " + err.Error()})
|
||||
return
|
||||
}
|
||||
log.Info(params.OperationID, "", "api SendMsg call end..., [data: %s] [reply: %s]", pbData.String(), reply.String())
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"errCode": reply.ErrCode,
|
||||
"errMsg": reply.ErrMsg,
|
||||
"data": gin.H{
|
||||
"clientMsgID": reply.ClientMsgID,
|
||||
"serverMsgID": reply.ServerMsgID,
|
||||
"sendTime": reply.SendTime,
|
||||
},
|
||||
})
|
||||
|
||||
}
|
@ -1,7 +1,6 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"OpenIM/internal/api/conversation"
|
||||
"OpenIM/internal/api/manage"
|
||||
"OpenIM/internal/api/msg"
|
||||
"OpenIM/internal/api/third"
|
||||
@ -9,6 +8,7 @@ import (
|
||||
"OpenIM/pkg/common/log"
|
||||
"OpenIM/pkg/common/middleware"
|
||||
"OpenIM/pkg/common/prome"
|
||||
"github.com/OpenIMSDK/openKeeper"
|
||||
"github.com/gin-gonic/gin"
|
||||
"io"
|
||||
"os"
|
||||
@ -31,9 +31,11 @@ func NewGinRouter() *gin.Engine {
|
||||
r.GET("/metrics", prome.PrometheusHandler())
|
||||
}
|
||||
|
||||
var zk *openKeeper.ZkClient
|
||||
|
||||
userRouterGroup := r.Group("/user")
|
||||
{
|
||||
u := NewUser(nil)
|
||||
u := NewUser(zk)
|
||||
userRouterGroup.POST("/update_user_info", u.UpdateUserInfo) //1
|
||||
userRouterGroup.POST("/set_global_msg_recv_opt", u.SetGlobalRecvMessageOpt)
|
||||
userRouterGroup.POST("/get_users_info", u.GetUsersPublicInfo) //1
|
||||
@ -49,23 +51,23 @@ func NewGinRouter() *gin.Engine {
|
||||
////friend routing group
|
||||
friendRouterGroup := r.Group("/friend")
|
||||
{
|
||||
f := NewFriend(nil)
|
||||
friendRouterGroup.POST("/add_friend", f.AddFriend) //1
|
||||
f := NewFriend(zk)
|
||||
friendRouterGroup.POST("/add_friend", f.ApplyToAddFriend) //1
|
||||
friendRouterGroup.POST("/delete_friend", f.DeleteFriend) //1
|
||||
friendRouterGroup.POST("/get_friend_apply_list", f.GetFriendApplyList) //1
|
||||
friendRouterGroup.POST("/get_self_friend_apply_list", f.GetSelfApplyList) //1
|
||||
friendRouterGroup.POST("/get_friend_list", f.GetFriendList) //1
|
||||
friendRouterGroup.POST("/add_friend_response", f.AddFriendResponse) //1
|
||||
friendRouterGroup.POST("/add_friend_response", f.RespondFriendApply) //1
|
||||
friendRouterGroup.POST("/set_friend_remark", f.SetFriendRemark) //1
|
||||
friendRouterGroup.POST("/add_black", f.AddBlack) //1
|
||||
friendRouterGroup.POST("/get_black_list", f.GetBlacklist) //1
|
||||
friendRouterGroup.POST("/remove_black", f.RemoveBlacklist) //1
|
||||
friendRouterGroup.POST("/import_friend", f.ImportFriend) //1
|
||||
friendRouterGroup.POST("/get_black_list", f.GetPaginationBlacks) //1
|
||||
friendRouterGroup.POST("/remove_black", f.RemoveBlack) //1
|
||||
friendRouterGroup.POST("/import_friend", f.ImportFriends) //1
|
||||
friendRouterGroup.POST("/is_friend", f.IsFriend) //1
|
||||
|
||||
}
|
||||
groupRouterGroup := r.Group("/group")
|
||||
g := NewGroup(nil)
|
||||
g := NewGroup(zk)
|
||||
{
|
||||
groupRouterGroup.POST("/create_group", g.NewCreateGroup) //1
|
||||
groupRouterGroup.POST("/set_group_info", g.NewSetGroupInfo) //1
|
||||
@ -98,7 +100,7 @@ func NewGinRouter() *gin.Engine {
|
||||
////certificate
|
||||
authRouterGroup := r.Group("/auth")
|
||||
{
|
||||
a := NewAuth(nil)
|
||||
a := NewAuth(zk)
|
||||
authRouterGroup.POST("/user_register", a.UserRegister) //1
|
||||
authRouterGroup.POST("/user_token", a.UserToken) //1
|
||||
authRouterGroup.POST("/parse_token", a.ParseToken) //1
|
||||
@ -141,13 +143,36 @@ func NewGinRouter() *gin.Engine {
|
||||
////Conversation
|
||||
conversationGroup := r.Group("/conversation")
|
||||
{ //1
|
||||
conversationGroup.POST("/get_all_conversations", conversation.GetAllConversations)
|
||||
conversationGroup.POST("/get_conversation", conversation.GetConversation)
|
||||
conversationGroup.POST("/get_conversations", conversation.GetConversations)
|
||||
conversationGroup.POST("/set_conversation", conversation.SetConversation)
|
||||
conversationGroup.POST("/batch_set_conversation", conversation.BatchSetConversations)
|
||||
conversationGroup.POST("/set_recv_msg_opt", conversation.SetRecvMsgOpt)
|
||||
conversationGroup.POST("/modify_conversation_field", conversation.ModifyConversationField)
|
||||
c := NewConversation(zk)
|
||||
conversationGroup.POST("/get_all_conversations", c.GetAllConversations)
|
||||
conversationGroup.POST("/get_conversation", c.GetConversation)
|
||||
conversationGroup.POST("/get_conversations", c.GetConversations)
|
||||
conversationGroup.POST("/set_conversation", c.SetConversation)
|
||||
conversationGroup.POST("/batch_set_conversation", c.BatchSetConversations)
|
||||
conversationGroup.POST("/set_recv_msg_opt", c.SetRecvMsgOpt)
|
||||
conversationGroup.POST("/modify_conversation_field", c.ModifyConversationField)
|
||||
}
|
||||
return r
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
{
|
||||
GetSeq
|
||||
SendMsg
|
||||
PullMsgBySeqList
|
||||
DelMsg
|
||||
DelSuperGroupMsg
|
||||
ClearMsg
|
||||
SetMsgMinSeq
|
||||
SetMessageReactionExtensions
|
||||
GetMessageListReactionExtensions
|
||||
AddMessageReactionExtensions
|
||||
DeleteMessageReactionExtensions
|
||||
ManagementSendMsg
|
||||
ManagementBatchSendMsg
|
||||
CheckMsgIsSendSuccess
|
||||
}
|
||||
|
||||
|
||||
*/
|
||||
|
@ -19,54 +19,54 @@ type User struct {
|
||||
zk *openKeeper.ZkClient
|
||||
}
|
||||
|
||||
func (u *User) getGroupClient() (user.UserClient, error) {
|
||||
conn, err := u.zk.GetConn(config.Config.RpcRegisterName.OpenImGroupName)
|
||||
func (o *User) client() (user.UserClient, error) {
|
||||
conn, err := o.zk.GetConn(config.Config.RpcRegisterName.OpenImGroupName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return user.NewUserClient(conn), nil
|
||||
}
|
||||
|
||||
func (u *User) UpdateUserInfo(c *gin.Context) {
|
||||
a2r.Call(user.UserClient.UpdateUserInfo, u.getGroupClient, c)
|
||||
func (o *User) UpdateUserInfo(c *gin.Context) {
|
||||
a2r.Call(user.UserClient.UpdateUserInfo, o.client, c)
|
||||
}
|
||||
|
||||
func (u *User) SetGlobalRecvMessageOpt(c *gin.Context) {
|
||||
a2r.Call(user.UserClient.SetGlobalRecvMessageOpt, u.getGroupClient, c)
|
||||
func (o *User) SetGlobalRecvMessageOpt(c *gin.Context) {
|
||||
a2r.Call(user.UserClient.SetGlobalRecvMessageOpt, o.client, c)
|
||||
}
|
||||
|
||||
func (u *User) GetUsersPublicInfo(c *gin.Context) {
|
||||
a2r.Call(user.UserClient.GetDesignateUsers, u.getGroupClient, c)
|
||||
func (o *User) GetUsersPublicInfo(c *gin.Context) {
|
||||
a2r.Call(user.UserClient.GetDesignateUsers, o.client, c)
|
||||
}
|
||||
|
||||
func (u *User) GetSelfUserInfo(c *gin.Context) {
|
||||
a2r.Call(user.UserClient.GetSelfUserInfo, u.getGroupClient, c)
|
||||
func (o *User) GetSelfUserInfo(c *gin.Context) {
|
||||
a2r.Call(user.UserClient.GetSelfUserInfo, o.client, c)
|
||||
}
|
||||
|
||||
func (u *User) GetUsersOnlineStatus(c *gin.Context) {
|
||||
a2r.Call(user.UserClient.GetUsersOnlineStatus, u.getGroupClient, c)
|
||||
func (o *User) GetUsersOnlineStatus(c *gin.Context) {
|
||||
a2r.Call(user.UserClient.GetUsersOnlineStatus, o.client, c)
|
||||
}
|
||||
|
||||
func (u *User) GetUsersInfoFromCache(c *gin.Context) {
|
||||
a2r.Call(user.UserClient.GetUsersInfoFromCache, u.getGroupClient, c)
|
||||
func (o *User) GetUsersInfoFromCache(c *gin.Context) {
|
||||
a2r.Call(user.UserClient.GetUsersInfoFromCache, o.client, c)
|
||||
}
|
||||
|
||||
func (u *User) GetFriendIDListFromCache(c *gin.Context) {
|
||||
a2r.Call(user.UserClient.GetFriendIDListFromCache, u.getGroupClient, c)
|
||||
func (o *User) GetFriendIDListFromCache(c *gin.Context) {
|
||||
a2r.Call(user.UserClient.GetFriendIDListFromCache, o.client, c)
|
||||
}
|
||||
|
||||
func (u *User) GetBlackIDListFromCache(c *gin.Context) {
|
||||
a2r.Call(user.UserClient.GetBlackIDListFromCache, u.getGroupClient, c)
|
||||
func (o *User) GetBlackIDListFromCache(c *gin.Context) {
|
||||
a2r.Call(user.UserClient.GetBlackIDListFromCache, o.client, c)
|
||||
}
|
||||
|
||||
//func (u *User) GetAllUsersUid(c *gin.Context) {
|
||||
// a2r.Call(user.UserClient.GetAllUsersUid, u.getGroupClient, c)
|
||||
// a2r.Call(user.UserClient.GetAllUsersUid, u.client, c)
|
||||
//}
|
||||
//
|
||||
//func (u *User) AccountCheck(c *gin.Context) {
|
||||
// a2r.Call(user.UserClient.AccountCheck, u.getGroupClient, c)
|
||||
// a2r.Call(user.UserClient.AccountCheck, u.client, c)
|
||||
//}
|
||||
|
||||
func (u *User) GetUsers(c *gin.Context) {
|
||||
a2r.Call(user.UserClient.GetPaginationUsers, u.getGroupClient, c)
|
||||
func (o *User) GetUsers(c *gin.Context) {
|
||||
a2r.Call(user.UserClient.GetPaginationUsers, o.client, c)
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
syntax = "proto3";
|
||||
import "Open-IM-Server/pkg/proto/sdkws/ws.proto";
|
||||
import "Open-IM-Server/pkg/proto/sdkws/wrappers.proto";
|
||||
import "sdkws/ws.proto";
|
||||
import "sdkws/wrappers.proto";
|
||||
option go_package = "OpenIM/pkg/proto/group;group";
|
||||
package group;
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
syntax = "proto3";
|
||||
import "Open-IM-Server/pkg/proto/sdkws/wrappers.proto";
|
||||
import "sdkws/wrappers.proto";
|
||||
option go_package = "OpenIM/pkg/proto/sdkws;sdkws";
|
||||
package sdkws;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user