Merge pull request #578 from GetStream/delete_message_fix

refactor(ui, core): delete_message
This commit is contained in:
Salvatore Giordano
2021-07-27 18:06:16 +02:00
committed by GitHub
7 changed files with 62 additions and 48 deletions
@@ -4,6 +4,7 @@
- Added `MessageListView.paginationLimit` - Added `MessageListView.paginationLimit`
- Allow the various ListView widgets to be themed via ThemeData classes - Allow the various ListView widgets to be themed via ThemeData classes
- Added `bottomRowBuilder` and `deletedBottomRowBuilder` that build a widget below a `MessageWidget`
🔄 Changed 🔄 Changed
@@ -2,6 +2,7 @@ import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:shimmer/shimmer.dart'; import 'package:shimmer/shimmer.dart';
import 'package:stream_chat_flutter/src/attachment/attachment_widget.dart'; import 'package:stream_chat_flutter/src/attachment/attachment_widget.dart';
import 'package:stream_chat_flutter/src/visible_footnote.dart';
import 'package:stream_chat_flutter/stream_chat_flutter.dart'; import 'package:stream_chat_flutter/stream_chat_flutter.dart';
import 'package:stream_chat_flutter_core/stream_chat_flutter_core.dart'; import 'package:stream_chat_flutter_core/stream_chat_flutter_core.dart';
@@ -216,36 +217,11 @@ class GiphyAttachment extends AttachmentWidget {
), ),
), ),
const SizedBox(height: 4), const SizedBox(height: 4),
Align( const Align(
alignment: Alignment.centerRight, alignment: Alignment.centerRight,
child: Padding( child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4), padding: EdgeInsets.symmetric(horizontal: 8, vertical: 4),
child: Row( child: VisibleFootnote(),
mainAxisSize: MainAxisSize.min,
children: [
StreamSvgIcon.eye(
color: StreamChatTheme.of(context)
.colorTheme
.textHighEmphasis
.withOpacity(0.5),
size: 16,
),
const SizedBox(
width: 8,
),
Text(
'Only visible to you',
style: StreamChatTheme.of(context)
.textTheme
.footnote
.copyWith(
color: StreamChatTheme.of(context)
.colorTheme
.textHighEmphasis
.withOpacity(0.5)),
),
],
),
), ),
), ),
], ],
@@ -92,6 +92,8 @@ class MessageWidget extends StatefulWidget {
this.userAvatarBuilder, this.userAvatarBuilder,
this.editMessageInputBuilder, this.editMessageInputBuilder,
this.textBuilder, this.textBuilder,
this.bottomRowBuilder,
this.deletedBottomRowBuilder,
this.onReturnAction, this.onReturnAction,
Map<String, AttachmentBuilder>? customAttachmentBuilders, Map<String, AttachmentBuilder>? customAttachmentBuilders,
this.readList, this.readList,
@@ -275,6 +277,12 @@ class MessageWidget extends StatefulWidget {
/// Function called on long press /// Function called on long press
final void Function(BuildContext, Message)? onMessageActions; final void Function(BuildContext, Message)? onMessageActions;
/// Widget builder for building a bottom row below the message
final Widget Function(BuildContext, Message)? bottomRowBuilder;
/// Widget builder for building a bottom row below a deleted message
final Widget Function(BuildContext, Message)? deletedBottomRowBuilder;
/// Widget builder for building user avatar /// Widget builder for building user avatar
final Widget Function(BuildContext, User)? userAvatarBuilder; final Widget Function(BuildContext, User)? userAvatarBuilder;
@@ -410,6 +418,8 @@ class MessageWidget extends StatefulWidget {
Widget Function(BuildContext, Message)? editMessageInputBuilder, Widget Function(BuildContext, Message)? editMessageInputBuilder,
Widget Function(BuildContext, Message)? textBuilder, Widget Function(BuildContext, Message)? textBuilder,
Widget Function(BuildContext, Message)? usernameBuilder, Widget Function(BuildContext, Message)? usernameBuilder,
Widget Function(BuildContext, Message)? bottomRowBuilder,
Widget Function(BuildContext, Message)? deletedBottomRowBuilder,
void Function(BuildContext, Message)? onMessageActions, void Function(BuildContext, Message)? onMessageActions,
Message? message, Message? message,
MessageTheme? messageTheme, MessageTheme? messageTheme,
@@ -463,6 +473,9 @@ class MessageWidget extends StatefulWidget {
editMessageInputBuilder ?? this.editMessageInputBuilder, editMessageInputBuilder ?? this.editMessageInputBuilder,
textBuilder: textBuilder ?? this.textBuilder, textBuilder: textBuilder ?? this.textBuilder,
usernameBuilder: usernameBuilder ?? this.usernameBuilder, usernameBuilder: usernameBuilder ?? this.usernameBuilder,
bottomRowBuilder: bottomRowBuilder ?? this.bottomRowBuilder,
deletedBottomRowBuilder:
deletedBottomRowBuilder ?? this.deletedBottomRowBuilder,
onMessageActions: onMessageActions ?? this.onMessageActions, onMessageActions: onMessageActions ?? this.onMessageActions,
message: message ?? this.message, message: message ?? this.message,
messageTheme: messageTheme ?? this.messageTheme, messageTheme: messageTheme ?? this.messageTheme,
@@ -782,7 +795,11 @@ class _MessageWidgetState extends State<MessageWidget>
bottom: bottom:
isPinned && widget.showPinHighlight ? 6.0 : 0.0, isPinned && widget.showPinHighlight ? 6.0 : 0.0,
), ),
child: _bottomRow, child: widget.bottomRowBuilder?.call(
context,
widget.message,
) ??
_bottomRow,
), ),
if (isFailedState) if (isFailedState)
Positioned( Positioned(
@@ -830,22 +847,11 @@ class _MessageWidgetState extends State<MessageWidget>
Widget get _bottomRow { Widget get _bottomRow {
if (isDeleted) { if (isDeleted) {
final chatThemeData = _streamChatTheme; return widget.deletedBottomRowBuilder?.call(
return Row( context,
mainAxisSize: MainAxisSize.min, widget.message,
children: [ ) ??
StreamSvgIcon.eye( const Offstage();
color: chatThemeData.colorTheme.textLowEmphasis,
size: 16,
),
const SizedBox(width: 8),
Text(
'Only visible to you',
style: chatThemeData.textTheme.footnote
.copyWith(color: chatThemeData.colorTheme.textLowEmphasis),
),
],
);
} }
final children = <Widget>[]; final children = <Widget>[];
@@ -0,0 +1,29 @@
import 'package:flutter/material.dart';
import 'package:stream_chat_flutter/src/stream_chat_theme.dart';
import 'package:stream_chat_flutter/stream_chat_flutter.dart';
/// Widget for displaying a footnote
class VisibleFootnote extends StatelessWidget {
/// Constructor for creating a [VisibleFootnote]
const VisibleFootnote({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
final chatThemeData = StreamChatTheme.of(context);
return Row(
mainAxisSize: MainAxisSize.min,
children: [
StreamSvgIcon.eye(
color: chatThemeData.colorTheme.textLowEmphasis,
size: 16,
),
const SizedBox(width: 8),
Text(
'Only visible to you',
style: chatThemeData.textTheme.footnote
.copyWith(color: chatThemeData.colorTheme.textLowEmphasis),
),
],
);
}
}
@@ -42,3 +42,4 @@ export 'src/user_item.dart';
export 'src/user_list_view.dart'; export 'src/user_list_view.dart';
export 'src/user_list_view.dart'; export 'src/user_list_view.dart';
export 'src/utils.dart'; export 'src/utils.dart';
export 'src/visible_footnote.dart';
@@ -1,10 +1,12 @@
## Upcoming ## Upcoming
🛑️ Breaking Changes from `2.0.0`
- Changed default message filter of `MessageListCore`
✅ Added ✅ Added
- Added `MessageListCore.paginationLimit` - Added `MessageListCore.paginationLimit`
🔄 Changed 🔄 Changed
- `StreamChatCore.of(context).user` is now deprecated in favor of `StreamChatCore.of(context).currentUser`. - `StreamChatCore.of(context).user` is now deprecated in favor of `StreamChatCore.of(context).currentUser`.
- `StreamChatCore.of(context).userStream` is now deprecated in favor of `StreamChatCore.of(context).currentUserStream`. - `StreamChatCore.of(context).userStream` is now deprecated in favor of `StreamChatCore.of(context).currentUserStream`.
@@ -134,8 +134,7 @@ class MessageListCoreState extends State<MessageListCore> {
bool defaultFilter(Message m) { bool defaultFilter(Message m) {
final isMyMessage = m.user?.id == _currentUser?.id; final isMyMessage = m.user?.id == _currentUser?.id;
final isDeletedOrShadowed = m.isDeleted == true || m.shadowed == true; if (m.shadowed && !isMyMessage) return false;
if (isDeletedOrShadowed && !isMyMessage) return false;
return true; return true;
} }