WFCCConversation.m 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. //
  2. // WFCCConversation.m
  3. // WFChatClient
  4. //
  5. // Created by heavyrain on 2017/8/16.
  6. // Copyright © 2017年 WildFireChat. All rights reserved.
  7. //
  8. #import "WFCCConversation.h"
  9. @implementation WFCCConversation
  10. +(instancetype)conversationWithType:(WFCCConversationType)type target:(NSString *)target line:(int)line {
  11. WFCCConversation *conversation = [[WFCCConversation alloc] init];
  12. conversation.type = type;
  13. conversation.target = target;
  14. conversation.line = line;
  15. return conversation;
  16. }
  17. +(instancetype)singleConversation:(NSString *)target {
  18. WFCCConversation *conversation = [[WFCCConversation alloc] init];
  19. conversation.type = Single_Type;
  20. conversation.target = target;
  21. conversation.line = 0;
  22. return conversation;
  23. }
  24. +(instancetype)groupConversation:(NSString *)target {
  25. WFCCConversation *conversation = [[WFCCConversation alloc] init];
  26. conversation.type = Group_Type;
  27. conversation.target = target;
  28. conversation.line = 0;
  29. return conversation;
  30. }
  31. - (instancetype)duplicate {
  32. WFCCConversation *conversation = [[WFCCConversation alloc] init];
  33. conversation.type = self.type;
  34. conversation.target = self.target;
  35. conversation.line = self.line;
  36. return conversation;
  37. }
  38. - (BOOL)isEqual:(id)object {
  39. if ([object isMemberOfClass:[WFCCConversation class]]) {
  40. WFCCConversation *o = (WFCCConversation *)object;
  41. if (self.type == o.type && [self.target isEqual:o.target] && self.line == o.line) {
  42. return YES;
  43. }
  44. }
  45. return NO;
  46. }
  47. - (NSUInteger)hash {
  48. return self.target.hash;
  49. }
  50. -(id)toJsonObj {
  51. NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
  52. dict[@"type"] = @(self.type);
  53. dict[@"target"] = self.target;
  54. dict[@"line"] = @(self.line);
  55. return dict;
  56. }
  57. #pragma mark - NSCopying
  58. - (id)copyWithZone:(nullable NSZone *)zone {
  59. WFCCConversation *conversation = [[WFCCConversation alloc] init];
  60. conversation.type = self.type;
  61. conversation.target = self.target;
  62. conversation.line = self.line;
  63. return conversation;
  64. }
  65. @end