|
|
@ -17,6 +17,9 @@ package notification
|
|
|
|
import (
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/openimsdk/open-im-server/v3/pkg/common/servererrs"
|
|
|
|
|
|
|
|
"github.com/openimsdk/tools/utils/datautil"
|
|
|
|
|
|
|
|
"github.com/openimsdk/tools/utils/stringutil"
|
|
|
|
|
|
|
|
|
|
|
|
"github.com/openimsdk/open-im-server/v3/pkg/authverify"
|
|
|
|
"github.com/openimsdk/open-im-server/v3/pkg/authverify"
|
|
|
|
"github.com/openimsdk/open-im-server/v3/pkg/common/config"
|
|
|
|
"github.com/openimsdk/open-im-server/v3/pkg/common/config"
|
|
|
@ -29,7 +32,6 @@ import (
|
|
|
|
"github.com/openimsdk/tools/errs"
|
|
|
|
"github.com/openimsdk/tools/errs"
|
|
|
|
"github.com/openimsdk/tools/log"
|
|
|
|
"github.com/openimsdk/tools/log"
|
|
|
|
"github.com/openimsdk/tools/mcontext"
|
|
|
|
"github.com/openimsdk/tools/mcontext"
|
|
|
|
"github.com/openimsdk/tools/utils"
|
|
|
|
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
func NewGroupNotificationSender(db controller.GroupDatabase, msgRpcClient *rpcclient.MessageRpcClient, userRpcClient *rpcclient.UserRpcClient, config *config.GlobalConfig, fn func(ctx context.Context, userIDs []string) ([]CommonUser, error)) *GroupNotificationSender {
|
|
|
|
func NewGroupNotificationSender(db controller.GroupDatabase, msgRpcClient *rpcclient.MessageRpcClient, userRpcClient *rpcclient.UserRpcClient, config *config.GlobalConfig, fn func(ctx context.Context, userIDs []string) ([]CommonUser, error)) *GroupNotificationSender {
|
|
|
@ -59,7 +61,7 @@ func (g *GroupNotificationSender) PopulateGroupMember(ctx context.Context, membe
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if len(emptyUserIDs) > 0 {
|
|
|
|
if len(emptyUserIDs) > 0 {
|
|
|
|
users, err := g.getUsersInfo(ctx, utils.Keys(emptyUserIDs))
|
|
|
|
users, err := g.getUsersInfo(ctx, datautil.Keys(emptyUserIDs))
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -89,7 +91,7 @@ func (g *GroupNotificationSender) getUser(ctx context.Context, userID string) (*
|
|
|
|
return nil, err
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if len(users) == 0 {
|
|
|
|
if len(users) == 0 {
|
|
|
|
return nil, errs.ErrUserIDNotFound.WrapMsg(fmt.Sprintf("user %s not found", userID))
|
|
|
|
return nil, servererrs.ErrUserIDNotFound.WrapMsg(fmt.Sprintf("user %s not found", userID))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return &sdkws.PublicUserInfo{
|
|
|
|
return &sdkws.PublicUserInfo{
|
|
|
|
UserID: users[0].GetUserID(),
|
|
|
|
UserID: users[0].GetUserID(),
|
|
|
@ -185,7 +187,7 @@ func (g *GroupNotificationSender) getGroupOwnerAndAdminUserID(ctx context.Contex
|
|
|
|
return nil, err
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fn := func(e *relation.GroupMemberModel) string { return e.UserID }
|
|
|
|
fn := func(e *relation.GroupMemberModel) string { return e.UserID }
|
|
|
|
return utils.Slice(members, fn), nil
|
|
|
|
return datautil.Slice(members, fn), nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//nolint:unused
|
|
|
|
//nolint:unused
|
|
|
@ -289,7 +291,7 @@ func (g *GroupNotificationSender) GroupCreatedNotification(ctx context.Context,
|
|
|
|
defer log.ZDebug(ctx, "return")
|
|
|
|
defer log.ZDebug(ctx, "return")
|
|
|
|
defer func() {
|
|
|
|
defer func() {
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
log.ZError(ctx, utils.GetFuncName(1)+" failed", err)
|
|
|
|
log.ZError(ctx, stringutil.GetFuncName(1)+" failed", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
}()
|
|
|
|
if err := g.fillOpUser(ctx, &tips.OpUser, tips.Group.GroupID); err != nil {
|
|
|
|
if err := g.fillOpUser(ctx, &tips.OpUser, tips.Group.GroupID); err != nil {
|
|
|
@ -302,7 +304,7 @@ func (g *GroupNotificationSender) GroupInfoSetNotification(ctx context.Context,
|
|
|
|
defer log.ZDebug(ctx, "return")
|
|
|
|
defer log.ZDebug(ctx, "return")
|
|
|
|
defer func() {
|
|
|
|
defer func() {
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
log.ZError(ctx, utils.GetFuncName(1)+" failed", err)
|
|
|
|
log.ZError(ctx, stringutil.GetFuncName(1)+" failed", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
}()
|
|
|
|
if err := g.fillOpUser(ctx, &tips.OpUser, tips.Group.GroupID); err != nil {
|
|
|
|
if err := g.fillOpUser(ctx, &tips.OpUser, tips.Group.GroupID); err != nil {
|
|
|
@ -315,7 +317,7 @@ func (g *GroupNotificationSender) GroupInfoSetNameNotification(ctx context.Conte
|
|
|
|
defer log.ZDebug(ctx, "return")
|
|
|
|
defer log.ZDebug(ctx, "return")
|
|
|
|
defer func() {
|
|
|
|
defer func() {
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
log.ZError(ctx, utils.GetFuncName(1)+" failed", err)
|
|
|
|
log.ZError(ctx, stringutil.GetFuncName(1)+" failed", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
}()
|
|
|
|
if err := g.fillOpUser(ctx, &tips.OpUser, tips.Group.GroupID); err != nil {
|
|
|
|
if err := g.fillOpUser(ctx, &tips.OpUser, tips.Group.GroupID); err != nil {
|
|
|
@ -328,7 +330,7 @@ func (g *GroupNotificationSender) GroupInfoSetAnnouncementNotification(ctx conte
|
|
|
|
defer log.ZDebug(ctx, "return")
|
|
|
|
defer log.ZDebug(ctx, "return")
|
|
|
|
defer func() {
|
|
|
|
defer func() {
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
log.ZError(ctx, utils.GetFuncName(1)+" failed", err)
|
|
|
|
log.ZError(ctx, stringutil.GetFuncName(1)+" failed", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
}()
|
|
|
|
if err := g.fillOpUser(ctx, &tips.OpUser, tips.Group.GroupID); err != nil {
|
|
|
|
if err := g.fillOpUser(ctx, &tips.OpUser, tips.Group.GroupID); err != nil {
|
|
|
@ -341,7 +343,7 @@ func (g *GroupNotificationSender) JoinGroupApplicationNotification(ctx context.C
|
|
|
|
defer log.ZDebug(ctx, "return")
|
|
|
|
defer log.ZDebug(ctx, "return")
|
|
|
|
defer func() {
|
|
|
|
defer func() {
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
log.ZError(ctx, utils.GetFuncName(1)+" failed", err)
|
|
|
|
log.ZError(ctx, stringutil.GetFuncName(1)+" failed", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
}()
|
|
|
|
group, err := g.getGroupInfo(ctx, req.GroupID)
|
|
|
|
group, err := g.getGroupInfo(ctx, req.GroupID)
|
|
|
@ -358,7 +360,7 @@ func (g *GroupNotificationSender) JoinGroupApplicationNotification(ctx context.C
|
|
|
|
}
|
|
|
|
}
|
|
|
|
userIDs = append(userIDs, req.InviterUserID, mcontext.GetOpUserID(ctx))
|
|
|
|
userIDs = append(userIDs, req.InviterUserID, mcontext.GetOpUserID(ctx))
|
|
|
|
tips := &sdkws.JoinGroupApplicationTips{Group: group, Applicant: user, ReqMsg: req.ReqMessage}
|
|
|
|
tips := &sdkws.JoinGroupApplicationTips{Group: group, Applicant: user, ReqMsg: req.ReqMessage}
|
|
|
|
for _, userID := range utils.Distinct(userIDs) {
|
|
|
|
for _, userID := range datautil.Distinct(userIDs) {
|
|
|
|
err = g.Notification(ctx, mcontext.GetOpUserID(ctx), userID, constant.JoinGroupApplicationNotification, tips)
|
|
|
|
err = g.Notification(ctx, mcontext.GetOpUserID(ctx), userID, constant.JoinGroupApplicationNotification, tips)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
log.ZError(ctx, "JoinGroupApplicationNotification failed", err, "group", req.GroupID, "userID", userID)
|
|
|
|
log.ZError(ctx, "JoinGroupApplicationNotification failed", err, "group", req.GroupID, "userID", userID)
|
|
|
@ -371,7 +373,7 @@ func (g *GroupNotificationSender) MemberQuitNotification(ctx context.Context, me
|
|
|
|
defer log.ZDebug(ctx, "return")
|
|
|
|
defer log.ZDebug(ctx, "return")
|
|
|
|
defer func() {
|
|
|
|
defer func() {
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
log.ZError(ctx, utils.GetFuncName(1)+" failed", err)
|
|
|
|
log.ZError(ctx, stringutil.GetFuncName(1)+" failed", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
}()
|
|
|
|
group, err := g.getGroupInfo(ctx, member.GroupID)
|
|
|
|
group, err := g.getGroupInfo(ctx, member.GroupID)
|
|
|
@ -386,7 +388,7 @@ func (g *GroupNotificationSender) GroupApplicationAcceptedNotification(ctx conte
|
|
|
|
defer log.ZDebug(ctx, "return")
|
|
|
|
defer log.ZDebug(ctx, "return")
|
|
|
|
defer func() {
|
|
|
|
defer func() {
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
log.ZError(ctx, utils.GetFuncName(1)+" failed", err)
|
|
|
|
log.ZError(ctx, stringutil.GetFuncName(1)+" failed", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
}()
|
|
|
|
group, err := g.getGroupInfo(ctx, req.GroupID)
|
|
|
|
group, err := g.getGroupInfo(ctx, req.GroupID)
|
|
|
@ -419,7 +421,7 @@ func (g *GroupNotificationSender) GroupApplicationRejectedNotification(ctx conte
|
|
|
|
defer log.ZDebug(ctx, "return")
|
|
|
|
defer log.ZDebug(ctx, "return")
|
|
|
|
defer func() {
|
|
|
|
defer func() {
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
log.ZError(ctx, utils.GetFuncName(1)+" failed", err)
|
|
|
|
log.ZError(ctx, stringutil.GetFuncName(1)+" failed", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
}()
|
|
|
|
group, err := g.getGroupInfo(ctx, req.GroupID)
|
|
|
|
group, err := g.getGroupInfo(ctx, req.GroupID)
|
|
|
@ -452,7 +454,7 @@ func (g *GroupNotificationSender) GroupOwnerTransferredNotification(ctx context.
|
|
|
|
defer log.ZDebug(ctx, "return")
|
|
|
|
defer log.ZDebug(ctx, "return")
|
|
|
|
defer func() {
|
|
|
|
defer func() {
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
log.ZError(ctx, utils.GetFuncName(1)+" failed", err)
|
|
|
|
log.ZError(ctx, stringutil.GetFuncName(1)+" failed", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
}()
|
|
|
|
group, err := g.getGroupInfo(ctx, req.GroupID)
|
|
|
|
group, err := g.getGroupInfo(ctx, req.GroupID)
|
|
|
@ -475,7 +477,7 @@ func (g *GroupNotificationSender) MemberKickedNotification(ctx context.Context,
|
|
|
|
defer log.ZDebug(ctx, "return")
|
|
|
|
defer log.ZDebug(ctx, "return")
|
|
|
|
defer func() {
|
|
|
|
defer func() {
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
log.ZError(ctx, utils.GetFuncName(1)+" failed", err)
|
|
|
|
log.ZError(ctx, stringutil.GetFuncName(1)+" failed", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
}()
|
|
|
|
if err := g.fillOpUser(ctx, &tips.OpUser, tips.Group.GroupID); err != nil {
|
|
|
|
if err := g.fillOpUser(ctx, &tips.OpUser, tips.Group.GroupID); err != nil {
|
|
|
@ -488,7 +490,7 @@ func (g *GroupNotificationSender) MemberInvitedNotification(ctx context.Context,
|
|
|
|
defer log.ZDebug(ctx, "return")
|
|
|
|
defer log.ZDebug(ctx, "return")
|
|
|
|
defer func() {
|
|
|
|
defer func() {
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
log.ZError(ctx, utils.GetFuncName(1)+" failed", err)
|
|
|
|
log.ZError(ctx, stringutil.GetFuncName(1)+" failed", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
}()
|
|
|
|
group, err := g.getGroupInfo(ctx, groupID)
|
|
|
|
group, err := g.getGroupInfo(ctx, groupID)
|
|
|
@ -513,7 +515,7 @@ func (g *GroupNotificationSender) MemberEnterNotification(ctx context.Context, g
|
|
|
|
defer log.ZDebug(ctx, "return")
|
|
|
|
defer log.ZDebug(ctx, "return")
|
|
|
|
defer func() {
|
|
|
|
defer func() {
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
log.ZError(ctx, utils.GetFuncName(1)+" failed", err)
|
|
|
|
log.ZError(ctx, stringutil.GetFuncName(1)+" failed", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
}()
|
|
|
|
group, err := g.getGroupInfo(ctx, groupID)
|
|
|
|
group, err := g.getGroupInfo(ctx, groupID)
|
|
|
@ -532,7 +534,7 @@ func (g *GroupNotificationSender) GroupDismissedNotification(ctx context.Context
|
|
|
|
defer log.ZDebug(ctx, "return")
|
|
|
|
defer log.ZDebug(ctx, "return")
|
|
|
|
defer func() {
|
|
|
|
defer func() {
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
log.ZError(ctx, utils.GetFuncName(1)+" failed", err)
|
|
|
|
log.ZError(ctx, stringutil.GetFuncName(1)+" failed", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
}()
|
|
|
|
if err := g.fillOpUser(ctx, &tips.OpUser, tips.Group.GroupID); err != nil {
|
|
|
|
if err := g.fillOpUser(ctx, &tips.OpUser, tips.Group.GroupID); err != nil {
|
|
|
@ -545,7 +547,7 @@ func (g *GroupNotificationSender) GroupMemberMutedNotification(ctx context.Conte
|
|
|
|
defer log.ZDebug(ctx, "return")
|
|
|
|
defer log.ZDebug(ctx, "return")
|
|
|
|
defer func() {
|
|
|
|
defer func() {
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
log.ZError(ctx, utils.GetFuncName(1)+" failed", err)
|
|
|
|
log.ZError(ctx, stringutil.GetFuncName(1)+" failed", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
}()
|
|
|
|
group, err := g.getGroupInfo(ctx, groupID)
|
|
|
|
group, err := g.getGroupInfo(ctx, groupID)
|
|
|
@ -570,7 +572,7 @@ func (g *GroupNotificationSender) GroupMemberCancelMutedNotification(ctx context
|
|
|
|
defer log.ZDebug(ctx, "return")
|
|
|
|
defer log.ZDebug(ctx, "return")
|
|
|
|
defer func() {
|
|
|
|
defer func() {
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
log.ZError(ctx, utils.GetFuncName(1)+" failed", err)
|
|
|
|
log.ZError(ctx, stringutil.GetFuncName(1)+" failed", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
}()
|
|
|
|
group, err := g.getGroupInfo(ctx, groupID)
|
|
|
|
group, err := g.getGroupInfo(ctx, groupID)
|
|
|
@ -592,7 +594,7 @@ func (g *GroupNotificationSender) GroupMutedNotification(ctx context.Context, gr
|
|
|
|
defer log.ZDebug(ctx, "return")
|
|
|
|
defer log.ZDebug(ctx, "return")
|
|
|
|
defer func() {
|
|
|
|
defer func() {
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
log.ZError(ctx, utils.GetFuncName(1)+" failed", err)
|
|
|
|
log.ZError(ctx, stringutil.GetFuncName(1)+" failed", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
}()
|
|
|
|
group, err := g.getGroupInfo(ctx, groupID)
|
|
|
|
group, err := g.getGroupInfo(ctx, groupID)
|
|
|
@ -617,7 +619,7 @@ func (g *GroupNotificationSender) GroupCancelMutedNotification(ctx context.Conte
|
|
|
|
defer log.ZDebug(ctx, "return")
|
|
|
|
defer log.ZDebug(ctx, "return")
|
|
|
|
defer func() {
|
|
|
|
defer func() {
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
log.ZError(ctx, utils.GetFuncName(1)+" failed", err)
|
|
|
|
log.ZError(ctx, stringutil.GetFuncName(1)+" failed", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
}()
|
|
|
|
group, err := g.getGroupInfo(ctx, groupID)
|
|
|
|
group, err := g.getGroupInfo(ctx, groupID)
|
|
|
@ -674,7 +676,7 @@ func (g *GroupNotificationSender) GroupMemberSetToOrdinaryUserNotification(ctx c
|
|
|
|
defer log.ZDebug(ctx, "return")
|
|
|
|
defer log.ZDebug(ctx, "return")
|
|
|
|
defer func() {
|
|
|
|
defer func() {
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
log.ZError(ctx, utils.GetFuncName(1)+" failed", err)
|
|
|
|
log.ZError(ctx, stringutil.GetFuncName(1)+" failed", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
}()
|
|
|
|
group, err := g.getGroupInfo(ctx, groupID)
|
|
|
|
group, err := g.getGroupInfo(ctx, groupID)
|
|
|
@ -696,7 +698,7 @@ func (g *GroupNotificationSender) SuperGroupNotification(ctx context.Context, se
|
|
|
|
defer log.ZDebug(ctx, "return")
|
|
|
|
defer log.ZDebug(ctx, "return")
|
|
|
|
defer func() {
|
|
|
|
defer func() {
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
log.ZError(ctx, utils.GetFuncName(1)+" failed", err)
|
|
|
|
log.ZError(ctx, stringutil.GetFuncName(1)+" failed", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
}()
|
|
|
|
err = g.Notification(ctx, sendID, recvID, constant.SuperGroupUpdateNotification, nil)
|
|
|
|
err = g.Notification(ctx, sendID, recvID, constant.SuperGroupUpdateNotification, nil)
|
|
|
|