room_notify.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package room
  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 *Room) notify(action int, data pb.ReasonData) {
  11. if data.UserId > 0 {
  12. // 获取用户信息
  13. if u := user.GetUserInfo(data.UserId); u != nil {
  14. data.NickName = u.NickName
  15. data.FaceId = u.FaceId
  16. data.FaceUrl = u.FaceUrl
  17. }
  18. }
  19. log.Debug("room_notify.notify roomId=%d action=%d data=%+v", this.RoomId, action, data)
  20. buf, _ := json.Marshal(notification.NotificationAudioRoom{
  21. NotifyId: action,
  22. RoomId: this.RoomId,
  23. Data: data,
  24. })
  25. // 只通知个人(麦位邀请、游戏强弹)
  26. if data.Reason == pb.Notify_Reason_Mic_Invite || data.Reason == pb.Notify_Reason_User_Mic_Apply_Agree {
  27. log.Debug("room_notify.notify roomId=%d notifyUserId=%d action=%d buf=%s", this.RoomId, data.NotifyUserId, action, string(buf))
  28. notification.AddNotification(data.NotifyUserId, notification.Notification_AudioRoom, string(buf))
  29. return
  30. }
  31. for _, uid := range this.onlineUsers {
  32. // 在线、离线不通知自己
  33. if data.Reason == pb.Notify_Reason_User_Online || data.Reason == pb.Notify_Reason_User_Offline {
  34. if uid == data.NotifyUserId {
  35. continue
  36. }
  37. }
  38. log.Debug("room_notify.notify notifyUserId=%d roomId=%d action=%d buf=%s", uid, this.RoomId, action, string(buf))
  39. go notification.AddNotification(uid, notification.Notification_AudioRoom, string(buf))
  40. }
  41. }