2
0

WFCUGroupAnnouncement.m 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. //
  2. // WFCUGroupAnnouncement.m
  3. // WFChatUIKit
  4. //
  5. // Created by Heavyrain Lee on 2019/10/22.
  6. // Copyright © 2019 WildFireChat. All rights reserved.
  7. //
  8. #import "WFCUGroupAnnouncement.h"
  9. @implementation WFCUGroupAnnouncement
  10. - (NSData *)data {
  11. NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
  12. [dict setValue:self.groupId forKey:@"gid"];
  13. [dict setValue:self.author forKey:@"a"];
  14. [dict setValue:self.text forKey:@"t"];
  15. [dict setValue:@(self.timestamp) forKey:@"ts"];
  16. return [NSJSONSerialization dataWithJSONObject:dict options:kNilOptions error:nil];
  17. }
  18. - (void)setData:(NSData *)data {
  19. if (data) {
  20. NSError *__error = nil;
  21. NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&__error];
  22. if (!__error) {
  23. self.groupId = [dict objectForKey:@"gid"];
  24. self.author = [dict objectForKey:@"a"];
  25. self.text = [dict objectForKey:@"t"];
  26. self.timestamp = [[dict objectForKey:@"ts"] longValue];
  27. }
  28. }
  29. }
  30. - (void)setText:(NSString *)text {
  31. if ([text isKindOfClass:[NSNull class]]) {
  32. _text = nil;
  33. } else {
  34. _text = text;
  35. }
  36. }
  37. - (void)setAuthor:(NSString *)author {
  38. if ([author isKindOfClass:[NSNull class]]) {
  39. _author = nil;
  40. } else {
  41. _author = author;
  42. }
  43. }
  44. @end