File tree Expand file tree Collapse file tree 3 files changed +62
-0
lines changed
webapp/apiv2/listeningSession Expand file tree Collapse file tree 3 files changed +62
-0
lines changed Original file line number Diff line number Diff line change @@ -384,3 +384,26 @@ func NewQueuePlaylist(session model.FullListeningSession) *SpotifeteError {
384384
385385 return nil
386386}
387+
388+ func RefollowQueuePlaylist (session model.FullListeningSession ) * SpotifeteError {
389+
390+ owner := session .Owner
391+ client := users .Client (owner )
392+
393+ ownerId := spotify .ID (owner .SpotifyId )
394+ queuePlaylistId := spotify .ID (session .QueuePlaylistId )
395+
396+ err := client .UnfollowPlaylist (ownerId , queuePlaylistId )
397+ if err != nil {
398+ return NewError ("Could not unfollow playlist." , err , http .StatusInternalServerError )
399+ }
400+
401+ time .Sleep (1 * time .Second )
402+
403+ err = client .FollowPlaylist (ownerId , queuePlaylistId , false )
404+ if err == nil {
405+ return nil
406+ } else {
407+ return NewError ("Could not unfollow playlist." , err , http .StatusInternalServerError )
408+ }
409+ }
Original file line number Diff line number Diff line change @@ -319,6 +319,44 @@ func newQueuePlaylist(c *gin.Context) {
319319 }
320320}
321321
322+ func refollowQueuePlaylist (c * gin.Context ) {
323+
324+ joinId := c .Param ("joinId" )
325+ session := listeningSession .FindFullListeningSession (model.SimpleListeningSession {
326+ JoinId : joinId ,
327+ Active : true ,
328+ })
329+ if session == nil {
330+ c .JSON (http .StatusNotFound , ErrorResponse {Message : "Listening session not found." })
331+ return
332+ }
333+
334+ request := AuthenticatedRequest {}
335+ err := c .ShouldBindJSON (& request )
336+ if err != nil {
337+ c .JSON (http .StatusBadRequest , ErrorResponse {Message : "invalid requestBody: " + err .Error ()})
338+ return
339+ }
340+
341+ authenticatedUser , spotifeteError := request .GetSimpleUser ()
342+ if spotifeteError != nil {
343+ SetJsonError (* spotifeteError , c )
344+ return
345+ }
346+
347+ if session .OwnerId != authenticatedUser .ID {
348+ c .JSON (http .StatusUnauthorized , ErrorResponse {Message : "Only the session owner can delete requests from the queue!" })
349+ return
350+ }
351+
352+ spotifeteError = listeningSession .RefollowQueuePlaylist (* session )
353+ if spotifeteError == nil {
354+ c .Status (http .StatusNoContent )
355+ } else {
356+ SetJsonError (* spotifeteError , c )
357+ }
358+ }
359+
322360func changeFallbackPlaylist (c * gin.Context ) {
323361 request := ChangeFallbackPlaylistRequest {}
324362 err := c .ShouldBindJSON (& request )
Original file line number Diff line number Diff line change @@ -18,6 +18,7 @@ func SetupRoutes(baseRouterGroup *gin.RouterGroup) {
1818 router .GET ("/id/:joinId/search/playlist" , searchPlaylist )
1919 router .POST ("/id/:joinId/request-track" , requestTrack )
2020 router .POST ("/id/:joinId/new-queue-playlist" , newQueuePlaylist )
21+ router .POST ("/id/:joinId/refollow-queue-playlist" , refollowQueuePlaylist )
2122 router .PUT ("/id/:joinId/fallback-playlist" , changeFallbackPlaylist )
2223 router .DELETE ("/id/:joinId/fallback-playlist" , removeFallbackPlaylist )
2324 router .PATCH ("/id/:joinId/fallback-playlist/shuffle" , setFallbackPlaylistShuffle )
You can’t perform that action at this time.
0 commit comments