From 8d998ad63cfbfeb528a75d6c5d7c9df38f6db908 Mon Sep 17 00:00:00 2001 From: Gordon <1432970085@qq.com> Date: Sat, 6 May 2023 10:27:07 +0800 Subject: [PATCH] pb update --- internal/api/route.go | 3 ++- internal/api/user.go | 16 ++++++++++++++++ internal/msggateway/client.go | 4 +++- internal/msggateway/hub_server.go | 1 - internal/msggateway/long_conn.go | 16 +++++++--------- 5 files changed, 28 insertions(+), 12 deletions(-) diff --git a/internal/api/route.go b/internal/api/route.go index 67af50e8c..b618d9fda 100644 --- a/internal/api/route.go +++ b/internal/api/route.go @@ -45,6 +45,7 @@ func NewGinRouter(zk discoveryregistry.SvcDiscoveryRegistry, rdb redis.Universal userRouterGroupChildToken.POST("/get_all_users_uid", u.GetAllUsersID) // todo userRouterGroupChildToken.POST("/account_check", u.AccountCheck) // todo userRouterGroupChildToken.POST("/get_users", u.GetUsers) + userRouterGroupChildToken.POST("/get_users_online_status", u.GetUsersOnlineStatus) } //friend routing group friendRouterGroup := r.Group("/friend") @@ -141,7 +142,7 @@ func NewGinRouter(zk discoveryregistry.SvcDiscoveryRegistry, rdb redis.Universal msgGroup.POST("/batch_send_msg", m.ManagementBatchSendMsg) msgGroup.POST("/check_msg_is_send_success", m.CheckMsgIsSendSuccess) - msgGroup.POST("/get_users_online_status", m.GetUsersOnlineStatus) + //msgGroup.POST("/set_message_reaction_extensions", msg.SetMessageReactionExtensions) //msgGroup.POST("/get_message_list_reaction_extensions", msg.GetMessageListReactionExtensions) //msgGroup.POST("/add_message_reaction_extensions", msg.AddMessageReactionExtensions) diff --git a/internal/api/user.go b/internal/api/user.go index 79b1a3ccc..ae9291251 100644 --- a/internal/api/user.go +++ b/internal/api/user.go @@ -2,6 +2,10 @@ package api import ( "context" + "github.com/OpenIMSDK/Open-IM-Server/pkg/apiresp" + "github.com/OpenIMSDK/Open-IM-Server/pkg/apistruct" + "github.com/OpenIMSDK/Open-IM-Server/pkg/common/tokenverify" + "github.com/OpenIMSDK/Open-IM-Server/pkg/errs" "github.com/OpenIMSDK/Open-IM-Server/pkg/a2r" "github.com/OpenIMSDK/Open-IM-Server/pkg/common/config" @@ -55,3 +59,15 @@ func (u *User) AccountCheck(c *gin.Context) { func (u *User) GetUsers(c *gin.Context) { a2r.Call(user.UserClient.GetPaginationUsers, u.client, c) } +func (u *User) GetUsersOnlineStatus(c *gin.Context) { + params := apistruct.ManagementSendMsgReq{} + if err := c.BindJSON(¶ms); err != nil { + apiresp.GinError(c, errs.ErrArgs.WithDetail(err.Error()).Wrap()) + return + } + if !tokenverify.IsAppManagerUid(c) { + apiresp.GinError(c, errs.ErrNoPermission.Wrap("only app manager can send message")) + return + } + +} diff --git a/internal/msggateway/client.go b/internal/msggateway/client.go index d270cd912..01aa2bd7b 100644 --- a/internal/msggateway/client.go +++ b/internal/msggateway/client.go @@ -202,7 +202,9 @@ func (c *Client) replyMessage(ctx context.Context, binaryReq *Req, err error, re } } func (c *Client) PushMessage(ctx context.Context, msgData *sdkws.MsgData) error { - data, err := proto.Marshal(msgData) + var msg sdkws.PushMessages + msg.Msgs = append(msg.Msgs, msgData) + data, err := proto.Marshal(&msg) if err != nil { return err } diff --git a/internal/msggateway/hub_server.go b/internal/msggateway/hub_server.go index 5ba26f2b6..7350cac72 100644 --- a/internal/msggateway/hub_server.go +++ b/internal/msggateway/hub_server.go @@ -125,7 +125,6 @@ func (s *Server) SuperGroupOnlineBatchPushOneMsg(ctx context.Context, req *msgga func (s *Server) KickUserOffline(ctx context.Context, req *msggateway.KickUserOfflineReq) (*msggateway.KickUserOfflineResp, error) { for _, v := range req.KickUserIDList { - if clients, _, ok := s.LongConnServer.GetUserPlatformCons(v, int(req.PlatformID)); ok { for _, client := range clients { err := client.KickOnlineMessage(ctx) diff --git a/internal/msggateway/long_conn.go b/internal/msggateway/long_conn.go index 819094ee0..ed31dbda7 100644 --- a/internal/msggateway/long_conn.go +++ b/internal/msggateway/long_conn.go @@ -9,27 +9,25 @@ import ( type LongConn interface { //Close this connection Close() error - //Write message to connection,messageType means data type,can be set binary(2) and text(1). + // WriteMessage Write message to connection,messageType means data type,can be set binary(2) and text(1). WriteMessage(messageType int, message []byte) error - //Read message from connection. + // ReadMessage Read message from connection. ReadMessage() (int, []byte, error) // SetReadDeadline sets the read deadline on the underlying network connection, //after a read has timed out, will return an error. SetReadDeadline(timeout time.Duration) error - // SetWriteDeadline sets the write deadline when send message,when read has timed out,will return error. + // SetWriteDeadline sets to write deadline when send message,when read has timed out,will return error. SetWriteDeadline(timeout time.Duration) error - //Try to dial a connection,url must set auth args,header can control compress data + // Dial Try to dial a connection,url must set auth args,header can control compress data Dial(urlStr string, requestHeader http.Header) (*http.Response, error) - //Whether the connection of the current long connection is nil + // IsNil Whether the connection of the current long connection is nil IsNil() bool - //Set the connection of the current long connection to nil + // SetConnNil Set the connection of the current long connection to nil SetConnNil() // SetReadLimit sets the maximum size for a message read from the peer.bytes SetReadLimit(limit int64) SetPongHandler(handler PongHandler) - //Check the connection of the current and when it was sent are the same - //CheckSendConnDiffNow() bool - // + // GenerateLongConn Check the connection of the current and when it was sent are the same GenerateLongConn(w http.ResponseWriter, r *http.Request) error } type GWebSocket struct {