mirror of
https://gitlab.com/famedly/fluffychat.git
synced 2025-02-25 10:50:40 +01:00
chore: Follow up jump to unread message
This commit is contained in:
parent
2acf49a12b
commit
fc8fe60613
@ -276,6 +276,8 @@ class ChatController extends State<ChatPageWithRoom> {
|
|||||||
_loadDraft();
|
_loadDraft();
|
||||||
super.initState();
|
super.initState();
|
||||||
sendingClient = Matrix.of(context).client;
|
sendingClient = Matrix.of(context).client;
|
||||||
|
readMarkerEventId = room.fullyRead;
|
||||||
|
loadTimelineFuture = _getTimeline();
|
||||||
}
|
}
|
||||||
|
|
||||||
void updateView() {
|
void updateView() {
|
||||||
@ -283,15 +285,16 @@ class ChatController extends State<ChatPageWithRoom> {
|
|||||||
setState(() {});
|
setState(() {});
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> getTimeline([String? eventContextId]) async {
|
Future<void>? loadTimelineFuture;
|
||||||
if (timeline == null) {
|
|
||||||
|
Future<void> _getTimeline([String? eventContextId]) async {
|
||||||
await Matrix.of(context).client.roomsLoading;
|
await Matrix.of(context).client.roomsLoading;
|
||||||
await Matrix.of(context).client.accountDataLoading;
|
await Matrix.of(context).client.accountDataLoading;
|
||||||
timeline = await room.getTimeline(
|
final timeline = this.timeline = await room.getTimeline(
|
||||||
onUpdate: updateView,
|
onUpdate: updateView,
|
||||||
eventContextId: eventContextId,
|
eventContextId: eventContextId,
|
||||||
);
|
);
|
||||||
if (timeline!.events.isNotEmpty) {
|
if (timeline.events.isNotEmpty) {
|
||||||
if (room.markedUnread) room.markUnread(false);
|
if (room.markedUnread) room.markUnread(false);
|
||||||
setReadMarker();
|
setReadMarker();
|
||||||
}
|
}
|
||||||
@ -308,8 +311,8 @@ class ChatController extends State<ChatPageWithRoom> {
|
|||||||
_updateScrollController();
|
_updateScrollController();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
|
||||||
timeline!.requestKeys(onlineKeyBackupOnly: false);
|
timeline.requestKeys(onlineKeyBackupOnly: false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -317,7 +320,8 @@ class ChatController extends State<ChatPageWithRoom> {
|
|||||||
|
|
||||||
void setReadMarker({String? eventId}) {
|
void setReadMarker({String? eventId}) {
|
||||||
if (_setReadMarkerFuture != null) return;
|
if (_setReadMarkerFuture != null) return;
|
||||||
if (lastReadEventVisible &&
|
if (eventId == null &&
|
||||||
|
lastReadEventVisible &&
|
||||||
!room.hasNewMessages &&
|
!room.hasNewMessages &&
|
||||||
room.notificationCount == 0) {
|
room.notificationCount == 0) {
|
||||||
return;
|
return;
|
||||||
@ -784,8 +788,9 @@ class ChatController extends State<ChatPageWithRoom> {
|
|||||||
if (eventIndex == -1) {
|
if (eventIndex == -1) {
|
||||||
setState(() {
|
setState(() {
|
||||||
timeline = null;
|
timeline = null;
|
||||||
|
loadTimelineFuture = _getTimeline(eventId);
|
||||||
});
|
});
|
||||||
await getTimeline(eventId);
|
await loadTimelineFuture;
|
||||||
eventIndex = timeline!.events.indexWhere((e) => e.eventId == eventId);
|
eventIndex = timeline!.events.indexWhere((e) => e.eventId == eventId);
|
||||||
}
|
}
|
||||||
if (!mounted) {
|
if (!mounted) {
|
||||||
@ -802,8 +807,9 @@ class ChatController extends State<ChatPageWithRoom> {
|
|||||||
if (!timeline!.allowNewEvent) {
|
if (!timeline!.allowNewEvent) {
|
||||||
setState(() {
|
setState(() {
|
||||||
timeline = null;
|
timeline = null;
|
||||||
|
loadTimelineFuture = _getTimeline();
|
||||||
});
|
});
|
||||||
await getTimeline();
|
await loadTimelineFuture;
|
||||||
setReadMarker(eventId: timeline!.events.first.eventId);
|
setReadMarker(eventId: timeline!.events.first.eventId);
|
||||||
}
|
}
|
||||||
scrollController.jumpTo(0);
|
scrollController.jumpTo(0);
|
||||||
|
@ -124,7 +124,8 @@ class ChatEventList extends StatelessWidget {
|
|||||||
.any((e) => e.eventId == event.eventId),
|
.any((e) => e.eventId == event.eventId),
|
||||||
timeline: controller.timeline!,
|
timeline: controller.timeline!,
|
||||||
displayReadMarker:
|
displayReadMarker:
|
||||||
controller.readMarkerEventId == event.eventId,
|
controller.readMarkerEventId == event.eventId &&
|
||||||
|
controller.timeline?.allowNewEvent == false,
|
||||||
nextEvent: i < controller.timeline!.events.length
|
nextEvent: i < controller.timeline!.events.length
|
||||||
? controller.timeline!.events[i]
|
? controller.timeline!.events[i]
|
||||||
: null,
|
: null,
|
||||||
|
@ -139,8 +139,6 @@ class ChatView extends StatelessWidget {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
controller.readMarkerEventId ??= controller.room.fullyRead;
|
|
||||||
|
|
||||||
if (controller.room.membership == Membership.invite) {
|
if (controller.room.membership == Membership.invite) {
|
||||||
showFutureLoadingDialog(
|
showFutureLoadingDialog(
|
||||||
context: context,
|
context: context,
|
||||||
@ -167,7 +165,7 @@ class ChatView extends StatelessWidget {
|
|||||||
stream: controller.room.onUpdate.stream
|
stream: controller.room.onUpdate.stream
|
||||||
.rateLimit(const Duration(seconds: 1)),
|
.rateLimit(const Duration(seconds: 1)),
|
||||||
builder: (context, snapshot) => FutureBuilder(
|
builder: (context, snapshot) => FutureBuilder(
|
||||||
future: controller.getTimeline(),
|
future: controller.loadTimelineFuture,
|
||||||
builder: (BuildContext context, snapshot) {
|
builder: (BuildContext context, snapshot) {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
|
@ -354,12 +354,30 @@ class Message extends StatelessWidget {
|
|||||||
if (displayReadMarker)
|
if (displayReadMarker)
|
||||||
Row(
|
Row(
|
||||||
children: [
|
children: [
|
||||||
const Expanded(child: Divider()),
|
Expanded(
|
||||||
Padding(
|
child: Divider(color: Theme.of(context).colorScheme.primary),
|
||||||
padding: const EdgeInsets.all(8.0),
|
),
|
||||||
child: Text(L10n.of(context)!.readUpToHere),
|
Container(
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
border: Border.all(
|
||||||
|
color: Theme.of(context).colorScheme.primary,
|
||||||
|
),
|
||||||
|
color: Theme.of(context).colorScheme.primaryContainer,
|
||||||
|
borderRadius: BorderRadius.circular(4),
|
||||||
|
),
|
||||||
|
margin: const EdgeInsets.all(8.0),
|
||||||
|
padding: const EdgeInsets.symmetric(
|
||||||
|
horizontal: 8,
|
||||||
|
),
|
||||||
|
child: Text(
|
||||||
|
L10n.of(context)!.readUpToHere,
|
||||||
|
style:
|
||||||
|
TextStyle(color: Theme.of(context).colorScheme.primary),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Expanded(
|
||||||
|
child: Divider(color: Theme.of(context).colorScheme.primary),
|
||||||
),
|
),
|
||||||
const Expanded(child: Divider()),
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
Loading…
x
Reference in New Issue
Block a user