From 9077b56df17e040dbc3edd478d8dbf6a86acd54a Mon Sep 17 00:00:00 2001 From: wenxu12345 <44203734@qq.com> Date: Tue, 8 Feb 2022 15:19:31 +0800 Subject: [PATCH] Refactor code --- config/config.yaml | 106 ++++++++++++------------- internal/rpc/msg/group_notification.go | 38 +++++++-- 2 files changed, 85 insertions(+), 59 deletions(-) diff --git a/config/config.yaml b/config/config.yaml index 65696d2ba..62ded8e46 100644 --- a/config/config.yaml +++ b/config/config.yaml @@ -179,7 +179,7 @@ notification: groupCreated: conversation: - reliabilityLevel: 1 + reliabilityLevel: 3 unreadCount: true offlinePush: switch: true @@ -191,111 +191,111 @@ notification: groupInfoSet: conversation: - reliabilityLevel: 1 - unreadCount: false + reliabilityLevel: 3 + unreadCount: true offlinePush: switch: false - title: "group info changed title" - desc: "group info changed desc" - ext: "group info changed ext" + title: "groupInfoSet title" + desc: "groupInfoSet desc" + ext: "groupInfoSet ext" defaultTips: - tips: "group info changed by" # group info changed by xx + tips: "modified the group profile" # group info changed by xx joinGroupApplication: conversation: - reliabilityLevel: 1 + reliabilityLevel: 2 unreadCount: false offlinePush: switch: false - title: "group info changed title" - desc: "group info changed desc" - ext: "group info changed ext" + title: "joinGroupApplication title" + desc: "joinGroupApplication desc" + ext: "joinGroupApplication ext" defaultTips: - tips: "group info changed by" # group info changed by xx + tips: "apply to join the group" # group info changed by xx memberQuit: conversation: - reliabilityLevel: 1 - unreadCount: false + reliabilityLevel: 3 + unreadCount: true offlinePush: switch: false - title: "group info changed title" - desc: "group info changed desc" - ext: "group info changed ext" + title: "memberQuit title" + desc: "memberQuit desc" + ext: "memberQuit ext" defaultTips: - tips: "group info changed by" # group info changed by xx + tips: "quit group chat" # group info changed by xx groupApplicationAccepted: conversation: - reliabilityLevel: 1 - unreadCount: false + reliabilityLevel: 3 + unreadCount: true offlinePush: switch: false - title: "group info changed title" - desc: "group info changed desc" - ext: "group info changed ext" + title: "groupApplicationAccepted title" + desc: "groupApplicationAccepted desc" + ext: "groupApplicationAccepted ext" defaultTips: - tips: "group info changed by" # group info changed by xx + tips: "was allowed to join the group" # group info changed by xx groupApplicationRejected: conversation: - reliabilityLevel: 1 + reliabilityLevel: 2 unreadCount: false offlinePush: switch: false - title: "group info changed title" - desc: "group info changed desc" - ext: "group info changed ext" + title: " title" + desc: " desc" + ext: " ext" defaultTips: - tips: "group info changed by" # group info changed by xx + tips: "was rejected into the group" # group info changed by xx groupOwnerTransferred: conversation: - reliabilityLevel: 1 - unreadCount: false + reliabilityLevel: 3 + unreadCount: true offlinePush: switch: false - title: "group info changed title" - desc: "group info changed desc" - ext: "group info changed ext" + title: "groupOwnerTransferred title" + desc: "groupOwnerTransferred desc" + ext: "groupOwnerTransferred ext" defaultTips: - tips: "group info changed by" # group info changed by xx + tips: "become a new group owner" # group info changed by xx memberKicked: conversation: - reliabilityLevel: 1 - unreadCount: false + reliabilityLevel: 3 + unreadCount: true offlinePush: switch: false - title: "group info changed title" - desc: "group info changed desc" - ext: "group info changed ext" + title: "memberKicked title" + desc: "memberKicked desc" + ext: "memberKicked ext" defaultTips: - tips: "group info changed by" # group info changed by xx + tips: "was kicked out of the group" # group info changed by xx memberInvited: conversation: - reliabilityLevel: 1 - unreadCount: false + reliabilityLevel: 3 + unreadCount: true offlinePush: switch: false - title: "group info changed title" - desc: "group info changed desc" - ext: "group info changed ext" + title: "memberInvited title" + desc: "memberInvited desc" + ext: "memberInvited ext" defaultTips: - tips: "group info changed by" # group info changed by xx + tips: "was invited into the group" # group info changed by xx memberEnter: conversation: - reliabilityLevel: 1 - unreadCount: false + reliabilityLevel: 3 + unreadCount: true offlinePush: switch: false - title: "group info changed title" - desc: "group info changed desc" - ext: "group info changed ext" + title: "memberEnter title" + desc: "memberEnter desc" + ext: "memberEnter ext" defaultTips: - tips: "group info changed by" # group info changed by xx + tips: "entered the group" # group info changed by xx #############################friend################################# diff --git a/internal/rpc/msg/group_notification.go b/internal/rpc/msg/group_notification.go index f9c428d18..511886ffa 100644 --- a/internal/rpc/msg/group_notification.go +++ b/internal/rpc/msg/group_notification.go @@ -94,18 +94,44 @@ func groupNotification(contentType int32, m proto.Message, sendID, groupID, recv return } + from, err := imdb.GetUserByUserID(sendID) + if err != nil { + log.Error(operationID, "GetUserByUserID failed ", err.Error()) + } + nickname := "" + if from != nil { + nickname = from.Nickname + } + + to, err := imdb.GetUserByUserID(recvUserID) + if err != nil { + log.Error(operationID, "GetUserByUserID failed ", err.Error()) + } + toNickname := "" + if from != nil { + toNickname = to.Nickname + } + cn := config.Config.Notification switch contentType { case constant.GroupCreatedNotification: - tips.DefaultTips = cn.GroupCreated.DefaultTips.Tips + tips.DefaultTips = nickname + " " + cn.GroupCreated.DefaultTips.Tips case constant.GroupInfoSetNotification: + tips.DefaultTips = nickname + " " + cn.GroupInfoSet.DefaultTips.Tips case constant.JoinGroupApplicationNotification: + tips.DefaultTips = nickname + " " + cn.JoinGroupApplication.DefaultTips.Tips case constant.MemberQuitNotification: - case constant.GroupApplicationAcceptedNotification: - case constant.GroupApplicationRejectedNotification: - case constant.GroupOwnerTransferredNotification: - case constant.MemberKickedNotification: - case constant.MemberInvitedNotification: + tips.DefaultTips = nickname + " " + cn.MemberQuit.DefaultTips.Tips + case constant.GroupApplicationAcceptedNotification: // + tips.DefaultTips = toNickname + " " + cn.GroupApplicationAccepted.DefaultTips.Tips + case constant.GroupApplicationRejectedNotification: // + tips.DefaultTips = toNickname + " " + cn.GroupApplicationRejected.DefaultTips.Tips + case constant.GroupOwnerTransferredNotification: // + tips.DefaultTips = toNickname + " " + cn.GroupOwnerTransferred.DefaultTips.Tips + case constant.MemberKickedNotification: // + tips.DefaultTips = toNickname + " " + cn.MemberKicked.DefaultTips.Tips + case constant.MemberInvitedNotification: // + tips.DefaultTips = toNickname + " " + cn.MemberInvited.DefaultTips.Tips default: log.Error(operationID, "contentType failed ", contentType) return