mirror of
https://gitlab.linphone.org/BC/public/linphone-android.git
synced 2026-01-17 11:28:06 +00:00
Fixed & improved a few things related to chat
This commit is contained in:
parent
f5d141d59f
commit
58ec0e7abb
7 changed files with 47 additions and 55 deletions
|
|
@ -42,11 +42,6 @@ import androidx.core.app.Person
|
|||
import androidx.core.app.RemoteInput
|
||||
import androidx.core.content.LocusIdCompat
|
||||
import androidx.navigation.NavDeepLinkBuilder
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.SupervisorJob
|
||||
import kotlinx.coroutines.async
|
||||
import kotlinx.coroutines.launch
|
||||
import org.linphone.LinphoneApplication.Companion.coreContext
|
||||
import org.linphone.LinphoneApplication.Companion.corePreferences
|
||||
import org.linphone.R
|
||||
|
|
@ -94,8 +89,6 @@ class NotificationsManager @MainThread constructor(private val context: Context)
|
|||
private const val MISSED_CALL_ID = 10
|
||||
}
|
||||
|
||||
private val scope = CoroutineScope(Dispatchers.IO + SupervisorJob())
|
||||
|
||||
private val notificationManager: NotificationManagerCompat by lazy {
|
||||
NotificationManagerCompat.from(context)
|
||||
}
|
||||
|
|
@ -152,7 +145,7 @@ class NotificationsManager @MainThread constructor(private val context: Context)
|
|||
Log.i("$TAG Received ${messages.size} aggregated messages")
|
||||
if (corePreferences.disableChat) return
|
||||
|
||||
val id = LinphoneUtils.getChatRoomId(chatRoom.localAddress, chatRoom.peerAddress)
|
||||
val id = LinphoneUtils.getChatRoomId(chatRoom)
|
||||
if (id == currentlyDisplayedChatRoomId) {
|
||||
Log.i(
|
||||
"$TAG Do not notify received messages for currently displayed conversation [$id]"
|
||||
|
|
@ -172,13 +165,8 @@ class NotificationsManager @MainThread constructor(private val context: Context)
|
|||
Log.i(
|
||||
"$TAG Ensure conversation shortcut exists for notification"
|
||||
)
|
||||
scope.launch {
|
||||
val shortcuts = async {
|
||||
ShortcutUtils.createShortcutsToChatRooms(context)
|
||||
}
|
||||
shortcuts.await()
|
||||
showChatRoomNotification(chatRoom, messages)
|
||||
}
|
||||
ShortcutUtils.createShortcutsToChatRooms(context)
|
||||
showChatRoomNotification(chatRoom, messages)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -199,7 +187,7 @@ class NotificationsManager @MainThread constructor(private val context: Context)
|
|||
)
|
||||
if (corePreferences.disableChat) return
|
||||
|
||||
val id = LinphoneUtils.getChatRoomId(chatRoom.localAddress, chatRoom.peerAddress)
|
||||
val id = LinphoneUtils.getChatRoomId(chatRoom)
|
||||
if (id == currentlyDisplayedChatRoomId) {
|
||||
Log.i(
|
||||
"$TAG Do not notify received reaction for currently displayed conversation [$id]"
|
||||
|
|
@ -234,7 +222,7 @@ class NotificationsManager @MainThread constructor(private val context: Context)
|
|||
if (corePreferences.disableChat) return
|
||||
|
||||
if (chatRoom.muted) {
|
||||
val id = LinphoneUtils.getChatRoomId(chatRoom.localAddress, chatRoom.peerAddress)
|
||||
val id = LinphoneUtils.getChatRoomId(chatRoom)
|
||||
Log.i("$TAG Conversation $id has been muted")
|
||||
return
|
||||
}
|
||||
|
|
@ -384,9 +372,7 @@ class NotificationsManager @MainThread constructor(private val context: Context)
|
|||
Log.i("$TAG Core has been started")
|
||||
core.addListener(coreListener)
|
||||
|
||||
scope.launch {
|
||||
ShortcutUtils.createShortcutsToChatRooms(context)
|
||||
}
|
||||
ShortcutUtils.createShortcutsToChatRooms(context)
|
||||
}
|
||||
|
||||
@WorkerThread
|
||||
|
|
@ -512,6 +498,7 @@ class NotificationsManager @MainThread constructor(private val context: Context)
|
|||
}
|
||||
}
|
||||
|
||||
@WorkerThread
|
||||
private fun getNotifiableForRoom(chatRoom: ChatRoom): Notifiable {
|
||||
val address = chatRoom.peerAddress.asStringUriOnly()
|
||||
var notifiable: Notifiable? = chatNotificationsMap[address]
|
||||
|
|
@ -521,14 +508,14 @@ class NotificationsManager @MainThread constructor(private val context: Context)
|
|||
notifiable.localIdentity = chatRoom.localAddress.asStringUriOnly()
|
||||
notifiable.remoteAddress = chatRoom.peerAddress.asStringUriOnly()
|
||||
|
||||
chatNotificationsMap[address] = notifiable
|
||||
|
||||
if (chatRoom.hasCapability(ChatRoom.Capabilities.OneToOne.toInt())) {
|
||||
notifiable.isGroup = false
|
||||
} else {
|
||||
notifiable.isGroup = true
|
||||
notifiable.groupTitle = chatRoom.subject
|
||||
}
|
||||
|
||||
chatNotificationsMap[address] = notifiable
|
||||
}
|
||||
return notifiable
|
||||
}
|
||||
|
|
@ -545,11 +532,14 @@ class NotificationsManager @MainThread constructor(private val context: Context)
|
|||
updated = true
|
||||
}
|
||||
|
||||
if (chatRoom.hasCapability(ChatRoom.Capabilities.OneToOne.toInt())) {
|
||||
notifiable.isGroup = false
|
||||
} else {
|
||||
notifiable.isGroup = true
|
||||
notifiable.groupTitle = chatRoom.subject
|
||||
if (!chatRoom.hasCapability(ChatRoom.Capabilities.OneToOne.toInt())) {
|
||||
if (chatRoom.subject != notifiable.groupTitle) {
|
||||
Log.i(
|
||||
"$TAG Updating notification subject from [${notifiable.groupTitle}] to [${chatRoom.subject}]"
|
||||
)
|
||||
notifiable.groupTitle = chatRoom.subject
|
||||
updated = true
|
||||
}
|
||||
}
|
||||
if (!updated) {
|
||||
Log.w("$TAG No changes made to notifiable, do not display it again")
|
||||
|
|
|
|||
|
|
@ -48,14 +48,14 @@ class MessageBottomSheetAdapter : ListAdapter<MessageBottomSheetParticipantModel
|
|||
oldItem: MessageBottomSheetParticipantModel,
|
||||
newItem: MessageBottomSheetParticipantModel
|
||||
): Boolean {
|
||||
return oldItem.sipUri == newItem.sipUri && oldItem.value == newItem.value
|
||||
return oldItem.sipUri == newItem.sipUri
|
||||
}
|
||||
|
||||
override fun areContentsTheSame(
|
||||
oldItem: MessageBottomSheetParticipantModel,
|
||||
newItem: MessageBottomSheetParticipantModel
|
||||
): Boolean {
|
||||
return true
|
||||
return oldItem.value == newItem.value
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -81,16 +81,11 @@ class ConversationsListFragment : AbstractTopBarFragment() {
|
|||
listViewModel.applyFilter()
|
||||
}
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
adapter = ConversationsListAdapter()
|
||||
}
|
||||
|
||||
override fun onCreateAnimation(transit: Int, enter: Boolean, nextAnim: Int): Animation? {
|
||||
if (
|
||||
findNavController().currentDestination?.id == R.id.startConversationFragment ||
|
||||
findNavController().currentDestination?.id == R.id.meetingWaitingRoomFragment
|
||||
findNavController().currentDestination?.id == R.id.meetingWaitingRoomFragment ||
|
||||
findNavController().currentDestination?.id == R.id.fileViewerFragment
|
||||
) {
|
||||
// Holds fragment in place while new fragment slides over it
|
||||
return AnimationUtils.loadAnimation(activity, R.anim.hold)
|
||||
|
|
@ -98,6 +93,12 @@ class ConversationsListFragment : AbstractTopBarFragment() {
|
|||
return super.onCreateAnimation(transit, enter, nextAnim)
|
||||
}
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
adapter = ConversationsListAdapter()
|
||||
}
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater,
|
||||
container: ViewGroup?,
|
||||
|
|
|
|||
|
|
@ -89,15 +89,6 @@ class MessageDeliveryModel @WorkerThread constructor(
|
|||
)
|
||||
)
|
||||
}
|
||||
if (!chatMessage.isOutgoing) {
|
||||
// Always add ourselves to prevent empty list
|
||||
displayedModels.add(
|
||||
MessageBottomSheetParticipantModel(
|
||||
chatMessage.localAddress,
|
||||
TimestampUtils.toString(chatMessage.time)
|
||||
)
|
||||
)
|
||||
}
|
||||
val readCount = displayedModels.size.toString()
|
||||
readLabel.postValue(
|
||||
AppUtils.getFormattedString(
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ class ShortcutUtils {
|
|||
}
|
||||
|
||||
@WorkerThread
|
||||
suspend fun createShortcutsToChatRooms(context: Context) {
|
||||
fun createShortcutsToChatRooms(context: Context) {
|
||||
if (ShortcutManagerCompat.isRateLimitingActive(context)) {
|
||||
Log.e("$TAG Rate limiting is active, aborting")
|
||||
return
|
||||
|
|
@ -74,7 +74,7 @@ class ShortcutUtils {
|
|||
}
|
||||
|
||||
@WorkerThread
|
||||
private suspend fun createChatRoomShortcut(context: Context, chatRoom: ChatRoom): ShortcutInfoCompat? {
|
||||
private fun createChatRoomShortcut(context: Context, chatRoom: ChatRoom): ShortcutInfoCompat? {
|
||||
val localAddress = chatRoom.localAddress
|
||||
val peerAddress = chatRoom.peerAddress
|
||||
val id = LinphoneUtils.getChatRoomId(localAddress, peerAddress)
|
||||
|
|
@ -85,8 +85,10 @@ class ShortcutUtils {
|
|||
|
||||
val personsList = arrayListOf<Person>()
|
||||
val subject: String
|
||||
val icon: IconCompat
|
||||
if (chatRoom.hasCapability(ChatRoom.Capabilities.Basic.toInt())) {
|
||||
val icon: IconCompat = if (chatRoom.hasCapability(
|
||||
ChatRoom.Capabilities.Basic.toInt()
|
||||
)
|
||||
) {
|
||||
val contact =
|
||||
coreContext.contactsManager.findContactByAddress(peerAddress)
|
||||
val person = contact?.getPerson()
|
||||
|
|
@ -95,7 +97,7 @@ class ShortcutUtils {
|
|||
}
|
||||
|
||||
subject = contact?.name ?: LinphoneUtils.getDisplayName(peerAddress)
|
||||
icon = person?.icon ?: AvatarGenerator(context).setInitials(
|
||||
person?.icon ?: AvatarGenerator(context).setInitials(
|
||||
AppUtils.getInitials(subject)
|
||||
).buildIcon()
|
||||
} else if (chatRoom.hasCapability(ChatRoom.Capabilities.OneToOne.toInt()) && chatRoom.participants.isNotEmpty()) {
|
||||
|
|
@ -108,11 +110,14 @@ class ShortcutUtils {
|
|||
}
|
||||
|
||||
subject = contact?.name ?: LinphoneUtils.getDisplayName(address)
|
||||
icon = person?.icon ?: AvatarGenerator(context).setInitials(
|
||||
person?.icon ?: AvatarGenerator(context).setInitials(
|
||||
AppUtils.getInitials(subject)
|
||||
).buildIcon()
|
||||
} else {
|
||||
val list = arrayListOf<String>()
|
||||
subject = chatRoom.subject.orEmpty()
|
||||
IconCompat.createWithResource(context, R.drawable.users_three)
|
||||
// TODO FIXME: use generated chat room avatar
|
||||
/*val list = arrayListOf<String>()
|
||||
for (participant in chatRoom.participants) {
|
||||
val contact =
|
||||
coreContext.contactsManager.findContactByAddress(participant.address)
|
||||
|
|
@ -125,15 +130,16 @@ class ShortcutUtils {
|
|||
}
|
||||
}
|
||||
}
|
||||
subject = chatRoom.subject.orEmpty()
|
||||
icon = if (list.isNotEmpty()) {
|
||||
AvatarGenerator(context).setInitials(subject).buildIcon()
|
||||
if (list.isNotEmpty()) {
|
||||
val iconSize = AppUtils.getDimension(R.dimen.avatar_list_cell_size).toInt()
|
||||
|
||||
IconCompat.createWithAdaptiveBitmap(
|
||||
ImageUtils.getBitmapFromMultipleAvatars(context, iconSize, list)
|
||||
)
|
||||
} else {
|
||||
AvatarGenerator(context).setInitials(subject).buildIcon()
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
val persons = arrayOfNulls<Person>(personsList.size)
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@
|
|||
<action
|
||||
android:id="@+id/action_conversationFragment_to_conversationInfoFragment"
|
||||
app:destination="@id/conversationInfoFragment"
|
||||
app:launchSingleTop="true"
|
||||
app:enterAnim="@anim/slide_in_right"
|
||||
app:exitAnim="@anim/slide_out_left"
|
||||
app:popEnterAnim="@anim/slide_in_left"
|
||||
|
|
@ -50,6 +51,7 @@
|
|||
<action
|
||||
android:id="@+id/action_conversationInfoFragment_to_addParticipantsFragment"
|
||||
app:destination="@id/addParticipantsFragment"
|
||||
app:launchSingleTop="true"
|
||||
app:enterAnim="@anim/slide_in_right"
|
||||
app:exitAnim="@anim/slide_out_left"
|
||||
app:popEnterAnim="@anim/slide_in_left"
|
||||
|
|
@ -57,6 +59,7 @@
|
|||
<action
|
||||
android:id="@+id/action_conversationInfoFragment_to_conversationEphemeralLifetimeFragment"
|
||||
app:destination="@id/conversationEphemeralLifetimeFragment"
|
||||
app:launchSingleTop="true"
|
||||
app:enterAnim="@anim/slide_in_right"
|
||||
app:exitAnim="@anim/slide_out_left"
|
||||
app:popEnterAnim="@anim/slide_in_left"
|
||||
|
|
|
|||
|
|
@ -188,6 +188,7 @@
|
|||
<action
|
||||
android:id="@+id/action_debugFragment_to_conversationsListFragment"
|
||||
app:destination="@id/conversationsListFragment"
|
||||
app:launchSingleTop="true"
|
||||
app:popUpTo="@id/helpFragment"
|
||||
app:popUpToInclusive="true"/>
|
||||
</fragment>
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue