Messaging

If you need translation feature, see below.

1. Get Messages

// get messages from channel
TPMessageRetrievalParams *params = 
    [[TPMessageRetrievalParams alloc] initWithChannel:channel];
params.lastMessage = lastMessage;
params.orderby = TPOrderByLatest;
params.translationLanguage = translationLanguage;

[[TalkPlus sharedInstance] getMessages:params 
    success:^(NSArray<TPMessage *> *tpMessages, BOOL hasNext) {
    // SUCCESS
    // If 'hasNext' is YES, call this method with the last object in 'tpMessages'.
} failure:^(int errorCode, NSError *error) {
    // FAILURE
}];

// get a single message from channel
TPMessageRetrievalParams *params = 
    [[TPMessageRetrievalParams alloc] initWithChannel:channel];
params.messageId = messageId;
params.translationLanguage = translationLanguage;

[[TalkPlus sharedInstance] getMessage:tpChannel
                            messageId:messageId
                            translationLanguage:@""
                            success:^(TPMessage *tpMessage) {
    
} failure:^(int errorCode, NSError *error) {
    
}];

2. View Messages With File Upload

View messages with file attachment.

TPMessageRetrievalParams *params = 
    [[TPMessageRetrievalParams alloc] initWithChannel:channel];
params.lastMessage = lastMessage;
params.orderby = TPOrderByLatest;
params.translationLanguage = translationLanguage;

[[TalkPlus sharedInstance] getFileMessages:params 
    success:^(NSArray<TPMessage *> *tpMessages, BOOL hasNext) {
    // SUCCESS
    // If 'hasNext' is YES, call this method with the last object in 'tpMessages'.
} failure:^(int errorCode, NSError *error) {
    // FAILURE
}];

3. Send Message

Setting translationLanguages property in TPMessageSendParams object will return TPMessage objects with translated texts via ''success block (success closure). Message recipient will be able to check the message via "messageReceived" callback event.

  • TPMessageSendParams class is available starting from TalkPlus iOS SDK v0.5.3.

// send message
TPMessageSendParams * params = 
    [[TPMessageSendParams alloc] initWithContentType:TPMessageContentText
        messageType:TPMessageText
        channel:channel];
        
params.textMessage = text; // required
params.mentionUserIDs = mentionUserIDs;
params.parentMessageId = parentMessageId;
params.fileUrl = fileUrl;
params.translationLanguages = translationLanguages;

[[TalkPlus sharedInstance] sendMessage:params success:^(TPMessage *tpMessage) {
    // SUCCESS
} failure:^(int errorCode, NSError *error) {
    // FAILURE
}];

// file upload
TPMessageSendParams * params = 
    [[TPMessageSendParams alloc] initWithContentType:TPMessageContentFile
        messageType:TPMessageText
        channel:channel];

params.filePath = filePath; // required
params.textMessage = textMessage;
params.mentionUserIDs = mentionUserIDs;
params.parentMessageId = parentMessageId;
params.translationLanguages = translationLanguages;

[[TalkPlus sharedInstance] sendMessage:params success:^(TPMessage *tpMessage) {
    // SUCCESS
} failure:^(int errorCode, NSError *error) {
    // FAILURE
}];

4. Get Message

View a single message.

// get a message from the channel
TPMessageRetrievalParams *params = 
    [[TPMessageRetrievalParams alloc] initWithChannel:channel];
params.translationLanguage = translationLanguage;

[[TalkPlus sharedInstance] getMessage:params 
    success:^(TPMessage *tpMessage) {
    // SUCCESS
} failure:^(int errorCode, NSError *error) {
    // FAILURE
}];

5. Reply To Message

Reply to another message.

TPMessageSendParams * params = 
    [[TPMessageSendParams alloc] initWithContentType:TPMessageContentText
        messageType:TPMessageText
        channel:channel];
        
params.textMessage = @"hello";
params.parentMessageId = @"anotherMessageIdThatIamReplyingTo";

[[TalkPlus sharedInstance] sendMessage:params success:^(TPMessage *tpMessage) {
    // SUCCESS
} failure:^(int errorCode, NSError *error) {
    // FAILURE
}];

6. Mark As Read

You can mark a channel as read.

[[TalkPlus sharedInstance] markAsReadChannel:tpChannel 
    success:^(TPChannel *tpChannel) {
    // SUCCESS
} failure:^(int errorCode, NSError *error) {
    // FAILURE
}]

7. React To Message

You can add/remove reaction to a message.

// add reaction
[[TalkPlus sharedInstance] addMessageReaction:tpMessage 
    reaction:reaction 
    success:^(TPMessage *tpMessage) {
    // SUCCESS
} failure:^(int errorCode, NSError *error) {
    // FAILURE
}];

// remove reaction
[[TalkPlus sharedInstance] removeMessageReaction:tpMessage 
    reaction:reaction 
    success:^(TPMessage *tpMessage) {
    // SUCCESS
} failure:^(int errorCode, NSError *error) {
    // FAILURE
}];

// see reactions in message object
[tpMessage getReactions];
/*
{
    "happy": [
        "user1",
        "user2"
    ],
    "sad": [
        "user3"
    ]
}
*/

8. Get Unread Message Count

You can find out how many channel members have not read a particular message.

[tpChannel getMessageUnreadCount:tpMessage];

9. Delete Message

You can delete your own message.

[[TalkPlus sharedInstance] deleteMessage:tpChannel 
    message:tpMessage 
    success:^{
    // SUCCESS
} failure:^(int errorCode, NSError *error) {
    // FAILURE
}];

Last updated