🐛 Fix events applying issue
This commit is contained in:
parent
793ad156e3
commit
a7035581e9
@ -56,14 +56,9 @@ class ChatEventController {
|
|||||||
);
|
);
|
||||||
totalEvents.value = result?.$2 ?? 0;
|
totalEvents.value = result?.$2 ?? 0;
|
||||||
if (result != null) {
|
if (result != null) {
|
||||||
currentEvents.addAll(result.$1.map(
|
for (final x in result.$1.reversed) {
|
||||||
(x) => LocalEvent(
|
applyEvent(LocalEvent(x.id, x, x.channelId, x.createdAt));
|
||||||
x.id,
|
}
|
||||||
x,
|
|
||||||
x.channelId,
|
|
||||||
x.createdAt,
|
|
||||||
),
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
final result = await database.syncEvents(
|
final result = await database.syncEvents(
|
||||||
@ -71,16 +66,7 @@ class ChatEventController {
|
|||||||
scope: scope,
|
scope: scope,
|
||||||
);
|
);
|
||||||
totalEvents.value = result?.$2 ?? 0;
|
totalEvents.value = result?.$2 ?? 0;
|
||||||
if (!await syncLocal(channel) && result != null) {
|
await syncLocal(channel);
|
||||||
currentEvents.addAll(result.$1.map(
|
|
||||||
(x) => LocalEvent(
|
|
||||||
x.id,
|
|
||||||
x,
|
|
||||||
x.channelId,
|
|
||||||
x.createdAt,
|
|
||||||
),
|
|
||||||
));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
isLoading.value = false;
|
isLoading.value = false;
|
||||||
}
|
}
|
||||||
@ -96,14 +82,9 @@ class ChatEventController {
|
|||||||
);
|
);
|
||||||
totalEvents.value = result?.$2 ?? 0;
|
totalEvents.value = result?.$2 ?? 0;
|
||||||
if (result != null) {
|
if (result != null) {
|
||||||
currentEvents.addAll(result.$1.map(
|
for (final x in result.$1.reversed) {
|
||||||
(x) => LocalEvent(
|
applyEvent(LocalEvent(x.id, x, x.channelId, x.createdAt));
|
||||||
x.id,
|
}
|
||||||
x,
|
|
||||||
x.channelId,
|
|
||||||
x.createdAt,
|
|
||||||
),
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
final result = await database.syncEvents(
|
final result = await database.syncEvents(
|
||||||
@ -113,27 +94,17 @@ class ChatEventController {
|
|||||||
offset: currentEvents.length,
|
offset: currentEvents.length,
|
||||||
);
|
);
|
||||||
totalEvents.value = result?.$2 ?? 0;
|
totalEvents.value = result?.$2 ?? 0;
|
||||||
if (!await syncLocal(channel) && result != null) {
|
await syncLocal(channel);
|
||||||
currentEvents.addAll(result.$1.map(
|
|
||||||
(x) => LocalEvent(
|
|
||||||
x.id,
|
|
||||||
x,
|
|
||||||
x.channelId,
|
|
||||||
x.createdAt,
|
|
||||||
),
|
|
||||||
));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
isLoading.value = false;
|
isLoading.value = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<bool> syncLocal(Channel channel) async {
|
Future<bool> syncLocal(Channel channel) async {
|
||||||
if (PlatformInfo.isWeb) return false;
|
if (PlatformInfo.isWeb) return false;
|
||||||
currentEvents.replaceRange(
|
final data = await database.localEvents.findAllByChannel(channel.id);
|
||||||
0,
|
for (final x in data.reversed) {
|
||||||
currentEvents.length,
|
applyEvent(x);
|
||||||
await database.localEvents.findAllByChannel(channel.id),
|
}
|
||||||
);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -150,28 +121,32 @@ class ChatEventController {
|
|||||||
entry = await database.receiveEvent(remote);
|
entry = await database.receiveEvent(remote);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (remote.channelId != channel?.id) return;
|
applyEvent(entry);
|
||||||
|
}
|
||||||
|
|
||||||
final idx = currentEvents.indexWhere((x) => x.data.uuid == remote.uuid);
|
applyEvent(LocalEvent entry) {
|
||||||
|
if (entry.channelId != channel?.id) return;
|
||||||
|
|
||||||
|
final idx = currentEvents.indexWhere((x) => x.data.uuid == entry.data.uuid);
|
||||||
if (idx != -1) {
|
if (idx != -1) {
|
||||||
currentEvents[idx] = entry;
|
currentEvents[idx] = entry;
|
||||||
} else {
|
} else {
|
||||||
currentEvents.insert(0, entry);
|
currentEvents.insert(0, entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (remote.type) {
|
switch (entry.data.type) {
|
||||||
case 'messages.edit':
|
case 'messages.edit':
|
||||||
final body = EventMessageBody.fromJson(remote.body);
|
final body = EventMessageBody.fromJson(entry.data.body);
|
||||||
if (body.relatedEvent != null) {
|
if (body.relatedEvent != null) {
|
||||||
final idx =
|
final idx =
|
||||||
currentEvents.indexWhere((x) => x.data.id == body.relatedEvent);
|
currentEvents.indexWhere((x) => x.data.id == body.relatedEvent);
|
||||||
if (idx != -1) {
|
if (idx != -1) {
|
||||||
currentEvents[idx].data.body = remote.body;
|
currentEvents[idx].data.body = entry.data.body;
|
||||||
currentEvents[idx].data.updatedAt = remote.updatedAt;
|
currentEvents[idx].data.updatedAt = entry.data.updatedAt;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case 'messages.delete':
|
case 'messages.delete':
|
||||||
final body = EventMessageBody.fromJson(remote.body);
|
final body = EventMessageBody.fromJson(entry.data.body);
|
||||||
if (body.relatedEvent != null) {
|
if (body.relatedEvent != null) {
|
||||||
currentEvents.removeWhere((x) => x.id == body.relatedEvent);
|
currentEvents.removeWhere((x) => x.id == body.relatedEvent);
|
||||||
}
|
}
|
||||||
|
@ -273,9 +273,7 @@ class _PostItemState extends State<PostItem> {
|
|||||||
attachmentsId: item.attachments ?? List.empty(),
|
attachmentsId: item.attachments ?? List.empty(),
|
||||||
divided: true,
|
divided: true,
|
||||||
),
|
),
|
||||||
SizedBox(
|
PostQuickAction(
|
||||||
width: MediaQuery.of(context).size.width * 0.9,
|
|
||||||
child: PostQuickAction(
|
|
||||||
isShowReply: widget.isShowReply,
|
isShowReply: widget.isShowReply,
|
||||||
isReactable: widget.isReactable,
|
isReactable: widget.isReactable,
|
||||||
item: widget.item,
|
item: widget.item,
|
||||||
@ -291,7 +289,6 @@ class _PostItemState extends State<PostItem> {
|
|||||||
right: 16,
|
right: 16,
|
||||||
bottom: 10,
|
bottom: 10,
|
||||||
),
|
),
|
||||||
),
|
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user