Skip to content

Commit

Permalink
rpc client
Browse files Browse the repository at this point in the history
  • Loading branch information
withchao committed Dec 23, 2024
1 parent fc6569b commit a53fe0b
Show file tree
Hide file tree
Showing 10 changed files with 75 additions and 20 deletions.
10 changes: 2 additions & 8 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ require (
github.com/gorilla/websocket v1.5.1
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0
github.com/mitchellh/mapstructure v1.5.0
github.com/openimsdk/protocol v0.0.72-alpha.67
github.com/openimsdk/tools v0.0.50-alpha.58
github.com/openimsdk/protocol v0.0.72-alpha.68
github.com/openimsdk/tools v0.0.50-alpha.60
github.com/pkg/errors v0.9.1 // indirect
github.com/prometheus/client_golang v1.18.0
github.com/stretchr/testify v1.9.0
Expand Down Expand Up @@ -221,9 +221,3 @@ require (
golang.org/x/crypto v0.27.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
)


replace (
github.com/openimsdk/protocol => /Users/chao/Desktop/code/protocol
github.com/openimsdk/tools => /Users/chao/Desktop/code/tools
)
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -347,10 +347,10 @@ github.com/onsi/gomega v1.25.0 h1:Vw7br2PCDYijJHSfBOWhov+8cAnUf8MfMaIOV323l6Y=
github.com/onsi/gomega v1.25.0/go.mod h1:r+zV744Re+DiYCIPRlYOTxn0YkOLcAnW8k1xXdMPGhM=
github.com/openimsdk/gomake v0.0.15-alpha.2 h1:5Q8yl8ezy2yx+q8/ucU/t4kJnDfCzNOrkXcDACCqtyM=
github.com/openimsdk/gomake v0.0.15-alpha.2/go.mod h1:PndCozNc2IsQIciyn9mvEblYWZwJmAI+06z94EY+csI=
github.com/openimsdk/protocol v0.0.72-alpha.67 h1:zlLbVkoT0OYsjO2RCutQuDFllcfNvZfdYchvlR6UIe0=
github.com/openimsdk/protocol v0.0.72-alpha.67/go.mod h1:Iet+piS/jaS+kWWyj6EEr36mk4ISzIRYjoMSVA4dq2M=
github.com/openimsdk/tools v0.0.50-alpha.58 h1:hkFL02Bzzp/l5x+tb7kJ9zes7hilh65EQ4qEIthsQX4=
github.com/openimsdk/tools v0.0.50-alpha.58/go.mod h1:muCtxguNJv8lFwLei27UASu2Nvg4ERSeN0R4K5tivk0=
github.com/openimsdk/protocol v0.0.72-alpha.68 h1:Ekn6S9Ftt12Xs/p9kJ39RDr2gSwIczz+MmSHQE4lAek=
github.com/openimsdk/protocol v0.0.72-alpha.68/go.mod h1:Iet+piS/jaS+kWWyj6EEr36mk4ISzIRYjoMSVA4dq2M=
github.com/openimsdk/tools v0.0.50-alpha.60 h1:dYqYpSdSN5o6CxlEjua2USfwfUiG0tUWFBpqghTjbWE=
github.com/openimsdk/tools v0.0.50-alpha.60/go.mod h1:muCtxguNJv8lFwLei27UASu2Nvg4ERSeN0R4K5tivk0=
github.com/pelletier/go-toml/v2 v2.2.2 h1:aYUidT7k73Pcl9nb2gScu7NSrKCSHIDE89b3+6Wq+LM=
github.com/pelletier/go-toml/v2 v2.2.2/go.mod h1:1t835xjRzz80PqgE6HHgN2JOsmgYu/h4qDAS4n929Rs=
github.com/pierrec/lz4/v4 v4.1.21 h1:yOVMLb6qSIDP67pl/5F7RepeKYu/VmTyEXvuMI5d9mQ=
Expand Down
1 change: 1 addition & 0 deletions internal/rpc/relation/friend.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ func Start(ctx context.Context, config *Config, client discovery.SvcDiscoveryReg
config: config,
webhookClient: webhook.NewWebhookClient(config.WebhooksConfig.URL),
queue: memamq.NewMemoryQueue(16, 1024*1024),
userClient: userClient,
})
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/rpccache/conversation.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func (c *ConversationLocalCache) GetConversation(ctx context.Context, userID, co
var cache cacheProto[pbconversation.Conversation]
return cache.Unmarshal(c.local.Get(ctx, cachekey.GetConversationKey(userID, conversationID), func(ctx context.Context) ([]byte, error) {
log.ZDebug(ctx, "ConversationLocalCache GetConversation rpc", "userID", userID, "conversationID", conversationID)
return cache.Marshal(c.client.GetConversation(ctx, userID, conversationID))
return cache.Marshal(c.client.GetConversation(ctx, conversationID, userID))
}))
}

