Skip to content

Commit

Permalink
Merge pull request #783 from tchapgouv/feature/fre/content_scanner_au…
Browse files Browse the repository at this point in the history
…dio_files

Activate the content scanner for audio files
  • Loading branch information
appndigital authored Dec 8, 2022
2 parents bdc9a07 + 747e090 commit 618300b
Show file tree
Hide file tree
Showing 6 changed files with 138 additions and 3 deletions.
1 change: 1 addition & 0 deletions changelog.d/780.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Activate the antivirus for audio files
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,9 @@ class MessageItemFactory @Inject constructor(
.contentDownloadStateTrackerBinder(contentDownloadStateTrackerBinder)
.highlighted(highlight)
.leftGuideline(avatarSizeProvider.leftGuideline)
// Tchap: Use for the Antivirus
.elementToDecrypt(messageContent.encryptedFileInfo?.toElementToDecrypt())
.contentScannerStateTracker(contentScannerStateTracker)
}

private fun getAudioFileUrl(
Expand Down Expand Up @@ -347,6 +350,9 @@ class MessageItemFactory @Inject constructor(
.contentDownloadStateTrackerBinder(contentDownloadStateTrackerBinder)
.highlighted(highlight)
.leftGuideline(avatarSizeProvider.leftGuideline)
// Tchap: Use for the Antivirus
.elementToDecrypt(messageContent.encryptedFileInfo?.toElementToDecrypt())
.contentScannerStateTracker(contentScannerStateTracker)
}

private fun buildVerificationRequestMessageItem(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import android.view.ViewGroup
import android.widget.ImageButton
import android.widget.SeekBar
import android.widget.TextView
import androidx.core.content.ContextCompat
import androidx.core.view.isVisible
import com.airbnb.epoxy.EpoxyAttribute
import com.airbnb.epoxy.EpoxyModelClass
Expand All @@ -33,9 +34,12 @@ import im.vector.app.core.epoxy.onClick
import im.vector.app.core.utils.TextUtils
import im.vector.app.features.home.room.detail.timeline.helper.AudioMessagePlaybackTracker
import im.vector.app.features.home.room.detail.timeline.helper.ContentDownloadStateTrackerBinder
import im.vector.app.features.home.room.detail.timeline.helper.ContentScannerStateTracker
import im.vector.app.features.home.room.detail.timeline.helper.ContentUploadStateTrackerBinder
import im.vector.app.features.home.room.detail.timeline.style.TimelineMessageLayout
import im.vector.app.features.themes.ThemeUtils
import me.gujun.android.span.span
import org.matrix.android.sdk.api.session.crypto.attachments.ElementToDecrypt

@EpoxyModelClass
abstract class MessageAudioItem : AbsMessageItem<MessageAudioItem.Holder>() {
Expand Down Expand Up @@ -71,6 +75,12 @@ abstract class MessageAudioItem : AbsMessageItem<MessageAudioItem.Holder>() {
@EpoxyAttribute
lateinit var audioMessagePlaybackTracker: AudioMessagePlaybackTracker

@EpoxyAttribute
var contentScannerStateTracker: ContentScannerStateTracker? = null

@EpoxyAttribute
var elementToDecrypt: ElementToDecrypt? = null

private var isUserSeeking = false

override fun bind(holder: Holder) {
Expand All @@ -82,6 +92,9 @@ abstract class MessageAudioItem : AbsMessageItem<MessageAudioItem.Holder>() {
bindSeekBar(holder)
holder.audioPlaybackControlButton.setOnClickListener { playbackControlButtonClickListener?.invoke(it) }
renderStateBasedOnAudioPlayback(holder)

holder.resetAV()
contentScannerStateTracker?.bind(attributes.informationData.eventId, mxcUrl, elementToDecrypt, holder)
}

private fun bindUploadState(holder: Holder) {
Expand Down Expand Up @@ -193,11 +206,12 @@ abstract class MessageAudioItem : AbsMessageItem<MessageAudioItem.Holder>() {
contentUploadStateTrackerBinder.unbind(attributes.informationData.eventId)
contentDownloadStateTrackerBinder.unbind(mxcUrl)
audioMessagePlaybackTracker.untrack(attributes.informationData.eventId)
contentScannerStateTracker?.unBind(attributes.informationData.eventId)
}

override fun getViewStubId() = STUB_ID

class Holder : AbsMessageItem.Holder(STUB_ID) {
class Holder : AbsMessageItem.Holder(STUB_ID), ScannableHolder {
val rootLayout by bind<ViewGroup>(R.id.messageRootLayout)
val mainLayout by bind<ViewGroup>(R.id.messageMainInnerLayout)
val filenameView by bind<TextView>(R.id.messageFilenameView)
Expand All @@ -207,6 +221,46 @@ abstract class MessageAudioItem : AbsMessageItem<MessageAudioItem.Holder>() {
val fileSize by bind<TextView>(R.id.fileSize)
val audioPlaybackDuration by bind<TextView>(R.id.audioPlaybackDuration)
val audioSeekBar by bind<SeekBar>(R.id.audioSeekBar)

private val messageFileAvText by bind<TextView>(R.id.messageFileAvText)

fun resetAV() {
messageFileAvText.isVisible = false
}

override fun mediaScanResult(clean: Boolean) {
if (clean) {
messageFileAvText.text = view.context.getText(R.string.antivirus_clean)
messageFileAvText.isVisible = true
messageFileAvText.setCompoundDrawablesWithIntrinsicBounds(
ContextCompat.getDrawable(view.context, R.drawable.ic_av_checked),
null,
null,
null
)
} else {
// disable click on infected files
audioPlaybackControlButton.setOnClickListener(null)
audioSeekBar.isEnabled = false
audioSeekBar.setOnSeekBarChangeListener(null)
filenameView.onClick(null)

messageFileAvText.text = span(view.context.getText(R.string.antivirus_infected)) {
textColor = ThemeUtils.getColor(view.context, R.attr.colorError)
}
messageFileAvText.isVisible = true
messageFileAvText.setCompoundDrawables(null, null, null, null)
filenameView.text = view.context.getString(R.string.tchap_scan_media_untrusted_content_message, filenameView.text)
}
}

override fun mediaScanInProgress() {
messageFileAvText.text = span(view.context.getText(R.string.antivirus_in_progress)) {
textColor = ThemeUtils.getColor(view.context, R.attr.vctr_notice_secondary)
}
messageFileAvText.isVisible = true
messageFileAvText.setCompoundDrawables(null, null, null, null)
}
}

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import android.view.View
import android.view.ViewGroup
import android.widget.ImageButton
import android.widget.TextView
import androidx.core.content.ContextCompat
import androidx.core.view.doOnPreDraw
import androidx.core.view.isVisible
import com.airbnb.epoxy.EpoxyAttribute
Expand All @@ -32,10 +33,13 @@ import im.vector.app.R
import im.vector.app.core.epoxy.ClickListener
import im.vector.app.features.home.room.detail.timeline.helper.AudioMessagePlaybackTracker
import im.vector.app.features.home.room.detail.timeline.helper.ContentDownloadStateTrackerBinder
import im.vector.app.features.home.room.detail.timeline.helper.ContentScannerStateTracker
import im.vector.app.features.home.room.detail.timeline.helper.ContentUploadStateTrackerBinder
import im.vector.app.features.home.room.detail.timeline.style.TimelineMessageLayout
import im.vector.app.features.themes.ThemeUtils
import im.vector.app.features.voice.AudioWaveformView
import me.gujun.android.span.span
import org.matrix.android.sdk.api.session.crypto.attachments.ElementToDecrypt

@EpoxyModelClass
abstract class MessageVoiceItem : AbsMessageItem<MessageVoiceItem.Holder>() {
Expand Down Expand Up @@ -73,6 +77,12 @@ abstract class MessageVoiceItem : AbsMessageItem<MessageVoiceItem.Holder>() {
@EpoxyAttribute
lateinit var audioMessagePlaybackTracker: AudioMessagePlaybackTracker

@EpoxyAttribute
var contentScannerStateTracker: ContentScannerStateTracker? = null

@EpoxyAttribute
var elementToDecrypt: ElementToDecrypt? = null

override fun bind(holder: Holder) {
super.bind(holder)
renderSendState(holder.voiceLayout, null)
Expand All @@ -94,6 +104,9 @@ abstract class MessageVoiceItem : AbsMessageItem<MessageVoiceItem.Holder>() {
ThemeUtils.getColor(holder.view.context, R.attr.vctr_content_quinary)
}
holder.voicePlaybackLayout.backgroundTintList = ColorStateList.valueOf(backgroundTint)

holder.resetAV()
contentScannerStateTracker?.bind(attributes.informationData.eventId, mxcUrl, elementToDecrypt, holder)
}

private fun onWaveformViewReady(holder: Holder) {
Expand Down Expand Up @@ -169,13 +182,54 @@ abstract class MessageVoiceItem : AbsMessageItem<MessageVoiceItem.Holder>() {

override fun getViewStubId() = STUB_ID

class Holder : AbsMessageItem.Holder(STUB_ID) {
class Holder : AbsMessageItem.Holder(STUB_ID), ScannableHolder {
val voicePlaybackLayout by bind<View>(R.id.voicePlaybackLayout)
val voiceLayout by bind<ViewGroup>(R.id.voiceLayout)
val voicePlaybackControlButton by bind<ImageButton>(R.id.voicePlaybackControlButton)
val voicePlaybackTime by bind<TextView>(R.id.voicePlaybackTime)
val voicePlaybackWaveform by bind<AudioWaveformView>(R.id.voicePlaybackWaveform)
val progressLayout by bind<ViewGroup>(R.id.messageFileUploadProgressLayout)

private val messageFileAvText by bind<TextView>(R.id.messageFileAvText)

fun resetAV() {
messageFileAvText.isVisible = false
}

override fun mediaScanResult(clean: Boolean) {
if (clean) {
messageFileAvText.text = view.context.getText(R.string.antivirus_clean)
messageFileAvText.isVisible = true
messageFileAvText.setCompoundDrawablesWithIntrinsicBounds(
ContextCompat.getDrawable(view.context, R.drawable.ic_av_checked),
null,
null,
null
)
} else {
// disable click on infected files
voicePlaybackWaveform.setOnTouchListener(null)
voicePlaybackWaveform.setOnLongClickListener(null)
voicePlaybackControlButton.setOnClickListener(null)

voicePlaybackControlButton.setImageResource(R.drawable.ic_cross)
voicePlaybackControlButton.contentDescription = view.context.getString(R.string.tchap_scan_media_error_file_is_infected)

messageFileAvText.text = span(view.context.getText(R.string.antivirus_infected)) {
textColor = ThemeUtils.getColor(view.context, R.attr.colorError)
}
messageFileAvText.isVisible = true
messageFileAvText.setCompoundDrawables(null, null, null, null)
}
}

override fun mediaScanInProgress() {
messageFileAvText.text = span(view.context.getText(R.string.antivirus_in_progress)) {
textColor = ThemeUtils.getColor(view.context, R.attr.vctr_notice_secondary)
}
messageFileAvText.isVisible = true
messageFileAvText.setCompoundDrawables(null, null, null, null)
}
}

companion object {
Expand Down
12 changes: 11 additions & 1 deletion vector/src/main/res/layout/item_timeline_event_audio_stub.xml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,16 @@

</androidx.constraintlayout.widget.ConstraintLayout>

<TextView
android:id="@+id/messageFileAvText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawablePadding="4dp"
android:visibility="gone"
tools:drawableLeft="@drawable/ic_av_checked"
tools:text="@string/antivirus_infected"
tools:visibility="visible" />

<include
android:id="@+id/messageFileUploadProgressLayout"
layout="@layout/media_upload_download_progress_layout"
Expand All @@ -104,4 +114,4 @@
android:visibility="gone"
tools:visibility="visible" />

</LinearLayout>
</LinearLayout>
10 changes: 10 additions & 0 deletions vector/src/main/res/layout/item_timeline_event_voice_stub.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,16 @@

</androidx.constraintlayout.widget.ConstraintLayout>

<TextView
android:id="@+id/messageFileAvText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawablePadding="4dp"
android:visibility="gone"
tools:drawableLeft="@drawable/ic_av_checked"
tools:text="@string/antivirus_infected"
tools:visibility="visible" />

<include
android:id="@+id/messageFileUploadProgressLayout"
layout="@layout/media_upload_download_progress_layout"
Expand Down

0 comments on commit 618300b

Please sign in to comment.