|
|
|
@ -20,6 +20,7 @@ class Chat extends StatefulWidget {
|
|
|
|
|
final String id;
|
|
|
|
|
|
|
|
|
|
const Chat(this.id, {Key key}) : super(key: key);
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
_ChatState createState() => _ChatState();
|
|
|
|
|
}
|
|
|
|
@ -55,6 +56,8 @@ class _ChatState extends State<Chat> {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void updateView() {
|
|
|
|
|
if (!mounted) return;
|
|
|
|
|
|
|
|
|
|
String seenByText = "";
|
|
|
|
|
if (timeline.events.isNotEmpty) {
|
|
|
|
|
List lastReceipts = List.from(timeline.events.first.receipts);
|
|
|
|
@ -74,10 +77,12 @@ class _ChatState extends State<Chat> {
|
|
|
|
|
(lastReceipts.length - 1).toString());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (timeline != null) {
|
|
|
|
|
setState(() {
|
|
|
|
|
this.seenByText = seenByText;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<bool> getTimeline() async {
|
|
|
|
|
timeline ??= await room.getTimeline(onUpdate: updateView);
|
|
|
|
@ -88,6 +93,7 @@ class _ChatState extends State<Chat> {
|
|
|
|
|
@override
|
|
|
|
|
void dispose() {
|
|
|
|
|
timeline?.sub?.cancel();
|
|
|
|
|
timeline = null;
|
|
|
|
|
matrix.activeRoomId = "";
|
|
|
|
|
super.dispose();
|
|
|
|
|
}
|
|
|
|
@ -243,11 +249,15 @@ class _ChatState extends State<Chat> {
|
|
|
|
|
timeline.events.isNotEmpty) {
|
|
|
|
|
room.sendReadReceipt(timeline.events[0].eventId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (timeline.events.isEmpty) return Container();
|
|
|
|
|
|
|
|
|
|
return ListView.builder(
|
|
|
|
|
reverse: true,
|
|
|
|
|
itemCount: timeline.events.length + 1,
|
|
|
|
|
controller: _scrollController,
|
|
|
|
|
itemBuilder: (BuildContext context, int i) => i == 0
|
|
|
|
|
itemBuilder: (BuildContext context, int i) {
|
|
|
|
|
return i == 0
|
|
|
|
|
? AnimatedContainer(
|
|
|
|
|
height: seenByText.isEmpty ? 0 : 24,
|
|
|
|
|
duration: seenByText.isEmpty
|
|
|
|
@ -273,8 +283,8 @@ class _ChatState extends State<Chat> {
|
|
|
|
|
)
|
|
|
|
|
: Message(timeline.events[i - 1],
|
|
|
|
|
nextEvent:
|
|
|
|
|
i >= 2 ? timeline.events[i - 2] : null),
|
|
|
|
|
);
|
|
|
|
|
i >= 2 ? timeline.events[i - 2] : null);
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|