Files
full/module/social/relation/internal/logic/friend/apply_do_message.go
2026-09-22 21:15:34 +08:00

61 lines
1.8 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package friend
import (
"context"
"time"
"bsm/full/module/social/relation/internal/impl"
"bsm/full/module/social/relation/internal/models"
pb "bsm/full/module/social/relation/pb"
"git.apinb.com/bsm-sdk/core/errcode"
"git.apinb.com/bsm-sdk/core/printer"
"git.apinb.com/bsm-sdk/core/service"
"git.apinb.com/bsm-sdk/core/vars"
)
// 好友申请Do:留言
func ApplyDoMessage(ctx context.Context, in *pb.ApplyMessageRequest) (reply *pb.DataStatusReply, err error) {
auth, err := service.ParseMetaCtx(ctx, nil)
if err != nil {
return nil, err
}
if in.Body == "" || in.ApplyId == 0 {
return nil, errcode.ErrInvalidArgument
}
// 校验该申请存在且属于当前调用者(申请方或被申请方),避免污染他人申请会话
var apply models.FriendApply
err = impl.DBService.Where("id=? and (from_identity=? or to_identity=?)", in.ApplyId, auth.Identity, auth.Identity).First(&apply).Error
if err != nil {
printer.Error(err.Error())
return nil, errcode.ErrPermissionDenied
}
msg := models.FriendApplyMessage{
ApplyID: uint(in.ApplyId),
Body: in.Body,
}
msg.PassportID = auth.ID
msg.PassportIdentity = auth.Identity
err = impl.DBService.Create(&msg).Error
if err != nil {
printer.Error(err.Error())
return nil, errcode.ErrDB
}
//回写最后一次交流的消息ID仍限定申请归属
err = impl.DBService.Model(models.FriendApply{}).Where("id=? and (from_identity=? or to_identity=?)", msg.ApplyID, auth.Identity, auth.Identity).UpdateColumn("last_message_id", msg.ID).Error
if err != nil {
printer.Error(err.Error())
return nil, errcode.ErrDB
}
//EventMQ向mesh MQ中心发送报文请求推送消息以及更新Cache.
return &pb.DataStatusReply{
Data: vars.OK,
Timeseq: time.Now().UnixMilli(),
}, nil
}