You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Open-IM-Server/internal/cms_api/message_cms/message.go

110 lines
3.8 KiB

3 years ago
package messageCMS
3 years ago
import (
3 years ago
"Open_IM/pkg/cms_api_struct"
"Open_IM/pkg/common/config"
3 years ago
openIMHttp "Open_IM/pkg/common/http"
3 years ago
"Open_IM/pkg/common/log"
"Open_IM/pkg/grpc-etcdv3/getcdv3"
pbMessage "Open_IM/pkg/proto/message_cms"
3 years ago
pbCommon "Open_IM/pkg/proto/sdk_ws"
3 years ago
"Open_IM/pkg/utils"
"context"
"strings"
3 years ago
3 years ago
"Open_IM/pkg/common/constant"
3 years ago
3 years ago
"github.com/gin-gonic/gin"
)
3 years ago
3 years ago
func BroadcastMessage(c *gin.Context) {
3 years ago
var (
reqPb pbMessage.BoradcastMessageReq
)
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImMessageCMSName)
client := pbMessage.NewMessageCMSClient(etcdConn)
_, err := client.BoradcastMessage(context.Background(), &reqPb)
if err != nil {
log.NewError(reqPb.OperationID, utils.GetSelfFuncName(), "GetChatLogs rpc failed", err.Error())
3 years ago
openIMHttp.RespHttp200(c, err, nil)
3 years ago
return
}
3 years ago
openIMHttp.RespHttp200(c, constant.OK, nil)
3 years ago
}
func MassSendMassage(c *gin.Context) {
3 years ago
var (
reqPb pbMessage.MassSendMessageReq
)
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImMessageCMSName)
client := pbMessage.NewMessageCMSClient(etcdConn)
_, err := client.MassSendMessage(context.Background(), &reqPb)
if err != nil {
log.NewError(reqPb.OperationID, utils.GetSelfFuncName(), "GetChatLogs rpc failed", err.Error())
openIMHttp.RespHttp200(c, err, nil)
return
}
3 years ago
openIMHttp.RespHttp200(c, constant.OK, nil)
3 years ago
}
3 years ago
func WithdrawMessage(c *gin.Context) {
3 years ago
var (
reqPb pbMessage.WithdrawMessageReq
)
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImMessageCMSName)
client := pbMessage.NewMessageCMSClient(etcdConn)
_, err := client.WithdrawMessage(context.Background(), &reqPb)
if err != nil {
log.NewError(reqPb.OperationID, utils.GetSelfFuncName(), "GetChatLogs rpc failed", err.Error())
openIMHttp.RespHttp200(c, err, nil)
return
}
3 years ago
openIMHttp.RespHttp200(c, constant.OK, nil)
3 years ago
}
3 years ago
func GetChatLogs(c *gin.Context) {
var (
req cms_api_struct.GetChatLogsRequest
resp cms_api_struct.GetChatLogsResponse
reqPb pbMessage.GetChatLogsReq
)
if err := c.ShouldBindQuery(&req); err != nil {
log.NewError(reqPb.OperationID, utils.GetSelfFuncName(), "ShouldBindQuery failed ", err.Error())
openIMHttp.RespHttp200(c, constant.ErrArgs, resp)
return
}
3 years ago
reqPb.Pagination = &pbCommon.RequestPagination{
PageNumber: int32(req.PageNumber),
ShowNumber: int32(req.ShowNumber),
}
3 years ago
utils.CopyStructFields(&reqPb, &req)
3 years ago
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImMessageCMSName)
client := pbMessage.NewMessageCMSClient(etcdConn)
3 years ago
respPb, err := client.GetChatLogs(context.Background(), &reqPb)
if err != nil {
log.NewError(reqPb.OperationID, utils.GetSelfFuncName(), "GetChatLogs rpc failed", err.Error())
3 years ago
openIMHttp.RespHttp200(c, err, resp)
3 years ago
return
}
3 years ago
//utils.CopyStructFields(&resp, &respPb)
for _, chatLog := range respPb.ChatLogs {
resp.ChatLogs = append(resp.ChatLogs, cms_api_struct.ChatLog{
SessionType: int(chatLog.SessionType),
ContentType: int(chatLog.ContentType),
SenderNickName: chatLog.SenderNickName,
SenderId: chatLog.SenderId,
SearchContent: chatLog.SearchContent,
WholeContent: chatLog.WholeContent,
ReceiverNickName: chatLog.ReciverNickName,
ReceiverID: chatLog.ReciverId,
GroupName: chatLog.GroupName,
GroupId: chatLog.GroupId,
Date: chatLog.Date,
})
}
resp.ShowNumber = int(respPb.Pagination.ShowNumber)
resp.CurrentPage = int(respPb.Pagination.CurrentPage)
resp.ChatLogsNum = int(respPb.ChatLogsNum)
3 years ago
openIMHttp.RespHttp200(c, constant.OK, resp)
}