Use localChannel if present instead of creating a new
Signed-off-by: Sahil Kumar <[email protected]>
This commit is contained in:
@@ -335,10 +335,11 @@ class _ChannelListPageState extends State<ChannelListPage> {
|
||||
onItemTap: (messageResponse) async {
|
||||
final client = StreamChat.of(context).client;
|
||||
final message = messageResponse.message;
|
||||
final channel = Channel.fromState(
|
||||
client,
|
||||
ChannelState(channel: messageResponse.channel),
|
||||
final channel = client.channel(
|
||||
messageResponse.channel.type,
|
||||
id: messageResponse.channel.id,
|
||||
);
|
||||
await channel.watch();
|
||||
Navigator.pushNamed(
|
||||
context,
|
||||
Routes.CHANNEL_PAGE,
|
||||
|
||||
@@ -183,7 +183,7 @@ class _MessageListViewState extends State<MessageListView> {
|
||||
final messageIndex = messages.indexWhere((e) {
|
||||
return e.id == streamChannel.initialMessageId;
|
||||
});
|
||||
return totalMessages - messageIndex - 1;
|
||||
return totalMessages - messageIndex;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -234,7 +234,14 @@ class _MessageListViewState extends State<MessageListView> {
|
||||
initialAlignment = _initialAlignment;
|
||||
}
|
||||
|
||||
return StreamBuilder<List<Message>>(
|
||||
return WillPopScope(
|
||||
onWillPop: () async {
|
||||
if (!_upToDate) {
|
||||
await streamChannel.reloadChannel();
|
||||
}
|
||||
return true;
|
||||
},
|
||||
child: StreamBuilder<List<Message>>(
|
||||
stream: messagesStream?.map((messages) => messages
|
||||
?.where((e) =>
|
||||
!e.isDeleted ||
|
||||
@@ -269,7 +276,8 @@ class _MessageListViewState extends State<MessageListView> {
|
||||
final newMessagesListLength = messages.length;
|
||||
|
||||
if (_bottomPaginationActive) {
|
||||
if (_itemPositionListener.itemPositions.value?.isNotEmpty == true &&
|
||||
if (_itemPositionListener.itemPositions.value?.isNotEmpty ==
|
||||
true &&
|
||||
_messageListLength != null) {
|
||||
final first = _itemPositionListener.itemPositions.value.first;
|
||||
final diff = newMessagesListLength - _messageListLength;
|
||||
@@ -294,7 +302,8 @@ class _MessageListViewState extends State<MessageListView> {
|
||||
if (!_upToDate) {
|
||||
_topPaginationActive = false;
|
||||
_bottomPaginationActive = true;
|
||||
return _paginateData(streamChannel, QueryDirection.bottom);
|
||||
return _paginateData(
|
||||
streamChannel, QueryDirection.bottom);
|
||||
}
|
||||
},
|
||||
onEndOfPage: () async {
|
||||
@@ -335,8 +344,9 @@ class _MessageListViewState extends State<MessageListView> {
|
||||
'Start of thread',
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
color:
|
||||
Theme.of(context).accentColor.withAlpha(50),
|
||||
color: Theme.of(context)
|
||||
.accentColor
|
||||
.withAlpha(50),
|
||||
),
|
||||
),
|
||||
],
|
||||
@@ -401,7 +411,8 @@ 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())
|
||||
@@ -450,7 +461,8 @@ class _MessageListViewState extends State<MessageListView> {
|
||||
),
|
||||
],
|
||||
);
|
||||
});
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _paginateData(
|
||||
|
||||
@@ -307,16 +307,29 @@ class StreamChannelState extends State<StreamChannel> {
|
||||
if (initialMessageId != null) false,
|
||||
],
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.hasError) {
|
||||
if (snapshot.error is Error) {
|
||||
print((snapshot.error as Error).stackTrace);
|
||||
}
|
||||
var message = snapshot.error.toString();
|
||||
if (snapshot.error is DioError) {
|
||||
final dioError = snapshot.error as DioError;
|
||||
if (dioError.type == DioErrorType.RESPONSE) {
|
||||
message = dioError.message;
|
||||
} else {
|
||||
message = 'Check your connection and retry';
|
||||
}
|
||||
}
|
||||
return Center(
|
||||
child: Text(message),
|
||||
);
|
||||
}
|
||||
final initialized = snapshot.data[0];
|
||||
final dataLoaded = initialMessageId == null ? true : snapshot.data[1];
|
||||
if (widget.showLoading && (!initialized || !dataLoaded)) {
|
||||
return Center(
|
||||
child: CircularProgressIndicator(),
|
||||
);
|
||||
} else if (snapshot.hasError) {
|
||||
return Center(
|
||||
child: Text(snapshot.error),
|
||||
);
|
||||
}
|
||||
return widget.child;
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user