Skip to content

Add additional data in voice broadcast events #7397

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Oct 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/7397.wip
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[Voice Broadcast] Add additional data in events
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,30 @@ interface SendService {
* @param text the text message to send
* @param msgType the message type: MessageType.MSGTYPE_TEXT (default) or MessageType.MSGTYPE_EMOTE
* @param autoMarkdown If true, the SDK will generate a formatted HTML message from the body text if markdown syntax is present
* @param additionalContent additional content to put in the event content
* @return a [Cancelable]
*/
fun sendTextMessage(text: CharSequence, msgType: String = MessageType.MSGTYPE_TEXT, autoMarkdown: Boolean = false): Cancelable
fun sendTextMessage(
text: CharSequence,
msgType: String = MessageType.MSGTYPE_TEXT,
autoMarkdown: Boolean = false,
additionalContent: Content? = null,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a bit weird to have this available in all methods but I guess its acceptable.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I was not sure but internally we thought that the sdk should allow adding custom fields for any event content following the Matrix specification. So, I added this field for each entry.

): Cancelable

/**
* Method to send a text message with a formatted body.
* @param text the text message to send
* @param formattedText The formatted body using MessageType#FORMAT_MATRIX_HTML
* @param msgType the message type: MessageType.MSGTYPE_TEXT (default) or MessageType.MSGTYPE_EMOTE
* @param additionalContent additional content to put in the event content
* @return a [Cancelable]
*/
fun sendFormattedTextMessage(text: String, formattedText: String, msgType: String = MessageType.MSGTYPE_TEXT): Cancelable
fun sendFormattedTextMessage(
text: String,
formattedText: String,
msgType: String = MessageType.MSGTYPE_TEXT,
additionalContent: Content? = null,
): Cancelable

/**
* Method to quote an events content.
Expand All @@ -65,6 +77,7 @@ interface SendService {
* @param formattedText the formatted text message to send
* @param autoMarkdown If true, the SDK will generate a formatted HTML message from the body text if markdown syntax is present
* @param rootThreadEventId when this param is not null, the message will be sent in this specific thread
* @param additionalContent additional content to put in the event content
* @return a [Cancelable]
*/
fun sendQuotedTextMessage(
Expand All @@ -73,6 +86,7 @@ interface SendService {
formattedText: String? = null,
autoMarkdown: Boolean,
rootThreadEventId: String? = null,
additionalContent: Content? = null,
): Cancelable

/**
Expand All @@ -83,6 +97,7 @@ interface SendService {
* It can be useful to send media to multiple room. It's safe to include the current roomId in this set
* @param rootThreadEventId when this param is not null, the Media will be sent in this specific thread
* @param relatesTo add a relation content to the media event
* @param additionalContent additional content to put in the event content
* @return a [Cancelable]
*/
fun sendMedia(
Expand All @@ -91,6 +106,7 @@ interface SendService {
roomIds: Set<String>,
rootThreadEventId: String? = null,
relatesTo: RelationDefaultContent? = null,
additionalContent: Content? = null,
): Cancelable

/**
Expand All @@ -100,45 +116,51 @@ interface SendService {
* @param roomIds set of roomIds to where the media will be sent. The current roomId will be add to this set if not present.
* It can be useful to send media to multiple room. It's safe to include the current roomId in this set
* @param rootThreadEventId when this param is not null, all the Media will be sent in this specific thread
* @param additionalContent additional content to put in the event content
* @return a [Cancelable]
*/
fun sendMedias(
attachments: List<ContentAttachmentData>,
compressBeforeSending: Boolean,
roomIds: Set<String>,
rootThreadEventId: String? = null,
additionalContent: Content? = null,
): Cancelable

/**
* Send a poll to the room.
* @param pollType indicates open or closed polls
* @param question the question
* @param options list of options
* @param additionalContent additional content to put in the event content
* @return a [Cancelable]
*/
fun sendPoll(pollType: PollType, question: String, options: List<String>): Cancelable
fun sendPoll(pollType: PollType, question: String, options: List<String>, additionalContent: Content? = null): Cancelable

/**
* Method to send a poll response.
* @param pollEventId the poll currently replied to
* @param answerId The id of the answer
* @param additionalContent additional content to put in the event content
* @return a [Cancelable]
*/
fun voteToPoll(pollEventId: String, answerId: String): Cancelable
fun voteToPoll(pollEventId: String, answerId: String, additionalContent: Content? = null): Cancelable

/**
* End a poll in the room.
* @param pollEventId event id of the poll
* @param additionalContent additional content to put in the event content
* @return a [Cancelable]
*/
fun endPoll(pollEventId: String): Cancelable
fun endPoll(pollEventId: String, additionalContent: Content? = null): Cancelable

/**
* Redact (delete) the given event.
* @param event The event to redact
* @param reason Optional reason string
* @param additionalContent additional content to put in the event content
*/
fun redactEvent(event: Event, reason: String?): Cancelable
fun redactEvent(event: Event, reason: String?, additionalContent: Content? = null): Cancelable

/**
* Schedule this message to be resent.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import org.matrix.android.sdk.api.extensions.tryOrNull
import org.matrix.android.sdk.api.listeners.ProgressListener
import org.matrix.android.sdk.api.session.content.ContentAttachmentData
import org.matrix.android.sdk.api.session.crypto.model.EncryptedFileInfo
import org.matrix.android.sdk.api.session.events.model.Content
import org.matrix.android.sdk.api.session.events.model.toContent
import org.matrix.android.sdk.api.session.events.model.toModel
import org.matrix.android.sdk.api.session.room.model.message.MessageAudioContent
Expand Down Expand Up @@ -407,15 +408,18 @@ internal class UploadContentWorker(val context: Context, params: WorkerParameter
newAttachmentAttributes: NewAttachmentAttributes
) {
localEchoRepository.updateEcho(eventId) { _, event ->
val messageContent: MessageContent? = event.asDomain().content.toModel()
val content: Content? = event.asDomain().content
val messageContent: MessageContent? = content.toModel()
// Retrieve potential additional content from the original event
val additionalContent = content.orEmpty() - messageContent?.toContent().orEmpty().keys
val updatedContent = when (messageContent) {
is MessageImageContent -> messageContent.update(url, encryptedFileInfo, newAttachmentAttributes)
is MessageVideoContent -> messageContent.update(url, encryptedFileInfo, thumbnailUrl, thumbnailEncryptedFileInfo, newAttachmentAttributes)
is MessageFileContent -> messageContent.update(url, encryptedFileInfo, newAttachmentAttributes.newFileSize)
is MessageAudioContent -> messageContent.update(url, encryptedFileInfo, newAttachmentAttributes.newFileSize)
else -> messageContent
}
event.content = ContentMapper.map(updatedContent.toContent())
event.content = ContentMapper.map(updatedContent.toContent().plus(additionalContent))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import dagger.assisted.AssistedInject
import kotlinx.coroutines.launch
import org.matrix.android.sdk.api.MatrixUrls.isMxcUrl
import org.matrix.android.sdk.api.session.content.ContentAttachmentData
import org.matrix.android.sdk.api.session.events.model.Content
import org.matrix.android.sdk.api.session.events.model.Event
import org.matrix.android.sdk.api.session.events.model.isAttachmentMessage
import org.matrix.android.sdk.api.session.events.model.isTextMessage
Expand Down Expand Up @@ -88,14 +89,14 @@ internal class DefaultSendService @AssistedInject constructor(
.let { sendEvent(it) }
}

override fun sendTextMessage(text: CharSequence, msgType: String, autoMarkdown: Boolean): Cancelable {
return localEchoEventFactory.createTextEvent(roomId, msgType, text, autoMarkdown)
override fun sendTextMessage(text: CharSequence, msgType: String, autoMarkdown: Boolean, additionalContent: Content?): Cancelable {
return localEchoEventFactory.createTextEvent(roomId, msgType, text, autoMarkdown, additionalContent)
.also { createLocalEcho(it) }
.let { sendEvent(it) }
}

override fun sendFormattedTextMessage(text: String, formattedText: String, msgType: String): Cancelable {
return localEchoEventFactory.createFormattedTextEvent(roomId, TextContent(text, formattedText), msgType)
override fun sendFormattedTextMessage(text: String, formattedText: String, msgType: String, additionalContent: Content?): Cancelable {
return localEchoEventFactory.createFormattedTextEvent(roomId, TextContent(text, formattedText), msgType, additionalContent)
.also { createLocalEcho(it) }
.let { sendEvent(it) }
}
Expand All @@ -105,41 +106,43 @@ internal class DefaultSendService @AssistedInject constructor(
text: String,
formattedText: String?,
autoMarkdown: Boolean,
rootThreadEventId: String?
rootThreadEventId: String?,
additionalContent: Content?,
): Cancelable {
return localEchoEventFactory.createQuotedTextEvent(
roomId = roomId,
quotedEvent = quotedEvent,
text = text,
formattedText = formattedText,
autoMarkdown = autoMarkdown,
rootThreadEventId = rootThreadEventId
rootThreadEventId = rootThreadEventId,
additionalContent = additionalContent,
)
.also { createLocalEcho(it) }
.let { sendEvent(it) }
}

override fun sendPoll(pollType: PollType, question: String, options: List<String>): Cancelable {
return localEchoEventFactory.createPollEvent(roomId, pollType, question, options)
override fun sendPoll(pollType: PollType, question: String, options: List<String>, additionalContent: Content?): Cancelable {
return localEchoEventFactory.createPollEvent(roomId, pollType, question, options, additionalContent)
.also { createLocalEcho(it) }
.let { sendEvent(it) }
}

override fun voteToPoll(pollEventId: String, answerId: String): Cancelable {
return localEchoEventFactory.createPollReplyEvent(roomId, pollEventId, answerId)
override fun voteToPoll(pollEventId: String, answerId: String, additionalContent: Content?): Cancelable {
return localEchoEventFactory.createPollReplyEvent(roomId, pollEventId, answerId, additionalContent)
.also { createLocalEcho(it) }
.let { sendEvent(it) }
}

override fun endPoll(pollEventId: String): Cancelable {
return localEchoEventFactory.createEndPollEvent(roomId, pollEventId)
override fun endPoll(pollEventId: String, additionalContent: Content?): Cancelable {
return localEchoEventFactory.createEndPollEvent(roomId, pollEventId, additionalContent)
.also { createLocalEcho(it) }
.let { sendEvent(it) }
}

override fun redactEvent(event: Event, reason: String?): Cancelable {
override fun redactEvent(event: Event, reason: String?, additionalContent: Content?): Cancelable {
// TODO manage media/attachements?
val redactionEcho = localEchoEventFactory.createRedactEvent(roomId, event.eventId!!, reason)
val redactionEcho = localEchoEventFactory.createRedactEvent(roomId, event.eventId!!, reason, additionalContent)
.also { createLocalEcho(it) }
return eventSenderProcessor.postRedaction(redactionEcho, reason)
}
Expand Down Expand Up @@ -265,7 +268,8 @@ internal class DefaultSendService @AssistedInject constructor(
attachments: List<ContentAttachmentData>,
compressBeforeSending: Boolean,
roomIds: Set<String>,
rootThreadEventId: String?
rootThreadEventId: String?,
additionalContent: Content?,
): Cancelable {
return attachments.mapTo(CancelableBag()) {
sendMedia(
Expand All @@ -283,6 +287,7 @@ internal class DefaultSendService @AssistedInject constructor(
roomIds: Set<String>,
rootThreadEventId: String?,
relatesTo: RelationDefaultContent?,
additionalContent: Content?,
): Cancelable {
// Ensure that the event will not be send in a thread if we are a different flow.
// Like sending files to multiple rooms
Expand All @@ -299,6 +304,7 @@ internal class DefaultSendService @AssistedInject constructor(
attachment = attachment,
rootThreadEventId = rootThreadId,
relatesTo,
additionalContent,
).also { event ->
createLocalEcho(event)
}
Expand Down
Loading