KSLiveChatroomEnter.m 1.5 KB

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