upsertUserProfile method
- UserProfile profile, {
- void onComplete(
- GemError error
Saves a profile locally, keyed by UserProfile.userID, and queues it for sync.
The profile syncs whenever a session is set, regardless of ActivityStoreConfig.syncEnabled. Set UserProfile.avatarLocalPath and UserProfile.avatarDirty to upload a new avatar. The store sets UserProfile.updatedAtMillis.
Parameters
profile: The profile; UserProfile.userID must be set.onComplete: Called with GemError.success, or another GemError when the profile could not be saved.
Returns
- The ProgressListener of the call, or null when it could not start.
Implementation
ProgressListener? upsertUserProfile(
UserProfile profile, {
void Function(GemError error)? onComplete,
}) {
final EventDrivenProgressListener progressListener =
EventDrivenProgressListener();
GemKitPlatform.instance.registerEventHandler(
progressListener.id,
progressListener,
);
progressListener.registerOnCompleteWithData((
int err,
String hint,
Map<dynamic, dynamic> json,
) {
GemKitPlatform.instance.unregisterEventHandler(progressListener.id);
onComplete?.call(GemErrorExtension.fromCode(err));
});
final OperationResult resultString = objectMethod(
pointerId,
'ActivityStore',
'upsertUserProfile',
args: <String, dynamic>{
'profile': profile.toJson(),
'listener': progressListener.id,
},
logPrivacyLevel: LogPrivacyLevel.hideArgumentValues,
);
final GemError errorCode = GemErrorExtension.fromCode(
resultString['result'],
);
if (errorCode != GemError.success) {
onComplete?.call(errorCode);
return null;
}
return progressListener;
}