Expand Down
3 changes: 3 additions & 0 deletions pkg/rpcli/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ type AuthClient struct {
}

func (x *AuthClient) KickTokens(ctx context.Context, tokens []string) error {
if len(tokens) == 0 {
return nil
}
return ignoreResp(x.AuthClient.KickTokens(ctx, &auth.KickTokensReq{Tokens: tokens}))
}

Expand Down
25 changes: 23 additions & 2 deletions pkg/rpcli/conversation.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,25 @@ type ConversationClient struct {
}

func (x *ConversationClient) SetConversationMaxSeq(ctx context.Context, conversationID string, ownerUserIDs []string, maxSeq int64) error {
if len(ownerUserIDs) == 0 {
return nil
}
req := &conversation.SetConversationMaxSeqReq{ConversationID: conversationID, OwnerUserID: ownerUserIDs, MaxSeq: maxSeq}
return ignoreResp(x.ConversationClient.SetConversationMaxSeq(ctx, req))
}

func (x *ConversationClient) SetConversations(ctx context.Context, userIDs []string, info *conversation.ConversationReq) error {
req := &conversation.SetConversationsReq{UserIDs: userIDs, Conversation: info}
func (x *ConversationClient) SetConversations(ctx context.Context, ownerUserIDs []string, info *conversation.ConversationReq) error {
if len(ownerUserIDs) == 0 {
return nil
}
req := &conversation.SetConversationsReq{UserIDs: ownerUserIDs, Conversation: info}
return ignoreResp(x.ConversationClient.SetConversations(ctx, req))
}

func (x *ConversationClient) GetConversationsByConversationIDs(ctx context.Context, conversationIDs []string) ([]*conversation.Conversation, error) {
if len(conversationIDs) == 0 {
return nil, nil
}
req := &conversation.GetConversationsByConversationIDReq{ConversationIDs: conversationIDs}
return extractField(ctx, x.ConversationClient.GetConversationsByConversationID, req, (*conversation.GetConversationsByConversationIDResp).GetConversations)
}
Expand All @@ -34,6 +43,9 @@ func (x *ConversationClient) GetConversationsByConversationID(ctx context.Contex
}

func (x *ConversationClient) SetConversationMinSeq(ctx context.Context, conversationID string, ownerUserIDs []string, minSeq int64) error {
if len(ownerUserIDs) == 0 {
return nil
}
req := &conversation.SetConversationMinSeqReq{ConversationID: conversationID, OwnerUserID: ownerUserIDs, MinSeq: minSeq}
return ignoreResp(x.ConversationClient.SetConversationMinSeq(ctx, req))
}
Expand All @@ -44,6 +56,9 @@ func (x *ConversationClient) GetConversation(ctx context.Context, conversationID
}

func (x *ConversationClient) GetConversations(ctx context.Context, conversationIDs []string, ownerUserID string) ([]*conversation.Conversation, error) {
if len(conversationIDs) == 0 {
return nil, nil
}
req := &conversation.GetConversationsReq{ConversationIDs: conversationIDs, OwnerUserID: ownerUserID}
return extractField(ctx, x.ConversationClient.GetConversations, req, (*conversation.GetConversationsResp).GetConversations)
}
Expand All @@ -59,6 +74,9 @@ func (x *ConversationClient) GetPinnedConversationIDs(ctx context.Context, owner
}

func (x *ConversationClient) CreateGroupChatConversations(ctx context.Context, groupID string, userIDs []string) error {
if len(userIDs) == 0 {
return nil
}
req := &conversation.CreateGroupChatConversationsReq{GroupID: groupID, UserIDs: userIDs}
return ignoreResp(x.ConversationClient.CreateGroupChatConversations(ctx, req))
}
Expand All @@ -68,6 +86,9 @@ func (x *ConversationClient) CreateSingleChatConversations(ctx context.Context,
}

func (x *ConversationClient) GetConversationOfflinePushUserIDs(ctx context.Context, conversationID string, userIDs []string) ([]string, error) {
if len(userIDs) == 0 {
return nil, nil
}
req := &conversation.GetConversationOfflinePushUserIDsReq{ConversationID: conversationID, UserIDs: userIDs}
return extractField(ctx, x.ConversationClient.GetConversationOfflinePushUserIDs, req, (*conversation.GetConversationOfflinePushUserIDsResp).GetUserIDs)
}
5 changes: 4 additions & 1 deletion pkg/rpcli/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ type GroupClient struct {
}

func (x *GroupClient) GetGroupsInfo(ctx context.Context, groupIDs []string) ([]*sdkws.GroupInfo, error) {
if len(groupIDs) == 0 {
return nil, nil
}
req := &group.GetGroupsInfoReq{GroupIDs: groupIDs}
return extractField(ctx, x.GroupClient.GetGroupsInfo, req, (*group.GetGroupsInfoResp).GetGroupInfos)
}
Expand All @@ -30,7 +33,7 @@ func (x *GroupClient) GetGroupInfoCache(ctx context.Context, groupID string) (*s
}

func (x *GroupClient) GetGroupMemberCache(ctx context.Context, groupID string, userID string) (*sdkws.GroupMemberFullInfo, error) {
req := &group.GetGroupMemberCacheReq{GroupID: groupID}
req := &group.GetGroupMemberCacheReq{GroupID: groupID, GroupMemberID: userID}
return extractField(ctx, x.GroupClient.GetGroupMemberCache, req, (*group.GetGroupMemberCacheResp).GetMember)
}

Expand Down
24 changes: 24 additions & 0 deletions pkg/rpcli/msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,41 @@ type MsgClient struct {
}

func (x *MsgClient) GetMaxSeqs(ctx context.Context, conversationIDs []string) (map[string]int64, error) {
if len(conversationIDs) == 0 {
return nil, nil
}
req := &msg.GetMaxSeqsReq{ConversationIDs: conversationIDs}
return extractField(ctx, x.MsgClient.GetMaxSeqs, req, (*msg.SeqsInfoResp).GetMaxSeqs)
}

func (x *MsgClient) GetMsgByConversationIDs(ctx context.Context, conversationIDs []string, maxSeqs map[string]int64) (map[string]*sdkws.MsgData, error) {
if len(conversationIDs) == 0 || len(maxSeqs) == 0 {
return nil, nil
}
req := &msg.GetMsgByConversationIDsReq{ConversationIDs: conversationIDs, MaxSeqs: maxSeqs}
return extractField(ctx, x.MsgClient.GetMsgByConversationIDs, req, (*msg.GetMsgByConversationIDsResp).GetMsgDatas)
}

func (x *MsgClient) GetHasReadSeqs(ctx context.Context, conversationIDs []string, userID string) (map[string]int64, error) {
if len(conversationIDs) == 0 {
return nil, nil
}
req := &msg.GetHasReadSeqsReq{ConversationIDs: conversationIDs, UserID: userID}
return extractField(ctx, x.MsgClient.GetHasReadSeqs, req, (*msg.SeqsInfoResp).GetMaxSeqs)
}

func (x *MsgClient) SetUserConversationMaxSeq(ctx context.Context, conversationID string, ownerUserIDs []string, maxSeq int64) error {
if len(ownerUserIDs) == 0 {
return nil
}
req := &msg.SetUserConversationMaxSeqReq{ConversationID: conversationID, OwnerUserID: ownerUserIDs, MaxSeq: maxSeq}
return ignoreResp(x.MsgClient.SetUserConversationMaxSeq(ctx, req))
}

func (x *MsgClient) SetUserConversationMin(ctx context.Context, conversationID string, ownerUserIDs []string, minSeq int64) error {
if len(ownerUserIDs) == 0 {
return nil
}
req := &msg.SetUserConversationsMinSeqReq{ConversationID: conversationID, UserIDs: ownerUserIDs, Seq: minSeq}
return ignoreResp(x.MsgClient.SetUserConversationsMinSeq(ctx, req))
}
Expand All @@ -51,16 +66,25 @@ func (x *MsgClient) GetConversationMaxSeq(ctx context.Context, conversationID st
}

func (x *MsgClient) GetActiveConversation(ctx context.Context, conversationIDs []string) ([]*msg.ActiveConversation, error) {
if len(conversationIDs) == 0 {
return nil, nil
}
req := &msg.GetActiveConversationReq{ConversationIDs: conversationIDs}
return extractField(ctx, x.MsgClient.GetActiveConversation, req, (*msg.GetActiveConversationResp).GetConversations)
}

func (x *MsgClient) GetSeqMessage(ctx context.Context, userID string, conversations []*msg.ConversationSeqs) (map[string]*sdkws.PullMsgs, error) {
if len(conversations) == 0 {
return nil, nil
}
req := &msg.GetSeqMessageReq{UserID: userID, Conversations: conversations}
return extractField(ctx, x.MsgClient.GetSeqMessage, req, (*msg.GetSeqMessageResp).GetMsgs)
}

func (x *MsgClient) SetUserConversationsMinSeq(ctx context.Context, conversationID string, userIDs []string, seq int64) error {
if len(userIDs) == 0 {
return nil
}
req := &msg.SetUserConversationsMinSeqReq{ConversationID: conversationID, UserIDs: userIDs, Seq: seq}
return ignoreResp(x.MsgClient.SetUserConversationsMinSeq(ctx, req))
}
3 changes: 3 additions & 0 deletions pkg/rpcli/relation.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ type RelationClient struct {
}

func (x *RelationClient) GetFriendsInfo(ctx context.Context, ownerUserID string, friendUserIDs []string) ([]*relation.FriendInfoOnly, error) {
if len(friendUserIDs) == 0 {
return nil, nil
}
req := &relation.GetFriendInfoReq{OwnerUserID: ownerUserID, FriendUserIDs: friendUserIDs}
return extractField(ctx, x.FriendClient.GetFriendInfo, req, (*relation.GetFriendInfoResp).GetFriendInfos)
}
14 changes: 10 additions & 4 deletions pkg/rpcli/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ type UserClient struct {
}

func (x *UserClient) GetUsersInfo(ctx context.Context, userIDs []string) ([]*sdkws.UserInfo, error) {
if len(userIDs) == 0 {
return nil, nil
}
req := &user.GetDesignateUsersReq{UserIDs: userIDs}
return extractField(ctx, x.UserClient.GetDesignateUsers, req, (*user.GetDesignateUsersResp).GetUsersInfo)
}
Expand All @@ -27,6 +30,9 @@ func (x *UserClient) GetUserInfo(ctx context.Context, userID string) (*sdkws.Use
}

func (x *UserClient) CheckUser(ctx context.Context, userIDs []string) error {
if len(userIDs) == 0 {
return nil
}
users, err := x.GetUsersInfo(ctx, userIDs)
if err != nil {
return err
Expand Down Expand Up @@ -73,14 +79,14 @@ func (x *UserClient) GetUserOnlinePlatform(ctx context.Context, userID string) (
}

func (x *UserClient) SetUserOnlineStatus(ctx context.Context, req *user.SetUserOnlineStatusReq) error {
if len(req.Status) == 0 {
return nil
}
return ignoreResp(x.UserClient.SetUserOnlineStatus(ctx, req))
}

func (x *UserClient) GetNotificationByID(ctx context.Context, userID string) error {
_, err := x.UserClient.GetNotificationAccount(ctx, &user.GetNotificationAccountReq{
UserID: userID,
})
return err
return ignoreResp(x.UserClient.GetNotificationAccount(ctx, &user.GetNotificationAccountReq{UserID: userID}))
}

func (x *UserClient) GetAllUserIDs(ctx context.Context, pageNumber, showNumber int32) ([]string, error) {
Expand Down

0 comments on commit a53fe0b

Please sign in to comment.