|
@@ -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 { showClearHistoryDialog(null) }
|
|
|
binding.addParticipantsAction.setOnClickListener { addParticipants() }
|
|
|
|
|
|
fetchRoomInfo()
|
|
@@ -299,6 +301,7 @@ class ConversationInfoController(args: Bundle) :
|
|
|
private fun showLovelyDialog(dialogId: Int, savedInstanceState: Bundle) {
|
|
|
when (dialogId) {
|
|
|
ID_DELETE_CONVERSATION_DIALOG -> showDeleteConversationDialog(savedInstanceState)
|
|
|
+ ID_CLEAR_CHAT_DIALOG -> showClearHistoryDialog(savedInstanceState)
|
|
|
else -> {
|
|
|
}
|
|
|
}
|
|
@@ -488,6 +491,55 @@ class ConversationInfoController(args: Bundle) :
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private fun showClearHistoryDialog(savedInstanceState: Bundle?) {
|
|
|
+ if (activity != null) {
|
|
|
+ LovelyStandardDialog(activity, LovelyStandardDialog.ButtonLayout.HORIZONTAL)
|
|
|
+ .setTopColorRes(R.color.nc_darkRed)
|
|
|
+ .setIcon(
|
|
|
+ DisplayUtils.getTintedDrawable(
|
|
|
+ context!!.resources,
|
|
|
+ R.drawable.ic_delete_black_24dp, R.color.bg_default
|
|
|
+ )
|
|
|
+ )
|
|
|
+ .setPositiveButtonColor(context!!.resources.getColor(R.color.nc_darkRed))
|
|
|
+ .setTitle(R.string.nc_clear_history)
|
|
|
+ .setMessage(R.string.nc_clear_history_warning)
|
|
|
+ .setPositiveButton(R.string.nc_delete) { clearHistory() }
|
|
|
+ .setNegativeButton(R.string.nc_cancel, null)
|
|
|
+ .setInstanceStateHandler(ID_CLEAR_CHAT_DIALOG, saveStateHandler!!)
|
|
|
+ .setSavedInstanceState(savedInstanceState)
|
|
|
+ .show()
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ 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) {
|
|
|
+ }
|
|
|
+
|
|
|
+ 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 +581,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)) {
|
|
@@ -1002,6 +1060,7 @@ class ConversationInfoController(args: Bundle) :
|
|
|
companion object {
|
|
|
private const val TAG = "ConversationInfControll"
|
|
|
private const val ID_DELETE_CONVERSATION_DIALOG = 0
|
|
|
+ private const val ID_CLEAR_CHAT_DIALOG = 1
|
|
|
private val LOW_EMPHASIS_OPACITY: Float = 0.38f
|
|
|
}
|
|
|
|