A music player that connects to your cloud/distributed storage.
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Improve the saving of the tracks collection

+108 -28
+40
src/Applications/Brain.elm
··· 17 17 import Return3 18 18 import Sources.Encoding as Sources 19 19 import Sources.Processing.Encoding as Processing 20 + import Tracks 20 21 import Tracks.Encoding as Tracks 21 22 22 23 ··· 159 160 |> returnWithModel { model | hypaethralUserData = decodedData } 160 161 |> andThen (updateSearchIndex encodedTracks) 161 162 163 + RemoveTracksBySourceId sourceId -> 164 + model.hypaethralUserData.tracks 165 + |> Tracks.removeBySourceId sourceId 166 + |> hypaethralLenses.setTracks model 167 + |> updateSearchIndexWithModel 168 + |> andThen saveHypaethralData 169 + 162 170 SaveHypaethralData -> 163 171 model.hypaethralUserData 164 172 |> Authentication.encodeHypaethral ··· 216 224 |> updateWithModel model 217 225 218 226 227 + updateSearchIndexWithModel : Model -> ( Model, Cmd Msg ) 228 + updateSearchIndexWithModel model = 229 + model.hypaethralUserData.tracks 230 + |> Json.Encode.list Tracks.encodeTrack 231 + |> Tracks.UpdateSearchIndex 232 + |> TracksMsg 233 + |> updateWithModel model 234 + 235 + 219 236 220 237 -- 📣 ░░ REPLIES 221 238 ··· 227 244 update SaveHypaethralData model 228 245 229 246 ----------------------------------------- 247 + -- Tracks 248 + ----------------------------------------- 249 + AddTracks tracks -> 250 + tracks 251 + |> (++) model.hypaethralUserData.tracks 252 + |> hypaethralLenses.setTracks model 253 + |> updateSearchIndexWithModel 254 + |> andThen saveHypaethralData 255 + 256 + RemoveTracksByPaths args -> 257 + model.hypaethralUserData.tracks 258 + |> Tracks.removeByPaths args 259 + |> hypaethralLenses.setTracks model 260 + |> updateSearchIndexWithModel 261 + |> andThen saveHypaethralData 262 + 263 + ----------------------------------------- 230 264 -- To UI 231 265 ----------------------------------------- 232 266 GiveUI Alien.LoadHypaethralUserData data -> ··· 395 429 |> Json.decodeValue (Json.field "origin" Json.string) 396 430 |> Result.withDefault "" 397 431 |> RedirectToBlockstackSignIn 432 + 433 + Alien.RemoveTracksBySourceId -> 434 + data 435 + |> Json.decodeValue Json.string 436 + |> Result.withDefault "" 437 + |> RemoveTracksBySourceId 398 438 399 439 Alien.SaveEnclosedUserData -> 400 440 AuthenticationMsg (Authentication.SaveEnclosedData data)
+1
src/Applications/Brain/Core.elm
··· 53 53 -- User data 54 54 ----------------------------------------- 55 55 | LoadHypaethralUserData Json.Value 56 + | RemoveTracksBySourceId String 56 57 | SaveHypaethralData 57 58 | SaveFavourites Json.Value 58 59 | SavePlaylists Json.Value
+4
src/Applications/Brain/Reply.elm
··· 2 2 3 3 import Alien 4 4 import Json.Encode as Json 5 + import Tracks exposing (Track) 5 6 6 7 7 8 ··· 10 11 11 12 type Reply 12 13 = FabricatedNewSecretKey 14 + -- Tracks 15 + | AddTracks (List Track) 16 + | RemoveTracksByPaths { sourceId : String, paths : List String } 13 17 -- UI 14 18 | GiveUI Alien.Tag Json.Value 15 19 | NudgeUI Alien.Tag
+12 -7
src/Applications/Brain/Sources/Processing.elm
··· 133 133 in 134 134 ( model 135 135 , Cmd.none 136 - , [ GiveUI Alien.RemoveTracksByPath encodedData ] 136 + , [ GiveUI Alien.RemoveTracksByPath encodedData 137 + , RemoveTracksByPaths { sourceId = sourceId, paths = filePaths } 138 + ] 137 139 ) 138 140 139 141 ----------------------------------------- ··· 161 163 [] 162 164 163 165 False -> 164 - tagsContext 165 - |> tracksFromTagsContext 166 - |> List.map (\track -> { track | insertedAt = model.currentTime }) 167 - |> Encode.list Tracks.Encoding.encodeTrack 168 - |> GiveUI Alien.AddTracks 169 - |> List.singleton 166 + let 167 + tracksToAdd = 168 + tagsContext 169 + |> tracksFromTagsContext 170 + |> List.map (\track -> { track | insertedAt = model.currentTime }) 171 + in 172 + [ GiveUI Alien.AddTracks (Encode.list Tracks.Encoding.encodeTrack tracksToAdd) 173 + , AddTracks tracksToAdd 174 + ] 170 175 ) 171 176 172 177 -----------------------------------------
+15 -1
src/Applications/UI.elm
··· 345 345 model 346 346 |> translateReply SaveFavourites 347 347 |> andThen (translateReply SaveSources) 348 - |> andThen (translateReply SaveTracks) 348 + |> andThen (translateReply SaveTracksFromCache) 349 349 |> andThen (translateReply <| ShowWarningNotification "Syncing") 350 350 351 351 ----------------------------------------- ··· 968 968 |> andThen (UI.Notifications.show notification) 969 969 970 970 RemoveTracksWithSourceId sourceId -> 971 + let 972 + cmd = 973 + sourceId 974 + |> Json.Encode.string 975 + |> Alien.broadcast Alien.RemoveTracksBySourceId 976 + |> Ports.toBrain 977 + in 971 978 sourceId 972 979 |> Tracks.RemoveBySourceId 973 980 |> TracksMsg 974 981 |> updateWithModel model 982 + |> addCommand cmd 975 983 976 984 ReplaceSourceInCollection source -> 977 985 let ··· 1052 1060 model 1053 1061 |> UserData.encodedTracks 1054 1062 |> Alien.broadcast Alien.SaveTracks 1063 + |> Ports.toBrain 1064 + |> returnWithModel model 1065 + 1066 + SaveTracksFromCache -> 1067 + Alien.SaveTracks 1068 + |> Alien.trigger 1055 1069 |> Ports.toBrain 1056 1070 |> returnWithModel model 1057 1071
+1
src/Applications/UI/Reply.elm
··· 78 78 | SaveSettings 79 79 | SaveSources 80 80 | SaveTracks 81 + | SaveTracksFromCache
+3 -3
src/Applications/UI/Tracks.elm
··· 220 220 |> Result.withDefault ( [], missingId ) 221 221 in 222 222 reviseCollection 223 - (removeByPaths sourceId paths) 223 + (Collection.removeByPaths sourceId paths) 224 224 model 225 225 226 226 RemoveBySourceId sourceId -> 227 227 reviseCollection 228 - (removeBySourceId sourceId) 228 + (Collection.removeBySourceId sourceId) 229 229 model 230 230 231 231 ----------------------------------------- ··· 470 470 -- Reply 471 471 -------- 472 472 , if collectionChanged then 473 - [ GenerateDirectoryPlaylists, ResetQueue, SaveTracks ] 473 + [ GenerateDirectoryPlaylists, ResetQueue ] 474 474 475 475 else if harvestChanged then 476 476 [ ResetQueue ]
+2
src/Library/Alien.elm
··· 37 37 -- from UI 38 38 | ProcessSources 39 39 | RedirectToBlockstackSignIn 40 + | RemoveTracksBySourceId 40 41 | SaveEnclosedUserData 41 42 | SaveFavourites 42 43 | SavePlaylists ··· 79 80 ----------------------------------------- 80 81 , ( "PROCESS_SOURCES", ProcessSources ) 81 82 , ( "REDIRECT_TO_BLOCKSTACK_SIGN_IN", RedirectToBlockstackSignIn ) 83 + , ( "REMOVE_TRACKS_BY_SOURCE_ID", RemoveTracksBySourceId ) 82 84 , ( "SAVE_ENCLOSED_USER_DATA", SaveEnclosedUserData ) 83 85 , ( "SAVE_FAVOURITES", SaveFavourites ) 84 86 , ( "SAVE_PLAYLISTS", SavePlaylists )
+21 -1
src/Library/Tracks.elm
··· 1 - module Tracks exposing (Collection, CollectionDependencies, Favourite, Grouping(..), IdentifiedTrack, Identifiers, Parcel, SortBy(..), SortDirection(..), Tags, Track, emptyCollection, emptyIdentifiedTrack, emptyIdentifiers, emptyTags, emptyTrack, isNowPlaying, makeTrack, missingId, removeFromPlaylist, toPlaylistTracks) 1 + module Tracks exposing (Collection, CollectionDependencies, Favourite, Grouping(..), IdentifiedTrack, Identifiers, Parcel, SortBy(..), SortDirection(..), Tags, Track, emptyCollection, emptyIdentifiedTrack, emptyIdentifiers, emptyTags, emptyTrack, isNowPlaying, makeTrack, missingId, removeByPaths, removeBySourceId, removeFromPlaylist, toPlaylistTracks) 2 2 3 3 import Base64 4 4 import List.Extra as List ··· 202 202 , sourceId = sourceId 203 203 , tags = tags 204 204 } 205 + 206 + 207 + removeByPaths : { sourceId : String, paths : List String } -> List Track -> List Track 208 + removeByPaths { sourceId, paths } tracks = 209 + tracks 210 + |> List.foldr 211 + (\t ( acc, remainingPaths ) -> 212 + if t.sourceId == sourceId && List.member t.path remainingPaths then 213 + ( acc, List.remove t.path remainingPaths ) 214 + 215 + else 216 + ( t :: acc, remainingPaths ) 217 + ) 218 + ( [], paths ) 219 + |> Tuple.first 220 + 221 + 222 + removeBySourceId : String -> List Track -> List Track 223 + removeBySourceId sourceId = 224 + List.filter (.sourceId >> (/=) sourceId) 205 225 206 226 207 227 removeFromPlaylist : List IdentifiedTrack -> Playlist -> Playlist
+9 -16
src/Library/Tracks/Collection.elm
··· 1 1 module Tracks.Collection exposing (add, arrange, harvest, harvestChanged, identify, map, removeByPaths, removeBySourceId, tracksChanged) 2 2 3 3 import List.Extra as List 4 - import Tracks exposing (..) 4 + import Tracks exposing (IdentifiedTrack, Parcel, Track, emptyCollection) 5 5 import Tracks.Collection.Internal as Internal 6 6 7 7 ··· 49 49 50 50 removeByPaths : String -> List String -> Parcel -> Parcel 51 51 removeByPaths sourceId paths ( deps, { untouched } ) = 52 - let 53 - ( filtered, _ ) = 54 - List.foldr 55 - (\t ( acc, remainingPaths ) -> 56 - if t.sourceId == sourceId && List.member t.path remainingPaths then 57 - ( acc, List.remove t.path remainingPaths ) 58 - 59 - else 60 - ( t :: acc, remainingPaths ) 61 - ) 62 - ( [], paths ) 63 - untouched 64 - in 65 52 identify 66 53 ( deps 67 - , { emptyCollection | untouched = filtered } 54 + , { emptyCollection 55 + | untouched = 56 + Tracks.removeByPaths { sourceId = sourceId, paths = paths } untouched 57 + } 68 58 ) 69 59 70 60 ··· 72 62 removeBySourceId sourceId ( deps, { untouched } ) = 73 63 identify 74 64 ( deps 75 - , { emptyCollection | untouched = List.filter (.sourceId >> (/=) sourceId) untouched } 65 + , { emptyCollection 66 + | untouched = 67 + Tracks.removeBySourceId sourceId untouched 68 + } 76 69 ) 77 70 78 71