project-error / npwd

NPWD is a FiveM phone resource written entirely in TypeScript and React.
https://projecterror.dev
Other
351 stars 275 forks source link

Fix message notification not appearing #1031

Closed BackSH00TER closed 1 year ago

BackSH00TER commented 1 year ago

Pull Request Description

Problem: If a user receives a text message, but has never opened the message conversation before, they will not receive a notification on their phone. Fixes issue: https://github.com/project-error/npwd/issues/1017

Repro steps:

The reason this is happening is because of the following error. We are trying to read id from activeMessageConversation which is undefined. image

Fix: Instead of trying to read from activeMessageConversation we can use the convId that is already passed to the addNotification function. This is sufficient as it will always pass the id of the conversation that the msg was for and doesn't have a need to rely on the active conversation.

Additionally in the handleUpdateMessages function, there is a comparison to the activeConversation.id, which also throws a can't read id from undefined error because activeConversation could be undefined. Fixed this error by using optional chaining (?.) to make sure the variable is defined before trying to access variables from it.

Demo: https://github.com/project-error/npwd/assets/18689469/bf6751ff-c222-4304-a21d-7fb685e6aba8

Pull Request Checklist: