-12
appview/db/notifications.go
-12
appview/db/notifications.go
···
248
248
return GetNotificationsPaginated(e, pagination.FirstPage(), filters...)
249
249
}
250
250
251
-
// GetNotifications retrieves notifications for a user with pagination (legacy method for backward compatibility)
252
-
func (d *DB) GetNotifications(ctx context.Context, userDID string, limit, offset int) ([]*models.Notification, error) {
253
-
page := pagination.Page{Limit: limit, Offset: offset}
254
-
return GetNotificationsPaginated(d.DB, page, FilterEq("recipient_did", userDID))
255
-
}
256
-
257
-
// GetNotificationsWithEntities retrieves notifications with entities for a user with pagination
258
-
func (d *DB) GetNotificationsWithEntities(ctx context.Context, userDID string, limit, offset int) ([]*models.NotificationWithEntity, error) {
259
-
page := pagination.Page{Limit: limit, Offset: offset}
260
-
return GetNotificationsWithEntities(d.DB, page, FilterEq("recipient_did", userDID))
261
-
}
262
-
263
251
func (d *DB) GetUnreadNotificationCount(ctx context.Context, userDID string) (int, error) {
264
252
recipientFilter := FilterEq("recipient_did", userDID)
265
253
readFilter := FilterEq("read", 0)
+3
-1
appview/notifications/notifications.go
+3
-1
appview/notifications/notifications.go
···
10
10
"tangled.org/core/appview/middleware"
11
11
"tangled.org/core/appview/oauth"
12
12
"tangled.org/core/appview/pages"
13
+
"tangled.org/core/appview/pagination"
13
14
)
14
15
15
16
type Notifications struct {
···
61
62
}
62
63
}
63
64
64
-
notifications, err := n.db.GetNotificationsWithEntities(r.Context(), userDid, limit+1, offset)
65
+
page := pagination.Page{Limit: limit + 1, Offset: offset}
66
+
notifications, err := db.GetNotificationsWithEntities(n.db, page, db.FilterEq("recipient_did", userDid))
65
67
if err != nil {
66
68
log.Println("failed to get notifications:", err)
67
69
n.pages.Error500(w)
+8
-48
appview/notify/db/db.go
+8
-48
appview/notify/db/db.go
···
30
30
31
31
func (n *databaseNotifier) NewStar(ctx context.Context, star *models.Star) {
32
32
var err error
33
-
repos, err := db.GetRepos(n.db, 1, db.FilterEq("at_uri", string(star.RepoAt)))
33
+
repo, err := db.GetRepo(n.db, db.FilterEq("at_uri", string(star.RepoAt)))
34
34
if err != nil {
35
35
log.Printf("NewStar: failed to get repos: %v", err)
36
36
return
37
37
}
38
-
if len(repos) == 0 {
39
-
log.Printf("NewStar: no repo found for %s", star.RepoAt)
40
-
return
41
-
}
42
-
repo := repos[0]
43
38
44
39
// don't notify yourself
45
40
if repo.Did == star.StarredByDid {
···
76
71
}
77
72
78
73
func (n *databaseNotifier) NewIssue(ctx context.Context, issue *models.Issue) {
79
-
repos, err := db.GetRepos(n.db, 1, db.FilterEq("at_uri", string(issue.RepoAt)))
74
+
repo, err := db.GetRepo(n.db, db.FilterEq("at_uri", string(issue.RepoAt)))
80
75
if err != nil {
81
76
log.Printf("NewIssue: failed to get repos: %v", err)
82
77
return
83
78
}
84
-
if len(repos) == 0 {
85
-
log.Printf("NewIssue: no repo found for %s", issue.RepoAt)
86
-
return
87
-
}
88
-
repo := repos[0]
89
79
90
80
if repo.Did == issue.Did {
91
81
return
···
129
119
}
130
120
issue := issues[0]
131
121
132
-
repos, err := db.GetRepos(n.db, 1, db.FilterEq("at_uri", string(issue.RepoAt)))
122
+
repo, err := db.GetRepo(n.db, db.FilterEq("at_uri", string(issue.RepoAt)))
133
123
if err != nil {
134
124
log.Printf("NewIssueComment: failed to get repos: %v", err)
135
125
return
136
126
}
137
-
if len(repos) == 0 {
138
-
log.Printf("NewIssueComment: no repo found for %s", issue.RepoAt)
139
-
return
140
-
}
141
-
repo := repos[0]
142
127
143
128
recipients := make(map[string]bool)
144
129
···
211
196
}
212
197
213
198
func (n *databaseNotifier) NewPull(ctx context.Context, pull *models.Pull) {
214
-
repos, err := db.GetRepos(n.db, 1, db.FilterEq("at_uri", string(pull.RepoAt)))
199
+
repo, err := db.GetRepo(n.db, db.FilterEq("at_uri", string(pull.RepoAt)))
215
200
if err != nil {
216
201
log.Printf("NewPull: failed to get repos: %v", err)
217
202
return
218
203
}
219
-
if len(repos) == 0 {
220
-
log.Printf("NewPull: no repo found for %s", pull.RepoAt)
221
-
return
222
-
}
223
-
repo := repos[0]
224
204
225
205
if repo.Did == pull.OwnerDid {
226
206
return
···
266
246
}
267
247
pull := pulls[0]
268
248
269
-
repos, err := db.GetRepos(n.db, 1, db.FilterEq("at_uri", comment.RepoAt))
249
+
repo, err := db.GetRepo(n.db, db.FilterEq("at_uri", comment.RepoAt))
270
250
if err != nil {
271
251
log.Printf("NewPullComment: failed to get repos: %v", err)
272
252
return
273
253
}
274
-
if len(repos) == 0 {
275
-
log.Printf("NewPullComment: no repo found for %s", comment.RepoAt)
276
-
return
277
-
}
278
-
repo := repos[0]
279
254
280
255
recipients := make(map[string]bool)
281
256
···
335
310
336
311
func (n *databaseNotifier) NewIssueClosed(ctx context.Context, issue *models.Issue) {
337
312
// Get repo details
338
-
repos, err := db.GetRepos(n.db, 1, db.FilterEq("at_uri", string(issue.RepoAt)))
313
+
repo, err := db.GetRepo(n.db, db.FilterEq("at_uri", string(issue.RepoAt)))
339
314
if err != nil {
340
315
log.Printf("NewIssueClosed: failed to get repos: %v", err)
341
316
return
342
317
}
343
-
if len(repos) == 0 {
344
-
log.Printf("NewIssueClosed: no repo found for %s", issue.RepoAt)
345
-
return
346
-
}
347
-
repo := repos[0]
348
318
349
319
// Don't notify yourself
350
320
if repo.Did == issue.Did {
···
380
350
381
351
func (n *databaseNotifier) NewPullMerged(ctx context.Context, pull *models.Pull) {
382
352
// Get repo details
383
-
repos, err := db.GetRepos(n.db, 1, db.FilterEq("at_uri", string(pull.RepoAt)))
353
+
repo, err := db.GetRepo(n.db, db.FilterEq("at_uri", string(pull.RepoAt)))
384
354
if err != nil {
385
355
log.Printf("NewPullMerged: failed to get repos: %v", err)
386
356
return
387
357
}
388
-
if len(repos) == 0 {
389
-
log.Printf("NewPullMerged: no repo found for %s", pull.RepoAt)
390
-
return
391
-
}
392
-
repo := repos[0]
393
358
394
359
// Don't notify yourself
395
360
if repo.Did == pull.OwnerDid {
···
425
390
426
391
func (n *databaseNotifier) NewPullClosed(ctx context.Context, pull *models.Pull) {
427
392
// Get repo details
428
-
repos, err := db.GetRepos(n.db, 1, db.FilterEq("at_uri", string(pull.RepoAt)))
393
+
repo, err := db.GetRepo(n.db, db.FilterEq("at_uri", string(pull.RepoAt)))
429
394
if err != nil {
430
395
log.Printf("NewPullClosed: failed to get repos: %v", err)
431
396
return
432
397
}
433
-
if len(repos) == 0 {
434
-
log.Printf("NewPullClosed: no repo found for %s", pull.RepoAt)
435
-
return
436
-
}
437
-
repo := repos[0]
438
398
439
399
// Don't notify yourself
440
400
if repo.Did == pull.OwnerDid {