Extensions.kt 1.79 KB
Newer Older
1 2
package org.briarproject.briar.headless.messaging

3
import org.briarproject.bramble.api.contact.ContactId
4 5
import org.briarproject.briar.api.introduction.IntroductionRequest
import org.briarproject.briar.api.introduction.IntroductionResponse
6 7
import org.briarproject.briar.api.messaging.PrivateMessage
import org.briarproject.briar.api.messaging.PrivateMessageHeader
8 9
import org.briarproject.briar.api.messaging.PrivateRequest
import org.briarproject.briar.api.messaging.PrivateResponse
10
import org.briarproject.briar.api.messaging.event.PrivateMessageReceivedEvent
11 12
import org.briarproject.briar.api.sharing.InvitationRequest
import org.briarproject.briar.api.sharing.InvitationResponse
13

14 15 16
internal fun PrivateMessageHeader.output(
    contactId: ContactId,
    body: String?
17
) = OutputPrivateMessageHeader(this, contactId, body)
18

19
internal fun PrivateMessage.output(contactId: ContactId, body: String) =
20
    OutputPrivateMessageHeader(this, contactId, body)
21

22
internal fun PrivateMessageReceivedEvent<*>.output(body: String) =
23
    messageHeader.output(contactId, body)
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42

internal fun IntroductionRequest.output(contactId: ContactId) =
    OutputIntroductionRequest(this, contactId)

internal fun PrivateRequest<*>.output(contactId: ContactId): OutputPrivateMessage {
    return when (this) {
        is IntroductionRequest -> OutputIntroductionRequest(this, contactId)
        is InvitationRequest -> OutputInvitationRequest(this, contactId)
        else -> throw AssertionError("Unknown PrivateRequest")
    }
}

internal fun PrivateResponse.output(contactId: ContactId): OutputPrivateMessage {
    return when (this) {
        is IntroductionResponse -> OutputIntroductionResponse(this, contactId)
        is InvitationResponse -> OutputInvitationResponse(this, contactId)
        else -> throw AssertionError("Unknown PrivateResponse")
    }
}