You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Open-IM-Server/internal/rpc/msg/revoke.go

104 lines
3.3 KiB

2 years ago
package msg
import (
"context"
2 years ago
"encoding/json"
2 years ago
"time"
2 years ago
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/constant"
2 years ago
unRelationTb "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/unrelation"
2 years ago
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/log"
2 years ago
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/tokenverify"
"github.com/OpenIMSDK/Open-IM-Server/pkg/errs"
2 years ago
"github.com/OpenIMSDK/Open-IM-Server/pkg/proto/msg"
2 years ago
"github.com/OpenIMSDK/Open-IM-Server/pkg/proto/sdkws"
"github.com/OpenIMSDK/Open-IM-Server/pkg/utils"
2 years ago
)
func (m *msgServer) RevokeMsg(ctx context.Context, req *msg.RevokeMsgReq) (*msg.RevokeMsgResp, error) {
2 years ago
defer log.ZInfo(ctx, "RevokeMsg return line")
2 years ago
if req.UserID == "" {
return nil, errs.ErrArgs.Wrap("user_id is empty")
}
2 years ago
if req.ConversationID == "" {
return nil, errs.ErrArgs.Wrap("conversation_id is empty")
2 years ago
}
2 years ago
if req.Seq < 0 {
return nil, errs.ErrArgs.Wrap("seq is invalid")
}
2 years ago
if err := tokenverify.CheckAccessV3(ctx, req.UserID); err != nil {
2 years ago
return nil, err
}
2 years ago
user, err := m.User.GetUserInfo(ctx, req.UserID)
if err != nil {
return nil, err
}
_, msgs, err := m.MsgDatabase.GetMsgBySeqs(ctx, req.UserID, req.ConversationID, []int64{req.Seq})
2 years ago
if err != nil {
return nil, err
}
if len(msgs) == 0 || msgs[0] == nil {
2 years ago
return nil, errs.ErrRecordNotFound.Wrap("msg not found")
}
2 years ago
if msgs[0].SendID == "" || msgs[0].RecvID == "" {
return nil, errs.ErrRecordNotFound.Wrap("sendID or recvID is empty")
}
// todo: 判断是否已经撤回
2 years ago
data, _ := json.Marshal(msgs[0])
2 years ago
log.ZInfo(ctx, "GetMsgBySeqs", "conversationID", req.ConversationID, "seq", req.Seq, "msg", string(data))
2 years ago
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")
}
}
2 years ago
err = m.MsgDatabase.RevokeMsg(ctx, req.ConversationID, req.Seq, &unRelationTb.RevokeModel{
2 years ago
UserID: req.UserID,
Nickname: user.Nickname,
Time: time.Now().UnixMilli(),
})
if err != nil {
return nil, err
}
1 year ago
2 years ago
tips := sdkws.RevokeMsgTips{
RevokerUserID: req.UserID,
ClientMsgID: "",
RevokeTime: utils.GetCurrentTimestampByMill(),
Seq: req.Seq,
2 years ago
SesstionType: msgs[0].SessionType,
ConversationID: req.ConversationID,
2 years ago
}
1 year ago
var recvID string
if msgs[0].SessionType == constant.SuperGroupChatType {
recvID = msgs[0].GroupID
} else {
recvID = msgs[0].RecvID
2 years ago
}
1 year ago
if err := m.notificationSender.NotificationWithSesstionType(ctx, req.UserID, recvID, constant.MsgRevokeNotification, msgs[0].SessionType, &tips); err != nil {
2 years ago
return nil, err
}
2 years ago
return &msg.RevokeMsgResp{}, nil
}