AgoraChatSDK 1.3.1
Instance Methods | Properties | List of all members
AgoraChatConversation Class Reference

#import <AgoraChatConversation.h>

Inheritance diagram for AgoraChatConversation:

Instance Methods

(AgoraChatMessage *_Nullable) - lastReceivedMessage
 
(void) - insertMessage:error:
 
(void) - appendMessage:error:
 
(void) - deleteMessageWithId:error:
 
(void) - deleteAllMessages:
 
(void) - removeMessagesFromServerMessageIds:completion:
 
(void) - removeMessagesFromServerWithTimeStamp:completion:
 
(void) - updateMessageChange:error:
 
(void) - markMessageAsReadWithId:error:
 
(void) - markAllMessagesAsRead:
 
(NSArray< AgoraChatMessage * > *_Nullable) - pinnedMessages
 
(AgoraChatMessage *_Nullable) - loadMessageWithId:error:
 
(NSArray< AgoraChatMessage * > *_Nullable) - loadMessagesStartFromId:count:searchDirection:
 
(void) - loadMessagesStartFromId:count:searchDirection:completion:
 
(NSArray< AgoraChatMessage * > *_Nullable) - loadMessagesWithType:timestamp:count:fromUser:searchDirection:
 
(void) - loadMessagesWithType:timestamp:count:fromUser:searchDirection:completion:
 
(void) - searchMessagesWithTypes:timestamp:count:fromUser:searchDirection:completion:
 
(NSArray< AgoraChatMessage * > *_Nullable) - loadMessagesWithKeyword:timestamp:count:fromUser:searchDirection:
 
(void) - loadMessagesWithKeyword:timestamp:count:fromUser:searchDirection:completion:
 
(void) - loadMessagesWithKeyword:timestamp:count:fromUser:searchDirection:scope:completion:
 
(NSArray< AgoraChatMessage * > *_Nullable) - loadCustomMsgWithKeyword:timestamp:count:fromUser:searchDirection:
 
(void) - loadCustomMsgWithKeyword:timestamp:count:fromUser:searchDirection:completion:
 
(NSArray< AgoraChatMessage * > *_Nullable) - loadMessagesFrom:to:count:
 
(void) - loadMessagesFrom:to:count:completion:
 
(AgoraChatError *_Nullable) - removeMessagesStart:to:
 
(NSInteger) - getMessageCountStart:to:
 

Properties

NSString * conversationId
 
AgoraChatConversationType type
 
int unreadMessagesCount
 
int messagesCount
 
NSDictionary * ext
 
BOOL isChatThread
 
BOOL isPinned
 
int64_t pinnedTime
 
AgoraChatMessagelatestMessage
 
NSArray< NSNumber * > * marks
 
AgoraChatPushRemindType disturbType
 

Detailed Description

The chat conversation class.

Method Documentation

◆ appendMessage:error:

- (void) appendMessage: (AgoraChatMessage *_Nonnull)  aMessage
error: (AgoraChatError **_Nullable)  pError 

Inserts a message to the end of a conversation in local database.

To insert the message correctly, ensure that the conversation ID of the message is the same as that of the conversation.

After a message is inserted, the SDK will automatically update attributes of the conversation, including latestMessage.

Parameters
aMessageThe message instance.
pErrorThe error information if the method fails: Error.

◆ deleteAllMessages:

- (void) deleteAllMessages: (AgoraChatError **_Nullable)  pError

Deletes all the messages in the conversation from the memory and local database.

Parameters
pErrorThe error information if the method fails: Error.

◆ deleteMessageWithId:error:

- (void) deleteMessageWithId: (NSString *_Nonnull)  aMessageId
error: (AgoraChatError **_Nullable)  pError 

Deletes a message from the local database.

Parameters
aMessageIdThe ID of the message to be deleted.
pErrorThe error information if the method fails: Error.

◆ getMessageCountStart:to:

- (NSInteger) getMessageCountStart: (NSInteger)  aStartTimestamp
to: (NSInteger)  aEndTimestamp 

