Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions go/bind/keybase.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,17 @@ func log(format string, args ...interface{}) {
}
}

// CurrentUID returns the UID of the currently active account, or empty string if not logged in.
// Used by the Android push listener to gate notification actions on the active account.
func CurrentUID() string {
if kbCtx == nil {
return ""
}
return kbCtx.Env.GetUID().String()
}

type PushNotifier interface {
LocalNotification(ident string, title string, msg string, badgeCount int, soundName string, convID string, typ string)
LocalNotification(ident string, title string, msg string, badgeCount int, soundName string, convID string, typ string, uid string)
DisplayChatNotification(notification *ChatNotification)
}

Expand Down Expand Up @@ -734,7 +743,7 @@ func pushPendingMessageFailure(obrs []chat1.OutboxRecord, pusher PushNotifier) {
kbCtx.Log.Debug("pushPendingMessageFailure: pushing convID: %s", obr.ConvID)
pusher.LocalNotification("failedpending", "",
"Heads up! Your message hasn't sent yet, tap here to retry.",
-1, "default", obr.ConvID.String(), "chat.failedpending")
-1, "default", obr.ConvID.String(), "chat.failedpending", "")
return
}
}
Expand Down
5 changes: 5 additions & 0 deletions go/bind/notifications.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ type ChatNotification struct {
BadgeCount int
// Title is the notification title, e.g. "username@keybase"
Title string
// Uid is the UID of the account this notification belongs to.
// Included in the local notification's userInfo so that a notification
// tap can switch to the correct account if a different one is active.
Uid string
}

func HandlePostTextReply(strConvID, tlfName string, intMessageID int, body string) (err error) {
Expand Down Expand Up @@ -224,6 +228,7 @@ func HandleBackgroundNotification(strConvID, body, serverMessageBody, sender str
SoundName: soundName,
BadgeCount: badgeCount,
Title: title,
Uid: uid.String(),
}
kbCtx.Log.CDebugf(ctx, "HandleBackgroundNotification: title=%s", chatNotification.Title)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@ class KBPushNotifier internal constructor(private val context: Context, private
bundle.putBoolean("userInteraction", true)
bundle.putString("type", "chat.newmessage")
bundle.putString("convID", chatNotification.convID)
if (chatNotification.uid.isNotEmpty()) {
bundle.putString("uid", chatNotification.uid)
}
val pending_intent = buildPendingIntent(bundle)
val convData = ConvData(chatNotification.convID, chatNotification.tlfName ?: "", chatNotification.message.id)
val builder = NotificationCompat.Builder(context, KeybasePushNotificationListenerService.CHAT_CHANNEL_ID)
Expand Down Expand Up @@ -236,7 +239,10 @@ class KBPushNotifier internal constructor(private val context: Context, private
}

override fun localNotification(ident: String, title: String, msg: String, badgeCount: Long, soundName: String, convID: String,
typ: String) {
typ: String, uid: String) {
if (uid.isNotEmpty()) {
bundle.putString("uid", uid)
}
genericNotification(ident, title, msg, bundle, KeybasePushNotificationListenerService.GENERAL_CHANNEL_ID)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ class KeybasePushNotificationListenerService : FirebaseMessagingService() {
chatNotif.isGroupConversation = false
chatNotif.tlfName = ""
chatNotif.title = bundle.getString("title", "")
chatNotif.uid = targetUID

notifier.displayChatNotification(chatNotif)
seenChatNotifications.add(n.convID + n.messageId)
Expand Down Expand Up @@ -244,13 +245,18 @@ class KeybasePushNotificationListenerService : FirebaseMessagingService() {

"chat.readmessage" -> {
val convID = bundle.getString("c")
val targetUID = bundle.getString("i", "")
// Clear the cache of msgs for this conv id
if (msgCache.containsKey(convID)) {
msgCache[convID] = SmallMsgRingBuffer()
}
// Cancel any push notifications.
val notificationManager = NotificationManagerCompat.from(applicationContext)
notificationManager.cancelAll()
// Only cancel notifications if this read receipt is for the active
// account. A receipt from another logged-in account must not clear
// the active account's notification tray.
if (targetUID.isEmpty() || targetUID == Keybase.currentUID()) {
val notificationManager = NotificationManagerCompat.from(applicationContext)
notificationManager.cancelAll()
}
val emitBundle = bundle.clone() as Bundle
KbModule.emitPushNotification(emitBundle)
}
Expand Down
2 changes: 2 additions & 0 deletions shared/constants/platform-specific/push.native.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type DataCommon = {
type DataReadMessage = DataCommon & {
type: 'chat.readmessage'
b: string | number
i?: string
}
type DataNewMessage = DataCommon & {
type: 'chat.newmessage'
Expand Down Expand Up @@ -98,6 +99,7 @@ const normalizePush = (_n?: object): T.Push.PushNotification | undefined => {
const badges = typeof data.b === 'string' ? parseInt(data.b) : data.b
return {
badges,
forUid: data.i,
type: 'chat.readmessage',
} as const
}
Expand Down
1 change: 1 addition & 0 deletions shared/constants/types/push.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export type TokenType = 'apple' | 'appledev' | 'androidplay'
export type PushNotification =
| {
badges: number
forUid?: string
type: 'chat.readmessage'
}
| {
Expand Down
18 changes: 13 additions & 5 deletions shared/ios/Keybase/Pusher.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import UserNotifications
class PushNotifier: NSObject, Keybasego.KeybasePushNotifierProtocol {
func localNotification(
_ ident: String?, title: String?, msg: String?, badgeCount: Int, soundName: String?,
convID: String?, typ: String?
convID: String?, typ: String?, uid: String?
) {
let content = UNMutableNotificationContent()
if let soundName = soundName {
Expand All @@ -14,7 +14,7 @@ class PushNotifier: NSObject, Keybasego.KeybasePushNotifierProtocol {
content.badge = (badgeCount >= 0) ? NSNumber(value: badgeCount) : nil
content.title = title ?? ""
content.body = msg ?? ""
content.userInfo = ["convID": convID ?? "", "type": typ ?? ""]
content.userInfo = ["convID": convID ?? "", "type": typ ?? "", "uid": uid ?? ""]
let request = UNNotificationRequest(
identifier: ident ?? UUID().uuidString, content: content, trigger: nil)
UNUserNotificationCenter.current().add(request) { error in
Expand All @@ -40,9 +40,17 @@ class PushNotifier: NSObject, Keybasego.KeybasePushNotifierProtocol {
msg = message.serverMessage
}
let title = notification.title
NSLog("PushNotifier display: title=%@", title ?? "")
NSLog("PushNotifier display: title=%@", title)

let soundName: String? = notification.soundName.isEmpty ? nil : notification.soundName
let uid: String? = notification.uid.isEmpty ? nil : notification.uid
localNotification(
ident, title: title, msg: msg, badgeCount: notification.badgeCount,
soundName: notification.soundName, convID: notification.convID, typ: "chat.newmessage")
ident, title: title, msg: msg,
badgeCount: notification.badgeCount,
soundName: soundName,
convID: notification.convID,
typ: "chat.newmessage",
uid: uid
)
}
}