MOLiveList.m 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373
  1. //
  2. // MOLiveList.m
  3. //
  4. // Created by SuperCabbage on 2023/10/18
  5. // Copyright (c) 2023 __MyCompanyName__. All rights reserved.
  6. //
  7. #import "MOLiveList.h"
  8. #import "MOUserProfile.h"
  9. #import "MOConfigList.h"
  10. #import "MOLiveBadge.h"
  11. NSString *const kLiveListLiveTag = @"liveTag";
  12. NSString *const kLiveListLiveType = @"liveType";
  13. NSString *const kLiveListId = @"id";
  14. NSString *const kLiveListActiveTag = @"activeTag";
  15. NSString *const kLiveListRoomType = @"roomType";
  16. NSString *const kLiveListLogo = @"logo";
  17. NSString *const kLiveListName = @"name";
  18. NSString *const kLiveListVisitNum = @"visitNum";
  19. NSString *const kLiveListAnchorUser = @"anchorUser";
  20. NSString *const kLiveListAtmosphere = @"atmosphere";
  21. NSString *const kLiveListOpenTime = @"openTime";
  22. NSString *const kLiveListWeScore = @"weScore";
  23. NSString *const kLiveListOppScore = @"oppScore";
  24. NSString *const kLiveListPkStartTime = @"pkStartTime";
  25. NSString *const kLiveListSettleTime = @"settleTime";
  26. NSString *const kLiveListPkEndTime = @"pkEndTime";
  27. NSString *const kLiveListPkStatus = @"pkStatus";
  28. NSString *const kLiveListRoomId = @"roomId";
  29. NSString *const kLiveListPkRtcToken = @"pkRtcToken";
  30. NSString *const kLiveListWeTops = @"weTops";
  31. NSString *const kLiveListOppoTops = @"oppoTops";
  32. NSString *const kLiveListLiveBadge = @"liveBadge";
  33. NSString *const kLiveListFansClubId = @"fansClubId";
  34. NSString *const kLiveListMultiple = @"multiple";
  35. NSString *const kLiveListPk= @"pk";
  36. NSString *const kLiveListRedEnvelope = @"redEnvelope";
  37. NSString *const kLiveListBgBorder = @"bgBorder";
  38. @interface MOLiveList ()
  39. - (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict;
  40. @end
  41. @implementation MOLiveList
  42. @synthesize liveTag = _liveTag;
  43. @synthesize liveType = _liveType;
  44. @synthesize id = _id;
  45. @synthesize activeTag = _activeTag;
  46. @synthesize roomType = _roomType;
  47. @synthesize logo = _logo;
  48. @synthesize name = _name;
  49. @synthesize visitNum = _visitNum;
  50. @synthesize anchorUser = _anchorUser;
  51. @synthesize atmosphere = _atmosphere;
  52. @synthesize openTime = _openTime;
  53. @synthesize weScore = _weScore;
  54. @synthesize oppScore = _oppScore;
  55. @synthesize pkStartTime = _pkStartTime;
  56. @synthesize settleTime = _settleTime;
  57. @synthesize pkEndTime = _pkEndTime;
  58. @synthesize pkStatus = _pkStatus;
  59. @synthesize roomId = _roomId;
  60. @synthesize pkRtcToken = _pkRtcToken;
  61. @synthesize weTops = _weTops;
  62. @synthesize oppoTops = _oppoTops;
  63. @synthesize liveBadge = _liveBadge;
  64. @synthesize fansClubId = _fansClubId;
  65. @synthesize multiple = _multiple;
  66. @synthesize pk = _pk;
  67. @synthesize redEnvelope = _redEnvelope;
  68. @synthesize bgBorder = _bgBorder;
  69. + (instancetype)modelObjectWithDictionary:(NSDictionary *)dict {
  70. return [[self alloc] initWithDictionary:dict];
  71. }
  72. - (instancetype)initWithDictionary:(NSDictionary *)dict {
  73. self = [super init];
  74. // This check serves to make sure that a non-NSDictionary object
  75. // passed into the model class doesn't break the parsing.
  76. if (self && [dict isKindOfClass:[NSDictionary class]]) {
  77. self.liveTag = [MOConfigList modelObjectWithDictionary:[dict objectForKey:kLiveListLiveTag]];
  78. self.liveType = [[self objectOrNilForKey:kLiveListLiveType fromDictionary:dict] doubleValue];
  79. self.id = [self objectOrNilForKey:kLiveListId fromDictionary:dict];
  80. self.activeTag = [MOConfigList modelObjectWithDictionary:[dict objectForKey:kLiveListActiveTag]];
  81. self.roomType = [[self objectOrNilForKey:kLiveListRoomType fromDictionary:dict] doubleValue];
  82. self.logo = [self objectOrNilForKey:kLiveListLogo fromDictionary:dict];
  83. self.name = [self objectOrNilForKey:kLiveListName fromDictionary:dict];
  84. self.anchorUser = [MOUserProfile modelObjectWithDictionary:[dict objectForKey:kLiveListAnchorUser]];
  85. self.visitNum = [[self objectOrNilForKey:kLiveListVisitNum fromDictionary:dict] doubleValue];
  86. self.atmosphere = [[self objectOrNilForKey:kLiveListAtmosphere fromDictionary:dict] doubleValue];
  87. self.openTime = [[self objectOrNilForKey:kLiveListOpenTime fromDictionary:dict] doubleValue];
  88. self.weScore = [[self objectOrNilForKey:kLiveListWeScore fromDictionary:dict] doubleValue];
  89. self.oppScore = [[self objectOrNilForKey:kLiveListOppScore fromDictionary:dict] doubleValue];
  90. self.pkStartTime = [[self objectOrNilForKey:kLiveListPkStartTime fromDictionary:dict] doubleValue];
  91. self.settleTime = [[self objectOrNilForKey:kLiveListSettleTime fromDictionary:dict] doubleValue];
  92. self.pkEndTime = [[self objectOrNilForKey:kLiveListPkEndTime fromDictionary:dict] doubleValue];
  93. self.pkStatus = [[self objectOrNilForKey:kLiveListPkStatus fromDictionary:dict] doubleValue];
  94. self.roomId = [self objectOrNilForKey:kLiveListRoomId fromDictionary:dict];
  95. self.pkRtcToken = [self objectOrNilForKey:kLiveListPkRtcToken fromDictionary:dict];
  96. self.liveBadge = [MOLiveBadge modelObjectWithDictionary:[dict objectForKey:kLiveListLiveBadge]];
  97. self.fansClubId = [self objectOrNilForKey:kLiveListFansClubId fromDictionary:dict];
  98. NSObject *receivedMOWeTops = [dict objectForKey:kLiveListWeTops];
  99. NSMutableArray *parsedMOWeTops = [NSMutableArray array];
  100. if ([receivedMOWeTops isKindOfClass:[NSArray class]]) {
  101. for (NSDictionary *item in (NSArray *)receivedMOWeTops) {
  102. if ([item isKindOfClass:[NSDictionary class]]) {
  103. [parsedMOWeTops addObject:[MOUserProfile modelObjectWithDictionary:item]];
  104. }
  105. }
  106. } else if ([receivedMOWeTops isKindOfClass:[NSDictionary class]]) {
  107. [parsedMOWeTops addObject:[MOUserProfile modelObjectWithDictionary:(NSDictionary *)receivedMOWeTops]];
  108. }
  109. self.weTops = [NSArray arrayWithArray:parsedMOWeTops];
  110. NSObject *receivedMOOppoTops = [dict objectForKey:kLiveListOppoTops];
  111. NSMutableArray *parsedMOOppoTops = [NSMutableArray array];
  112. if ([receivedMOOppoTops isKindOfClass:[NSArray class]]) {
  113. for (NSDictionary *item in (NSArray *)receivedMOOppoTops) {
  114. if ([item isKindOfClass:[NSDictionary class]]) {
  115. [parsedMOOppoTops addObject:[MOUserProfile modelObjectWithDictionary:item]];
  116. }
  117. }
  118. } else if ([receivedMOOppoTops isKindOfClass:[NSDictionary class]]) {
  119. [parsedMOOppoTops addObject:[MOUserProfile modelObjectWithDictionary:(NSDictionary *)receivedMOOppoTops]];
  120. }
  121. self.oppoTops = [NSArray arrayWithArray:parsedMOOppoTops];
  122. self.multiple = [[self objectOrNilForKey:kLiveListMultiple fromDictionary:dict] boolValue];
  123. self.pk = [[self objectOrNilForKey:kLiveListPk fromDictionary:dict] boolValue];
  124. self.redEnvelope = [[self objectOrNilForKey:kLiveListRedEnvelope fromDictionary:dict] boolValue];
  125. self.bgBorder = [self objectOrNilForKey:kLiveListBgBorder fromDictionary:dict];
  126. }
  127. return self;
  128. }
  129. - (NSDictionary *)dictionaryRepresentation {
  130. NSMutableDictionary *mutableDict = [NSMutableDictionary dictionary];
  131. [mutableDict setValue:[self.liveTag dictionaryRepresentation] forKey:kLiveListLiveTag];
  132. [mutableDict setValue:[NSNumber numberWithDouble:self.liveType] forKey:kLiveListLiveType];
  133. [mutableDict setValue:self.id forKey:kLiveListId];
  134. [mutableDict setValue:[self.activeTag dictionaryRepresentation] forKey:kLiveListActiveTag];
  135. [mutableDict setValue:[NSNumber numberWithDouble:self.roomType] forKey:kLiveListRoomType];
  136. [mutableDict setValue:self.logo forKey:kLiveListLogo];
  137. [mutableDict setValue:self.name forKey:kLiveListName];
  138. [mutableDict setValue:[self.anchorUser dictionaryRepresentation] forKey:kLiveListAnchorUser];
  139. [mutableDict setValue:[NSNumber numberWithDouble:self.visitNum] forKey:kLiveListVisitNum];
  140. [mutableDict setValue:[NSNumber numberWithDouble:self.atmosphere] forKey:kLiveListAtmosphere];
  141. [mutableDict setValue:[NSNumber numberWithDouble:self.openTime] forKey:kLiveListOpenTime];
  142. [mutableDict setValue:[NSNumber numberWithDouble:self.weScore] forKey:kLiveListWeScore];
  143. [mutableDict setValue:[NSNumber numberWithDouble:self.oppScore] forKey:kLiveListOppScore];
  144. [mutableDict setValue:[NSNumber numberWithDouble:self.pkStartTime] forKey:kLiveListPkStartTime];
  145. [mutableDict setValue:[NSNumber numberWithDouble:self.settleTime] forKey:kLiveListSettleTime];
  146. [mutableDict setValue:[NSNumber numberWithDouble:self.pkEndTime] forKey:kLiveListPkEndTime];
  147. [mutableDict setValue:[NSNumber numberWithDouble:self.pkStatus] forKey:kLiveListPkStatus];
  148. [mutableDict setValue:self.roomId forKey:kLiveListRoomId];
  149. [mutableDict setValue:self.pkRtcToken forKey:kLiveListPkRtcToken];
  150. [mutableDict setValue:self.fansClubId forKey:kLiveListFansClubId];
  151. [mutableDict setValue:[self.liveBadge dictionaryRepresentation] forKey:kLiveListLiveBadge];
  152. NSMutableArray *tempArrayForWeTops = [NSMutableArray array];
  153. for (NSObject *subArrayObject in self.weTops) {
  154. if ([subArrayObject respondsToSelector:@selector(dictionaryRepresentation)]) {
  155. // This class is a model object
  156. [tempArrayForWeTops addObject:[subArrayObject performSelector:@selector(dictionaryRepresentation)]];
  157. } else {
  158. // Generic object
  159. [tempArrayForWeTops addObject:subArrayObject];
  160. }
  161. }
  162. [mutableDict setValue:[NSArray arrayWithArray:tempArrayForWeTops] forKey:kLiveListWeTops];
  163. NSMutableArray *tempArrayForOppoTops= [NSMutableArray array];
  164. for (NSObject *subArrayObject in self.oppoTops) {
  165. if ([subArrayObject respondsToSelector:@selector(dictionaryRepresentation)]) {
  166. // This class is a model object
  167. [tempArrayForOppoTops addObject:[subArrayObject performSelector:@selector(dictionaryRepresentation)]];
  168. } else {
  169. // Generic object
  170. [tempArrayForOppoTops addObject:subArrayObject];
  171. }
  172. }
  173. [mutableDict setValue:[NSArray arrayWithArray:tempArrayForOppoTops] forKey:kLiveListOppoTops];
  174. [mutableDict setValue:[NSNumber numberWithBool:self.multiple] forKey:kLiveListMultiple];
  175. [mutableDict setValue:[NSNumber numberWithBool:self.pk] forKey:kLiveListPk];
  176. [mutableDict setValue:[NSNumber numberWithBool:self.redEnvelope] forKey:kLiveListRedEnvelope];
  177. [mutableDict setValue:self.bgBorder forKey:kLiveListBgBorder];
  178. return [NSDictionary dictionaryWithDictionary:mutableDict];
  179. }
  180. - (NSString *)description {
  181. return [NSString stringWithFormat:@"%@", [self dictionaryRepresentation]];
  182. }
  183. #pragma mark - Helper Method
  184. - (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict {
  185. id object = [dict objectForKey:aKey];
  186. return [object isEqual:[NSNull null]] ? nil : object;
  187. }
  188. #pragma mark - NSCoding Methods
  189. - (id)initWithCoder:(NSCoder *)aDecoder {
  190. self = [super init];
  191. self.liveTag = [aDecoder decodeObjectForKey:kLiveListLiveTag];
  192. self.liveType = [aDecoder decodeDoubleForKey:kLiveListLiveType];
  193. self.id = [aDecoder decodeObjectForKey:kLiveListId];
  194. self.activeTag = [aDecoder decodeObjectForKey:kLiveListActiveTag];
  195. self.roomType = [aDecoder decodeDoubleForKey:kLiveListRoomType];
  196. self.logo = [aDecoder decodeObjectForKey:kLiveListLogo];
  197. self.name = [aDecoder decodeObjectForKey:kLiveListName];
  198. self.anchorUser = [aDecoder decodeObjectForKey:kLiveListAnchorUser];
  199. self.visitNum = [aDecoder decodeDoubleForKey:kLiveListVisitNum];
  200. self.atmosphere = [aDecoder decodeDoubleForKey:kLiveListAtmosphere];
  201. self.openTime = [aDecoder decodeDoubleForKey:kLiveListOpenTime];
  202. self.weScore = [aDecoder decodeDoubleForKey:kLiveListWeScore];
  203. self.oppScore = [aDecoder decodeDoubleForKey:kLiveListOppScore];
  204. self.pkStartTime = [aDecoder decodeDoubleForKey:kLiveListPkStartTime];
  205. self.settleTime = [aDecoder decodeDoubleForKey:kLiveListSettleTime];
  206. self.pkEndTime = [aDecoder decodeDoubleForKey:kLiveListPkEndTime];
  207. self.pkStatus = [aDecoder decodeDoubleForKey:kLiveListPkStatus];
  208. self.roomId = [aDecoder decodeObjectForKey:kLiveListRoomId];
  209. self.pkRtcToken = [aDecoder decodeObjectForKey:kLiveListPkRtcToken];
  210. self.fansClubId = [aDecoder decodeObjectForKey:kLiveListFansClubId];
  211. self.weTops = [aDecoder decodeObjectForKey:kLiveListWeTops];
  212. self.oppoTops = [aDecoder decodeObjectForKey:kLiveListOppoTops];
  213. self.liveBadge = [aDecoder decodeObjectForKey:kLiveListLiveBadge];
  214. self.multiple = [aDecoder decodeBoolForKey:kLiveListMultiple];
  215. self.pk = [aDecoder decodeBoolForKey:kLiveListPk];
  216. self.redEnvelope = [aDecoder decodeBoolForKey:kLiveListRedEnvelope];
  217. self.bgBorder = [aDecoder decodeObjectForKey:kLiveListBgBorder];
  218. return self;
  219. }
  220. - (void)encodeWithCoder:(NSCoder *)aCoder
  221. {
  222. [aCoder encodeObject:_liveTag forKey:kLiveListLiveTag];
  223. [aCoder encodeDouble:_liveType forKey:kLiveListLiveType];
  224. [aCoder encodeObject:_id forKey:kLiveListId];
  225. [aCoder encodeObject:_activeTag forKey:kLiveListActiveTag];
  226. [aCoder encodeDouble:_roomType forKey:kLiveListRoomType];
  227. [aCoder encodeObject:_logo forKey:kLiveListLogo];
  228. [aCoder encodeObject:_name forKey:kLiveListName];
  229. [aCoder encodeObject:_anchorUser forKey:kLiveListAnchorUser];
  230. [aCoder encodeDouble:_visitNum forKey:kLiveListVisitNum];
  231. [aCoder encodeDouble:_atmosphere forKey:kLiveListAtmosphere];
  232. [aCoder encodeDouble:_openTime forKey:kLiveListOpenTime];
  233. [aCoder encodeDouble:_weScore forKey:kLiveListWeScore];
  234. [aCoder encodeDouble:_oppScore forKey:kLiveListOppScore];
  235. [aCoder encodeDouble:_pkStartTime forKey:kLiveListPkStartTime];
  236. [aCoder encodeDouble:_settleTime forKey:kLiveListSettleTime];
  237. [aCoder encodeDouble:_pkEndTime forKey:kLiveListPkEndTime];
  238. [aCoder encodeDouble:_pkStatus forKey:kLiveListPkStatus];
  239. [aCoder encodeObject:_roomId forKey:kLiveListRoomId];
  240. [aCoder encodeObject:_pkRtcToken forKey:kLiveListPkRtcToken];
  241. [aCoder encodeObject:_fansClubId forKey:kLiveListFansClubId];
  242. [aCoder encodeObject:_weTops forKey:kLiveListWeTops];
  243. [aCoder encodeObject:_oppoTops forKey:kLiveListOppoTops];
  244. [aCoder encodeObject:_liveBadge forKey:kLiveListLiveBadge];
  245. [aCoder encodeBool:_multiple forKey:kLiveListMultiple];
  246. [aCoder encodeBool:_pk forKey:kLiveListPk];
  247. [aCoder encodeBool:_redEnvelope forKey:kLiveListRedEnvelope];
  248. [aCoder encodeObject:_bgBorder forKey:kLiveListBgBorder];
  249. }
  250. - (id)copyWithZone:(NSZone *)zone {
  251. MOLiveList *copy = [[MOLiveList alloc] init];
  252. if (copy) {
  253. copy.liveTag = [self.liveTag copyWithZone:zone];
  254. copy.liveType = self.liveType;
  255. copy.id = [self.id copyWithZone:zone];
  256. copy.activeTag = [self.activeTag copyWithZone:zone];
  257. copy.roomType = self.roomType;
  258. copy.logo = [self.logo copyWithZone:zone];
  259. copy.name = [self.name copyWithZone:zone];
  260. copy.anchorUser = [self.anchorUser copyWithZone:zone];
  261. copy.visitNum = self.visitNum;
  262. copy.atmosphere = self.atmosphere;
  263. copy.openTime = self.openTime;
  264. copy.weScore = self.weScore;
  265. copy.oppScore = self.oppScore;
  266. copy.pkStartTime = self.pkStartTime;
  267. copy.settleTime = self.settleTime;
  268. copy.pkEndTime = self.pkEndTime;
  269. copy.pkStatus = self.pkStatus;
  270. copy.roomId = [self.roomId copyWithZone:zone];
  271. copy.pkRtcToken = [self.pkRtcToken copyWithZone:zone];
  272. copy.fansClubId = [self.fansClubId copyWithZone:zone];
  273. copy.weTops = [self.weTops copyWithZone:zone];
  274. copy.oppoTops = [self.oppoTops copyWithZone:zone];
  275. copy.liveBadge = [self.liveBadge copyWithZone:zone];
  276. copy.isViewSelect = self.isViewSelect;
  277. copy.multiple = self.multiple;
  278. copy.pk = self.pk;
  279. copy.redEnvelope = self.redEnvelope;
  280. copy.bgBorder = [self.bgBorder copyWithZone:zone];
  281. }
  282. return copy;
  283. }
  284. @end