Gets the number of messages in a conversation within a certain period of time.

Parameters
aStartTimestampThe starting timestamp for query. The unit is millisecond.
aEndTimestampThe ending timestamp for query. The unit is millisecond.
Returns
The number of messages in a conversation within a certain period of time.

◆ insertMessage:error:

- (void) insertMessage: (AgoraChatMessage *_Nonnull)  aMessage
error: (AgoraChatError **_Nullable)  pError 

Inserts a message to a conversation in the local database.

To insert the message correctly, ensure that the conversation ID of the message is the same as that of the conversation.

The message is inserted based on timestamp and the SDK will automatically update attributes of the conversation, including latestMessage.

Parameters
aMessageThe message instance.
pErrorThe error information if the method fails: Error.

◆ lastReceivedMessage

- (AgoraChatMessage *_Nullable) lastReceivedMessage

Gets the last received message.

Returns
The message instance.

◆ loadCustomMsgWithKeyword:timestamp:count:fromUser:searchDirection:

- (NSArray< AgoraChatMessage * > *_Nullable) loadCustomMsgWithKeyword: (NSString *)  aKeyword
timestamp: (long long)  aTimestamp
count: (int)  aCount
fromUser: (NSString *_Nullable)  aSender
searchDirection: (AgoraChatMessageSearchDirection)  aDirection 

Loads custom messages with keywords that the specified user sends in the conversation.

This is a synchronous method and blocks the current thread.

Parameters
aKeywordThe keywords for query. Setting it as NIL means that the SDK ignores this parameter.
aTimestampThe starting Unix timestamp in the message for query. The unit is millisecond. After this parameter is set, the SDK retrieves messages, starting from the specified one, according to the message search direction. If this parameter is set as a negative value, the SDK retrieves from the current time.
aCountThe number of messages to load each time. If you set this parameter to a value less than 1, the SDK retrieves one message.
aSenderThe message sender. Setting it as NIL means that the SDK ignores this parameter.
aDirectionThe message search direction. See AgoraChatMessageSearchDirection.
Returns
AgoraChatMessage The message list.

◆ loadCustomMsgWithKeyword:timestamp:count:fromUser:searchDirection:completion:

- (void) loadCustomMsgWithKeyword: (NSString *_Nullable)  aKeyword
timestamp: (long long)  aTimestamp
count: (int)  aCount
fromUser: (NSString *_Nullable)  aSender
searchDirection: (AgoraChatMessageSearchDirection)  aDirection
completion: (void(^)(NSArray< AgoraChatMessage * > *_Nullable aMessages, AgoraChatError *_Nullable aError))  aCompletionBlock 

Loads custom messages with keywords that the specified user sends in the conversation.

Parameters
aKeywordThe keyword for searching the messages. Setting it as NIL means that the SDK ignores this parameter.
aTimestampThe starting Unix timestamp in the message for query. The unit is millisecond. After this parameter is set, the SDK retrieves messages, starting from the specified one, according to the message search direction. If this parameter is set as a negative value, the SDK retrieves from the current time.
aCountThe number of messages to load each time. If you set this parameter to a value less than 1, the SDK retrieves one message.
aSenderThe message sender. Setting it as NIL means that the SDK ignores this parameter.
aDirectionThe message search direction. See AgoraChatMessageSearchDirection.
aCompletionBlockThe completion block, which contains the error message if the method fails.

◆ loadMessagesFrom:to:count:

- (NSArray< AgoraChatMessage * > *_Nullable) loadMessagesFrom: (long long)  aStartTimestamp
to: (long long)  aEndTimestamp
count: (int)  aCount 

Loads a certain quantity of messages sent or received in a certain period from the local database.

Messages are retrieved in the ascending order of the timestamp included in them.

This is a synchronous method and blocks the current thread.

Parameters
aStartTimestampThe starting Unix timestamp in the message for query. The unit is millisecond.
aEndTimestampThe ending Unix timestamp in the message for query. The unit is millisecond.
aCountThe number of messages to load each time. If you set this parameter to a value less than 1, the SDK retrieves one message.
Returns
AgoraChatMessage The message list.

◆ loadMessagesFrom:to:count:completion:

- (void) loadMessagesFrom: (long long)  aStartTimestamp
to: (long long)  aEndTimestamp
count: (int)  aCount
completion: (void(^)(NSArray< AgoraChatMessage * > *_Nullable aMessages, AgoraChatError *_Nullable aError))  aCompletionBlock 

Loads a certain quantity of messages sent or received in a certain period from the local database.

Parameters
aStartTimestampThe starting Unix timestamp in the message for query. The unit is millisecond.
aEndTimestampThe ending Unix timestamp in the message for query. The unit is millisecond.
aCountThe number of messages to load each time. If you set this parameter to a value less than 1, the SDK retrieves one message.
aCompletionBlockThe completion block, which contains the error message if the method fails.

◆ loadMessagesStartFromId:count:searchDirection:

- (NSArray< AgoraChatMessage * > *_Nullable) loadMessagesStartFromId: (NSString *_Nullable)  aMessageId
count: (int)  aCount
searchDirection: (AgoraChatMessageSearchDirection)  aDirection 

Loads the messages from the local database, starting from a specific message ID.

This is a synchronous method and blocks the current thread.

Parameters
aMessageIdThe starting message ID for query. After this parameter is set, the SDK retrieves messages, from the specified one, according to the message search direction. If this parameter is set as nil, the SDK retrieves messages according to the search direction while ignoring this parameter.
  • If aDirection is set as UP, the SDK retrieves messages, starting from the latest one, in the descending order of the timestamp included in them.
  • If aDirection is set as DOWN, the SDK retrieves messages, starting from the oldest one, in the ascending order of the timestamp included in them.
aCountThe number of messages to load each time. If you set this parameter to a value less than 1, the SDK retrieves one message.
aDirectionThe message search direction. See AgoraChatMessageSearchDirection.
Returns
AgoraChatMessage The message instance.

◆ loadMessagesStartFromId:count:searchDirection:completion:

- (void) loadMessagesStartFromId: (NSString *_Nullable)  aMessageId
count: (int)  aCount
searchDirection: (AgoraChatMessageSearchDirection)  aDirection
completion: (void(^)(NSArray< AgoraChatMessage * > *_Nullable aMessages, AgoraChatError *_Nullable aError))  aCompletionBlock 

Loads messages starting from the specified message ID from local database.

Returning messages are sorted by receiving timestamp based on AgoraChatMessageSearchDirection. If the aMessageId is nil, will return starting from the latest message.

Parameters
aMessageIdThe starting message ID for query. After this parameter is set, the SDK retrieves messages, from the specified one, according to the message search direction. If this parameter is set as nil, the SDK retrieves messages according to the search direction while ignoring this parameter.
  • If aDirection is set as UP, the SDK retrieves messages, starting from the latest one, in the descending order of the timestamp included in them.
  • If aDirection is set as DOWN, the SDK retrieves messages, starting from the oldest one, in the ascending order of the timestamp included in them.
aCountThe number of messages to load each time. If you set this parameter to a value less than 1, the SDK retrieves one message.
aDirectionThe message search direction. See AgoraChatMessageSearchDirection.
aCompletionBlockThe completion block, which contains the error message if the method fails.

◆ loadMessagesWithKeyword:timestamp:count:fromUser:searchDirection:

- (NSArray< AgoraChatMessage * > *_Nullable) loadMessagesWithKeyword: (NSString *_Nullable)  aKeyword
timestamp: (long long)  aTimestamp
count: (int)  aCount
fromUser: (NSString *_Nullable)  aSender
searchDirection: (AgoraChatMessageSearchDirection)  aDirection 

Loads messages with keywords that the specified user sends in the conversation.

This is a synchronous method and blocks the current thread.

