🔒 (notes): 新想法默认私有,设置里可改可见范围

公开和仅关注只对新想法生效。已有想法沿用原来记下的范围。
This commit is contained in:
Garfield committed 2026-12-01 15:37:10 +08:00
1 parent 352ee1bd99
commit 338e2d2d3c
10 files changed
+207 -61

No files matched your search

@@ -328,23 +328,30 @@ function Push:updates()
end, function() self:reviews() end)
end
--- 发表或修改之后读回 ``review.isPrivate``。对不上就停,不把 HTTP 成功当成私密已生效。
--- 发表或修改之后读回可见范围。对不上就停,不把 HTTP 成功当成已经按设置生效。
---@param item table
---@param wanted integer
---@param wanted_private integer|nil
---@param wanted_friendship integer|nil
---@param next fun()
function Push:confirmPrivate(item, wanted, next)
item.wr_private = wanted
function Push:confirmPrivate(item, wanted_private, wanted_friendship, next)
if wanted_private ~= nil then item.wr_private = wanted_private end
if wanted_friendship ~= nil then item.wr_friendship = wanted_friendship end
item.wr_update_review = true
self:call(function(done)
return self.client:reviewSingleAsync(item.wr_review_id, 0, 1, done)
end, _("无法确认想法是否私密"), function(wire)
local got = Notes.privateOf(wire)
if got == nil then
local got_friendship = Notes.friendshipOf(wire)
if wanted_private ~= nil and got == nil then
self:finish(nil, _("无法确认想法是否私密"))
return
end
item.wr_private = got
if got ~= wanted then
if wanted_friendship ~= nil and got_friendship == nil then got_friendship = 0 end
local mismatch = (wanted_private ~= nil and got ~= wanted_private)
or (wanted_friendship ~= nil and got_friendship ~= wanted_friendship)
if got ~= nil then item.wr_private = got end
if Notes.friendshipOf(wire) ~= nil then item.wr_friendship = Notes.friendshipOf(wire) end
if mismatch then
item.wr_update_review = nil
self:finish(nil, _("想法的可见范围没有按设置保存"))
return
@@ -354,11 +361,20 @@ function Push:confirmPrivate(item, wanted, next)
end)
end
--- 串行推想法:已有 reviewId 走 edit,否则 add。新想法先读这本书是不是私密阅读。
--- 设置里的想法默认范围。没设过或值不对就是私有。
---@return string
function Push:noteVisibility()
local choice = require("utils.settings").getSource("weread").note_visibility
if choice == "public" or choice == "follow" then return choice end
return "private"
end
--- 串行推想法:已有 reviewId 走 edit,否则 add。
function Push:reviews()
local function submit()
local deferred = false
local secret = Context.bookSecret(self.book_id)
local choice = self:noteVisibility()
self:each(Notes.notePushCandidates(self.annotations), function(item, next)
if not item.wr_review_id and self.reviews_unknown then
deferred = true
@@ -372,10 +388,10 @@ function Push:reviews()
local body, body_err
local send
if item.wr_review_id then
body, body_err = Notes.toReviewEditBody(self.book_id, self.chapter_uid, item, secret)
body, body_err = Notes.toReviewEditBody(self.book_id, self.chapter_uid, item, secret, choice)
send = function(done) return self.client:editReviewAsync(body, done) end
else
body, body_err = Notes.toReviewBody(self.book_id, self.chapter_uid, item, secret)
body, body_err = Notes.toReviewBody(self.book_id, self.chapter_uid, item, secret, choice)
send = function(done) return self.client:addReviewAsync(body, done) end
end
if not body then
@@ -391,12 +407,12 @@ function Push:reviews()
end
item.wr_review_id = review_id
end
if body.isPrivate == nil then
if body.isPrivate == nil and body.friendship == nil then
item.wr_update_review = nil
next()
return
end
self:confirmPrivate(item, body.isPrivate, next)
self:confirmPrivate(item, body.isPrivate, body.friendship, next)
end)
end, function()
if deferred then
@@ -406,28 +422,6 @@ function Push:reviews()
end
end)
end
local needs_secret = false
if not self.reviews_unknown then
for _idx, item in ipairs(Notes.notePushCandidates(self.annotations)) do
if not item.wr_review_id and item.wr_private ~= 0 and item.wr_private ~= 1 then
needs_secret = true
break
end
end
end
if needs_secret and Context.bookSecret(self.book_id) == nil then
self:call(function(done)
return self.client:bookInfoAsync(self.book_id, done)
end, _("书籍详情为空"), function(wire)
Context.rememberBook(self.book_id, wire)
if Context.bookSecret(self.book_id) == nil then
self:finish(nil, _("书籍详情为空"))
return
end
submit()
end)
return
end
submit()
end