Commit 7d94f2721776af73002354133ddc7192d3c5eb0c
1 parent
f07a05ef
0.6.4 版本,添加会话变更监听
Showing
3 changed files
with
44 additions
and
2 deletions
CNLiveNewIMAManagerKit.podspec
CNLiveNewIMAManagerKit/Classes/Playform/IMAConversationManager.h
| ... | ... | @@ -39,6 +39,17 @@ typedef NS_OPTIONS(NSUInteger, IMAConversationChangedNotifyType) { |
| 39 | 39 | - (NSNotification *)changedNotification; |
| 40 | 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 | 53 | typedef void (^IMAConversationChangedCompletion)(IMAConversationChangedNotifyItem *item); |
| 43 | 54 | |
| 44 | 55 | @interface IMAConversationManager : NSObject<TIMMessageListener> |
| ... | ... | @@ -57,6 +68,8 @@ typedef void (^IMAConversationChangedCompletion)(IMAConversationChangedNotifyIte |
| 57 | 68 | |
| 58 | 69 | /// 会话列表发生改变给外部回调 |
| 59 | 70 | @property (nonatomic, copy) IMAConversationChangedCompletion conversationChangedCompletion; |
| 71 | +/// 会话列表变动监听者 | |
| 72 | +@property (nonatomic, strong, readonly) NSHashTable <IMAConversationChangedDeleagte>*conversationListeners; | |
| 60 | 73 | |
| 61 | 74 | /// 是否正在播放听见中国中的音频 |
| 62 | 75 | @property (nonatomic, assign) BOOL isPlay; |
| ... | ... | @@ -124,6 +137,12 @@ typedef void (^IMAConversationChangedCompletion)(IMAConversationChangedNotifyIte |
| 124 | 137 | |
| 125 | 138 | /// 清除正在聊天的会话 |
| 126 | 139 | - (void)clearChattingConversation; |
| 140 | + | |
| 141 | +/// 添加会话变动监听者 | |
| 142 | +- (void)addConversationListener:(id)listener; | |
| 143 | +/// 移除会话变动监听者 | |
| 144 | +- (void)removeConversationListener:(id)listener; | |
| 145 | + | |
| 127 | 146 | @end |
| 128 | 147 | |
| 129 | 148 | ... | ... |
CNLiveNewIMAManagerKit/Classes/Playform/IMAConversationManager.m
| ... | ... | @@ -59,6 +59,8 @@ |
| 59 | 59 | if (self = [super init]) |
| 60 | 60 | { |
| 61 | 61 | _conversationList = [[CLSafeSetArray alloc] init]; |
| 62 | + _conversationListeners = [NSHashTable hashTableWithOptions:NSPointerFunctionsWeakMemory]; | |
| 63 | + | |
| 62 | 64 | } |
| 63 | 65 | return self; |
| 64 | 66 | } |
| ... | ... | @@ -1722,6 +1724,18 @@ |
| 1722 | 1724 | } |
| 1723 | 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 | 1739 | @end |
| 1726 | 1740 | |
| 1727 | 1741 | |
| ... | ... | @@ -1829,7 +1843,11 @@ |
| 1829 | 1843 | { |
| 1830 | 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 | 1851 | [[NSNotificationQueue defaultQueue] enqueueNotification:[item changedNotification] postingStyle:NSPostWhenIdle]; |
| 1834 | 1852 | } |
| 1835 | 1853 | |
| ... | ... | @@ -1934,6 +1952,11 @@ |
| 1934 | 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 | 1960 | [[NSNotificationQueue defaultQueue] enqueueNotification:[item changedNotification] postingStyle:NSPostWhenIdle]; |
| 1938 | 1961 | |
| 1939 | 1962 | //zl_判断是否为好友, 如果是好友直接更新会话列表,否则重新获取用户信息,返回结果后更新会话列表 | ... | ... |