Refactoring for sanity
This commit is contained in:
parent
d18b576d7e
commit
3acb20d1f5
@ -4,11 +4,11 @@ import 'dart:ui';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_localizations/flutter_localizations.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
||||
|
||||
import 'profile_screen.dart';
|
||||
import 'shared_preferences_provider.dart';
|
||||
import 'status_page.dart';
|
||||
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
||||
|
||||
void main() {
|
||||
runApp(
|
||||
|
@ -57,6 +57,7 @@ class StatusPageState extends State<StatusPage> with WidgetsBindingObserver {
|
||||
void _reconnectWebSocket() {
|
||||
if (channel.closeCode != null) {
|
||||
debugPrint("Reinitializing WebSocket connection...");
|
||||
channel.sink.close();
|
||||
_initializeWebSocket();
|
||||
}
|
||||
}
|
||||
@ -165,18 +166,26 @@ class StatusPageState extends State<StatusPage> with WidgetsBindingObserver {
|
||||
debugPrint(
|
||||
"Incoming id $incomingId, status: $status, prefsID: $prefsId, timestamp: $timeStamp");
|
||||
|
||||
if (status == 'removed') {
|
||||
if (incomingId == prefsProvider.getUserId() &&
|
||||
if (incomingId == prefsProvider.getUserId()) {
|
||||
if ((status == 'removed' || status == 'none') &&
|
||||
prefsProvider.getCurrentStatus() != 'none') {
|
||||
debugPrint("Clearing local message: $status");
|
||||
await prefsProvider.setCurrentStatus('none');
|
||||
} else if (messages.any((msg) => msg['Id'] == incomingId)) {
|
||||
messages.removeWhere((msg) => msg['Id'] == incomingId);
|
||||
} else {
|
||||
debugPrint("Ignoring own message: $status");
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
if (status == 'removed' || status == 'none') {
|
||||
if (messages.any((msg) => msg['Id'] == incomingId)) {
|
||||
debugPrint("Removing message from user: $incomingId");
|
||||
messages.removeWhere((msg) => msg['Id'] == incomingId);
|
||||
}
|
||||
} else {
|
||||
debugPrint("Adding incoming message: $status");
|
||||
messages.add(message);
|
||||
_cacheImage(incomingId, image);
|
||||
}
|
||||
} else if (incomingId != prefsId) {
|
||||
debugPrint("Adding incoming message: $status");
|
||||
messages.add(message);
|
||||
_cacheImage(incomingId, image);
|
||||
}
|
||||
}
|
||||
|
||||
@ -307,6 +316,8 @@ class StatusPageState extends State<StatusPage> with WidgetsBindingObserver {
|
||||
if (snapshot.hasData) {
|
||||
final newMessage =
|
||||
jsonDecode(snapshot.data as String) as Map<String, dynamic>;
|
||||
final id = newMessage['Id'];
|
||||
debugPrint("Handling incoming message: $id");
|
||||
_handleIncomingMessage(newMessage);
|
||||
}
|
||||
var status = prefsProvider.getCurrentStatus();
|
||||
|
Loading…
Reference in New Issue
Block a user