user_room_notify.go 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. package user
  2. import (
  3. "encoding/json"
  4. "bet24.com/log"
  5. pb "bet24.com/servers/micros/audioroom/proto"
  6. notification "bet24.com/servers/micros/notification/proto"
  7. user "bet24.com/servers/micros/userservices/proto"
  8. )
  9. // 发出邀请加入通知
  10. func (this *UserRoom) inviteJoinNotify(toUserId, roomId int, code string) {
  11. u := user.GetUserInfo(this.userId)
  12. if u == nil {
  13. return
  14. }
  15. buf, _ := json.Marshal(notification.NotificationAudioRoom{
  16. NotifyId: pb.Notify_Action_Refresh_User,
  17. RoomId: roomId,
  18. Data: pb.ReasonData{
  19. Reason: pb.Notify_Reason_User_Invite,
  20. UserId: u.UserId,
  21. NickName: u.NickName,
  22. Code: code,
  23. },
  24. })
  25. log.Debug("user_room_notify.inviteJoinNotify userId=%d toUserId=%d roomId=%d buf=%s", this.userId, toUserId, roomId, string(buf))
  26. go notification.AddNotification(toUserId, notification.Notification_AudioRoom, string(buf))
  27. return
  28. }
  29. // 发送礼物通知
  30. func (this *UserRoom) givingNotify(roomId, toUserId, giftId, num int, isBarrage bool) {
  31. // 发送数据
  32. var sendData struct {
  33. UserId int `json:"sender.UserId"`
  34. NickName string `json:"sender.NickName"`
  35. FaceId int `json:"sender.FaceId"`
  36. FaceUrl string `json:"sender.FaceUrl"`
  37. ToUserId int `json:"receiver.UserId,omitempty"`
  38. ToNickName string `json:"receiver.NickName,omitempty"`
  39. ToFaceId int `json:"receiver.FaceId,omitempty"`
  40. ToFaceUrl string `json:"receiver.FaceUrl,omitempty"`
  41. GiftId int `json:"GiftId"`
  42. Num int `json:"Num"`
  43. IsBarrage bool
  44. }
  45. // 礼物信息
  46. sendData.GiftId = giftId
  47. sendData.Num = num
  48. sendData.IsBarrage = isBarrage
  49. // 发送者用户信息
  50. if sender := user.GetUserInfo(this.userId); sender != nil {
  51. sendData.UserId = sender.UserId
  52. sendData.NickName = sender.NickName
  53. sendData.FaceId = sender.FaceId
  54. sendData.FaceUrl = sender.FaceUrl
  55. }
  56. // 接收者用户信息
  57. if receiver := user.GetUserInfo(toUserId); receiver != nil {
  58. sendData.ToUserId = receiver.UserId
  59. sendData.ToNickName = receiver.NickName
  60. sendData.ToFaceId = receiver.FaceId
  61. sendData.ToFaceUrl = receiver.FaceUrl
  62. }
  63. buf, _ := json.Marshal(notification.NotificationAudioRoom{
  64. NotifyId: pb.Notify_Action_Giving,
  65. RoomId: roomId,
  66. Data: sendData,
  67. })
  68. // 给所有用户发送通知
  69. log.Debug("user_room_notify.givingNotify userId=%d toUserId=%d roomId=%d giftId=%d buf=%s", this.userId, toUserId, roomId, giftId, string(buf))
  70. notification.AddNotification(-1, notification.Notification_AudioRoom, string(buf))
  71. return
  72. }
  73. // 等级通知
  74. func (this *UserRoom) levelNotify(roomId int) {
  75. buf, _ := json.Marshal(notification.NotificationAudioRoom{
  76. NotifyId: pb.Notify_Action_Refresh_User,
  77. RoomId: roomId,
  78. Data: pb.ReasonData{
  79. Reason: pb.Notify_Reason_User_Level_Up,
  80. UserId: this.userId,
  81. },
  82. })
  83. log.Debug("user_room_notify.levelNotify userId=%d roomId=%d buf=%s", this.userId, roomId, string(buf))
  84. go notification.AddNotification(this.userId, notification.Notification_AudioRoom, string(buf))
  85. return
  86. }