feat: add first call notification
This commit is contained in:
parent
e876dc3ebd
commit
a3dfd1dd0c
|
@ -11,6 +11,7 @@ import network.loki.messenger.R
|
|||
import org.session.libsession.utilities.recipients.Recipient
|
||||
import org.thoughtcrime.securesms.calls.WebRtcCallActivity
|
||||
import org.thoughtcrime.securesms.notifications.NotificationChannels
|
||||
import org.thoughtcrime.securesms.preferences.SettingsActivity
|
||||
import org.thoughtcrime.securesms.service.WebRtcCallService
|
||||
|
||||
class CallNotificationBuilder {
|
||||
|
@ -24,6 +25,26 @@ class CallNotificationBuilder {
|
|||
const val TYPE_INCOMING_CONNECTING = 4
|
||||
const val TYPE_INCOMING_PRE_OFFER = 5
|
||||
|
||||
@JvmStatic
|
||||
fun getFirstCallNotification(context: Context): Notification {
|
||||
val contentIntent = Intent(context, SettingsActivity::class.java)
|
||||
|
||||
val pendingIntent = PendingIntent.getActivity(context, 0, contentIntent, PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE)
|
||||
|
||||
val text = context.getString(R.string.CallNotificationBuilder_first_call_message)
|
||||
|
||||
val builder = NotificationCompat.Builder(context, NotificationChannels.CALLS)
|
||||
.setSound(null)
|
||||
.setSmallIcon(R.drawable.ic_baseline_call_24)
|
||||
.setContentIntent(pendingIntent)
|
||||
.setPriority(NotificationCompat.PRIORITY_HIGH)
|
||||
.setContentTitle(context.getString(R.string.CallNotificationBuilder_first_call_title))
|
||||
.setContentText(text)
|
||||
.setStyle(NotificationCompat.BigTextStyle().bigText(text))
|
||||
|
||||
return builder.build()
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun getCallInProgressNotification(context: Context, type: Int, recipient: Recipient?): Notification {
|
||||
val contentIntent = Intent(context, WebRtcCallActivity::class.java)
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package org.thoughtcrime.securesms.webrtc
|
||||
|
||||
import android.app.NotificationManager
|
||||
import android.content.Context
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.lifecycle.Lifecycle
|
||||
|
@ -16,6 +17,7 @@ import org.session.libsession.utilities.TextSecurePreferences
|
|||
import org.session.libsignal.protos.SignalServiceProtos.CallMessage.Type.*
|
||||
import org.session.libsignal.utilities.Log
|
||||
import org.thoughtcrime.securesms.service.WebRtcCallService
|
||||
import org.thoughtcrime.securesms.util.CallNotificationBuilder
|
||||
import org.webrtc.IceCandidate
|
||||
|
||||
|
||||
|
@ -31,6 +33,11 @@ class CallMessageProcessor(private val context: Context, lifecycle: Lifecycle, p
|
|||
if (nextMessage.type != PRE_OFFER) continue
|
||||
val sentTimestamp = nextMessage.sentTimestamp ?: continue
|
||||
val sender = nextMessage.sender ?: continue
|
||||
if (TextSecurePreferences.setShownCallNotification(context)) {
|
||||
// first time call notification encountered
|
||||
val notification = CallNotificationBuilder.getFirstCallNotification(context)
|
||||
context.getSystemService(NotificationManager::class.java).notify(CallNotificationBuilder.WEBRTC_NOTIFICATION, notification)
|
||||
}
|
||||
insertMissedCall(sender, sentTimestamp)
|
||||
continue
|
||||
}
|
||||
|
|
|
@ -917,5 +917,7 @@
|
|||
<string name="preferences__allow_access_voice_video">Allow access to accept voice and video calls from other users</string>
|
||||
<string name="dialog_voice_video_title">Voice / video calls</string>
|
||||
<string name="dialog_voice_video_message">The current implementation of voice / video calls will expose your IP address to the Oxen Foundation servers and the calling / called user</string>
|
||||
<string name="CallNotificationBuilder_first_call_title">Call Missed</string>
|
||||
<string name="CallNotificationBuilder_first_call_message">You missed a call because you need to enable the \'Voice and video calls\' permission in the Privacy Settings.</string>
|
||||
|
||||
</resources>
|
||||
|
|
|
@ -90,7 +90,8 @@ object TextSecurePreferences {
|
|||
private const val LAST_PROFILE_UPDATE_TIME = "pref_last_profile_update_time"
|
||||
private const val LAST_OPEN_DATE = "pref_last_open_date"
|
||||
const val CALL_NOTIFICATIONS_ENABLED = "pref_call_notifications_enabled"
|
||||
private const val SHOWN_CALL_WARNING = "pref_shown_call_warning"
|
||||
private const val SHOWN_CALL_WARNING = "pref_shown_call_warning" // call warning is user-facing warning of enabling calls
|
||||
private const val SHOWN_CALL_NOTIFICATION = "pref_shown_call_notification" // call notification is a promp to check privacy settings
|
||||
|
||||
@JvmStatic
|
||||
fun getLastConfigurationSyncTime(context: Context): Long {
|
||||
|
@ -744,6 +745,15 @@ object TextSecurePreferences {
|
|||
return getBooleanPreference(context, CALL_NOTIFICATIONS_ENABLED, false)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun setShownCallNotification(context: Context): Boolean {
|
||||
val previousValue = getBooleanPreference(context, SHOWN_CALL_NOTIFICATION, false)
|
||||
if (previousValue) return false
|
||||
val setValue = true
|
||||
setBooleanPreference(context, SHOWN_CALL_NOTIFICATION, setValue)
|
||||
return previousValue != setValue
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the SHOWN_CALL_WARNING preference to `true`
|
||||
|
|
Loading…
Reference in New Issue