Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
notifications-bot
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
archives
notifications-bot
Commits
cb0bfcae
Commit
cb0bfcae
authored
Sep 17, 2021
by
Jonah Husson
Browse files
Options
Downloads
Patches
Plain Diff
Fixes for apns sending
parent
80922f76
No related branches found
No related tags found
2 merge requests
!12
Release
,
!7
Jonah/alt apns
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
notifications/notifications.go
+13
-4
13 additions, 4 deletions
notifications/notifications.go
notifications/notifications_test.go
+3
-3
3 additions, 3 deletions
notifications/notifications_test.go
with
16 additions
and
7 deletions
notifications/notifications.go
+
13
−
4
View file @
cb0bfcae
...
@@ -38,7 +38,7 @@ import (
...
@@ -38,7 +38,7 @@ import (
)
)
// Function type definitions for the main operations (poll and notify)
// Function type definitions for the main operations (poll and notify)
type
NotifyFunc
func
(
*
pb
.
NotificationData
,
ApnsSender
,
*
messaging
.
Client
,
*
firebase
.
FirebaseComm
,
*
storage
.
Storage
)
error
type
NotifyFunc
func
(
*
pb
.
NotificationData
,
ApnsSender
,
*
messaging
.
Client
,
*
firebase
.
FirebaseComm
,
*
storage
.
Storage
,
string
)
error
type
ApnsSender
interface
{
type
ApnsSender
interface
{
//Send(token string, p apns.Payload, opts ...apns.SendOption) (*apns.Response, error)
//Send(token string, p apns.Payload, opts ...apns.SendOption) (*apns.Response, error)
Push
(
n
*
apns2
.
Notification
)
(
*
apns2
.
Response
,
error
)
Push
(
n
*
apns2
.
Notification
)
(
*
apns2
.
Response
,
error
)
...
@@ -69,6 +69,7 @@ type Impl struct {
...
@@ -69,6 +69,7 @@ type Impl struct {
fcm
*
messaging
.
Client
fcm
*
messaging
.
Client
apnsClient
*
apns2
.
Client
apnsClient
*
apns2
.
Client
receivedNdf
*
uint32
receivedNdf
*
uint32
params
*
Params
ndfStopper
Stopper
ndfStopper
Stopper
}
}
...
@@ -110,6 +111,7 @@ func StartNotifications(params Params, noTLS, noFirebase bool) (*Impl, error) {
...
@@ -110,6 +111,7 @@ func StartNotifications(params Params, noTLS, noFirebase bool) (*Impl, error) {
notifyFunc
:
notifyUser
,
notifyFunc
:
notifyUser
,
fcm
:
app
,
fcm
:
app
,
receivedNdf
:
&
receivedNdf
,
receivedNdf
:
&
receivedNdf
,
params
:
&
params
,
}
}
if
params
.
APNS
.
KeyPath
==
""
{
if
params
.
APNS
.
KeyPath
==
""
{
...
@@ -119,7 +121,7 @@ func StartNotifications(params Params, noTLS, noFirebase bool) (*Impl, error) {
...
@@ -119,7 +121,7 @@ func StartNotifications(params Params, noTLS, noFirebase bool) (*Impl, error) {
return
nil
,
errors
.
WithMessagef
(
err
,
"APNS not properly configured: %+v"
,
params
.
APNS
)
return
nil
,
errors
.
WithMessagef
(
err
,
"APNS not properly configured: %+v"
,
params
.
APNS
)
}
}
authKey
,
err
:=
apnstoken
.
AuthKeyFromFile
(
"
params.APNS.KeyPath
"
)
authKey
,
err
:=
apnstoken
.
AuthKeyFromFile
(
params
.
APNS
.
KeyPath
)
if
err
!=
nil
{
if
err
!=
nil
{
log
.
Fatal
(
"token error:"
,
err
)
log
.
Fatal
(
"token error:"
,
err
)
}
}
...
@@ -131,6 +133,12 @@ func StartNotifications(params Params, noTLS, noFirebase bool) (*Impl, error) {
...
@@ -131,6 +133,12 @@ func StartNotifications(params Params, noTLS, noFirebase bool) (*Impl, error) {
TeamID
:
params
.
APNS
.
Issuer
,
TeamID
:
params
.
APNS
.
Issuer
,
}
}
apnsClient
:=
apns2
.
NewTokenClient
(
token
)
apnsClient
:=
apns2
.
NewTokenClient
(
token
)
if
params
.
APNS
.
Dev
{
jww
.
INFO
.
Printf
(
"Running with dev apns gateway"
)
apnsClient
.
Development
()
}
else
{
apnsClient
.
Production
()
}
impl
.
apnsClient
=
apnsClient
impl
.
apnsClient
=
apnsClient
}
}
...
@@ -170,7 +178,7 @@ func NewImplementation(instance *Impl) *notificationBot.Implementation {
...
@@ -170,7 +178,7 @@ func NewImplementation(instance *Impl) *notificationBot.Implementation {
// NotifyUser accepts a UID and service key file path.
// NotifyUser accepts a UID and service key file path.
// It handles the logic involved in retrieving a user's token and sending the notification
// It handles the logic involved in retrieving a user's token and sending the notification
func
notifyUser
(
data
*
pb
.
NotificationData
,
apnsClient
ApnsSender
,
fcm
*
messaging
.
Client
,
fc
*
firebase
.
FirebaseComm
,
db
*
storage
.
Storage
)
error
{
func
notifyUser
(
data
*
pb
.
NotificationData
,
apnsClient
ApnsSender
,
fcm
*
messaging
.
Client
,
fc
*
firebase
.
FirebaseComm
,
db
*
storage
.
Storage
,
topic
string
)
error
{
elist
,
err
:=
db
.
GetEphemeral
(
data
.
EphemeralID
)
elist
,
err
:=
db
.
GetEphemeral
(
data
.
EphemeralID
)
if
err
!=
nil
{
if
err
!=
nil
{
if
errors
.
Is
(
err
,
gorm
.
ErrRecordNotFound
)
{
if
errors
.
Is
(
err
,
gorm
.
ErrRecordNotFound
)
{
...
@@ -201,6 +209,7 @@ func notifyUser(data *pb.NotificationData, apnsClient ApnsSender, fcm *messaging
...
@@ -201,6 +209,7 @@ func notifyUser(data *pb.NotificationData, apnsClient ApnsSender, fcm *messaging
Priority
:
apns2
.
PriorityHigh
,
Priority
:
apns2
.
PriorityHigh
,
Payload
:
notifPayload
,
Payload
:
notifPayload
,
PushType
:
apns2
.
PushTypeAlert
,
PushType
:
apns2
.
PushTypeAlert
,
Topic
:
topic
,
}
}
resp
,
err
:=
apnsClient
.
Push
(
notif
)
resp
,
err
:=
apnsClient
.
Push
(
notif
)
//resp, err := apnsClient.Send(u.Token, apns.Payload{
//resp, err := apnsClient.Send(u.Token, apns.Payload{
...
@@ -349,7 +358,7 @@ func (nb *Impl) ReceiveNotificationBatch(notifBatch *pb.NotificationBatch, auth
...
@@ -349,7 +358,7 @@ func (nb *Impl) ReceiveNotificationBatch(notifBatch *pb.NotificationBatch, auth
fbComm
:=
firebase
.
NewFirebaseComm
()
fbComm
:=
firebase
.
NewFirebaseComm
()
for
_
,
notifData
:=
range
notifBatch
.
GetNotifications
()
{
for
_
,
notifData
:=
range
notifBatch
.
GetNotifications
()
{
err
:=
nb
.
notifyFunc
(
notifData
,
nb
.
apnsClient
,
nb
.
fcm
,
fbComm
,
nb
.
Storage
)
err
:=
nb
.
notifyFunc
(
notifData
,
nb
.
apnsClient
,
nb
.
fcm
,
fbComm
,
nb
.
Storage
,
nb
.
params
.
APNS
.
BundleID
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
...
...
This diff is collapsed.
Click to expand it.
notifications/notifications_test.go
+
3
−
3
View file @
cb0bfcae
...
@@ -77,7 +77,7 @@ func TestNotifyUser(t *testing.T) {
...
@@ -77,7 +77,7 @@ func TestNotifyUser(t *testing.T) {
EphemeralID
:
eph
.
EphemeralId
,
EphemeralID
:
eph
.
EphemeralId
,
IdentityFP
:
nil
,
IdentityFP
:
nil
,
MessageHash
:
nil
,
MessageHash
:
nil
,
},
&
MockApns
{},
nil
,
fcBadSend
,
s
)
},
&
MockApns
{},
nil
,
fcBadSend
,
s
,
""
)
if
err
==
nil
{
if
err
==
nil
{
t
.
Errorf
(
"Should have returned an error"
)
t
.
Errorf
(
"Should have returned an error"
)
}
}
...
@@ -86,7 +86,7 @@ func TestNotifyUser(t *testing.T) {
...
@@ -86,7 +86,7 @@ func TestNotifyUser(t *testing.T) {
EphemeralID
:
eph
.
EphemeralId
,
EphemeralID
:
eph
.
EphemeralId
,
IdentityFP
:
nil
,
IdentityFP
:
nil
,
MessageHash
:
nil
,
MessageHash
:
nil
,
},
&
MockApns
{},
nil
,
fc
,
s
)
},
&
MockApns
{},
nil
,
fc
,
s
,
""
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Errorf
(
"Failed to notify user properly"
)
t
.
Errorf
(
"Failed to notify user properly"
)
}
}
...
@@ -297,7 +297,7 @@ func TestImpl_UnregisterForNotifications(t *testing.T) {
...
@@ -297,7 +297,7 @@ func TestImpl_UnregisterForNotifications(t *testing.T) {
func
TestImpl_ReceiveNotificationBatch
(
t
*
testing
.
T
)
{
func
TestImpl_ReceiveNotificationBatch
(
t
*
testing
.
T
)
{
impl
:=
getNewImpl
()
impl
:=
getNewImpl
()
dataChan
:=
make
(
chan
*
pb
.
NotificationData
)
dataChan
:=
make
(
chan
*
pb
.
NotificationData
)
impl
.
notifyFunc
=
func
(
data
*
pb
.
NotificationData
,
apns
ApnsSender
,
f
*
messaging
.
Client
,
fc
*
firebase
.
FirebaseComm
,
s
*
storage
.
Storage
)
error
{
impl
.
notifyFunc
=
func
(
data
*
pb
.
NotificationData
,
apns
ApnsSender
,
f
*
messaging
.
Client
,
fc
*
firebase
.
FirebaseComm
,
s
*
storage
.
Storage
,
topic
string
)
error
{
go
func
()
{
dataChan
<-
data
}()
go
func
()
{
dataChan
<-
data
}()
return
nil
return
nil
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment