Message edit/delete/self-destroy feature

A banking app or any other app, where security is crucial and sensitive information might be passed, might need messages to be deleted some time after their receipt.

ConnectyCube platform provides you with message edit/delete/self-destroy feature. This feature can be used if your app requires a functionality for message editing/deleting or you need messages to be visible only for some limited amount of time. Self-destroy messages are not stored in server history.

We will show you how it can be configured below.

Software requirements

Our servers support this feature. However, you need to use the following SDK versions to configure it in your app:

How to use

Android

On Android the following code is required to configure message edit/delete/self-destroy features:

1. Edit message:

In order to edit a message you need to use the following method in ConnectycubeChatDialog:

try {
    dialog.editMessageWithId("5356c64ab35c12bd3b10wa64", "Updated message body", true);
} catch (SmackException.NotConnectedException e) {
    e.printStackTrace();
}

Note: User can edit a message he sent. In this case other parties (user or group chat) should be notified about it and correct the message at their side as well.

Message update listener:
In order to listen to message ‘update’ status and see when the message is edited you need to use the following listener:

MessageUpdateListener messageUpdateListener = new MessageUpdateListener() {
    @Override
    public void processMessageUpdated(String messageID, String dialogId, String newBody, boolean isLastMessage) {

    }
};
ConnectycubeChatService.getInstance().getMessageStatusesManager().addMessageUpdateListener(messageUpdateListener);

The following parameters are used:

Parameter Description
messageID Unique identifier of message to be edited
newBody New message text
isLast Is last in dialog and `last_message` field

 

2. Delete message:
In order to delete a message you need to use the following method in ConnectycubeChatDialog:

try {
    dialog.removeMessageWithId("5356c64ab35c12bd3b10wa64");
} catch (SmackException.NotConnectedException e) {
    e.printStackTrace();
}

Note: If user is the chat message owner (he sent it) then he can delete the message completely. In this case other parties (user or group chat) should be notified about it and delete the message at their side as well.

Message delete listener:
In order to listen to message ‘delete’ status you need to use the following listener:

MessageDeleteListener messageDeleteListener = new MessageDeleteListener() {
    @Override
    public void processMessageDeleted(String messageID, String dialogId) {

    }
};
ConnectycubeChatService.getInstance().getMessageStatusesManager().addMessageDeleteListener(messageDeleteListener);

messageID parameter means ID of the message to be removed.


3. Self-destroy message:
In order to use self-destroy message feature you need to use the following code in ConnectycubeChatMessage:

ConnectycubeChatMessage chatMessage = new ConnectycubeChatMessage();
chatMessage.setBody("Self destroy message");
chatMessage.setDestroyAfter(10);
try {
    chatDialog.sendMessage(chatMessage);
} catch (SmackException.NotConnectedException e) {
    e.printStackTrace();
}

Self-destroy message listener:

The following listener is required in CYBChatMessage model to get updates for self-destroy messages:

chatDialog.addMessageListener(new ChatDialogMessageListener() {
    @Override
    public void processMessage(String dialogId, ConnectycubeChatMessage message, Integer senderId) {
        if (message.getDestroyAfter() > 0) {
            // setup a timer
        }
     }
});

destroyAfter parameter means an interval in seconds after which the message must be destroyed on both sender and receiver’s sides.

Important note: It’s your responsibility to setup a timer in your app and remove messages from the client side.

 

iOS

On iOS the following code is required to configure message edit/delete/self-destroy features:

1. Edit message:
In order to edit a message you need to use the following method in CYBChatDialog model:

Objective-C:

CYBChatDialog *dialog = ...
[dialog editMessageWithID:@"5356c64ab35c12bd3b10wa64" text:@"New message text" last:YES completion:^(NSError * _Nullable error) {

}];

Swift:

let dialog = ...
dialog.editMessage(withID: "5356c64ab35c12bd3b10wa64", text: "New message text", last: true) { (error) in

}

Note: User can edit a message he sent. In this case other parties (user or group chat) should be notified about it and correct the message at their side as well.

Message edit listener:
In order to listen to message ‘edited’ status and see when the message is edited you need to use the following listener in CYBChatMessage model:

Objective-C:

//MARK: CYBChatDelegate
- (void)chatDidReceiveMessage:(CYBChatMessage *)message {
    //Handle edited message
    if (message.edited) {
    }
}

Swift:

//MARK: CYBChatDelegate
func chatDidReceive(_ message: ChatMessage) {
    //Handle edited message
    if (message.edited) {
    }
}

The following parameters are used:

Parameter Description
ID Unique identifier of message to be edited
text New message text
last The attribute is optional and can be included only if you edit last message in chat thread.
completion Completion block with failure error.

 

2. Delete message:
In order to delete a message you need to use the following method in CYBChatDialog model:

Objective-C:

CYBChatDialog *dialog = ...
[dialog removeMessageWithID:@"5356c64ab35c12bd3b10wa64" completion:^(NSError * _Nullable error) {

}];

Swift:

let dialog = ...
dialog.removeMessage(withID: "5356c64ab35c12bd3b10wa64") { (error) in

}

Note: If user is the chat message owner (he sent it) then he can delete the message completely. In this case other parties (user or group chat) should be notified about it and delete the message at their side as well.

 

Message delete listener:
In order to listen to message ‘delete’ status and see when the message is removed you need to use the following listener in CYBChatMessage model:

Objective-C:

//MARK: CYBChatDelegate
- (void)chatDidReceiveMessage:(CYBChatMessage *)message {
    //Handle removed message
    if (message.removed) {
    }
}

Swift:

//MARK: CYBChatDelegate
func chatDidReceive(_ message: ChatMessage) {
    //Handle removed message
    if (message.removed) {
    }
}

The following parameters are used:

Parameter Description
ID Unique identifier of message to be deleted
completion Completion block with failure error.

 

3. Self-destroy message:
In order to use self-destroy message feature you need to use the following code in CYBChatMessage model:

Objective-C:

CYBChatMessage *message = [[CYBChatMessage alloc] init];
message.text = @"Self destroy message";
message.destroyAfterInterval = 10 // in seconds

CYBChatDialog *privateDialog = ...;
[privateDialog sendMessage:message completionBlock:^(NSError * _Nullable error) {

}];

Swift:

let message = ChatMessage()
message.text = "Self destroy message"
message.destroyAfterInterval = 10 // in seconds

let privateDialog = ...
privateDialog.send(message) { (error) in

}

Important note: It’s your responsibility to setup a timer in your app and remove messages from the client side.

Self-destroy message listener:

The following delegate is required in CYBChatMessage model to get updates for self-destroy messages:

Objective-C:

//MARK: CYBChatDelegate
- (void)chatDidReceiveMessage:(CYBChatMessage *)message {
    //Handle destroyAfterInterval
    if (message.destroyAfterInterval > 0) {
        // setup a timer
    }
}

Swift:

//MARK: CYBChatDelegate
func chatDidReceive(_ message: ChatMessage) {
    //Handle destroyAfterInterval
    if (message.destroyAfterInterval > 0) {
        // setup a timer
    }
}

 

Hope you find the above information useful.

Please check our documentation for instructions how to start building an app:

iOS

Android

If you have any questions, please feel free to contact us.

Your feedback is always welcome!