NCPoll.m 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /**
  2. * SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors
  3. * SPDX-License-Identifier: GPL-3.0-or-later
  4. */
  5. #import "NCPoll.h"
  6. @implementation NCPoll
  7. + (instancetype)initWithPollDictionary:(NSDictionary *)pollDict
  8. {
  9. if (!pollDict || ![pollDict isKindOfClass:[NSDictionary class]]) {
  10. return nil;
  11. }
  12. NCPoll *poll = [[NCPoll alloc] init];
  13. poll.pollId = [[pollDict objectForKey:@"id"] integerValue];
  14. poll.question = [pollDict objectForKey:@"question"];
  15. poll.options = [pollDict objectForKey:@"options"];
  16. poll.votes = [pollDict objectForKey:@"votes"];
  17. poll.actorType = [pollDict objectForKey:@"actorType"];
  18. poll.actorId = [pollDict objectForKey:@"actorId"];
  19. poll.actorDisplayName = [pollDict objectForKey:@"actorDisplayName"];
  20. poll.status = (NCPollStatus)[[pollDict objectForKey:@"status"] integerValue];
  21. poll.resultMode = (NCPollResultMode)[[pollDict objectForKey:@"resultMode"] integerValue];
  22. poll.maxVotes = [[pollDict objectForKey:@"maxVotes"] integerValue];
  23. poll.votedSelf = [pollDict objectForKey:@"votedSelf"];
  24. poll.numVoters = [[pollDict objectForKey:@"numVoters"] integerValue];
  25. poll.details = [pollDict objectForKey:@"details"];
  26. if (![poll.votes isKindOfClass:[NSDictionary class]]) {
  27. poll.votes = @{};
  28. }
  29. if (![poll.options isKindOfClass:[NSArray class]]) {
  30. poll.options = @[];
  31. }
  32. if (![poll.votedSelf isKindOfClass:[NSArray class]]) {
  33. poll.votedSelf = @[];
  34. }
  35. if (![poll.details isKindOfClass:[NSArray class]]) {
  36. poll.details = @[];
  37. }
  38. return poll;
  39. }
  40. @end