Skip to content

Commit

Permalink
修复传统模式下通知未归属于会话
Browse files Browse the repository at this point in the history
fix #22
  • Loading branch information
Chenhe committed Sep 22, 2021
1 parent 64eb735 commit 3af1432
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ package cc.chenhe.qqnotifyevo.core
import android.app.Notification
import android.content.Context
import android.service.notification.StatusBarNotification
import androidx.core.app.NotificationCompat
import androidx.core.app.NotificationManagerCompat
import androidx.core.content.pm.ShortcutInfoCompat
import androidx.core.content.pm.ShortcutManagerCompat
import cc.chenhe.qqnotifyevo.utils.NotifyChannel
import cc.chenhe.qqnotifyevo.utils.Tag
import timber.log.Timber
Expand Down Expand Up @@ -84,16 +87,28 @@ class InnerNotificationProcessor(
// 确保只刷新新增的通知
continue
}
notification = createConversationNotification(context, tag, channel, c, original).apply {
contentIntent = original.contentIntent
deleteIntent = original.deleteIntent
}
notification =
createConversationNotification(context, tag, channel, c, original).apply {
contentIntent = original.contentIntent
deleteIntent = original.deleteIntent
}
sendNotification(context, tag, c.name.hashCode(), notification)
commander.cancelNotification(sbn.key)
}
return notification ?: Notification() // 此处返回值没有实际意义
}

override fun buildNotification(
builder: NotificationCompat.Builder,
shortcutInfo: ShortcutInfoCompat?
): Notification {
if (shortcutInfo != null) {
ShortcutManagerCompat.pushDynamicShortcut(ctx, shortcutInfo)
builder.setShortcutId(shortcutInfo.id)
}
return builder.build()
}

private fun addNotifyId(tag: Tag, ids: Int) {
when (tag) {
Tag.QQ -> qqNotifyIds.add(ids)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import androidx.core.app.NotificationCompat
import androidx.core.app.Person
import androidx.core.content.ContextCompat
import androidx.core.content.pm.ShortcutInfoCompat
import androidx.core.content.pm.ShortcutManagerCompat
import androidx.core.graphics.drawable.IconCompat
import androidx.core.graphics.drawable.toBitmap
import cc.chenhe.qqnotifyevo.R
Expand Down Expand Up @@ -503,6 +504,14 @@ abstract class NotificationProcessor(context: Context) {
// 清除 QQ 空间特别关心动态推送历史记录
clearQzoneSpecialHistory(tag)
}
// 清除关联的 long live shortcut
// 因为 QQ 的限制,shortcut 并不能直接跳转对话框,仅用于满足 Android 11 「会话」通知的要求
// 所以保留它没有任何意义
sbn.notification.shortcutId?.also { shortcutId ->
if (shortcutId.isNotEmpty()) {
ShortcutManagerCompat.removeLongLivedShortcuts(ctx, listOf(shortcutId))
}
}
}

/**
Expand Down Expand Up @@ -617,15 +626,21 @@ abstract class NotificationProcessor(context: Context) {
builder.setContentText(text)
if (ticker != null)
builder.setTicker(ticker)
shortcutInfo?.also { builder.setShortcutInfo(it) }

setIcon(context, builder, tag, channel == NotifyChannel.QZONE)

return builder.build().apply {
return buildNotification(builder, shortcutInfo).apply {
extras.putString(NOTIFICATION_EXTRA_TAG, tag.name)
}
}

protected open fun buildNotification(
builder: NotificationCompat.Builder,
shortcutInfo: ShortcutInfoCompat?
): Notification {
return builder.build()
}

protected fun createQZoneNotification(
context: Context, tag: Tag, conversation: Conversation,
original: Notification
Expand Down

0 comments on commit 3af1432

Please sign in to comment.