Added support for comment deletion.

This commit is contained in:
Koen 2023-11-29 13:54:26 +01:00
commit c806ff2e33
2 changed files with 48 additions and 44 deletions

View file

@ -154,33 +154,35 @@ class CommentsFragment : MainFragment() {
} }
private fun onDelete(comment: IPlatformComment) { private fun onDelete(comment: IPlatformComment) {
val processHandle = StatePolycentric.instance.processHandle ?: return UIDialogs.showConfirmationDialog(context, "Are you sure you want to delete this comment?", {
if (comment !is PolycentricPlatformComment) { val processHandle = StatePolycentric.instance.processHandle ?: return@showConfirmationDialog
return if (comment !is PolycentricPlatformComment) {
} return@showConfirmationDialog
}
val index = _comments.indexOf(comment) val index = _comments.indexOf(comment)
if (index != -1) { if (index != -1) {
_comments.removeAt(index) _comments.removeAt(index)
_adapterComments.notifyItemRemoved(_adapterComments.childToParentPosition(index)) _adapterComments.notifyItemRemoved(_adapterComments.childToParentPosition(index))
StateApp.instance.scopeOrNull?.launch(Dispatchers.IO) { StateApp.instance.scopeOrNull?.launch(Dispatchers.IO) {
try { try {
processHandle.delete(comment.eventPointer.process, comment.eventPointer.logicalClock) processHandle.delete(comment.eventPointer.process, comment.eventPointer.logicalClock)
} catch (e: Throwable) { } catch (e: Throwable) {
Logger.e(TAG, "Failed to delete event.", e); Logger.e(TAG, "Failed to delete event.", e);
return@launch; return@launch
} }
try { try {
Logger.i(TAG, "Started backfill"); Logger.i(TAG, "Started backfill");
processHandle.fullyBackfillServersAnnounceExceptions(); processHandle.fullyBackfillServersAnnounceExceptions();
Logger.i(TAG, "Finished backfill"); Logger.i(TAG, "Finished backfill");
} catch (e: Throwable) { } catch (e: Throwable) {
Logger.e(TAG, "Failed to fully backfill servers.", e); Logger.e(TAG, "Failed to fully backfill servers.", e);
}
} }
} }
} })
} }
fun onBackPressed(): Boolean { fun onBackPressed(): Boolean {

View file

@ -111,33 +111,35 @@ class CommentsList : ConstraintLayout {
} }
private fun onDelete(comment: IPlatformComment) { private fun onDelete(comment: IPlatformComment) {
val processHandle = StatePolycentric.instance.processHandle ?: return UIDialogs.showConfirmationDialog(context, "Are you sure you want to delete this comment?", {
if (comment !is PolycentricPlatformComment) { val processHandle = StatePolycentric.instance.processHandle ?: return@showConfirmationDialog
return if (comment !is PolycentricPlatformComment) {
} return@showConfirmationDialog
}
val index = _comments.indexOf(comment) val index = _comments.indexOf(comment)
if (index != -1) { if (index != -1) {
_comments.removeAt(index) _comments.removeAt(index)
_adapterComments.notifyItemRemoved(_adapterComments.childToParentPosition(index)) _adapterComments.notifyItemRemoved(_adapterComments.childToParentPosition(index))
StateApp.instance.scopeOrNull?.launch(Dispatchers.IO) { StateApp.instance.scopeOrNull?.launch(Dispatchers.IO) {
try { try {
processHandle.delete(comment.eventPointer.process, comment.eventPointer.logicalClock) processHandle.delete(comment.eventPointer.process, comment.eventPointer.logicalClock)
} catch (e: Throwable) { } catch (e: Throwable) {
Logger.e(TAG, "Failed to delete event.", e); Logger.e(TAG, "Failed to delete event.", e);
return@launch; return@launch;
} }
try { try {
Logger.i(TAG, "Started backfill"); Logger.i(TAG, "Started backfill");
processHandle.fullyBackfillServersAnnounceExceptions(); processHandle.fullyBackfillServersAnnounceExceptions();
Logger.i(TAG, "Finished backfill"); Logger.i(TAG, "Finished backfill");
} catch (e: Throwable) { } catch (e: Throwable) {
Logger.e(TAG, "Failed to fully backfill servers.", e); Logger.e(TAG, "Failed to fully backfill servers.", e);
}
} }
} }
} })
} }
private fun onScrolled() { private fun onScrolled() {