processMetaSub method

  1. @override
void processMetaSub(
  1. List<TopicSubscription> subscriptions
)
override

Override the original Topic.processMetaSub

Implementation

@override
void processMetaSub(List<TopicSubscription> subscriptions) {
  for (var sub in subscriptions) {
    var topicName = sub.topic;
    // Don't show 'me' and 'fnd' topics in the list of contacts.
    if (topicName == topic_names.TOPIC_FND ||
        topicName == topic_names.TOPIC_ME) {
      continue;
    }

    var cont = TopicSubscription();
    if (sub.deleted != null) {
      _contacts.remove(topicName);
      _cacheManager.delete('topic', topicName ?? '');
    } else {
      // Ensure the values are defined and are integers.
      if (sub.seq != null) {
        sub.seq = sub.seq ?? 0;
        sub.recv = sub.recv ?? 0;
        sub.read = sub.read ?? 0;
        sub.unread = (sub.seq ?? 0) - (sub.read ?? 0);
      }

      var cached = _contacts[topicName];
      if (cached != null) {
        cached.acs = sub.acs ?? cached.acs;
        cached.clear = sub.clear ?? cached.clear;
        cached.created = sub.created ?? cached.created;
        cached.deleted = cached.deleted ?? cached.deleted;
        cached.mode = sub.mode ?? cached.mode;
        cached.noForwarding = sub.noForwarding ?? cached.noForwarding;
        cached.online = sub.online ?? cached.online;
        cached.private = sub.private ?? cached.private;
        cached.public = sub.public ?? cached.public;
        cached.read = sub.read ?? cached.read;
        cached.recv = sub.recv ?? cached.recv;
        cached.seen = sub.seen ?? cached.seen;
        cached.seen = sub.seen ?? cached.seen;
        cached.topic = sub.topic ?? cached.topic;
        cached.touched = sub.touched ?? cached.touched;
        cached.updated = sub.updated ?? cached.updated;
        cached.user = sub.user ?? cached.user;
      } else {
        cached = sub;
        _contacts[(topicName ?? '')] = sub;
      }
      cont = cached;

      if (topicName != null) {
        if (Tools.isP2PTopicName(topicName)) {
          _cacheManager.putUser(topicName, cont);
        }
      }

      // Notify topic of the update if it's an external update.
      if (sub.noForwarding == false || sub.noForwarding == null) {
        var topic = _tinodeService.getTopic(topicName);
        if (topic != null) {
          sub.noForwarding = true;
          topic.processMetaDesc(sub.asDesc());
        }
      }
    }

    onMetaSub.add(cont);
  }

  onSubsUpdated.add(_contacts.values.toList());
}