publishUserAvatar method

Future<Result<AvatarError, bool>> publishUserAvatar(
  1. String base64,
  2. String hash,
  3. bool public
)

Publish the avatar data, base64, on the pubsub node using hash as the item id. hash must be the SHA-1 hash of the image data, while base64 must be the base64-encoded version of the image data.

Implementation

Future<Result<AvatarError, bool>> publishUserAvatar(
  String base64,
  String hash,
  bool public,
) async {
  final pubsub = _getPubSubManager();
  final result = await pubsub.publish(
    getAttributes().getFullJID().toBare(),
    userAvatarDataXmlns,
    XMLNode.xmlns(
      tag: 'data',
      xmlns: userAvatarDataXmlns,
      text: base64,
    ),
    id: hash,
    options: PubSubPublishOptions(
      accessModel: public ? 'open' : 'roster',
    ),
  );

  if (result.isType<PubSubError>()) return Result(UnknownAvatarError());

  return const Result(true);
}