Fixed bug where room list was not processed properly
This was caused by a wrong type. To fix this I updated the type and implemented Room.fromJSON which should make fetching rooms easier in the future
This commit is contained in:
parent
cfd54e3bb5
commit
f2cbfaf924
3 changed files with 82 additions and 83 deletions
|
@ -2,8 +2,6 @@ import 'package:localstore/localstore.dart';
|
|||
import 'package:http/http.dart' as http;
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:outbag_app/main.dart';
|
||||
|
||||
const String wellKnownPath = "/.well-known/outbag/server";
|
||||
const int defaultPort = 7223;
|
||||
|
||||
|
|
|
@ -232,9 +232,9 @@ class Room {
|
|||
id: map['id'],
|
||||
serverTag: map['server'],
|
||||
name: map['name'],
|
||||
description: map['description']??'',
|
||||
icon: RoomIcon(type: map['icon']??'Other'),
|
||||
visibility: RoomVisibility(map['visibility']??0));
|
||||
description: map['description'] ?? '',
|
||||
icon: RoomIcon(type: map['icon'] ?? 'Other'),
|
||||
visibility: RoomVisibility(map['visibility'] ?? 0));
|
||||
}
|
||||
|
||||
Map<String, dynamic> toMap() {
|
||||
|
@ -248,6 +248,16 @@ class Room {
|
|||
};
|
||||
}
|
||||
|
||||
factory Room.fromJSON(dynamic json) {
|
||||
return Room(
|
||||
id: json['name'],
|
||||
serverTag: json['server'],
|
||||
name: json['title'],
|
||||
description: json['description'],
|
||||
icon: RoomIcon(type: json['icon']),
|
||||
visibility: RoomVisibility(json['visibility']));
|
||||
}
|
||||
|
||||
Future<void> toDisk() async {
|
||||
final db = Localstore.instance;
|
||||
await db.collection('rooms').doc('$id@$serverTag').set(toMap());
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_svg/flutter_svg.dart';
|
||||
import 'package:outbag_app/backend/request.dart';
|
||||
|
@ -50,24 +52,16 @@ class _HomePageState extends State<HomePage> {
|
|||
|
||||
try {
|
||||
final resp = await postWithCreadentials(
|
||||
path: 'listLocalRooms',
|
||||
path: 'listRooms',
|
||||
credentials: user,
|
||||
target: user.server,
|
||||
body: {});
|
||||
if (resp.res == Result.ok) {
|
||||
final List<Map<String, dynamic>> list = resp.body['data'];
|
||||
for (Map<String, dynamic> rawRoom in list) {
|
||||
try {
|
||||
Room(
|
||||
id: rawRoom['room'],
|
||||
serverTag: rawRoom['server'],
|
||||
name: rawRoom['title'],
|
||||
icon: RoomIcon(type: rawRoom['icon']),
|
||||
visibility: RoomVisibility(rawRoom['visibility']))
|
||||
.toDisk();
|
||||
} catch (_) {
|
||||
continue;
|
||||
}
|
||||
final List<Room> list = resp.body['data'].map<Room>((json){
|
||||
return Room.fromJSON(json);
|
||||
}).toList();
|
||||
for (Room r in list) {
|
||||
await r.toDisk();
|
||||
}
|
||||
}
|
||||
} catch (_) {}
|
||||
|
@ -131,7 +125,8 @@ class _HomePageState extends State<HomePage> {
|
|||
child: InkWell(
|
||||
onTap: () {
|
||||
// open room
|
||||
Routemaster.of(context).push("/r/${room.serverTag}/${room.id}");
|
||||
Routemaster.of(context)
|
||||
.push("/r/${room.serverTag}/${room.id}");
|
||||
},
|
||||
onLongPress: () {
|
||||
// open bottom sheet
|
||||
|
@ -148,11 +143,7 @@ class _HomePageState extends State<HomePage> {
|
|||
child: SvgPicture.asset("${room.icon?.img}"),
|
||||
),
|
||||
hoverColor: Colors.transparent,
|
||||
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
))));
|
||||
},
|
||||
),
|
||||
floatingActionButton: FloatingActionButton.extended(
|
||||
|
|
Loading…
Reference in a new issue