KSLiveChatroomWelcome.m 2.0 KB

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