Hook up RemoveSession socket event

This commit is contained in:
Nutcake 2023-10-03 18:36:41 +02:00
parent bace94b6d2
commit 890a931cb4

View file

@ -250,6 +250,7 @@ class MessagingClient extends ChangeNotifier {
_hubManager.setHandler(EventTarget.messagesRead, _onMessagesRead); _hubManager.setHandler(EventTarget.messagesRead, _onMessagesRead);
_hubManager.setHandler(EventTarget.receiveStatusUpdate, _onReceiveStatusUpdate); _hubManager.setHandler(EventTarget.receiveStatusUpdate, _onReceiveStatusUpdate);
_hubManager.setHandler(EventTarget.receiveSessionUpdate, _onReceiveSessionUpdate); _hubManager.setHandler(EventTarget.receiveSessionUpdate, _onReceiveSessionUpdate);
_hubManager.setHandler(EventTarget.removeSession, _onRemoveSession);
await _hubManager.start(); await _hubManager.start();
await setUserStatus(userStatus); await setUserStatus(userStatus);
@ -309,7 +310,7 @@ class MessagingClient extends ChangeNotifier {
} }
void _onReceiveStatusUpdate(List args) { void _onReceiveStatusUpdate(List args) {
for (final statusUpdate in args) { final statusUpdate = args[0];
var status = UserStatus.fromMap(statusUpdate); var status = UserStatus.fromMap(statusUpdate);
final sessionMap = createSessionMap(status.hashSalt); final sessionMap = createSessionMap(status.hashSalt);
status = status.copyWith( status = status.copyWith(
@ -318,15 +319,19 @@ class MessagingClient extends ChangeNotifier {
if (friend != null) { if (friend != null) {
_updateContact(friend); _updateContact(friend);
} }
}
notifyListeners(); notifyListeners();
} }
void _onReceiveSessionUpdate(List args) { void _onReceiveSessionUpdate(List args) {
for (final sessionUpdate in args) { final sessionUpdate = args[0];
final session = Session.fromMap(sessionUpdate); final session = Session.fromMap(sessionUpdate);
_sessionMap[session.id] = session; _sessionMap[session.id] = session;
notifyListeners();
} }
void _onRemoveSession(List args) {
final session = args[0];
_sessionMap.remove(session);
notifyListeners(); notifyListeners();
} }
} }