How to clear the chat record of a session on rongyun Android

Time:2021-8-10

How to clear the chat record of a session on rongyun Android

Implementation instructions

If “cloud storage of historical messages” is not enabled, only local data can be deleted. Remote messages can be deleted only after the “cloud storage function of historical messages” is enabled on the rongyun console.

Implementation steps

1. Call the cleanhistorymessages method. Cleanremote sends true and recordtime sends the current timestamp.

/**
     *Delete the messages before the specified timestamp. You can choose whether to delete the server-side messages at the same time
     *< p > this method clears historical messages from the server, but the cloud storage function of historical messages must be enabled first</ p>
     *< p > clear the local database message (server history message) before the specified timestamp of a session according to the session type and targetid,
     *After successful clearing, the historical messages after the timestamp can only be obtained from the local database (server)</ p>
     *
     *@ param conversationtype session type.
     *@ param targetid session targetid.
     *@ param recordtime clears the message deadline timestamp, [0 ~ UNIX timestamp of current time].
     *@ param cleanremote delete server-side message
     *@ param callback clears the callback of the message.
     */
    public void cleanHistoryMessages(final Conversation.ConversationType conversationType,
                                     final String targetId,
                                     final long recordTime,
                                     final boolean cleanRemote,
                                     final OperationCallback callback)

2. You are using imlib and need to refresh your interface by yourself.
3. You use imkit to call the getmessageadapter method of conversationfragment to obtain the session interface message display adapter, remove the data and refresh the data source.

mListAdapter.removeAll();
mListAdapter.notifyDataSetChanged();

4. After the user logs in to uninstall, reinstall or replace the device, the historical message can also be pulled to ensure that the user can still have a context after replacing the device or uninstalling and reinstalling. If you don’t want to receive these messages after the end change, you can provide appkey to submit the work order. We will help you turn off the caching function of this part of data.