Add reminder about unread bookmarks

This commit is contained in:
2024-02-23 08:31:12 +11:00
parent a8f74b1e04
commit 6978a3dfc6
8 changed files with 110 additions and 1 deletions

View File

@@ -88,6 +88,14 @@ namespace :blog do
Que.connection = Adamantium::Container["persistence.db"] Que.connection = Adamantium::Container["persistence.db"]
Adamantium::Jobs::ArchiveDeletedWebmentions.enqueue Adamantium::Jobs::ArchiveDeletedWebmentions.enqueue
end end
task gently_remind_me: ["blog:load_environment"] do
require "hanami/prepare"
require "que"
command = Adamantium::GentlyRemindMe.new
command.call(limit: 5)
end
end end
namespace :tailwind do namespace :tailwind do

View File

@@ -0,0 +1,9 @@
# frozen_string_literal: true
ROM::SQL.migration do
change do
alter_table :posts do
add_column :is_read, :bool, default: false
end
end
end

View File

@@ -0,0 +1,47 @@
module Adamantium
class GentlyRemindMe
def call(limit:)
repo = Adamantium::Container["repos.post_repo"]
app_settings = Adamantium::Container["settings"]
bookmarks = repo.for_reminders(limit: limit)
bookmarks_struct = bookmarks.map do |bookmark|
{
name: bookmark.name,
source_url: bookmark.url,
url: "#{app_settings.micropub_site_url}/bookmark/#{bookmark.slug}"
}
end
body_content = ""
bookmarks_struct.each do |bm|
body_content += "#{bm[:name]}#{bm[:source_url]} \n"
body_content += " #{bm[:url]}\n"
body_content += "\n"
end
Mail.defaults do
delivery_method :smtp, {
address: app_settings.smtp_server,
port: 587,
authentication: "plain",
openssl_verify_mode: "peer",
enable_starttls_auto: true
}
end
Mail.delivery_method.settings[:user_name] = app_settings.smtp_username
Mail.delivery_method.settings[:password] = app_settings.smtp_password
mail = Mail.new do
subject "A gentle reminder"
body body_content
end
mail[:to] = app_settings.from_email
mail[:from] = app_settings.from_email
mail.deliver
end
end
end

View File

@@ -0,0 +1,15 @@
module Admin
module Actions
module Bookmarks
class MarkRead < Action
include Deps["repos.bookmark_repo"]
def handle(req, res)
bookmark_id = req.params[:id]
bookmark_repo.mark_read(id: bookmark_id)
end
end
end
end
end

View File

@@ -0,0 +1,15 @@
module Admin
module Actions
module Bookmarks
class MarkUnread < Action
include Deps["repos.bookmark_repo"]
def handle(req, res)
bookmark_id = req.params[:id]
bookmark_repo.mark_unread(id: bookmark_id)
end
end
end
end
end

View File

@@ -42,6 +42,8 @@ module Admin
post "/bookmarks/cache/:id", to: Auth.call(action: "bookmarks.cache") post "/bookmarks/cache/:id", to: Auth.call(action: "bookmarks.cache")
post "/bookmarks/:id/archive", to: Auth.call(action: "bookmarks.archive") post "/bookmarks/:id/archive", to: Auth.call(action: "bookmarks.archive")
post "/bookmarks/:id/publish", to: Auth.call(action: "bookmarks.publish") post "/bookmarks/:id/publish", to: Auth.call(action: "bookmarks.publish")
post "/bookmarks/:id/mark_read", to: Auth.call(action: "bookmarks.mark_read")
post "/bookmarks/:id/mark_unread", to: Auth.call(action: "bookmarks.mark_unread")
get "/posts", to: Auth.call(action: "posts.index") get "/posts", to: Auth.call(action: "posts.index")
delete "/posts/:id", to: Auth.call(action: "posts.delete") delete "/posts/:id", to: Auth.call(action: "posts.delete")

View File

@@ -34,6 +34,14 @@ module Admin
def update(id:, params:) def update(id:, params:)
posts.where(id: id).update(params) posts.where(id: id).update(params)
end end
def mark_read(id:)
posts.where(id: id).update(is_read: true)
end
def mark_unread(id:)
posts.where(id: id).update(is_read: false)
end
end end
end end
end end

View File

@@ -13,7 +13,7 @@ div class="max-w-prose mx-auto" x-data="{ activeTab: 0 }"
thead thead
th Details th Details
th Date th Date
th colspan="2" Actions th colspan="3" Actions
tbody class="{ 'active': activeTab === 0 }" x-show.transition.in.opacity.duration.600="activeTab === 0" tbody class="{ 'active': activeTab === 0 }" x-show.transition.in.opacity.duration.600="activeTab === 0"
- published_bookmarks.each do |bookmark| - published_bookmarks.each do |bookmark|
tr id="bookmark-#{bookmark.id}" tr id="bookmark-#{bookmark.id}"
@@ -36,6 +36,11 @@ div class="max-w-prose mx-auto" x-data="{ activeTab: 0 }"
button class="text-red-600" hx-delete="/admin/bookmarks/#{bookmark.id}" hx-target="#bookmark-#{bookmark.id}" delete button class="text-red-600" hx-delete="/admin/bookmarks/#{bookmark.id}" hx-target="#bookmark-#{bookmark.id}" delete
td td
button hx-post="/admin/bookmarks/#{bookmark.id}/archive" archive button hx-post="/admin/bookmarks/#{bookmark.id}/archive" archive
td
- if bookmark.is_read
button hx-post="/admin/bookmarks/#{bookmark.id}/mark_unread" mark unread
- else
button hx-post="/admin/bookmarks/#{bookmark.id}/mark_read" mark read
tbody class="{ 'active': activeTab === 1 }" x-show.transition.in.opacity.duration.600="activeTab === 1" tbody class="{ 'active': activeTab === 1 }" x-show.transition.in.opacity.duration.600="activeTab === 1"
- unpublished_bookmarks.each do |bookmark| - unpublished_bookmarks.each do |bookmark|
tr id="bookmark-#{bookmark.id}" tr id="bookmark-#{bookmark.id}"