applyPollUpdateEvent method Null safety

bool applyPollUpdateEvent(
  1. PollUpdateEvent event
)

Applies PollUpdateEvent event to this message

Implementation

bool applyPollUpdateEvent(PollUpdateEvent event) {
  if (this.id != event.pollId) {
    return false;
  } else if (updatedAt < event.json['ts']) {
    //Replace all event here
    if (event.json['poll']['title'] != null) {
      this.title = event.json['poll']['title'];
    }
    if (event.json['poll']['close_at'] != null) {
      this.closeAt = event.json['poll']['close_at'];
    }
    if (event.json['poll']['status'] != null) {
      switch (event.json['poll']['status']) {
        case 'open':
          this.status = PollStatus.open;
          break;
        case 'closed':
          this.status = PollStatus.closed;
          break;
      }
    }
    if (event.json['poll']['data'] != null) {
      this.data = PollData(text: event.json['poll']['data']['text']);
    }
    if (event.json['poll']['voter_count'] != null) {
      this.voterCount = event.json['poll']['voter_count'];
    }
    if (event.json['poll']['options'] != null) {
      List<PollOption> list = [];
      for (var pollOption in event.json['poll']['options']) {
        list.add(PollOption.fromJson(pollOption));
      }
      this.options = list;
    }
    //TODO include when isAnonymous is available
    // if (event.json['poll']['is_anonymous'] != null) {
    //   this.isAnonymous = event.json['poll']['is_anonymous'];
    // }
    if (event.json['poll']['allow_user_suggestion'] != null) {
      this.allowUserSuggestion = event.json['poll']['allow_user_suggestion'];
    }
    if (event.json['poll']['allow_multiple_votes'] != null) {
      this.allowMultipleVotes = event.json['poll']['allow_multiple_votes'];
    }
    if (event.json['poll']['voted_poll_option_ids'] != null) {
      this.votedPollOptionIds = event.json['poll']['voted_poll_option_ids'];
    }

    return true;
  } else {
    return false;
  }
}