feat: merge v3dev into main

This commit is contained in:
Gordon
2023-07-12 15:12:23 +08:00
123 changed files with 7377 additions and 10288 deletions
+15 -90
View File
@@ -1,29 +1,14 @@
// Copyright © 2023 OpenIM. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package rpcclient
import (
"context"
"fmt"
"google.golang.org/grpc"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/config"
"github.com/OpenIMSDK/Open-IM-Server/pkg/discoveryregistry"
"github.com/OpenIMSDK/Open-IM-Server/pkg/errs"
pbConversation "github.com/OpenIMSDK/Open-IM-Server/pkg/proto/conversation"
"google.golang.org/grpc"
)
type Conversation struct {
@@ -47,18 +32,7 @@ func NewConversationRpcClient(discov discoveryregistry.SvcDiscoveryRegistry) Con
return ConversationRpcClient(*NewConversation(discov))
}
func (c *ConversationRpcClient) ModifyConversationField(
ctx context.Context,
req *pbConversation.ModifyConversationFieldReq,
) error {
_, err := c.Client.ModifyConversationField(ctx, req)
return err
}
func (c *ConversationRpcClient) GetSingleConversationRecvMsgOpt(
ctx context.Context,
userID, conversationID string,
) (int32, error) {
func (c *ConversationRpcClient) GetSingleConversationRecvMsgOpt(ctx context.Context, userID, conversationID string) (int32, error) {
var req pbConversation.GetConversationReq
req.OwnerUserID = userID
req.ConversationID = conversationID
@@ -70,51 +44,21 @@ func (c *ConversationRpcClient) GetSingleConversationRecvMsgOpt(
}
func (c *ConversationRpcClient) SingleChatFirstCreateConversation(ctx context.Context, recvID, sendID string) error {
_, err := c.Client.CreateSingleChatConversations(
ctx,
&pbConversation.CreateSingleChatConversationsReq{RecvID: recvID, SendID: sendID},
)
_, err := c.Client.CreateSingleChatConversations(ctx, &pbConversation.CreateSingleChatConversationsReq{RecvID: recvID, SendID: sendID})
return err
}
func (c *ConversationRpcClient) GroupChatFirstCreateConversation(
ctx context.Context,
groupID string,
userIDs []string,
) error {
_, err := c.Client.CreateGroupChatConversations(
ctx,
&pbConversation.CreateGroupChatConversationsReq{UserIDs: userIDs, GroupID: groupID},
)
func (c *ConversationRpcClient) GroupChatFirstCreateConversation(ctx context.Context, groupID string, userIDs []string) error {
_, err := c.Client.CreateGroupChatConversations(ctx, &pbConversation.CreateGroupChatConversationsReq{UserIDs: userIDs, GroupID: groupID})
return err
}
func (c *ConversationRpcClient) SetConversationMaxSeq(
ctx context.Context,
ownerUserIDs []string,
conversationID string,
maxSeq int64,
) error {
_, err := c.Client.SetConversationMaxSeq(
ctx,
&pbConversation.SetConversationMaxSeqReq{
OwnerUserID: ownerUserIDs,
ConversationID: conversationID,
MaxSeq: maxSeq,
},
)
func (c *ConversationRpcClient) SetConversationMaxSeq(ctx context.Context, ownerUserIDs []string, conversationID string, maxSeq int64) error {
_, err := c.Client.SetConversationMaxSeq(ctx, &pbConversation.SetConversationMaxSeqReq{OwnerUserID: ownerUserIDs, ConversationID: conversationID, MaxSeq: maxSeq})
return err
}
func (c *ConversationRpcClient) SetConversations(
ctx context.Context,
userIDs []string,
conversation *pbConversation.ConversationReq,
) error {
_, err := c.Client.SetConversations(
ctx,
&pbConversation.SetConversationsReq{UserIDs: userIDs, Conversation: conversation},
)
func (c *ConversationRpcClient) SetConversations(ctx context.Context, userIDs []string, conversation *pbConversation.ConversationReq) error {
_, err := c.Client.SetConversations(ctx, &pbConversation.SetConversationsReq{UserIDs: userIDs, Conversation: conversation})
return err
}
@@ -126,28 +70,16 @@ func (c *ConversationRpcClient) GetConversationIDs(ctx context.Context, ownerUse
return resp.ConversationIDs, nil
}
func (c *ConversationRpcClient) GetConversation(
ctx context.Context,
ownerUserID, conversationID string,
) (*pbConversation.Conversation, error) {
resp, err := c.Client.GetConversation(
ctx,
&pbConversation.GetConversationReq{OwnerUserID: ownerUserID, ConversationID: conversationID},
)
func (c *ConversationRpcClient) GetConversation(ctx context.Context, ownerUserID, conversationID string) (*pbConversation.Conversation, error) {
resp, err := c.Client.GetConversation(ctx, &pbConversation.GetConversationReq{OwnerUserID: ownerUserID, ConversationID: conversationID})
if err != nil {
return nil, err
}
return resp.Conversation, nil
}
func (c *ConversationRpcClient) GetConversationsByConversationID(
ctx context.Context,
conversationIDs []string,
) ([]*pbConversation.Conversation, error) {
resp, err := c.Client.GetConversationsByConversationID(
ctx,
&pbConversation.GetConversationsByConversationIDReq{ConversationIDs: conversationIDs},
)
func (c *ConversationRpcClient) GetConversationsByConversationID(ctx context.Context, conversationIDs []string) ([]*pbConversation.Conversation, error) {
resp, err := c.Client.GetConversationsByConversationID(ctx, &pbConversation.GetConversationsByConversationIDReq{ConversationIDs: conversationIDs})
if err != nil {
return nil, err
}
@@ -157,15 +89,8 @@ func (c *ConversationRpcClient) GetConversationsByConversationID(
return resp.Conversations, nil
}
func (c *ConversationRpcClient) GetConversations(
ctx context.Context,
ownerUserID string,
conversationIDs []string,
) ([]*pbConversation.Conversation, error) {
resp, err := c.Client.GetConversations(
ctx,
&pbConversation.GetConversationsReq{OwnerUserID: ownerUserID, ConversationIDs: conversationIDs},
)
func (c *ConversationRpcClient) GetConversations(ctx context.Context, ownerUserID string, conversationIDs []string) ([]*pbConversation.Conversation, error) {
resp, err := c.Client.GetConversations(ctx, &pbConversation.GetConversationsReq{OwnerUserID: ownerUserID, ConversationIDs: conversationIDs})
if err != nil {
return nil, err
}
+44 -58
View File
@@ -1,26 +1,9 @@
// Copyright © 2023 OpenIM. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package rpcclient
import (
"context"
"encoding/json"
"google.golang.org/grpc"
"google.golang.org/protobuf/proto"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/config"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/constant"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/log"
@@ -28,6 +11,8 @@ import (
"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/utils"
"google.golang.org/grpc"
"google.golang.org/protobuf/proto"
// "google.golang.org/protobuf/proto"
)
@@ -115,6 +100,8 @@ func newSessionTypeConf() map[int32]int32 {
constant.ConversationChangeNotification: constant.SingleChatType,
constant.ConversationUnreadNotification: constant.SingleChatType,
constant.ConversationPrivateChatNotification: constant.SingleChatType,
// delete
constant.MsgDeleteNotification: constant.SingleChatType,
}
}
@@ -149,10 +136,7 @@ func (m *MessageRpcClient) GetMaxSeq(ctx context.Context, req *sdkws.GetMaxSeqRe
return resp, err
}
func (m *MessageRpcClient) PullMessageBySeqList(
ctx context.Context,
req *sdkws.PullMessageBySeqsReq,
) (*sdkws.PullMessageBySeqsResp, error) {
func (m *MessageRpcClient) PullMessageBySeqList(ctx context.Context, req *sdkws.PullMessageBySeqsReq) (*sdkws.PullMessageBySeqsResp, error) {
resp, err := m.Client.PullMessageBySeqs(ctx, req)
return resp, err
}
@@ -169,62 +153,71 @@ type NotificationSender struct {
contentTypeConf map[int32]config.NotificationConf
sessionTypeConf map[int32]int32
sendMsg func(ctx context.Context, req *msg.SendMsgReq) (*msg.SendMsgResp, error)
getUserInfo func(ctx context.Context, userID string) (*sdkws.UserInfo, error)
}
type NewNotificationSenderOptions func(*NotificationSender)
type NotificationSenderOptions func(*NotificationSender)
func WithLocalSendMsg(
sendMsg func(ctx context.Context, req *msg.SendMsgReq) (*msg.SendMsgResp, error),
) NewNotificationSenderOptions {
func WithLocalSendMsg(sendMsg func(ctx context.Context, req *msg.SendMsgReq) (*msg.SendMsgResp, error)) NotificationSenderOptions {
return func(s *NotificationSender) {
s.sendMsg = sendMsg
}
}
func WithRpcClient(msgRpcClient *MessageRpcClient) NewNotificationSenderOptions {
func WithRpcClient(msgRpcClient *MessageRpcClient) NotificationSenderOptions {
return func(s *NotificationSender) {
s.sendMsg = msgRpcClient.SendMsg
}
}
func NewNotificationSender(opts ...NewNotificationSenderOptions) *NotificationSender {
notificationSender := &NotificationSender{
contentTypeConf: newContentTypeConf(),
sessionTypeConf: newSessionTypeConf(),
func WithUserRpcClient(userRpcClient *UserRpcClient) NotificationSenderOptions {
return func(s *NotificationSender) {
s.getUserInfo = userRpcClient.GetUserInfo
}
}
func NewNotificationSender(opts ...NotificationSenderOptions) *NotificationSender {
notificationSender := &NotificationSender{contentTypeConf: newContentTypeConf(), sessionTypeConf: newSessionTypeConf()}
for _, opt := range opts {
opt(notificationSender)
}
return notificationSender
}
func (s *NotificationSender) NotificationWithSesstionType(
ctx context.Context,
sendID, recvID string,
contentType, sesstionType int32,
m proto.Message,
opts ...utils.OptionsOpt,
) (err error) {
type notificationOpt struct {
WithRpcGetUsername bool
}
type NotificationOptions func(*notificationOpt)
func WithRpcGetUserName() NotificationOptions {
return func(opt *notificationOpt) {
opt.WithRpcGetUsername = true
}
}
func (s *NotificationSender) NotificationWithSesstionType(ctx context.Context, sendID, recvID string, contentType, sesstionType int32, m proto.Message, opts ...NotificationOptions) (err error) {
n := sdkws.NotificationElem{Detail: utils.StructToJsonString(m)}
content, err := json.Marshal(&n)
if err != nil {
log.ZError(
ctx,
"MsgClient Notification json.Marshal failed",
err,
"sendID",
sendID,
"recvID",
recvID,
"contentType",
contentType,
"msg",
m,
)
log.ZError(ctx, "MsgClient Notification json.Marshal failed", err, "sendID", sendID, "recvID", recvID, "contentType", contentType, "msg", m)
return err
}
notificationOpt := &notificationOpt{}
for _, opt := range opts {
opt(notificationOpt)
}
var req msg.SendMsgReq
var msg sdkws.MsgData
if notificationOpt.WithRpcGetUsername && s.getUserInfo != nil {
userInfo, err := s.getUserInfo(ctx, sendID)
if err != nil {
log.ZWarn(ctx, "getUserInfo failed", err, "sendID", sendID)
} else {
msg.SenderNickname = userInfo.Nickname
msg.SenderFaceURL = userInfo.FaceURL
}
}
var offlineInfo sdkws.OfflinePushInfo
var title, desc, ex string
msg.SendID = sendID
@@ -239,7 +232,6 @@ func (s *NotificationSender) NotificationWithSesstionType(
msg.CreateTime = utils.GetCurrentTimestampByMill()
msg.ClientMsgID = utils.GetMsgID(sendID)
options := config.GetOptionsByNotification(s.contentTypeConf[contentType])
options = utils.WithOptions(options, opts...)
msg.Options = options
offlineInfo.Title = title
offlineInfo.Desc = desc
@@ -255,12 +247,6 @@ func (s *NotificationSender) NotificationWithSesstionType(
return err
}
func (s *NotificationSender) Notification(
ctx context.Context,
sendID, recvID string,
contentType int32,
m proto.Message,
opts ...utils.OptionsOpt,
) error {
func (s *NotificationSender) Notification(ctx context.Context, sendID, recvID string, contentType int32, m proto.Message, opts ...NotificationOptions) error {
return s.NotificationWithSesstionType(ctx, sendID, recvID, contentType, s.sessionTypeConf[contentType], m, opts...)
}
-162
View File
@@ -1,162 +0,0 @@
// Copyright © 2023 OpenIM. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package notification
import (
"context"
"encoding/json"
"google.golang.org/protobuf/proto"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/constant"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/mcontext"
"github.com/OpenIMSDK/Open-IM-Server/pkg/discoveryregistry"
"github.com/OpenIMSDK/Open-IM-Server/pkg/errs"
"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/rpcclient"
"github.com/OpenIMSDK/Open-IM-Server/pkg/utils"
)
type ExtendMsgNotificationSender struct {
*rpcclient.MessageRpcClient
}
func NewExtendMsgNotificationSender(client discoveryregistry.SvcDiscoveryRegistry) *ExtendMsgNotificationSender {
return &ExtendMsgNotificationSender{}
}
func (e *ExtendMsgNotificationSender) ExtendMessageUpdatedNotification(
ctx context.Context,
sendID string,
conversationID string,
sessionType int32,
req *msg.SetMessageReactionExtensionsReq,
resp *msg.SetMessageReactionExtensionsResp,
isHistory bool,
isReactionFromCache bool,
) {
var content sdkws.ReactionMessageModifierNotification
content.ConversationID = req.ConversationID
content.OpUserID = mcontext.GetOpUserID(ctx)
content.SessionType = req.SessionType
keyMap := make(map[string]*sdkws.KeyValue)
for _, valueResp := range resp.Result {
if valueResp.ErrCode == 0 {
keyMap[valueResp.KeyValue.TypeKey] = valueResp.KeyValue
}
}
if len(keyMap) == 0 {
return
}
content.SuccessReactionExtensions = keyMap
content.ClientMsgID = req.ClientMsgID
content.IsReact = resp.IsReact
content.IsExternalExtensions = req.IsExternalExtensions
content.MsgFirstModifyTime = resp.MsgFirstModifyTime
e.messageReactionSender(
ctx,
sendID,
conversationID,
sessionType,
constant.ReactionMessageModifier,
&content,
isHistory,
isReactionFromCache,
)
}
func (e *ExtendMsgNotificationSender) ExtendMessageDeleteNotification(
ctx context.Context,
sendID string,
conversationID string,
sessionType int32,
req *msg.DeleteMessagesReactionExtensionsReq,
resp *msg.DeleteMessagesReactionExtensionsResp,
isHistory bool,
isReactionFromCache bool,
) {
var content sdkws.ReactionMessageDeleteNotification
content.ConversationID = req.ConversationID
content.OpUserID = req.OpUserID
content.SessionType = req.SessionType
keyMap := make(map[string]*sdkws.KeyValue)
for _, valueResp := range resp.Result {
if valueResp.ErrCode == 0 {
keyMap[valueResp.KeyValue.TypeKey] = valueResp.KeyValue
}
}
if len(keyMap) == 0 {
return
}
content.SuccessReactionExtensions = keyMap
content.ClientMsgID = req.ClientMsgID
content.MsgFirstModifyTime = req.MsgFirstModifyTime
e.messageReactionSender(
ctx,
sendID,
conversationID,
sessionType,
constant.ReactionMessageDeleter,
&content,
isHistory,
isReactionFromCache,
)
}
func (e *ExtendMsgNotificationSender) messageReactionSender(
ctx context.Context,
sendID string,
conversationID string,
sessionType, contentType int32,
m proto.Message,
isHistory bool,
isReactionFromCache bool,
) error {
options := make(map[string]bool, 5)
utils.SetSwitchFromOptions(options, constant.IsOfflinePush, false)
utils.SetSwitchFromOptions(options, constant.IsConversationUpdate, false)
utils.SetSwitchFromOptions(options, constant.IsSenderConversationUpdate, false)
utils.SetSwitchFromOptions(options, constant.IsUnreadCount, false)
utils.SetSwitchFromOptions(options, constant.IsReactionFromCache, isReactionFromCache)
if !isHistory {
utils.SetSwitchFromOptions(options, constant.IsHistory, false)
utils.SetSwitchFromOptions(options, constant.IsPersistent, false)
}
bytes, err := json.Marshal(m)
if err != nil {
return errs.ErrData.Wrap(err.Error())
}
pbData := msg.SendMsgReq{
MsgData: &sdkws.MsgData{
SendID: sendID,
ClientMsgID: utils.GetMsgID(sendID),
SessionType: sessionType,
MsgFrom: constant.SysMsgType,
ContentType: contentType,
Content: bytes,
CreateTime: utils.GetCurrentTimestampByMill(),
Options: options,
},
}
switch sessionType {
case constant.SingleChatType, constant.NotificationChatType:
pbData.MsgData.RecvID = conversationID
case constant.GroupChatType, constant.SuperGroupChatType:
pbData.MsgData.GroupID = conversationID
}
_, err = e.SendMsg(ctx, &pbData)
return err
}
+43 -217
View File
@@ -1,17 +1,3 @@
// Copyright © 2023 OpenIM. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package notification
import (
@@ -30,13 +16,9 @@ import (
"github.com/OpenIMSDK/Open-IM-Server/pkg/utils"
)
func NewGroupNotificationSender(
db controller.GroupDatabase,
msgRpcClient *rpcclient.MessageRpcClient,
fn func(ctx context.Context, userIDs []string) ([]CommonUser, error),
) *GroupNotificationSender {
func NewGroupNotificationSender(db controller.GroupDatabase, msgRpcClient *rpcclient.MessageRpcClient, userRpcClient *rpcclient.UserRpcClient, fn func(ctx context.Context, userIDs []string) ([]CommonUser, error)) *GroupNotificationSender {
return &GroupNotificationSender{
NotificationSender: rpcclient.NewNotificationSender(rpcclient.WithRpcClient(msgRpcClient)),
NotificationSender: rpcclient.NewNotificationSender(rpcclient.WithRpcClient(msgRpcClient), rpcclient.WithUserRpcClient(userRpcClient)),
getUsersInfo: fn,
db: db,
}
@@ -98,11 +80,7 @@ func (g *GroupNotificationSender) getGroupInfo(ctx context.Context, groupID stri
}, nil
}
func (g *GroupNotificationSender) getGroupMembers(
ctx context.Context,
groupID string,
userIDs []string,
) ([]*sdkws.GroupMemberFullInfo, error) {
func (g *GroupNotificationSender) getGroupMembers(ctx context.Context, groupID string, userIDs []string) ([]*sdkws.GroupMemberFullInfo, error) {
members, err := g.db.FindGroupMember(ctx, []string{groupID}, userIDs, nil)
if err != nil {
return nil, err
@@ -117,9 +95,7 @@ func (g *GroupNotificationSender) getGroupMembers(
for _, member := range members {
user, ok := users[member.UserID]
if !ok {
return nil, errs.ErrUserIDNotFound.Wrap(
fmt.Sprintf("group %s member %s not in user", member.GroupID, member.UserID),
)
return nil, errs.ErrUserIDNotFound.Wrap(fmt.Sprintf("group %s member %s not in user", member.GroupID, member.UserID))
}
if member.Nickname == "" {
member.Nickname = user.Nickname
@@ -141,11 +117,7 @@ func (g *GroupNotificationSender) getGroupMembers(
return res, nil
}
func (g *GroupNotificationSender) getGroupMemberMap(
ctx context.Context,
groupID string,
userIDs []string,
) (map[string]*sdkws.GroupMemberFullInfo, error) {
func (g *GroupNotificationSender) getGroupMemberMap(ctx context.Context, groupID string, userIDs []string) (map[string]*sdkws.GroupMemberFullInfo, error) {
members, err := g.getGroupMembers(ctx, groupID, userIDs)
if err != nil {
return nil, err
@@ -157,11 +129,7 @@ func (g *GroupNotificationSender) getGroupMemberMap(
return m, nil
}
func (g *GroupNotificationSender) getGroupMember(
ctx context.Context,
groupID string,
userID string,
) (*sdkws.GroupMemberFullInfo, error) {
func (g *GroupNotificationSender) getGroupMember(ctx context.Context, groupID string, userID string) (*sdkws.GroupMemberFullInfo, error) {
members, err := g.getGroupMembers(ctx, groupID, []string{userID})
if err != nil {
return nil, err
@@ -181,11 +149,7 @@ func (g *GroupNotificationSender) getGroupOwnerAndAdminUserID(ctx context.Contex
return utils.Slice(members, fn), nil
}
func (g *GroupNotificationSender) groupDB2PB(
group *relation.GroupModel,
ownerUserID string,
memberCount uint32,
) *sdkws.GroupInfo {
func (g *GroupNotificationSender) groupDB2PB(group *relation.GroupModel, ownerUserID string, memberCount uint32) *sdkws.GroupInfo {
return &sdkws.GroupInfo{
GroupID: group.GroupID,
GroupName: group.GroupName,
@@ -207,10 +171,7 @@ func (g *GroupNotificationSender) groupDB2PB(
}
}
func (g *GroupNotificationSender) groupMemberDB2PB(
member *relation.GroupMemberModel,
appMangerLevel int32,
) *sdkws.GroupMemberFullInfo {
func (g *GroupNotificationSender) groupMemberDB2PB(member *relation.GroupMemberModel, appMangerLevel int32) *sdkws.GroupMemberFullInfo {
return &sdkws.GroupMemberFullInfo{
GroupID: member.GroupID,
UserID: member.UserID,
@@ -227,10 +188,7 @@ func (g *GroupNotificationSender) groupMemberDB2PB(
}
}
func (g *GroupNotificationSender) getUsersInfoMap(
ctx context.Context,
userIDs []string,
) (map[string]*sdkws.UserInfo, error) {
func (g *GroupNotificationSender) getUsersInfoMap(ctx context.Context, userIDs []string) (map[string]*sdkws.UserInfo, error) {
users, err := g.getUsersInfo(ctx, userIDs)
if err != nil {
return nil, err
@@ -242,11 +200,7 @@ func (g *GroupNotificationSender) getUsersInfoMap(
return result, nil
}
func (g *GroupNotificationSender) fillOpUser(
ctx context.Context,
opUser **sdkws.GroupMemberFullInfo,
groupID string,
) error {
func (g *GroupNotificationSender) fillOpUser(ctx context.Context, opUser **sdkws.GroupMemberFullInfo, groupID string) error {
if opUser == nil {
return errs.ErrInternalServer.Wrap("**sdkws.GroupMemberFullInfo is nil")
}
@@ -285,62 +239,35 @@ func (g *GroupNotificationSender) fillOpUser(
return nil
}
func (g *GroupNotificationSender) GroupCreatedNotification(
ctx context.Context,
tips *sdkws.GroupCreatedTips,
) (err error) {
func (g *GroupNotificationSender) GroupCreatedNotification(ctx context.Context, tips *sdkws.GroupCreatedTips) (err error) {
if err := g.fillOpUser(ctx, &tips.OpUser, tips.Group.GroupID); err != nil {
return err
}
return g.Notification(ctx, mcontext.GetOpUserID(ctx), tips.Group.GroupID, constant.GroupCreatedNotification, tips)
}
func (g *GroupNotificationSender) GroupInfoSetNotification(
ctx context.Context,
tips *sdkws.GroupInfoSetTips,
) (err error) {
func (g *GroupNotificationSender) GroupInfoSetNotification(ctx context.Context, tips *sdkws.GroupInfoSetTips) (err error) {
if err := g.fillOpUser(ctx, &tips.OpUser, tips.Group.GroupID); err != nil {
return err
}
return g.Notification(ctx, mcontext.GetOpUserID(ctx), tips.Group.GroupID, constant.GroupInfoSetNotification, tips)
return g.Notification(ctx, mcontext.GetOpUserID(ctx), tips.Group.GroupID, constant.GroupInfoSetNotification, tips, rpcclient.WithRpcGetUserName())
}
func (g *GroupNotificationSender) GroupInfoSetNameNotification(
ctx context.Context,
tips *sdkws.GroupInfoSetNameTips,
) (err error) {
func (g *GroupNotificationSender) GroupInfoSetNameNotification(ctx context.Context, tips *sdkws.GroupInfoSetNameTips) (err error) {
if err := g.fillOpUser(ctx, &tips.OpUser, tips.Group.GroupID); err != nil {
return err
}
return g.Notification(
ctx,
mcontext.GetOpUserID(ctx),
tips.Group.GroupID,
constant.GroupInfoSetNameNotification,
tips,
)
return g.Notification(ctx, mcontext.GetOpUserID(ctx), tips.Group.GroupID, constant.GroupInfoSetNameNotification, tips)
}
func (g *GroupNotificationSender) GroupInfoSetAnnouncementNotification(
ctx context.Context,
tips *sdkws.GroupInfoSetAnnouncementTips,
) (err error) {
func (g *GroupNotificationSender) GroupInfoSetAnnouncementNotification(ctx context.Context, tips *sdkws.GroupInfoSetAnnouncementTips) (err error) {
if err := g.fillOpUser(ctx, &tips.OpUser, tips.Group.GroupID); err != nil {
return err
}
return g.Notification(
ctx,
mcontext.GetOpUserID(ctx),
tips.Group.GroupID,
constant.GroupInfoSetAnnouncementNotification,
tips,
)
return g.Notification(ctx, mcontext.GetOpUserID(ctx), tips.Group.GroupID, constant.GroupInfoSetAnnouncementNotification, tips, rpcclient.WithRpcGetUserName())
}
func (g *GroupNotificationSender) JoinGroupApplicationNotification(
ctx context.Context,
req *pbGroup.JoinGroupReq,
) (err error) {
func (g *GroupNotificationSender) JoinGroupApplicationNotification(ctx context.Context, req *pbGroup.JoinGroupReq) (err error) {
group, err := g.getGroupInfo(ctx, req.GroupID)
if err != nil {
return err
@@ -364,10 +291,7 @@ func (g *GroupNotificationSender) JoinGroupApplicationNotification(
return nil
}
func (g *GroupNotificationSender) MemberQuitNotification(
ctx context.Context,
member *sdkws.GroupMemberFullInfo,
) (err error) {
func (g *GroupNotificationSender) MemberQuitNotification(ctx context.Context, member *sdkws.GroupMemberFullInfo) (err error) {
defer log.ZDebug(ctx, "return")
defer func() {
if err != nil {
@@ -382,10 +306,7 @@ func (g *GroupNotificationSender) MemberQuitNotification(
return g.Notification(ctx, mcontext.GetOpUserID(ctx), member.GroupID, constant.MemberQuitNotification, tips)
}
func (g *GroupNotificationSender) GroupApplicationAcceptedNotification(
ctx context.Context,
req *pbGroup.GroupApplicationResponseReq,
) (err error) {
func (g *GroupNotificationSender) GroupApplicationAcceptedNotification(ctx context.Context, req *pbGroup.GroupApplicationResponseReq) (err error) {
defer log.ZDebug(ctx, "return")
defer func() {
if err != nil {
@@ -405,13 +326,7 @@ func (g *GroupNotificationSender) GroupApplicationAcceptedNotification(
return err
}
for _, userID := range append(userIDs, mcontext.GetOpUserID(ctx)) {
err = g.Notification(
ctx,
mcontext.GetOpUserID(ctx),
userID,
constant.GroupApplicationAcceptedNotification,
tips,
)
err = g.Notification(ctx, mcontext.GetOpUserID(ctx), userID, constant.GroupApplicationAcceptedNotification, tips)
if err != nil {
log.ZError(ctx, "failed", err)
}
@@ -419,10 +334,7 @@ func (g *GroupNotificationSender) GroupApplicationAcceptedNotification(
return nil
}
func (g *GroupNotificationSender) GroupApplicationRejectedNotification(
ctx context.Context,
req *pbGroup.GroupApplicationResponseReq,
) (err error) {
func (g *GroupNotificationSender) GroupApplicationRejectedNotification(ctx context.Context, req *pbGroup.GroupApplicationResponseReq) (err error) {
group, err := g.getGroupInfo(ctx, req.GroupID)
if err != nil {
return err
@@ -436,13 +348,7 @@ func (g *GroupNotificationSender) GroupApplicationRejectedNotification(
return err
}
for _, userID := range append(userIDs, mcontext.GetOpUserID(ctx)) {
err = g.Notification(
ctx,
mcontext.GetOpUserID(ctx),
userID,
constant.GroupApplicationRejectedNotification,
tips,
)
err = g.Notification(ctx, mcontext.GetOpUserID(ctx), userID, constant.GroupApplicationRejectedNotification, tips)
if err != nil {
log.ZError(ctx, "failed", err)
}
@@ -450,10 +356,7 @@ func (g *GroupNotificationSender) GroupApplicationRejectedNotification(
return nil
}
func (g *GroupNotificationSender) GroupOwnerTransferredNotification(
ctx context.Context,
req *pbGroup.TransferGroupOwnerReq,
) (err error) {
func (g *GroupNotificationSender) GroupOwnerTransferredNotification(ctx context.Context, req *pbGroup.TransferGroupOwnerReq) (err error) {
group, err := g.getGroupInfo(ctx, req.GroupID)
if err != nil {
return err
@@ -463,38 +366,21 @@ func (g *GroupNotificationSender) GroupOwnerTransferredNotification(
if err != nil {
return err
}
tips := &sdkws.GroupOwnerTransferredTips{
Group: group,
OpUser: member[opUserID],
NewGroupOwner: member[req.NewOwnerUserID],
}
tips := &sdkws.GroupOwnerTransferredTips{Group: group, OpUser: member[opUserID], NewGroupOwner: member[req.NewOwnerUserID]}
if err := g.fillOpUser(ctx, &tips.OpUser, tips.Group.GroupID); err != nil {
return err
}
return g.Notification(
ctx,
mcontext.GetOpUserID(ctx),
group.GroupID,
constant.GroupOwnerTransferredNotification,
tips,
)
return g.Notification(ctx, mcontext.GetOpUserID(ctx), group.GroupID, constant.GroupOwnerTransferredNotification, tips)
}
func (g *GroupNotificationSender) MemberKickedNotification(
ctx context.Context,
tips *sdkws.MemberKickedTips,
) (err error) {
func (g *GroupNotificationSender) MemberKickedNotification(ctx context.Context, tips *sdkws.MemberKickedTips) (err error) {
if err := g.fillOpUser(ctx, &tips.OpUser, tips.Group.GroupID); err != nil {
return err
}
return g.Notification(ctx, mcontext.GetOpUserID(ctx), tips.Group.GroupID, constant.MemberKickedNotification, tips)
}
func (g *GroupNotificationSender) MemberInvitedNotification(
ctx context.Context,
groupID, reason string,
invitedUserIDList []string,
) (err error) {
func (g *GroupNotificationSender) MemberInvitedNotification(ctx context.Context, groupID, reason string, invitedUserIDList []string) (err error) {
group, err := g.getGroupInfo(ctx, groupID)
if err != nil {
return err
@@ -513,10 +399,7 @@ func (g *GroupNotificationSender) MemberInvitedNotification(
return g.Notification(ctx, mcontext.GetOpUserID(ctx), group.GroupID, constant.MemberInvitedNotification, tips)
}
func (g *GroupNotificationSender) MemberEnterNotification(
ctx context.Context,
req *pbGroup.GroupApplicationResponseReq,
) (err error) {
func (g *GroupNotificationSender) MemberEnterNotification(ctx context.Context, req *pbGroup.GroupApplicationResponseReq) (err error) {
group, err := g.getGroupInfo(ctx, req.GroupID)
if err != nil {
return err
@@ -529,21 +412,14 @@ func (g *GroupNotificationSender) MemberEnterNotification(
return g.Notification(ctx, mcontext.GetOpUserID(ctx), group.GroupID, constant.MemberEnterNotification, tips)
}
func (g *GroupNotificationSender) GroupDismissedNotification(
ctx context.Context,
tips *sdkws.GroupDismissedTips,
) (err error) {
func (g *GroupNotificationSender) GroupDismissedNotification(ctx context.Context, tips *sdkws.GroupDismissedTips) (err error) {
if err := g.fillOpUser(ctx, &tips.OpUser, tips.Group.GroupID); err != nil {
return err
}
return g.Notification(ctx, mcontext.GetOpUserID(ctx), tips.Group.GroupID, constant.GroupDismissedNotification, tips)
}
func (g *GroupNotificationSender) GroupMemberMutedNotification(
ctx context.Context,
groupID, groupMemberUserID string,
mutedSeconds uint32,
) (err error) {
func (g *GroupNotificationSender) GroupMemberMutedNotification(ctx context.Context, groupID, groupMemberUserID string, mutedSeconds uint32) (err error) {
group, err := g.getGroupInfo(ctx, groupID)
if err != nil {
return err
@@ -560,10 +436,7 @@ func (g *GroupNotificationSender) GroupMemberMutedNotification(
return g.Notification(ctx, mcontext.GetOpUserID(ctx), group.GroupID, constant.GroupMemberMutedNotification, tips)
}
func (g *GroupNotificationSender) GroupMemberCancelMutedNotification(
ctx context.Context,
groupID, groupMemberUserID string,
) (err error) {
func (g *GroupNotificationSender) GroupMemberCancelMutedNotification(ctx context.Context, groupID, groupMemberUserID string) (err error) {
group, err := g.getGroupInfo(ctx, groupID)
if err != nil {
return err
@@ -572,21 +445,11 @@ func (g *GroupNotificationSender) GroupMemberCancelMutedNotification(
if err != nil {
return err
}
tips := &sdkws.GroupMemberCancelMutedTips{
Group: group,
OpUser: user[mcontext.GetOpUserID(ctx)],
MutedUser: user[groupMemberUserID],
}
tips := &sdkws.GroupMemberCancelMutedTips{Group: group, OpUser: user[mcontext.GetOpUserID(ctx)], MutedUser: user[groupMemberUserID]}
if err := g.fillOpUser(ctx, &tips.OpUser, tips.Group.GroupID); err != nil {
return err
}
return g.Notification(
ctx,
mcontext.GetOpUserID(ctx),
group.GroupID,
constant.GroupMemberCancelMutedNotification,
tips,
)
return g.Notification(ctx, mcontext.GetOpUserID(ctx), group.GroupID, constant.GroupMemberCancelMutedNotification, tips)
}
func (g *GroupNotificationSender) GroupMutedNotification(ctx context.Context, groupID string) (err error) {
@@ -627,10 +490,7 @@ func (g *GroupNotificationSender) GroupCancelMutedNotification(ctx context.Conte
return g.Notification(ctx, mcontext.GetOpUserID(ctx), group.GroupID, constant.GroupCancelMutedNotification, tips)
}
func (g *GroupNotificationSender) GroupMemberInfoSetNotification(
ctx context.Context,
groupID, groupMemberUserID string,
) (err error) {
func (g *GroupNotificationSender) GroupMemberInfoSetNotification(ctx context.Context, groupID, groupMemberUserID string) (err error) {
group, err := g.getGroupInfo(ctx, groupID)
if err != nil {
return err
@@ -639,21 +499,14 @@ func (g *GroupNotificationSender) GroupMemberInfoSetNotification(
if err != nil {
return err
}
tips := &sdkws.GroupMemberInfoSetTips{
Group: group,
OpUser: user[mcontext.GetOpUserID(ctx)],
ChangedUser: user[groupMemberUserID],
}
tips := &sdkws.GroupMemberInfoSetTips{Group: group, OpUser: user[mcontext.GetOpUserID(ctx)], ChangedUser: user[groupMemberUserID]}
if err := g.fillOpUser(ctx, &tips.OpUser, tips.Group.GroupID); err != nil {
return err
}
return g.Notification(ctx, mcontext.GetOpUserID(ctx), group.GroupID, constant.GroupMemberInfoSetNotification, tips)
}
func (g *GroupNotificationSender) GroupMemberSetToAdminNotification(
ctx context.Context,
groupID, groupMemberUserID string,
) (err error) {
func (g *GroupNotificationSender) GroupMemberSetToAdminNotification(ctx context.Context, groupID, groupMemberUserID string) (err error) {
group, err := g.getGroupInfo(ctx, groupID)
if err != nil {
return err
@@ -662,27 +515,14 @@ func (g *GroupNotificationSender) GroupMemberSetToAdminNotification(
if err != nil {
return err
}
tips := &sdkws.GroupMemberInfoSetTips{
Group: group,
OpUser: user[mcontext.GetOpUserID(ctx)],
ChangedUser: user[groupMemberUserID],
}
tips := &sdkws.GroupMemberInfoSetTips{Group: group, OpUser: user[mcontext.GetOpUserID(ctx)], ChangedUser: user[groupMemberUserID]}
if err := g.fillOpUser(ctx, &tips.OpUser, tips.Group.GroupID); err != nil {
return err
}
return g.Notification(
ctx,
mcontext.GetOpUserID(ctx),
group.GroupID,
constant.GroupMemberSetToAdminNotification,
tips,
)
return g.Notification(ctx, mcontext.GetOpUserID(ctx), group.GroupID, constant.GroupMemberSetToAdminNotification, tips)
}
func (g *GroupNotificationSender) GroupMemberSetToOrdinaryUserNotification(
ctx context.Context,
groupID, groupMemberUserID string,
) (err error) {
func (g *GroupNotificationSender) GroupMemberSetToOrdinaryUserNotification(ctx context.Context, groupID, groupMemberUserID string) (err error) {
group, err := g.getGroupInfo(ctx, groupID)
if err != nil {
return err
@@ -691,28 +531,14 @@ func (g *GroupNotificationSender) GroupMemberSetToOrdinaryUserNotification(
if err != nil {
return err
}
tips := &sdkws.GroupMemberInfoSetTips{
Group: group,
OpUser: user[mcontext.GetOpUserID(ctx)],
ChangedUser: user[groupMemberUserID],
}
tips := &sdkws.GroupMemberInfoSetTips{Group: group, OpUser: user[mcontext.GetOpUserID(ctx)], ChangedUser: user[groupMemberUserID]}
if err := g.fillOpUser(ctx, &tips.OpUser, tips.Group.GroupID); err != nil {
return err
}
return g.Notification(
ctx,
mcontext.GetOpUserID(ctx),
group.GroupID,
constant.GroupMemberSetToOrdinaryUserNotification,
tips,
)
return g.Notification(ctx, mcontext.GetOpUserID(ctx), group.GroupID, constant.GroupMemberSetToOrdinaryUserNotification, tips)
}
func (g *GroupNotificationSender) MemberEnterDirectlyNotification(
ctx context.Context,
groupID string,
entrantUserID string,
) (err error) {
func (g *GroupNotificationSender) MemberEnterDirectlyNotification(ctx context.Context, groupID string, entrantUserID string) (err error) {
defer log.ZDebug(ctx, "return")
defer func() {
if err != nil {
+36
View File
@@ -0,0 +1,36 @@
package notification
import (
"context"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/constant"
"github.com/OpenIMSDK/Open-IM-Server/pkg/proto/sdkws"
"github.com/OpenIMSDK/Open-IM-Server/pkg/rpcclient"
)
type MsgNotificationSender struct {
*rpcclient.NotificationSender
}
func NewMsgNotificationSender(opts ...rpcclient.NotificationSenderOptions) *MsgNotificationSender {
return &MsgNotificationSender{rpcclient.NewNotificationSender(opts...)}
}
func (m *MsgNotificationSender) UserDeleteMsgsNotification(ctx context.Context, userID, conversationID string, seqs []int64) error {
tips := sdkws.DeleteMsgsTips{
UserID: userID,
ConversationID: conversationID,
Seqs: seqs,
}
return m.Notification(ctx, userID, userID, constant.MsgDeleteNotification, &tips)
}
func (m *MsgNotificationSender) MarkAsReadNotification(ctx context.Context, conversationID string, sesstionType int32, sendID, recvID string, seqs []int64, hasReadSeq int64) error {
tips := &sdkws.MarkAsReadTips{
MarkAsReadUserID: sendID,
ConversationID: conversationID,
Seqs: seqs,
HasReadSeq: hasReadSeq,
}
return m.NotificationWithSesstionType(ctx, sendID, recvID, constant.HasReadReceipt, sesstionType, tips)
}
+3 -5
View File
@@ -17,7 +17,6 @@ package rpcclient
import (
"context"
"strings"
"time"
"google.golang.org/grpc"
@@ -33,17 +32,16 @@ import (
type User struct {
conn grpc.ClientConnInterface
Client user.UserClient
discov discoveryregistry.SvcDiscoveryRegistry
Discov discoveryregistry.SvcDiscoveryRegistry
}
func NewUser(discov discoveryregistry.SvcDiscoveryRegistry) *User {
ctx, _ := context.WithTimeout(context.Background(), time.Second*3)
conn, err := discov.GetConn(ctx, config.Config.RpcRegisterName.OpenImUserName)
conn, err := discov.GetConn(context.Background(), config.Config.RpcRegisterName.OpenImUserName)
if err != nil {
panic(err)
}
client := user.NewUserClient(conn)
return &User{discov: discov, Client: client, conn: conn}
return &User{Discov: discov, Client: client, conn: conn}
}
type UserRpcClient User