PR Review

This commit is contained in:
Benoit Marty 2020-12-15 10:21:12 +01:00
parent 7da8b13cde
commit 6957768567
4 changed files with 100 additions and 112 deletions

View File

@ -35,7 +35,7 @@ enum class ChatEffect {
* It also manages effect duration and some cool down, for example if an effect is currently playing,
* any other trigger will be ignored
* For now it uses visibility callback to check for an effect (that means that a fail to decrypt event - more
* precisly an event decrypted with a few delay won't trigger an effect; it's acceptable)
* precisely an event decrypted with a few delay won't trigger an effect; it's acceptable)
* Events that are more that 10s old won't trigger effects
*/
class ChatEffectManager @Inject constructor() {
@ -50,7 +50,7 @@ class ChatEffectManager @Inject constructor() {
private var stopTimer: Timer? = null
// an in memory store to avoid trigger twice for an event (quick close/open timeline)
private val alreadyPlayed = emptyList<String>().toMutableList()
private val alreadyPlayed = mutableListOf<String>()
fun checkForEffect(event: TimelineEvent) {
val age = event.root.ageLocalTs ?: 0
@ -80,7 +80,6 @@ class ChatEffectManager @Inject constructor() {
fun dispose() {
stopTimer?.cancel()
stopTimer = null
delegate = null
alreadyPlayed.clear()
}
@ -98,7 +97,7 @@ class ChatEffectManager @Inject constructor() {
}
}
private fun hasAlreadyPlayed(event: TimelineEvent) : Boolean {
private fun hasAlreadyPlayed(event: TimelineEvent): Boolean {
return alreadyPlayed.contains(event.eventId)
|| (event.root.unsignedData?.transactionId?.let { alreadyPlayed.contains(it) } ?: false)
}
@ -107,19 +106,29 @@ class ChatEffectManager @Inject constructor() {
return when (content.msgType) {
MessageType.MSGTYPE_CONFETTI -> ChatEffect.CONFETTI
MessageType.MSGTYPE_SNOW -> ChatEffect.SNOW
MessageType.MSGTYPE_TEXT -> {
val text = event.root.getClearContent().toModel<MessageContent>()?.body ?: ""
if (text.contains("🎉")
|| text.contains("🎊")) {
ChatEffect.CONFETTI
} else if (text.contains("⛄️")
|| text.contains("☃️")
|| text.contains("❄️")) {
ChatEffect.SNOW
} else null
event.root.getClearContent().toModel<MessageContent>()?.body
?.let { text ->
when {
EMOJIS_FOR_CONFETTI.any { text.contains(it) } -> ChatEffect.CONFETTI
EMOJIS_FOR_SNOW.any { text.contains(it) } -> ChatEffect.SNOW
else -> null
}
}
}
else -> null
}
}
companion object {
private val EMOJIS_FOR_CONFETTI = listOf(
"🎉",
"🎊"
)
private val EMOJIS_FOR_SNOW = listOf(
"⛄️",
"☃️",
"❄️"
)
}
}

View File

@ -998,14 +998,7 @@ class RoomDetailViewModel @AssistedInject constructor(
}
override fun shouldStartEffect(effect: ChatEffect) {
when (effect) {
ChatEffect.CONFETTI -> {
_viewEvents.post(RoomDetailViewEvents.StartChatEffect(ChatEffect.CONFETTI))
}
ChatEffect.SNOW -> {
_viewEvents.post(RoomDetailViewEvents.StartChatEffect(ChatEffect.SNOW))
}
}
_viewEvents.post(RoomDetailViewEvents.StartChatEffect(effect))
}
override fun stopEffects() {
@ -1413,6 +1406,7 @@ class RoomDetailViewModel @AssistedInject constructor(
if (vectorPreferences.sendTypingNotifs()) {
room.userStopsTyping()
}
chatEffectManager.delegate = null
chatEffectManager.dispose()
super.onCleared()
}

View File

@ -1,13 +0,0 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="106dp"
android:height="106dp"
android:viewportWidth="106"
android:viewportHeight="106">
<path
android:pathData="M53,53m-52,0a52,52 0,1 1,104 0a52,52 0,1 1,-104 0"
android:strokeAlpha="0.5168103"
android:strokeWidth="1"
android:fillColor="#FFFFFF"
android:strokeColor="#979797"
android:fillType="evenOdd"/>
</vector>

View File

@ -6,21 +6,6 @@
android:layout_width="match_parent"
android:layout_height="match_parent">
<nl.dionsegijn.konfetti.KonfettiView
android:id="@+id/viewKonfetti"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:elevation="4dp"
android:visibility="invisible" />
<com.jetradarmobile.snowfall.SnowfallView
android:id="@+id/viewSnowFall"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?vctr_chat_effect_snow_background"
android:elevation="4dp"
android:visibility="invisible" />
<androidx.appcompat.widget.Toolbar
android:id="@+id/roomToolbar"
style="@style/VectorToolbarStyle"
@ -240,4 +225,17 @@
app:maxImageSize="16dp"
app:tint="@color/black" />
<nl.dionsegijn.konfetti.KonfettiView
android:id="@+id/viewKonfetti"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="invisible" />
<com.jetradarmobile.snowfall.SnowfallView
android:id="@+id/viewSnowFall"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?vctr_chat_effect_snow_background"
android:visibility="invisible" />
</androidx.constraintlayout.widget.ConstraintLayout>