@@ -4,6 +4,7 @@ import ( | |||
"context" | |||
"gim/internal/logic/domain/message/service" | |||
"gim/pkg/pb" | |||
"time" | |||
"google.golang.org/protobuf/proto" | |||
) | |||
@@ -18,8 +19,8 @@ func (*messageApp) SendToUser(ctx context.Context, sender *pb.Sender, toUserId i | |||
} | |||
// RecallMessageSendToUser 撤回消息发送给用户 | |||
func (*messageApp) RecallMessageSendToUser(ctx context.Context, sender *pb.Sender, toUserId int64, req *pb.RecallMessageReq, isRecallMessageUser bool) (int64, error) { | |||
return service.MessageService.RecallMessageSendToUser(ctx, sender, toUserId, req, isRecallMessageUser) | |||
func (*messageApp) RecallMessageSendToUser(ctx context.Context, sender *pb.Sender, toUserId int64, req *pb.RecallMessageReq, sendTime time.Time) (int64, error) { | |||
return service.MessageService.RecallMessageSendToUser(ctx, sender, toUserId, req, sendTime) | |||
} | |||
// SendRedPackageToUser 发送红包给用户 | |||
@@ -79,7 +80,7 @@ func (s *messageApp) RecallMessage(ctx context.Context, sender *pb.Sender, req * | |||
if sender.SenderType == pb.SenderType_ST_USER { | |||
return FriendApp.RecallMessageSendToFriend(ctx, sender, req) | |||
} else { | |||
return s.RecallMessageSendToUser(ctx, sender, req.ReceiverId, req, true) | |||
//return s.RecallMessageSendToUser(ctx, sender, req.ReceiverId, req, true) | |||
} | |||
// 消息接收者是群组 | |||
case pb.ReceiverType_RT_GROUP: | |||
@@ -4,11 +4,13 @@ import ( | |||
"context" | |||
svc "gim/internal/business/comm/service" | |||
"gim/internal/business/comm/utils" | |||
"gim/internal/logic/domain/message/repo" | |||
"gim/internal/logic/proxy" | |||
"gim/pkg/gerrors" | |||
"gim/pkg/grpclib" | |||
"gim/pkg/pb" | |||
"gim/pkg/rpc" | |||
"google.golang.org/protobuf/proto" | |||
"time" | |||
) | |||
@@ -225,19 +227,30 @@ func (*friendService) RecallMessageSendToFriend(ctx context.Context, sender *pb. | |||
if friend == nil || friend.Status != FriendStatusAgree { | |||
return 0, gerrors.ErrNotIsFriend | |||
} | |||
utils.FilePutContents("RecallMessageSendToFriend", utils.SerializeStr(map[string]interface{}{ | |||
"send": sender, | |||
"req": req, | |||
})) | |||
//查询到对应seq的消息 | |||
msg := &pb.RECALL{} | |||
err = proto.Unmarshal(req.MessageContent, msg) | |||
if err != nil { | |||
return 0, err | |||
} | |||
message, err := repo.MessageRepo.GetMessage(sender.SenderId, msg.RecallSeq) | |||
if err != nil { | |||
return 0, err | |||
} | |||
// 发给发送者 | |||
seq, err := proxy.MessageProxy.RecallMessageSendToUser(ctx, sender, sender.SenderId, req, true) | |||
seq, err := proxy.MessageProxy.RecallMessageSendToUser(ctx, sender, sender.SenderId, req, message.SendTime) | |||
if err != nil { | |||
return 0, err | |||
} | |||
// 发给接收者 | |||
_, err = proxy.MessageProxy.RecallMessageSendToUser(ctx, sender, req.ReceiverId, req, false) | |||
_, err = proxy.MessageProxy.RecallMessageSendToUser(ctx, sender, req.ReceiverId, req, message.SendTime) | |||
if err != nil { | |||
return 0, err | |||
} | |||
@@ -2,6 +2,7 @@ package model | |||
import ( | |||
"context" | |||
"gim/internal/logic/domain/message/repo" | |||
"gim/internal/logic/proxy" | |||
"gim/pkg/gerrors" | |||
"gim/pkg/grpclib" | |||
@@ -167,12 +168,23 @@ func (g *Group) RecallSendMessage(ctx context.Context, sender *pb.Sender, req *p | |||
logger.Sugar.Error(ctx, sender.SenderId, req.ReceiverId, "不在群组内") | |||
return 0, gerrors.ErrNotInGroup | |||
} | |||
var err error | |||
//查询到对应seq的消息 | |||
msg := &pb.RECALL{} | |||
err = proto.Unmarshal(req.MessageContent, msg) | |||
if err != nil { | |||
return 0, err | |||
} | |||
message, err := repo.MessageRepo.GetMessage(sender.SenderId, msg.RecallSeq) | |||
if err != nil { | |||
return 0, err | |||
} | |||
// 如果发送者是用户,将消息发送给发送者,获取用户seq | |||
var userSeq int64 | |||
var err error | |||
if sender.SenderType == pb.SenderType_ST_USER { | |||
userSeq, err = proxy.MessageProxy.RecallMessageSendToUser(ctx, sender, sender.SenderId, req, true) | |||
userSeq, err = proxy.MessageProxy.RecallMessageSendToUser(ctx, sender, sender.SenderId, req, message.SendTime) | |||
if err != nil { | |||
return 0, err | |||
} | |||
@@ -186,7 +198,7 @@ func (g *Group) RecallSendMessage(ctx context.Context, sender *pb.Sender, req *p | |||
if sender.SenderType == pb.SenderType_ST_USER && user.UserId == sender.SenderId { | |||
continue | |||
} | |||
_, err := proxy.MessageProxy.RecallMessageSendToUser(grpclib.NewAndCopyRequestId(ctx), sender, user.UserId, req, false) | |||
_, err := proxy.MessageProxy.RecallMessageSendToUser(grpclib.NewAndCopyRequestId(ctx), sender, user.UserId, req, message.SendTime) | |||
if err != nil { | |||
return | |||
} | |||
@@ -5,6 +5,7 @@ import ( | |||
"gim/internal/logic/domain/message/model" | |||
"gim/pkg/db" | |||
"gim/pkg/gerrors" | |||
"time" | |||
) | |||
const messageTableNum = 1 | |||
@@ -48,9 +49,19 @@ func (d *messageRepo) ListBySeq(userId, seq, limit int64) ([]model.Message, bool | |||
return messages, count > limit, nil | |||
} | |||
// GetMessage 获取消息状态 | |||
func (d *messageRepo) GetMessage(senderId, seq int64) (*model.Message, error) { | |||
var message model.Message | |||
if err := db.DB.Where("sender_id = ? and seq = ?", senderId, seq). | |||
First(&message).Error; err != nil { | |||
return nil, gerrors.WrapError(err) | |||
} | |||
return &message, nil | |||
} | |||
// UpdateStatus 更新消息状态 | |||
func (d *messageRepo) UpdateStatus(senderId, seq int64, status int) (int64, error) { | |||
db := db.DB.Model(&model.Message{}).Where("sender_id = ? and seq = ?", senderId, seq). | |||
func (d *messageRepo) UpdateStatus(senderId int64, sendTime time.Time, status int) (int64, error) { | |||
db := db.DB.Model(&model.Message{}).Where("sender_id = ? and send_time = ?", senderId, sendTime). | |||
Update("status", status) | |||
if db.Error != nil { | |||
return 0, gerrors.WrapError(db.Error) | |||
@@ -257,7 +257,7 @@ func (*messageService) SendToUser(ctx context.Context, sender *pb.Sender, toUser | |||
} | |||
// RecallMessageSendToUser 撤回消息用户 | |||
func (*messageService) RecallMessageSendToUser(ctx context.Context, sender *pb.Sender, toUserId int64, req *pb.RecallMessageReq, isRecallMessageUser bool) (int64, error) { | |||
func (*messageService) RecallMessageSendToUser(ctx context.Context, sender *pb.Sender, toUserId int64, req *pb.RecallMessageReq, sendTime time.Time) (int64, error) { | |||
masterId, _ := grpclib.GetCtxMasterId(ctx) | |||
logger.Logger.Debug("SendToUser", | |||
zap.String("master_id", masterId), | |||
@@ -268,15 +268,10 @@ func (*messageService) RecallMessageSendToUser(ctx context.Context, sender *pb.S | |||
err error | |||
) | |||
//1、解析消息体内容,content值为撤回消息的req | |||
msg := &pb.RECALL{} | |||
err = proto.Unmarshal(req.MessageContent, msg) | |||
if isRecallMessageUser { | |||
//2、改变消息状态 | |||
_, err = repo.MessageRepo.UpdateStatus(sender.SenderId, msg.RecallSeq, int(pb.MessageStatus_MS_RECALL)) | |||
if err != nil { | |||
return 0, err | |||
} | |||
//1、改变消息状态 | |||
_, err = repo.MessageRepo.UpdateStatus(sender.SenderId, sendTime, int(pb.MessageStatus_MS_RECALL)) | |||
if err != nil { | |||
return 0, err | |||
} | |||
//3、发送一条新的消息 | |||
@@ -3,6 +3,7 @@ package proxy | |||
import ( | |||
"context" | |||
"gim/pkg/pb" | |||
"time" | |||
"google.golang.org/protobuf/proto" | |||
) | |||
@@ -11,7 +12,7 @@ var MessageProxy messageProxy | |||
type messageProxy interface { | |||
SendToUser(ctx context.Context, sender *pb.Sender, toUserId int64, req *pb.SendMessageReq) (int64, error) | |||
RecallMessageSendToUser(ctx context.Context, sender *pb.Sender, toUserId int64, req *pb.RecallMessageReq, isRecallMessageUser bool) (int64, error) | |||
RecallMessageSendToUser(ctx context.Context, sender *pb.Sender, toUserId int64, req *pb.RecallMessageReq, sendTime time.Time) (int64, error) | |||
SendRedPackageToUser(ctx context.Context, sender *pb.Sender, toUserId int64, req *pb.SendRedPacketReq) (int64, error) | |||
PushToUser(ctx context.Context, userId int64, code pb.PushCode, message proto.Message, isPersist bool) error | |||
} |
@@ -146,6 +146,7 @@ message RED_PACKAGE { | |||
repeated float received_user_amount = 9; // 已领取用户金额 | |||
repeated string received_user_nickname = 10; // 已领取用户昵称 | |||
RedPacketStatusType red_packet_status_type = 11; // 领取状态 | |||
int64 red_packet_id = 12; // 红包id | |||
} | |||
/************************************消息体定义结束************************************/ | |||