chore: Follow up display read marker in timeline
This commit is contained in:
parent
d0e1e0229c
commit
d3298f0b09
2 changed files with 25 additions and 16 deletions
|
|
@ -102,7 +102,7 @@ class ChatController extends State<ChatPageWithRoom>
|
||||||
|
|
||||||
Timeline? timeline;
|
Timeline? timeline;
|
||||||
|
|
||||||
String? readMarkerEventId;
|
late final String readMarkerEventId;
|
||||||
|
|
||||||
String get roomId => widget.room.id;
|
String get roomId => widget.room.id;
|
||||||
|
|
||||||
|
|
@ -270,6 +270,7 @@ class ChatController extends State<ChatPageWithRoom>
|
||||||
);
|
);
|
||||||
|
|
||||||
sendingClient = Matrix.of(context).client;
|
sendingClient = Matrix.of(context).client;
|
||||||
|
readMarkerEventId = room.hasNewMessages ? room.fullyRead : '';
|
||||||
WidgetsBinding.instance.addObserver(this);
|
WidgetsBinding.instance.addObserver(this);
|
||||||
_tryLoadTimeline();
|
_tryLoadTimeline();
|
||||||
if (kIsWeb) {
|
if (kIsWeb) {
|
||||||
|
|
@ -284,19 +285,22 @@ class ChatController extends State<ChatPageWithRoom>
|
||||||
await loadTimelineFuture;
|
await loadTimelineFuture;
|
||||||
if (initialEventId != null) scrollToEventId(initialEventId);
|
if (initialEventId != null) scrollToEventId(initialEventId);
|
||||||
|
|
||||||
final fullyRead = room.fullyRead;
|
final readMarkerEventIndex = readMarkerEventId.isEmpty
|
||||||
if (fullyRead.isEmpty) {
|
? -1
|
||||||
setReadMarker();
|
: timeline!.events
|
||||||
return;
|
.where((e) => e.isVisibleInGui)
|
||||||
}
|
.toList()
|
||||||
if (timeline?.events.any((event) => event.eventId == fullyRead) ??
|
.indexWhere((e) => e.eventId == readMarkerEventId);
|
||||||
false) {
|
|
||||||
Logs().v('Scroll up to visible event', fullyRead);
|
if (readMarkerEventIndex > 1) {
|
||||||
scrollToEventId(fullyRead, highlightEvent: false);
|
Logs().v('Scroll up to visible event', readMarkerEventId);
|
||||||
|
scrollToEventId(readMarkerEventId, highlightEvent: false);
|
||||||
return;
|
return;
|
||||||
|
} else if (readMarkerEventId.isNotEmpty && readMarkerEventIndex == -1) {
|
||||||
|
_showScrollUpMaterialBanner(readMarkerEventId);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!mounted) return;
|
if (!mounted) return;
|
||||||
_showScrollUpMaterialBanner(fullyRead);
|
|
||||||
} catch (e, s) {
|
} catch (e, s) {
|
||||||
ErrorReporter(context, 'Unable to load timeline').onErrorCallback(e, s);
|
ErrorReporter(context, 'Unable to load timeline').onErrorCallback(e, s);
|
||||||
rethrow;
|
rethrow;
|
||||||
|
|
@ -323,13 +327,16 @@ class ChatController extends State<ChatPageWithRoom>
|
||||||
int? animateInEventIndex;
|
int? animateInEventIndex;
|
||||||
|
|
||||||
void onInsert(int i) {
|
void onInsert(int i) {
|
||||||
|
onChange(i);
|
||||||
|
// setState will be called by updateView() anyway
|
||||||
|
animateInEventIndex = i;
|
||||||
|
}
|
||||||
|
|
||||||
|
void onChange(int i) {
|
||||||
if (timeline?.events[i].status == EventStatus.synced) {
|
if (timeline?.events[i].status == EventStatus.synced) {
|
||||||
final index = timeline!.events.firstIndexWhereNotError;
|
final index = timeline!.events.firstIndexWhereNotError;
|
||||||
if (i == index) setReadMarker(eventId: timeline?.events[i].eventId);
|
if (i == index) setReadMarker(eventId: timeline?.events[i].eventId);
|
||||||
}
|
}
|
||||||
|
|
||||||
// setState will be called by updateView() anyway
|
|
||||||
animateInEventIndex = i;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _getTimeline({
|
Future<void> _getTimeline({
|
||||||
|
|
@ -347,6 +354,7 @@ class ChatController extends State<ChatPageWithRoom>
|
||||||
onUpdate: updateView,
|
onUpdate: updateView,
|
||||||
eventContextId: eventContextId,
|
eventContextId: eventContextId,
|
||||||
onInsert: onInsert,
|
onInsert: onInsert,
|
||||||
|
onChange: onChange,
|
||||||
);
|
);
|
||||||
} catch (e, s) {
|
} catch (e, s) {
|
||||||
Logs().w('Unable to load timeline on event ID $eventContextId', e, s);
|
Logs().w('Unable to load timeline on event ID $eventContextId', e, s);
|
||||||
|
|
@ -354,6 +362,7 @@ class ChatController extends State<ChatPageWithRoom>
|
||||||
timeline = await room.getTimeline(
|
timeline = await room.getTimeline(
|
||||||
onUpdate: updateView,
|
onUpdate: updateView,
|
||||||
onInsert: onInsert,
|
onInsert: onInsert,
|
||||||
|
onChange: onChange,
|
||||||
);
|
);
|
||||||
if (!mounted) return;
|
if (!mounted) return;
|
||||||
if (e is TimeoutException || e is IOException) {
|
if (e is TimeoutException || e is IOException) {
|
||||||
|
|
@ -380,6 +389,7 @@ class ChatController extends State<ChatPageWithRoom>
|
||||||
if (_setReadMarkerFuture != null) return;
|
if (_setReadMarkerFuture != null) return;
|
||||||
if (_scrolledUp) return;
|
if (_scrolledUp) return;
|
||||||
if (scrollUpBannerEventId != null) return;
|
if (scrollUpBannerEventId != null) return;
|
||||||
|
|
||||||
if (eventId == null &&
|
if (eventId == null &&
|
||||||
!room.hasNewMessages &&
|
!room.hasNewMessages &&
|
||||||
room.notificationCount == 0) {
|
room.notificationCount == 0) {
|
||||||
|
|
|
||||||
|
|
@ -141,8 +141,7 @@ 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 &&
|
i > 0 && controller.readMarkerEventId == event.eventId,
|
||||||
controller.timeline?.allowNewEvent == false,
|
|
||||||
nextEvent: i + 1 < events.length ? events[i + 1] : null,
|
nextEvent: i + 1 < events.length ? events[i + 1] : null,
|
||||||
previousEvent: i > 0 ? events[i - 1] : null,
|
previousEvent: i > 0 ? events[i - 1] : null,
|
||||||
avatarPresenceBackgroundColor:
|
avatarPresenceBackgroundColor:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue