@@ -94,18 +94,6 @@ func (api *API) watchInboxNotifications(rw http.ResponseWriter, r *http.Request)
94
94
return
95
95
}
96
96
97
- conn , err := websocket .Accept (rw , r , nil )
98
- if err != nil {
99
- httpapi .Write (ctx , rw , http .StatusInternalServerError , codersdk.Response {
100
- Message : "Failed to upgrade connection to websocket." ,
101
- Detail : err .Error (),
102
- })
103
- return
104
- }
105
-
106
- go httpapi .Heartbeat (ctx , conn )
107
- defer conn .Close (websocket .StatusNormalClosure , "connection closed" )
108
-
109
97
notificationCh := make (chan codersdk.InboxNotification , 10 )
110
98
111
99
closeInboxNotificationsSubscriber , err := api .Pubsub .SubscribeWithErr (pubsub .InboxNotificationForOwnerEventChannel (apikey .UserID ),
@@ -161,9 +149,20 @@ func (api *API) watchInboxNotifications(rw http.ResponseWriter, r *http.Request)
161
149
api .Logger .Error (ctx , "subscribe to inbox notification event" , slog .Error (err ))
162
150
return
163
151
}
164
-
165
152
defer closeInboxNotificationsSubscriber ()
166
153
154
+ conn , err := websocket .Accept (rw , r , nil )
155
+ if err != nil {
156
+ httpapi .Write (ctx , rw , http .StatusInternalServerError , codersdk.Response {
157
+ Message : "Failed to upgrade connection to websocket." ,
158
+ Detail : err .Error (),
159
+ })
160
+ return
161
+ }
162
+
163
+ go httpapi .Heartbeat (ctx , conn )
164
+ defer conn .Close (websocket .StatusNormalClosure , "connection closed" )
165
+
167
166
encoder := wsjson .NewEncoder [codersdk.GetInboxNotificationResponse ](conn , websocket .MessageText )
168
167
defer encoder .Close (websocket .StatusNormalClosure )
169
168
0 commit comments