Skip to content

Commit

Permalink
Merge pull request #919 from gponsinet/fix-916
Browse files Browse the repository at this point in the history
fix(node): token randomly change when provide it in chan
  • Loading branch information
Godefroy Ponsinet committed Jan 21, 2019
2 parents e681d5c + a65c253 commit da2f732
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
20 changes: 8 additions & 12 deletions client/react-native/gomobile/core/notification.go
Expand Up @@ -45,29 +45,25 @@ func (n *MobileNotification) Receive(data string) {
}

func (n *MobileNotification) ReceiveAPNSToken(token []byte) {
n.ReceiveToken(&notification.Token{
Value: token,
Type: push.DevicePushType_APNS,
})
t := &notification.Token{Type: push.DevicePushType_APNS, Value: make([]byte, len(token))}
copy(t.Value, token)
n.ReceiveToken(t)
}

func (n *MobileNotification) ReceiveFCMToken(token []byte) {
n.ReceiveToken(&notification.Token{
Value: token,
Type: push.DevicePushType_FCM,
})
t := &notification.Token{Type: push.DevicePushType_FCM, Value: make([]byte, len(token))}
copy(t.Value, token)
n.ReceiveToken(t)
}

func (n *MobileNotification) ReceiveToken(token *notification.Token) {
logger().Debug("receive token",
logger().Debug("mobile receive token",
zap.String("type", token.Type.String()),
zap.String("hash", token.Hash()),
)
n.tokenSubscribersMutex.Lock()
for i := range n.subscribers {
// make soft copy
t := *token
n.tokenSubscribers[i] <- &t
n.tokenSubscribers[i] <- token
}
n.tokenSubscribersMutex.Unlock()

Expand Down
8 changes: 4 additions & 4 deletions client/react-native/ios/modules/core/Notification.swift
Expand Up @@ -40,7 +40,7 @@ class Notification: NSObject, UNUserNotificationCenterDelegate, CoreNativeNotifi
let content = UNMutableNotificationContent()
content.title = utitle
content.body = ubody
content.userInfo = [ "url": url ]
content.userInfo = ["url": url]
content.categoryIdentifier = "berty.core.notification"
content.sound = UNNotificationSound.default()

Expand Down Expand Up @@ -147,9 +147,9 @@ extension AppDelegate {
if let url = data["url"] {
if url.count > 0 {
self.application(application, open: URL.init(string: url)!, options: [
UIApplicationOpenURLOptionsKey.sourceApplication: Bundle.main.bundleIdentifier!,
UIApplicationOpenURLOptionsKey.openInPlace: false
])
UIApplicationOpenURLOptionsKey.sourceApplication: Bundle.main.bundleIdentifier!,
UIApplicationOpenURLOptionsKey.openInPlace: false
])
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions core/node/push.go
Expand Up @@ -35,6 +35,10 @@ func WithPushTokenSubscriber() NewNodeOption {
select {
case token := <-tokenSubscription:
{
logger().Debug("node push token subscriber receive token",
zap.String("type", token.Type.String()),
zap.String("hash", token.Hash()),
)
currentToken := &entity.DevicePushConfig{}

if err = n.sql(ctx).First(&currentToken, &entity.DevicePushConfig{PushType: token.Type}).Error; err != nil {
Expand Down

0 comments on commit da2f732

Please sign in to comment.