Skip to content

Commit

Permalink
Merge pull request #205 from XFFFCCCC/dev
Browse files Browse the repository at this point in the history
fix get message
  • Loading branch information
liaosunny123 authored Aug 30, 2023
2 parents abda0fd + 9b4e0d6 commit f597e3d
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 11 deletions.
7 changes: 4 additions & 3 deletions src/constant/strings/service.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package strings

const (
VideoExchange = "video_exchange"
EventExchange = "event"
VideoExchange = "video_exchange"
EventExchange = "event"
MessageExchange = "message_exchange"

VideoPicker = "video_picker"
VideoSummary = "video_summary"
Expand All @@ -12,5 +13,5 @@ const (
VideoCommentEvent = "video.comment.action"
VideoPublishEvent = "video.publish.action"

MessageActionEvent = "message_send"
MessageActionEvent = "message.send"
)
46 changes: 38 additions & 8 deletions src/services/message/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,30 @@ func (c MessageServiceImpl) New() {
if err != nil {
failOnError(err, "Fialed to conenct to RabbitMQ")
}

channel, err = conn.Channel()
if err != nil {
failOnError(err, "Failed to open a channel")
}

err = channel.ExchangeDeclare(
strings.MessageExchange,
"x-delayed-message",
true, false, false, false,
amqp.Table{
"x-delayed-type": "direct",
},
)
if err != nil {
failOnError(err, "Failed to get exchange")
}

_, err = channel.QueueDeclare(
strings.MessageActionEvent,
false, false, false, false,
nil,
)

if err != nil {
failOnError(err, "Failed to define queue")
}
Expand Down Expand Up @@ -281,14 +296,29 @@ func (c MessageServiceImpl) Chat(ctx context.Context, request *chat.ChatRequest)
}

rMessageList := make([]*chat.Message, 0, len(pMessageList))
for _, pMessage := range pMessageList {
rMessageList = append(rMessageList, &chat.Message{
Id: pMessage.ID,
Content: pMessage.Content,
CreateTime: uint64(pMessage.CreatedAt.UnixMilli()),
FromUserId: ptr.Ptr(pMessage.FromUserId),
ToUserId: ptr.Ptr(pMessage.ToUserId),
})
if request.PreMsgTime == 0 {
for _, pMessage := range pMessageList {

rMessageList = append(rMessageList, &chat.Message{
Id: pMessage.ID,
Content: pMessage.Content,
CreateTime: uint64(pMessage.CreatedAt.UnixMilli()),
FromUserId: ptr.Ptr(pMessage.FromUserId),
ToUserId: ptr.Ptr(pMessage.ToUserId),
})
}
} else {
for _, pMessage := range pMessageList {
if pMessage.ToUserId == request.ActorId {
rMessageList = append(rMessageList, &chat.Message{
Id: pMessage.ID,
Content: pMessage.Content,
CreateTime: uint64(pMessage.CreatedAt.UnixMilli()),
FromUserId: ptr.Ptr(pMessage.FromUserId),
ToUserId: ptr.Ptr(pMessage.ToUserId),
})
}
}
}

resp = &chat.ChatResponse{
Expand Down
6 changes: 6 additions & 0 deletions src/services/msgconsumer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,12 @@ func main() {
// logging.SetSpanError(span, err)
return
}
/* err = body.Ack(true)
if err != nil {
logger.WithFields(logrus.Fields{
"err": err,
}).Errorf("Error when dealing with the ,essage...")
} */
}
}()

Expand Down

0 comments on commit f597e3d

Please sign in to comment.