mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-10-26 05:02:11 +08:00
update notification logic.
This commit is contained in:
parent
a96e8c28c4
commit
789136d5e8
@ -16,6 +16,7 @@ package group
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
pbgroup "github.com/openimsdk/protocol/group"
|
pbgroup "github.com/openimsdk/protocol/group"
|
||||||
@ -55,41 +56,56 @@ func UpdateGroupInfoMap(ctx context.Context, group *sdkws.GroupInfoForSet) map[s
|
|||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
|
|
||||||
func UpdateGroupInfoExMap(ctx context.Context, group *pbgroup.SetGroupInfoExReq) (map[string]any, error) {
|
func UpdateGroupInfoExMap(ctx context.Context, group *pbgroup.SetGroupInfoExReq) (m map[string]any, normalFlag, groupNameFlag, notificationFlag bool, err error) {
|
||||||
m := make(map[string]any)
|
m = make(map[string]any)
|
||||||
|
|
||||||
if group.GroupName != nil {
|
if group.GroupName != nil {
|
||||||
if group.GroupName.Value != "" {
|
if strings.TrimSpace(group.GroupName.Value) != "" {
|
||||||
m["group_name"] = group.GroupName.Value
|
m["group_name"] = group.GroupName.Value
|
||||||
|
groupNameFlag = true
|
||||||
} else {
|
} else {
|
||||||
return nil, errs.ErrArgs.WrapMsg("group name is empty")
|
return nil, normalFlag, notificationFlag, groupNameFlag, errs.ErrArgs.WrapMsg("group name is empty")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if group.Notification != nil {
|
if group.Notification != nil {
|
||||||
m["notification"] = group.Notification.Value
|
// if Notification only contains spaces, set it to empty string
|
||||||
m["notification_update_time"] = time.Now()
|
if strings.TrimSpace(group.Notification.Value) != "" {
|
||||||
|
m["notification"] = group.Notification.Value
|
||||||
|
notificationFlag = true
|
||||||
|
} else {
|
||||||
|
m["notification"] = ""
|
||||||
|
normalFlag = true
|
||||||
|
}
|
||||||
m["notification_user_id"] = mcontext.GetOpUserID(ctx)
|
m["notification_user_id"] = mcontext.GetOpUserID(ctx)
|
||||||
|
m["notification_update_time"] = time.Now()
|
||||||
}
|
}
|
||||||
if group.Introduction != nil {
|
if group.Introduction != nil {
|
||||||
m["introduction"] = group.Introduction.Value
|
m["introduction"] = group.Introduction.Value
|
||||||
|
normalFlag = true
|
||||||
}
|
}
|
||||||
if group.FaceURL != nil {
|
if group.FaceURL != nil {
|
||||||
m["face_url"] = group.FaceURL.Value
|
m["face_url"] = group.FaceURL.Value
|
||||||
|
normalFlag = true
|
||||||
}
|
}
|
||||||
if group.NeedVerification != nil {
|
if group.NeedVerification != nil {
|
||||||
m["need_verification"] = group.NeedVerification.Value
|
m["need_verification"] = group.NeedVerification.Value
|
||||||
|
normalFlag = true
|
||||||
}
|
}
|
||||||
if group.LookMemberInfo != nil {
|
if group.LookMemberInfo != nil {
|
||||||
m["look_member_info"] = group.LookMemberInfo.Value
|
m["look_member_info"] = group.LookMemberInfo.Value
|
||||||
|
normalFlag = true
|
||||||
}
|
}
|
||||||
if group.ApplyMemberFriend != nil {
|
if group.ApplyMemberFriend != nil {
|
||||||
m["apply_member_friend"] = group.ApplyMemberFriend.Value
|
m["apply_member_friend"] = group.ApplyMemberFriend.Value
|
||||||
|
normalFlag = true
|
||||||
}
|
}
|
||||||
if group.Ex != nil {
|
if group.Ex != nil {
|
||||||
m["ex"] = group.Ex.Value
|
m["ex"] = group.Ex.Value
|
||||||
|
normalFlag = true
|
||||||
}
|
}
|
||||||
|
|
||||||
return m, nil
|
return m, normalFlag, groupNameFlag, notificationFlag, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func UpdateGroupStatusMap(status int) map[string]any {
|
func UpdateGroupStatusMap(status int) map[string]any {
|
||||||
|
|||||||
@ -1087,12 +1087,7 @@ func (g *groupServer) SetGroupInfoEx(ctx context.Context, req *pbgroup.SetGroupI
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// if Notification only contains spaces, set it to empty string
|
updatedData, normalFlag, groupNameFlag, notificationFlag, err := UpdateGroupInfoExMap(ctx, req)
|
||||||
if strings.TrimSpace(req.Notification.Value) == "" {
|
|
||||||
req.Notification.Value = ""
|
|
||||||
}
|
|
||||||
|
|
||||||
updatedData, err := UpdateGroupInfoExMap(ctx, req)
|
|
||||||
if len(updatedData) == 0 {
|
if len(updatedData) == 0 {
|
||||||
return &pbgroup.SetGroupInfoExResp{}, nil
|
return &pbgroup.SetGroupInfoExResp{}, nil
|
||||||
}
|
}
|
||||||
@ -1120,43 +1115,35 @@ func (g *groupServer) SetGroupInfoEx(ctx context.Context, req *pbgroup.SetGroupI
|
|||||||
tips.OpUser = g.groupMemberDB2PB(opMember, 0)
|
tips.OpUser = g.groupMemberDB2PB(opMember, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
// num is len of updatedData, use for the different type of notification
|
if notificationFlag {
|
||||||
num := len(updatedData)
|
func() {
|
||||||
|
conversation := &pbconv.ConversationReq{
|
||||||
|
ConversationID: msgprocessor.GetConversationIDBySessionType(constant.ReadGroupChatType, req.GroupID),
|
||||||
|
ConversationType: constant.ReadGroupChatType,
|
||||||
|
GroupID: req.GroupID,
|
||||||
|
}
|
||||||
|
|
||||||
if req.Notification != nil {
|
resp, err := g.GetGroupMemberUserIDs(ctx, &pbgroup.GetGroupMemberUserIDsReq{GroupID: req.GroupID})
|
||||||
if req.Notification.Value != "" {
|
if err != nil {
|
||||||
num -= 3
|
log.ZWarn(ctx, "GetGroupMemberIDs is failed.", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
func() {
|
conversation.GroupAtType = &wrapperspb.Int32Value{Value: constant.GroupNotification}
|
||||||
conversation := &pbconv.ConversationReq{
|
if err := g.conversationClient.SetConversations(ctx, resp.UserIDs, conversation); err != nil {
|
||||||
ConversationID: msgprocessor.GetConversationIDBySessionType(constant.ReadGroupChatType, req.GroupID),
|
log.ZWarn(ctx, "SetConversations", err, "UserIDs", resp.UserIDs, "conversation", conversation)
|
||||||
ConversationType: constant.ReadGroupChatType,
|
}
|
||||||
GroupID: req.GroupID,
|
}()
|
||||||
}
|
|
||||||
|
|
||||||
resp, err := g.GetGroupMemberUserIDs(ctx, &pbgroup.GetGroupMemberUserIDsReq{GroupID: req.GroupID})
|
g.notification.GroupInfoSetAnnouncementNotification(ctx, &sdkws.GroupInfoSetAnnouncementTips{Group: tips.Group, OpUser: tips.OpUser})
|
||||||
if err != nil {
|
|
||||||
log.ZWarn(ctx, "GetGroupMemberIDs is failed.", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
conversation.GroupAtType = &wrapperspb.Int32Value{Value: constant.GroupNotification}
|
|
||||||
if err := g.conversationClient.SetConversations(ctx, resp.UserIDs, conversation); err != nil {
|
|
||||||
log.ZWarn(ctx, "SetConversations", err, "UserIDs", resp.UserIDs, "conversation", conversation)
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
g.notification.GroupInfoSetAnnouncementNotification(ctx, &sdkws.GroupInfoSetAnnouncementTips{Group: tips.Group, OpUser: tips.OpUser})
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if req.GroupName != nil {
|
if groupNameFlag {
|
||||||
num--
|
|
||||||
g.notification.GroupInfoSetNameNotification(ctx, &sdkws.GroupInfoSetNameTips{Group: tips.Group, OpUser: tips.OpUser})
|
g.notification.GroupInfoSetNameNotification(ctx, &sdkws.GroupInfoSetNameTips{Group: tips.Group, OpUser: tips.OpUser})
|
||||||
}
|
}
|
||||||
|
|
||||||
// if num > 0, send the normal notification
|
// if updatedData > 0, send the normal notification
|
||||||
if num > 0 {
|
if normalFlag {
|
||||||
g.notification.GroupInfoSetNotification(ctx, tips)
|
g.notification.GroupInfoSetNotification(ctx, tips)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user