feat(ui): open message list to unread position
This commit is contained in:
@@ -387,6 +387,11 @@ class _StreamMessageListViewState extends State<StreamMessageListView> {
|
|||||||
if (index != 0) return index + 1;
|
if (index != 0) return index + 1;
|
||||||
return index;
|
return index;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (unreadCount > 0) {
|
||||||
|
return unreadCount + 1;
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -932,6 +937,9 @@ class _StreamMessageListViewState extends State<StreamMessageListView> {
|
|||||||
if (unreadCount > 0) {
|
if (unreadCount > 0) {
|
||||||
streamChannel!.channel.markRead();
|
streamChannel!.channel.markRead();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final index = unreadCount > 0 ? unreadCount + 1 : 0;
|
||||||
|
|
||||||
if (!_upToDate) {
|
if (!_upToDate) {
|
||||||
_bottomPaginationActive = false;
|
_bottomPaginationActive = false;
|
||||||
initialAlignment = 0;
|
initialAlignment = 0;
|
||||||
@@ -939,11 +947,11 @@ class _StreamMessageListViewState extends State<StreamMessageListView> {
|
|||||||
await streamChannel!.reloadChannel();
|
await streamChannel!.reloadChannel();
|
||||||
|
|
||||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||||
_scrollController!.jumpTo(index: unreadCount);
|
_scrollController!.jumpTo(index: index);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
_scrollController!.scrollTo(
|
_scrollController!.scrollTo(
|
||||||
index: unreadCount,
|
index: index,
|
||||||
duration: const Duration(seconds: 1),
|
duration: const Duration(seconds: 1),
|
||||||
curve: Curves.easeInOut,
|
curve: Curves.easeInOut,
|
||||||
);
|
);
|
||||||
@@ -1366,6 +1374,8 @@ class _StreamMessageListViewState extends State<StreamMessageListView> {
|
|||||||
if (newStreamChannel != streamChannel) {
|
if (newStreamChannel != streamChannel) {
|
||||||
streamChannel = newStreamChannel;
|
streamChannel = newStreamChannel;
|
||||||
_messageNewListener?.cancel();
|
_messageNewListener?.cancel();
|
||||||
|
|
||||||
|
unreadCount = streamChannel?.channel.state?.unreadCount ?? 0;
|
||||||
initialIndex = _initialIndex;
|
initialIndex = _initialIndex;
|
||||||
initialAlignment = _initialAlignment;
|
initialAlignment = _initialAlignment;
|
||||||
|
|
||||||
@@ -1376,8 +1386,10 @@ class _StreamMessageListViewState extends State<StreamMessageListView> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
_messageNewListener =
|
_messageNewListener = streamChannel!.channel
|
||||||
streamChannel!.channel.on(EventType.messageNew).listen((event) {
|
.on(EventType.messageNew)
|
||||||
|
.skip(1) //skipping the first event
|
||||||
|
.listen((event) {
|
||||||
if (_upToDate) {
|
if (_upToDate) {
|
||||||
_bottomPaginationActive = false;
|
_bottomPaginationActive = false;
|
||||||
}
|
}
|
||||||
@@ -1395,6 +1407,7 @@ class _StreamMessageListViewState extends State<StreamMessageListView> {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
} else if (streamChannel?.channel.state?.unreadCount != 0) {
|
} else if (streamChannel?.channel.state?.unreadCount != 0) {
|
||||||
|
print('increasing unread');
|
||||||
setState(() {
|
setState(() {
|
||||||
unreadCount = unreadCount + 1;
|
unreadCount = unreadCount + 1;
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user