JCHATSendMsgManager.m 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. //
  2. // JCHATSendMsgManager.m
  3. // JChat
  4. //
  5. // Created by HuminiOS on 15/10/30.
  6. // Copyright © 2015年 HXHG. All rights reserved.
  7. //
  8. #import "JCHATSendMsgManager.h"
  9. #import "JCHATSendMsgController.h"
  10. #import "JCHATStringUtils.h"
  11. @implementation JCHATSendMsgManager
  12. + (JCHATSendMsgManager *)ins {
  13. static JCHATSendMsgManager *sendMsgManage = nil;
  14. static dispatch_once_t onceToken;
  15. dispatch_once(&onceToken, ^{
  16. sendMsgManage = [[JCHATSendMsgManager alloc] init];
  17. });
  18. return sendMsgManage;
  19. }
  20. - (id)init {
  21. self = [super init];
  22. if (self) {
  23. _sendMsgListDic = @{}.mutableCopy;
  24. _textDraftDic = @{}.mutableCopy;
  25. }
  26. return self;
  27. }
  28. - (void)addMessage:(JMSGMessage *)imgMsg withConversation:(JMSGConversation *)conversation {
  29. NSString *key = nil;
  30. if (conversation.conversationType == kJMSGConversationTypeSingle) {
  31. key = ((JMSGUser *)conversation.target).username;
  32. } else {
  33. key = ((JMSGGroup *)conversation.target).gid;
  34. }
  35. if (_sendMsgListDic[key] == nil) {
  36. JCHATSendMsgController *sendMsgCtl = [[JCHATSendMsgController alloc] init];
  37. sendMsgCtl.msgConversation = conversation;
  38. [sendMsgCtl addDelegateForConversation:conversation];
  39. [sendMsgCtl prepareImageMessage:imgMsg];
  40. _sendMsgListDic[key] = sendMsgCtl;
  41. } else {
  42. JCHATSendMsgController *sendMsgCtl = _sendMsgListDic[key];
  43. [sendMsgCtl prepareImageMessage:imgMsg];
  44. }
  45. }
  46. - (void)updateConversation:(JMSGConversation *)conversation withDraft:(NSString *)draftString {
  47. NSString *key = nil;
  48. key = [JCHATStringUtils conversationIdWithConversation:conversation];
  49. _textDraftDic[key] = draftString;
  50. }
  51. - (NSString *)draftStringWithConversation:(JMSGConversation *)conversation {
  52. NSString *key = nil;
  53. key = [JCHATStringUtils conversationIdWithConversation:conversation];
  54. return _textDraftDic[key] ? _textDraftDic[key] : @"";
  55. }
  56. @end