applyPollVoteEvent method

bool applyPollVoteEvent(
  1. PollVoteEvent event
)

Applies PollVoteEvent event to this message

Implementation

bool applyPollVoteEvent(PollVoteEvent event) {
  if (this.id != event.pollId) {
    return false;
  } else if (updatedAt < event.json['ts']) {
    //Replace all event here
    if (event.json['updated_vote_counts'] != null) {
      //go through each list and update
      (event.json['updated_vote_counts'] as List).forEach((e) {
        int id = e['option_id'];
        int voteCount = e['vote_count'];
        options.indexWhere((option) {
          if (option.id == id) {
            option.voteCount = voteCount;
          }
          return true;
        });
      });
    }
  } else {
    return false;
  }

  return true;

  // var _result = false;
  // final currentPoll = poll;
  // if (currentPoll == null) {
  //   return false;
  // }
  // if (currentPoll.id != event.pollId) return false;
  // final currentPollDetail = currentPoll.details;
  // if (currentPollDetail == null) {
  //   return false;
  // } else {
  //   //update vote count and vote at
  //   for (var option in currentPollDetail.options) {
  //     if (option.applyEvent(event)) {
  //       _result = true;
  //     }
  //   }
  //   return _result;
  // }
}