Send emote

This commit is contained in:
Benoit Marty 2019-04-09 17:53:23 +02:00
parent eaff5ac9f0
commit 6248cc5552
4 changed files with 12 additions and 8 deletions

View File

@ -18,6 +18,7 @@ package im.vector.matrix.android.api.session.room.send


import im.vector.matrix.android.api.MatrixCallback import im.vector.matrix.android.api.MatrixCallback
import im.vector.matrix.android.api.session.events.model.Event import im.vector.matrix.android.api.session.events.model.Event
import im.vector.matrix.android.api.session.room.model.message.MessageType
import im.vector.matrix.android.api.util.Cancelable import im.vector.matrix.android.api.util.Cancelable


/** /**
@ -28,10 +29,13 @@ interface SendService {
/** /**
* Method to send a text message asynchronously. * Method to send a text message asynchronously.
* @param text the text message to send * @param text the text message to send
* @param msgType the message type: MessageType.MSGTYPE_TEXT (default) or MessageType.MSGTYPE_EMOTE
* @param callback the callback to be notified. * @param callback the callback to be notified.
* @return a [Cancelable] * @return a [Cancelable]
*/ */
fun sendTextMessage(text: String, callback: MatrixCallback<Event>): Cancelable fun sendTextMessage(text: String,
msgType: String = MessageType.MSGTYPE_TEXT,
callback: MatrixCallback<Event>): Cancelable




} }

View File

@ -42,8 +42,8 @@ internal class DefaultSendService(private val roomId: String,
.build() .build()


// TODO callback is not used // TODO callback is not used
override fun sendTextMessage(text: String, callback: MatrixCallback<Event>): Cancelable { override fun sendTextMessage(text: String, msgType: String, callback: MatrixCallback<Event>): Cancelable {
val event = eventFactory.createTextEvent(roomId, text) val event = eventFactory.createTextEvent(roomId, msgType, text)


monarchy.tryTransactionAsync { realm -> monarchy.tryTransactionAsync { realm ->
val chunkEntity = ChunkEntity.findLastLiveChunkFromRoom(realm, roomId) val chunkEntity = ChunkEntity.findLastLiveChunkFromRoom(realm, roomId)

View File

@ -21,15 +21,14 @@ import im.vector.matrix.android.api.session.events.model.Content
import im.vector.matrix.android.api.session.events.model.Event import im.vector.matrix.android.api.session.events.model.Event
import im.vector.matrix.android.api.session.events.model.EventType import im.vector.matrix.android.api.session.events.model.EventType
import im.vector.matrix.android.api.session.room.model.message.MessageTextContent import im.vector.matrix.android.api.session.room.model.message.MessageTextContent
import im.vector.matrix.android.api.session.room.model.message.MessageType
import im.vector.matrix.android.internal.di.MoshiProvider import im.vector.matrix.android.internal.di.MoshiProvider


internal class EventFactory(private val credentials: Credentials) { internal class EventFactory(private val credentials: Credentials) {


private val moshi = MoshiProvider.providesMoshi() private val moshi = MoshiProvider.providesMoshi()


fun createTextEvent(roomId: String, text: String): Event { fun createTextEvent(roomId: String, msgType: String, text: String): Event {
val content = MessageTextContent(type = MessageType.MSGTYPE_TEXT, body = text) val content = MessageTextContent(type = msgType, body = text)


return Event( return Event(
roomId = roomId, roomId = roomId,

View File

@ -24,6 +24,7 @@ import com.jakewharton.rxrelay2.BehaviorRelay
import im.vector.matrix.android.api.MatrixCallback import im.vector.matrix.android.api.MatrixCallback
import im.vector.matrix.android.api.session.Session import im.vector.matrix.android.api.session.Session
import im.vector.matrix.android.api.session.events.model.Event import im.vector.matrix.android.api.session.events.model.Event
import im.vector.matrix.android.api.session.room.model.message.MessageType
import im.vector.matrix.rx.rx import im.vector.matrix.rx.rx
import im.vector.riotredesign.core.platform.VectorViewModel import im.vector.riotredesign.core.platform.VectorViewModel
import im.vector.riotredesign.core.utils.LiveEvent import im.vector.riotredesign.core.utils.LiveEvent
@ -136,8 +137,8 @@ class RoomDetailViewModel(initialState: RoomDetailViewState,
_sendMessageResultLiveData.postValue(LiveEvent(SendMessageResult.SlashCommandNotImplemented)) _sendMessageResultLiveData.postValue(LiveEvent(SendMessageResult.SlashCommandNotImplemented))
} }
is ParsedCommand.SendEmote -> { is ParsedCommand.SendEmote -> {
// TODO room.sendTextMessage(slashCommandResult.message, msgType = MessageType.MSGTYPE_EMOTE, callback = object : MatrixCallback<Event> {})
_sendMessageResultLiveData.postValue(LiveEvent(SendMessageResult.SlashCommandNotImplemented)) _sendMessageResultLiveData.postValue(LiveEvent(SendMessageResult.SlashCommandHandled))
} }
is ParsedCommand.ChangeTopic -> { is ParsedCommand.ChangeTopic -> {
// TODO // TODO