From 7b23b121258d74b473fcd89e3483897b52fc0c30 Mon Sep 17 00:00:00 2001 From: Jakob Meier Date: Wed, 22 Mar 2023 21:12:04 +0100 Subject: [PATCH] Implemented room member and room info In preperation for upcoming room screens. RoomInfo is supposed to be used in conjunction with the Room class. They are not merged (Room as a attribut in RoomInfo), because whilst Room can be stored on disk, RoomInfo can not. This is done to prevent tampering with the data (when offline). This also makes hiding elements easier when the user is offline, as we can just pretend, that they do not have the required permission. --- lib/backend/room.dart | 45 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/lib/backend/room.dart b/lib/backend/room.dart index f084c3a..0039a67 100644 --- a/lib/backend/room.dart +++ b/lib/backend/room.dart @@ -262,4 +262,49 @@ class Room { final db = Localstore.instance; await db.collection('rooms').doc('$id@$serverTag').set(toMap()); } + + static Future fromDisk({required String id, required String serverTag}) async { + final db = Localstore.instance; + final raw = await db.collection('rooms').doc('$id@$serverTag').get(); + return Room.fromMap(raw!); + } +} + +class ShoppingListItem { + +} + +class RoomMember { + final String id; + final String serverTag; + final bool isAdmin; + + const RoomMember( + {required this.id, required this.serverTag, required this.isAdmin}); + + factory RoomMember.fromJSON(dynamic json) { + return RoomMember( + id: json['name'], serverTag: json['server'], isAdmin: json['admin']); + } +} + +class RoomInfo { + final String owner; + final bool isAdmin; + final bool isOwner; + final int permissions; + + const RoomInfo( + {required this.permissions, + required this.owner, + required this.isAdmin, + required this.isOwner}); + + factory RoomInfo.fromJSON(dynamic json) { + return RoomInfo( + permissions: json['rights'], + owner: json['owner'], + isAdmin: json['isAdmin'], + isOwner: json['isOwner']); + } }