Upgrade messaging client to support attachments.

This commit is contained in:
akwizgran
2019-06-10 15:30:42 +01:00
parent f73d298752
commit 2bae639105
45 changed files with 1318 additions and 245 deletions

View File

@@ -20,7 +20,7 @@ internal class OutputEvent(val name: String, val data: JsonDict) {
val type = "event"
}
internal fun ConversationMessageReceivedEvent<*>.output(text: String): JsonDict {
internal fun ConversationMessageReceivedEvent<*>.output(text: String?): JsonDict {
check(messageHeader is PrivateMessageHeader)
return (messageHeader as PrivateMessageHeader).output(contactId, text)
}

View File

@@ -67,16 +67,16 @@ constructor(
override fun write(ctx: Context): Context {
val contact = getContact(ctx)
val message = ctx.getFromJson(objectMapper, "text")
if (utf8IsTooLong(message, MAX_PRIVATE_MESSAGE_TEXT_LENGTH))
val text = ctx.getFromJson(objectMapper, "text")
if (utf8IsTooLong(text, MAX_PRIVATE_MESSAGE_TEXT_LENGTH))
throw BadRequestResponse("Message text is too long")
val group = messagingManager.getContactGroup(contact)
val now = clock.currentTimeMillis()
val m = privateMessageFactory.createPrivateMessage(group.id, now, message, emptyList())
val m = privateMessageFactory.createPrivateMessage(group.id, now, text, emptyList())
messagingManager.addLocalMessage(m)
return ctx.json(m.output(contact.id, message))
return ctx.json(m.output(contact.id, text))
}
override fun eventOccurred(e: Event) {

View File

@@ -169,7 +169,12 @@ internal class MessagingControllerImplTest : ControllerTest() {
val event = PrivateMessageReceivedEvent(header, contact.id)
every { messagingManager.getMessageText(message.id) } returns text
every { webSocketController.sendEvent(EVENT_CONVERSATION_MESSAGE, event.output(text)) } just runs
every {
webSocketController.sendEvent(
EVENT_CONVERSATION_MESSAGE,
event.output(text)
)
} just runs
controller.eventOccurred(event)
}