Created
April 7, 2022 10:15
-
-
Save nkenna/dffe8fae2358b1f1e8a1e410273b20a8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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