add channel, user and messages db
This commit is contained in:
@@ -215,7 +215,10 @@ class _ChannelListViewState extends State<ChannelListView> {
|
|||||||
if (i < channels.length) {
|
if (i < channels.length) {
|
||||||
final channel = channels[i];
|
final channel = channels[i];
|
||||||
|
|
||||||
final channelClient = streamChat.client.channels[channel.cid];
|
final channelClient = streamChat.channels.firstWhere(
|
||||||
|
(c) => c.cid == channel.cid,
|
||||||
|
orElse: () => null,
|
||||||
|
);
|
||||||
|
|
||||||
ChannelTapCallback onTap;
|
ChannelTapCallback onTap;
|
||||||
if (widget.onChannelTap != null) {
|
if (widget.onChannelTap != null) {
|
||||||
|
|||||||
@@ -110,15 +110,15 @@ class ChannelPreview extends StatelessWidget {
|
|||||||
initialData: channel.state.messages,
|
initialData: channel.state.messages,
|
||||||
builder: (context, snapshot) {
|
builder: (context, snapshot) {
|
||||||
final messages = snapshot.data;
|
final messages = snapshot.data;
|
||||||
final lastMessage = messages.isNotEmpty ? messages.last : null;
|
final lastMessage = messages?.isNotEmpty == true ? messages.last : null;
|
||||||
if (lastMessage == null) {
|
if (lastMessage == null) {
|
||||||
return SizedBox();
|
return SizedBox();
|
||||||
}
|
}
|
||||||
|
|
||||||
String text;
|
String text = lastMessage.text;
|
||||||
if (lastMessage.isDeleted) {
|
if (lastMessage.isDeleted) {
|
||||||
text = 'This message was deleted.';
|
text = 'This message was deleted.';
|
||||||
} else {
|
} else if (lastMessage.attachments != null) {
|
||||||
final prefix = lastMessage.attachments
|
final prefix = lastMessage.attachments
|
||||||
.map((e) {
|
.map((e) {
|
||||||
if (e.type == 'image') {
|
if (e.type == 'image') {
|
||||||
|
|||||||
+31
-25
@@ -101,7 +101,7 @@ class _MessageWidgetState extends State<MessageWidget>
|
|||||||
widget.message.isDeleted
|
widget.message.isDeleted
|
||||||
? _buildDeletedMessage(alignment)
|
? _buildDeletedMessage(alignment)
|
||||||
: _buildBubble(context),
|
: _buildBubble(context),
|
||||||
if (_streamChannel.channel.config.replies)
|
if (_streamChannel.channel.config?.replies == true)
|
||||||
_buildThreadIndicator(context),
|
_buildThreadIndicator(context),
|
||||||
if (!_isNextUser) _buildTimestamp(alignment),
|
if (!_isNextUser) _buildTimestamp(alignment),
|
||||||
],
|
],
|
||||||
@@ -146,7 +146,8 @@ class _MessageWidgetState extends State<MessageWidget>
|
|||||||
UserAvatar(user: widget.message.user),
|
UserAvatar(user: widget.message.user),
|
||||||
if (_isMyMessage &&
|
if (_isMyMessage &&
|
||||||
widget.nextMessage == null &&
|
widget.nextMessage == null &&
|
||||||
widget.message.status == MessageSendingStatus.SENT)
|
(widget.message.status == MessageSendingStatus.SENT ||
|
||||||
|
widget.message.status == null))
|
||||||
Padding(
|
Padding(
|
||||||
padding: const EdgeInsets.symmetric(
|
padding: const EdgeInsets.symmetric(
|
||||||
horizontal: 1.0,
|
horizontal: 1.0,
|
||||||
@@ -278,28 +279,30 @@ class _MessageWidgetState extends State<MessageWidget>
|
|||||||
var nOfAttachmentWidgets = 0;
|
var nOfAttachmentWidgets = 0;
|
||||||
|
|
||||||
final column =
|
final column =
|
||||||
List<Widget>.from(widget.message.attachments.map((attachment) {
|
List<Widget>.from(widget.message.attachments?.map((attachment) {
|
||||||
nOfAttachmentWidgets++;
|
nOfAttachmentWidgets++;
|
||||||
|
|
||||||
Widget attachmentWidget;
|
Widget attachmentWidget;
|
||||||
if (attachment.type == 'video') {
|
if (attachment.type == 'video') {
|
||||||
attachmentWidget = _buildVideo(attachment);
|
attachmentWidget = _buildVideo(attachment);
|
||||||
} else if (attachment.type == 'image' || attachment.type == 'giphy') {
|
} else if (attachment.type == 'image' ||
|
||||||
attachmentWidget = _buildImage(attachment);
|
attachment.type == 'giphy') {
|
||||||
}
|
attachmentWidget = _buildImage(attachment);
|
||||||
|
}
|
||||||
|
|
||||||
if (attachmentWidget != null) {
|
if (attachmentWidget != null) {
|
||||||
return _buildAttachment(
|
return _buildAttachment(
|
||||||
attachmentWidget,
|
attachmentWidget,
|
||||||
attachment,
|
attachment,
|
||||||
nOfAttachmentWidgets,
|
nOfAttachmentWidgets,
|
||||||
context,
|
context,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
nOfAttachmentWidgets--;
|
nOfAttachmentWidgets--;
|
||||||
return SizedBox();
|
return SizedBox();
|
||||||
}));
|
}) ??
|
||||||
|
[]);
|
||||||
|
|
||||||
if (widget.message.text.trim().isNotEmpty) {
|
if (widget.message.text.trim().isNotEmpty) {
|
||||||
String text = widget.message.text;
|
String text = widget.message.text;
|
||||||
@@ -312,7 +315,7 @@ class _MessageWidgetState extends State<MessageWidget>
|
|||||||
? CrossAxisAlignment.end
|
? CrossAxisAlignment.end
|
||||||
: CrossAxisAlignment.start,
|
: CrossAxisAlignment.start,
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
if (_streamChannel.channel.config.reactions &&
|
if (_streamChannel.channel.config?.reactions == true &&
|
||||||
nOfAttachmentWidgets == 0)
|
nOfAttachmentWidgets == 0)
|
||||||
Align(
|
Align(
|
||||||
child: _buildReactions(),
|
child: _buildReactions(),
|
||||||
@@ -323,7 +326,9 @@ class _MessageWidgetState extends State<MessageWidget>
|
|||||||
Stack(
|
Stack(
|
||||||
overflow: Overflow.visible,
|
overflow: Overflow.visible,
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
if (nOfAttachmentWidgets == 0) _buildReactionPaint(),
|
if (nOfAttachmentWidgets == 0 &&
|
||||||
|
_streamChannel.channel.config?.reactions == true)
|
||||||
|
_buildReactionPaint(),
|
||||||
_buildMessageText(nOfAttachmentWidgets, text, context),
|
_buildMessageText(nOfAttachmentWidgets, text, context),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
@@ -333,7 +338,8 @@ class _MessageWidgetState extends State<MessageWidget>
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_streamChannel.channel.config.reactions && nOfAttachmentWidgets > 0) {
|
if (_streamChannel.channel.config?.reactions == true &&
|
||||||
|
nOfAttachmentWidgets > 0) {
|
||||||
column.insert(
|
column.insert(
|
||||||
0,
|
0,
|
||||||
Align(
|
Align(
|
||||||
@@ -991,7 +997,7 @@ class _MessageWidgetState extends State<MessageWidget>
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
bool get wantKeepAlive {
|
bool get wantKeepAlive {
|
||||||
return widget.message.attachments.isNotEmpty;
|
return widget.message.attachments?.isNotEmpty == true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -171,19 +171,6 @@ class StreamChatState extends State<StreamChat> {
|
|||||||
return theme;
|
return theme;
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
|
||||||
void initState() {
|
|
||||||
super.initState();
|
|
||||||
_subscriptions.add(widget.client.on('message.new').listen((Event e) {
|
|
||||||
final index = channels.indexWhere((c) => c.cid == e.cid);
|
|
||||||
if (index > 0) {
|
|
||||||
final channel = channels.removeAt(index);
|
|
||||||
channels.insert(0, channel);
|
|
||||||
_channelsController.add(channels);
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
|
|
||||||
/// The current user
|
/// The current user
|
||||||
User get user => widget.client.state.user;
|
User get user => widget.client.state.user;
|
||||||
|
|
||||||
@@ -191,12 +178,10 @@ class StreamChatState extends State<StreamChat> {
|
|||||||
Stream<User> get userStream => widget.client.state.userStream;
|
Stream<User> get userStream => widget.client.state.userStream;
|
||||||
|
|
||||||
/// The current channel list
|
/// The current channel list
|
||||||
final List<Channel> channels = [];
|
List<Channel> get channels => client.state.channels;
|
||||||
|
|
||||||
/// The current channel list as a stream
|
/// The current channel list as a stream
|
||||||
Stream<List<Channel>> get channelsStream => _channelsController.stream;
|
Stream<List<Channel>> get channelsStream => client.state.channelsStream;
|
||||||
|
|
||||||
final BehaviorSubject<List<Channel>> _channelsController = BehaviorSubject();
|
|
||||||
|
|
||||||
final BehaviorSubject<bool> _queryChannelsLoadingController =
|
final BehaviorSubject<bool> _queryChannelsLoadingController =
|
||||||
BehaviorSubject.seeded(false);
|
BehaviorSubject.seeded(false);
|
||||||
@@ -218,16 +203,12 @@ class StreamChatState extends State<StreamChat> {
|
|||||||
_queryChannelsLoadingController.sink.add(true);
|
_queryChannelsLoadingController.sink.add(true);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
final res = await widget.client.queryChannels(
|
await widget.client.queryChannels(
|
||||||
filter: filter,
|
filter: filter,
|
||||||
sort: sortOptions,
|
sort: sortOptions,
|
||||||
options: options,
|
options: options,
|
||||||
paginationParams: paginationParams,
|
paginationParams: paginationParams,
|
||||||
);
|
);
|
||||||
channels.addAll(res);
|
|
||||||
_channelsController.sink.add(channels);
|
|
||||||
} catch (e) {
|
|
||||||
_channelsController.sink.addError(e);
|
|
||||||
} finally {
|
} finally {
|
||||||
_queryChannelsLoadingController.sink.add(false);
|
_queryChannelsLoadingController.sink.add(false);
|
||||||
}
|
}
|
||||||
@@ -243,7 +224,6 @@ class StreamChatState extends State<StreamChat> {
|
|||||||
widget.client.dispose();
|
widget.client.dispose();
|
||||||
_subscriptions.forEach((s) => s.cancel());
|
_subscriptions.forEach((s) => s.cancel());
|
||||||
_queryChannelsLoadingController.close();
|
_queryChannelsLoadingController.close();
|
||||||
_channelsController.close();
|
|
||||||
super.dispose();
|
super.dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-1
@@ -20,7 +20,8 @@ dependencies:
|
|||||||
file_picker: ^1.4.3+2
|
file_picker: ^1.4.3+2
|
||||||
image_picker: ^0.6.3+4
|
image_picker: ^0.6.3+4
|
||||||
keyboard_visibility: ^0.5.6
|
keyboard_visibility: ^0.5.6
|
||||||
stream_chat: ^0.1.18
|
stream_chat:
|
||||||
|
path: ../stream_chat_dart
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
pedantic: ^1.9.0
|
pedantic: ^1.9.0
|
||||||
|
|||||||
Reference in New Issue
Block a user