Skip to content

Commit

Permalink
feature: add the beginnings of self_destruct_after field handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Ed Geraghty committed Apr 10, 2022
1 parent dcbba8b commit 2e7d965
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/store/events/messages/formatters.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,19 @@ Future<Message> formatMessageContent({
EncryptInfo? info = const EncryptInfo(),
File? file,
}) async {
final timestamp = DateTime.now().millisecondsSinceEpoch;

final formatted = Message(
id: tempId,
url: message.url,
body: message.body?.trimRight(),
type: message.type,
sender: userId,
roomId: room.id,
timestamp: DateTime.now().millisecondsSinceEpoch,
timestamp: timestamp,
selfDestructAfter: (room.ephemeralMessagesTimer! > 0)
? timestamp + (room.ephemeralMessagesTimer ?? 0)
: 0,
pending: true,
syncing: true,
);
Expand Down
10 changes: 10 additions & 0 deletions lib/store/events/messages/model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ class Message extends Event implements drift.Insertable<Message> {
// Message timestamps
@JsonKey(defaultValue: 0)
final int received;
@JsonKey(defaultValue: 0)
final int selfDestructAfter;

// Message Only
final String? body;
Expand Down Expand Up @@ -76,6 +78,7 @@ class Message extends Event implements drift.Insertable<Message> {
this.info,
this.formattedBody,
this.received = 0,
this.selfDestructAfter = 0,
this.ciphertext,
this.senderKey,
this.deviceId,
Expand Down Expand Up @@ -121,6 +124,7 @@ class Message extends Event implements drift.Insertable<Message> {
bool? edited,
int? timestamp,
int? received,
int? selfDestructAfter,
String? body,
String? typeDecrypted, // inner type of decrypted event
String? msgtype,
Expand Down Expand Up @@ -157,6 +161,7 @@ class Message extends Event implements drift.Insertable<Message> {
url: url ?? this.url,
info: info ?? this.info,
received: received ?? this.received,
selfDestructAfter: selfDestructAfter ?? this.selfDestructAfter,
ciphertext: ciphertext ?? this.ciphertext,
senderKey: senderKey ?? this.senderKey,
deviceId: deviceId ?? this.deviceId,
Expand Down Expand Up @@ -191,6 +196,7 @@ class Message extends Event implements drift.Insertable<Message> {
edited: drift.Value(edited),
timestamp: drift.Value(timestamp),
received: drift.Value(received),
selfDestructAfter: drift.Value(selfDestructAfter),
body: drift.Value(body),
msgtype: drift.Value(msgtype),
format: drift.Value(format),
Expand Down Expand Up @@ -244,6 +250,9 @@ class Message extends Event implements drift.Insertable<Message> {
}
}

// see https://github.com/matrix-org/synapse/pull/6409#issuecomment-585722447
final selfDestructAfter = content['org.matrix.self_destruct_after'] ?? 0;

return Message(
id: event.id,
userId: event.userId,
Expand Down Expand Up @@ -271,6 +280,7 @@ class Message extends Event implements drift.Insertable<Message> {
replacement: replacement,
relatedEventId: relatedEventId,
received: DateTime.now().millisecondsSinceEpoch,
selfDestructAfter: selfDestructAfter,
failed: false,
pending: false,
syncing: false,
Expand Down

0 comments on commit 2e7d965

Please sign in to comment.