From 6c7c5dea7b0cc484c183b14b35fde16a25f6d850 Mon Sep 17 00:00:00 2001 From: withchao <993506633@qq.com> Date: Fri, 26 May 2023 18:52:47 +0800 Subject: [PATCH 1/3] RevokeMsg --- internal/rpc/msg/revoke.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/rpc/msg/revoke.go b/internal/rpc/msg/revoke.go index 45a8841d8..97520350b 100644 --- a/internal/rpc/msg/revoke.go +++ b/internal/rpc/msg/revoke.go @@ -110,7 +110,7 @@ func (m *msgServer) RevokeMsg(ctx context.Context, req *msg.RevokeMsgReq) (*msg. CreateTime: utils.GetCurrentTimestampByMill(), ClientMsgID: utils.GetMsgID(req.UserID), Options: config.GetOptionsByNotification(config.NotificationConf{ - IsSendMsg: true, + IsSendMsg: false, ReliabilityLevel: 2, }), OfflinePushInfo: nil, From 8b31f676c2765e1a172239b20894b299fbb03af1 Mon Sep 17 00:00:00 2001 From: withchao <993506633@qq.com> Date: Fri, 26 May 2023 19:47:57 +0800 Subject: [PATCH 2/3] RevokeMsg --- pkg/common/convert/msg.go | 38 ++++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/pkg/common/convert/msg.go b/pkg/common/convert/msg.go index a9dd3add3..c8b8a6625 100644 --- a/pkg/common/convert/msg.go +++ b/pkg/common/convert/msg.go @@ -5,7 +5,10 @@ import ( "github.com/OpenIMSDK/Open-IM-Server/pkg/proto/sdkws" ) -func MsgPb2DB(msg *sdkws.MsgData) unrelation.MsgDataModel { +func MsgPb2DB(msg *sdkws.MsgData) *unrelation.MsgDataModel { + if msg == nil { + return nil + } var msgDataModel unrelation.MsgDataModel msgDataModel.SendID = msg.SendID msgDataModel.RecvID = msg.RecvID @@ -24,21 +27,26 @@ func MsgPb2DB(msg *sdkws.MsgData) unrelation.MsgDataModel { msgDataModel.CreateTime = msg.CreateTime msgDataModel.Status = msg.Status msgDataModel.Options = msg.Options - msgDataModel.OfflinePush = &unrelation.OfflinePushModel{ - Title: msg.OfflinePushInfo.Title, - Desc: msg.OfflinePushInfo.Desc, - Ex: msg.OfflinePushInfo.Ex, - IOSPushSound: msg.OfflinePushInfo.IOSPushSound, - IOSBadgeCount: msg.OfflinePushInfo.IOSBadgeCount, + if msg.OfflinePushInfo != nil { + msgDataModel.OfflinePush = &unrelation.OfflinePushModel{ + Title: msg.OfflinePushInfo.Title, + Desc: msg.OfflinePushInfo.Desc, + Ex: msg.OfflinePushInfo.Ex, + IOSPushSound: msg.OfflinePushInfo.IOSPushSound, + IOSBadgeCount: msg.OfflinePushInfo.IOSBadgeCount, + } } msgDataModel.AtUserIDList = msg.AtUserIDList msgDataModel.AttachedInfo = msg.AttachedInfo msgDataModel.Ex = msg.Ex - return msgDataModel + return &msgDataModel } func MsgDB2Pb(msgModel *unrelation.MsgDataModel) *sdkws.MsgData { + if msgModel == nil { + return nil + } var msg sdkws.MsgData msg.SendID = msgModel.SendID msg.RecvID = msgModel.RecvID @@ -57,12 +65,14 @@ func MsgDB2Pb(msgModel *unrelation.MsgDataModel) *sdkws.MsgData { msg.CreateTime = msgModel.CreateTime msg.Status = msgModel.Status msg.Options = msgModel.Options - msg.OfflinePushInfo = &sdkws.OfflinePushInfo{ - Title: msgModel.OfflinePush.Title, - Desc: msgModel.OfflinePush.Desc, - Ex: msgModel.OfflinePush.Ex, - IOSPushSound: msgModel.OfflinePush.IOSPushSound, - IOSBadgeCount: msgModel.OfflinePush.IOSBadgeCount, + if msgModel.OfflinePush != nil { + msg.OfflinePushInfo = &sdkws.OfflinePushInfo{ + Title: msgModel.OfflinePush.Title, + Desc: msgModel.OfflinePush.Desc, + Ex: msgModel.OfflinePush.Ex, + IOSPushSound: msgModel.OfflinePush.IOSPushSound, + IOSBadgeCount: msgModel.OfflinePush.IOSBadgeCount, + } } msg.AtUserIDList = msgModel.AtUserIDList msg.AttachedInfo = msgModel.AttachedInfo From 4d7b49aa1f2461eb72f0c3ae6ee0c4348b6002c1 Mon Sep 17 00:00:00 2001 From: withchao <993506633@qq.com> Date: Fri, 26 May 2023 20:34:46 +0800 Subject: [PATCH 3/3] RevokeMsg --- internal/rpc/msg/revoke.go | 68 +++++++++++++++++++------------------- 1 file changed, 34 insertions(+), 34 deletions(-) diff --git a/internal/rpc/msg/revoke.go b/internal/rpc/msg/revoke.go index 97520350b..b4cc06b6a 100644 --- a/internal/rpc/msg/revoke.go +++ b/internal/rpc/msg/revoke.go @@ -18,15 +18,9 @@ import ( func (m *msgServer) RevokeMsg(ctx context.Context, req *msg.RevokeMsgReq) (*msg.RevokeMsgResp, error) { defer log.ZInfo(ctx, "RevokeMsg return line") - //if req.UserID == "" { - // return nil, errs.ErrArgs.Wrap("user_id is empty") - //} - //if req.RecvID == "" && req.GroupID == "" { - // return nil, errs.ErrArgs.Wrap("recv_id and group_id are empty") - //} - //if req.RecvID != "" && req.GroupID != "" { - // return nil, errs.ErrArgs.Wrap("recv_id and group_id cannot exist at the same time") - //} + if req.UserID == "" { + return nil, errs.ErrArgs.Wrap("user_id is empty") + } if req.ConversationID == "" { return nil, errs.ErrArgs.Wrap("conversation_id is empty") } @@ -47,33 +41,39 @@ func (m *msgServer) RevokeMsg(ctx context.Context, req *msg.RevokeMsgReq) (*msg. if len(msgs) == 0 { return nil, errs.ErrRecordNotFound.Wrap("msg not found") } + if msgs[0].SendID == "" || msgs[0].RecvID == "" { + return nil, errs.ErrRecordNotFound.Wrap("sendID or recvID is empty") + } + // todo: 判断是否已经撤回 data, _ := json.Marshal(msgs[0]) log.ZInfo(ctx, "GetMsgBySeqs", "conversationID", req.ConversationID, "seq", req.Seq, "msg", string(data)) - //sendID := msgs[0] - //if !tokenverify.IsAppManagerUid(ctx) { - // if req.GroupID == "" { - // if req.UserID != sendID { - // return nil, errs.ErrNoPermission.Wrap("no permission") - // } - // } else { - // members, err := m.Group.GetGroupMemberInfoMap(ctx, req.GroupID, utils.Distinct([]string{req.UserID, sendID}), true) - // if err != nil { - // return nil, err - // } - // if req.UserID != sendID { - // roleLevel := members[req.UserID].RoleLevel - // switch members[req.UserID].RoleLevel { - // case constant.GroupOwner: - // case constant.GroupAdmin: - // if roleLevel != constant.GroupOrdinaryUsers { - // return nil, errs.ErrNoPermission.Wrap("no permission") - // } - // default: - // return nil, errs.ErrNoPermission.Wrap("no permission") - // } - // } - // } - //} + if !tokenverify.IsAppManagerUid(ctx) { + switch msgs[0].SessionType { + case constant.SingleChatType: + if err := tokenverify.CheckAccessV3(ctx, msgs[0].SendID); err != nil { + return nil, err + } + case constant.SuperGroupChatType: + members, err := m.Group.GetGroupMemberInfoMap(ctx, msgs[0].RecvID, utils.Distinct([]string{req.UserID, msgs[0].SendID}), true) + if err != nil { + return nil, err + } + if req.UserID != msgs[0].SendID { + roleLevel := members[req.UserID].RoleLevel + switch members[req.UserID].RoleLevel { + case constant.GroupOwner: + case constant.GroupAdmin: + if roleLevel != constant.GroupOrdinaryUsers { + return nil, errs.ErrNoPermission.Wrap("no permission") + } + default: + return nil, errs.ErrNoPermission.Wrap("no permission") + } + } + default: + return nil, errs.ErrInternalServer.Wrap("msg sessionType not supported") + } + } err = m.MsgDatabase.RevokeMsg(ctx, req.ConversationID, req.Seq, &unRelationTb.RevokeModel{ UserID: req.UserID, Nickname: user.Nickname,