Example #1
0
        public void SendMessage(string messageId, string message, string notificationTypeId)
        {
            if (_sentMessageIds.Contains(messageId))
            {
                // this is for duplicate send protection
                return;
            }

            var fts = _firebaseTokenAndNotificationTypeIds.Where(t => t.NotificationTypeId == notificationTypeId).ToList();

            foreach (var firebaseToken in fts)
            {
                var response = _firebaseNotificationSender.SendNotification(firebaseToken.FirebaseToken, message);
                if (response.WasSent)
                {
                    var evt = new SentFirebaseMessage(PersonalNumber, messageId, message, notificationTypeId);
                    Publish(evt);
                }
                else
                {
                    if (response.ShouldBeDeleted)
                    {
                        RemoveToken(firebaseToken.FirebaseToken, firebaseToken.NotificationTypeId);
                    }

                    var evt = new FailedToSendFirebaseMessage(PersonalNumber, message, response.ErrorMessage);
                    Publish(evt);
                }
            }
        }
Example #2
0
 public void Apply(SentFirebaseMessage evt)
 {
     _sentMessageIds.Add(evt.MessageId);
 }