upsertUserProfile method

ProgressListener? upsertUserProfile(
  1. UserProfile profile, {
  2. void onComplete(
    1. 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

Returns

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;
}