feat(notifications): smart replies

Signed-off-by: rhunk <101876869+rhunk@users.noreply.github.com>
This commit is contained in:
rhunk 2024-06-05 14:24:34 +02:00
parent d901cba828
commit ae15ad7ce9
3 changed files with 18 additions and 2 deletions

View File

@ -685,6 +685,10 @@
"name": "Reply Button",
"description": "Adds a reply button to the notification"
},
"smart_replies": {
"name": "Smart Replies",
"description": "Adds suggested replies to notifications (Android 10+). Use in combination with Reply Button"
},
"download_button": {
"name": "Download Button",
"description": "Allows you to download media from the notification"

View File

@ -45,6 +45,7 @@ class MessagingTweaks : ConfigContainer() {
val stackedMediaMessages = boolean("stacked_media_messages")
val friendAddSource = boolean("friend_add_source")
val replyButton = boolean("reply_button") { addNotices(FeatureNotice.UNSTABLE) }
val smartReplies = boolean("smart_replies")
val downloadButton = boolean("download_button")
val markAsReadButton = boolean("mark_as_read_button") { addNotices(FeatureNotice.UNSTABLE) }
val markAsReadAndSaveInChat = boolean("mark_as_read_and_save_in_chat") { addNotices(FeatureNotice.UNSTABLE) }

View File

@ -8,6 +8,7 @@ import android.content.Context
import android.content.Intent
import android.graphics.Bitmap
import android.graphics.BitmapFactory
import android.os.Build
import android.os.Bundle
import android.os.UserHandle
import de.robv.android.xposed.XposedBridge
@ -139,6 +140,9 @@ class Notifications : Feature("Notifications", loadParams = FeatureLoadParams.IN
.setLabel(translations["button.reply"])
.build()
it.addRemoteInput(chatReplyInput)
if (config.smartReplies.get()) {
it.setAllowGeneratedReplies(true)
}
}
newAction(translations["button.download"], ACTION_DOWNLOAD, {
@ -298,7 +302,15 @@ class Notifications : Feature("Notifications", loadParams = FeatureLoadParams.IN
}
}
notificationData.copy(id = notificationId).also {
val builder = newNotificationBuilder(notificationData.notification).apply {
setGroup(SNAPCHAT_NOTIFICATION_GROUP)
setGroupAlertBehavior(Notification.GROUP_ALERT_CHILDREN)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q && config.smartReplies.get()) {
setAllowSystemGeneratedContextualActions(true)
}
}
notificationData.copy(id = notificationId, notification = builder.build()).also {
setupNotificationActionButtons(message.messageContent!!.contentType!!, conversationId, message, it)
}.send()
}
@ -354,7 +366,6 @@ class Notifications : Feature("Notifications", loadParams = FeatureLoadParams.IN
setLargeIcon(bitmapPreview)
style = Notification.BigPictureStyle().bigPicture(bitmapPreview).bigLargeIcon(null as Bitmap?)
}
if (config.mediaCaption.get()) {
message.serialize()?.let {
notificationBuilder.setContentText(it)