Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
notella
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Monitor
Service Desk
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Churros
notella
Commits
e86cf33b
Verified
Commit
e86cf33b
authored
6 months ago
by
Gwenn Le Bihan
Browse files
Options
Downloads
Patches
Plain Diff
fix: test notification was not sent to any subscription
parent
8bf412e6
Branches
Branches containing commit
Tags
v0.11.1
Tags containing commit
No related merge requests found
Pipeline
#18559
passed
6 months ago
Stage: update
Stage: test
Stage: build
Changes
2
Pipelines
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
messages.go
+2
-9
2 additions, 9 deletions
messages.go
subscriptions.go
+40
-15
40 additions, 15 deletions
subscriptions.go
with
42 additions
and
24 deletions
messages.go
+
2
−
9
View file @
e86cf33b
...
...
@@ -14,16 +14,9 @@ func (msg Message) ShouldRun() bool {
}
func
(
msg
Message
)
Run
()
error
{
users
,
err
:=
Receivers
(
msg
)
subs
,
users
,
err
:=
msg
.
ShouldSendTo
(
)
if
err
!=
nil
{
return
fmt
.
Errorf
(
"could not determine who to send the notification to: %w"
,
err
)
}
ll
.
Debug
(
"Sending notification for %s on %s to %d users: %v"
,
msg
.
Event
,
msg
.
ChurrosObjectId
,
len
(
users
),
users
)
subs
,
err
:=
subscriptionsOfUsers
(
users
)
if
err
!=
nil
{
return
fmt
.
Errorf
(
"could not determine which subscriptions to send the notification to: %w"
,
err
)
return
fmt
.
Errorf
(
"could not determine what subscriptions to send the notification to: %w"
,
err
)
}
if
len
(
subs
)
==
0
{
...
...
This diff is collapsed.
Click to expand it.
subscriptions.go
+
40
−
15
View file @
e86cf33b
...
...
@@ -21,6 +21,27 @@ type Subscription struct {
Owner
SubscriptionOwner
`json:"owner"`
}
func
(
msg
Message
)
ShouldSendTo
()
(
subs
[]
Subscription
,
userIds
[]
string
,
err
error
)
{
if
msg
.
Event
==
EventTest
{
sub
,
err
:=
prisma
.
NotificationSubscription
.
FindUnique
(
db
.
NotificationSubscription
.
ID
.
Equals
(
msg
.
ChurrosObjectId
))
.
With
(
db
.
NotificationSubscription
.
Owner
.
Fetch
())
.
Exec
(
context
.
Background
())
return
[]
Subscription
{
SubscriptionFromDatabase
(
*
sub
)},
[]
string
{},
err
}
users
,
err
:=
Receivers
(
msg
)
if
err
!=
nil
{
return
[]
Subscription
{},
users
,
fmt
.
Errorf
(
"could not determine who to send the notification to: %w"
,
err
)
}
ll
.
Debug
(
"Sending notification for %s on %s to %d users: %v"
,
msg
.
Event
,
msg
.
ChurrosObjectId
,
len
(
users
),
users
)
subs
,
err
=
subscriptionsOfUsers
(
users
)
if
err
!=
nil
{
return
[]
Subscription
{},
users
,
fmt
.
Errorf
(
"could not determine which subscriptions to send the notification to: %w"
,
err
)
}
return
subs
,
[]
string
{},
nil
}
func
subscriptionsOfUsers
(
ids
[]
string
)
(
subscriptions
[]
Subscription
,
err
error
)
{
if
err
:=
prisma
.
Prisma
.
Connect
();
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"could not connect to prisma: %w"
,
err
)
...
...
@@ -34,7 +55,16 @@ func subscriptionsOfUsers(ids []string) (subscriptions []Subscription, err error
}
for
_
,
sub
:=
range
subs
{
subscriptions
=
append
(
subscriptions
,
Subscription
{
subscriptions
=
append
(
subscriptions
,
SubscriptionFromDatabase
(
sub
))
}
ll
.
Debug
(
"Found %d subscriptions for %d users %v"
,
len
(
subscriptions
),
len
(
ids
),
ids
)
return
subscriptions
,
nil
}
func
SubscriptionFromDatabase
(
sub
db
.
NotificationSubscriptionModel
)
Subscription
{
return
Subscription
{
Webpush
:
webpush
.
Subscription
{
Endpoint
:
sub
.
Endpoint
,
Keys
:
webpush
.
Keys
{
...
...
@@ -48,12 +78,7 @@ func subscriptionsOfUsers(ids []string) (subscriptions []Subscription, err error
FirstName
:
sub
.
Owner
()
.
FirstName
,
LastName
:
sub
.
Owner
()
.
LastName
,
},
})
}
ll
.
Debug
(
"Found %d subscriptions for %d users %v"
,
len
(
subscriptions
),
len
(
ids
),
ids
)
return
subscriptions
,
nil
}
func
(
sub
Subscription
)
Destroy
()
error
{
...
...
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