|
|
|
@ -64,6 +64,7 @@ Message compileOverlay(MessageInfo messageInfo) {
|
|
|
|
|
|
|
|
|
|
abstract class CacheHandler {
|
|
|
|
|
Future<MessageInfo?> get(Cwtch cwtch, String profileOnion, int conversationIdentifier, MessageCache cache);
|
|
|
|
|
Future<MessageInfo?> sync(Cwtch cwtch, String profileOnion, int conversationIdentifier, MessageCache cache);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class ByIndex implements CacheHandler {
|
|
|
|
@ -128,7 +129,7 @@ class ByIndex implements CacheHandler {
|
|
|
|
|
List<dynamic> messagesWrapper = jsonDecode(msgs);
|
|
|
|
|
|
|
|
|
|
for (; i < messagesWrapper.length; i++) {
|
|
|
|
|
var messageInfo = messageWrapperToInfo(profileOnion, conversationIdentifier, messagesWrapper[i]);
|
|
|
|
|
var messageInfo = MessageWrapperToInfo(profileOnion, conversationIdentifier, messagesWrapper[i]);
|
|
|
|
|
cache.addIndexed(messageInfo, start + i);
|
|
|
|
|
}
|
|
|
|
|
} catch (e, stacktrace) {
|
|
|
|
@ -143,6 +144,13 @@ class ByIndex implements CacheHandler {
|
|
|
|
|
void add(MessageCache cache, MessageInfo messageInfo) {
|
|
|
|
|
cache.addIndexed(messageInfo, index);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Future<MessageInfo?> sync(Cwtch cwtch, String profileOnion, int conversationIdentifier, MessageCache cache) {
|
|
|
|
|
EnvironmentConfig.debugLog("performing a resync on message ${index}");
|
|
|
|
|
fetchAndProcess(index, 1, cwtch, profileOnion, conversationIdentifier, cache);
|
|
|
|
|
return get(cwtch, profileOnion, conversationIdentifier, cache);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class ById implements CacheHandler {
|
|
|
|
@ -172,6 +180,11 @@ class ById implements CacheHandler {
|
|
|
|
|
}
|
|
|
|
|
return fetch(cwtch, profileOnion, conversationIdentifier, cache);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Future<MessageInfo?> sync(Cwtch cwtch, String profileOnion, int conversationIdentifier, MessageCache cache) {
|
|
|
|
|
return get(cwtch, profileOnion, conversationIdentifier, cache);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class ByContentHash implements CacheHandler {
|
|
|
|
@ -200,6 +213,11 @@ class ByContentHash implements CacheHandler {
|
|
|
|
|
}
|
|
|
|
|
return fetch(cwtch, profileOnion, conversationIdentifier, cache);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Future<MessageInfo?> sync(Cwtch cwtch, String profileOnion, int conversationIdentifier, MessageCache cache) {
|
|
|
|
|
return get(cwtch, profileOnion, conversationIdentifier, cache);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
List<Message> getReplies(MessageCache cache, int messageIdentifier) {
|
|
|
|
@ -257,6 +275,16 @@ Future<Message> messageHandler(BuildContext context, String profileOnion, int co
|
|
|
|
|
|
|
|
|
|
MessageInfo? messageInfo = await cacheHandler.get(cwtch, profileOnion, conversationIdentifier, cache);
|
|
|
|
|
|
|
|
|
|
if (messageInfo != null) {
|
|
|
|
|
if (messageInfo.metadata.ackd == false) {
|
|
|
|
|
if (messageInfo.metadata.lastChecked == null || messageInfo.metadata.lastChecked!.difference(DateTime.now()).abs().inSeconds > 30) {
|
|
|
|
|
messageInfo.metadata.lastChecked = DateTime.now();
|
|
|
|
|
// NOTE: Only ByIndex lookups will trigger
|
|
|
|
|
messageInfo = await cacheHandler.sync(cwtch, profileOnion, conversationIdentifier, cache);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (messageInfo != null) {
|
|
|
|
|
return compileOverlay(messageInfo);
|
|
|
|
|
} else {
|
|
|
|
@ -272,14 +300,14 @@ MessageInfo? messageJsonToInfo(String profileOnion, int conversationIdentifier,
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return messageWrapperToInfo(profileOnion, conversationIdentifier, messageWrapper);
|
|
|
|
|
return MessageWrapperToInfo(profileOnion, conversationIdentifier, messageWrapper);
|
|
|
|
|
} catch (e, stacktrace) {
|
|
|
|
|
EnvironmentConfig.debugLog("message handler exception on parse message and cache: " + e.toString() + " " + stacktrace.toString());
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MessageInfo messageWrapperToInfo(String profileOnion, int conversationIdentifier, dynamic messageWrapper) {
|
|
|
|
|
MessageInfo MessageWrapperToInfo(String profileOnion, int conversationIdentifier, dynamic messageWrapper) {
|
|
|
|
|
// Construct the initial metadata
|
|
|
|
|
var messageID = messageWrapper['ID'];
|
|
|
|
|
var timestamp = DateTime.tryParse(messageWrapper['Timestamp'])!;
|
|
|
|
@ -312,6 +340,7 @@ class MessageMetadata extends ChangeNotifier {
|
|
|
|
|
|
|
|
|
|
final String? signature;
|
|
|
|
|
final String contenthash;
|
|
|
|
|
DateTime? lastChecked;
|
|
|
|
|
|
|
|
|
|
dynamic get attributes => this._attributes;
|
|
|
|
|
|
|
|
|
|