-
Notifications
You must be signed in to change notification settings - Fork 902
feat(coderd): add inbox notifications endpoints #16889
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
3c6512b
c8ccc60
18b694b
0e8ac4c
d72d1f2
796bcd0
75c310d
07ab7c4
cb41d1a
6ff4c7e
1ebc7f4
736a2d7
c28002e
2637d86
4d0a561
1f18868
4f01a86
cf6af1b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -140,7 +140,7 @@ func (api *API) watchInboxNotifications(rw http.ResponseWriter, r *http.Request) | |
go httpapi.Heartbeat(ctx, conn) | ||
defer conn.Close(websocket.StatusNormalClosure, "connection closed") | ||
|
||
notificationCh := make(chan codersdk.InboxNotification, 1) | ||
notificationCh := make(chan codersdk.InboxNotification, 10) | ||
|
||
closeInboxNotificationsSubscriber, err := api.Pubsub.SubscribeWithErr(pubsub.InboxNotificationForOwnerEventChannel(apikey.UserID), | ||
pubsub.HandleInboxNotificationEvent( | ||
|
@@ -150,6 +150,10 @@ func (api *API) watchInboxNotifications(rw http.ResponseWriter, r *http.Request) | |
return | ||
} | ||
|
||
// HandleInboxNotificationEvent cb receives all the inbox notifications - without any filters excepted the user_id. | ||
// Based on query parameters defined above and filters defined by the client - we then filter out the | ||
// notifications we do not want to forward and discard it. | ||
|
||
// filter out notifications that don't match the targets | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Curious why we need this here when the SQL query allows a list of targets to match on? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +1 unless this is intended, then please drop a comment on why this is mandatory. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is indeed intended - I added a comment to clarify the situation but also here : The inbox notifications received on the This is why here - for each websocket connection and based on the filters set as query params, we filters the events we want to process or not. |
||
if len(targets) > 0 { | ||
for _, target := range targets { | ||
|
@@ -179,7 +183,11 @@ func (api *API) watchInboxNotifications(rw http.ResponseWriter, r *http.Request) | |
} | ||
} | ||
|
||
notificationCh <- payload.InboxNotification | ||
// keep a safe guard in case of latency to push notifications through websocket | ||
select { | ||
case notificationCh <- payload.InboxNotification: | ||
default: | ||
} | ||
}, | ||
)) | ||
if err != nil { | ||
|
@@ -306,7 +314,7 @@ func (api *API) listInboxNotifications(rw http.ResponseWriter, r *http.Request) | |
// @Produce json | ||
// @Tags Notifications | ||
// @Param id path string true "id of the notification" | ||
// @Success 201 {object} codersdk.Response | ||
// @Success 200 {object} codersdk.Response | ||
// @Router /notifications/inbox/{id}/read-status [put] | ||
func (api *API) updateInboxNotificationReadStatus(rw http.ResponseWriter, r *http.Request) { | ||
ctx := r.Context() | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package uuid | ||
|
||
import ( | ||
"strings" | ||
|
||
"github.com/google/uuid" | ||
) | ||
|
||
func FromSliceToString(uuids []uuid.UUID, separator string) string { | ||
uuidStrings := make([]string, 0, len(uuids)) | ||
|
||
for _, u := range uuids { | ||
uuidStrings = append(uuidStrings, u.String()) | ||
} | ||
|
||
return strings.Join(uuidStrings, separator) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.