forked from eatvio/eatvio_app
feat(chat): add chat lazy loading, send message and websocket init for notifications and new chat messages
This commit is contained in:
@@ -9,6 +9,38 @@ class InitializationCubit extends Cubit<InitializationState> {
|
||||
|
||||
InitializationCubit({required this.chatRepository}) : super(const InitializationState.loading());
|
||||
|
||||
Future<void> subscribeNotifications(int userId, PusherChannelsClient client) async {
|
||||
final privateNotificationChannel = await client.privateChannel(
|
||||
'private-message-events.$userId',
|
||||
authorizationDelegate: EndpointAuthorizableChannelTokenAuthorizationDelegate.forPrivateChannel(
|
||||
authorizationEndpoint: Uri.parse('https://mobile-stage.eatvio.ru/broadcasting/auth'),
|
||||
headers: {
|
||||
'Authorization': 'Bearer ${await TokenStorage.getTokenFromStorage()}',
|
||||
},
|
||||
),
|
||||
);
|
||||
|
||||
privateNotificationChannel.subscribe();
|
||||
|
||||
privateNotificationChannel.bindToAll().listen((event) {});
|
||||
}
|
||||
|
||||
Future<void> subscribeChatMessages(int userId, PusherChannelsClient client) async {
|
||||
final privateMessagesChannel = await client.privateChannel(
|
||||
'private-new-chat-messages.$userId',
|
||||
authorizationDelegate: EndpointAuthorizableChannelTokenAuthorizationDelegate.forPrivateChannel(
|
||||
authorizationEndpoint: Uri.parse('https://mobile-stage.eatvio.ru/broadcasting/auth'),
|
||||
headers: {
|
||||
'Authorization': 'Bearer ${await TokenStorage.getTokenFromStorage()}',
|
||||
},
|
||||
),
|
||||
);
|
||||
|
||||
privateMessagesChannel.subscribe();
|
||||
|
||||
privateMessagesChannel.bindToAll().listen((event) {});
|
||||
}
|
||||
|
||||
Future<void> runInitialization() async {
|
||||
try {
|
||||
await TokenStorage.haveTokenInStorage();
|
||||
@@ -40,6 +72,10 @@ class InitializationCubit extends Cubit<InitializationState> {
|
||||
),
|
||||
);
|
||||
await client.connect();
|
||||
|
||||
await subscribeNotifications(wsUrl.userId, client);
|
||||
await subscribeChatMessages(wsUrl.userId, client);
|
||||
|
||||
emit(InitializationState.success(
|
||||
client: client,
|
||||
));
|
||||
|
||||
Reference in New Issue
Block a user