IMAConversationManager.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. //
  2. // IMAConversationManager.h
  3. // TIMAdapter
  4. //
  5. // Created by AlexiChen on 16/2/18.
  6. // Copyright © 2016年 AlexiChen. All rights reserved.
  7. //
  8. #import <ImSDK_Plus/ImSDK_Plus.h>
  9. typedef NS_OPTIONS(NSUInteger, IMAConversationChangedNotifyType) {
  10. EIMAConversation_SyncLocalConversation = 0x01, // 同步本地会话结束
  11. EIMAConversation_BecomeActiveTop = 0x01 << 1, // 当前会话放在会话列表顶部
  12. EIMAConversation_NewConversation = 0x01 << 2, // 新增会话
  13. EIMAConversation_DeleteConversation = 0x01 << 3, // 删除会话
  14. EIMAConversation_Connected = 0x01 << 4, // 网络连上
  15. EIMAConversation_DisConnected = 0x01 << 5, // 网络连上
  16. EIMAConversation_ConversationChanged = 0x01 << 6, // 会话有更新
  17. EIMAConversation_AllEvents = EIMAConversation_SyncLocalConversation | EIMAConversation_BecomeActiveTop | EIMAConversation_NewConversation | EIMAConversation_DeleteConversation | EIMAConversation_Connected | EIMAConversation_DisConnected | EIMAConversation_ConversationChanged,
  18. };
  19. @interface IMAConversationChangedNotifyItem : NSObject
  20. @property (nonatomic, assign) IMAConversationChangedNotifyType type;
  21. @property (nonatomic, strong) IMAConversation *conversation;
  22. @property (nonatomic, assign) NSInteger index;
  23. @property (nonatomic, assign) NSInteger toIndex;
  24. - (instancetype)initWith:(IMAConversationChangedNotifyType)type;
  25. - (NSString *)notificationName;
  26. - (NSNotification *)changedNotification;
  27. @end
  28. typedef void (^IMAConversationChangedCompletion)(IMAConversationChangedNotifyItem *item);
  29. @interface IMAConversationManager : NSObject<TIMMessageListener, TIMMessageRevokeListener>
  30. {
  31. @protected
  32. CLSafeMutableArray *_conversationList;
  33. NSInteger _refreshStyle;
  34. V2TIMConversation *_chattingConversation; // 正在聊
  35. }
  36. @property (nonatomic, readonly) CLSafeMutableArray *conversationList;
  37. @property (nonatomic, assign) NSInteger unReadMessageCount;
  38. @property (nonatomic, copy) IMAConversationChangedCompletion conversationChangedCompletion;
  39. //- (void)addConversationChangedObserver:(id)observer handler:(SEL)selector forEvent:(NSUInteger)eventID;
  40. //
  41. //- (void)removeConversationChangedObser:(id)observer;
  42. // 释放当前正在聊天的conversation
  43. - (void)releaseChattingConversation;
  44. // 删除会话
  45. - (void)deleteConversation:(IMAConversation *)conv needUIRefresh:(BOOL)need;
  46. // 更新会话列表
  47. - (void)asyncConversationList;
  48. // 开始与user聊天,会产生新的conversationa或更新原conversation的位置
  49. - (IMAConversation *)chatWith:(IMAUser *)user;
  50. // 查询列表conversationList中与user的conversation;
  51. // 如果存在,则返回在conversationList的对象,否则返回nil
  52. // 与chatWith区别其不会产生新的会话
  53. - (IMAConversation *)queryConversationWith:(IMAUser *)user;
  54. // 删除与某人的会话
  55. - (void)removeConversationWith:(IMAUser *)user;
  56. // 移除sdk生成的会话(不一定在_converdationlist中)
  57. //- (void)removeConversationWithConv:(IMAConversation *)conv;
  58. // 更新与user的会话
  59. - (void)updateConversationWith:(IMAUser *)user;
  60. @end
  61. @interface IMAConversationManager (Protected)
  62. // TIMAdapter内部调用,外部不要调用
  63. // 当连接上
  64. - (void)onConnect;
  65. // 网络断开
  66. - (void)onDisConnect;
  67. // 同步完列表数据后,更新会话列表里面的显示
  68. - (void)updateOnAsyncLoadContactComplete;
  69. // 加载本地会话消息完成,通知外部更新
  70. - (void)updateOnLocalMsgComplete;
  71. // 会话,如果发消息,才更新其在列表中的位置
  72. - (void)updateOnLastMessageChanged:(IMAConversation *)conv;
  73. // conv并非新建,而是已在列表中,有收到新消息 或 chatwith后,将conv移到从列表index处移到0;
  74. // 外部先删除index,然后再插入0
  75. - (void)updateOnChat:(IMAConversation *)conv moveFromIndex:(NSUInteger)index;
  76. - (void)updateOnDelete:(IMAConversation *)conv atIndex:(NSUInteger)index;
  77. - (void)updateOnNewConversation:(IMAConversation *)conv;
  78. - (void)updateOnConversationChanged:(IMAConversation *)conv;
  79. @end