Parameters
aKeywordThe keywords for query. Setting it as NIL means that the SDK ignores this parameter.
aTimestampThe starting Unix timestamp for search. The unit is millisecond. If this parameter is set as a negative value, the SDK retrieves from the current time.
aCountThe number of messages to load each time. If you set this parameter to a value less than 1, the SDK retrieves one message.
aSenderThe message sender. Setting it as nil means that the SDK ignores this parameter.
aDirectionThe message search direction. See AgoraChatMessageSearchDirection.
Returns
AgoraChatMessage The message list.

◆ loadMessagesWithKeyword:timestamp:count:fromUser:searchDirection:completion:

- (void) loadMessagesWithKeyword: (NSString *_Nullable)  aKeyword
timestamp: (long long)  aTimestamp
count: (int)  aCount
fromUser: (NSString *_Nullable)  aSender
searchDirection: (AgoraChatMessageSearchDirection)  aDirection
completion: (void(^)(NSArray< AgoraChatMessage * > *_Nullable aMessages, AgoraChatError *_Nullable aError))  aCompletionBlock 

Loads messages with specified keyword from local database. Returning messages are sorted by receiving timestamp based on AgoraChatMessageSearchDirection. If reference timestamp is negative, load from the latest messages; if message count is negative, will be handled as count=1

Parameters
aKeywordThe keywords for query. Setting it as NIL means that the SDK ignores this parameter.
aTimestampThe starting Unix timestamp for search. The unit is millisecond. If this parameter is set as a negative value, the SDK retrieves from the current time.
aCountThe number of messages to load each time. If you set this parameter to a value less than 1, the SDK retrieves one message.
aSenderThe message sender. Setting it as nil means that the SDK ignores this parameter.
aDirectionThe message search direction. See AgoraChatMessageSearchDirection.
aCompletionBlockThe completion block, which contains the error message if the method fails.

◆ loadMessagesWithKeyword:timestamp:count:fromUser:searchDirection:scope:completion:

- (void) loadMessagesWithKeyword: (NSString *_Nullable)  aKeyword
timestamp: (long long)  aTimestamp
count: (int)  aCount
fromUser: (NSString *_Nullable)  aSender
searchDirection: (AgoraChatMessageSearchDirection)  aDirection
scope: (AgoraChatMessageSearchScope)  aScope
completion: (void(^)(NSArray< AgoraChatMessage * > *_Nullable aMessages, AgoraChatError *_Nullable aError))  aCompletionBlock 

Loads messages with the specified keyword from a user in the local database.

The SDK returns messages in the chronological order.

Parameters
aKeywordThe keyword for message search. If you set this parameter as nil, the SDK ignores this parameter when retrieving messages.
aTimestampThe Unix timestamp threshold for message search. The unit is millisecond. If you set this parameter as a negative value, the SDK loads messages from the latest one. If this parameter is set as a negative value, the SDK retrieves from the current time.
aCountThe number of messages to load. If you set this parameter to 0 or less, the SDK gets one message from the local database.
aSenderThe sender of the message. If you set this parameter as nil, the SDK ignores this parameter when retrieving messages.
aDirectionThe message search direction. See AgoraChatMessageSearchDirection.
  • UP: The SDK retrieves messages in the descending order of the timestamp included in them.
  • DOWN:The SDK retrieves messages in the ascending order of the timestamp included in them.
aScopeThe message search scope. See AgoraChatMessageSearchScope.
aCompletionBlockThe completion block, which contains the error message if the method fails.

◆ loadMessagesWithType:timestamp:count:fromUser:searchDirection:

- (NSArray< AgoraChatMessage * > *_Nullable) loadMessagesWithType: (AgoraChatMessageBodyType)  aType
timestamp: (long long)  aTimestamp
count: (int)  aCount
fromUser: (NSString *_Nullable)  aUsername
searchDirection: (AgoraChatMessageSearchDirection)  aDirection 

Gets messages of certain types that a specified user sends in the conversation.

This is a synchronous method and blocks the current thread.

Parameters
aTypeThe message type to load. Types include txt (text message), img (image message), loc (location message), audio (audio message), video (video message), file (file message), and cmd (command message).
aTimestampThe starting Unix timestamp in the message for query. The unit is millisecond. If you set this parameter as a negative value, the SDK loads messages from the latest one.
aCountThe number of messages to load each time. If you set this parameter to a value less than 1, the SDK retrieves one message.
aUsernameThe message sender. Setting it as NIL means that the SDK ignores this parameter.
aDirectionThe message search direction. See AgoraChatMessageSearchDirection.
Returns
AgoraChatMessage The message instance.

◆ loadMessagesWithType:timestamp:count:fromUser:searchDirection:completion:

- (void) loadMessagesWithType: (AgoraChatMessageBodyType)  aType
timestamp: (long long)  aTimestamp
count: (int)  aCount
fromUser: (NSString *_Nullable)  aUsername
searchDirection: (AgoraChatMessageSearchDirection)  aDirection
completion: (void(^)(NSArray< AgoraChatMessage * > *_Nullable aMessages, AgoraChatError *_Nullable aError))  aCompletionBlock 

Gets messages of certain types that a specified user sends in the conversation.

Parameters
aTypeThe message type to load. Types include txt (text message), img (image message), loc (location message), audio (audio message), video (video message), file (file message), and cmd (command message).
aTimestampThe starting Unix timestamp in the message for query. The unit is millisecond. If you set this parameter as a negative value, the SDK loads messages from the latest one.
aCountThe number of messages to load each time. If you set this parameter to a value less than 1, the SDK retrieves one message.
aUsernameThe message sender. Setting it as nil means that the SDK ignores this parameter.
aDirectionThe message search direction. See AgoraChatMessageSearchDirection.
aCompletionBlockThe completion block, which contains the error message if the method fails.

◆ loadMessageWithId:error:

- (AgoraChatMessage *_Nullable) loadMessageWithId: (NSString *_Nonnull)  aMessageId
error: (AgoraChatError **_Nullable)  pError 

Gets a message with the specified message ID from the local database.

Parameters
aMessageIdThe message ID.
pErrorThe error information if the method fails: Error.

◆ markAllMessagesAsRead:

- (void) markAllMessagesAsRead: (AgoraChatError **_Nullable)  pError

Marks all messages in the local database as read.

Parameters
pErrorThe error information if the method fails: Error.

◆ markMessageAsReadWithId:error:

- (void) markMessageAsReadWithId: (NSString *_Nonnull)  aMessageId
error: (AgoraChatError **_Nullable)  pError 

Marks a message in the local database as read.

Parameters
aMessageIdThe message ID.
pErrorThe error information if the method fails: Error.

◆ pinnedMessages

- (NSArray< AgoraChatMessage * > *_Nullable) pinnedMessages

Get the pinned messages in the conversation

◆ removeMessagesFromServerMessageIds:completion:

- (void) removeMessagesFromServerMessageIds: (NSArray< __kindof NSString * > *_Nonnull)  messageIds
completion: (void(^)(AgoraChatError *_Nullable aError))  aCompletionBlock 

Removes messages from the conversation by timestamp.

This method deletes messages from both local storage and server.

Parameters
messageIdsThe list of IDs of messages to be removed form the current conversation.
completionThe completion block, which contains the error message if the method fails.

◆ removeMessagesFromServerWithTimeStamp:completion:

- (void) removeMessagesFromServerWithTimeStamp: (NSTimeInterval)  beforeTimeStamp
completion: (void(^)(AgoraChatError *_Nullable aError))  aCompletionBlock 

Removes messages from the conversation by message ID.

This method deletes messages from both local storage and server.

Parameters
messageIdsThe message timestamp in millisecond. Messages with the timestamp smaller than the specified one will be removed from the current conversation.
completionThe completion block, which contains the error message if the method fails.

◆ removeMessagesStart:to:

