pstream is dead; long live pstream taciturnaxolotl.github.io/pstream-ng/
1
fork

Configure Feed

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

fix groups (collections) not syncing correctly

Pas 1c05f99b 3b4b8915

+38 -8
+16 -6
src/stores/bookmarks/index.ts
··· 29 29 poster?: string; 30 30 type?: "show" | "movie"; 31 31 group?: string[]; 32 + /** Groups before modification - used to sync removals to Trakt lists */ 33 + previousGroup?: string[]; 32 34 favoriteEpisodes?: string[]; 33 35 action: "delete" | "add"; 34 36 } ··· 115 117 }, 116 118 addBookmarkWithGroups(meta, groups) { 117 119 set((s) => { 120 + const existingBookmark = s.bookmarks[meta.tmdbId]; 118 121 updateId += 1; 119 122 const item: BookmarkUpdateItem = { 120 123 id: updateId.toString(), ··· 125 128 year: meta.releaseYear, 126 129 poster: meta.poster, 127 130 group: groups, 131 + previousGroup: existingBookmark?.group, 128 132 }; 129 133 s.updateQueue.push(item); 130 134 s.traktUpdateQueue.push(item); ··· 245 249 set((s) => { 246 250 const { modifiedBookmarks, result: modificationResult } = 247 251 modifyBookmarks(s.bookmarks, bookmarkIds, options); 248 - s.bookmarks = modifiedBookmarks; 249 252 result = modificationResult; 250 253 251 - // Add to update queue for modified bookmarks 254 + // Add to update queue for modified bookmarks (capture previousGroup before overwriting) 252 255 if (result.hasChanges) { 253 256 result.modifiedIds.forEach((bookmarkId) => { 254 - const bookmark = s.bookmarks[bookmarkId]; 257 + const originalBookmark = s.bookmarks[bookmarkId]; 258 + const bookmark = modifiedBookmarks[bookmarkId]; 255 259 if (bookmark) { 256 260 updateId += 1; 257 261 const item: BookmarkUpdateItem = { ··· 263 267 poster: bookmark.poster, 264 268 type: bookmark.type, 265 269 group: bookmark.group, 270 + previousGroup: originalBookmark?.group, 266 271 favoriteEpisodes: bookmark.favoriteEpisodes, 267 272 }; 268 273 s.updateQueue.push(item); ··· 270 275 } 271 276 }); 272 277 } 278 + 279 + s.bookmarks = modifiedBookmarks; 273 280 }); 274 281 275 282 return result; ··· 285 292 set((s) => { 286 293 const { modifiedBookmarks, result: modificationResult } = 287 294 modifyBookmarksByGroup(s.bookmarks, options); 288 - s.bookmarks = modifiedBookmarks; 289 295 result = modificationResult; 290 296 291 - // Add to update queue for modified bookmarks 297 + // Add to update queue for modified bookmarks (capture previousGroup before overwriting) 292 298 if (result.hasChanges) { 293 299 result.modifiedIds.forEach((bookmarkId) => { 294 - const bookmark = s.bookmarks[bookmarkId]; 300 + const originalBookmark = s.bookmarks[bookmarkId]; 301 + const bookmark = modifiedBookmarks[bookmarkId]; 295 302 if (bookmark) { 296 303 updateId += 1; 297 304 const item: BookmarkUpdateItem = { ··· 303 310 poster: bookmark.poster, 304 311 type: bookmark.type, 305 312 group: bookmark.group, 313 + previousGroup: originalBookmark?.group, 306 314 favoriteEpisodes: bookmark.favoriteEpisodes, 307 315 }; 308 316 s.updateQueue.push(item); ··· 310 318 } 311 319 }); 312 320 } 321 + 322 + s.bookmarks = modifiedBookmarks; 313 323 }); 314 324 315 325 return result;
+22 -2
src/stores/trakt/TraktBookmarkSyncer.tsx
··· 70 70 71 71 if (item.action === "add") { 72 72 await traktService.addToWatchlist(contentData); 73 - if (hasLists && item.group?.length) { 74 - for (const groupName of item.group) { 73 + if (hasLists) { 74 + const newGroups = item.group ?? []; 75 + const prevGroups = item.previousGroup ?? []; 76 + 77 + // Remove from Trakt lists that the bookmark no longer belongs to 78 + const groupsToRemove = prevGroups.filter( 79 + (g) => !newGroups.includes(g), 80 + ); 81 + for (const groupName of groupsToRemove) { 82 + const list = await findListByName(slug!, groupName); 83 + if (list) { 84 + await traktService.removeFromList(slug!, listId(list), [ 85 + contentData, 86 + ]); 87 + } 88 + } 89 + 90 + // Add to Trakt lists that are new 91 + const groupsToAdd = newGroups.filter( 92 + (g) => !prevGroups.includes(g), 93 + ); 94 + for (const groupName of groupsToAdd) { 75 95 const list = await ensureListExists(slug!, groupName); 76 96 if (list) { 77 97 await traktService.addToList(slug!, listId(list), [