DengBiao преди 1 година
родител
ревизия
09d17f524a
променени са 4 файла, в които са добавени 47 реда и са изтрити 20 реда
  1. +0
    -4
      internal/logic/api/logic_ext.go
  2. +4
    -5
      internal/logic/domain/friend/friend_service.go
  3. +42
    -10
      internal/logic/domain/message/service/message_service.go
  4. +1
    -1
      test/tcp_conn/main.go

+ 0
- 4
internal/logic/api/logic_ext.go Целия файл

@@ -2,7 +2,6 @@ package api

import (
"context"
"gim/internal/business/comm/utils"
"gim/internal/logic/app"
"gim/pkg/grpclib"
"gim/pkg/pb"
@@ -37,9 +36,6 @@ func (*LogicExtServer) SendMessage(ctx context.Context, in *pb.SendMessageReq) (
SenderId: userId,
DeviceId: deviceId,
}
utils.FilePutContents("sendMessage", utils.SerializeStr(map[string]interface{}{
"data": sender,
}))
seq, err := app.MessageApp.SendMessage(ctx, &sender, in)
if err != nil {
return nil, err


+ 4
- 5
internal/logic/domain/friend/friend_service.go Целия файл

@@ -3,7 +3,6 @@ package friend
import (
"context"
svc "gim/internal/business/comm/service"
"gim/internal/business/comm/utils"
"gim/internal/logic/proxy"
"gim/pkg/gerrors"
"gim/pkg/grpclib"
@@ -179,10 +178,10 @@ func (*friendService) SendToFriend(ctx context.Context, sender *pb.Sender, req *
return 0, gerrors.ErrNotIsFriend
}

utils.FilePutContents("sendToFriend", utils.SerializeStr(map[string]interface{}{
"send": sender,
"req": req,
}))
//utils.FilePutContents("sendToFriend", utils.SerializeStr(map[string]interface{}{
// "send": sender,
// "req": req,
//}))
// 发给发送者
seq, err := proxy.MessageProxy.SendToUser(ctx, sender, sender.SenderId, req)
if err != nil {


+ 42
- 10
internal/logic/domain/message/service/message_service.go Целия файл

@@ -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,


+ 1
- 1
test/tcp_conn/main.go Целия файл

@@ -88,7 +88,7 @@ func (c *TcpClient) SignIn() {
signIn := pb.SignInInput{
UserId: c.UserId,
DeviceId: c.DeviceId,
Token: "DIGHPXERETPBZWVFSOCBUTMUFONSLDUZZBADYLLR",
Token: "WAOLJWZLZNTJRSOVGCLPZHQYDIIPMUFAYKYESISY",
}
c.Output(pb.PackageType_PT_SIGN_IN, time.Now().UnixNano(), &signIn)
}


Зареждане…
Отказ
Запис