mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-13 19:29:06 +01:00
Add method to mark message as read to REST API
When exposing unread messages counters in https://code.briarproject.org/briar/briar/-/merge_requests/1283, I noticed that they were never set to 0. Fixes #1780
This commit is contained in:
@@ -86,6 +86,9 @@ constructor(
|
||||
get { ctx -> messagingController.list(ctx) }
|
||||
post { ctx -> messagingController.write(ctx) }
|
||||
}
|
||||
path("/messages/:contactId/read") {
|
||||
post { ctx -> messagingController.markMessageRead(ctx) }
|
||||
}
|
||||
path("/forums") {
|
||||
get { ctx -> forumController.list(ctx) }
|
||||
post { ctx -> forumController.create(ctx) }
|
||||
|
||||
@@ -8,4 +8,6 @@ interface MessagingController {
|
||||
|
||||
fun write(ctx: Context): Context
|
||||
|
||||
fun markMessageRead(ctx: Context): Context
|
||||
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ import org.briarproject.bramble.api.event.Event
|
||||
import org.briarproject.bramble.api.event.EventListener
|
||||
import org.briarproject.bramble.api.sync.event.MessagesAckedEvent
|
||||
import org.briarproject.bramble.api.sync.event.MessagesSentEvent
|
||||
import org.briarproject.bramble.api.sync.MessageId
|
||||
import org.briarproject.bramble.api.system.Clock
|
||||
import org.briarproject.bramble.util.StringUtils.utf8IsTooLong
|
||||
import org.briarproject.briar.api.blog.BlogInvitationRequest
|
||||
@@ -35,6 +36,8 @@ import org.briarproject.briar.headless.event.output
|
||||
import org.briarproject.briar.headless.getContactIdFromPathParam
|
||||
import org.briarproject.briar.headless.getFromJson
|
||||
import org.briarproject.briar.headless.json.JsonDict
|
||||
import org.spongycastle.util.encoders.Base64
|
||||
import org.spongycastle.util.encoders.DecoderException
|
||||
import java.util.concurrent.Executor
|
||||
import javax.annotation.concurrent.Immutable
|
||||
import javax.inject.Inject
|
||||
@@ -83,6 +86,26 @@ constructor(
|
||||
return ctx.json(m.output(contact.id, text))
|
||||
}
|
||||
|
||||
override fun markMessageRead(ctx: Context): Context {
|
||||
val contact = getContact(ctx)
|
||||
val groupId = messagingManager.getContactGroup(contact).id
|
||||
|
||||
val messageIdString = ctx.getFromJson(objectMapper, "messageId")
|
||||
val messageId = deserializeMessageId(messageIdString)
|
||||
messagingManager.setReadFlag(groupId, messageId, true)
|
||||
return ctx.json(messageIdString)
|
||||
}
|
||||
|
||||
private fun deserializeMessageId(idString: String): MessageId {
|
||||
val idBytes = try {
|
||||
Base64.decode(idString)
|
||||
} catch (e: DecoderException) {
|
||||
throw NotFoundResponse()
|
||||
}
|
||||
if (idBytes.size != MessageId.LENGTH) throw NotFoundResponse()
|
||||
return MessageId(idBytes)
|
||||
}
|
||||
|
||||
override fun eventOccurred(e: Event) {
|
||||
when (e) {
|
||||
is ConversationMessageReceivedEvent<*> -> {
|
||||
|
||||
Reference in New Issue
Block a user