Handle onQuotedMessageTap
Signed-off-by: Sahil Kumar <[email protected]>
This commit is contained in:
@@ -181,7 +181,6 @@ class MessageListView extends StatefulWidget {
|
|||||||
class _MessageListViewState extends State<MessageListView> {
|
class _MessageListViewState extends State<MessageListView> {
|
||||||
ItemScrollController _scrollController;
|
ItemScrollController _scrollController;
|
||||||
bool _bottomWasVisible = false;
|
bool _bottomWasVisible = false;
|
||||||
bool _topWasVisible = false;
|
|
||||||
Function _onThreadTap;
|
Function _onThreadTap;
|
||||||
bool _showScrollToBottom = false;
|
bool _showScrollToBottom = false;
|
||||||
ItemPositionsListener _itemPositionListener;
|
ItemPositionsListener _itemPositionListener;
|
||||||
@@ -772,6 +771,17 @@ class _MessageListViewState extends State<MessageListView> {
|
|||||||
bottom: index == 0 ? 30 : (isNextUser ? 2 : 7),
|
bottom: index == 0 ? 30 : (isNextUser ? 2 : 7),
|
||||||
top: 3,
|
top: 3,
|
||||||
),
|
),
|
||||||
|
onQuotedMessageTap: (quotedMessageId) {
|
||||||
|
if (messages.map((e) => e.id).contains(quotedMessageId)) {
|
||||||
|
final index = messages.indexWhere((m) => m.id == quotedMessageId);
|
||||||
|
_scrollController?.scrollTo(
|
||||||
|
index: index,
|
||||||
|
duration: const Duration(milliseconds: 350),
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
streamChannel.loadChannelAtMessage(quotedMessageId);
|
||||||
|
}
|
||||||
|
},
|
||||||
showInChannelIndicator: widget.parentMessage == null,
|
showInChannelIndicator: widget.parentMessage == null,
|
||||||
showThreadReplyIndicator: widget.parentMessage == null,
|
showThreadReplyIndicator: widget.parentMessage == null,
|
||||||
showUsername: !isMyMessage && !isNextUser,
|
showUsername: !isMyMessage && !isNextUser,
|
||||||
|
|||||||
+27
-23
@@ -20,6 +20,7 @@ import 'message_text.dart';
|
|||||||
import 'extension.dart';
|
import 'extension.dart';
|
||||||
|
|
||||||
typedef AttachmentBuilder = Widget Function(BuildContext, Message, Attachment);
|
typedef AttachmentBuilder = Widget Function(BuildContext, Message, Attachment);
|
||||||
|
typedef OnQuotedMessageTap = void Function(String);
|
||||||
|
|
||||||
/// The display behaviour of a widget
|
/// The display behaviour of a widget
|
||||||
enum DisplayWidget {
|
enum DisplayWidget {
|
||||||
@@ -135,6 +136,9 @@ class MessageWidget extends StatefulWidget {
|
|||||||
/// Center user avatar with bottom of the message
|
/// Center user avatar with bottom of the message
|
||||||
final bool translateUserAvatar;
|
final bool translateUserAvatar;
|
||||||
|
|
||||||
|
/// Function called when quotedMessage is tapped
|
||||||
|
final OnQuotedMessageTap onQuotedMessageTap;
|
||||||
|
|
||||||
///
|
///
|
||||||
MessageWidget({
|
MessageWidget({
|
||||||
Key key,
|
Key key,
|
||||||
@@ -177,6 +181,7 @@ class MessageWidget extends StatefulWidget {
|
|||||||
),
|
),
|
||||||
this.attachmentPadding = EdgeInsets.zero,
|
this.attachmentPadding = EdgeInsets.zero,
|
||||||
this.allRead = false,
|
this.allRead = false,
|
||||||
|
this.onQuotedMessageTap,
|
||||||
}) : attachmentBuilders = {
|
}) : attachmentBuilders = {
|
||||||
'image': (context, message, attachment) {
|
'image': (context, message, attachment) {
|
||||||
return ImageAttachment(
|
return ImageAttachment(
|
||||||
@@ -338,8 +343,7 @@ class _MessageWidgetState extends State<MessageWidget> {
|
|||||||
: 0,
|
: 0,
|
||||||
)
|
)
|
||||||
: EdgeInsets.zero,
|
: EdgeInsets.zero,
|
||||||
child:
|
child: (widget.message.isDeleted &&
|
||||||
(widget.message.isDeleted &&
|
|
||||||
!isFailedState)
|
!isFailedState)
|
||||||
? Transform(
|
? Transform(
|
||||||
alignment: Alignment.center,
|
alignment: Alignment.center,
|
||||||
@@ -347,10 +351,9 @@ class _MessageWidgetState extends State<MessageWidget> {
|
|||||||
widget.reverse ? pi : 0),
|
widget.reverse ? pi : 0),
|
||||||
child: DeletedMessage(
|
child: DeletedMessage(
|
||||||
reverse: widget.reverse,
|
reverse: widget.reverse,
|
||||||
borderRadiusGeometry: widget
|
borderRadiusGeometry:
|
||||||
.borderRadiusGeometry,
|
widget.borderRadiusGeometry,
|
||||||
borderSide:
|
borderSide: widget.borderSide,
|
||||||
widget.borderSide,
|
|
||||||
shape: widget.shape,
|
shape: widget.shape,
|
||||||
messageTheme:
|
messageTheme:
|
||||||
widget.messageTheme,
|
widget.messageTheme,
|
||||||
@@ -400,25 +403,11 @@ class _MessageWidgetState extends State<MessageWidget> {
|
|||||||
MainAxisSize.min,
|
MainAxisSize.min,
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
if (_hasQuotedMessage)
|
if (_hasQuotedMessage)
|
||||||
QuotedMessageWidget(
|
_buildQuotedMessage(
|
||||||
onTap: () {},
|
isMyMessage),
|
||||||
message: widget
|
|
||||||
.message
|
|
||||||
.quotedMessage,
|
|
||||||
messageTheme: isMyMessage
|
|
||||||
? StreamChatTheme.of(
|
|
||||||
context)
|
|
||||||
.otherMessageTheme
|
|
||||||
: StreamChatTheme.of(
|
|
||||||
context)
|
|
||||||
.ownMessageTheme,
|
|
||||||
reverse: widget
|
|
||||||
.reverse,
|
|
||||||
),
|
|
||||||
..._parseAttachments(
|
..._parseAttachments(
|
||||||
context),
|
context),
|
||||||
if (widget
|
if (widget.message.text
|
||||||
.message.text
|
|
||||||
.trim()
|
.trim()
|
||||||
.isNotEmpty &&
|
.isNotEmpty &&
|
||||||
!isGiphy)
|
!isGiphy)
|
||||||
@@ -480,6 +469,21 @@ class _MessageWidgetState extends State<MessageWidget> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Widget _buildQuotedMessage(bool isMyMessage) {
|
||||||
|
return QuotedMessageWidget(
|
||||||
|
onTap: () {
|
||||||
|
if (widget.onQuotedMessageTap != null) {
|
||||||
|
widget.onQuotedMessageTap(widget.message.quotedMessageId);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
message: widget.message.quotedMessage,
|
||||||
|
messageTheme: isMyMessage
|
||||||
|
? StreamChatTheme.of(context).otherMessageTheme
|
||||||
|
: StreamChatTheme.of(context).ownMessageTheme,
|
||||||
|
reverse: widget.reverse,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
Widget _buildBottomRow(double leftPadding) {
|
Widget _buildBottomRow(double leftPadding) {
|
||||||
final deleted = widget.message.isDeleted;
|
final deleted = widget.message.isDeleted;
|
||||||
var children = <Widget>[];
|
var children = <Widget>[];
|
||||||
|
|||||||
Reference in New Issue
Block a user