From b13d07d03d57f392c9d541713ab11971d82be8c1 Mon Sep 17 00:00:00 2001 From: Brett <> Date: Wed, 7 Aug 2024 16:06:15 +0800 Subject: [PATCH] feat: Add input status related API. (#42) --- OpenIMSDK/Callbacker/OIMCallbacker+Closure.h | 9 ++++++++ OpenIMSDK/Callbacker/OIMCallbacker+Closure.m | 18 ++++++++++++++- OpenIMSDK/Callbacker/OIMCallbacker.h | 8 +++++++ OpenIMSDK/Interface/OIMManager+Conversation.h | 22 +++++++++++++++++++ OpenIMSDK/Interface/OIMManager+Conversation.m | 22 +++++++++++++++++++ OpenIMSDK/Model/OIMConversationInfo.h | 12 ++++++++++ OpenIMSDK/Model/OIMConversationInfo.m | 4 ++++ 7 files changed, 94 insertions(+), 1 deletion(-) diff --git a/OpenIMSDK/Callbacker/OIMCallbacker+Closure.h b/OpenIMSDK/Callbacker/OIMCallbacker+Closure.h index e0166af..23278fb 100644 --- a/OpenIMSDK/Callbacker/OIMCallbacker+Closure.h +++ b/OpenIMSDK/Callbacker/OIMCallbacker+Closure.h @@ -26,6 +26,15 @@ NS_ASSUME_NONNULL_BEGIN onNewConversation:(OIMConversationsInfoCallback)onNewConversation onTotalUnreadMessageCountChanged:(OIMNumberCallback)onTotalUnreadMessageCountChanged; +- (void)setConversationListenerWithOnSyncServerStart:(OIMBoolCallback)onSyncServerStart + onSyncServerFinish:(OIMBoolCallback)onSyncServerFinish + onSyncServerFailed:(OIMBoolCallback)onSyncServerFailed + onSyncServerProgress:(OIMNumberCallback)onSyncServerProgress + onConversationChanged:(OIMConversationsInfoCallback)onConversationChanged + onNewConversation:(OIMConversationsInfoCallback)onNewConversation + onTotalUnreadMessageCountChanged:(OIMNumberCallback)onTotalUnreadMessageCountChanged + onConversationUserInputStatusChanged:(nullable OIMInputStatusChangedCallback)onConversationUserInputStatusChanged; + /** * Set friend relationship listeners * diff --git a/OpenIMSDK/Callbacker/OIMCallbacker+Closure.m b/OpenIMSDK/Callbacker/OIMCallbacker+Closure.m index e77d32f..39316bc 100644 --- a/OpenIMSDK/Callbacker/OIMCallbacker+Closure.m +++ b/OpenIMSDK/Callbacker/OIMCallbacker+Closure.m @@ -13,7 +13,22 @@ - (void)setConversationListenerWithOnSyncServerStart:(OIMBoolCallback)onSyncServ onSyncServerFinish:(OIMBoolCallback)onSyncServerFinish onSyncServerFailed:(OIMBoolCallback)onSyncServerFailed onSyncServerProgress:(OIMNumberCallback)onSyncServerProgress - onConversationChanged:(OIMConversationsInfoCallback)onConversationChanged onNewConversation:(OIMConversationsInfoCallback)onNewConversation onTotalUnreadMessageCountChanged:(OIMNumberCallback)onTotalUnreadMessageCountChanged{ + onConversationChanged:(OIMConversationsInfoCallback)onConversationChanged onNewConversation:(OIMConversationsInfoCallback)onNewConversation onTotalUnreadMessageCountChanged:(OIMNumberCallback)onTotalUnreadMessageCountChanged { + [self setConversationListenerWithOnSyncServerStart:onSyncServerStart + onSyncServerFinish:onSyncServerFinish + onSyncServerFailed:onSyncServerFailed + onSyncServerProgress: onSyncServerProgress + onConversationChanged:onConversationChanged + onNewConversation:onNewConversation + onTotalUnreadMessageCountChanged:onTotalUnreadMessageCountChanged + onConversationUserInputStatusChanged:nil]; +} + +- (void)setConversationListenerWithOnSyncServerStart:(OIMBoolCallback)onSyncServerStart + onSyncServerFinish:(OIMBoolCallback)onSyncServerFinish + onSyncServerFailed:(OIMBoolCallback)onSyncServerFailed + onSyncServerProgress:(OIMNumberCallback)onSyncServerProgress + onConversationChanged:(OIMConversationsInfoCallback)onConversationChanged onNewConversation:(OIMConversationsInfoCallback)onNewConversation onTotalUnreadMessageCountChanged:(OIMNumberCallback)onTotalUnreadMessageCountChanged onConversationUserInputStatusChanged:(OIMInputStatusChangedCallback)onConversationUserInputStatusChanged { self.syncServerStart = onSyncServerStart; self.syncServerFinish = onSyncServerFinish; self.syncServerFailed = onSyncServerFailed; @@ -21,6 +36,7 @@ - (void)setConversationListenerWithOnSyncServerStart:(OIMBoolCallback)onSyncServ self.onConversationChanged = onConversationChanged; self.onNewConversation = onNewConversation; self.onTotalUnreadMessageCountChanged = onTotalUnreadMessageCountChanged; + self.onConversationUserInputStatusChanged = onConversationUserInputStatusChanged; } - (void)setFriendListenerWithOnBlackAdded:(OIMBlackInfoCallback)onBlackAdded diff --git a/OpenIMSDK/Callbacker/OIMCallbacker.h b/OpenIMSDK/Callbacker/OIMCallbacker.h index 7b1e46d..aee47ef 100644 --- a/OpenIMSDK/Callbacker/OIMCallbacker.h +++ b/OpenIMSDK/Callbacker/OIMCallbacker.h @@ -68,6 +68,8 @@ typedef void (^OIMRevokedCallback)(OIMMessageRevokedInfo * _Nullable msgRovoked) typedef void (^OIMGetAdvancedHistoryMessageListCallback)(OIMGetAdvancedHistoryMessageListInfo * _Nullable result); +typedef void (^OIMInputStatusChangedCallback)(NSArray *inputStatesChangedData); + /// IMSDK Core Callbacks @protocol OIMSDKListener @optional @@ -263,6 +265,11 @@ typedef void (^OIMGetAdvancedHistoryMessageListCallback)(OIMGetAdvancedHistoryMe */ - (void)onTotalUnreadMessageCountChanged:(NSInteger)totalUnreadCount; +/** + * User input status updates. + */ +- (void)onConversationUserInputStatusChanged:(OIMInputStatusChangedData *)inputStatusChangedData; + @end /// Advanced Message Listener @@ -405,6 +412,7 @@ Open_im_sdk_callbackOnCustomBusinessListener @property (nonatomic, nullable, copy) OIMConversationsInfoCallback onNewConversation; @property (nonatomic, nullable, copy) OIMConversationsInfoCallback onConversationChanged; @property (nonatomic, nullable, copy) OIMNumberCallback onTotalUnreadMessageCountChanged; +@property (nonatomic, nullable, copy) OIMInputStatusChangedCallback onConversationUserInputStatusChanged; /** * Add conversation listener. diff --git a/OpenIMSDK/Interface/OIMManager+Conversation.h b/OpenIMSDK/Interface/OIMManager+Conversation.h index 5500fa0..9074a7c 100644 --- a/OpenIMSDK/Interface/OIMManager+Conversation.h +++ b/OpenIMSDK/Interface/OIMManager+Conversation.h @@ -164,6 +164,28 @@ NS_ASSUME_NONNULL_BEGIN - (void)searchConversation:(NSString *)name onSuccess:(nullable OIMConversationsInfoCallback)onSuccess onFailure:(nullable OIMFailureCallback)onFailure; + +/** + * Typing status for one-on-one chat + * + * @param conversationID Receiver's ID + * @param focus Customized tip message + */ +- (void)changeInputStates:(NSString *)conversationID + focus:(BOOL)focus + onSuccess:(nullable OIMSuccessCallback)onSuccess + onFailure:(nullable OIMFailureCallback)onFailure; + +/** + * Typing status for one-on-one chat + * + * @param conversationID Conversation's ID + * @param userID User's ID + */ +- (void)getInputstates:(NSString *)conversationID + userID:(NSString *)userID + onSuccess:(nullable OIMInputStatusChangedCallback)onSuccess + onFailure:(nullable OIMFailureCallback)onFailure; @end NS_ASSUME_NONNULL_END diff --git a/OpenIMSDK/Interface/OIMManager+Conversation.m b/OpenIMSDK/Interface/OIMManager+Conversation.m index 223cab3..22dccef 100644 --- a/OpenIMSDK/Interface/OIMManager+Conversation.m +++ b/OpenIMSDK/Interface/OIMManager+Conversation.m @@ -204,4 +204,26 @@ - (void)searchConversation:(NSString *)name Open_im_sdkSearchConversation(callback, [self operationId], name); } + +- (void)changeInputStates:(NSString *)conversationID + focus:(BOOL)focus + onSuccess:(OIMSuccessCallback)onSuccess + onFailure:(OIMFailureCallback)onFailure { + CallbackProxy *callback = [[CallbackProxy alloc]initWithOnSuccess:onSuccess onFailure:onFailure]; + + Open_im_sdkChangeInputStates(callback, [self operationId], conversationID, focus); +} + +- (void)getInputstates:(NSString *)conversationID + userID:(NSString *)userID + onSuccess:(OIMInputStatusChangedCallback)onSuccess + onFailure:(OIMFailureCallback)onFailure { + CallbackProxy *callback = [[CallbackProxy alloc]initWithOnSuccess:^(NSString * _Nullable data) { + if (onSuccess) { + onSuccess(data.mj_JSONObject); + } + } onFailure:onFailure]; + + Open_im_sdkGetInputStates(callback, [self operationId], conversationID, userID); +} @end diff --git a/OpenIMSDK/Model/OIMConversationInfo.h b/OpenIMSDK/Model/OIMConversationInfo.h index 29aded2..64d3c1e 100644 --- a/OpenIMSDK/Model/OIMConversationInfo.h +++ b/OpenIMSDK/Model/OIMConversationInfo.h @@ -80,4 +80,16 @@ NS_ASSUME_NONNULL_BEGIN @end +/// input status Information +/// +@interface OIMInputStatusChangedData : NSObject + +@property (nonatomic, copy) NSString *conversationID; + +@property (nonatomic, copy) NSString *userID; +// OIMPlatform +@property (nonatomic, copy) NSArray *platformIDs; + +@end + NS_ASSUME_NONNULL_END diff --git a/OpenIMSDK/Model/OIMConversationInfo.m b/OpenIMSDK/Model/OIMConversationInfo.m index b5e9493..5d3b1de 100644 --- a/OpenIMSDK/Model/OIMConversationInfo.m +++ b/OpenIMSDK/Model/OIMConversationInfo.m @@ -18,3 +18,7 @@ @implementation OIMConversationInfo @implementation OIMConversationNotDisturbInfo @end + +@implementation OIMInputStatusChangedData + +@end