mirror of
https://github.com/discourse/discourse.git
synced 2025-09-04 08:47:37 +08:00
FEATURE: Polymorphic bookmarks pt. 3 (reminders, imports, exports, refactors) (#16591)
A bit of a mixed bag, this addresses several edge areas of bookmarks and makes them compatible with polymorphic bookmarks (hidden behind the `use_polymorphic_bookmarks` site setting). The main ones are: * ExportUserArchive compatibility * SyncTopicUserBookmarked job compatibility * Sending different notifications for the bookmark reminders based on the bookmarkable type * Import scripts compatibility * BookmarkReminderNotificationHandler compatibility This PR also refactors the `register_bookmarkable` API so it accepts a class descended from a `BaseBookmarkable` class instead. This was done because we kept having to add more and more lambdas/properties inline and it was very messy, so a factory pattern is cleaner. The classes can be tested independently as well. Some later PRs will address some other areas like the discourse narrative bot, advanced search, reports, and the .ics endpoint for bookmarks.
This commit is contained in:
parent
c99a6b10fb
commit
222c8d9b6a
33 changed files with 880 additions and 271 deletions
|
@ -624,7 +624,12 @@ class ImportScripts::Base
|
|||
else
|
||||
begin
|
||||
manager = BookmarkManager.new(user)
|
||||
bookmark = manager.create(post_id: post.id)
|
||||
|
||||
if SiteSetting.use_polymorphic_bookmarks
|
||||
bookmark = manager.create_for(bookmarkable_id: post.id, bookmarkable_type: "Post")
|
||||
else
|
||||
bookmark = manager.create(post_id: post.id)
|
||||
end
|
||||
|
||||
created += 1 if manager.errors.none?
|
||||
skipped += 1 if manager.errors.any?
|
||||
|
|
|
@ -285,10 +285,14 @@ class ImportScripts::JiveApi < ImportScripts::Base
|
|||
|
||||
loop do
|
||||
favorites = get("contents?#{fields}&filter=type(favorite)#{filter}&sort=dateCreatedAsc&count=#{POST_COUNT}&startIndex=#{start_index}")
|
||||
favorites["list"].each do |favorite|
|
||||
bookmarks_to_create = favorites["list"].map do |favorite|
|
||||
next unless user_id = user_id_from_imported_user_id(favorite["author"]["id"])
|
||||
next unless post_id = post_id_from_imported_post_id(favorite["favoriteObject"]["id"])
|
||||
PostActionCreator.create(User.find(user_id), Post.find(post_id), :bookmark)
|
||||
{ user_id: user_id, post_id: post_id }
|
||||
end.flatten
|
||||
|
||||
create_bookmarks(bookmarks_to_create) do |row|
|
||||
row
|
||||
end
|
||||
|
||||
break if favorites["list"].size < POST_COUNT || favorites.dig("links", "next").blank?
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue