Skip to content
Snippets Groups Projects
Commit ef7787d5 authored by Vitalii Nikitchyn's avatar Vitalii Nikitchyn
Browse files

notification: contact request to not active account fixes

GitLab: #1259
Change-Id: I760a36b66cfc1cd8d3e60174925efe5f300c40c5
parent 6344e54f
Branches
Tags
No related merge requests found
......@@ -36,7 +36,6 @@ import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentTransaction
import androidx.lifecycle.ViewModelProvider
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import cx.ring.BuildConfig
import cx.ring.R
import cx.ring.about.AboutFragment
import cx.ring.account.AccountEditionFragment
......@@ -216,14 +215,20 @@ class HomeActivity : AppCompatActivity(), ContactPickerFragment.OnContactedPicke
private fun handleIntent(intent: Intent) {
Log.d(TAG, "handleIntent: $intent")
val extra = intent.extras
val action = intent.action
when (action) {
ACTION_PRESENT_TRUST_REQUEST_FRAGMENT ->
presentTrustRequestFragment(extra?.getString(AccountEditionFragment.ACCOUNT_ID_KEY) ?: return)
Intent.ACTION_SEND,
Intent.ACTION_SEND_MULTIPLE -> {
val path = ConversationPath.fromBundle(extra)
when (intent.action) {
NotificationService.NOTIF_TRUST_REQUEST_MULTIPLE -> {
val accountId = intent.getStringExtra(NotificationService.NOTIF_TRUST_REQUEST_ACCOUNT_ID)
// Select the current account if it's not active
if (mAccountService.currentAccount?.accountId != accountId)
mAccountService.currentAccount = mAccountService.getAccount(accountId)
mHomeFragment!!.handleIntent(intent)
}
Intent.ACTION_SEND, Intent.ACTION_SEND_MULTIPLE -> {
val path = ConversationPath.fromBundle(intent.extras)
if (path != null) {
startConversation(path, intent)
} else {
......@@ -231,17 +236,23 @@ class HomeActivity : AppCompatActivity(), ContactPickerFragment.OnContactedPicke
startActivity(intent)
}
}
Intent.ACTION_VIEW,
DRingService.ACTION_CONV_ACCEPT -> {
val path = ConversationPath.fromIntent(intent)
if (path != null)
Intent.ACTION_VIEW, DRingService.ACTION_CONV_ACCEPT -> {
val path = ConversationPath.fromUri(intent.data)
if (path != null) {
// Select the current account if it's not active
if (mAccountService.currentAccount?.accountId != path.accountId)
mAccountService.currentAccount = mAccountService.getAccount(path.accountId)
startConversation(path, intent)
}
}
if (Intent.ACTION_SEARCH == action) {
Intent.ACTION_SEARCH -> {
mHomeFragment!!.handleIntent(intent)
}
}
}
private fun showMigrationDialog() {
if (mMigrationDialog != null) {
......@@ -542,8 +553,6 @@ class HomeActivity : AppCompatActivity(), ContactPickerFragment.OnContactedPicke
const val ACCOUNTS_TAG = "Accounts"
const val ABOUT_TAG = "About"
const val SETTINGS_TAG = "Prefs"
const val ACTION_PRESENT_TRUST_REQUEST_FRAGMENT =
BuildConfig.APPLICATION_ID + "presentTrustRequestFragment"
private const val CONVERSATIONS_CATEGORY = "conversations"
private const val fragmentContainerId: Int = R.id.frame
}
......
......@@ -76,6 +76,7 @@ import cx.ring.databinding.FragHomeBinding
import cx.ring.utils.TextUtils
import cx.ring.utils.ActionHelper.openJamiDonateWebPage
import io.reactivex.rxjava3.disposables.Disposable
import net.jami.services.NotificationService
@AndroidEntryPoint
class HomeFragment: BaseSupportFragment<HomePresenter, HomeView>(),
......@@ -354,10 +355,6 @@ class HomeFragment: BaseSupportFragment<HomePresenter, HomeView>(),
height = ViewGroup.LayoutParams.MATCH_PARENT
}
val insetsCompat = ViewCompat.getRootWindowInsets(binding.invitationCard.invitationGroup) ?: return
val insets = insetsCompat.getInsets(WindowInsetsCompat.Type.systemBars())
binding.appBar.updatePadding(bottom = insets.bottom)
// Adapt the margins of the invitation card.
requireContext().resources.getDimensionPixelSize(R.dimen.bottom_sheet_radius).let {
(binding.invitationCard.invitationGroup.layoutParams as ViewGroup.MarginLayoutParams)
......@@ -379,6 +376,10 @@ class HomeFragment: BaseSupportFragment<HomePresenter, HomeView>(),
// Enable back press.
conversationBackPressedCallback.isEnabled = true
val insetsCompat = ViewCompat.getRootWindowInsets(binding.invitationCard.invitationGroup) ?: return
val insets = insetsCompat.getInsets(WindowInsetsCompat.Type.systemBars())
binding.appBar.updatePadding(bottom = insets.bottom)
}
fun collapsePendingView() {
......@@ -560,21 +561,24 @@ class HomeFragment: BaseSupportFragment<HomePresenter, HomeView>(),
}
fun handleIntent(intent: Intent) {
val searchView = mSearchView ?: return
when (intent.action) {
Intent.ACTION_CALL -> {
expandSearchActionView()
searchView.setQuery(intent.dataString, true)
mSearchView?.setQuery(intent.dataString, true)
}
Intent.ACTION_DIAL -> {
expandSearchActionView()
searchView.setQuery(intent.dataString, false)
mSearchView?.setQuery(intent.dataString, false)
}
Intent.ACTION_SEARCH -> {
expandSearchActionView()
searchView.setQuery(intent.getStringExtra(SearchManager.QUERY), true)
mSearchView?.setQuery(intent.getStringExtra(SearchManager.QUERY), true)
}
NotificationService.NOTIF_TRUST_REQUEST_MULTIPLE -> {
expandPendingView()
}
else -> {}
......
......@@ -44,7 +44,6 @@ import androidx.core.content.res.ResourcesCompat
import androidx.core.graphics.drawable.IconCompat
import com.bumptech.glide.Glide
import cx.ring.R
import cx.ring.account.AccountEditionFragment
import cx.ring.application.JamiApplication
import cx.ring.client.CallActivity
import cx.ring.client.ConversationActivity
......@@ -662,8 +661,8 @@ class NotificationServiceImpl(
mNotificationBuilders.put(notificationId, messageNotificationBuilder)
}
private fun getRequestNotificationBuilder(accountId: String): NotificationCompat.Builder {
val builder = NotificationCompat.Builder(mContext, NOTIF_CHANNEL_REQUEST)
private fun getRequestNotificationBuilder(): NotificationCompat.Builder {
return NotificationCompat.Builder(mContext, NOTIF_CHANNEL_REQUEST)
.setDefaults(NotificationCompat.DEFAULT_ALL)
.setPriority(NotificationCompat.PRIORITY_HIGH)
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
......@@ -671,13 +670,7 @@ class NotificationServiceImpl(
.setSmallIcon(R.drawable.ic_ring_logo_white)
.setCategory(NotificationCompat.CATEGORY_SOCIAL)
.setContentTitle(mContext.getString(R.string.contact_request_title))
val intentOpenTrustRequestFragment = Intent(HomeActivity.ACTION_PRESENT_TRUST_REQUEST_FRAGMENT)
.setClass(mContext, HomeActivity::class.java)
.putExtra(AccountEditionFragment.ACCOUNT_ID_KEY, accountId)
builder.setContentIntent(PendingIntent.getActivity(mContext, random.nextInt(), intentOpenTrustRequestFragment,
ContentUri.immutable(PendingIntent.FLAG_ONE_SHOT)))
builder.color = ResourcesCompat.getColor(mContext.resources, R.color.color_primary_dark, null)
return builder
.setColor(ResourcesCompat.getColor(mContext.resources, R.color.color_primary_dark, null))
}
override fun showIncomingTrustRequestNotification(account: Account) {
......@@ -695,9 +688,15 @@ class NotificationServiceImpl(
return
}
mContactService.getLoadedConversation(request).subscribe({ vm ->
val builder = getRequestNotificationBuilder(account.accountId)
mPreferencesService.saveRequestPreferences(account.accountId, contactKey)
val info = ConversationPath.toUri(account.accountId, request.uri)
val builder = getRequestNotificationBuilder()
builder.setContentIntent(PendingIntent.getActivity(mContext, random.nextInt(),
Intent(Intent.ACTION_VIEW, info, mContext, HomeActivity::class.java),
ContentUri.immutable(PendingIntent.FLAG_ONE_SHOT))
)
builder.setContentText(vm.uriTitle)
.addAction(R.drawable.baseline_person_add_24, mContext.getText(R.string.accept), PendingIntent.getService(
mContext, random.nextInt(),
......@@ -715,7 +714,7 @@ class NotificationServiceImpl(
notificationManager.notify(notificationId, builder.build())
}) { e: Throwable -> Log.w(TAG, "error showing notification", e) }
} else {
val builder = getRequestNotificationBuilder(account.accountId)
val builder = getRequestNotificationBuilder()
var newRequest = false
for (request in requests) {
val contact = request.contact
......@@ -728,6 +727,14 @@ class NotificationServiceImpl(
}
}
if (!newRequest) return
builder.setContentIntent(PendingIntent.getActivity(mContext, random.nextInt(),
Intent(mContext, HomeActivity::class.java)
.setAction(NotificationService.NOTIF_TRUST_REQUEST_MULTIPLE)
.putExtra(NotificationService.NOTIF_TRUST_REQUEST_ACCOUNT_ID, account.accountId),
ContentUri.immutable(PendingIntent.FLAG_ONE_SHOT))
)
builder.setContentText(String.format(mContext.getString(R.string.contact_request_msg), requests.size))
builder.setLargeIcon(null as Icon?)
notificationManager.notify(notificationId, builder.build())
......@@ -908,8 +915,7 @@ class NotificationServiceImpl(
}
override fun cancelTrustRequestNotification(accountID: String) {
val notificationId = getIncomingTrustNotificationId(accountID)
notificationManager.cancel(notificationId)
notificationManager.cancel(getIncomingTrustNotificationId(accountID))
}
override fun cancelCallNotification() {
......
......@@ -45,8 +45,7 @@ class ConversationFacade(
private val mPreferencesService: PreferencesService
) {
private val mDisposableBag = CompositeDisposable()
val currentAccountSubject: Observable<Account> = mAccountService
.currentAccountSubject
val currentAccountSubject: Observable<Account> = mAccountService.currentAccountSubject
.switchMapSingle { account: Account -> loadSmartlist(account) }
/**
......@@ -720,14 +719,15 @@ class ConversationFacade(
mDisposableBag.add(mCallService.confsUpdates
.observeOn(Schedulers.io())
.subscribe { conference: Conference -> onConfStateChange(conference) })
mDisposableBag.add(currentAccountSubject
.switchMap { a: Account -> a.getPendingSubject()
.doOnNext { mNotificationService.showIncomingTrustRequestNotification(a) } }
.subscribe())
mDisposableBag.add(mAccountService.incomingRequests
.concatMapSingle { r: TrustRequest -> getAccountSubject(r.accountId) }
.subscribe({ account: Account -> mNotificationService.showIncomingTrustRequestNotification(account) })
{ Log.e(TAG, "Error showing contact request") })
mDisposableBag.add(mAccountService.observableAccountList
.switchMap { accounts ->
Observable.merge(accounts.map { a -> a.getPendingSubject().map { a } })
}
.subscribe { account ->
mNotificationService.showIncomingTrustRequestNotification(account)
})
mDisposableBag.add(mAccountService
.incomingMessages
.concatMapSingle { msg: TextMessage -> getAccountSubject(msg.account!!)
......
......@@ -46,8 +46,8 @@ interface NotificationService {
fun processPush()
companion object {
const val TRUST_REQUEST_NOTIFICATION_ACCOUNT_ID = "trustRequestNotificationAccountId"
const val TRUST_REQUEST_NOTIFICATION_FROM = "trustRequestNotificationFrom"
const val NOTIF_TRUST_REQUEST_ACCOUNT_ID = "NOTIF_TRUST_REQUEST_ACCOUNT_ID"
const val NOTIF_TRUST_REQUEST_MULTIPLE = "NOTIFICATION_TRUST_REQUEST_MULTIPLE"
const val KEY_CALL_ID = "callId"
const val KEY_HOLD_ID = "holdId"
const val KEY_END_ID = "endId"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment