Using new chatRoom muted API from SDK
This commit is contained in:
parent
c1db11beaf
commit
4fd1241589
5 changed files with 48 additions and 38 deletions
|
@ -28,7 +28,6 @@ import kotlinx.coroutines.Dispatchers
|
|||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
import org.linphone.LinphoneApplication.Companion.coreContext
|
||||
import org.linphone.LinphoneApplication.Companion.corePreferences
|
||||
import org.linphone.R
|
||||
import org.linphone.contact.ContactDataInterface
|
||||
import org.linphone.contact.ContactsUpdatedListenerStub
|
||||
|
@ -273,6 +272,6 @@ class ChatRoomData(val chatRoom: ChatRoom) : ContactDataInterface {
|
|||
}
|
||||
|
||||
private fun areNotificationsMuted(): Boolean {
|
||||
return corePreferences.chatRoomMuted(id)
|
||||
return chatRoom.muted
|
||||
}
|
||||
}
|
||||
|
|
|
@ -285,13 +285,11 @@ class ChatRoomViewModel(val chatRoom: ChatRoom) : ViewModel(), ContactDataInterf
|
|||
}
|
||||
|
||||
fun areNotificationsMuted(): Boolean {
|
||||
val id = LinphoneUtils.getChatRoomId(chatRoom.localAddress, chatRoom.peerAddress)
|
||||
return corePreferences.chatRoomMuted(id)
|
||||
return chatRoom.muted
|
||||
}
|
||||
|
||||
fun muteNotifications(mute: Boolean) {
|
||||
val id = LinphoneUtils.getChatRoomId(chatRoom.localAddress, chatRoom.peerAddress)
|
||||
corePreferences.muteChatRoom(id, mute)
|
||||
chatRoom.muted = mute
|
||||
}
|
||||
|
||||
fun getRemoteAddress(): Address? {
|
||||
|
|
|
@ -481,6 +481,35 @@ class CoreContext(
|
|||
|
||||
computeUserAgent()
|
||||
|
||||
val fiveTwoMigrationRequired = core.config.getBool("app", "migration_5.2_required", true)
|
||||
if (fiveTwoMigrationRequired) {
|
||||
Log.i(
|
||||
"[Context] Starting migration of muted chat room from shared preferences to our SDK"
|
||||
)
|
||||
val sharedPreferences: SharedPreferences = context.getSharedPreferences(
|
||||
"notifications",
|
||||
Context.MODE_PRIVATE
|
||||
)
|
||||
val editor = sharedPreferences.edit()
|
||||
|
||||
for (chatRoom in core.chatRooms) {
|
||||
val id = LinphoneUtils.getChatRoomId(chatRoom)
|
||||
if (sharedPreferences.getBoolean(id, false)) {
|
||||
Log.i("[Context] Migrating muted flag for chat room [$id]")
|
||||
chatRoom.muted = true
|
||||
editor.remove(id)
|
||||
}
|
||||
}
|
||||
|
||||
editor.apply()
|
||||
core.config.setBool(
|
||||
"app",
|
||||
"migration_5.2_required",
|
||||
false
|
||||
)
|
||||
Log.i("[Context] Migration of muted chat room finished")
|
||||
}
|
||||
|
||||
val fiveOneMigrationRequired = core.config.getBool("app", "migration_5.1_required", true)
|
||||
if (fiveOneMigrationRequired) {
|
||||
core.config.setBool(
|
||||
|
|
|
@ -91,24 +91,6 @@ class CorePreferences constructor(private val context: Context) {
|
|||
// logcatLogsOutput = false
|
||||
}
|
||||
|
||||
fun chatRoomMuted(id: String): Boolean {
|
||||
val sharedPreferences: SharedPreferences = coreContext.context.getSharedPreferences(
|
||||
"notifications",
|
||||
Context.MODE_PRIVATE
|
||||
)
|
||||
return sharedPreferences.getBoolean(id, false)
|
||||
}
|
||||
|
||||
fun muteChatRoom(id: String, mute: Boolean) {
|
||||
val sharedPreferences: SharedPreferences = coreContext.context.getSharedPreferences(
|
||||
"notifications",
|
||||
Context.MODE_PRIVATE
|
||||
)
|
||||
val editor = sharedPreferences.edit()
|
||||
editor.putBoolean(id, mute)
|
||||
editor.apply()
|
||||
}
|
||||
|
||||
/* App settings */
|
||||
|
||||
var debugLogs: Boolean
|
||||
|
|
|
@ -161,9 +161,8 @@ class NotificationsManager(private val context: Context) {
|
|||
return
|
||||
}
|
||||
|
||||
val id = LinphoneUtils.getChatRoomId(room.localAddress, room.peerAddress)
|
||||
val mute = corePreferences.chatRoomMuted(id)
|
||||
if (mute) {
|
||||
if (room.muted) {
|
||||
val id = LinphoneUtils.getChatRoomId(room.localAddress, room.peerAddress)
|
||||
Log.i("[Notifications Manager] Chat room $id has been muted")
|
||||
return
|
||||
}
|
||||
|
@ -179,14 +178,6 @@ class NotificationsManager(private val context: Context) {
|
|||
}
|
||||
}
|
||||
|
||||
var allOutgoing = true
|
||||
for (message in messages) {
|
||||
if (!message.isOutgoing) {
|
||||
allOutgoing = false
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
val notifiable = getNotifiableForRoom(room)
|
||||
val updated = updateChatNotifiableWithMessages(notifiable, room, messages)
|
||||
if (!updated) {
|
||||
|
@ -205,6 +196,18 @@ class NotificationsManager(private val context: Context) {
|
|||
}
|
||||
}
|
||||
|
||||
override fun onReactionRemoved(
|
||||
core: Core,
|
||||
chatRoom: ChatRoom,
|
||||
message: ChatMessage,
|
||||
address: Address
|
||||
) {
|
||||
Log.i(
|
||||
"[Notifications Manager] [${address.asStringUriOnly()}] removed it's previously sent reaction for chat message [$message]"
|
||||
// TODO: remove notification if any
|
||||
)
|
||||
}
|
||||
|
||||
override fun onNewMessageReaction(
|
||||
core: Core,
|
||||
chatRoom: ChatRoom,
|
||||
|
@ -234,9 +237,8 @@ class NotificationsManager(private val context: Context) {
|
|||
return
|
||||
}
|
||||
|
||||
val id = LinphoneUtils.getChatRoomId(chatRoom.localAddress, chatRoom.peerAddress)
|
||||
val mute = corePreferences.chatRoomMuted(id)
|
||||
if (mute) {
|
||||
if (chatRoom.muted) {
|
||||
val id = LinphoneUtils.getChatRoomId(chatRoom.localAddress, chatRoom.peerAddress)
|
||||
Log.i("[Notifications Manager] Chat room $id has been muted")
|
||||
return
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue