mirror of
https://github.com/nextcloud/talk-android.git
synced 2024-11-26 23:25:20 +03:00
add ability to clear chat history
- moderators can clear the chat in the conversations settings - chat is cleared by system message CLEARED_CHAT Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
This commit is contained in:
parent
50a89ba2ba
commit
1558c8ed33
7 changed files with 67 additions and 3 deletions
|
@ -415,4 +415,7 @@ public interface NcApi {
|
|||
@Field("objectType") String objectType,
|
||||
@Field("objectId") String objectId,
|
||||
@Field("metaData") String metaData);
|
||||
|
||||
@DELETE
|
||||
Observable<GenericOverall> clearChatHistory(@Header("Authorization") String authorization, @Url String url);
|
||||
}
|
||||
|
|
|
@ -1805,7 +1805,7 @@ class ChatController(args: Bundle) :
|
|||
}
|
||||
|
||||
override fun onError(e: Throwable) {
|
||||
// unused atm
|
||||
Log.e(TAG, "failed to pull chat messages", e)
|
||||
}
|
||||
|
||||
override fun onComplete() {
|
||||
|
@ -1877,6 +1877,13 @@ class ChatController(args: Bundle) :
|
|||
val chatOverall = response.body() as ChatOverall?
|
||||
val chatMessageList = setDeletionFlagsAndRemoveInfomessages(chatOverall?.ocs!!.data)
|
||||
|
||||
if (chatMessageList.isNotEmpty() &&
|
||||
ChatMessage.SystemMessageType.CLEARED_CHAT == chatMessageList[0].systemMessageType
|
||||
) {
|
||||
adapter?.clear()
|
||||
adapter?.notifyDataSetChanged()
|
||||
}
|
||||
|
||||
if (isFirstMessagesProcessing) {
|
||||
cancelNotificationsForCurrentConversation()
|
||||
|
||||
|
|
|
@ -30,6 +30,7 @@ import android.text.TextUtils
|
|||
import android.util.Log
|
||||
import android.view.MenuItem
|
||||
import android.view.View
|
||||
import android.widget.Toast
|
||||
import androidx.appcompat.widget.SwitchCompat
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.work.Data
|
||||
|
@ -165,6 +166,7 @@ class ConversationInfoController(args: Bundle) :
|
|||
|
||||
binding.deleteConversationAction.setOnClickListener { showDeleteConversationDialog(null) }
|
||||
binding.leaveConversationAction.setOnClickListener { leaveConversation() }
|
||||
binding.clearConversationHistory.setOnClickListener { clearHistory() }
|
||||
binding.addParticipantsAction.setOnClickListener { addParticipants() }
|
||||
|
||||
fetchRoomInfo()
|
||||
|
@ -488,6 +490,35 @@ class ConversationInfoController(args: Bundle) :
|
|||
}
|
||||
}
|
||||
|
||||
private fun clearHistory() {
|
||||
val apiVersion = ApiUtils.getChatApiVersion(conversationUser, intArrayOf(1))
|
||||
|
||||
ncApi?.clearChatHistory(
|
||||
credentials,
|
||||
ApiUtils.getUrlForChat(apiVersion, conversationUser!!.baseUrl, conversationToken)
|
||||
)
|
||||
?.subscribeOn(Schedulers.io())
|
||||
?.observeOn(AndroidSchedulers.mainThread())
|
||||
?.subscribe(object : Observer<GenericOverall> {
|
||||
override fun onSubscribe(d: Disposable) {
|
||||
}
|
||||
|
||||
@Suppress("Detekt.TooGenericExceptionCaught")
|
||||
override fun onNext(genericOverall: GenericOverall) {
|
||||
Toast.makeText(context, context?.getString(R.string.nc_clear_history_success), Toast.LENGTH_LONG)
|
||||
.show()
|
||||
}
|
||||
|
||||
override fun onError(e: Throwable) {
|
||||
Toast.makeText(context, R.string.nc_common_error_sorry, Toast.LENGTH_LONG).show()
|
||||
Log.e(TAG, "failed to clear chat history", e)
|
||||
}
|
||||
|
||||
override fun onComplete() {
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
private fun deleteConversation() {
|
||||
workerData?.let {
|
||||
WorkManager.getInstance().enqueue(
|
||||
|
@ -529,8 +560,14 @@ class ConversationInfoController(args: Bundle) :
|
|||
|
||||
if (conversationCopy!!.canModerate(conversationUser)) {
|
||||
binding.addParticipantsAction.visibility = View.VISIBLE
|
||||
if (CapabilitiesUtil.hasSpreedFeatureCapability(conversationUser, "clear-history")) {
|
||||
binding.clearConversationHistory.visibility = View.VISIBLE
|
||||
} else {
|
||||
binding.clearConversationHistory.visibility = View.GONE
|
||||
}
|
||||
} else {
|
||||
binding.addParticipantsAction.visibility = View.GONE
|
||||
binding.clearConversationHistory.visibility = View.GONE
|
||||
}
|
||||
|
||||
if (isAttached && (!isBeingDestroyed || !isDestroyed)) {
|
||||
|
|
|
@ -646,6 +646,7 @@ public class ChatMessage implements MessageContentType, MessageContentType.Image
|
|||
MATTERBRIDGE_CONFIG_EDITED,
|
||||
MATTERBRIDGE_CONFIG_REMOVED,
|
||||
MATTERBRIDGE_CONFIG_ENABLED,
|
||||
MATTERBRIDGE_CONFIG_DISABLED
|
||||
MATTERBRIDGE_CONFIG_DISABLED,
|
||||
CLEARED_CHAT
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,8 +3,10 @@
|
|||
*
|
||||
* @author Mario Danic
|
||||
* @author Tim Krüger
|
||||
* Copyright (C) 2021 Tim Krüger <t@timkrueger.me>
|
||||
* @author Marcel Hibbe
|
||||
* Copyright (C) 2017-2018 Mario Danic <mario@lovelyhq.com>
|
||||
* Copyright (C) 2021 Tim Krüger <t@timkrueger.me>
|
||||
* Copyright (C) 2021 Marcel Hibbe <dev@mhibbe.de>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
@ -30,6 +32,7 @@ import com.nextcloud.talk.models.json.chat.ChatMessage.SystemMessageType.CALL_LE
|
|||
import com.nextcloud.talk.models.json.chat.ChatMessage.SystemMessageType.CALL_MISSED
|
||||
import com.nextcloud.talk.models.json.chat.ChatMessage.SystemMessageType.CALL_STARTED
|
||||
import com.nextcloud.talk.models.json.chat.ChatMessage.SystemMessageType.CALL_TRIED
|
||||
import com.nextcloud.talk.models.json.chat.ChatMessage.SystemMessageType.CLEARED_CHAT
|
||||
import com.nextcloud.talk.models.json.chat.ChatMessage.SystemMessageType.CONVERSATION_CREATED
|
||||
import com.nextcloud.talk.models.json.chat.ChatMessage.SystemMessageType.CONVERSATION_RENAMED
|
||||
import com.nextcloud.talk.models.json.chat.ChatMessage.SystemMessageType.DESCRIPTION_REMOVED
|
||||
|
@ -92,6 +95,7 @@ import com.nextcloud.talk.models.json.chat.ChatMessage.SystemMessageType.USER_RE
|
|||
* `guest_moderator_promoted` - {actor} promoted {user} to moderator
|
||||
* `guest_moderator_demoted` - {actor} demoted {user} from moderator
|
||||
* `message_deleted` - Message deleted by {actor} (Should not be shown to the user)
|
||||
* `history_cleared` - {actor} cleared the history of the conversation
|
||||
* `file_shared` - {file}
|
||||
* `object_shared` - {object}
|
||||
* `matterbridge_config_added` - {actor} set up Matterbridge to synchronize this conversation with other chats
|
||||
|
@ -139,6 +143,7 @@ class EnumSystemMessageTypeConverter : StringBasedTypeConverter<ChatMessage.Syst
|
|||
"matterbridge_config_removed" -> return MATTERBRIDGE_CONFIG_REMOVED
|
||||
"matterbridge_config_enabled" -> return MATTERBRIDGE_CONFIG_ENABLED
|
||||
"matterbridge_config_disabled" -> return MATTERBRIDGE_CONFIG_DISABLED
|
||||
"history_cleared" -> return CLEARED_CHAT
|
||||
else -> return DUMMY
|
||||
}
|
||||
}
|
||||
|
@ -186,6 +191,7 @@ class EnumSystemMessageTypeConverter : StringBasedTypeConverter<ChatMessage.Syst
|
|||
MATTERBRIDGE_CONFIG_REMOVED -> return "matterbridge_config_removed"
|
||||
MATTERBRIDGE_CONFIG_ENABLED -> return "matterbridge_config_enabled"
|
||||
MATTERBRIDGE_CONFIG_DISABLED -> return "matterbridge_config_disabled"
|
||||
CLEARED_CHAT -> return "clear_history"
|
||||
else -> return ""
|
||||
}
|
||||
}
|
||||
|
|
|
@ -171,6 +171,14 @@
|
|||
apc:mp_icon_tint="@color/grey_600"
|
||||
apc:mp_title="@string/nc_leave" />
|
||||
|
||||
<com.yarolegovich.mp.MaterialStandardPreference
|
||||
android:id="@+id/clearConversationHistory"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
apc:mp_icon="@drawable/ic_delete_black_24dp"
|
||||
apc:mp_icon_tint="@color/grey_600"
|
||||
apc:mp_title="@string/nc_clear_history" />
|
||||
|
||||
<com.yarolegovich.mp.MaterialStandardPreference
|
||||
android:id="@+id/deleteConversationAction"
|
||||
android:layout_width="match_parent"
|
||||
|
|
|
@ -167,6 +167,8 @@
|
|||
<string name="nc_start_conversation">Start a conversation</string>
|
||||
<string name="nc_configure_room">Configure conversation</string>
|
||||
<string name="nc_leave">Leave conversation</string>
|
||||
<string name="nc_clear_history">Clear history</string>
|
||||
<string name="nc_clear_history_success">Chat history was cleared</string>
|
||||
<string name="nc_rename">Rename conversation</string>
|
||||
<string name="nc_set_password">Set a password</string>
|
||||
<string name="nc_change_password">Change password</string>
|
||||
|
|
Loading…
Reference in a new issue