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

[FEATURE] Add support for draft messages #548

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
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
8 changes: 6 additions & 2 deletions lib/model/social.dart
Original file line number Diff line number Diff line change
Expand Up @@ -892,16 +892,17 @@ class Message {

final String? message;
final bool? read;
final bool? draft;

final DateTime? dateSentUtc;
final DateTime? dateUpdatedUtc;

Message({this.id, this.globalId, this.conversationId, this.sender, this.recipient, this.message, this.read, this.dateSentUtc, this.dateUpdatedUtc});
Message({this.id, this.globalId, this.conversationId, this.sender, this.recipient, this.message, this.read, this.draft, this.dateSentUtc, this.dateUpdatedUtc});

factory Message.fromOther(Message? other, {
String? id, String? globalId, String? conversationId,
ConversationMember? sender, ConversationMember? recipient,
String? message, bool? read,
String? message, bool? read, bool? draft,
DateTime? dateSentUtc,
DateTime? dateUpdatedUtc
}) => Message(
Expand All @@ -912,6 +913,7 @@ class Message {
recipient: recipient ?? other?.recipient,
message: message ?? other?.message,
read: read ?? other?.read,
draft: draft ?? other?.draft,
dateSentUtc: dateSentUtc ?? other?.dateSentUtc,
dateUpdatedUtc: dateUpdatedUtc ?? other?.dateUpdatedUtc,
);
Expand All @@ -924,6 +926,7 @@ class Message {
recipient: ConversationMember.fromJson(json['recipient']),
message: JsonUtils.stringValue(json['message']),
read: JsonUtils.boolValue(json['read']),
draft: JsonUtils.boolValue(json['draft']),
dateSentUtc: DateTimeUtils.dateTimeFromString(JsonUtils.stringValue(json['date_sent']), isUtc: true),
dateUpdatedUtc: DateTimeUtils.dateTimeFromString(JsonUtils.stringValue(json['date_updated']), isUtc: true),
) : null;
Expand All @@ -937,6 +940,7 @@ class Message {
'recipient': recipient?.toJson(),
'message': message,
'read': read,
'draft': draft,
'date_sent': DateTimeUtils.utcDateTimeToString(dateSentUtc),
'date_updated': DateTimeUtils.utcDateTimeToString(dateUpdatedUtc),
};
Expand Down
9 changes: 5 additions & 4 deletions lib/service/social.dart
Original file line number Diff line number Diff line change
Expand Up @@ -678,7 +678,7 @@ class Social extends Service implements NotificationsListener {
}
}

Future<bool> updateConversationMessage({required String conversationId, required String globalMessageId, required String newText,}) async {
Future<bool> updateConversationMessage({required String conversationId, required String globalMessageId, required String newText, bool draft = false}) async {
String? socialUrl = Config().socialUrl;
if (StringUtils.isEmpty(socialUrl)) {
Log.e('Failed to update conversation message. Reason: missing social url.');
Expand All @@ -693,7 +693,7 @@ class Social extends Service implements NotificationsListener {
return false;
}

String? requestBody = JsonUtils.encode({'message': newText});
String? requestBody = JsonUtils.encode({'message': newText, 'draft': draft});

String url = '$socialUrl/conversations/$conversationId/messages/$globalMessageId/update';

Expand Down Expand Up @@ -748,7 +748,7 @@ class Social extends Service implements NotificationsListener {



Future<List<Message>?> createConversationMessage({required String conversationId, required String message}) async {
Future<List<Message>?> createConversationMessage({required String conversationId, required String message, bool draft = false}) async {
String? socialUrl = Config().socialUrl;
if (StringUtils.isEmpty(socialUrl)) {
Log.e('Failed to create message for conversation $conversationId. Reason: missing social url.');
Expand All @@ -759,7 +759,8 @@ class Social extends Service implements NotificationsListener {
return null;
}
String? requestBody = JsonUtils.encode({
'message': message
'message': message,
'draft': draft
});
Response? response = await Network().post('$socialUrl/conversations/$conversationId/messages/send', auth: Auth2(), body: requestBody);
int? responseCode = response?.statusCode;
Expand Down