notifyLocal finds the right push actions for a local user, given an event.
(ctx context.Context, event *gomatrixserverlib.HeaderedEvent, pos int64, mem *localMembership, roomSize int, roomName string)
| 289 | |
| 290 | // notifyLocal finds the right push actions for a local user, given an event. |
| 291 | func (s *OutputStreamEventConsumer) notifyLocal(ctx context.Context, event *gomatrixserverlib.HeaderedEvent, pos int64, mem *localMembership, roomSize int, roomName string) error { |
| 292 | actions, err := s.evaluatePushRules(ctx, event, mem, roomSize) |
| 293 | if err != nil { |
| 294 | return err |
| 295 | } |
| 296 | a, tweaks, err := pushrules.ActionsToTweaks(actions) |
| 297 | if err != nil { |
| 298 | return err |
| 299 | } |
| 300 | // TODO: support coalescing. |
| 301 | if a != pushrules.NotifyAction && a != pushrules.CoalesceAction { |
| 302 | log.WithFields(log.Fields{ |
| 303 | "event_id": event.EventID(), |
| 304 | "room_id": event.RoomID(), |
| 305 | "localpart": mem.Localpart, |
| 306 | }).Tracef("Push rule evaluation rejected the event") |
| 307 | return nil |
| 308 | } |
| 309 | |
| 310 | devicesByURLAndFormat, profileTag, err := s.localPushDevices(ctx, mem.Localpart, tweaks) |
| 311 | if err != nil { |
| 312 | return err |
| 313 | } |
| 314 | |
| 315 | n := &api.Notification{ |
| 316 | Actions: actions, |
| 317 | // UNSPEC: the spec doesn't say this is a ClientEvent, but the |
| 318 | // fields seem to match. room_id should be missing, which |
| 319 | // matches the behaviour of FormatSync. |
| 320 | Event: gomatrixserverlib.HeaderedToClientEvent(event, gomatrixserverlib.FormatSync), |
| 321 | // TODO: this is per-device, but it's not part of the primary |
| 322 | // key. So inserting one notification per profile tag doesn't |
| 323 | // make sense. What is this supposed to be? Sytests require it |
| 324 | // to "work", but they only use a single device. |
| 325 | ProfileTag: profileTag, |
| 326 | RoomID: event.RoomID(), |
| 327 | TS: gomatrixserverlib.AsTimestamp(time.Now()), |
| 328 | } |
| 329 | if err = s.db.InsertNotification(ctx, mem.Localpart, event.EventID(), pos, tweaks, n); err != nil { |
| 330 | return err |
| 331 | } |
| 332 | |
| 333 | if err = s.syncProducer.GetAndSendNotificationData(ctx, mem.UserID, event.RoomID()); err != nil { |
| 334 | return err |
| 335 | } |
| 336 | |
| 337 | // We do this after InsertNotification. Thus, this should always return >=1. |
| 338 | userNumUnreadNotifs, err := s.db.GetNotificationCount(ctx, mem.Localpart, tables.AllNotifications) |
| 339 | if err != nil { |
| 340 | return err |
| 341 | } |
| 342 | |
| 343 | log.WithFields(log.Fields{ |
| 344 | "event_id": event.EventID(), |
| 345 | "room_id": event.RoomID(), |
| 346 | "localpart": mem.Localpart, |
| 347 | "num_urls": len(devicesByURLAndFormat), |
| 348 | "num_unread": userNumUnreadNotifs, |
no test coverage detected