fix: user logout recycle resources

test-errcode
Gordon 2 years ago
parent 103cb3cb99
commit 8a21e07d6d

@ -2,6 +2,8 @@ package msggateway
import ( import (
"context" "context"
"github.com/OpenIMSDK/Open-IM-Server/pkg/discoveryregistry"
"github.com/OpenIMSDK/Open-IM-Server/pkg/proto/push"
"github.com/OpenIMSDK/Open-IM-Server/pkg/proto/msg" "github.com/OpenIMSDK/Open-IM-Server/pkg/proto/msg"
"github.com/OpenIMSDK/Open-IM-Server/pkg/proto/sdkws" "github.com/OpenIMSDK/Open-IM-Server/pkg/proto/sdkws"
@ -50,11 +52,13 @@ var _ MessageHandler = (*GrpcHandler)(nil)
type GrpcHandler struct { type GrpcHandler struct {
msgRpcClient *rpcclient.MsgClient msgRpcClient *rpcclient.MsgClient
pushClient *rpcclient.PushClient
validate *validator.Validate validate *validator.Validate
} }
func NewGrpcHandler(validate *validator.Validate, msgRpcClient *rpcclient.MsgClient) *GrpcHandler { func NewGrpcHandler(validate *validator.Validate, client discoveryregistry.SvcDiscoveryRegistry) *GrpcHandler {
return &GrpcHandler{msgRpcClient: msgRpcClient, validate: validate} return &GrpcHandler{msgRpcClient: rpcclient.NewMsgClient(client),
pushClient: rpcclient.NewPushClient(client), validate: validate}
} }
func (g GrpcHandler) GetSeq(context context.Context, data Req) ([]byte, error) { func (g GrpcHandler) GetSeq(context context.Context, data Req) ([]byte, error) {
@ -137,8 +141,11 @@ func (g GrpcHandler) PullMessageBySeqList(context context.Context, data Req) ([]
} }
func (g GrpcHandler) UserLogout(context context.Context, data Req) ([]byte, error) { func (g GrpcHandler) UserLogout(context context.Context, data Req) ([]byte, error) {
//todo req := push.DelUserPushTokenReq{}
resp, err := g.msgRpcClient.PullMessageBySeqList(context, nil) if err := proto.Unmarshal(data.Data, &req); err != nil {
return nil, err
}
resp, err := g.pushClient.DelUserPushToken(context, req)
if err != nil { if err != nil {
return nil, err return nil, err
} }

@ -2,6 +2,7 @@ package msggateway
import ( import (
"errors" "errors"
"github.com/OpenIMSDK/Open-IM-Server/pkg/discoveryregistry"
"net/http" "net/http"
"sync" "sync"
"sync/atomic" "sync/atomic"
@ -10,7 +11,6 @@ import (
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/log" "github.com/OpenIMSDK/Open-IM-Server/pkg/common/log"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/tokenverify" "github.com/OpenIMSDK/Open-IM-Server/pkg/common/tokenverify"
"github.com/OpenIMSDK/Open-IM-Server/pkg/errs" "github.com/OpenIMSDK/Open-IM-Server/pkg/errs"
"github.com/OpenIMSDK/Open-IM-Server/pkg/rpcclient"
"github.com/OpenIMSDK/Open-IM-Server/pkg/utils" "github.com/OpenIMSDK/Open-IM-Server/pkg/utils"
"github.com/go-playground/validator/v10" "github.com/go-playground/validator/v10"
) )
@ -21,7 +21,8 @@ type LongConnServer interface {
GetUserAllCons(userID string) ([]*Client, bool) GetUserAllCons(userID string) ([]*Client, bool)
GetUserPlatformCons(userID string, platform int) ([]*Client, bool, bool) GetUserPlatformCons(userID string, platform int) ([]*Client, bool, bool)
Validate(s interface{}) error Validate(s interface{}) error
SetMessageHandler(msgRpcClient *rpcclient.MsgClient) //SetMessageHandler(msgRpcClient *rpcclient.MsgClient)
SetDiscoveryRegistry(client discoveryregistry.SvcDiscoveryRegistry)
UnRegister(c *Client) UnRegister(c *Client)
Compressor Compressor
Encoder Encoder
@ -51,8 +52,8 @@ type WsServer struct {
MessageHandler MessageHandler
} }
func (ws *WsServer) SetMessageHandler(rpcClient *rpcclient.MsgClient) { func (ws *WsServer) SetDiscoveryRegistry(client discoveryregistry.SvcDiscoveryRegistry) {
ws.MessageHandler = NewGrpcHandler(ws.validate, rpcClient) ws.MessageHandler = NewGrpcHandler(ws.validate, client)
} }
func (ws *WsServer) UnRegister(c *Client) { func (ws *WsServer) UnRegister(c *Client) {

@ -0,0 +1,33 @@
package rpcclient
import (
"context"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/config"
"github.com/OpenIMSDK/Open-IM-Server/pkg/discoveryregistry"
"github.com/OpenIMSDK/Open-IM-Server/pkg/proto/push"
)
type PushClient struct {
MetaClient
}
func NewPushClient(client discoveryregistry.SvcDiscoveryRegistry) *PushClient {
return &PushClient{
MetaClient: MetaClient{
client: client,
rpcRegisterName: config.Config.RpcRegisterName.OpenImPushName,
},
}
}
func (p *PushClient) DelUserPushToken(ctx context.Context, req push.DelUserPushTokenReq) (*push.DelUserPushTokenResp, error) {
cc, err := p.getConn(ctx)
if err != nil {
return nil, err
}
resp, err := push.NewPushMsgServiceClient(cc).DelUserPushToken(ctx, &req)
if err != nil {
return nil, err
}
return resp, nil
}
Loading…
Cancel
Save