applyPollUpdateEvent method

bool applyPollUpdateEvent(
  1. PollUpdateEvent event
)

Applies poll update event to this user message's poll.

Implementation

bool applyPollUpdateEvent(PollUpdateEvent event) {
  sbLog.i(StackTrace.current, 'event: $event');

  if (id != event.pollId) {
    return false;
  } else if (updatedAt < event.json['ts']) {
    // Replace all event here
    if (event.json['poll']['title'] != null) {
      title = event.json['poll']['title'];
    }
    if (event.json['poll']['close_at'] != null) {
      closeAt = event.json['poll']['close_at'];
    }
    if (event.json['poll']['status'] != null) {
      switch (event.json['poll']['status']) {
        case 'open':
          status = PollStatus.open;
          break;
        case 'closed':
          status = PollStatus.closed;
          break;
      }
    }
    if (event.json['poll']['data'] != null) {
      data = PollData(text: event.json['poll']['data']['text']);
    }
    if (event.json['poll']['voter_count'] != null) {
      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));
      }
      options = list;
    }

    if (event.json['poll']['allow_user_suggestion'] != null) {
      allowUserSuggestion = event.json['poll']['allow_user_suggestion'];
    }
    if (event.json['poll']['allow_multiple_votes'] != null) {
      allowMultipleVotes = event.json['poll']['allow_multiple_votes'];
    }
    if (event.json['poll']['voted_poll_option_ids'] != null) {
      votedPollOptionIds = event.json['poll']['voted_poll_option_ids'];
    }

    return true;
  } else {
    return false;
  }
}