Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ui): added edited label to messages #2032

Merged
merged 5 commits into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions packages/stream_chat/lib/src/core/models/message.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class Message extends Equatable {
this.localUpdatedAt,
DateTime? deletedAt,
this.localDeletedAt,
this.messageTextUpdatedAt,
this.user,
this.pinned = false,
this.pinnedAt,
Expand Down Expand Up @@ -192,6 +193,10 @@ class Message extends Equatable {
@JsonKey(includeToJson: false)
DateTime? get deletedAt => localDeletedAt ?? remoteDeletedAt;

/// Reserved field indicating when the message text was edited.
@JsonKey(includeToJson: false)
final DateTime? messageTextUpdatedAt;

/// Indicates when the message was deleted locally.
@JsonKey(includeToJson: false, includeFromJson: false)
final DateTime? localDeletedAt;
Expand Down Expand Up @@ -265,6 +270,7 @@ class Message extends Equatable {
'created_at',
'updated_at',
'deleted_at',
'message_text_updated_at',
'user',
'pinned',
'pinned_at',
Expand Down Expand Up @@ -304,6 +310,7 @@ class Message extends Equatable {
DateTime? localUpdatedAt,
DateTime? deletedAt,
DateTime? localDeletedAt,
DateTime? messageTextUpdatedAt,
User? user,
bool? pinned,
DateTime? pinnedAt,
Expand Down Expand Up @@ -373,6 +380,7 @@ class Message extends Equatable {
localUpdatedAt: localUpdatedAt ?? this.localUpdatedAt,
deletedAt: deletedAt ?? remoteDeletedAt,
localDeletedAt: localDeletedAt ?? this.localDeletedAt,
messageTextUpdatedAt: messageTextUpdatedAt ?? this.messageTextUpdatedAt,
user: user ?? this.user,
pinned: pinned ?? this.pinned,
pinnedAt: pinnedAt ?? this.pinnedAt,
Expand Down Expand Up @@ -413,6 +421,7 @@ class Message extends Equatable {
localUpdatedAt: other.localUpdatedAt,
deletedAt: other.remoteDeletedAt,
localDeletedAt: other.localDeletedAt,
messageTextUpdatedAt: other.messageTextUpdatedAt,
user: other.user,
pinned: other.pinned,
pinnedAt: other.pinnedAt,
Expand Down Expand Up @@ -472,6 +481,7 @@ class Message extends Equatable {
remoteUpdatedAt,
localDeletedAt,
remoteDeletedAt,
messageTextUpdatedAt,
user,
pinned,
pinnedAt,
Expand Down
3 changes: 3 additions & 0 deletions packages/stream_chat/lib/src/core/models/message.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions packages/stream_chat_flutter/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## Upcoming

✅ Added

- Messages by default now show an "Edited" label if text is edited. Use `showEditedLabel` to disable this functionality.

## 8.1.0

🐞 Fixed
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import UIKit
import Flutter

@UIApplicationMain
@main
@objc class AppDelegate: FlutterAppDelegate {
override func application(
_ application: UIApplication,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ abstract class Translations {
/// The label for message deleted
String get messageDeletedLabel;

/// The label for showing the message is edited
String get editedMessageLabel;

/// The label for message reactions
String get messageReactionsLabel;

Expand Down Expand Up @@ -455,6 +458,9 @@ class DefaultTranslations implements Translations {
@override
String get messageDeletedLabel => 'Message deleted';

@override
String get editedMessageLabel => 'Edited';

@override
String get messageReactionsLabel => 'Message Reactions';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class BottomRow extends StatelessWidget {
required this.showInChannel,
required this.showTimeStamp,
required this.showUsername,
required this.showEditedLabel,
required this.reverse,
required this.showSendingIndicator,
required this.hasUrlAttachments,
Expand Down Expand Up @@ -56,6 +57,9 @@ class BottomRow extends StatelessWidget {
/// {@macro showUsername}
final bool showUsername;

/// {@macro showEdited}
final bool showEditedLabel;

/// {@macro reverse}
final bool reverse;

Expand Down Expand Up @@ -104,6 +108,7 @@ class BottomRow extends StatelessWidget {
bool? showInChannel,
bool? showTimeStamp,
bool? showUsername,
bool? showEditedLabel,
bool? reverse,
bool? showSendingIndicator,
bool? hasUrlAttachments,
Expand All @@ -127,6 +132,7 @@ class BottomRow extends StatelessWidget {
showInChannel: showInChannel ?? this.showInChannel,
showTimeStamp: showTimeStamp ?? this.showTimeStamp,
showUsername: showUsername ?? this.showUsername,
showEditedLabel: showEditedLabel ?? this.showEditedLabel,
reverse: reverse ?? this.reverse,
showSendingIndicator: showSendingIndicator ?? this.showSendingIndicator,
hasUrlAttachments: hasUrlAttachments ?? this.hasUrlAttachments,
Expand Down Expand Up @@ -156,6 +162,7 @@ class BottomRow extends StatelessWidget {
final threadParticipants = message.threadParticipants?.take(2);
final showThreadParticipants = threadParticipants?.isNotEmpty == true;
final replyCount = message.replyCount;
final isEdited = message.messageTextUpdatedAt != null;

var msg = context.translations.threadReplyLabel;
if (showThreadReplyIndicator && replyCount! > 1) {
Expand Down Expand Up @@ -185,6 +192,11 @@ class BottomRow extends StatelessWidget {
message: message,
messageTheme: messageTheme,
),
if (showEditedLabel && isEdited)
Text(
context.translations.editedMessageLabel,
style: messageTheme.createdAtStyle,
),
if (showTimeStamp)
Text(
Jiffy.parseFromDateTime(message.createdAt.toLocal()).jm,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class StreamMessageWidget extends StatefulWidget {
this.onConfirmDeleteTap,
this.showUsername = true,
this.showTimestamp = true,
this.showEditedLabel = true,
this.showReactions = true,
this.showDeleteMessage = true,
this.showEditMessage = true,
Expand Down Expand Up @@ -268,6 +269,11 @@ class StreamMessageWidget extends StatefulWidget {
/// {@endtemplate}
final bool showTimestamp;

/// {@template showTimestamp}
/// Show edited label if message is edited
/// {@endtemplate}
final bool showEditedLabel;

/// {@template showReplyMessage}
/// Show reply action
/// {@endtemplate}
Expand Down Expand Up @@ -415,6 +421,7 @@ class StreamMessageWidget extends StatefulWidget {
ShowMessageCallback? onShowMessage,
bool? showUsername,
bool? showTimestamp,
bool? showEditedLabel,
bool? showReplyMessage,
bool? showThreadReplyMessage,
bool? showEditMessage,
Expand Down Expand Up @@ -465,6 +472,7 @@ class StreamMessageWidget extends StatefulWidget {
widthFactor: widthFactor ?? this.widthFactor,
showUserAvatar: showUserAvatar ?? this.showUserAvatar,
showSendingIndicator: showSendingIndicator ?? this.showSendingIndicator,
showEditedLabel: showEditedLabel ?? this.showEditedLabel,
showReactions: showReactions ?? this.showReactions,
showThreadReplyIndicator:
showThreadReplyIndicator ?? this.showThreadReplyIndicator,
Expand Down Expand Up @@ -525,6 +533,10 @@ class _StreamMessageWidgetState extends State<StreamMessageWidget>

bool get showTimeStamp => widget.showTimestamp;

bool get showEditedLabel => widget.showEditedLabel;

bool get isTextEdited => widget.message.messageTextUpdatedAt != null;

bool get showInChannel => widget.showInChannelIndicator;

/// {@template hasQuotedMessage}
Expand Down Expand Up @@ -582,7 +594,8 @@ class _StreamMessageWidgetState extends State<StreamMessageWidget>
showUsername ||
showTimeStamp ||
showInChannel ||
showSendingIndicator;
showSendingIndicator ||
isTextEdited;

/// {@template isPinned}
/// Whether [StreamMessageWidget.message] is pinned or not.
Expand Down Expand Up @@ -695,6 +708,7 @@ class _StreamMessageWidgetState extends State<StreamMessageWidget>
streamChatTheme: _streamChatTheme,
showUsername: showUsername,
showTimeStamp: showTimeStamp,
showEditedLabel: showEditedLabel,
showThreadReplyIndicator: showThreadReplyIndicator,
showSendingIndicator: showSendingIndicator,
showInChannel: showInChannel,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class MessageWidgetContent extends StatelessWidget {
required this.showThreadReplyIndicator,
required this.showTimeStamp,
required this.showUsername,
required this.showEditedLabel,
required this.messageWidget,
this.onUserAvatarTap,
this.borderRadiusGeometry,
Expand Down Expand Up @@ -210,6 +211,9 @@ class MessageWidgetContent extends StatelessWidget {
/// {@macro showUsername}
final bool showUsername;

/// {@macro showEdited}
final bool showEditedLabel;

/// {@macro messageWidget}
final StreamMessageWidget messageWidget;

Expand Down Expand Up @@ -437,6 +441,7 @@ class MessageWidgetContent extends StatelessWidget {
showThreadReplyIndicator: showThreadReplyIndicator,
showTimeStamp: showTimeStamp,
showUsername: showUsername,
showEditedLabel: showEditedLabel,
streamChatTheme: streamChatTheme,
streamChat: streamChat,
hasNonUrlAttachments: hasNonUrlAttachments,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ void main() {
showUsername: false,
showInChannel: true,
showTimeStamp: false,
showEditedLabel: false,
reverse: false,
showSendingIndicator: false,
hasUrlAttachments: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ class NnStreamChatLocalizations extends GlobalStreamChatLocalizations {
@override
String get messageDeletedLabel => 'Message deleted';

@override
String get editedMessageLabel => 'Edited';

@override
String get messageReactionsLabel => 'Message Reactions';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ class StreamChatLocalizationsCa extends GlobalStreamChatLocalizations {
@override
String get messageDeletedLabel => 'Missatge esborrat';

@override
String get editedMessageLabel => 'Editat';

@override
String get messageReactionsLabel => 'Reaccions dels missatges';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ class StreamChatLocalizationsDe extends GlobalStreamChatLocalizations {
@override
String get messageDeletedLabel => 'Nachricht gelöscht';

@override
String get editedMessageLabel => 'Bearbeitet';

@override
String get messageReactionsLabel => 'Nachricht-Reaktionen';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ class StreamChatLocalizationsEn extends GlobalStreamChatLocalizations {
@override
String get messageDeletedLabel => 'Message deleted';

@override
String get editedMessageLabel => 'Edited';

@override
String get messageReactionsLabel => 'Message Reactions';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ class StreamChatLocalizationsEs extends GlobalStreamChatLocalizations {
@override
String get messageDeletedLabel => 'Mensaje borrado';

@override
String get editedMessageLabel => 'Editado';

@override
String get messageReactionsLabel => 'Reacciones de los mensajes';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ class StreamChatLocalizationsFr extends GlobalStreamChatLocalizations {
@override
String get messageDeletedLabel => 'Message supprimé';

@override
String get editedMessageLabel => 'Édité';

@override
String get messageReactionsLabel => 'Réactions aux messages';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ class StreamChatLocalizationsHi extends GlobalStreamChatLocalizations {
@override
String get messageDeletedLabel => 'संदेश हटाये';

@override
String get editedMessageLabel => 'संपादित';

@override
String get messageReactionsLabel => 'संदेश प्रतिक्रियाएं';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ class StreamChatLocalizationsIt extends GlobalStreamChatLocalizations {
@override
String get messageDeletedLabel => 'Messaggio cancellato';

@override
String get editedMessageLabel => 'Modificato';

@override
String get messageReactionsLabel => 'Reazioni al messaggio';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ class StreamChatLocalizationsJa extends GlobalStreamChatLocalizations {
@override
String get messageDeletedLabel => 'メッセージ削除';

@override
String get editedMessageLabel => '編集済み';

@override
String get messageReactionsLabel => 'メッセージのリアクション';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ class StreamChatLocalizationsKo extends GlobalStreamChatLocalizations {
@override
String get messageDeletedLabel => '메시지가 삭제되었습니다';

@override
String get editedMessageLabel => '편집됨';

@override
String get messageReactionsLabel => '메시지에 대한 응답';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ class StreamChatLocalizationsNo extends GlobalStreamChatLocalizations {
@override
String get messageDeletedLabel => 'Melding slettet';

@override
String get editedMessageLabel => 'Redigert';

@override
String get messageReactionsLabel => 'Reaksjoner på melding';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ class StreamChatLocalizationsPt extends GlobalStreamChatLocalizations {
@override
String get messageDeletedLabel => 'Mensagem excluída';

@override
String get editedMessageLabel => 'Editado';

@override
String get messageReactionsLabel => 'Reações às mensagens';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ void main() {
);
expect(localizations.threadReplyLabel, isNotNull);
expect(localizations.onlyVisibleToYouText, isNotNull);
expect(localizations.editedMessageLabel, isNotNull);
expect(localizations.threadReplyCountText(3), isNotNull);
expect(
localizations.attachmentsUploadProgressText(remaining: 3, total: 10),
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading