MCPcopy Create free account
hub / github.com/daodst/chat / notifyHTTP

Method notifyHTTP

userapi/consumers/syncapi_streamevent.go:519–588  ·  view source on GitHub ↗

notifyHTTP performs a notificatation to a Push Gateway.

(ctx context.Context, event *gomatrixserverlib.HeaderedEvent, url, format string, devices []*pushgateway.Device, localpart, roomName string, userNumUnreadNotifs int)

Source from the content-addressed store, hash-verified

517
518// notifyHTTP performs a notificatation to a Push Gateway.
519func (s *OutputStreamEventConsumer) notifyHTTP(ctx context.Context, event *gomatrixserverlib.HeaderedEvent, url, format string, devices []*pushgateway.Device, localpart, roomName string, userNumUnreadNotifs int) ([]*pushgateway.Device, error) {
520 logger := log.WithFields(log.Fields{
521 "event_id": event.EventID(),
522 "url": url,
523 "localpart": localpart,
524 "num_devices": len(devices),
525 })
526
527 var req pushgateway.NotifyRequest
528 switch format {
529 case "event_id_only":
530 req = pushgateway.NotifyRequest{
531 Notification: pushgateway.Notification{
532 Counts: &pushgateway.Counts{},
533 Devices: devices,
534 EventID: event.EventID(),
535 RoomID: event.RoomID(),
536 },
537 }
538
539 default:
540 req = pushgateway.NotifyRequest{
541 Notification: pushgateway.Notification{
542 Content: event.Content(),
543 Counts: &pushgateway.Counts{
544 Unread: userNumUnreadNotifs,
545 },
546 Devices: devices,
547 EventID: event.EventID(),
548 ID: event.EventID(),
549 RoomID: event.RoomID(),
550 RoomName: roomName,
551 Sender: event.Sender(),
552 Type: event.Type(),
553 },
554 }
555 if mem, err := event.Membership(); err == nil {
556 req.Notification.Membership = mem
557 }
558 if event.StateKey() != nil && *event.StateKey() == fmt.Sprintf("@%s:%s", localpart, s.cfg.Matrix.ServerName) {
559 req.Notification.UserIsTarget = true
560 }
561 }
562
563 logger.Debugf("Notifying push gateway %s", url)
564 var res pushgateway.NotifyResponse
565 if err := s.pgClient.Notify(ctx, url, &req, &res); err != nil {
566 logger.WithError(err).Errorf("Failed to notify push gateway %s", url)
567 return nil, err
568 }
569 logger.WithField("num_rejected", len(res.Rejected)).Tracef("Push gateway result")
570
571 if len(res.Rejected) == 0 {
572 return nil, nil
573 }
574
575 devMap := make(map[string]*pushgateway.Device, len(devices))
576 for _, d := range devices {

Callers 1

notifyLocalMethod · 0.95

Calls 1

NotifyMethod · 0.65

Tested by

no test coverage detected