|
|
|
@ -19,7 +19,7 @@ import 'package:matrix/matrix.dart';
|
|
|
|
/// Represents an item in the completion cache.
|
|
|
|
/// Represents an item in the completion cache.
|
|
|
|
class _RequestCacheItem {
|
|
|
|
class _RequestCacheItem {
|
|
|
|
MessageActivityRequest req;
|
|
|
|
MessageActivityRequest req;
|
|
|
|
PracticeActivityModel? practiceActivity;
|
|
|
|
PracticeActivityModelResponse? practiceActivity;
|
|
|
|
|
|
|
|
|
|
|
|
_RequestCacheItem({
|
|
|
|
_RequestCacheItem({
|
|
|
|
required this.req,
|
|
|
|
required this.req,
|
|
|
|
@ -99,7 +99,7 @@ class PracticeGenerationController {
|
|
|
|
|
|
|
|
|
|
|
|
//TODO - allow return of activity content before sending the event
|
|
|
|
//TODO - allow return of activity content before sending the event
|
|
|
|
// this requires some downstream changes to the way the event is handled
|
|
|
|
// this requires some downstream changes to the way the event is handled
|
|
|
|
Future<PracticeActivityModel?> getPracticeActivity(
|
|
|
|
Future<PracticeActivityModelResponse?> getPracticeActivity(
|
|
|
|
MessageActivityRequest req,
|
|
|
|
MessageActivityRequest req,
|
|
|
|
PangeaMessageEvent event,
|
|
|
|
PangeaMessageEvent event,
|
|
|
|
) async {
|
|
|
|
) async {
|
|
|
|
@ -119,6 +119,8 @@ class PracticeGenerationController {
|
|
|
|
return null;
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final eventCompleter = Completer<PracticeActivityEvent?>();
|
|
|
|
|
|
|
|
|
|
|
|
// if the server points to an existing event, return that event
|
|
|
|
// if the server points to an existing event, return that event
|
|
|
|
if (res.existingActivityEventId != null) {
|
|
|
|
if (res.existingActivityEventId != null) {
|
|
|
|
final Event? existingEvent =
|
|
|
|
final Event? existingEvent =
|
|
|
|
@ -127,11 +129,19 @@ class PracticeGenerationController {
|
|
|
|
debugPrint(
|
|
|
|
debugPrint(
|
|
|
|
'Existing activity event found: ${existingEvent?.content}',
|
|
|
|
'Existing activity event found: ${existingEvent?.content}',
|
|
|
|
);
|
|
|
|
);
|
|
|
|
if (existingEvent != null) {
|
|
|
|
debugPrint(
|
|
|
|
return PracticeActivityEvent(
|
|
|
|
"eventID: ${existingEvent?.eventId}, event is redacted: ${existingEvent?.redacted}",
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
if (existingEvent != null && !existingEvent.redacted) {
|
|
|
|
|
|
|
|
final activityEvent = PracticeActivityEvent(
|
|
|
|
event: existingEvent,
|
|
|
|
event: existingEvent,
|
|
|
|
timeline: event.timeline,
|
|
|
|
timeline: event.timeline,
|
|
|
|
).practiceActivity;
|
|
|
|
);
|
|
|
|
|
|
|
|
eventCompleter.complete(activityEvent);
|
|
|
|
|
|
|
|
return PracticeActivityModelResponse(
|
|
|
|
|
|
|
|
activity: activityEvent.practiceActivity,
|
|
|
|
|
|
|
|
eventCompleter: eventCompleter,
|
|
|
|
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ -141,11 +151,30 @@ class PracticeGenerationController {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
debugPrint('Activity generated: ${res.activity!.toJson()}');
|
|
|
|
debugPrint('Activity generated: ${res.activity!.toJson()}');
|
|
|
|
|
|
|
|
_sendAndPackageEvent(res.activity!, event).then((event) {
|
|
|
|
|
|
|
|
eventCompleter.complete(event);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final responseModel = PracticeActivityModelResponse(
|
|
|
|
|
|
|
|
activity: res.activity!,
|
|
|
|
|
|
|
|
eventCompleter: eventCompleter,
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
_sendAndPackageEvent(res.activity!, event);
|
|
|
|
_cache[cacheKey] = _RequestCacheItem(
|
|
|
|
_cache[cacheKey] =
|
|
|
|
req: req,
|
|
|
|
_RequestCacheItem(req: req, practiceActivity: res.activity!);
|
|
|
|
practiceActivity: responseModel,
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
return _cache[cacheKey]!.practiceActivity;
|
|
|
|
return responseModel;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class PracticeActivityModelResponse {
|
|
|
|
|
|
|
|
final PracticeActivityModel? activity;
|
|
|
|
|
|
|
|
final Completer<PracticeActivityEvent?> eventCompleter;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
PracticeActivityModelResponse({
|
|
|
|
|
|
|
|
required this.activity,
|
|
|
|
|
|
|
|
required this.eventCompleter,
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|