Skip to content

Commit

Permalink
refactor!: 🔨 update sendBy parameter name of Message class to sentBy (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
vatsaltanna-simformsolutions authored Jun 18, 2024
1 parent 232214c commit 34a29c8
Show file tree
Hide file tree
Showing 13 changed files with 49 additions and 45 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
json serializable of models and added copyWith method (Message, Reaction and Reply Message).
* **Breaking**: [181](https://github.com/SimformSolutionsPvtLtd/flutter_chatview/pull/181) Removed
deprecated field `showTypingIndicator` from ChatView.
* **Breaking**: [187](https://github.com/SimformSolutionsPvtLtd/flutter_chatview/pull/187) update sendBy
parameter name of Message class to sentBy
* **Feat**: [179](https://github.com/SimformSolutionsPvtLtd/flutter_chatview/pull/179) Added reply
suggestions functionality
* **Feat**: [157](https://github.com/SimformSolutionsPvtLtd/flutter_chatview/pull/157) Added onTap
Expand Down
14 changes: 8 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ ChatView(
),
```

Renamed `sendBy` field to `sentBy` in `Message` class.

Updated `ChatUser`, `Message` and `ReplyMessage` Data Model's `fromJson` and `toJson` methods:

in `ChatUser.fromJson`:
Expand Down Expand Up @@ -222,13 +224,13 @@ List<Message> messageList = [
id: '1',
message: "Hi",
createdAt: createdAt,
sendBy: userId,
sentBy: userId,
),
Message(
id: '2',
message: "Hello",
createdAt: createdAt,
sendBy: userId,
sentBy: userId,
),
];
```
Expand All @@ -240,7 +242,7 @@ void onSendTap(String message, ReplyMessage replyMessage, MessageType messageTyp
id: '3',
message: "How are you",
createdAt: DateTime.now(),
sendBy: currentUser.id,
senBy: currentUser.id,
replyMessage: replyMessage,
messageType: messageType,
);
Expand Down Expand Up @@ -389,10 +391,10 @@ ChatView(
ChatView(
...
swipeToReplyConfig: SwipeToReplyConfiguration(
onLeftSwipe: (message, sendBy){
onLeftSwipe: (message, sentBy){
// Your code goes here
},
onRightSwipe: (message, sendBy){
onRightSwipe: (message, sentBy){
// Your code goes here
},
),
Expand Down Expand Up @@ -658,7 +660,7 @@ ChatView(
onReportTap: (Message message) {
debugPrint('Message: $message');
},
onMoreTap: (Message message, bool sendByCurrentUser) {
onMoreTap: (Message message, bool sentByCurrentUser) {
debugPrint('Message : $message');
},
),
Expand Down
24 changes: 12 additions & 12 deletions example/lib/data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,57 +8,57 @@ class Data {
id: '1',
message: "Hi!",
createdAt: DateTime.now(),
sendBy: '1', // userId of who sends the message
sentBy: '1', // userId of who sends the message
status: MessageStatus.read,
),
Message(
id: '2',
message: "Hi!",
createdAt: DateTime.now(),
sendBy: '2',
sentBy: '2',
status: MessageStatus.read,
),
Message(
id: '3',
message: "We can meet?I am free",
createdAt: DateTime.now(),
sendBy: '1',
sentBy: '1',
status: MessageStatus.read,
),
Message(
id: '4',
message: "Can you write the time and place of the meeting?",
createdAt: DateTime.now(),
sendBy: '1',
sentBy: '1',
status: MessageStatus.read,
),
Message(
id: '5',
message: "That's fine",
createdAt: DateTime.now(),
sendBy: '2',
sentBy: '2',
reaction: Reaction(reactions: ['\u{2764}'], reactedUserIds: ['1']),
status: MessageStatus.read,
),
Message(
id: '6',
message: "When to go ?",
createdAt: DateTime.now(),
sendBy: '3',
sentBy: '3',
status: MessageStatus.read,
),
Message(
id: '7',
message: "I guess Simform will reply",
createdAt: DateTime.now(),
sendBy: '4',
sentBy: '4',
status: MessageStatus.read,
),
Message(
id: '8',
message: "https://bit.ly/3JHS2Wl",
createdAt: DateTime.now(),
sendBy: '2',
sentBy: '2',
reaction: Reaction(
reactions: ['\u{2764}', '\u{1F44D}', '\u{1F44D}'],
reactedUserIds: ['2', '3', '4'],
Expand All @@ -75,7 +75,7 @@ class Data {
id: '9',
message: "Done",
createdAt: DateTime.now(),
sendBy: '1',
sentBy: '1',
status: MessageStatus.read,
reaction: Reaction(
reactions: [
Expand All @@ -91,7 +91,7 @@ class Data {
message: "Thank you!!",
status: MessageStatus.read,
createdAt: DateTime.now(),
sendBy: '1',
sentBy: '1',
reaction: Reaction(
reactions: ['\u{2764}', '\u{2764}', '\u{2764}', '\u{2764}'],
reactedUserIds: ['2', '4', '3', '1'],
Expand All @@ -102,15 +102,15 @@ class Data {
message: "https://miro.medium.com/max/1000/0*s7of7kWnf9fDg4XM.jpeg",
createdAt: DateTime.now(),
messageType: MessageType.image,
sendBy: '1',
sentBy: '1',
reaction: Reaction(reactions: ['\u{2764}'], reactedUserIds: ['2']),
status: MessageStatus.read,
),
Message(
id: '12',
message: "🤩🤩",
createdAt: DateTime.now(),
sendBy: '2',
sentBy: '2',
status: MessageStatus.read,
),
];
Expand Down
4 changes: 2 additions & 2 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class _ChatScreenState extends State<ChatScreen> {
id: DateTime.now().toString(),
message: 'I will schedule the meeting.',
createdAt: DateTime.now(),
sendBy: '2',
sentBy: '2',
),
);
await Future.delayed(const Duration(milliseconds: 500));
Expand Down Expand Up @@ -321,7 +321,7 @@ class _ChatScreenState extends State<ChatScreen> {
id: DateTime.now().toString(),
createdAt: DateTime.now(),
message: message,
sendBy: currentUser.id,
sentBy: currentUser.id,
replyMessage: replyMessage,
messageType: messageType,
),
Expand Down
2 changes: 1 addition & 1 deletion lib/src/controller/chat_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ class ChatController {
id: messageId,
message: message.message,
createdAt: message.createdAt,
sendBy: message.sendBy,
sentBy: message.sentBy,
replyMessage: message.replyMessage,
reaction: message.reaction,
messageType: message.messageType,
Expand Down
12 changes: 6 additions & 6 deletions lib/src/models/message.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class Message {
final DateTime createdAt;

/// Provides id of sender of message.
final String sendBy;
final String sentBy;

/// Provides reply message if user triggers any reply on any message.
final ReplyMessage replyMessage;
Expand All @@ -58,7 +58,7 @@ class Message {
this.id = '',
required this.message,
required this.createdAt,
required this.sendBy,
required this.sentBy,
this.replyMessage = const ReplyMessage(),
Reaction? reaction,
this.messageType = MessageType.text,
Expand Down Expand Up @@ -95,7 +95,7 @@ class Message {
message: json['message']?.toString() ?? '',
createdAt:
DateTime.tryParse(json['createdAt'].toString()) ?? DateTime.now(),
sendBy: json['sendBy']?.toString() ?? '',
sentBy: json['sentBy']?.toString() ?? '',
replyMessage: json['reply_message'] is Map<String, dynamic>
? ReplyMessage.fromJson(json['reply_message'])
: const ReplyMessage(),
Expand All @@ -116,7 +116,7 @@ class Message {
'id': id,
'message': message,
'createdAt': createdAt.toIso8601String(),
'sendBy': sendBy,
'sentBy': sentBy,
'reply_message': replyMessage.toJson(),
'reaction': reaction.toJson(),
'message_type': messageType.name,
Expand All @@ -129,7 +129,7 @@ class Message {
GlobalKey? key,
String? message,
DateTime? createdAt,
String? sendBy,
String? sentBy,
ReplyMessage? replyMessage,
Reaction? reaction,
MessageType? messageType,
Expand All @@ -141,7 +141,7 @@ class Message {
id: id ?? this.message,
message: message ?? this.message,
createdAt: createdAt ?? this.createdAt,
sendBy: sendBy ?? this.sendBy,
sentBy: sentBy ?? this.sentBy,
messageType: messageType ?? this.messageType,
voiceMessageDuration: forceNullValue
? voiceMessageDuration
Expand Down
2 changes: 1 addition & 1 deletion lib/src/models/reply_popup_configuration.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class ReplyPopupConfiguration {
final Color? backgroundColor;

/// Provides builder for creating reply pop-up widget.
final Widget Function(Message message, bool sendByCurrentUser)?
final Widget Function(Message message, bool sentByCurrentUser)?
replyPopupBuilder;

/// Provides callback on unSend button.
Expand Down
4 changes: 2 additions & 2 deletions lib/src/models/swipe_to_reply_configuration.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ class SwipeToReplyConfiguration {
final Duration? animationDuration;

/// Provides callback when user swipe chat bubble from left side.
final void Function(String message, String sendBy)? onLeftSwipe;
final void Function(String message, String sentBy)? onLeftSwipe;

/// Provides callback when user swipe chat bubble from right side.
final void Function(String message, String sendBy)? onRightSwipe;
final void Function(String message, String sentBy)? onRightSwipe;

const SwipeToReplyConfiguration({
this.replyIconColor,
Expand Down
2 changes: 1 addition & 1 deletion lib/src/values/typedefs.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ typedef StringWithReturnWidget = Widget Function(String separator);
typedef DragUpdateDetailsCallback = void Function(DragUpdateDetails);
typedef MoreTapCallBack = void Function(
Message message,
bool sendByCurrentUser,
bool sentByCurrentUser,
);
typedef ReactionCallback = void Function(
Message message,
Expand Down
8 changes: 4 additions & 4 deletions lib/src/widgets/chat_bubble_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class ChatBubbleWidget extends StatefulWidget {
class _ChatBubbleWidgetState extends State<ChatBubbleWidget> {
String get replyMessage => widget.message.replyMessage.message;

bool get isMessageBySender => widget.message.sendBy == currentUser?.id;
bool get isMessageBySender => widget.message.sentBy == currentUser?.id;

bool get isLastMessage =>
chatController?.initialMessageList.last.id == widget.message.id;
Expand All @@ -124,7 +124,7 @@ class _ChatBubbleWidgetState extends State<ChatBubbleWidget> {
@override
Widget build(BuildContext context) {
// Get user from id.
final messagedUser = chatController?.getUserFromId(widget.message.sendBy);
final messagedUser = chatController?.getUserFromId(widget.message.sentBy);
return Stack(
children: [
if (featureActiveConfig?.enableSwipeToSeeTime ?? true) ...[
Expand Down Expand Up @@ -196,7 +196,7 @@ class _ChatBubbleWidgetState extends State<ChatBubbleWidget> {
null) {
widget.swipeToReplyConfig?.onLeftSwipe!(
widget.message.message,
widget.message.sendBy);
widget.message.sentBy);
}
widget.onSwipe(widget.message);
}
Expand All @@ -218,7 +218,7 @@ class _ChatBubbleWidgetState extends State<ChatBubbleWidget> {
null) {
widget.swipeToReplyConfig?.onRightSwipe!(
widget.message.message,
widget.message.sendBy);
widget.message.sentBy);
}
widget.onSwipe(widget.message);
}
Expand Down
10 changes: 5 additions & 5 deletions lib/src/widgets/chat_list_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ class _ChatListWidgetState extends State<ChatListWidget>
if (featureActiveConfig?.enableReplySnackBar ?? false) {
_showReplyPopup(
message: message,
sendByCurrentUser: message.sendBy == currentUser?.id,
sentByCurrentUser: message.sentBy == currentUser?.id,
);
}
},
Expand Down Expand Up @@ -256,7 +256,7 @@ class _ChatListWidgetState extends State<ChatListWidget>

void _showReplyPopup({
required Message message,
required bool sendByCurrentUser,
required bool sentByCurrentUser,
}) {
final replyPopup = widget.replyPopupConfig;
ScaffoldMessenger.of(context)
Expand All @@ -265,15 +265,15 @@ class _ChatListWidgetState extends State<ChatListWidget>
duration: const Duration(hours: 1),
backgroundColor: replyPopup?.backgroundColor ?? Colors.white,
content: replyPopup?.replyPopupBuilder != null
? replyPopup!.replyPopupBuilder!(message, sendByCurrentUser)
? replyPopup!.replyPopupBuilder!(message, sentByCurrentUser)
: ReplyPopupWidget(
buttonTextStyle: replyPopup?.buttonTextStyle,
topBorderColor: replyPopup?.topBorderColor,
onMoreTap: () {
_onChatListTap();
replyPopup?.onMoreTap?.call(
message,
sendByCurrentUser,
sentByCurrentUser,
);
},
onReportTap: () {
Expand All @@ -298,7 +298,7 @@ class _ChatListWidgetState extends State<ChatListWidget>
replyPopup?.onReplyTap!(message);
}
},
sendByCurrentUser: sendByCurrentUser,
sentByCurrentUser: sentByCurrentUser,
),
padding: EdgeInsets.zero,
),
Expand Down
8 changes: 4 additions & 4 deletions lib/src/widgets/reply_popup_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import '../values/typedefs.dart';
class ReplyPopupWidget extends StatelessWidget {
const ReplyPopupWidget({
Key? key,
required this.sendByCurrentUser,
required this.sentByCurrentUser,
required this.onUnsendTap,
required this.onReplyTap,
required this.onReportTap,
Expand All @@ -38,7 +38,7 @@ class ReplyPopupWidget extends StatelessWidget {
}) : super(key: key);

/// Represents message is sent by current user or not.
final bool sendByCurrentUser;
final bool sentByCurrentUser;

/// Provides call back when user tap on unsend button.
final VoidCallBack onUnsendTap;
Expand Down Expand Up @@ -82,7 +82,7 @@ class ReplyPopupWidget extends StatelessWidget {
),
),
),
if (sendByCurrentUser)
if (sentByCurrentUser)
Expanded(
child: InkWell(
onTap: onUnsendTap,
Expand All @@ -93,7 +93,7 @@ class ReplyPopupWidget extends StatelessWidget {
),
),
),
if (!sendByCurrentUser)
if (!sentByCurrentUser)
Expanded(
child: InkWell(
onTap: onReportTap,
Expand Down
Loading

0 comments on commit 34a29c8

Please sign in to comment.