fix: changing naming irregularities under pkg and internal packages (#520)

pull/636/head
BanTanger 2 years ago
parent 2de5861488
commit 5283232017

@ -154,17 +154,21 @@ func (m *MessageRpcClient) GetMaxSeq(ctx context.Context, req *sdkws.GetMaxSeqRe
func (m *MessageRpcClient) PullMessageBySeqList(ctx context.Context, req *sdkws.PullMessageBySeqsReq) (*sdkws.PullMessageBySeqsResp, error) {
resp, err := m.Client.PullMessageBySeqs(ctx, req)
return resp, err
}
// GetConversationMaxSeq
func (m *MessageRpcClient) GetConversationMaxSeq(ctx context.Context, conversationID string) (int64, error) {
resp, err := m.Client.GetConversationMaxSeq(ctx, &msg.GetConversationMaxSeqReq{ConversationID: conversationID})
if err != nil {
return 0, err
}
return resp.MaxSeq, nil
}
// NotificationSender
type NotificationSender struct {
contentTypeConf map[int32]config.NotificationConf
sessionTypeConf map[int32]int32
@ -172,31 +176,37 @@ type NotificationSender struct {
getUserInfo func(ctx context.Context, userID string) (*sdkws.UserInfo, error)
}
// NotificationSenderOptions
type NotificationSenderOptions func(*NotificationSender)
// WithLocalSendMsg
func WithLocalSendMsg(sendMsg func(ctx context.Context, req *msg.SendMsgReq) (*msg.SendMsgResp, error)) NotificationSenderOptions {
return func(s *NotificationSender) {
s.sendMsg = sendMsg
}
}
// WithRpcClient
func WithRpcClient(msgRpcClient *MessageRpcClient) NotificationSenderOptions {
return func(s *NotificationSender) {
s.sendMsg = msgRpcClient.SendMsg
}
}
// WithUserRpcClient
func WithUserRpcClient(userRpcClient *UserRpcClient) NotificationSenderOptions {
return func(s *NotificationSender) {
s.getUserInfo = userRpcClient.GetUserInfo
}
}
// NewNotificationSender
func NewNotificationSender(opts ...NotificationSenderOptions) *NotificationSender {
notificationSender := &NotificationSender{contentTypeConf: newContentTypeConf(), sessionTypeConf: newSessionTypeConf()}
for _, opt := range opts {
opt(notificationSender)
}
return notificationSender
}
@ -204,19 +214,23 @@ type notificationOpt struct {
WithRpcGetUsername bool
}
// NotificationOptions
type NotificationOptions func(*notificationOpt)
// WithRpcGetUserName
func WithRpcGetUserName() NotificationOptions {
return func(opt *notificationOpt) {
opt.WithRpcGetUsername = true
}
}
// NotificationWithSesstionType
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)
return err
}
notificationOpt := &notificationOpt{}
@ -260,9 +274,11 @@ func (s *NotificationSender) NotificationWithSesstionType(ctx context.Context, s
} else {
log.ZError(ctx, "MsgClient Notification SendMsg failed", err, "req", &req)
}
return err
}
// Notification
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...)
}

@ -14,6 +14,7 @@
package notification
// CommonUser
type CommonUser interface {
GetNickname() string
GetFaceURL() string
@ -21,6 +22,7 @@ type CommonUser interface {
GetEx() string
}
// CommonGroup
type CommonGroup interface {
GetNickname() string
GetFaceURL() string

@ -22,15 +22,17 @@ import (
"github.com/OpenIMSDK/Open-IM-Server/pkg/rpcclient"
)
// ConversationNotificationSender
type ConversationNotificationSender struct {
*rpcclient.NotificationSender
}
// NewConversationNotificationSender
func NewConversationNotificationSender(msgRpcClient *rpcclient.MessageRpcClient) *ConversationNotificationSender {
return &ConversationNotificationSender{rpcclient.NewNotificationSender(rpcclient.WithRpcClient(msgRpcClient))}
}
// SetPrivate调用.
// ConversationSetPrivateNotification
func (c *ConversationNotificationSender) ConversationSetPrivateNotification(
ctx context.Context,
sendID, recvID string,
@ -41,18 +43,20 @@ func (c *ConversationNotificationSender) ConversationSetPrivateNotification(
SendID: sendID,
IsPrivate: isPrivateChat,
}
return c.Notification(ctx, sendID, recvID, constant.ConversationPrivateChatNotification, tips)
}
// 会话改变.
// ConversationChangeNotification
func (c *ConversationNotificationSender) ConversationChangeNotification(ctx context.Context, userID string) error {
tips := &sdkws.ConversationUpdateTips{
UserID: userID,
}
return c.Notification(ctx, userID, userID, constant.ConversationChangeNotification, tips)
}
// 会话未读数同步.
// ConversationUnreadChangeNotification
func (c *ConversationNotificationSender) ConversationUnreadChangeNotification(
ctx context.Context,
userID, conversationID string,
@ -64,5 +68,6 @@ func (c *ConversationNotificationSender) ConversationUnreadChangeNotification(
HasReadSeq: hasReadSeq,
UnreadCountTime: unreadCountTime,
}
return c.Notification(ctx, userID, userID, constant.ConversationUnreadNotification, tips)
}

@ -28,9 +28,10 @@ import (
"github.com/OpenIMSDK/Open-IM-Server/pkg/rpcclient"
)
// FriendNotificationSender
type FriendNotificationSender struct {
*rpcclient.NotificationSender
// 找不到报错
// if not finded, return err
getUsersInfo func(ctx context.Context, userIDs []string) ([]CommonUser, error)
// db controller
db controller.FriendDatabase
@ -38,12 +39,14 @@ type FriendNotificationSender struct {
type friendNotificationSenderOptions func(*FriendNotificationSender)
// WithFriendDB
func WithFriendDB(db controller.FriendDatabase) friendNotificationSenderOptions {
return func(s *FriendNotificationSender) {
s.db = db
}
}
// WithDBFunc
func WithDBFunc(
fn func(ctx context.Context, userIDs []string) (users []*relationTb.UserModel, err error),
) friendNotificationSenderOptions {
@ -56,12 +59,14 @@ func WithDBFunc(
for _, user := range users {
result = append(result, user)
}
return result, nil
}
s.getUsersInfo = f
}
}
// WithRpcFunc
func WithRpcFunc(
fn func(ctx context.Context, userIDs []string) ([]*sdkws.UserInfo, error),
) friendNotificationSenderOptions {
@ -74,12 +79,14 @@ func WithRpcFunc(
for _, user := range users {
result = append(result, user)
}
return result, err
}
s.getUsersInfo = f
}
}
// NewFriendNotificationSender
func NewFriendNotificationSender(
msgRpcClient *rpcclient.MessageRpcClient,
opts ...friendNotificationSenderOptions,
@ -90,6 +97,7 @@ func NewFriendNotificationSender(
for _, opt := range opts {
opt(f)
}
return f
}
@ -105,6 +113,7 @@ func (f *FriendNotificationSender) getUsersInfoMap(
for _, user := range users {
result[user.GetUserID()] = user.(*sdkws.UserInfo)
}
return result, nil
}
@ -114,16 +123,20 @@ func (f *FriendNotificationSender) getFromToUserNickname(
) (string, string, error) {
users, err := f.getUsersInfoMap(ctx, []string{fromUserID, toUserID})
if err != nil {
return "", "", nil
return "", "", err
}
return users[fromUserID].Nickname, users[toUserID].Nickname, nil
}
// UserInfoUpdatedNotification
func (f *FriendNotificationSender) UserInfoUpdatedNotification(ctx context.Context, changedUserID string) error {
tips := sdkws.UserInfoUpdatedTips{UserID: changedUserID}
return f.Notification(ctx, mcontext.GetOpUserID(ctx), changedUserID, constant.UserInfoUpdatedNotification, &tips)
}
// FriendApplicationAddNotification
func (f *FriendNotificationSender) FriendApplicationAddNotification(
ctx context.Context,
req *pbFriend.ApplyToAddFriendReq,
@ -132,9 +145,11 @@ func (f *FriendNotificationSender) FriendApplicationAddNotification(
FromUserID: req.FromUserID,
ToUserID: req.ToUserID,
}}
return f.Notification(ctx, req.FromUserID, req.ToUserID, constant.FriendApplicationNotification, &tips)
}
// FriendApplicationAgreedNotification
func (c *FriendNotificationSender) FriendApplicationAgreedNotification(
ctx context.Context,
req *pbFriend.RespondFriendApplyReq,
@ -143,6 +158,7 @@ func (c *FriendNotificationSender) FriendApplicationAgreedNotification(
FromUserID: req.FromUserID,
ToUserID: req.ToUserID,
}, HandleMsg: req.HandleMsg}
return c.Notification(ctx, req.ToUserID, req.FromUserID, constant.FriendApplicationApprovedNotification, &tips)
}
@ -154,9 +170,11 @@ func (c *FriendNotificationSender) FriendApplicationRefusedNotification(
FromUserID: req.FromUserID,
ToUserID: req.ToUserID,
}, HandleMsg: req.HandleMsg}
return c.Notification(ctx, req.ToUserID, req.FromUserID, constant.FriendApplicationRejectedNotification, &tips)
}
// FriendAddedNotification
func (c *FriendNotificationSender) FriendAddedNotification(
ctx context.Context,
operationID, opUserID, fromUserID, toUserID string,
@ -178,31 +196,39 @@ func (c *FriendNotificationSender) FriendAddedNotification(
if err != nil {
return err
}
return c.Notification(ctx, fromUserID, toUserID, constant.FriendAddedNotification, &tips)
}
// FriendDeletedNotification
func (c *FriendNotificationSender) FriendDeletedNotification(ctx context.Context, req *pbFriend.DeleteFriendReq) error {
tips := sdkws.FriendDeletedTips{FromToUserID: &sdkws.FromToUserID{
FromUserID: req.OwnerUserID,
ToUserID: req.FriendUserID,
}}
return c.Notification(ctx, req.OwnerUserID, req.FriendUserID, constant.FriendDeletedNotification, &tips)
}
// FriendRemarkSetNotification
func (c *FriendNotificationSender) FriendRemarkSetNotification(ctx context.Context, fromUserID, toUserID string) error {
tips := sdkws.FriendInfoChangedTips{FromToUserID: &sdkws.FromToUserID{}}
tips.FromToUserID.FromUserID = fromUserID
tips.FromToUserID.ToUserID = toUserID
return c.Notification(ctx, fromUserID, toUserID, constant.FriendRemarkSetNotification, &tips)
}
// BlackAddedNotification
func (c *FriendNotificationSender) BlackAddedNotification(ctx context.Context, req *pbFriend.AddBlackReq) error {
tips := sdkws.BlackAddedTips{FromToUserID: &sdkws.FromToUserID{}}
tips.FromToUserID.FromUserID = req.OwnerUserID
tips.FromToUserID.ToUserID = req.BlackUserID
return c.Notification(ctx, req.OwnerUserID, req.BlackUserID, constant.BlackAddedNotification, &tips)
}
// BlackDeletedNotification
func (c *FriendNotificationSender) BlackDeletedNotification(ctx context.Context, req *pbFriend.RemoveBlackReq) {
blackDeletedTips := sdkws.BlackDeletedTips{FromToUserID: &sdkws.FromToUserID{
FromUserID: req.OwnerUserID,
@ -211,6 +237,7 @@ func (c *FriendNotificationSender) BlackDeletedNotification(ctx context.Context,
c.Notification(ctx, req.OwnerUserID, req.BlackUserID, constant.BlackDeletedNotification, &blackDeletedTips)
}
// FriendInfoUpdatedNotification
func (c *FriendNotificationSender) FriendInfoUpdatedNotification(
ctx context.Context,
changedUserID string,

@ -30,6 +30,7 @@ import (
"github.com/OpenIMSDK/Open-IM-Server/pkg/utils"
)
// NewGroupNotificationSender
func NewGroupNotificationSender(
db controller.GroupDatabase,
msgRpcClient *rpcclient.MessageRpcClient,
@ -43,6 +44,7 @@ func NewGroupNotificationSender(
}
}
// GroupNotificationSender
type GroupNotificationSender struct {
*rpcclient.NotificationSender
getUsersInfo func(ctx context.Context, userIDs []string) ([]CommonUser, error)
@ -57,6 +59,7 @@ func (g *GroupNotificationSender) getUser(ctx context.Context, userID string) (*
if len(users) == 0 {
return nil, errs.ErrUserIDNotFound.Wrap(fmt.Sprintf("user %s not found", userID))
}
return &sdkws.PublicUserInfo{
UserID: users[0].GetUserID(),
Nickname: users[0].GetNickname(),
@ -78,6 +81,7 @@ func (g *GroupNotificationSender) getGroupInfo(ctx context.Context, groupID stri
if err != nil {
return nil, err
}
return &sdkws.GroupInfo{
GroupID: gm.GroupID,
GroupName: gm.GroupName,
@ -122,7 +126,7 @@ func (g *GroupNotificationSender) getGroupMembers(ctx context.Context, groupID s
res = append(res, g.groupMemberDB2PB(member, user.AppMangerLevel))
delete(users, member.UserID)
}
//for userID, info := range users {
// for userID, info := range users {
// if info.AppMangerLevel == constant.AppAdmin {
// res = append(res, &sdkws.GroupMemberFullInfo{
// GroupID: groupID,
@ -132,7 +136,7 @@ func (g *GroupNotificationSender) getGroupMembers(ctx context.Context, groupID s
// AppMangerLevel: info.AppMangerLevel,
// })
// }
//}
// }
return res, nil
}
@ -145,6 +149,7 @@ func (g *GroupNotificationSender) getGroupMemberMap(ctx context.Context, groupID
for i, member := range members {
m[member.UserID] = members[i]
}
return m, nil
}
@ -156,6 +161,7 @@ func (g *GroupNotificationSender) getGroupMember(ctx context.Context, groupID st
if len(members) == 0 {
return nil, errs.ErrInternalServer.Wrap(fmt.Sprintf("group %s member %s not found", groupID, userID))
}
return members[0], nil
}
@ -165,6 +171,7 @@ func (g *GroupNotificationSender) getGroupOwnerAndAdminUserID(ctx context.Contex
return nil, err
}
fn := func(e *relation.GroupMemberModel) string { return e.UserID }
return utils.Slice(members, fn), nil
}
@ -216,6 +223,7 @@ func (g *GroupNotificationSender) getUsersInfoMap(ctx context.Context, userIDs [
for _, user := range users {
result[user.GetUserID()] = user.(*sdkws.UserInfo)
}
return result, nil
}
@ -255,37 +263,47 @@ func (g *GroupNotificationSender) fillOpUser(ctx context.Context, opUser **sdkws
(*opUser).FaceURL = user.FaceURL
}
}
return nil
}
// GroupCreatedNotification
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)
}
// GroupInfoSetNotification
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, rpcclient.WithRpcGetUserName())
}
// GroupInfoSetNameNotification
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)
}
// GroupInfoSetAnnouncementNotification
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, rpcclient.WithRpcGetUserName())
}
// JoinGroupApplicationNotification
func (g *GroupNotificationSender) JoinGroupApplicationNotification(ctx context.Context, req *pbGroup.JoinGroupReq) (err error) {
group, err := g.getGroupInfo(ctx, req.GroupID)
if err != nil {
@ -307,9 +325,11 @@ func (g *GroupNotificationSender) JoinGroupApplicationNotification(ctx context.C
log.ZError(ctx, "JoinGroupApplicationNotification failed", err, "group", req.GroupID, "userID", userID)
}
}
return nil
}
// MemberQuitNotification
func (g *GroupNotificationSender) MemberQuitNotification(ctx context.Context, member *sdkws.GroupMemberFullInfo) (err error) {
defer log.ZDebug(ctx, "return")
defer func() {
@ -322,9 +342,11 @@ func (g *GroupNotificationSender) MemberQuitNotification(ctx context.Context, me
return err
}
tips := &sdkws.MemberQuitTips{Group: group, QuitUser: member}
return g.Notification(ctx, mcontext.GetOpUserID(ctx), member.GroupID, constant.MemberQuitNotification, tips)
}
// GroupApplicationAcceptedNotification
func (g *GroupNotificationSender) GroupApplicationAcceptedNotification(ctx context.Context, req *pbGroup.GroupApplicationResponseReq) (err error) {
defer log.ZDebug(ctx, "return")
defer func() {
@ -350,9 +372,11 @@ func (g *GroupNotificationSender) GroupApplicationAcceptedNotification(ctx conte
log.ZError(ctx, "failed", err)
}
}
return nil
}
// GroupApplicationRejectedNotification
func (g *GroupNotificationSender) GroupApplicationRejectedNotification(ctx context.Context, req *pbGroup.GroupApplicationResponseReq) (err error) {
group, err := g.getGroupInfo(ctx, req.GroupID)
if err != nil {
@ -372,9 +396,11 @@ func (g *GroupNotificationSender) GroupApplicationRejectedNotification(ctx conte
log.ZError(ctx, "failed", err)
}
}
return nil
}
// GroupOwnerTransferredNotification
func (g *GroupNotificationSender) GroupOwnerTransferredNotification(ctx context.Context, req *pbGroup.TransferGroupOwnerReq) (err error) {
group, err := g.getGroupInfo(ctx, req.GroupID)
if err != nil {
@ -389,16 +415,20 @@ func (g *GroupNotificationSender) GroupOwnerTransferredNotification(ctx context.
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)
}
// MemberKickedNotification
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)
}
// MemberInvitedNotification
func (g *GroupNotificationSender) MemberInvitedNotification(ctx context.Context, groupID, reason string, invitedUserIDList []string) (err error) {
group, err := g.getGroupInfo(ctx, groupID)
if err != nil {
@ -415,9 +445,11 @@ func (g *GroupNotificationSender) MemberInvitedNotification(ctx context.Context,
if err := g.fillOpUser(ctx, &tips.OpUser, tips.Group.GroupID); err != nil {
return err
}
return g.Notification(ctx, mcontext.GetOpUserID(ctx), group.GroupID, constant.MemberInvitedNotification, tips)
}
// MemberEnterNotification
func (g *GroupNotificationSender) MemberEnterNotification(ctx context.Context, req *pbGroup.GroupApplicationResponseReq) (err error) {
group, err := g.getGroupInfo(ctx, req.GroupID)
if err != nil {
@ -435,9 +467,11 @@ func (g *GroupNotificationSender) GroupDismissedNotification(ctx context.Context
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)
}
// GroupMemberMutedNotification
func (g *GroupNotificationSender) GroupMemberMutedNotification(ctx context.Context, groupID, groupMemberUserID string, mutedSeconds uint32) (err error) {
group, err := g.getGroupInfo(ctx, groupID)
if err != nil {
@ -454,6 +488,7 @@ func (g *GroupNotificationSender) GroupMemberMutedNotification(ctx context.Conte
if err := g.fillOpUser(ctx, &tips.OpUser, tips.Group.GroupID); err != nil {
return err
}
return g.Notification(ctx, mcontext.GetOpUserID(ctx), group.GroupID, constant.GroupMemberMutedNotification, tips)
}
@ -470,6 +505,7 @@ func (g *GroupNotificationSender) GroupMemberCancelMutedNotification(ctx context
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)
}
@ -489,6 +525,7 @@ func (g *GroupNotificationSender) GroupMutedNotification(ctx context.Context, gr
if err := g.fillOpUser(ctx, &tips.OpUser, tips.Group.GroupID); err != nil {
return err
}
return g.Notification(ctx, mcontext.GetOpUserID(ctx), group.GroupID, constant.GroupMutedNotification, tips)
}
@ -508,9 +545,11 @@ func (g *GroupNotificationSender) GroupCancelMutedNotification(ctx context.Conte
if err := g.fillOpUser(ctx, &tips.OpUser, tips.Group.GroupID); err != nil {
return err
}
return g.Notification(ctx, mcontext.GetOpUserID(ctx), group.GroupID, constant.GroupCancelMutedNotification, tips)
}
// GroupMemberInfoSetNotification
func (g *GroupNotificationSender) GroupMemberInfoSetNotification(ctx context.Context, groupID, groupMemberUserID string) (err error) {
group, err := g.getGroupInfo(ctx, groupID)
if err != nil {
@ -524,6 +563,7 @@ func (g *GroupNotificationSender) GroupMemberInfoSetNotification(ctx context.Con
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)
}
@ -540,6 +580,7 @@ func (g *GroupNotificationSender) GroupMemberSetToAdminNotification(ctx context.
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)
}
@ -559,6 +600,7 @@ func (g *GroupNotificationSender) GroupMemberSetToOrdinaryUserNotification(ctx c
return g.Notification(ctx, mcontext.GetOpUserID(ctx), group.GroupID, constant.GroupMemberSetToOrdinaryUserNotification, tips)
}
// MemberEnterDirectlyNotification
func (g *GroupNotificationSender) MemberEnterDirectlyNotification(ctx context.Context, groupID string, entrantUserID string) (err error) {
defer log.ZDebug(ctx, "return")
defer func() {
@ -575,9 +617,11 @@ func (g *GroupNotificationSender) MemberEnterDirectlyNotification(ctx context.Co
return err
}
tips := &sdkws.MemberEnterTips{Group: group, EntrantUser: user}
return g.Notification(ctx, mcontext.GetOpUserID(ctx), group.GroupID, constant.MemberEnterNotification, tips)
}
// SuperGroupNotification
func (g *GroupNotificationSender) SuperGroupNotification(ctx context.Context, sendID, recvID string) (err error) {
defer log.ZDebug(ctx, "return")
defer func() {
@ -586,5 +630,6 @@ func (g *GroupNotificationSender) SuperGroupNotification(ctx context.Context, se
}
}()
err = g.Notification(ctx, sendID, recvID, constant.SuperGroupUpdateNotification, nil)
return err
}

@ -22,23 +22,28 @@ import (
"github.com/OpenIMSDK/Open-IM-Server/pkg/rpcclient"
)
// MsgNotificationSender
type MsgNotificationSender struct {
*rpcclient.NotificationSender
}
// NewMsgNotificationSender
func NewMsgNotificationSender(opts ...rpcclient.NotificationSenderOptions) *MsgNotificationSender {
return &MsgNotificationSender{rpcclient.NewNotificationSender(opts...)}
}
// UserDeleteMsgsNotification
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.DeleteMsgsNotification, &tips)
}
// MarkAsReadNotification
func (m *MsgNotificationSender) MarkAsReadNotification(ctx context.Context, conversationID string, sesstionType int32, sendID, recvID string, seqs []int64, hasReadSeq int64) error {
tips := &sdkws.MarkAsReadTips{
MarkAsReadUserID: sendID,
@ -46,5 +51,6 @@ func (m *MsgNotificationSender) MarkAsReadNotification(ctx context.Context, conv
Seqs: seqs,
HasReadSeq: hasReadSeq,
}
return m.NotificationWithSesstionType(ctx, sendID, recvID, constant.HasReadReceipt, sesstionType, tips)
}

@ -24,17 +24,20 @@ import (
"github.com/OpenIMSDK/Open-IM-Server/pkg/proto/push"
)
// Push
type Push struct {
conn grpc.ClientConnInterface
Client push.PushMsgServiceClient
discov discoveryregistry.SvcDiscoveryRegistry
}
// NewPush
func NewPush(discov discoveryregistry.SvcDiscoveryRegistry) *Push {
conn, err := discov.GetConn(context.Background(), config.Config.RpcRegisterName.OpenImPushName)
if err != nil {
panic(err)
}
return &Push{
discov: discov,
conn: conn,
@ -42,12 +45,15 @@ func NewPush(discov discoveryregistry.SvcDiscoveryRegistry) *Push {
}
}
// PushRpcClient
type PushRpcClient Push
// NewPushRpcClient
func NewPushRpcClient(discov discoveryregistry.SvcDiscoveryRegistry) PushRpcClient {
return PushRpcClient(*NewPush(discov))
}
// DelUserPushToken
func (p *PushRpcClient) DelUserPushToken(
ctx context.Context,
req *push.DelUserPushTokenReq,

@ -28,6 +28,7 @@ import (
"github.com/OpenIMSDK/Open-IM-Server/pkg/proto/third"
)
// Third
type Third struct {
conn grpc.ClientConnInterface
Client third.ThirdClient
@ -35,20 +36,22 @@ type Third struct {
MinioClient *minio.Client
}
// NewThird
func NewThird(discov discoveryregistry.SvcDiscoveryRegistry) *Third {
var minioClient *minio.Client
conn, err := discov.GetConn(context.Background(), config.Config.RpcRegisterName.OpenImThirdName)
if err != nil {
panic(err)
}
client := third.NewThirdClient(conn)
minioClient, err := minioInit()
minioClient, err = minioInit()
return &Third{discov: discov, Client: client, conn: conn, MinioClient: minioClient}
}
func minioInit() (*minio.Client, error) {
minioClient := &minio.Client{}
var initUrl string
initUrl = config.Config.Object.Minio.Endpoint
var minioClient *minio.Client
initUrl := config.Config.Object.Minio.Endpoint
minioUrl, err := url.Parse(initUrl)
if err != nil {
return nil, err
@ -66,5 +69,6 @@ func minioInit() (*minio.Client, error) {
if err != nil {
return nil, err
}
return minioClient, nil
}

@ -29,32 +29,39 @@ import (
"github.com/OpenIMSDK/Open-IM-Server/pkg/utils"
)
// User
type User struct {
conn grpc.ClientConnInterface
Client user.UserClient
Discov discoveryregistry.SvcDiscoveryRegistry
}
// NewUser
func NewUser(discov discoveryregistry.SvcDiscoveryRegistry) *User {
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}
}
type UserRpcClient User
// NewUserRpcClientByUser
func NewUserRpcClientByUser(user *User) *UserRpcClient {
rpc := UserRpcClient(*user)
return &rpc
}
// NewUserRpcClient
func NewUserRpcClient(client discoveryregistry.SvcDiscoveryRegistry) UserRpcClient {
return UserRpcClient(*NewUser(client))
}
// GetUsersInfo
func (u *UserRpcClient) GetUsersInfo(ctx context.Context, userIDs []string) ([]*sdkws.UserInfo, error) {
resp, err := u.Client.GetDesignateUsers(ctx, &user.GetDesignateUsersReq{
UserIDs: userIDs,
@ -67,27 +74,33 @@ func (u *UserRpcClient) GetUsersInfo(ctx context.Context, userIDs []string) ([]*
})); len(ids) > 0 {
return nil, errs.ErrUserIDNotFound.Wrap(strings.Join(ids, ","))
}
return resp.UsersInfo, nil
}
// GetUserInfo
func (u *UserRpcClient) GetUserInfo(ctx context.Context, userID string) (*sdkws.UserInfo, error) {
users, err := u.GetUsersInfo(ctx, []string{userID})
if err != nil {
return nil, err
}
return users[0], nil
}
// GetUsersInfoMap
func (u *UserRpcClient) GetUsersInfoMap(ctx context.Context, userIDs []string) (map[string]*sdkws.UserInfo, error) {
users, err := u.GetUsersInfo(ctx, userIDs)
if err != nil {
return nil, err
}
return utils.SliceToMap(users, func(e *sdkws.UserInfo) string {
return e.UserID
}), nil
}
// GetPublicUserInfos
func (u *UserRpcClient) GetPublicUserInfos(
ctx context.Context,
userIDs []string,
@ -97,6 +110,7 @@ func (u *UserRpcClient) GetPublicUserInfos(
if err != nil {
return nil, err
}
return utils.Slice(users, func(e *sdkws.UserInfo) *sdkws.PublicUserInfo {
return &sdkws.PublicUserInfo{
UserID: e.UserID,
@ -107,14 +121,17 @@ func (u *UserRpcClient) GetPublicUserInfos(
}), nil
}
// GetPublicUserInfo
func (u *UserRpcClient) GetPublicUserInfo(ctx context.Context, userID string) (*sdkws.PublicUserInfo, error) {
users, err := u.GetPublicUserInfos(ctx, []string{userID}, true)
if err != nil {
return nil, err
}
return users[0], nil
}
// GetPublicUserInfoMap
func (u *UserRpcClient) GetPublicUserInfoMap(
ctx context.Context,
userIDs []string,
@ -124,11 +141,13 @@ func (u *UserRpcClient) GetPublicUserInfoMap(
if err != nil {
return nil, err
}
return utils.SliceToMap(users, func(e *sdkws.PublicUserInfo) string {
return e.UserID
}), nil
}
// GetUserGlobalMsgRecvOpt
func (u *UserRpcClient) GetUserGlobalMsgRecvOpt(ctx context.Context, userID string) (int32, error) {
resp, err := u.Client.GetGlobalRecvMessageOpt(ctx, &user.GetGlobalRecvMessageOptReq{
UserID: userID,
@ -136,21 +155,26 @@ func (u *UserRpcClient) GetUserGlobalMsgRecvOpt(ctx context.Context, userID stri
if err != nil {
return 0, err
}
return resp.GlobalRecvMsgOpt, err
}
// Access
func (u *UserRpcClient) Access(ctx context.Context, ownerUserID string) error {
_, err := u.GetUserInfo(ctx, ownerUserID)
if err != nil {
return err
}
return tokenverify.CheckAccessV3(ctx, ownerUserID)
}
// GetAllUserIDs
func (u *UserRpcClient) GetAllUserIDs(ctx context.Context, pageNumber, showNumber int32) ([]string, error) {
resp, err := u.Client.GetAllUserID(ctx, &user.GetAllUserIDReq{Pagination: &sdkws.RequestPagination{PageNumber: pageNumber, ShowNumber: showNumber}})
if err != nil {
return nil, err
}
return resp.UserIDs, nil
}

@ -34,6 +34,7 @@ import (
"github.com/OpenIMSDK/Open-IM-Server/pkg/utils"
)
// Start
func Start(
rpcPort int,
rpcRegisterName string,
@ -108,5 +109,6 @@ func Start(
}
}
}()
return utils.Wrap1(srv.Serve(listener))
}

@ -21,6 +21,7 @@ import (
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/log"
)
// Statistics num
type Statistics struct {
AllCount *uint64
ModuleName string
@ -34,10 +35,12 @@ func (s *Statistics) output() {
defer t.Stop()
var sum uint64
var timeIntervalNum uint64
outputCh := make(chan struct{})
for {
sum = *s.AllCount
select {
case <-t.C:
outputCh <- struct{}{}
}
if *s.AllCount-sum <= 0 {
intervalCount = 0
@ -63,8 +66,10 @@ func (s *Statistics) output() {
}
}
// NewStatistics
func NewStatistics(allCount *uint64, moduleName, printArgs string, sleepTime int) *Statistics {
p := &Statistics{AllCount: allCount, ModuleName: moduleName, SleepTime: uint64(sleepTime), PrintArgs: printArgs}
go p.output()
return p
}

Loading…
Cancel
Save