mirror of
https://github.com/BlueBubblesApp/bluebubbles-app.git
synced 2025-08-06 19:44:08 +08:00
Revert "Revert "more message match improvements""
This reverts commit e7e73af99d99a843444a915370d3ad077b23d76b.
This commit is contained in:
@ -27,6 +27,12 @@ class _DeliveredIndicatorState extends CustomState<DeliveredIndicator, void, Mes
|
|||||||
void initState() {
|
void initState() {
|
||||||
forceDelete = false;
|
forceDelete = false;
|
||||||
super.initState();
|
super.initState();
|
||||||
|
|
||||||
|
eventDispatcher.stream.listen((event) {
|
||||||
|
if (event.item1 == "message-updated-${message.guid}") {
|
||||||
|
setState(() {});
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
bool get shouldShow {
|
bool get shouldShow {
|
||||||
|
@ -282,7 +282,7 @@ class Message {
|
|||||||
set dateDelivered(DateTime? d) => _dateDelivered.value = d;
|
set dateDelivered(DateTime? d) => _dateDelivered.value = d;
|
||||||
|
|
||||||
final RxBool _isDelivered = RxBool(false);
|
final RxBool _isDelivered = RxBool(false);
|
||||||
bool get isDelivered => _isDelivered.value;
|
bool get isDelivered => (dateDelivered != null) ? true : _isDelivered.value;
|
||||||
set isDelivered(bool b) => _isDelivered.value = b;
|
set isDelivered(bool b) => _isDelivered.value = b;
|
||||||
|
|
||||||
final Rxn<DateTime> _dateEdited = Rxn<DateTime>();
|
final Rxn<DateTime> _dateEdited = Rxn<DateTime>();
|
||||||
@ -1113,6 +1113,9 @@ class Message {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool isNewerThan(Message other) {
|
bool isNewerThan(Message other) {
|
||||||
|
// If the other message has an error, we want to show that.
|
||||||
|
if (error == 0 && other.error != 0) return false;
|
||||||
|
|
||||||
// Check null dates in order of what should be filled in first -> last
|
// Check null dates in order of what should be filled in first -> last
|
||||||
if (dateCreated == null && other.dateCreated != null) return false;
|
if (dateCreated == null && other.dateCreated != null) return false;
|
||||||
if (dateCreated != null && other.dateCreated == null) return true;
|
if (dateCreated != null && other.dateCreated == null) return true;
|
||||||
|
@ -66,27 +66,36 @@ class ActionHandler extends GetxService {
|
|||||||
return messages;
|
return messages;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> matchMessageWithExisting(Chat chat, Message existing, Message replacement) async {
|
Future<void> matchMessageWithExisting(Chat chat, String existingGuid, Message replacement, {Message? existing}) async {
|
||||||
// First, try to find a matching message with the replacement's GUID.
|
// First, try to find a matching message with the replacement's GUID.
|
||||||
// We check this first because if an event came in for that GUID, we should be able to ignore
|
// We check this first because if an event came in for that GUID, we should be able to ignore
|
||||||
// the API response.
|
// the API response.
|
||||||
final existingReplacementMessage = Message.findOne(guid: replacement.guid);
|
final existingReplacementMessage = Message.findOne(guid: replacement.guid);
|
||||||
if (existingReplacementMessage != null) {
|
if (existingReplacementMessage != null) {
|
||||||
Logger.debug("Found existing message with GUID ${replacement.guid}! Not replacing...", tag: "MessageStatus");
|
Logger.debug("Found existing message with GUID ${replacement.guid}...", tag: "MessageStatus");
|
||||||
|
|
||||||
|
if (replacement.isNewerThan(existingReplacementMessage)) {
|
||||||
|
Logger.debug("Replacing existing message with newer message (GUID: ${replacement.guid})...", tag: "MessageStatus");
|
||||||
|
await Message.replaceMessage(replacement.guid, replacement);
|
||||||
|
} else {
|
||||||
|
Logger.debug("Existing message with GUID ${replacement.guid} is newer than the replacement...", tag: "MessageStatus");
|
||||||
|
}
|
||||||
|
|
||||||
// Delete the temp message if it exists
|
// Delete the temp message if it exists
|
||||||
if (existing.guid != replacement.guid) {
|
if (existingGuid != replacement.guid) {
|
||||||
Logger.debug("Deleting temp message with GUID ${existing.guid}...", tag: "MessageStatus");
|
Logger.debug("Deleting temp message with GUID $existingGuid...", tag: "MessageStatus");
|
||||||
final existingTempMessage = Message.findOne(guid: existing.guid);
|
final existingTempMessage = Message.findOne(guid: existingGuid);
|
||||||
if (existingTempMessage != null) {
|
if (existingTempMessage != null) {
|
||||||
Message.delete(existingTempMessage.guid!);
|
Message.delete(existingTempMessage.guid!);
|
||||||
|
if (existing != null) {
|
||||||
ms(chat.guid).removeMessage(existing);
|
ms(chat.guid).removeMessage(existing);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// If we didn't find a matching message with the replacement's GUID, replace the existing message.
|
// If we didn't find a matching message with the replacement's GUID, replace the existing message.
|
||||||
Logger.debug("Replacing message with GUID ${existing.guid} with ${replacement.guid}...", tag: "MessageStatus");
|
Logger.debug("Replacing message with GUID $existingGuid with ${replacement.guid}...", tag: "MessageStatus");
|
||||||
await Message.replaceMessage(existing.guid, replacement);
|
await Message.replaceMessage(existingGuid, replacement);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -111,7 +120,7 @@ class ActionHandler extends GetxService {
|
|||||||
).then((response) async {
|
).then((response) async {
|
||||||
final newMessage = Message.fromMap(response.data['data']);
|
final newMessage = Message.fromMap(response.data['data']);
|
||||||
try {
|
try {
|
||||||
await matchMessageWithExisting(c, m, newMessage);
|
await matchMessageWithExisting(c, m.guid!, newMessage, existing: m);
|
||||||
} catch (_) {
|
} catch (_) {
|
||||||
Logger.warn("Failed to find message match for ${m.guid} -> ${newMessage.guid}!", tag: "MessageStatus");
|
Logger.warn("Failed to find message match for ${m.guid} -> ${newMessage.guid}!", tag: "MessageStatus");
|
||||||
}
|
}
|
||||||
@ -133,7 +142,7 @@ class ActionHandler extends GetxService {
|
|||||||
http.sendTapback(c.guid, selected!.text ?? "", selected.guid!, r, partIndex: m.associatedMessagePart).then((response) async {
|
http.sendTapback(c.guid, selected!.text ?? "", selected.guid!, r, partIndex: m.associatedMessagePart).then((response) async {
|
||||||
final newMessage = Message.fromMap(response.data['data']);
|
final newMessage = Message.fromMap(response.data['data']);
|
||||||
try {
|
try {
|
||||||
await matchMessageWithExisting(c, m, newMessage);
|
await matchMessageWithExisting(c, m.guid!, newMessage, existing: m);
|
||||||
} catch (_) {
|
} catch (_) {
|
||||||
Logger.warn("Failed to find message match for ${m.guid} -> ${newMessage.guid}!", tag: "MessageStatus");
|
Logger.warn("Failed to find message match for ${m.guid} -> ${newMessage.guid}!", tag: "MessageStatus");
|
||||||
}
|
}
|
||||||
@ -172,7 +181,7 @@ class ActionHandler extends GetxService {
|
|||||||
).then((response) async {
|
).then((response) async {
|
||||||
final newMessage = Message.fromMap(response.data['data']);
|
final newMessage = Message.fromMap(response.data['data']);
|
||||||
try {
|
try {
|
||||||
await matchMessageWithExisting(c, m, newMessage);
|
await matchMessageWithExisting(c, m.guid!, newMessage, existing: m);
|
||||||
} catch (_) {
|
} catch (_) {
|
||||||
Logger.warn("Failed to find message match for ${m.guid} -> ${newMessage.guid}!", tag: "MessageStatus");
|
Logger.warn("Failed to find message match for ${m.guid} -> ${newMessage.guid}!", tag: "MessageStatus");
|
||||||
}
|
}
|
||||||
@ -237,10 +246,16 @@ class ActionHandler extends GetxService {
|
|||||||
|
|
||||||
for (Attachment? a in newMessage.attachments) {
|
for (Attachment? a in newMessage.attachments) {
|
||||||
if (a == null) continue;
|
if (a == null) continue;
|
||||||
Attachment.replaceAttachment(m.guid, a);
|
|
||||||
}
|
|
||||||
try {
|
try {
|
||||||
await matchMessageWithExisting(c, m, newMessage);
|
Attachment.replaceAttachment(m.guid, a);
|
||||||
|
} catch (e) {
|
||||||
|
Logger.warn("Failed to replace attachment ${a.guid}!", tag: "MessageStatus");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
await matchMessageWithExisting(c, m.guid!, newMessage, existing: m);
|
||||||
} catch (_) {
|
} catch (_) {
|
||||||
Logger.warn("Failed to find message match for ${m.guid} -> ${newMessage.guid}!", tag: "MessageStatus");
|
Logger.warn("Failed to find message match for ${m.guid} -> ${newMessage.guid}!", tag: "MessageStatus");
|
||||||
}
|
}
|
||||||
@ -296,13 +311,21 @@ class ActionHandler extends GetxService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
Logger.info("Updated message: [${m.text}] ${m.getLastUpdate().toLowerCase()} - for chat [${c.guid}]", tag: "ActionHandler");
|
Logger.info("Updated message: [${m.text}] ${m.getLastUpdate().toLowerCase()} - for chat [${c.guid}]", tag: "ActionHandler");
|
||||||
|
|
||||||
// update any attachments
|
// update any attachments
|
||||||
for (Attachment? a in m.attachments) {
|
for (Attachment? a in m.attachments) {
|
||||||
if (a == null) continue;
|
if (a == null) continue;
|
||||||
|
|
||||||
|
try {
|
||||||
Attachment.replaceAttachment(tempGuid ?? m.guid, a);
|
Attachment.replaceAttachment(tempGuid ?? m.guid, a);
|
||||||
|
} catch (e) {
|
||||||
|
Logger.warn("Failed to replace attachment ${a.guid}!", tag: "MessageStatus");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// update the message in the DB
|
// update the message in the DB
|
||||||
await Message.replaceMessage(tempGuid ?? m.guid, m);
|
await matchMessageWithExisting(c, tempGuid ?? m.guid!, m);
|
||||||
|
eventDispatcher.emit("message-updated-${m.guid}");
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<Chat> handleNewOrUpdatedChat(Chat partialData) async {
|
Future<Chat> handleNewOrUpdatedChat(Chat partialData) async {
|
||||||
|
Reference in New Issue
Block a user