Add output of DeletionResult to deleteAllMessages call

This commit is contained in:
Nico Alt
2020-10-08 14:42:40 +02:00
parent 6c6dbfd357
commit c017a813b0
3 changed files with 37 additions and 3 deletions

View File

@@ -109,11 +109,11 @@ constructor(
override fun deleteAllMessages(ctx: Context): Context {
val contactId = ctx.getContactIdFromPathParam()
try {
conversationManager.deleteAllMessages(contactId)
val result = conversationManager.deleteAllMessages(contactId)
return ctx.json(result.output())
} catch (e: NoSuchContactException) {
throw NotFoundResponse()
}
return ctx
}
override fun eventOccurred(e: Event) {

View File

@@ -5,6 +5,7 @@ import org.briarproject.bramble.api.sync.MessageId
import org.briarproject.bramble.api.sync.event.MessagesAckedEvent
import org.briarproject.bramble.api.sync.event.MessagesSentEvent
import org.briarproject.briar.api.conversation.ConversationMessageHeader
import org.briarproject.briar.api.conversation.DeletionResult
import org.briarproject.briar.api.messaging.PrivateMessage
import org.briarproject.briar.api.messaging.PrivateMessageHeader
import org.briarproject.briar.headless.json.JsonDict
@@ -47,6 +48,15 @@ internal fun PrivateMessage.output(contactId: ContactId, text: String) = JsonDic
"text" to text
)
internal fun DeletionResult.output() = JsonDict(
"allDeleted" to allDeleted(),
"hasIntroductionSessionInProgress" to hasIntroductionSessionInProgress(),
"hasInvitationSessionInProgress" to hasInvitationSessionInProgress(),
"hasNotAllIntroductionSelected" to hasNotAllIntroductionSelected(),
"hasNotAllInvitationSelected" to hasNotAllInvitationSelected(),
"hasNotFullyDownloaded" to hasNotFullyDownloaded()
)
internal fun MessagesAckedEvent.output() = JsonDict(
"contactId" to contactId.int,
"messageIds" to messageIds.toJson()