KSLiveChatroomLike.m 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. //
  2. // KSLiveChatroomLike.m
  3. // KulexiuForTeacher
  4. //
  5. // Created by Kyle on 2022/3/30.
  6. //
  7. #import "KSLiveChatroomLike.h"
  8. @implementation KSLiveChatroomLike
  9. - (NSData *)encode {
  10. NSMutableDictionary *dataDict = [NSMutableDictionary dictionary];
  11. if (self.counts) {
  12. [dataDict setObject:@(self.counts) forKey:@"counts"];
  13. }
  14. if (self.extra) {
  15. [dataDict setObject:self.extra forKey:@"extra"];
  16. } else {
  17. [dataDict setObject:@"" forKey:@"extra"];
  18. }
  19. if (self.senderUserInfo) {
  20. [dataDict setObject:[self encodeUserInfo:self.senderUserInfo] forKey:@"user"];
  21. }
  22. return [NSJSONSerialization dataWithJSONObject:dataDict options:kNilOptions error:nil];
  23. }
  24. - (void)decodeWithData:(NSData *)data {
  25. if (data == nil) {
  26. return;
  27. }
  28. NSDictionary *dictionary = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:nil];
  29. NSDictionary *json = [[NSDictionary alloc] initWithDictionary:dictionary];
  30. if (json) {
  31. self.counts = [[json ks_stringValueForKey:@"counts"] intValue];
  32. self.extra = [json ks_stringValueForKey:@"extra"];
  33. NSDictionary *userinfoDic = dictionary[@"user"];
  34. [self decodeUserInfo:userinfoDic];
  35. }
  36. }
  37. + (NSString *)getObjectName {
  38. return @"RC:Chatroom:Like";
  39. }
  40. - (NSArray<NSString *> *)getSearchableWords {
  41. return nil;
  42. }
  43. + (RCMessagePersistent)persistentFlag {
  44. return MessagePersistent_NONE;
  45. }
  46. @end