mirror of
https://github.com/twonlyapp/twonly-app.git
synced 2026-07-18 01:14:07 +00:00
fix smaller issues
This commit is contained in:
parent
cec25675c3
commit
04680e0855
2 changed files with 51 additions and 48 deletions
|
|
@ -263,26 +263,28 @@ class MessagesDao extends DatabaseAccessor<TwonlyDB> with _$MessagesDaoMixin {
|
||||||
String text,
|
String text,
|
||||||
DateTime timestamp,
|
DateTime timestamp,
|
||||||
) async {
|
) async {
|
||||||
final msg = await getMessageById(messageId).getSingleOrNull();
|
await transaction(() async {
|
||||||
if (msg == null || msg.content == null || msg.senderId != contactId) {
|
final msg = await getMessageById(messageId).getSingleOrNull();
|
||||||
return;
|
if (msg == null || msg.content == null || msg.senderId != contactId) {
|
||||||
}
|
return;
|
||||||
await into(messageHistories).insert(
|
}
|
||||||
MessageHistoriesCompanion(
|
await into(messageHistories).insert(
|
||||||
messageId: Value(messageId),
|
MessageHistoriesCompanion(
|
||||||
content: Value(msg.content),
|
messageId: Value(messageId),
|
||||||
createdAt: Value(timestamp),
|
content: Value(msg.content),
|
||||||
),
|
createdAt: Value(timestamp),
|
||||||
);
|
),
|
||||||
await (update(messages)..where(
|
);
|
||||||
(t) => t.messageId.equals(messageId),
|
await (update(messages)..where(
|
||||||
))
|
(t) => t.messageId.equals(messageId),
|
||||||
.write(
|
))
|
||||||
MessagesCompanion(
|
.write(
|
||||||
content: Value(text),
|
MessagesCompanion(
|
||||||
modifiedAt: Value(timestamp),
|
content: Value(text),
|
||||||
),
|
modifiedAt: Value(timestamp),
|
||||||
);
|
),
|
||||||
|
);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> handleMessagesOpened(
|
Future<void> handleMessagesOpened(
|
||||||
|
|
@ -291,7 +293,9 @@ class MessagesDao extends DatabaseAccessor<TwonlyDB> with _$MessagesDaoMixin {
|
||||||
DateTime timestamp,
|
DateTime timestamp,
|
||||||
) async {
|
) async {
|
||||||
if (contactId.present) {
|
if (contactId.present) {
|
||||||
final contactExists = await twonlyDB.contactsDao.getContactById(contactId.value);
|
final contactExists = await twonlyDB.contactsDao.getContactById(
|
||||||
|
contactId.value,
|
||||||
|
);
|
||||||
if (contactExists == null) {
|
if (contactExists == null) {
|
||||||
Log.info(
|
Log.info(
|
||||||
'handleMessagesOpened: Contact ${contactId.value} does not exist in database, ignoring messages opened action.',
|
'handleMessagesOpened: Contact ${contactId.value} does not exist in database, ignoring messages opened action.',
|
||||||
|
|
@ -301,25 +305,24 @@ class MessagesDao extends DatabaseAccessor<TwonlyDB> with _$MessagesDaoMixin {
|
||||||
}
|
}
|
||||||
for (final messageId in messageIds) {
|
for (final messageId in messageIds) {
|
||||||
try {
|
try {
|
||||||
var actionTimestamp = timestamp;
|
|
||||||
final msg = await getMessageById(messageId).getSingleOrNull();
|
|
||||||
if (msg == null) {
|
|
||||||
Log.info(
|
|
||||||
'handleMessagesOpened: Message $messageId does not exist in database, skipping.',
|
|
||||||
);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (actionTimestamp.isBefore(msg.createdAt)) {
|
|
||||||
Log.warn(
|
|
||||||
'Receiver clock skew detected for message $messageId. '
|
|
||||||
'Action timestamp $actionTimestamp is before message creation ${msg.createdAt}. '
|
|
||||||
'Clamping to creation time.',
|
|
||||||
);
|
|
||||||
actionTimestamp = msg.createdAt;
|
|
||||||
}
|
|
||||||
|
|
||||||
final ts = actionTimestamp;
|
|
||||||
await transaction(() async {
|
await transaction(() async {
|
||||||
|
final msg = await getMessageById(messageId).getSingleOrNull();
|
||||||
|
if (msg == null) {
|
||||||
|
Log.info(
|
||||||
|
'handleMessagesOpened: Message $messageId does not exist in database, skipping.',
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var ts = timestamp;
|
||||||
|
if (ts.isBefore(msg.createdAt)) {
|
||||||
|
Log.warn(
|
||||||
|
'Receiver clock skew detected for message $messageId. '
|
||||||
|
'Action timestamp $ts is before message creation ${msg.createdAt}. '
|
||||||
|
'Clamping to creation time.',
|
||||||
|
);
|
||||||
|
ts = msg.createdAt;
|
||||||
|
}
|
||||||
|
|
||||||
await into(messageActions).insertOnConflictUpdate(
|
await into(messageActions).insertOnConflictUpdate(
|
||||||
MessageActionsCompanion(
|
MessageActionsCompanion(
|
||||||
messageId: Value(messageId),
|
messageId: Value(messageId),
|
||||||
|
|
@ -353,7 +356,7 @@ class MessagesDao extends DatabaseAccessor<TwonlyDB> with _$MessagesDaoMixin {
|
||||||
messages,
|
messages,
|
||||||
)..where((tbl) => tbl.messageId.equals(messageId))).write(
|
)..where((tbl) => tbl.messageId.equals(messageId))).write(
|
||||||
MessagesCompanion(
|
MessagesCompanion(
|
||||||
openedAt: Value(actionTimestamp),
|
openedAt: Value(timestamp),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
@ -383,14 +386,14 @@ class MessagesDao extends DatabaseAccessor<TwonlyDB> with _$MessagesDaoMixin {
|
||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final msg = await getMessageById(messageId).getSingleOrNull();
|
|
||||||
if (msg == null) {
|
|
||||||
Log.info(
|
|
||||||
'handleMessageAckByServer: Message $messageId does not exist in database, skipping.',
|
|
||||||
);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
await transaction(() async {
|
await transaction(() async {
|
||||||
|
final msg = await getMessageById(messageId).getSingleOrNull();
|
||||||
|
if (msg == null) {
|
||||||
|
Log.info(
|
||||||
|
'handleMessageAckByServer: Message $messageId does not exist in database, skipping.',
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
await into(messageActions).insertOnConflictUpdate(
|
await into(messageActions).insertOnConflictUpdate(
|
||||||
MessageActionsCompanion(
|
MessageActionsCompanion(
|
||||||
messageId: Value(messageId),
|
messageId: Value(messageId),
|
||||||
|
|
|
||||||
|
|
@ -112,7 +112,7 @@ Future<bool> createThumbnailsForImage(
|
||||||
);
|
);
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
Log.error('Compressed image thumbnail is empty or missing.');
|
Log.warn('Compressed image thumbnail is empty or missing.');
|
||||||
try {
|
try {
|
||||||
if (destinationFile.existsSync()) {
|
if (destinationFile.existsSync()) {
|
||||||
destinationFile.deleteSync();
|
destinationFile.deleteSync();
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue