newReply method

Future<List<ModeratorEntry>?> newReply(
  1. String text,
  2. String nick,
  3. String avatar,
  4. String rootShortlink,
  5. String ppShortlink,
  6. Uint8List attachement,
  7. String mimeType,
  8. String _xxHash,
  9. String _blurHash,
)

Implementation

Future<List<ModeratorEntry>?> newReply(
    String text,
    String nick,
    String avatar,
    String rootShortlink,
    String ppShortlink,
    Uint8List attachement,
    String mimeType,
    String _xxHash,
    String _blurHash) async {
  if (_latestCapsule == null) return null;
  Uint8List nt;
  if (text.contains('https://')) {
    bool bcHash = text.contains('#bandcamp');
    bool tagBc = false;
    if (!text.startsWith('[')) {
      final ali = text.split('https://');
      final alib = ali[1].split(' ');
      final scresu = await scrapeBClink('https://' + alib[0]);
      if (scresu.isNotEmpty) {
        //pull the image as attachement
        if (scresu.last is Uint8List && attachement.isEmpty) {
          attachement = scresu.last;
          //patch url title pair
          text = '[' + scresu[0] + '](' + scresu[1] + ') ';
        } else {
          text = scresu[2];
        }

        if (!bcHash && scresu.contains('bandcamp')) tagBc = true;
        bool sk = false;
        alib.forEach((element) {
          if (!sk) {
            sk = true;
            return;
          }
          text += ' ' + element;
        });

        if (!bcHash && tagBc) text += ' #bandcamp';
      }
    }
  } //dont touch markdown links

  if (mimeType.isEmpty) {
    nt = await _io!.newReply(
        baseUrl,
        text,
        rootShortlink,
        ppShortlink,
        _latestCapsule != null ? _latestCapsule!.katamari : Uint8List(0),
        nick,
        avatar,
        Uint8List(0));

    if (nt.isEmpty) return null;
    //return empty list with dup
    final u = updateLatestCapsule(nt, false);
    if (u != null && u.isEmpty) return [];

    _dirty = true;
    currentPendingAsModeratorEntries;
    return threadByShortLink(rootShortlink).toList();
  }

  var attParamsToPass = Uint8List(0);
  final atty = await _xxCache.pullLocalXX(_xxHash.toString());
  if (atty != null && atty.isNotEmpty) {
    final cid = await _xxCache.CIDforXX(_xxHash);
    if (cid.isEmpty) {
      //dont submit without ipfs
      return [];
    }
    final rds = redressTextAndAttachment(
        text, atty.lengthInBytes, _xxHash, mimeType, cid);
    if (rds.isEmpty) {
      return null;
    }
    text = rds[0];
    attParamsToPass = rds[1];
    if (_blurHash.isNotEmpty) {
      text += ' !|' + _blurHash + ' ';
    }
  }

  //text += ' !&' + cid + ' ';
  /*xxC.pushCidData(cid, attachement);
  try {
    final image = img.decodeImage(attachement);
    final blurHash = BlurHash.encode(image!, numCompX: 4, numCompY: 3);
    text += ' !|' + blurHash.hash + ' ';
  } catch (e) {}*/
  if (_latestCapsule == null) {
    return null;
  }
  return await _io!
      .newReply(baseUrl, text, rootShortlink, ppShortlink,
          _latestCapsule!.katamari, nick, avatar, attParamsToPass)
      .then((value) {
    if (value.isEmpty) return null;
    //gives empty list on dup
    _dirty = true;
    currentPendingAsModeratorEntries;
    return updateLatestCapsule(value, false);
  });
}