View messages for a room
This commit is contained in:
parent
a6306ceddc
commit
3352939009
|
@ -1,7 +1,7 @@
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
import 'package:shared_preferences/shared_preferences.dart';
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
import 'package:zenith/chats.dart';
|
import 'package:zenith/rooms.dart';
|
||||||
import 'package:zenith/zenith_client_provider.dart';
|
import 'package:zenith/zenith_client_provider.dart';
|
||||||
|
|
||||||
class LoginPage extends StatefulWidget {
|
class LoginPage extends StatefulWidget {
|
||||||
|
@ -29,7 +29,7 @@ class _LoginPageState extends State<LoginPage> {
|
||||||
if (!mounted) return;
|
if (!mounted) return;
|
||||||
Navigator.pushAndRemoveUntil(
|
Navigator.pushAndRemoveUntil(
|
||||||
context,
|
context,
|
||||||
MaterialPageRoute(builder: (context) => const ChatsPage()),
|
MaterialPageRoute(builder: (context) => const RoomsPage()),
|
||||||
(route) => false);
|
(route) => false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:matrix/matrix.dart';
|
import 'package:matrix/matrix.dart';
|
||||||
import 'package:shared_preferences/shared_preferences.dart';
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
import 'package:zenith/chats.dart';
|
import 'package:zenith/rooms.dart';
|
||||||
import 'package:zenith/login.dart';
|
import 'package:zenith/login.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
import 'package:zenith/zenith_client_provider.dart';
|
import 'package:zenith/zenith_client_provider.dart';
|
||||||
|
@ -66,7 +66,7 @@ class _MyHomePageState extends State<MyHomePage> {
|
||||||
if (!savedCreds) {
|
if (!savedCreds) {
|
||||||
return const LoginPage();
|
return const LoginPage();
|
||||||
} else {
|
} else {
|
||||||
return const ChatsPage();
|
return const RoomsPage();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
77
lib/room.dart
Normal file
77
lib/room.dart
Normal file
|
@ -0,0 +1,77 @@
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:matrix/matrix.dart';
|
||||||
|
|
||||||
|
class RoomPage extends StatefulWidget {
|
||||||
|
const RoomPage({super.key, required this.room});
|
||||||
|
|
||||||
|
final Room room;
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<RoomPage> createState() => _RoomPageState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _RoomPageState extends State<RoomPage> {
|
||||||
|
Timeline? timeline;
|
||||||
|
|
||||||
|
void updateTimeline() async {
|
||||||
|
final newTimeline = await widget.room.getTimeline(
|
||||||
|
eventContextId: widget.room.fullyRead, onUpdate: () => setState(() {}));
|
||||||
|
setState(() {
|
||||||
|
timeline = newTimeline;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
updateTimeline();
|
||||||
|
widget.room.onUpdate.stream.listen((event) {
|
||||||
|
updateTimeline();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
super.dispose();
|
||||||
|
timeline?.cancelSubscriptions();
|
||||||
|
widget.room.onUpdate.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
void sendMessage() {}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Scaffold(
|
||||||
|
appBar: AppBar(
|
||||||
|
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
|
||||||
|
title: Text(widget.room.getLocalizedDisplayname()),
|
||||||
|
),
|
||||||
|
body: Padding(
|
||||||
|
padding: const EdgeInsets.all(16.0),
|
||||||
|
child: Column(
|
||||||
|
children: timeline == null
|
||||||
|
? [const CircularProgressIndicator()]
|
||||||
|
: [
|
||||||
|
Expanded(
|
||||||
|
child: ListView.builder(
|
||||||
|
itemCount: timeline?.events.length,
|
||||||
|
reverse: true,
|
||||||
|
itemBuilder: (context, index) => ListTile(
|
||||||
|
title: Text(timeline!
|
||||||
|
.events[index]
|
||||||
|
.senderFromMemoryOrFallback
|
||||||
|
.displayName ??
|
||||||
|
""),
|
||||||
|
subtitle: Text(timeline!.events[index].body),
|
||||||
|
)),
|
||||||
|
)
|
||||||
|
],
|
||||||
|
)),
|
||||||
|
floatingActionButton: FloatingActionButton(
|
||||||
|
onPressed: sendMessage,
|
||||||
|
tooltip: 'Send message',
|
||||||
|
child: const Icon(Icons.send),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,15 +1,17 @@
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:matrix/matrix.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
|
import 'package:zenith/room.dart';
|
||||||
import 'package:zenith/zenith_client_provider.dart';
|
import 'package:zenith/zenith_client_provider.dart';
|
||||||
|
|
||||||
class ChatsPage extends StatefulWidget {
|
class RoomsPage extends StatefulWidget {
|
||||||
const ChatsPage({super.key});
|
const RoomsPage({super.key});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<ChatsPage> createState() => _ChatsPageState();
|
State<RoomsPage> createState() => _RoomsPageState();
|
||||||
}
|
}
|
||||||
|
|
||||||
class _ChatsPageState extends State<ChatsPage> {
|
class _RoomsPageState extends State<RoomsPage> {
|
||||||
final serverController = TextEditingController();
|
final serverController = TextEditingController();
|
||||||
final usernameController = TextEditingController();
|
final usernameController = TextEditingController();
|
||||||
final passwordController = TextEditingController();
|
final passwordController = TextEditingController();
|
||||||
|
@ -21,6 +23,11 @@ class _ChatsPageState extends State<ChatsPage> {
|
||||||
|
|
||||||
void sendMessage() {}
|
void sendMessage() {}
|
||||||
|
|
||||||
|
void viewRoom(Room room) {
|
||||||
|
Navigator.push(
|
||||||
|
context, MaterialPageRoute(builder: (context) => RoomPage(room: room)));
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
|
@ -36,9 +43,11 @@ class _ChatsPageState extends State<ChatsPage> {
|
||||||
return const CircularProgressIndicator();
|
return const CircularProgressIndicator();
|
||||||
else
|
else
|
||||||
return ListView.builder(
|
return ListView.builder(
|
||||||
|
itemCount: provider.client.rooms.length,
|
||||||
itemBuilder: (context, index) => ListTile(
|
itemBuilder: (context, index) => ListTile(
|
||||||
title: Text(provider.client.rooms[index]
|
title: Text(provider.client.rooms[index]
|
||||||
.getLocalizedDisplayname()),
|
.getLocalizedDisplayname()),
|
||||||
|
onTap: () => viewRoom(provider.client.rooms[index]),
|
||||||
));
|
));
|
||||||
},
|
},
|
||||||
)),
|
)),
|
Loading…
Reference in New Issue
Block a user