-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: send and receive in-call reactions [#WPB-14254]
- Loading branch information
1 parent
bb9bd8f
commit 06392c4
Showing
19 changed files
with
588 additions
and
22 deletions.
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
data/src/commonMain/kotlin/com/wire/kalium/logic/data/call/InCallReactionMessage.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* Wire | ||
* Copyright (C) 2024 Wire Swiss GmbH | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see http://www.gnu.org/licenses/. | ||
*/ | ||
package com.wire.kalium.logic.data.call | ||
|
||
import com.wire.kalium.logic.data.id.QualifiedID | ||
|
||
data class InCallReactionMessage( | ||
val emojis: Set<String>, | ||
val senderUserId: QualifiedID, | ||
val senderUserName: String? | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
logic/src/commonMain/kotlin/com/wire/kalium/logic/data/call/InCallReactionsRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* Wire | ||
* Copyright (C) 2024 Wire Swiss GmbH | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see http://www.gnu.org/licenses/. | ||
*/ | ||
package com.wire.kalium.logic.data.call | ||
|
||
import com.wire.kalium.logic.data.user.UserId | ||
import com.wire.kalium.logic.data.user.UserRepository | ||
import com.wire.kalium.logic.functional.onSuccess | ||
import kotlinx.coroutines.channels.BufferOverflow | ||
import kotlinx.coroutines.flow.Flow | ||
import kotlinx.coroutines.flow.MutableSharedFlow | ||
import kotlinx.coroutines.flow.asSharedFlow | ||
|
||
internal interface InCallReactionsRepository { | ||
suspend fun addInCallReaction(emojis: Set<String>, senderUserId: UserId) | ||
fun observeInCallReactions(): Flow<InCallReactionMessage> | ||
} | ||
|
||
internal class InCallReactionsDataSource( | ||
private val userRepository: UserRepository, | ||
) : InCallReactionsRepository { | ||
|
||
private val inCallReactionsFlow: MutableSharedFlow<InCallReactionMessage> = | ||
MutableSharedFlow(extraBufferCapacity = BUFFER_SIZE, onBufferOverflow = BufferOverflow.DROP_OLDEST) | ||
|
||
override suspend fun addInCallReaction(emojis: Set<String>, senderUserId: UserId) { | ||
userRepository.userById(senderUserId).onSuccess { user -> | ||
inCallReactionsFlow.emit( | ||
InCallReactionMessage(emojis, senderUserId, user.name) | ||
) | ||
} | ||
} | ||
|
||
override fun observeInCallReactions(): Flow<InCallReactionMessage> = inCallReactionsFlow.asSharedFlow() | ||
|
||
private companion object { | ||
const val BUFFER_SIZE = 32 // drop after this threshold | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
...onMain/kotlin/com/wire/kalium/logic/feature/call/usecase/ObserveInCallReactionsUseCase.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Wire | ||
* Copyright (C) 2024 Wire Swiss GmbH | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see http://www.gnu.org/licenses/. | ||
*/ | ||
package com.wire.kalium.logic.feature.call.usecase | ||
|
||
import com.wire.kalium.logic.data.call.InCallReactionMessage | ||
import com.wire.kalium.logic.data.call.InCallReactionsRepository | ||
import kotlinx.coroutines.flow.Flow | ||
|
||
/** | ||
* Observe incoming in-call reactions | ||
*/ | ||
interface ObserveInCallReactionsUseCase { | ||
operator fun invoke(): Flow<InCallReactionMessage> | ||
} | ||
|
||
internal class ObserveInCallReactionsUseCaseImpl( | ||
private val inCallReactionsRepository: InCallReactionsRepository, | ||
) : ObserveInCallReactionsUseCase { | ||
|
||
override fun invoke(): Flow<InCallReactionMessage> { | ||
return inCallReactionsRepository.observeInCallReactions() | ||
} | ||
} |
Oops, something went wrong.