~emersion/goguma-dev

Store bouncer network names locally v1 PROPOSED

delthas: 1
 Store bouncer network names locally

 3 files changed, 25 insertions(+), 9 deletions(-)
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~emersion/goguma-dev/patches/30999/mbox | git am -3
Learn more about email & git

[PATCH] Store bouncer network names locally Export this patch

This is used for displaying buffer_list items (`on $name`).
---
 lib/client_controller.dart |  7 +++++++
 lib/database.dart          | 15 ++++++++++++---
 lib/models.dart            | 12 ++++++------
 3 files changed, 25 insertions(+), 9 deletions(-)

diff --git a/lib/client_controller.dart b/lib/client_controller.dart
index 76752bd..8dbe127 100644
--- a/lib/client_controller.dart
+++ b/lib/client_controller.dart
@@ -507,6 +507,13 @@ class ClientController {
				return _db.deleteNetwork(childNetwork.networkId);
			}

			if (childNetwork != null && attrs['name'] != null) {
				childNetwork.bouncerName = attrs['name'];
				_db.storeNetwork(childNetwork.networkEntry);
				break;
			}


			if (bouncerNetwork != null) {
				// The bouncer network has been updated
				bouncerNetwork.setAttrs(attrs);
diff --git a/lib/database.dart b/lib/database.dart
index ebe81ff..842b36b 100644
--- a/lib/database.dart
+++ b/lib/database.dart
@@ -45,12 +45,14 @@ class NetworkEntry {
	int? id;
	final int server;
	String? bouncerId;
	String? bouncerName;

	Map<String, Object?> toMap() {
		return <String, Object?>{
			'id': id,
			'server': server,
			'bouncer_id': bouncerId,
			'bouncer_name': bouncerName,
		};
	}

@@ -59,7 +61,8 @@ class NetworkEntry {
	NetworkEntry.fromMap(Map<String, dynamic> m) :
		id = m['id'] as int,
		server = m['server'] as int,
		bouncerId = m['bouncer_id'] as String?;
		bouncerId = m['bouncer_id'] as String?,
		bouncerName = m['bouncer_name'] as String?;
}

class BufferEntry {
@@ -179,6 +182,7 @@ class DB {
						id INTEGER PRIMARY KEY,
						server INTEGER NOT NULL,
						bouncer_id TEXT,
						bouncer_name TEXT,
						FOREIGN KEY (server) REFERENCES Server(id) ON DELETE CASCADE,
						UNIQUE(server, bouncer_id)
					)
@@ -238,12 +242,17 @@ class DB {
						ALTER TABLE Buffer ADD COLUMN realname TEXT;
					''');
				}
				if (prevVersion < 6) {
					batch.execute('''
						ALTER TABLE Network ADD COLUMN bouncer_name TEXT;
					''');
				}
				await batch.commit();
			},
			onDowngrade: (_, prevVersion, newVersion) async {
				throw Exception('Attempted to downgrade database from version $prevVersion to version $newVersion');
			},
			version: 5,
			version: 6,
		);
		return DB._(db);
	}
@@ -299,7 +308,7 @@ class DB {

	Future<List<NetworkEntry>> listNetworks() async {
		var entries = await _db.rawQuery('''
			SELECT id, server, bouncer_id FROM Network ORDER BY id
			SELECT id, server, bouncer_id, bouncer_name FROM Network ORDER BY id
		''');
		return entries.map((m) => NetworkEntry.fromMap(m)).toList();
	}
diff --git a/lib/models.dart b/lib/models.dart
index 63bc3d5..4f5f601 100644
--- a/lib/models.dart
+++ b/lib/models.dart
@@ -61,7 +61,7 @@ class NetworkModel extends ChangeNotifier {

	String get displayName {
		// If the user has set a custom bouncer network name, use that
		var bouncerNetworkName = bouncerNetwork?.name;
		var bouncerNetworkName = networkEntry.bouncerName;
		var bouncerNetworkHost = bouncerNetwork?.host;
		if (bouncerNetworkName != null && bouncerNetworkName != bouncerNetworkHost) {
			return bouncerNetworkName;
@@ -99,6 +99,11 @@ class NetworkModel extends ChangeNotifier {
		_realname = realname;
		notifyListeners();
	}

	set bouncerName(String? bouncerName) {
		networkEntry.bouncerName = bouncerName;
		notifyListeners();
	}
}

class BouncerNetworkListModel extends ChangeNotifier {
@@ -144,7 +149,6 @@ BouncerNetworkState _parseBouncerNetworkState(String s) {
/// the bouncer while the bouncer is disconnected from the upstream network.
class BouncerNetworkModel extends ChangeNotifier {
	final String id;
	String? _name;
	String? _host;
	BouncerNetworkState _state = BouncerNetworkState.disconnected;

@@ -152,16 +156,12 @@ class BouncerNetworkModel extends ChangeNotifier {
		setAttrs(attrs);
	}

	String? get name => _name;
	String? get host => _host;
	BouncerNetworkState get state => _state;

	void setAttrs(Map<String, String?> attrs) {
		for (var kv in attrs.entries) {
			switch (kv.key) {
			case 'name':
				_name = kv.value;
				break;
			case 'host':
				_host = kv.value;
				break;

base-commit: 6c75fafa5a11cd6c37a64c68f74a75208d365072
-- 
2.17.1