Повторный вход в аккаунт, очистка кэша
This commit is contained in:
@@ -13,6 +13,9 @@ class SignalRService {
|
||||
SignalRService(this.prefs);
|
||||
|
||||
Future<void> init() async {
|
||||
if (_hubConnection != null) {
|
||||
await stop();
|
||||
}
|
||||
final apiUrl = prefs.getString('api_url') ?? 'https://api.messenger.app';
|
||||
final token = prefs.getString('access_token');
|
||||
|
||||
@@ -33,12 +36,38 @@ class SignalRService {
|
||||
});
|
||||
|
||||
_hubConnection?.on('ReceiveMessage', _handleReceiveMessage);
|
||||
_hubConnection?.on('user_typing', _handleUserTyping);
|
||||
_hubConnection?.on('user_stopped_typing', _handleUserStoppedTyping);
|
||||
|
||||
try {
|
||||
await _hubConnection?.start();
|
||||
// print('[SignalR] Connection started');
|
||||
} catch (e) {
|
||||
// print('[SignalR] Error starting connection: $e');
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
|
||||
final _typingController = StreamController<Map<String, dynamic>>.broadcast();
|
||||
Stream<Map<String, dynamic>> get typingUpdates => _typingController.stream;
|
||||
|
||||
void _handleUserTyping(List<dynamic>? arguments) {
|
||||
if (arguments != null && arguments.isNotEmpty) {
|
||||
final data = arguments[0] as Map<String, dynamic>;
|
||||
_typingController.add({'chatId': data['ChatId'] ?? data['chatId'], 'userId': data['UserId'] ?? data['userId'], 'isTyping': true});
|
||||
}
|
||||
}
|
||||
|
||||
void _handleUserStoppedTyping(List<dynamic>? arguments) {
|
||||
if (arguments != null && arguments.isNotEmpty) {
|
||||
final data = arguments[0] as Map<String, dynamic>;
|
||||
_typingController.add({'chatId': data['ChatId'] ?? data['chatId'], 'userId': data['UserId'] ?? data['userId'], 'isTyping': false});
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> sendTypingStatus(String chatId, bool isTyping) async {
|
||||
if (isTyping) {
|
||||
await _hubConnection?.invoke('typing_start', args: [chatId]);
|
||||
} else {
|
||||
await _hubConnection?.invoke('typing_stop', args: [chatId]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user