|
|
|
@@ -173,10 +173,10 @@ class _MessageListViewState extends State<MessageListView> {
|
|
|
|
|
bool _showScrollToBottom = false;
|
|
|
|
|
ItemPositionsListener _itemPositionListener;
|
|
|
|
|
int _messageListLength;
|
|
|
|
|
StreamChannelState streamChannel;
|
|
|
|
|
|
|
|
|
|
int get _initialIndex {
|
|
|
|
|
if (widget.initialScrollIndex != null) return widget.initialScrollIndex;
|
|
|
|
|
final streamChannel = StreamChannel.of(context);
|
|
|
|
|
if (streamChannel.initialMessageId != null) {
|
|
|
|
|
final messages = streamChannel.channel.state.messages;
|
|
|
|
|
final totalMessages = messages.length;
|
|
|
|
@@ -196,11 +196,10 @@ class _MessageListViewState extends State<MessageListView> {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool _isInitialMessage(String id) {
|
|
|
|
|
final streamChannel = StreamChannel.of(context);
|
|
|
|
|
return streamChannel.initialMessageId == id;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool get _upToDate => StreamChannel.of(context).channel.state.isUpToDate;
|
|
|
|
|
bool get _upToDate => streamChannel.channel.state.isUpToDate;
|
|
|
|
|
|
|
|
|
|
bool _topPaginationActive = false;
|
|
|
|
|
bool _bottomPaginationActive = false;
|
|
|
|
@@ -216,22 +215,13 @@ class _MessageListViewState extends State<MessageListView> {
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
final streamChannel = StreamChannel.of(context);
|
|
|
|
|
|
|
|
|
|
final messagesStream = widget.parentMessage != null
|
|
|
|
|
? streamChannel.channel.state.threadsStream
|
|
|
|
|
.where((threads) => threads.containsKey(widget.parentMessage.id))
|
|
|
|
|
.map((threads) => threads[widget.parentMessage.id])
|
|
|
|
|
: streamChannel.channel.state?.messagesStream;
|
|
|
|
|
|
|
|
|
|
return WillPopScope(
|
|
|
|
|
onWillPop: () async {
|
|
|
|
|
if (!_upToDate) {
|
|
|
|
|
await streamChannel.reloadChannel();
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
},
|
|
|
|
|
child: StreamBuilder<List<Message>>(
|
|
|
|
|
return StreamBuilder<List<Message>>(
|
|
|
|
|
stream: messagesStream?.map((messages) => messages
|
|
|
|
|
?.where((e) =>
|
|
|
|
|
!e.isDeleted ||
|
|
|
|
@@ -428,8 +418,7 @@ class _MessageListViewState extends State<MessageListView> {
|
|
|
|
|
children: <Widget>[
|
|
|
|
|
messageWidget,
|
|
|
|
|
Padding(
|
|
|
|
|
padding:
|
|
|
|
|
const EdgeInsets.symmetric(vertical: 12.0),
|
|
|
|
|
padding: const EdgeInsets.symmetric(vertical: 12.0),
|
|
|
|
|
child: widget.dateDividerBuilder != null
|
|
|
|
|
? widget.dateDividerBuilder(
|
|
|
|
|
nextMessage.createdAt.toLocal())
|
|
|
|
@@ -478,8 +467,7 @@ class _MessageListViewState extends State<MessageListView> {
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
);
|
|
|
|
|
}),
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<void> _paginateData(
|
|
|
|
@@ -499,7 +487,6 @@ class _MessageListViewState extends State<MessageListView> {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Widget _buildScrollToBottom() {
|
|
|
|
|
final streamChannel = StreamChannel.of(context);
|
|
|
|
|
return StreamBuilder<Tuple2<bool, int>>(
|
|
|
|
|
stream: Rx.combineLatest2(
|
|
|
|
|
streamChannel.channel.state.isUpToDateStream,
|
|
|
|
@@ -744,7 +731,7 @@ class _MessageListViewState extends State<MessageListView> {
|
|
|
|
|
final isNextUser =
|
|
|
|
|
index - 2 >= 0 && message.user.id == messages[index - 2]?.user?.id;
|
|
|
|
|
|
|
|
|
|
final channel = StreamChannel.of(context).channel;
|
|
|
|
|
final channel = streamChannel.channel;
|
|
|
|
|
final readList = channel.state?.read
|
|
|
|
|
?.where((element) => element.user.id != userId)
|
|
|
|
|
?.where((read) =>
|
|
|
|
@@ -836,7 +823,7 @@ class _MessageListViewState extends State<MessageListView> {
|
|
|
|
|
_itemPositionListener =
|
|
|
|
|
widget.itemPositionListener ?? ItemPositionsListener.create();
|
|
|
|
|
|
|
|
|
|
final streamChannel = StreamChannel.of(context);
|
|
|
|
|
streamChannel = StreamChannel.of(context);
|
|
|
|
|
|
|
|
|
|
initialIndex = _initialIndex;
|
|
|
|
|
initialAlignment = _initialAlignment;
|
|
|
|
@@ -879,16 +866,13 @@ class _MessageListViewState extends State<MessageListView> {
|
|
|
|
|
context,
|
|
|
|
|
MaterialPageRoute(builder: (_) {
|
|
|
|
|
return StreamBuilder<Message>(
|
|
|
|
|
stream: StreamChannel.of(context)
|
|
|
|
|
.channel
|
|
|
|
|
.state
|
|
|
|
|
.messagesStream
|
|
|
|
|
.map((messages) =>
|
|
|
|
|
stream: streamChannel.channel.state.messagesStream.map(
|
|
|
|
|
(messages) =>
|
|
|
|
|
messages.firstWhere((m) => m.id == message.id)),
|
|
|
|
|
initialData: message,
|
|
|
|
|
builder: (_, snapshot) {
|
|
|
|
|
return StreamChannel(
|
|
|
|
|
channel: StreamChannel.of(context).channel,
|
|
|
|
|
channel: streamChannel.channel,
|
|
|
|
|
child: widget.threadBuilder(context, snapshot.data),
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
@@ -900,6 +884,9 @@ class _MessageListViewState extends State<MessageListView> {
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
void dispose() {
|
|
|
|
|
if (!_upToDate) {
|
|
|
|
|
streamChannel.reloadChannel();
|
|
|
|
|
}
|
|
|
|
|
_messageNewListener?.cancel();
|
|
|
|
|
super.dispose();
|
|
|
|
|
}
|
|
|
|
|