Skip to content

Instantly share code, notes, and snippets.

@nkenna
Created April 7, 2022 10:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nkenna/dffe8fae2358b1f1e8a1e410273b20a8 to your computer and use it in GitHub Desktop.
Save nkenna/dffe8fae2358b1f1e8a1e410273b20a8 to your computer and use it in GitHub Desktop.
FirebaseMessaging.instance.getInitialMessage().then((RemoteMessage message) async{
if (message != null) {
if(message.data != null){
if(message.data['not_type'] == 'user_chat_new_message'){
print(message.data['not_type']);
// intialise chat between this two users
var startChat = await Provider.of<ChatProvider>(navigatorKey.currentState.context, listen: false).initChat(
message.data['user_1_id'],
message.data['user_2_id']
);
// valid data was returned from API
if(startChat != null){
// set this data to the current conversation
Provider.of<ChatProvider>(navigatorKey.currentState.context, listen: false).setSelectedChatConverstion(startChat);
// navigate to the main chat screen using the selected conversation
// make sure that the sender and reciever Ids are not the same person
Get.offAll(() => MainChatScreen(
chatId: message.data['user_chat_id'],
senderId: Provider.of<HomeProvider>(navigatorKey.currentState.context, listen: false).profile.id,
receiverId: Provider.of<HomeProvider>(navigatorKey.currentState.context, listen: false).profile.id == message.data['user_1_id']
? message.data['user_2_id']
: message.data['user_1_id']
));
}
}
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment