applyPollVoteEvent method

bool applyPollVoteEvent(
  1. PollVoteEvent event
)

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

Implementation

bool applyPollVoteEvent(PollVoteEvent 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['updated_vote_counts'] != null) {
      // go through each list and update
      for (final element in (event.json['updated_vote_counts'] as List)) {
        int optionId = element['option_id'];
        int voteCount = element['vote_count'];
        options.firstWhere((e) => (e.id == optionId)).voteCount = voteCount;
      }
    }
  } else {
    return false;
  }
  return true;
}