mirror of
https://github.com/openimsdk/open-im-server.git
synced 2026-05-07 10:35:59 +08:00
feat: Optimizing RPC call (#2993)
* pb * fix: Modifying other fields while setting IsPrivateChat does not take effect * fix: quote message error revoke * refactoring scheduled tasks * refactoring scheduled tasks * refactoring scheduled tasks * refactoring scheduled tasks * refactoring scheduled tasks * refactoring scheduled tasks * rpc client * rpc client * rpc client * rpc client * rpc client * rpc client * rpc client * rpc client
This commit is contained in:
+34
-40
@@ -21,11 +21,10 @@ import (
|
||||
"github.com/openimsdk/open-im-server/v3/pkg/apistruct"
|
||||
"github.com/openimsdk/open-im-server/v3/pkg/authverify"
|
||||
"github.com/openimsdk/open-im-server/v3/pkg/common/config"
|
||||
"github.com/openimsdk/open-im-server/v3/pkg/rpcli"
|
||||
"github.com/openimsdk/protocol/constant"
|
||||
"github.com/openimsdk/protocol/msg"
|
||||
"github.com/openimsdk/protocol/rpccall"
|
||||
"github.com/openimsdk/protocol/sdkws"
|
||||
"github.com/openimsdk/protocol/user"
|
||||
"github.com/openimsdk/tools/a2r"
|
||||
"github.com/openimsdk/tools/apiresp"
|
||||
"github.com/openimsdk/tools/errs"
|
||||
@@ -38,12 +37,14 @@ import (
|
||||
)
|
||||
|
||||
type MessageApi struct {
|
||||
validate *validator.Validate
|
||||
Client msg.MsgClient
|
||||
userClient *rpcli.UserClient
|
||||
imAdminUserID []string
|
||||
validate *validator.Validate
|
||||
}
|
||||
|
||||
func NewMessageApi(imAdminUserID []string) MessageApi {
|
||||
return MessageApi{validate: validator.New(), imAdminUserID: imAdminUserID}
|
||||
func NewMessageApi(client msg.MsgClient, userClient *rpcli.UserClient, imAdminUserID []string) MessageApi {
|
||||
return MessageApi{Client: client, userClient: userClient, imAdminUserID: imAdminUserID, validate: validator.New()}
|
||||
}
|
||||
|
||||
func (*MessageApi) SetOptions(options map[string]bool, value bool) {
|
||||
@@ -105,51 +106,51 @@ func (m *MessageApi) newUserSendMsgReq(_ *gin.Context, params *apistruct.SendMsg
|
||||
}
|
||||
|
||||
func (m *MessageApi) GetSeq(c *gin.Context) {
|
||||
a2r.CallV2(c, msg.GetMaxSeqCaller.Invoke)
|
||||
a2r.Call(c, msg.MsgClient.GetMaxSeq, m.Client)
|
||||
}
|
||||
|
||||
func (m *MessageApi) PullMsgBySeqs(c *gin.Context) {
|
||||
a2r.CallV2(c, msg.PullMessageBySeqsCaller.Invoke)
|
||||
a2r.Call(c, msg.MsgClient.PullMessageBySeqs, m.Client)
|
||||
}
|
||||
|
||||
func (m *MessageApi) RevokeMsg(c *gin.Context) {
|
||||
a2r.CallV2(c, msg.RevokeMsgCaller.Invoke)
|
||||
a2r.Call(c, msg.MsgClient.RevokeMsg, m.Client)
|
||||
}
|
||||
|
||||
func (m *MessageApi) MarkMsgsAsRead(c *gin.Context) {
|
||||
a2r.CallV2(c, msg.MarkMsgsAsReadCaller.Invoke)
|
||||
a2r.Call(c, msg.MsgClient.MarkMsgsAsRead, m.Client)
|
||||
}
|
||||
|
||||
func (m *MessageApi) MarkConversationAsRead(c *gin.Context) {
|
||||
a2r.CallV2(c, msg.MarkConversationAsReadCaller.Invoke)
|
||||
a2r.Call(c, msg.MsgClient.MarkConversationAsRead, m.Client)
|
||||
}
|
||||
|
||||
func (m *MessageApi) GetConversationsHasReadAndMaxSeq(c *gin.Context) {
|
||||
a2r.CallV2(c, msg.GetConversationsHasReadAndMaxSeqCaller.Invoke)
|
||||
a2r.Call(c, msg.MsgClient.GetConversationsHasReadAndMaxSeq, m.Client)
|
||||
}
|
||||
|
||||
func (m *MessageApi) SetConversationHasReadSeq(c *gin.Context) {
|
||||
a2r.CallV2(c, msg.SetConversationHasReadSeqCaller.Invoke)
|
||||
a2r.Call(c, msg.MsgClient.SetConversationHasReadSeq, m.Client)
|
||||
}
|
||||
|
||||
func (m *MessageApi) ClearConversationsMsg(c *gin.Context) {
|
||||
a2r.CallV2(c, msg.ClearConversationsMsgCaller.Invoke)
|
||||
a2r.Call(c, msg.MsgClient.ClearConversationsMsg, m.Client)
|
||||
}
|
||||
|
||||
func (m *MessageApi) UserClearAllMsg(c *gin.Context) {
|
||||
a2r.CallV2(c, msg.UserClearAllMsgCaller.Invoke)
|
||||
a2r.Call(c, msg.MsgClient.UserClearAllMsg, m.Client)
|
||||
}
|
||||
|
||||
func (m *MessageApi) DeleteMsgs(c *gin.Context) {
|
||||
a2r.CallV2(c, msg.DeleteMsgsCaller.Invoke)
|
||||
a2r.Call(c, msg.MsgClient.DeleteMsgs, m.Client)
|
||||
}
|
||||
|
||||
func (m *MessageApi) DeleteMsgPhysicalBySeq(c *gin.Context) {
|
||||
a2r.CallV2(c, msg.DeleteMsgPhysicalBySeqCaller.Invoke)
|
||||
a2r.Call(c, msg.MsgClient.DeleteMsgPhysicalBySeq, m.Client)
|
||||
}
|
||||
|
||||
func (m *MessageApi) DeleteMsgPhysical(c *gin.Context) {
|
||||
a2r.CallV2(c, msg.DeleteMsgPhysicalCaller.Invoke)
|
||||
a2r.Call(c, msg.MsgClient.DeleteMsgPhysical, m.Client)
|
||||
}
|
||||
|
||||
func (m *MessageApi) getSendMsgReq(c *gin.Context, req apistruct.SendMsg) (sendMsgReq *msg.SendMsgReq, err error) {
|
||||
@@ -170,14 +171,10 @@ func (m *MessageApi) getSendMsgReq(c *gin.Context, req apistruct.SendMsg) (sendM
|
||||
data = apistruct.AtElem{}
|
||||
case constant.Custom:
|
||||
data = apistruct.CustomElem{}
|
||||
case constant.Quote:
|
||||
data = apistruct.QuoteElem{}
|
||||
case constant.Stream:
|
||||
data = apistruct.StreamMsgElem{}
|
||||
case constant.OANotification:
|
||||
data = apistruct.OANotificationElem{}
|
||||
req.SessionType = constant.NotificationChatType
|
||||
if err = user.GetNotificationAccountCaller.Execute(c, &user.GetNotificationAccountReq{UserID: req.SendID}); err != nil {
|
||||
if err = m.userClient.GetNotificationByID(c, req.SendID); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
default:
|
||||
@@ -224,7 +221,7 @@ func (m *MessageApi) SendMessage(c *gin.Context) {
|
||||
sendMsgReq.MsgData.RecvID = req.RecvID
|
||||
|
||||
// Attempt to send the message using the client.
|
||||
respPb, err := msg.SendMsgCaller.Invoke(c, sendMsgReq)
|
||||
respPb, err := m.Client.SendMsg(c, sendMsgReq)
|
||||
if err != nil {
|
||||
// Set the status to failed and respond with an error if sending fails.
|
||||
apiresp.GinError(c, err)
|
||||
@@ -235,7 +232,7 @@ func (m *MessageApi) SendMessage(c *gin.Context) {
|
||||
var status = constant.MsgSendSuccessed
|
||||
|
||||
// Attempt to update the message sending status in the system.
|
||||
err = msg.SetSendMsgStatusCaller.Execute(c, &msg.SetSendMsgStatusReq{
|
||||
_, err = m.Client.SetSendMsgStatus(c, &msg.SetSendMsgStatusReq{
|
||||
Status: int32(status),
|
||||
})
|
||||
|
||||
@@ -287,7 +284,7 @@ func (m *MessageApi) SendBusinessNotification(c *gin.Context) {
|
||||
}),
|
||||
},
|
||||
}
|
||||
respPb, err := msg.SendMsgCaller.Invoke(c, &sendMsgReq)
|
||||
respPb, err := m.Client.SendMsg(c, &sendMsgReq)
|
||||
if err != nil {
|
||||
apiresp.GinError(c, err)
|
||||
return
|
||||
@@ -311,13 +308,10 @@ func (m *MessageApi) BatchSendMsg(c *gin.Context) {
|
||||
|
||||
var recvIDs []string
|
||||
if req.IsSendAll {
|
||||
pageNumber := 1
|
||||
showNumber := 500
|
||||
var pageNumber int32 = 1
|
||||
const showNumber = 500
|
||||
for {
|
||||
recvIDsPart, err := rpccall.ExtractField(c, user.GetAllUserIDCaller.Invoke, &user.GetAllUserIDReq{Pagination: &sdkws.RequestPagination{
|
||||
PageNumber: int32(pageNumber),
|
||||
ShowNumber: int32(showNumber),
|
||||
}}, (*user.GetAllUserIDResp).GetUserIDs)
|
||||
recvIDsPart, err := m.userClient.GetAllUserIDs(c, pageNumber, showNumber)
|
||||
if err != nil {
|
||||
apiresp.GinError(c, err)
|
||||
return
|
||||
@@ -339,7 +333,7 @@ func (m *MessageApi) BatchSendMsg(c *gin.Context) {
|
||||
}
|
||||
for _, recvID := range recvIDs {
|
||||
sendMsgReq.MsgData.RecvID = recvID
|
||||
rpcResp, err := msg.SendMsgCaller.Invoke(c, sendMsgReq)
|
||||
rpcResp, err := m.Client.SendMsg(c, sendMsgReq)
|
||||
if err != nil {
|
||||
resp.FailedIDs = append(resp.FailedIDs, recvID)
|
||||
continue
|
||||
@@ -355,33 +349,33 @@ func (m *MessageApi) BatchSendMsg(c *gin.Context) {
|
||||
}
|
||||
|
||||
func (m *MessageApi) CheckMsgIsSendSuccess(c *gin.Context) {
|
||||
a2r.CallV2(c, msg.GetSendMsgStatusCaller.Invoke)
|
||||
a2r.Call(c, msg.MsgClient.GetSendMsgStatus, m.Client)
|
||||
}
|
||||
|
||||
func (m *MessageApi) GetUsersOnlineStatus(c *gin.Context) {
|
||||
a2r.CallV2(c, msg.GetSendMsgStatusCaller.Invoke)
|
||||
a2r.Call(c, msg.MsgClient.GetSendMsgStatus, m.Client)
|
||||
}
|
||||
|
||||
func (m *MessageApi) GetActiveUser(c *gin.Context) {
|
||||
a2r.CallV2(c, msg.GetActiveUserCaller.Invoke)
|
||||
a2r.Call(c, msg.MsgClient.GetActiveUser, m.Client)
|
||||
}
|
||||
|
||||
func (m *MessageApi) GetActiveGroup(c *gin.Context) {
|
||||
a2r.CallV2(c, msg.GetActiveGroupCaller.Invoke)
|
||||
a2r.Call(c, msg.MsgClient.GetActiveGroup, m.Client)
|
||||
}
|
||||
|
||||
func (m *MessageApi) SearchMsg(c *gin.Context) {
|
||||
a2r.CallV2(c, msg.SearchMessageCaller.Invoke)
|
||||
a2r.Call(c, msg.MsgClient.SearchMessage, m.Client)
|
||||
}
|
||||
|
||||
func (m *MessageApi) GetServerTime(c *gin.Context) {
|
||||
a2r.CallV2(c, msg.GetServerTimeCaller.Invoke)
|
||||
a2r.Call(c, msg.MsgClient.GetServerTime, m.Client)
|
||||
}
|
||||
|
||||
func (m *MessageApi) GetStreamMsg(c *gin.Context) {
|
||||
a2r.CallV2(c, msg.GetStreamMsgCaller.Invoke)
|
||||
a2r.Call(c, msg.MsgClient.GetServerTime, m.Client)
|
||||
}
|
||||
|
||||
func (m *MessageApi) AppendStreamMsg(c *gin.Context) {
|
||||
a2r.CallV2(c, msg.AppendStreamMsgCaller.Invoke)
|
||||
a2r.Call(c, msg.MsgClient.GetServerTime, m.Client)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user