message refactoring

This commit is contained in:
Salvatore Giordano
2020-03-08 11:04:11 +01:00
parent 456e345558
commit ffac94fc2f
3 changed files with 424 additions and 390 deletions
+1 -1
View File
@@ -116,7 +116,7 @@ class ChannelPreview extends StatelessWidget {
} }
String text; String text;
if (lastMessage.type == 'deleted') { if (lastMessage.isDeleted) {
text = 'This message was deleted.'; text = 'This message was deleted.';
} else { } else {
final prefix = lastMessage.attachments final prefix = lastMessage.attachments
+2 -2
View File
@@ -320,8 +320,8 @@ class _MessageListViewState extends State<MessageListView> {
if (widget.parentMessage == null) { if (widget.parentMessage == null) {
stream = streamChannel.channel.state.messagesStream.map((messages) => stream = streamChannel.channel.state.messagesStream.map((messages) =>
messages messages
.where((m) => !(m.status == MessageSendingStatus.FAILED && .where((m) =>
m.type == 'deleted')) !(m.status == MessageSendingStatus.FAILED && m.isDeleted))
.toList()); .toList());
} else { } else {
streamChannel.getReplies(widget.parentMessage.id); streamChannel.getReplies(widget.parentMessage.id);
+324 -290
View File
@@ -70,62 +70,81 @@ class _MessageWidgetState extends State<MessageWidget>
final Map<String, ChangeNotifier> _videoControllers = {}; final Map<String, ChangeNotifier> _videoControllers = {};
final Map<String, ChangeNotifier> _chuwieControllers = {}; final Map<String, ChangeNotifier> _chuwieControllers = {};
MessageTheme messageTheme; MessageTheme _messageTheme;
StreamChatState streamChat; StreamChatState _streamChat;
StreamChannelState streamChannel; StreamChannelState _streamChannel;
bool isMyMessage; bool _isMyMessage;
String _currentUserId;
String _messageUserId;
String _previousUserId;
String _nextUserId;
bool _isLastUser;
bool _isNextUser;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
super.build(context); super.build(context);
streamChat = StreamChat.of(context); _messageTheme = _isMyMessage
streamChannel = StreamChannel.of(context);
final currentUserId = streamChat.client.state.user.id;
final messageUserId = widget.message.user.id;
final previousUserId = widget.previousMessage?.user?.id;
final nextUserId = widget.nextMessage?.user?.id;
final isLastUser = previousUserId == messageUserId;
final isNextUser = nextUserId == messageUserId;
isMyMessage = messageUserId == currentUserId;
final alignment =
isMyMessage ? Alignment.centerRight : Alignment.centerLeft;
messageTheme = isMyMessage
? StreamChatTheme.of(context).ownMessageTheme ? StreamChatTheme.of(context).ownMessageTheme
: StreamChatTheme.of(context).otherMessageTheme; : StreamChatTheme.of(context).otherMessageTheme;
Widget child; final alignment =
_isMyMessage ? Alignment.centerRight : Alignment.centerLeft;
var row = <Widget>[ List<Widget> row = <Widget>[
Column( Column(
crossAxisAlignment: crossAxisAlignment:
isMyMessage ? CrossAxisAlignment.end : CrossAxisAlignment.start, _isMyMessage ? CrossAxisAlignment.end : CrossAxisAlignment.start,
children: <Widget>[ children: <Widget>[
widget.message.type == 'deleted' widget.message.isDeleted
? _buildDeletedMessage(alignment) ? _buildDeletedMessage(alignment)
: _buildBubble(context, isLastUser), : _buildBubble(context),
streamChannel.channel.config.replies if (_streamChannel.channel.config.replies)
? _buildThreadIndicator(context) _buildThreadIndicator(context),
: SizedBox(), if (!_isNextUser) _buildTimestamp(alignment),
isNextUser ? SizedBox() : _buildTimestamp(alignment),
], ],
), ),
isNextUser _isNextUser
? Container( ? Container(
width: 40, width: 40,
) )
: Padding( : _buildUserAvatar(),
];
if (!_isMyMessage) {
row = row.reversed.toList();
}
return Container(
padding: EdgeInsets.symmetric(
horizontal: (_isMyMessage && widget.nextMessage == null) ? 0.0 : 10,
),
margin: EdgeInsets.only(
top: _isLastUser ? 5 : 24,
bottom: widget.nextMessage == null ? 30 : 0,
),
child: Row(
crossAxisAlignment: CrossAxisAlignment.end,
mainAxisAlignment:
_isMyMessage ? MainAxisAlignment.end : MainAxisAlignment.start,
mainAxisSize: MainAxisSize.max,
children: row,
),
);
}
Padding _buildUserAvatar() {
return Padding(
padding: EdgeInsets.only( padding: EdgeInsets.only(
left: isMyMessage ? 8.0 : 0, left: _isMyMessage ? 8.0 : 0,
right: isMyMessage ? 0 : 8.0, right: _isMyMessage ? 0 : 8.0,
), ),
child: Row( child: Row(
children: <Widget>[ children: <Widget>[
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)
Padding( Padding(
@@ -140,7 +159,7 @@ class _MessageWidgetState extends State<MessageWidget>
), ),
), ),
), ),
if (isMyMessage && if (_isMyMessage &&
widget.message.status == MessageSendingStatus.SENDING) widget.message.status == MessageSendingStatus.SENDING)
Padding( Padding(
padding: const EdgeInsets.symmetric( padding: const EdgeInsets.symmetric(
@@ -156,7 +175,7 @@ class _MessageWidgetState extends State<MessageWidget>
), ),
), ),
), ),
if (isMyMessage && if (_isMyMessage &&
widget.message.status == MessageSendingStatus.FAILED) widget.message.status == MessageSendingStatus.FAILED)
Padding( Padding(
padding: const EdgeInsets.symmetric( padding: const EdgeInsets.symmetric(
@@ -174,33 +193,24 @@ class _MessageWidgetState extends State<MessageWidget>
), ),
], ],
), ),
), );
];
if (!isMyMessage) {
row = row.reversed.toList();
} }
child = Container( @override
padding: EdgeInsets.symmetric( void initState() {
horizontal: (isMyMessage && widget.nextMessage == null) ? 0.0 : 10), super.initState();
margin: EdgeInsets.only(
top: isLastUser ? 5 : 24,
bottom: widget.nextMessage == null ? 30 : 0,
),
child: Row(
crossAxisAlignment: CrossAxisAlignment.end,
mainAxisAlignment:
isMyMessage ? MainAxisAlignment.end : MainAxisAlignment.start,
mainAxisSize: MainAxisSize.max,
children: row,
),
);
return AnimatedSwitcher( _streamChat = StreamChat.of(context);
duration: Duration(milliseconds: 300), _streamChannel = StreamChannel.of(context);
child: child,
); _currentUserId = _streamChat.client.state.user.id;
_messageUserId = widget.message.user.id;
_previousUserId = widget.previousMessage?.user?.id;
_nextUserId = widget.nextMessage?.user?.id;
_isLastUser = _previousUserId == _messageUserId;
_isNextUser = _nextUserId == _messageUserId;
_isMyMessage = _messageUserId == _currentUserId;
} }
Align _buildDeletedMessage(Alignment alignment) { Align _buildDeletedMessage(Alignment alignment) {
@@ -213,7 +223,7 @@ class _MessageWidgetState extends State<MessageWidget>
), ),
child: Text( child: Text(
'This message was deleted...', 'This message was deleted...',
style: messageTheme.messageText.copyWith( style: _messageTheme.messageText.copyWith(
fontStyle: FontStyle.italic, fontStyle: FontStyle.italic,
color: Colors.black, color: Colors.black,
), ),
@@ -226,10 +236,10 @@ class _MessageWidgetState extends State<MessageWidget>
var row = [ var row = [
Text( Text(
'Replies: ${widget.message.replyCount}', 'Replies: ${widget.message.replyCount}',
style: messageTheme.replies, style: _messageTheme.replies,
), ),
Transform( Transform(
transform: Matrix4.rotationY(isMyMessage ? 0 : pi), transform: Matrix4.rotationY(_isMyMessage ? 0 : pi),
alignment: Alignment.center, alignment: Alignment.center,
child: Icon( child: Icon(
Icons.subdirectory_arrow_left, Icons.subdirectory_arrow_left,
@@ -238,7 +248,7 @@ class _MessageWidgetState extends State<MessageWidget>
), ),
]; ];
if (!isMyMessage) { if (!_isMyMessage) {
row = row.reversed.toList(); row = row.reversed.toList();
} }
@@ -264,26 +274,127 @@ class _MessageWidgetState extends State<MessageWidget>
Widget _buildBubble( Widget _buildBubble(
BuildContext context, BuildContext context,
bool isLastUser,
) { ) {
var nOfAttachmentWidgets = 0; var nOfAttachmentWidgets = 0;
final column = Column( final column =
crossAxisAlignment: List<Widget>.from(widget.message.attachments.map((attachment) {
isMyMessage ? CrossAxisAlignment.end : CrossAxisAlignment.start,
children: 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, isLastUser); attachmentWidget = _buildVideo(attachment);
} else if (attachment.type == 'image' || attachment.type == 'giphy') { } else if (attachment.type == 'image' || attachment.type == 'giphy') {
attachmentWidget = _buildImage(isLastUser, attachment); attachmentWidget = _buildImage(attachment);
} }
if (attachmentWidget != null) { if (attachmentWidget != null) {
final boxDecoration = _buildBoxDecoration(isLastUser) return _buildAttachment(
.copyWith(color: Color(0xffebebeb)); attachmentWidget,
attachment,
nOfAttachmentWidgets,
context,
);
}
nOfAttachmentWidgets--;
return SizedBox();
}));
if (widget.message.text.trim().isNotEmpty) {
String text = widget.message.text;
text = _replaceMentions(text);
column.addAll(
<Widget>[
Column(
crossAxisAlignment: _isMyMessage
? CrossAxisAlignment.end
: CrossAxisAlignment.start,
children: <Widget>[
if (_streamChannel.channel.config.reactions &&
nOfAttachmentWidgets == 0)
Align(
child: _buildReactions(),
alignment: _isMyMessage
? Alignment.centerLeft
: Alignment.centerRight,
),
Stack(
overflow: Overflow.visible,
children: <Widget>[
if (nOfAttachmentWidgets == 0) _buildReactionPaint(),
_buildMessageText(nOfAttachmentWidgets, text, context),
],
),
],
),
],
);
}
if (_streamChannel.channel.config.reactions && nOfAttachmentWidgets > 0) {
column.insert(
0,
Align(
child: _buildReactions(),
alignment:
_isMyMessage ? Alignment.centerLeft : Alignment.centerRight,
),
);
column[1] = Stack(
overflow: Overflow.visible,
children: <Widget>[
Padding(
padding: EdgeInsets.only(
right: _isMyMessage ? 0.0 : 8.0,
left: _isMyMessage ? 8.0 : 0.0,
),
child: column[1],
),
_buildReactionPaint(),
],
);
}
return GestureDetector(
child: IntrinsicWidth(
child: Column(
children: column,
crossAxisAlignment:
_isMyMessage ? CrossAxisAlignment.end : CrossAxisAlignment.start,
),
),
onTap: () {
if (widget.message.status == MessageSendingStatus.FAILED) {
StreamChannel.of(context).channel.sendMessage(widget.message);
return;
}
},
onLongPress: () {
if (widget.message.isEphemeral ||
widget.message.status == MessageSendingStatus.SENDING) {
return;
}
if (widget.onMessageActions != null) {
widget.onMessageActions(context, widget.message);
} else {
_showMessageBottomSheet(context);
}
},
);
}
Padding _buildAttachment(
Widget attachmentWidget,
Attachment attachment,
int nOfAttachmentWidgets,
BuildContext context,
) {
final boxDecoration = _buildBoxDecoration(_isLastUser).copyWith(
color: Color(0xffebebeb),
);
return Padding( return Padding(
padding: const EdgeInsets.only(bottom: 2.0), padding: const EdgeInsets.only(bottom: 2.0),
child: Column( child: Column(
@@ -301,69 +412,13 @@ class _MessageWidgetState extends State<MessageWidget>
crossAxisAlignment: CrossAxisAlignment.stretch, crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[ children: <Widget>[
attachmentWidget, attachmentWidget,
attachment.title != null if (attachment.title != null)
? GestureDetector( _buildAttachmentTitle(attachment),
onTap: () {
if (attachment.titleLink != null) {
_launchURL(attachment.titleLink);
}
},
child: Container(
constraints:
BoxConstraints.loose(Size(300, 500)),
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment:
CrossAxisAlignment.start,
children: <Widget>[
Text(
attachment.title,
overflow: TextOverflow.ellipsis,
style: messageTheme.messageText
.copyWith(
color: Colors.blue,
fontWeight: FontWeight.bold,
),
),
if (attachment.titleLink != null ||
attachment.ogScrapeUrl != null)
Text(
Uri.parse(attachment
.titleLink ??
attachment.ogScrapeUrl)
.authority
.split('.')
.reversed
.take(2)
.toList()
.reversed
.join('.'),
overflow: TextOverflow.ellipsis,
style: messageTheme.createdAt,
),
], ],
), ),
), if (attachment.type == 'image' &&
color: Color(0xffebebeb), attachment.titleLink != null)
), _buildPreviewInkwell(attachment),
)
: SizedBox(),
],
),
attachment.type == 'image' &&
attachment.titleLink != null
? Positioned.fill(
child: Material(
color: Colors.transparent,
child: InkWell(
onTap: () =>
_launchURL(attachment.titleLink),
),
),
)
: SizedBox(),
], ],
), ),
margin: EdgeInsets.only( margin: EdgeInsets.only(
@@ -372,105 +427,35 @@ class _MessageWidgetState extends State<MessageWidget>
), ),
), ),
if (attachment.actions != null) if (attachment.actions != null)
Row( _buildAttachmentActions(attachment, context),
mainAxisAlignment: MainAxisAlignment.end,
children: attachment.actions?.map((action) {
if (action.style == 'primary') {
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 4.0),
child: FlatButton(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(16),
),
child: Text('${action.text}'),
color: action.style == 'primary'
? StreamChatTheme.of(context).accentColor
: null,
textColor: Colors.white,
onPressed: () {
streamChannel.channel
.sendAction(widget.message.id, {
action.name: action.value,
});
},
),
);
}
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 4.0),
child: OutlineButton(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(16),
),
child: Text('${action.text}'),
color: StreamChatTheme.of(context).accentColor,
onPressed: () {
streamChannel.channel
.sendAction(widget.message.id, {
action.name: action.value,
});
},
),
);
})?.toList(),
),
], ],
), ),
); );
} }
nOfAttachmentWidgets--; Padding _buildMessageText(
return SizedBox(); int nOfAttachmentWidgets,
})), String text,
); BuildContext context,
) {
if (widget.message.text.trim().isNotEmpty) { return Padding(
String text = widget.message.text;
widget.message.mentionedUsers?.forEach((u) {
text = text.replaceAll(
'@${u.name}', '[@${u.name}](@${u.name.replaceAll(' ', '')})');
});
column.children.addAll(
<Widget>[
Column(
crossAxisAlignment:
isMyMessage ? CrossAxisAlignment.end : CrossAxisAlignment.start,
children: <Widget>[
(streamChannel.channel.config.reactions &&
nOfAttachmentWidgets == 0)
? Align(
child: _buildReactions(),
alignment: isMyMessage
? Alignment.centerLeft
: Alignment.centerRight,
)
: SizedBox(),
Stack(
overflow: Overflow.visible,
children: <Widget>[
nOfAttachmentWidgets == 0
? _buildReactionPaint()
: SizedBox(),
Padding(
padding: EdgeInsets.only( padding: EdgeInsets.only(
right: isMyMessage ? 0.0 : 8.0, right: _isMyMessage ? 0.0 : 8.0,
left: isMyMessage ? 8.0 : 0.0, left: _isMyMessage ? 8.0 : 0.0,
), ),
child: Container( child: Container(
decoration: _buildBoxDecoration( decoration:
isLastUser || nOfAttachmentWidgets > 0), _buildBoxDecoration(_isLastUser || nOfAttachmentWidgets > 0),
padding: EdgeInsets.all(10), padding: EdgeInsets.all(10),
constraints: BoxConstraints.loose(Size.fromWidth(300)), constraints: BoxConstraints.loose(Size.fromWidth(300)),
child: Column( child: Column(
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[ children: <Widget>[
if (widget.message.status == if (widget.message.status == MessageSendingStatus.FAILED)
MessageSendingStatus.FAILED)
Text( Text(
'MESSAGE FAILED · CLICK TO TRY AGAIN', 'MESSAGE FAILED · CLICK TO TRY AGAIN',
style: TextStyle( style: _messageTheme.messageText.copyWith(
color: Colors.black.withOpacity(.5), color: Colors.black.withOpacity(.5),
fontSize: 11, fontSize: 11,
), ),
@@ -481,8 +466,7 @@ class _MessageWidgetState extends State<MessageWidget>
if (link.startsWith('@')) { if (link.startsWith('@')) {
final mentionedUser = final mentionedUser =
widget.message.mentionedUsers.firstWhere( widget.message.mentionedUsers.firstWhere(
(u) => (u) => '@${u.name.replaceAll(' ', '')}' == link,
'@${u.name.replaceAll(' ', '')}' == link,
orElse: () => null, orElse: () => null,
); );
@@ -498,86 +482,137 @@ class _MessageWidgetState extends State<MessageWidget>
styleSheet: MarkdownStyleSheet.fromTheme( styleSheet: MarkdownStyleSheet.fromTheme(
Theme.of(context).copyWith( Theme.of(context).copyWith(
textTheme: Theme.of(context).textTheme.apply( textTheme: Theme.of(context).textTheme.apply(
bodyColor: messageTheme.messageText.color, bodyColor: _messageTheme.messageText.color,
decoration: decoration: _messageTheme.messageText.decoration,
messageTheme.messageText.decoration, decorationColor:
decorationColor: messageTheme _messageTheme.messageText.decorationColor,
.messageText.decorationColor, decorationStyle:
decorationStyle: messageTheme _messageTheme.messageText.decorationStyle,
.messageText.decorationStyle, fontFamily: _messageTheme.messageText.fontFamily,
fontFamily:
messageTheme.messageText.fontFamily,
), ),
), ),
).copyWith( ).copyWith(
p: messageTheme.messageText, p: _messageTheme.messageText,
), ),
), ),
], ],
), ),
), ),
),
],
),
],
),
],
); );
} }
if (nOfAttachmentWidgets > 0) { String _replaceMentions(String text) {
column.children.insert( widget.message.mentionedUsers?.forEach((u) {
0, text = text.replaceAll(
streamChannel.channel.config.reactions '@${u.name}', '[@${u.name}](@${u.name.replaceAll(' ', '')})');
? Align( });
child: _buildReactions(), return text;
alignment: }
isMyMessage ? Alignment.centerLeft : Alignment.centerRight,
) Row _buildAttachmentActions(Attachment attachment, BuildContext context) {
: SizedBox(), return Row(
mainAxisAlignment: MainAxisAlignment.end,
children: attachment.actions?.map((action) {
if (action.style == 'primary') {
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 4.0),
child: FlatButton(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(16),
),
child: Text('${action.text}'),
color: action.style == 'primary'
? StreamChatTheme.of(context).accentColor
: null,
textColor: Colors.white,
onPressed: () {
_streamChannel.channel.sendAction(widget.message.id, {
action.name: action.value,
});
},
),
); );
column.children[1] = Stack( }
overflow: Overflow.visible, return Padding(
children: <Widget>[ padding: const EdgeInsets.symmetric(horizontal: 4.0),
Padding( child: OutlineButton(
padding: EdgeInsets.only( shape: RoundedRectangleBorder(
right: isMyMessage ? 0.0 : 8.0, borderRadius: BorderRadius.circular(16),
left: isMyMessage ? 8.0 : 0.0,
), ),
child: column.children[1], child: Text('${action.text}'),
color: StreamChatTheme.of(context).accentColor,
onPressed: () {
_streamChannel.channel.sendAction(widget.message.id, {
action.name: action.value,
});
},
), ),
_buildReactionPaint(), );
], })?.toList(),
); );
} }
Positioned _buildPreviewInkwell(Attachment attachment) {
return Positioned.fill(
child: Material(
color: Colors.transparent,
child: InkWell(
onTap: () => _launchURL(attachment.titleLink),
),
),
);
}
GestureDetector _buildAttachmentTitle(Attachment attachment) {
return GestureDetector( return GestureDetector(
child: IntrinsicWidth(child: column),
onTap: () { onTap: () {
if (widget.message.status == MessageSendingStatus.FAILED) { if (attachment.titleLink != null) {
StreamChannel.of(context).channel.sendMessage(widget.message); _launchURL(attachment.titleLink);
return;
} }
}, },
onLongPress: () { child: Container(
if (widget.message.type == 'ephemeral' || constraints: BoxConstraints.loose(Size(300, 500)),
widget.message.status == MessageSendingStatus.SENDING) { child: Padding(
return; padding: const EdgeInsets.all(8.0),
} child: Column(
mainAxisSize: MainAxisSize.min,
if (widget.onMessageActions != null) { crossAxisAlignment: CrossAxisAlignment.start,
widget.onMessageActions(context, widget.message); children: <Widget>[
} else { Text(
_showMessageBottomSheet(context); attachment.title,
} overflow: TextOverflow.ellipsis,
}); style: _messageTheme.messageText.copyWith(
color: Colors.blue,
fontWeight: FontWeight.bold,
),
),
if (attachment.titleLink != null ||
attachment.ogScrapeUrl != null)
Text(
Uri.parse(attachment.titleLink ?? attachment.ogScrapeUrl)
.authority
.split('.')
.reversed
.take(2)
.toList()
.reversed
.join('.'),
overflow: TextOverflow.ellipsis,
style: _messageTheme.createdAt,
),
],
),
),
color: Color(0xffebebeb),
),
);
} }
Widget _buildReactionPaint() { Widget _buildReactionPaint() {
return widget.message.reactionCounts?.isNotEmpty == true return widget.message.reactionCounts?.isNotEmpty == true
? Positioned( ? Positioned(
left: isMyMessage ? 8 : null, left: _isMyMessage ? 8 : null,
right: !isMyMessage ? 8 : null, right: !_isMyMessage ? 8 : null,
top: -6, top: -6,
child: CustomPaint( child: CustomPaint(
painter: _ReactionBubblePainter(), painter: _ReactionBubblePainter(),
@@ -587,8 +622,8 @@ class _MessageWidgetState extends State<MessageWidget>
} }
void _showMessageBottomSheet(BuildContext context) { void _showMessageBottomSheet(BuildContext context) {
if (!streamChannel.channel.config.reactions && if (!_streamChannel.channel.config.reactions &&
!streamChannel.channel.config.replies) { !_streamChannel.channel.config.replies) {
return; return;
} }
@@ -611,7 +646,7 @@ class _MessageWidgetState extends State<MessageWidget>
children: <Widget>[ children: <Widget>[
Container( Container(
color: Colors.black87, color: Colors.black87,
child: (streamChannel.channel.config.reactions && child: (_streamChannel.channel.config.reactions &&
widget.message.status != MessageSendingStatus.FAILED) widget.message.status != MessageSendingStatus.FAILED)
? ReactionPicker( ? ReactionPicker(
channel: StreamChannel.of(context).channel, channel: StreamChannel.of(context).channel,
@@ -620,7 +655,7 @@ class _MessageWidgetState extends State<MessageWidget>
) )
: SizedBox(), : SizedBox(),
), ),
isMyMessage _isMyMessage
? FlatButton( ? FlatButton(
child: Padding( child: Padding(
padding: const EdgeInsets.all(28.0), padding: const EdgeInsets.all(28.0),
@@ -634,12 +669,12 @@ class _MessageWidgetState extends State<MessageWidget>
Navigator.pop(context); Navigator.pop(context);
StreamChat.of(context).client.deleteMessage( StreamChat.of(context).client.deleteMessage(
widget.message, widget.message,
streamChannel.channel.cid, _streamChannel.channel.cid,
); );
}, },
) )
: SizedBox(), : SizedBox(),
isMyMessage _isMyMessage
? FlatButton( ? FlatButton(
child: Padding( child: Padding(
padding: const EdgeInsets.all(28.0), padding: const EdgeInsets.all(28.0),
@@ -655,7 +690,7 @@ class _MessageWidgetState extends State<MessageWidget>
}, },
) )
: SizedBox(), : SizedBox(),
(streamChannel.channel.config.replies && (_streamChannel.channel.config.replies &&
widget.message.status != MessageSendingStatus.FAILED && widget.message.status != MessageSendingStatus.FAILED &&
widget.message.parentId == null && widget.message.parentId == null &&
!widget.isParent) !widget.isParent)
@@ -692,7 +727,7 @@ class _MessageWidgetState extends State<MessageWidget>
), ),
builder: (context) { builder: (context) {
return StreamChannel( return StreamChannel(
channel: streamChannel.channel, channel: _streamChannel.channel,
child: Flex( child: Flex(
direction: Axis.vertical, direction: Axis.vertical,
mainAxisAlignment: MainAxisAlignment.end, mainAxisAlignment: MainAxisAlignment.end,
@@ -834,7 +869,6 @@ class _MessageWidgetState extends State<MessageWidget>
}; };
Widget _buildImage( Widget _buildImage(
bool isLastUser,
Attachment attachment, Attachment attachment,
) { ) {
return CachedNetworkImage( return CachedNetworkImage(
@@ -859,7 +893,6 @@ class _MessageWidgetState extends State<MessageWidget>
Widget _buildVideo( Widget _buildVideo(
Attachment attachment, Attachment attachment,
bool isLastUser,
) { ) {
VideoPlayerController videoController; VideoPlayerController videoController;
if (_videoControllers.containsKey(attachment.assetUrl)) { if (_videoControllers.containsKey(attachment.assetUrl)) {
@@ -934,24 +967,25 @@ class _MessageWidgetState extends State<MessageWidget>
child: widget.message.createdAt != null child: widget.message.createdAt != null
? Text( ? Text(
Jiffy(widget.message.createdAt.toLocal()).format('HH:mm'), Jiffy(widget.message.createdAt.toLocal()).format('HH:mm'),
style: messageTheme.createdAt, style: _messageTheme.createdAt,
) )
: SizedBox(), : SizedBox(),
); );
} }
BoxDecoration _buildBoxDecoration(bool isLastUser) { BoxDecoration _buildBoxDecoration(bool rectBorders) {
return BoxDecoration( return BoxDecoration(
border: isMyMessage ? null : Border.all(color: Colors.black.withAlpha(8)), border:
_isMyMessage ? null : Border.all(color: Colors.black.withAlpha(8)),
borderRadius: BorderRadius.only( borderRadius: BorderRadius.only(
topLeft: Radius.circular((isMyMessage || !isLastUser) ? 16 : 2), topLeft: Radius.circular((_isMyMessage || !rectBorders) ? 16 : 2),
bottomLeft: Radius.circular(isMyMessage ? 16 : 2), bottomLeft: Radius.circular(_isMyMessage ? 16 : 2),
topRight: Radius.circular((isMyMessage && isLastUser) ? 2 : 16), topRight: Radius.circular((_isMyMessage && rectBorders) ? 2 : 16),
bottomRight: Radius.circular(isMyMessage ? 2 : 16), bottomRight: Radius.circular(_isMyMessage ? 2 : 16),
), ),
color: widget.message.status == MessageSendingStatus.FAILED color: widget.message.status == MessageSendingStatus.FAILED
? Color(0xffd0021B).withAlpha(26) ? Color(0xffd0021B).withAlpha(26)
: messageTheme.messageBackgroundColor, : _messageTheme.messageBackgroundColor,
); );
} }