Skip to content

Commit

Permalink
Added more granularity when using socket to find notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
Danzabar committed Feb 13, 2017
1 parent e80c88d commit 9262086
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
6 changes: 4 additions & 2 deletions api.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ type NotificationRead struct {

// Request sent from client socket to refresh notifications by page
type NotificationRefresh struct {
Page int `json:"page"`
PageSize int `json:"pageSize"`
Page int `json:"page"`
PageSize int `json:"pageSize"`
Tags []string `json:"tags"`
Read bool `json:"read"`
}
23 changes: 15 additions & 8 deletions application.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,18 +112,25 @@ func (a *Application) OnNotificationRefresh(msg string) string {
var n []Notification
var c int

App.db.
Model(&Notification{}).
Where(&Notification{Read: false}).
Count(&c)
cd := App.db.Model(&Notification{})

App.db.
Where(&Notification{Read: false}).
if !r.Read {
cd.Where(&Notification{Read: false})
}

cd.Count(&c)

nd := App.db.
Preload("Tags").
Limit(p.Limit).
Offset(p.Offset).
Order("updated_at DESC").
Find(&n)
Order("updated_at DESC")

if !r.Read {
nd.Where(&Notification{Read: false})
}

nd.Find(&n)

resp := &SocketLoadPayload{
Notifications: n,
Expand Down

0 comments on commit 9262086

Please sign in to comment.