Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Notifications not working #11

Open
itsjakeelmir opened this issue Nov 22, 2019 · 0 comments
Open

Notifications not working #11

itsjakeelmir opened this issue Nov 22, 2019 · 0 comments
Labels

Comments

@itsjakeelmir
Copy link

itsjakeelmir commented Nov 22, 2019

Push Notifications are not working. When a message is sent the other user does not receive a notification. This is happening because the code that sends the notification is not being called. I would appreciate if anyone can fix it.

for notificationID in notificationIDs.values {
        
      
      NotificationsController.send(to: notificationID, title: message.sender, message: message.text ?? Constants.Placeholders.pictureMessagePlaceholder)
    }

This code is not being executed from the send message and no notifications is being sent.

func send(message: Message) {
    
    
    
    // Write the message to Firebase
    let randomMessageId = messagesRef!.childByAutoId().key
    
    // Since we are sending this message, we can cache it as most recent
    mostRecentMessageTimestamp = message.timestamp
    
    
    // If there are inactive members, attempt to rejoin them
    // Otherwise you would manually have to rejoin to be added again
    
    for (uid, username) in inactiveMembers {
      databaseManager.attemptRejoinIntoConversation(convoID: convoId, uid: uid, username: username, completion: {_ in})
    }
    
    
    // Each message record (uniquely identified) will record sender and message text
    if let text = message.text {
        messagesRef?.child(randomMessageId!).setValue(
        ["sender" : message.sender, "text" : text, "timestamp" : message.timestamp.timeIntervalSince1970]
      )
      
    } else if let imageURL = message.imageURL {
        messagesRef?.child(randomMessageId!).setValue(
        ["imageURL": imageURL, "sender" : message.sender, "timestamp" : message.timestamp.timeIntervalSince1970]
      )
    }
    
    
    // Set timestamp for most recent conversation viewing
    // This is required to later determine if messages loaded have already been seen
    updateLastSeenTimestamp(convoID: convoId)
    
    // TODO: Internet speed may prevent sending notification if observers do not find out about newly reactivated users in time
    // Ask NotificationController to send this message as a push notification
    
 
    for notificationID in notificationIDs.values {
        
      
      NotificationsController.send(to: notificationID, title: message.sender, message: message.text ?? Constants.Placeholders.pictureMessagePlaceholder)
    }
    
    
  }

Let me know if you know how to fix this issue!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants