diff --git a/.github/workflows/dart.yml b/.github/workflows/dart.yml index 523ccbfb..da5e1a68 100644 --- a/.github/workflows/dart.yml +++ b/.github/workflows/dart.yml @@ -21,7 +21,7 @@ jobs: - name: Setup Flutter uses: subosito/flutter-action@dbf1fa04f4d2e52c33185153d06cdb5443aa189d #v2.8.0 with: - flutter-version: '3.3.5' + flutter-version: '3.7.1' - name: Check out source uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 #v3.1.0 diff --git a/bruig/flutterui/bruig/lib/models/client.dart b/bruig/flutterui/bruig/lib/models/client.dart index e75c5e8f..c0c36c05 100644 --- a/bruig/flutterui/bruig/lib/models/client.dart +++ b/bruig/flutterui/bruig/lib/models/client.dart @@ -3,6 +3,7 @@ import 'package:bruig/models/menus.dart'; import 'package:flutter/foundation.dart'; import 'package:golib_plugin/definitions.dart'; import 'package:golib_plugin/golib_plugin.dart'; +import '../storage_manager.dart'; const SCE_unknown = 0; const SCE_sending = 1; @@ -190,13 +191,23 @@ class ClientModel extends ChangeNotifier { _fetchInfo(); } - final List _gcChats = []; + List _gcChats = []; UnmodifiableListView get gcChats => UnmodifiableListView(_gcChats); - final List _userChats = []; + void set gcChats(List gc) { + _gcChats = gc; + notifyListeners(); + } + + List _userChats = []; UnmodifiableListView get userChats => UnmodifiableListView(_userChats); + void set userChats(List us) { + _userChats = us; + notifyListeners(); + } + final Map> _subGCMenus = {}; UnmodifiableMapView> get subGCMenus => UnmodifiableMapView(_subGCMenus); @@ -353,12 +364,31 @@ class ClientModel extends ChangeNotifier { source = chat; } chat.append(ChatEventModel(evnt, source)); - // Sorting algo to attempt to retain order if (chat.isGC) { _gcChats.sort((a, b) => b.unreadMsgCount.compareTo(a.unreadMsgCount)); + + String gcChatOrder = ""; + for (int i = 0; i < _gcChats.length; i++) { + if (i == _gcChats.length - 1) { + gcChatOrder += _gcChats[i].nick; + } else { + gcChatOrder += "${_gcChats[i].nick},"; + } + } + StorageManager.saveData('gcListOrder', gcChatOrder); } else { _userChats.sort((a, b) => b.unreadMsgCount.compareTo(a.unreadMsgCount)); + + String userChatOrder = ""; + for (int i = 0; i < _userChats.length; i++) { + if (i == _userChats.length - 1) { + userChatOrder += _userChats[i].nick; + } else { + userChatOrder += "${_userChats[i].nick},"; + } + } + StorageManager.saveData('userListOrder', userChatOrder); } notifyListeners(); } @@ -372,6 +402,64 @@ class ClientModel extends ChangeNotifier { ab.forEach((v) => _newChat(v.id, v.nick, false)); var gcs = await Golib.listGCs(); gcs.forEach((v) => _newChat(v.id, v.name, true)); + + StorageManager.readData('gcListOrder').then((value) { + if (value != null && value.length > 0) { + List sortedGCList = []; + var gcSplitList = value.split(','); + for (int i = 0; i < gcSplitList.length; i++) { + for (int j = 0; j < _gcChats.length; j++) { + if (gcSplitList[i] == _gcChats[j].nick) { + sortedGCList.add(_gcChats[j]); + break; + } + } + } + for (int i = 0; i < _gcChats.length; i++) { + var found = false; + for (int j = 0; j < gcSplitList.length; j++) { + if (gcSplitList[j] == _gcChats[i].nick) { + found = true; + break; + } + } + if (!found) { + sortedGCList.add(_gcChats[i]); + } + } + gcChats = sortedGCList; + } + }); + StorageManager.readData('userListOrder').then((value) { + if (value != null && value.length > 0) { + List sortedUserList = []; + var userSplitList = value.split(','); + // First order existing users from last saved. + for (int i = 0; i < userSplitList.length; i++) { + for (int j = 0; j < _userChats.length; j++) { + if (userSplitList[i] == _userChats[j].nick) { + sortedUserList.add(_userChats[j]); + break; + } + } + } + // Then try and find any received chats that aren't in the saved list. + // Add them on the end. + for (int i = 0; i < _userChats.length; i++) { + var found = false; + for (int j = 0; j < userSplitList.length; j++) { + if (userSplitList[j] == _userChats[i].nick) { + found = true; + break; + } + } + if (!found) { + sortedUserList.add(_userChats[i]); + } + } + userChats = sortedUserList; + } + }); } void acceptInvite(Invitation invite) async { diff --git a/bruig/flutterui/bruig/macos/Flutter/GeneratedPluginRegistrant.swift b/bruig/flutterui/bruig/macos/Flutter/GeneratedPluginRegistrant.swift index 93415d77..b6495dbb 100644 --- a/bruig/flutterui/bruig/macos/Flutter/GeneratedPluginRegistrant.swift +++ b/bruig/flutterui/bruig/macos/Flutter/GeneratedPluginRegistrant.swift @@ -6,9 +6,9 @@ import FlutterMacOS import Foundation import golib_plugin -import path_provider_macos +import path_provider_foundation import screen_retriever -import shared_preferences_macos +import shared_preferences_foundation import url_launcher_macos import window_manager import window_size diff --git a/bruig/flutterui/bruig/pubspec.lock b/bruig/flutterui/bruig/pubspec.lock index afee5f92..6e394a0f 100644 --- a/bruig/flutterui/bruig/pubspec.lock +++ b/bruig/flutterui/bruig/pubspec.lock @@ -782,5 +782,5 @@ packages: source: hosted version: "3.1.1" sdks: - dart: ">=2.18.0 <4.0.0" + dart: ">=2.18.0 <3.0.0" flutter: ">=3.0.0"