- (AgoraChatError *_Nullable) removeMessagesStart: (NSInteger)  aStartTimestamp
to: (NSInteger)  aEndTimestamp 

Deletes messages sent or received in a certain period from the local database.

Parameters
aStartTimestampThe starting UNIX timestamp for message deletion. The unit is millisecond.
aEndTimestampThe end UNIX timestamp for message deletion. The unit is millisecond.
Returns
AgoraChatError Whether the message deletion succeeds:
  • If the operation succeeds, the SDK returns nil.
  • If the operation fails, the SDK returns the failure reason such as the parameter error or database operation failure.

◆ searchMessagesWithTypes:timestamp:count:fromUser:searchDirection:completion:

- (void) searchMessagesWithTypes: (NSArray< NSNumber * > *_Nonnull)  aTypes
timestamp: (long long)  aTimestamp
count: (int)  aCount
fromUser: (NSString *_Nullable)  aUsername
searchDirection: (AgoraChatMessageSearchDirection)  aDirection
completion: (void(^)(NSArray< AgoraChatMessage * > *_Nullable aMessages, AgoraChatError *_Nullable aError))  aCompletionBlock 

Gets messages of certain types that a specified user sends in the conversation.

Parameters
aTypesThe message types to search. Types include txt (text message), img (image message), loc (location message), audio (audio message), video (video message), file (file message), and cmd (command message). AgoraChatMessageBodyType
aTimestampThe starting Unix timestamp in the message for query. The unit is millisecond. If you set this parameter as a negative value, the SDK loads messages from the latest one.
aCountThe number of messages to load each time. If you set this parameter to a value less than 1, the SDK retrieves one message.
aUsernameThe message sender. Setting it as nil means that the SDK ignores this parameter.
aDirectionThe message search direction. See AgoraChatMessageSearchDirection.
aCompletionBlockThe completion block, which contains the error message if the method fails.

◆ updateMessageChange:error:

- (void) updateMessageChange: (AgoraChatMessage *_Nonnull)  aMessage
error: (AgoraChatError **_Nullable)  pError 

Updates a message in the local database.

After you update a message, the message ID remains unchanged and the SDK automatically updates attributes of the conversation, like latestMessage.

Parameters
aMessageThe message to be updated.
pErrorThe error information if the method fails: Error.

Property Documentation

◆ conversationId

- (NSString*) conversationId
readnonatomiccopy

The conversation ID.

  • One-to-one chat: The conversation ID is the user ID of the peer user.
  • Group chat: The conversation ID is the group ID.
  • Chat room: The conversation ID is the chat room ID.

◆ disturbType

- (AgoraChatPushRemindType) disturbType
readnonatomicassign

The conversation no disturb type.AgoraChatPushRemindType

◆ ext

- (NSDictionary*) ext
readwritenonatomiccopy

The conversation extension attribute.

This attribute is not available for thread conversations.

◆ isChatThread

- (BOOL) isChatThread
readwritenonatomicassign

Whether the conversation is a thread conversation:

  • YES:Yes
  • NO:No

◆ isPinned

- (BOOL) isPinned
readatomicassign

Whether the conversation is pinned:

  • YES:Yes
  • NO:No

◆ latestMessage

- (AgoraChatMessage*) latestMessage
readnonatomicstrong

The latest message in the conversation.

◆ marks

- (NSArray<NSNumber*>*) marks
readnonatomicassign

The conversation mark.

◆ messagesCount

- (int) messagesCount
readnonatomicassign

The message count in the conversation.

◆ pinnedTime

- (int64_t) pinnedTime
readatomicassign

The UNIX timestamp when the conversation is pinned. The unit is millisecond. This value is 0 when the conversation is not pinned.

◆ type

- (AgoraChatConversationType) type
readnonatomicassign

The conversation type.

◆ unreadMessagesCount

- (int) unreadMessagesCount
readnonatomicassign

The number of unread messages in the conversation.


The documentation for this class was generated from the following file: