mirror of
https://github.com/twonlyapp/twonly-app.git
synced 2026-09-01 07:04:07 +00:00
fix time issue
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
3171541b6a
commit
dafa7603d8
3 changed files with 35 additions and 16 deletions
|
|
@ -340,6 +340,24 @@ class GroupsDao extends DatabaseAccessor<TwonlyDB> with _$GroupsDaoMixin {
|
|||
.write(GroupsCompanion(lastMessageExchange: Value(clampedLastMessage)));
|
||||
}
|
||||
|
||||
Future<void> increaseMemberLastMessage(
|
||||
String groupId,
|
||||
int contactId,
|
||||
DateTime newLastMessage,
|
||||
) async {
|
||||
final now = clock.now();
|
||||
final clampedLastMessage =
|
||||
newLastMessage.isAfter(now) ? now : newLastMessage;
|
||||
await (update(groupMembers)..where(
|
||||
(t) =>
|
||||
t.groupId.equals(groupId) &
|
||||
t.contactId.equals(contactId) &
|
||||
(t.lastMessage.isNull() |
|
||||
t.lastMessage.isSmallerThanValue(clampedLastMessage)),
|
||||
))
|
||||
.write(GroupMembersCompanion(lastMessage: Value(clampedLastMessage)));
|
||||
}
|
||||
|
||||
Stream<List<Group>> watchNonDirectGroupsForMember(int contactId) {
|
||||
final query =
|
||||
select(groups).join([
|
||||
|
|
|
|||
|
|
@ -489,22 +489,28 @@ class MessagesDao extends DatabaseAccessor<TwonlyDB> with _$MessagesDaoMixin {
|
|||
|
||||
await into(messages).insertOnConflictUpdate(insertMessage);
|
||||
|
||||
final msgTime = insertMessage.createdAt.present
|
||||
? insertMessage.createdAt.value
|
||||
: clock.now();
|
||||
|
||||
await twonlyDB.groupsDao.updateGroup(
|
||||
message.groupId.value,
|
||||
GroupsCompanion(
|
||||
lastMessageExchange: Value(clock.now()),
|
||||
archived: const Value(false),
|
||||
deletedContent: const Value(false),
|
||||
const GroupsCompanion(
|
||||
archived: Value(false),
|
||||
deletedContent: Value(false),
|
||||
),
|
||||
);
|
||||
|
||||
if (message.senderId.present) {
|
||||
await twonlyDB.groupsDao.updateMember(
|
||||
await twonlyDB.groupsDao.increaseLastMessageExchange(
|
||||
message.groupId.value,
|
||||
msgTime,
|
||||
);
|
||||
|
||||
if (message.senderId.present && message.senderId.value != null) {
|
||||
await twonlyDB.groupsDao.increaseMemberLastMessage(
|
||||
message.groupId.value,
|
||||
message.senderId.value!,
|
||||
GroupMembersCompanion(
|
||||
lastMessage: Value(clock.now()),
|
||||
),
|
||||
msgTime,
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@ import 'dart:async';
|
|||
|
||||
import 'package:clock/clock.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:twonly/locator.dart';
|
||||
import 'package:twonly/src/database/twonly.db.dart';
|
||||
import 'package:twonly/src/utils/misc.dart';
|
||||
|
||||
|
|
@ -42,12 +41,8 @@ class _LastMessageTimeCompState extends State<LastMessageTimeComp> {
|
|||
_actionSubscription = null;
|
||||
|
||||
if (widget.message != null) {
|
||||
_actionSubscription = twonlyDB.messagesDao
|
||||
.watchLastMessageAction(widget.message!.messageId)
|
||||
.listen((lastAction) {
|
||||
targetTime = lastAction?.actionAt ?? widget.message!.createdAt;
|
||||
targetTime = widget.message!.openedAt ?? widget.message!.createdAt;
|
||||
_updateSeconds();
|
||||
});
|
||||
} else if (widget.dateTime != null) {
|
||||
targetTime = widget.dateTime;
|
||||
_updateSeconds();
|
||||
|
|
|
|||
Loading…
Reference in a new issue