mirror of
https://github.com/twonlyapp/twonly-app.git
synced 2026-04-22 13:02:54 +00:00
fix receipts are getting deleted if message was removed
Some checks are pending
Flutter analyze & test / flutter_analyze_and_test (push) Waiting to run
Some checks are pending
Flutter analyze & test / flutter_analyze_and_test (push) Waiting to run
This commit is contained in:
parent
75b9d3e379
commit
37c5ce933d
4 changed files with 44 additions and 19 deletions
|
|
@ -64,18 +64,39 @@ class MessagesDao extends DatabaseAccessor<TwonlyDB> with _$MessagesDaoMixin {
|
||||||
return query.map((row) => row.readTable(messages)).watch();
|
return query.map((row) => row.readTable(messages)).watch();
|
||||||
}
|
}
|
||||||
|
|
||||||
Stream<Message?> watchLastMessage(String groupId) {
|
Future<Stream<Message?>> watchLastMessage(String groupId) async {
|
||||||
|
final group = await twonlyDB.groupsDao.getGroup(groupId);
|
||||||
|
final deletionTime = clock.now().subtract(
|
||||||
|
Duration(
|
||||||
|
milliseconds: group!.deleteMessagesAfterMilliseconds,
|
||||||
|
),
|
||||||
|
);
|
||||||
return (select(messages)
|
return (select(messages)
|
||||||
..where((t) => t.groupId.equals(groupId))
|
..where(
|
||||||
|
(t) =>
|
||||||
|
t.groupId.equals(groupId) &
|
||||||
|
// messages in groups will only be removed in case all members have received it...
|
||||||
|
// so ensuring that this message is not shown in the messages anymore
|
||||||
|
t.openedAt.isBiggerThanValue(deletionTime),
|
||||||
|
)
|
||||||
..orderBy([(t) => OrderingTerm.desc(t.createdAt)])
|
..orderBy([(t) => OrderingTerm.desc(t.createdAt)])
|
||||||
..limit(1))
|
..limit(1))
|
||||||
.watchSingleOrNull();
|
.watchSingleOrNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
Stream<List<Message>> watchByGroupId(String groupId) {
|
Future<Stream<List<Message>>> watchByGroupId(String groupId) async {
|
||||||
|
final group = await twonlyDB.groupsDao.getGroup(groupId);
|
||||||
|
final deletionTime = clock.now().subtract(
|
||||||
|
Duration(
|
||||||
|
milliseconds: group!.deleteMessagesAfterMilliseconds,
|
||||||
|
),
|
||||||
|
);
|
||||||
return ((select(messages)..where(
|
return ((select(messages)..where(
|
||||||
(t) =>
|
(t) =>
|
||||||
t.groupId.equals(groupId) &
|
t.groupId.equals(groupId) &
|
||||||
|
// messages in groups will only be removed in case all members have received it...
|
||||||
|
// so ensuring that this message is not shown in the messages anymore
|
||||||
|
t.openedAt.isBiggerThanValue(deletionTime) &
|
||||||
(t.isDeletedFromSender.equals(true) |
|
(t.isDeletedFromSender.equals(true) |
|
||||||
(t.type.equals(MessageType.text.name).not() |
|
(t.type.equals(MessageType.text.name).not() |
|
||||||
t.type.equals(MessageType.media.name).not()) |
|
t.type.equals(MessageType.media.name).not()) |
|
||||||
|
|
@ -127,7 +148,8 @@ class MessagesDao extends DatabaseAccessor<TwonlyDB> with _$MessagesDaoMixin {
|
||||||
(m.mediaStored.equals(true) &
|
(m.mediaStored.equals(true) &
|
||||||
m.isDeletedFromSender.equals(true) |
|
m.isDeletedFromSender.equals(true) |
|
||||||
m.mediaStored.equals(false)) &
|
m.mediaStored.equals(false)) &
|
||||||
(m.openedAt.isSmallerThanValue(deletionTime) |
|
// Only remove the message when ALL members have seen it. Otherwise the receipt will also be deleted which could cause issues in case a member opens the image later..
|
||||||
|
(m.openedByAll.isSmallerThanValue(deletionTime) |
|
||||||
(m.isDeletedFromSender.equals(true) &
|
(m.isDeletedFromSender.equals(true) &
|
||||||
m.createdAt.isSmallerThanValue(deletionTime))),
|
m.createdAt.isSmallerThanValue(deletionTime))),
|
||||||
))
|
))
|
||||||
|
|
|
||||||
|
|
@ -102,21 +102,23 @@ Future<(Uint8List, Uint8List?)?> tryToSendCompleteMessage({
|
||||||
message.encryptedContent,
|
message.encryptedContent,
|
||||||
);
|
);
|
||||||
|
|
||||||
final pushNotification = await getPushNotificationFromEncryptedContent(
|
Log.info('Uploading $receiptId.');
|
||||||
receipt.contactId,
|
|
||||||
receipt.messageId,
|
|
||||||
encryptedContent,
|
|
||||||
);
|
|
||||||
|
|
||||||
Log.info('Uploading $receiptId. (${pushNotification?.kind})');
|
|
||||||
|
|
||||||
Uint8List? pushData;
|
Uint8List? pushData;
|
||||||
if (pushNotification != null && receipt.retryCount <= 1) {
|
if (receipt.retryCount == 0) {
|
||||||
// Only show the push notification the first two time.
|
final pushNotification = await getPushNotificationFromEncryptedContent(
|
||||||
pushData = await encryptPushNotification(
|
|
||||||
receipt.contactId,
|
receipt.contactId,
|
||||||
pushNotification,
|
receipt.messageId,
|
||||||
|
encryptedContent,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (pushNotification != null) {
|
||||||
|
// Only show the push notification the first two time.
|
||||||
|
pushData = await encryptPushNotification(
|
||||||
|
receipt.contactId,
|
||||||
|
pushNotification,
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (message.type == pb.Message_Type.TEST_NOTIFICATION) {
|
if (message.type == pb.Message_Type.TEST_NOTIFICATION) {
|
||||||
|
|
|
||||||
|
|
@ -63,9 +63,10 @@ class _UserListItem extends State<GroupListItem> {
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> initStreams() async {
|
Future<void> initStreams() async {
|
||||||
_lastMessageStream = twonlyDB.messagesDao
|
_lastMessageStream =
|
||||||
.watchLastMessage(widget.group.groupId)
|
(await twonlyDB.messagesDao.watchLastMessage(
|
||||||
.listen((update) {
|
widget.group.groupId,
|
||||||
|
)).listen((update) {
|
||||||
protectUpdateState.protect(() async {
|
protectUpdateState.protect(() async {
|
||||||
await updateState(update, _messagesNotOpened);
|
await updateState(update, _messagesNotOpened);
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -107,7 +107,7 @@ class _ChatMessagesViewState extends State<ChatMessagesView> {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
final msgStream = twonlyDB.messagesDao.watchByGroupId(widget.groupId);
|
final msgStream = await twonlyDB.messagesDao.watchByGroupId(widget.groupId);
|
||||||
messageSub = msgStream.listen((update) async {
|
messageSub = msgStream.listen((update) async {
|
||||||
allMessages = update;
|
allMessages = update;
|
||||||
await protectMessageUpdating.protect(() async {
|
await protectMessageUpdating.protect(() async {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue