|
|
@@ -2,7 +2,10 @@ package service |
|
|
|
|
|
|
|
import ( |
|
|
|
"context" |
|
|
|
"gim/internal/business/comm/utils" |
|
|
|
"gim/internal/business/comm/db" |
|
|
|
svc "gim/internal/business/comm/service" |
|
|
|
repo2 "gim/internal/business/domain/user/repo" |
|
|
|
"gim/internal/logic/domain/message/md" |
|
|
|
"gim/internal/logic/domain/message/model" |
|
|
|
"gim/internal/logic/domain/message/repo" |
|
|
|
"gim/internal/logic/proxy" |
|
|
@@ -12,9 +15,10 @@ import ( |
|
|
|
"gim/pkg/pb" |
|
|
|
"gim/pkg/rpc" |
|
|
|
"gim/pkg/util" |
|
|
|
|
|
|
|
"go.uber.org/zap" |
|
|
|
"google.golang.org/protobuf/proto" |
|
|
|
"strconv" |
|
|
|
"time" |
|
|
|
) |
|
|
|
|
|
|
|
const MessageLimit = 50 // 最大消息同步数量 |
|
|
@@ -90,7 +94,9 @@ func (*messageService) ListByUserIdAndSeq(ctx context.Context, userId, seq int64 |
|
|
|
|
|
|
|
// SendToUser 将消息发送给用户 |
|
|
|
func (*messageService) SendToUser(ctx context.Context, sender *pb.Sender, toUserId int64, req *pb.SendMessageReq) (int64, error) { |
|
|
|
masterId, _ := grpclib.GetCtxMasterId(ctx) |
|
|
|
logger.Logger.Debug("SendToUser", |
|
|
|
zap.String("master_id", masterId), |
|
|
|
zap.Int64("request_id", grpclib.GetCtxRequestId(ctx)), |
|
|
|
zap.Int64("to_user_id", toUserId)) |
|
|
|
var ( |
|
|
@@ -151,14 +157,44 @@ func (*messageService) SendToUser(ctx context.Context, sender *pb.Sender, toUser |
|
|
|
logger.Sugar.Error(err) |
|
|
|
return 0, err |
|
|
|
} |
|
|
|
utils.FilePutContents("devices", utils.SerializeStr(map[string]interface{}{ |
|
|
|
"data": devices, |
|
|
|
})) |
|
|
|
|
|
|
|
isOpenAppPush := svc.SysCfgGet(masterId, "is_open_app_push") |
|
|
|
if sender.SenderType == pb.SenderType_ST_USER && req.ReceiverType == pb.ReceiverType_RT_USER && isOpenAppPush == "1" && req.ReceiverId != toUserId { |
|
|
|
uid := strconv.FormatInt(req.ReceiverId, 10) |
|
|
|
alia := db.DbUserPushForJg.UserPushForJgGetWithDb(masterId, uid) |
|
|
|
if alia != "" { |
|
|
|
if sender.Nickname == "" { |
|
|
|
sendUser, err := repo2.UserRepo.Get(sender.SenderId) |
|
|
|
if err != nil { |
|
|
|
logger.Sugar.Error(err) |
|
|
|
return 0, err |
|
|
|
} |
|
|
|
sender.Nickname = sendUser.Nickname |
|
|
|
sender.AvatarUrl = sendUser.AvatarUrl |
|
|
|
} |
|
|
|
//TODO::接收者类型为`user`, 进行极光推送 |
|
|
|
CommAddPush(md.PushParams{ |
|
|
|
MasterId: masterId, |
|
|
|
Uid: uid, |
|
|
|
PushAlia: alia, |
|
|
|
Title: "新消息提醒", |
|
|
|
Content: "您收到一条新消息,来自会员\"[消息发送者-会员昵称]\",发送时间\"[时间]\",消息类型\"[消息类型]\",备注\"[备注]\"", |
|
|
|
PushType: "zhi_ying_gim", |
|
|
|
MessageType: req.MessageType.String(), |
|
|
|
SendUserNickname: sender.Nickname, |
|
|
|
SendUserAvatarUrl: sender.AvatarUrl, |
|
|
|
Memo: sender.SenderType.String(), |
|
|
|
Times: time.Now().Format("2006-01-02 15:04:05.000"), |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
for i := range devices { |
|
|
|
// 消息不需要投递给发送消息的设备 |
|
|
|
if sender.DeviceId == devices[i].DeviceId { |
|
|
|
// 消息不需要投递给发送消息的设备 |
|
|
|
continue |
|
|
|
} |
|
|
|
|
|
|
|
err = MessageService.SendToDevice(ctx, devices[i], &message) |
|
|
|
if err != nil { |
|
|
|
logger.Sugar.Error(err, zap.Any("SendToUser error", devices[i]), zap.Error(err)) |
|
|
@@ -170,10 +206,6 @@ func (*messageService) SendToUser(ctx context.Context, sender *pb.Sender, toUser |
|
|
|
|
|
|
|
// SendToDevice 将消息发送给设备 |
|
|
|
func (*messageService) SendToDevice(ctx context.Context, device *pb.Device, message *pb.Message) error { |
|
|
|
utils.FilePutContents("sendToDevice", utils.SerializeStr(map[string]interface{}{ |
|
|
|
"device": device, |
|
|
|
"message": message, |
|
|
|
})) |
|
|
|
messageSend := pb.MessageSend{Message: message} |
|
|
|
_, err := rpc.GetConnectIntClient().DeliverMessage(picker.ContextWithAddr(ctx, device.ConnAddr), &pb.DeliverMessageReq{ |
|
|
|
DeviceId: device.DeviceId, |
|
|
|