mirror of
https://github.com/twonlyapp/twonly-app.git
synced 2026-03-03 12:16:47 +00:00
use sql match
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
cd00910e86
commit
3806525653
4 changed files with 53 additions and 49 deletions
|
|
@ -212,32 +212,41 @@ class MessagesDao extends DatabaseAccessor<TwonlyDB> with _$MessagesDaoMixin {
|
|||
);
|
||||
}
|
||||
|
||||
Future<void> handleMessageOpened(
|
||||
Future<void> handleMessagesOpened(
|
||||
int contactId,
|
||||
String messageId,
|
||||
List<String> messageIds,
|
||||
DateTime timestamp,
|
||||
) async {
|
||||
await into(messageActions).insertOnConflictUpdate(
|
||||
await batch((batch) async {
|
||||
for (final messageId in messageIds) {
|
||||
batch.insert(
|
||||
messageActions,
|
||||
MessageActionsCompanion(
|
||||
messageId: Value(messageId),
|
||||
contactId: Value(contactId),
|
||||
type: const Value(MessageActionType.openedAt),
|
||||
actionAt: Value(timestamp),
|
||||
),
|
||||
mode: InsertMode.insertOrReplace,
|
||||
);
|
||||
// Directly show as message opened as soon as one person has opened it
|
||||
final openedByAll =
|
||||
await haveAllMembers(messageId, MessageActionType.openedAt)
|
||||
? clock.now()
|
||||
: null;
|
||||
await twonlyDB.messagesDao.updateMessageId(
|
||||
messageId,
|
||||
}
|
||||
|
||||
for (final messageId in messageIds) {
|
||||
final isOpenedByAll =
|
||||
await haveAllMembers(messageId, MessageActionType.openedAt);
|
||||
final now = clock.now();
|
||||
|
||||
batch.update(
|
||||
twonlyDB.messages,
|
||||
MessagesCompanion(
|
||||
openedAt: Value(clock.now()),
|
||||
openedByAll: Value(openedByAll),
|
||||
openedAt: Value(now),
|
||||
openedByAll: Value(isOpenedByAll ? now : null),
|
||||
),
|
||||
where: (tbl) => tbl.messageId.equals(messageId),
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> handleMessageAckByServer(
|
||||
int contactId,
|
||||
|
|
|
|||
|
|
@ -9,20 +9,18 @@ Future<void> handleMessageUpdate(
|
|||
) async {
|
||||
switch (messageUpdate.type) {
|
||||
case EncryptedContent_MessageUpdate_Type.OPENED:
|
||||
for (final targetMessageId in messageUpdate.multipleTargetMessageIds) {
|
||||
Log.info(
|
||||
'Opened message $targetMessageId',
|
||||
'Opened message ${messageUpdate.multipleTargetMessageIds}',
|
||||
);
|
||||
try {
|
||||
await twonlyDB.messagesDao.handleMessageOpened(
|
||||
await twonlyDB.messagesDao.handleMessagesOpened(
|
||||
contactId,
|
||||
targetMessageId,
|
||||
messageUpdate.multipleTargetMessageIds,
|
||||
fromTimestamp(messageUpdate.timestamp),
|
||||
);
|
||||
} catch (e) {
|
||||
Log.warn(e);
|
||||
}
|
||||
}
|
||||
case EncryptedContent_MessageUpdate_Type.DELETE:
|
||||
if (!await isSender(contactId, messageUpdate.senderMessageId)) {
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -375,15 +375,18 @@ Future<void> notifyContactAboutOpeningMessage(
|
|||
),
|
||||
blocking: false,
|
||||
);
|
||||
await twonlyDB.batch((batch) {
|
||||
for (final messageId in messageOtherIds) {
|
||||
await twonlyDB.messagesDao.updateMessageId(
|
||||
messageId,
|
||||
batch.update(
|
||||
twonlyDB.messages,
|
||||
MessagesCompanion(
|
||||
openedAt: Value(actionAt),
|
||||
openedByAll: Value(actionAt),
|
||||
),
|
||||
where: (tbl) => tbl.messageId.equals(messageId),
|
||||
);
|
||||
}
|
||||
});
|
||||
await updateLastMessageId(contactId, biggestMessageId);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -128,12 +128,6 @@ class _ChatMessagesViewState extends State<ChatMessagesView> {
|
|||
final msgStream = twonlyDB.messagesDao.watchByGroupId(group.groupId);
|
||||
messageSub = msgStream.listen((update) async {
|
||||
allMessages = update;
|
||||
|
||||
/// In case a message is not open yet the message is updated, which will trigger this watch to be called again.
|
||||
/// So as long as the Mutex is locked just return...
|
||||
if (protectMessageUpdating.isLocked) {
|
||||
// return;
|
||||
}
|
||||
await protectMessageUpdating.protect(() async {
|
||||
await setMessages(update, groupActions);
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue