Commit 7d94f2721776af73002354133ddc7192d3c5eb0c

Authored by niudaojian
1 parent f07a05ef

0.6.4 版本,添加会话变更监听

CNLiveNewIMAManagerKit.podspec
@@ -8,7 +8,7 @@ @@ -8,7 +8,7 @@
8 8
9 Pod::Spec.new do |s| 9 Pod::Spec.new do |s|
10 s.name = 'CNLiveNewIMAManagerKit' 10 s.name = 'CNLiveNewIMAManagerKit'
11 - s.version = '0.6.3' 11 + s.version = '0.6.4'
12 s.summary = 'A short description of CNLiveNewIMAManagerKit.' 12 s.summary = 'A short description of CNLiveNewIMAManagerKit.'
13 13
14 #s.description = <<-DESC 14 #s.description = <<-DESC
CNLiveNewIMAManagerKit/Classes/Playform/IMAConversationManager.h
@@ -39,6 +39,17 @@ typedef NS_OPTIONS(NSUInteger, IMAConversationChangedNotifyType) { @@ -39,6 +39,17 @@ typedef NS_OPTIONS(NSUInteger, IMAConversationChangedNotifyType) {
39 - (NSNotification *)changedNotification; 39 - (NSNotification *)changedNotification;
40 @end 40 @end
41 41
  42 +/// 会话变更代理
  43 +@protocol IMAConversationChangedDeleagte <NSObject>
  44 +
  45 +
  46 +/// 会话列表已改变
  47 +/// @param item 改变的会话
  48 +- (void)imaConversationDidChanged:(IMAConversationChangedNotifyItem *)item;
  49 +
  50 +@end
  51 +
  52 +/// 会话变更block
42 typedef void (^IMAConversationChangedCompletion)(IMAConversationChangedNotifyItem *item); 53 typedef void (^IMAConversationChangedCompletion)(IMAConversationChangedNotifyItem *item);
43 54
44 @interface IMAConversationManager : NSObject<TIMMessageListener> 55 @interface IMAConversationManager : NSObject<TIMMessageListener>
@@ -57,6 +68,8 @@ typedef void (^IMAConversationChangedCompletion)(IMAConversationChangedNotifyIte @@ -57,6 +68,8 @@ typedef void (^IMAConversationChangedCompletion)(IMAConversationChangedNotifyIte
57 68
58 /// 会话列表发生改变给外部回调 69 /// 会话列表发生改变给外部回调
59 @property (nonatomic, copy) IMAConversationChangedCompletion conversationChangedCompletion; 70 @property (nonatomic, copy) IMAConversationChangedCompletion conversationChangedCompletion;
  71 +/// 会话列表变动监听者
  72 +@property (nonatomic, strong, readonly) NSHashTable <IMAConversationChangedDeleagte>*conversationListeners;
60 73
61 /// 是否正在播放听见中国中的音频 74 /// 是否正在播放听见中国中的音频
62 @property (nonatomic, assign) BOOL isPlay; 75 @property (nonatomic, assign) BOOL isPlay;
@@ -124,6 +137,12 @@ typedef void (^IMAConversationChangedCompletion)(IMAConversationChangedNotifyIte @@ -124,6 +137,12 @@ typedef void (^IMAConversationChangedCompletion)(IMAConversationChangedNotifyIte
124 137
125 /// 清除正在聊天的会话 138 /// 清除正在聊天的会话
126 - (void)clearChattingConversation; 139 - (void)clearChattingConversation;
  140 +
  141 +/// 添加会话变动监听者
  142 +- (void)addConversationListener:(id)listener;
  143 +/// 移除会话变动监听者
  144 +- (void)removeConversationListener:(id)listener;
  145 +
127 @end 146 @end
128 147
129 148
CNLiveNewIMAManagerKit/Classes/Playform/IMAConversationManager.m
@@ -59,6 +59,8 @@ @@ -59,6 +59,8 @@
59 if (self = [super init]) 59 if (self = [super init])
60 { 60 {
61 _conversationList = [[CLSafeSetArray alloc] init]; 61 _conversationList = [[CLSafeSetArray alloc] init];
  62 + _conversationListeners = [NSHashTable hashTableWithOptions:NSPointerFunctionsWeakMemory];
  63 +
62 } 64 }
63 return self; 65 return self;
64 } 66 }
@@ -1722,6 +1724,18 @@ @@ -1722,6 +1724,18 @@
1722 } 1724 }
1723 return nil; 1725 return nil;
1724 } 1726 }
  1727 +
  1728 +/// 添加会话变动监听者
  1729 +- (void)addConversationListener:(id)listener
  1730 +{
  1731 + [_conversationListeners addObject:listener];
  1732 +}
  1733 +/// 移除会话变动监听者
  1734 +- (void)removeConversationListener:(id)listener
  1735 +{
  1736 + [_conversationListeners removeObject:listener];
  1737 +}
  1738 +
1725 @end 1739 @end
1726 1740
1727 1741
@@ -1829,7 +1843,11 @@ @@ -1829,7 +1843,11 @@
1829 { 1843 {
1830 _conversationChangedCompletion(item); 1844 _conversationChangedCompletion(item);
1831 } 1845 }
1832 - 1846 + for (id<IMAConversationChangedDeleagte> delegate in _conversationListeners) {
  1847 + if ([delegate respondsToSelector:@selector(imaConversationDidChanged:)]) {
  1848 + [delegate imaConversationDidChanged:item];
  1849 + }
  1850 + }
1833 [[NSNotificationQueue defaultQueue] enqueueNotification:[item changedNotification] postingStyle:NSPostWhenIdle]; 1851 [[NSNotificationQueue defaultQueue] enqueueNotification:[item changedNotification] postingStyle:NSPostWhenIdle];
1834 } 1852 }
1835 1853
@@ -1934,6 +1952,11 @@ @@ -1934,6 +1952,11 @@
1934 _conversationChangedCompletion(item); 1952 _conversationChangedCompletion(item);
1935 } 1953 }
1936 1954
  1955 + for (id<IMAConversationChangedDeleagte> delegate in _conversationListeners) {
  1956 + if ([delegate respondsToSelector:@selector(imaConversationDidChanged:)]) {
  1957 + [delegate imaConversationDidChanged:item];
  1958 + }
  1959 + }
1937 [[NSNotificationQueue defaultQueue] enqueueNotification:[item changedNotification] postingStyle:NSPostWhenIdle]; 1960 [[NSNotificationQueue defaultQueue] enqueueNotification:[item changedNotification] postingStyle:NSPostWhenIdle];
1938 1961
1939 //zl_判断是否为好友, 如果是好友直接更新会话列表,否则重新获取用户信息,返回结果后更新会话列表 1962 //zl_判断是否为好友, 如果是好友直接更新会话列表,否则重新获取用户信息,返回结果后更新会话列表