🔒 (notes): 新想法默认私有,设置里可改可见范围
公开和仅关注只对新想法生效。已有想法沿用原来记下的范围。
This commit is contained in:
1 parent
352ee1bd99
commit
338e2d2d3c
10 files changed
+207
-61
No files matched your search
@@ -11,7 +11,7 @@
|
|||||||
| 阅读进度同步 | 支持 | 开书比较云端位置;本地先落盘,阅读中合并推送,离线保留待同步数据 |
|
| 阅读进度同步 | 支持 | 开书比较云端位置;本地先落盘,阅读中合并推送,离线保留待同步数据 |
|
||||||
| 阅读时长同步 | 支持 | 上传本地采集时长及补报数据 |
|
| 阅读时长同步 | 支持 | 上传本地采集时长及补报数据 |
|
||||||
| 维持官网「在读」状态 | 已实现,未实测 | 零时长 Web 心跳,不重复增加阅读时长 |
|
| 维持官网「在读」状态 | 已实现,未实测 | 零时长 Web 心跳,不重复增加阅读时长 |
|
||||||
| 划线与想法同步 | 支持 | 新想法按这本书的私密阅读设置带 isPrivate;修改已有想法沿用原来的可见范围,并回读确认 |
|
| 划线与想法同步 | 支持 | 新想法默认私有,设置里可改成公开或仅关注。修改已有想法沿用原来的范围,并回读确认 |
|
||||||
| 整书书评与独立章评 | 不支持 | 未接入可验证接口,不能把其他书籍的想法当作属主书评 |
|
| 整书书评与独立章评 | 不支持 | 未接入可验证接口,不能把其他书籍的想法当作属主书评 |
|
||||||
| 段评与回复 | 支持 | 按章节及文本范围定位,使用公共评论标记和列表 |
|
| 段评与回复 | 支持 | 按章节及文本范围定位,使用公共评论标记和列表 |
|
||||||
| 离线阅读 | 支持 | 已下载内容和本地记录可用;联网后再同步 |
|
| 离线阅读 | 支持 | 已下载内容和本地记录可用;联网后再同步 |
|
||||||
|
|||||||
@@ -24,6 +24,11 @@ return {
|
|||||||
["试读结束"] = "Trial ended",
|
["试读结束"] = "Trial ended",
|
||||||
["想法上传失败"] = "Failed to upload note",
|
["想法上传失败"] = "Failed to upload note",
|
||||||
["想法上传成功但缺少 reviewId"] = "Note upload succeeded without a reviewId",
|
["想法上传成功但缺少 reviewId"] = "Note upload succeeded without a reviewId",
|
||||||
|
["想法默认可见"] = "Default note visibility",
|
||||||
|
["公开"] = "Public",
|
||||||
|
["仅关注"] = "Mutuals only",
|
||||||
|
["私有"] = "Private",
|
||||||
|
["点按切换。仅关注是互相关注可见,只影响新想法"] = "Tap to change. Mutuals only means visible to people you follow each other. New notes only",
|
||||||
["无法确认想法是否私密"] = "Cannot confirm whether the note is private",
|
["无法确认想法是否私密"] = "Cannot confirm whether the note is private",
|
||||||
["想法的可见范围没有按设置保存"] = "The note visibility was not saved as requested",
|
["想法的可见范围没有按设置保存"] = "The note visibility was not saved as requested",
|
||||||
["按章书籍请打开章节后同步划线"] = "Open a chapter first to sync highlights",
|
["按章书籍请打开章节后同步划线"] = "Open a chapter first to sync highlights",
|
||||||
|
|||||||
@@ -24,6 +24,11 @@ return {
|
|||||||
["试读结束"] = "試讀結束",
|
["试读结束"] = "試讀結束",
|
||||||
["想法上传失败"] = "想法上傳失敗",
|
["想法上传失败"] = "想法上傳失敗",
|
||||||
["想法上传成功但缺少 reviewId"] = "想法上傳成功但缺少 reviewId",
|
["想法上传成功但缺少 reviewId"] = "想法上傳成功但缺少 reviewId",
|
||||||
|
["想法默认可见"] = "想法預設可見",
|
||||||
|
["公开"] = "公開",
|
||||||
|
["仅关注"] = "僅關注",
|
||||||
|
["私有"] = "私有",
|
||||||
|
["点按切换。仅关注是互相关注可见,只影响新想法"] = "點按切換。僅關注是互相關注可見,只影響新想法",
|
||||||
["无法确认想法是否私密"] = "無法確認想法是否私密",
|
["无法确认想法是否私密"] = "無法確認想法是否私密",
|
||||||
["想法的可见范围没有按设置保存"] = "想法的可見範圍沒有按設定保存",
|
["想法的可见范围没有按设置保存"] = "想法的可見範圍沒有按設定保存",
|
||||||
["按章书籍请打开章节后同步划线"] = "分章書籍請開啟章節後再同步劃線",
|
["按章书籍请打开章节后同步划线"] = "分章書籍請開啟章節後再同步劃線",
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ local LOCAL_COLOR = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
local WR_FIELDS = {
|
local WR_FIELDS = {
|
||||||
"wr_range", "wr_bookmark_id", "wr_review_id", "wr_review_only", "wr_private",
|
"wr_range", "wr_bookmark_id", "wr_review_id", "wr_review_only", "wr_private", "wr_friendship",
|
||||||
"wr_delete_review", "wr_update_review", "wr_update_bookmark",
|
"wr_delete_review", "wr_update_review", "wr_update_bookmark",
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -48,6 +48,7 @@ local WR_FIELDS = {
|
|||||||
---@field wr_range string|nil
|
---@field wr_range string|nil
|
||||||
---@field wr_review_id string|number|nil
|
---@field wr_review_id string|number|nil
|
||||||
---@field wr_private integer|nil 0 公开,1 仅自己可见
|
---@field wr_private integer|nil 0 公开,1 仅自己可见
|
||||||
|
---@field wr_friendship integer|nil 1 仅互相关注可见
|
||||||
---@field wr_deleted boolean|nil
|
---@field wr_deleted boolean|nil
|
||||||
---@field chapter_idx number|nil
|
---@field chapter_idx number|nil
|
||||||
---@field datetime string|nil
|
---@field datetime string|nil
|
||||||
@@ -89,17 +90,37 @@ function Notes.privateOf(review)
|
|||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
--- 发表/修改要带的 ``isPrivate``。已有想法没记过可见范围时返回 nil,请求里就不带这个字段。
|
--- 想法上的 ``friendship``:1 仅互相关注可见。没有这个字段就返回 nil。
|
||||||
---@param annotation table
|
---@param review table|nil
|
||||||
---@param book_secret integer|boolean|nil 书籍 ``secret==1`` 表示私密阅读
|
|
||||||
---@return integer|nil
|
---@return integer|nil
|
||||||
function Notes.reviewIsPrivate(annotation, book_secret)
|
function Notes.friendshipOf(review)
|
||||||
local known = annotation.wr_private
|
if type(review) ~= "table" then return nil end
|
||||||
if known == 1 or known == true then return 1 end
|
local body = type(review.review) == "table" and review.review or review
|
||||||
if known == 0 or known == false then return 0 end
|
local flag = body.friendship
|
||||||
if annotation.wr_review_id ~= nil then return nil end
|
if flag == 1 or flag == true then return 1 end
|
||||||
if book_secret == 1 or book_secret == true then return 1 end
|
if flag == 0 or flag == false then return 0 end
|
||||||
return 0
|
return nil
|
||||||
|
end
|
||||||
|
|
||||||
|
--- 发表/修改要带的可见范围。已有想法没记过时两个都是 nil,请求里就不带。
|
||||||
|
--- choice 为设置项:public / follow。没设过或 private 都是私有。
|
||||||
|
---@param annotation table
|
||||||
|
---@param book_secret integer|boolean|nil 保留参数,新想法不再看私密阅读
|
||||||
|
---@param choice string|nil
|
||||||
|
---@return integer|nil is_private
|
||||||
|
---@return integer|nil friendship
|
||||||
|
function Notes.reviewFlags(annotation, book_secret, choice)
|
||||||
|
local function known(value)
|
||||||
|
if value == 1 or value == true then return 1 end
|
||||||
|
if value == 0 or value == false then return 0 end
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
local private, friendship = known(annotation.wr_private), known(annotation.wr_friendship)
|
||||||
|
if private ~= nil or friendship ~= nil then return private, friendship end
|
||||||
|
if annotation.wr_review_id ~= nil then return nil, nil end
|
||||||
|
if choice == "public" then return 0, 0 end
|
||||||
|
if choice == "follow" then return 0, 1 end
|
||||||
|
return 1, 0
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param items table[]|nil
|
---@param items table[]|nil
|
||||||
@@ -482,6 +503,10 @@ function Notes.reconcileReviews(annotations, wire)
|
|||||||
local private = Notes.privateOf(review)
|
local private = Notes.privateOf(review)
|
||||||
if private ~= nil then item.wr_private = private end
|
if private ~= nil then item.wr_private = private end
|
||||||
end
|
end
|
||||||
|
if item.wr_friendship ~= 0 and item.wr_friendship ~= 1 then
|
||||||
|
local friendship = Notes.friendshipOf(review)
|
||||||
|
if friendship ~= nil then item.wr_friendship = friendship end
|
||||||
|
end
|
||||||
confirmed[item] = true
|
confirmed[item] = true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -549,6 +574,8 @@ function Notes.toAnnotations(wire, chapter_uid, reviews, source_id, stable_id)
|
|||||||
ann.wr_review_id = review and review.reviewId or nil
|
ann.wr_review_id = review and review.reviewId or nil
|
||||||
local private = review and Notes.privateOf(review) or nil
|
local private = review and Notes.privateOf(review) or nil
|
||||||
if private ~= nil then ann.wr_private = private end
|
if private ~= nil then ann.wr_private = private end
|
||||||
|
local friendship = review and Notes.friendshipOf(review) or nil
|
||||||
|
if friendship ~= nil then ann.wr_friendship = friendship end
|
||||||
out[#out + 1] = ann
|
out[#out + 1] = ann
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -572,6 +599,8 @@ function Notes.toAnnotations(wire, chapter_uid, reviews, source_id, stable_id)
|
|||||||
ann.wr_review_id = review.reviewId or entry.reviewId
|
ann.wr_review_id = review.reviewId or entry.reviewId
|
||||||
local private = Notes.privateOf(review)
|
local private = Notes.privateOf(review)
|
||||||
if private ~= nil then ann.wr_private = private end
|
if private ~= nil then ann.wr_private = private end
|
||||||
|
local friendship = Notes.friendshipOf(review)
|
||||||
|
if friendship ~= nil then ann.wr_friendship = friendship end
|
||||||
ann.wr_review_only = true
|
ann.wr_review_only = true
|
||||||
out[#out + 1] = ann
|
out[#out + 1] = ann
|
||||||
end
|
end
|
||||||
@@ -595,7 +624,8 @@ function Notes.keepLocalReviews(annotations, local_items)
|
|||||||
if type(old) == "table" and old.wr_review_id and not known[tostring(old.wr_review_id)] then
|
if type(old) == "table" and old.wr_review_id and not known[tostring(old.wr_review_id)] then
|
||||||
local ann = old.wr_bookmark_id and by_bookmark[tostring(old.wr_bookmark_id)] or nil
|
local ann = old.wr_bookmark_id and by_bookmark[tostring(old.wr_bookmark_id)] or nil
|
||||||
if ann then
|
if ann then
|
||||||
ann.note, ann.wr_review_id, ann.wr_private = old.note, old.wr_review_id, old.wr_private
|
ann.note, ann.wr_review_id = old.note, old.wr_review_id
|
||||||
|
ann.wr_private, ann.wr_friendship = old.wr_private, old.wr_friendship
|
||||||
elseif old.wr_review_only then
|
elseif old.wr_review_only then
|
||||||
annotations[#annotations + 1] = old
|
annotations[#annotations + 1] = old
|
||||||
end
|
end
|
||||||
@@ -707,14 +737,15 @@ function Notes.toBookmarkUpdateBody(annotation)
|
|||||||
end
|
end
|
||||||
|
|
||||||
--- KOReader 注解 → ``/review/add`` 请求体。
|
--- KOReader 注解 → ``/review/add`` 请求体。
|
||||||
--- 新想法:私密阅读的书 ``isPrivate=1``,否则 ``0``。已有想法沿用 ``wr_private``。
|
--- 新想法按设置项;没设过时私有。已有想法沿用记下来的范围。
|
||||||
---@param book_id string
|
---@param book_id string
|
||||||
---@param chapter_uid string|number
|
---@param chapter_uid string|number
|
||||||
---@param annotation table
|
---@param annotation table
|
||||||
---@param book_secret integer|boolean|nil
|
---@param book_secret integer|boolean|nil
|
||||||
|
---@param choice string|nil public / private / follow
|
||||||
---@return table|nil body
|
---@return table|nil body
|
||||||
---@return string|nil err
|
---@return string|nil err
|
||||||
function Notes.toReviewBody(book_id, chapter_uid, annotation, book_secret)
|
function Notes.toReviewBody(book_id, chapter_uid, annotation, book_secret, choice)
|
||||||
local content = annotation.note
|
local content = annotation.note
|
||||||
if type(content) ~= "string" or content == "" then
|
if type(content) ~= "string" or content == "" then
|
||||||
return nil, "empty note"
|
return nil, "empty note"
|
||||||
@@ -735,8 +766,9 @@ function Notes.toReviewBody(book_id, chapter_uid, annotation, book_secret)
|
|||||||
abstract = abstract,
|
abstract = abstract,
|
||||||
chapterUid = tonumber(chapter_uid) or chapter_uid,
|
chapterUid = tonumber(chapter_uid) or chapter_uid,
|
||||||
}
|
}
|
||||||
local private = Notes.reviewIsPrivate(annotation, book_secret)
|
local private, friendship = Notes.reviewFlags(annotation, book_secret, choice)
|
||||||
if private ~= nil then body.isPrivate = private end
|
if private ~= nil then body.isPrivate = private end
|
||||||
|
if friendship ~= nil then body.friendship = friendship end
|
||||||
return body, nil
|
return body, nil
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -745,14 +777,15 @@ end
|
|||||||
---@param chapter_uid string|number
|
---@param chapter_uid string|number
|
||||||
---@param annotation table
|
---@param annotation table
|
||||||
---@param book_secret integer|boolean|nil
|
---@param book_secret integer|boolean|nil
|
||||||
|
---@param choice string|nil
|
||||||
---@return table|nil body
|
---@return table|nil body
|
||||||
---@return string|nil err
|
---@return string|nil err
|
||||||
function Notes.toReviewEditBody(book_id, chapter_uid, annotation, book_secret)
|
function Notes.toReviewEditBody(book_id, chapter_uid, annotation, book_secret, choice)
|
||||||
local review_id = annotation.wr_review_id
|
local review_id = annotation.wr_review_id
|
||||||
if type(review_id) ~= "string" and type(review_id) ~= "number" then
|
if type(review_id) ~= "string" and type(review_id) ~= "number" then
|
||||||
return nil, "missing review id"
|
return nil, "missing review id"
|
||||||
end
|
end
|
||||||
local body, err = Notes.toReviewBody(book_id, chapter_uid, annotation, book_secret)
|
local body, err = Notes.toReviewBody(book_id, chapter_uid, annotation, book_secret, choice)
|
||||||
if not body then return nil, err end
|
if not body then return nil, err end
|
||||||
body.reviewId = tostring(review_id)
|
body.reviewId = tostring(review_id)
|
||||||
return body, nil
|
return body, nil
|
||||||
|
|||||||
@@ -328,23 +328,30 @@ function Push:updates()
|
|||||||
end, function() self:reviews() end)
|
end, function() self:reviews() end)
|
||||||
end
|
end
|
||||||
|
|
||||||
--- 发表或修改之后读回 ``review.isPrivate``。对不上就停,不把 HTTP 成功当成私密已生效。
|
--- 发表或修改之后读回可见范围。对不上就停,不把 HTTP 成功当成已经按设置生效。
|
||||||
---@param item table
|
---@param item table
|
||||||
---@param wanted integer
|
---@param wanted_private integer|nil
|
||||||
|
---@param wanted_friendship integer|nil
|
||||||
---@param next fun()
|
---@param next fun()
|
||||||
function Push:confirmPrivate(item, wanted, next)
|
function Push:confirmPrivate(item, wanted_private, wanted_friendship, next)
|
||||||
item.wr_private = wanted
|
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
|
item.wr_update_review = true
|
||||||
self:call(function(done)
|
self:call(function(done)
|
||||||
return self.client:reviewSingleAsync(item.wr_review_id, 0, 1, done)
|
return self.client:reviewSingleAsync(item.wr_review_id, 0, 1, done)
|
||||||
end, _("无法确认想法是否私密"), function(wire)
|
end, _("无法确认想法是否私密"), function(wire)
|
||||||
local got = Notes.privateOf(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, _("无法确认想法是否私密"))
|
self:finish(nil, _("无法确认想法是否私密"))
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
item.wr_private = got
|
if wanted_friendship ~= nil and got_friendship == nil then got_friendship = 0 end
|
||||||
if got ~= wanted then
|
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
|
item.wr_update_review = nil
|
||||||
self:finish(nil, _("想法的可见范围没有按设置保存"))
|
self:finish(nil, _("想法的可见范围没有按设置保存"))
|
||||||
return
|
return
|
||||||
@@ -354,11 +361,20 @@ function Push:confirmPrivate(item, wanted, next)
|
|||||||
end)
|
end)
|
||||||
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()
|
function Push:reviews()
|
||||||
local function submit()
|
local function submit()
|
||||||
local deferred = false
|
local deferred = false
|
||||||
local secret = Context.bookSecret(self.book_id)
|
local secret = Context.bookSecret(self.book_id)
|
||||||
|
local choice = self:noteVisibility()
|
||||||
self:each(Notes.notePushCandidates(self.annotations), function(item, next)
|
self:each(Notes.notePushCandidates(self.annotations), function(item, next)
|
||||||
if not item.wr_review_id and self.reviews_unknown then
|
if not item.wr_review_id and self.reviews_unknown then
|
||||||
deferred = true
|
deferred = true
|
||||||
@@ -372,10 +388,10 @@ function Push:reviews()
|
|||||||
local body, body_err
|
local body, body_err
|
||||||
local send
|
local send
|
||||||
if item.wr_review_id then
|
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
|
send = function(done) return self.client:editReviewAsync(body, done) end
|
||||||
else
|
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
|
send = function(done) return self.client:addReviewAsync(body, done) end
|
||||||
end
|
end
|
||||||
if not body then
|
if not body then
|
||||||
@@ -391,12 +407,12 @@ function Push:reviews()
|
|||||||
end
|
end
|
||||||
item.wr_review_id = review_id
|
item.wr_review_id = review_id
|
||||||
end
|
end
|
||||||
if body.isPrivate == nil then
|
if body.isPrivate == nil and body.friendship == nil then
|
||||||
item.wr_update_review = nil
|
item.wr_update_review = nil
|
||||||
next()
|
next()
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
self:confirmPrivate(item, body.isPrivate, next)
|
self:confirmPrivate(item, body.isPrivate, body.friendship, next)
|
||||||
end)
|
end)
|
||||||
end, function()
|
end, function()
|
||||||
if deferred then
|
if deferred then
|
||||||
@@ -406,28 +422,6 @@ function Push:reviews()
|
|||||||
end
|
end
|
||||||
end)
|
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()
|
submit()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -159,6 +159,31 @@ function Setting.rows(plugin)
|
|||||||
toggle("merge_local_stats", false, "history", _("合并本地阅读时长"),
|
toggle("merge_local_stats", false, "history", _("合并本地阅读时长"),
|
||||||
_("关闭时以云端为准;打开后每天取云端与本地中较大的,补上离线阅读。只影响月读里的统计"))
|
_("关闭时以云端为准;打开后每天取云端与本地中较大的,补上离线阅读。只影响月读里的统计"))
|
||||||
toggle("show_paragraph_reviews", false, "forum", _("显示段评"), _("阅读时给有他人段评的句子画线,点按查看;需联网"))
|
toggle("show_paragraph_reviews", false, "forum", _("显示段评"), _("阅读时给有他人段评的句子画线,点按查看;需联网"))
|
||||||
|
local visibility = {
|
||||||
|
{ value = "private", label = _("私有") },
|
||||||
|
{ value = "public", label = _("公开") },
|
||||||
|
{ value = "follow", label = _("仅关注") },
|
||||||
|
}
|
||||||
|
rows[#rows + 1] = function(iw)
|
||||||
|
local cfg = Settings.getSource(SOURCE_ID)
|
||||||
|
local current = cfg.note_visibility
|
||||||
|
if current ~= "public" and current ~= "follow" then current = "private" end
|
||||||
|
local index = 1
|
||||||
|
for i, item in ipairs(visibility) do
|
||||||
|
if item.value == current then index = i end
|
||||||
|
end
|
||||||
|
return Row.widget({ width = iw, chevron = false, kind = "action", icon = "lock",
|
||||||
|
title = _("想法默认可见"),
|
||||||
|
subtitle = _("点按切换。仅关注是互相关注可见,只影响新想法"),
|
||||||
|
status = visibility[index].label,
|
||||||
|
status_on = current ~= "public",
|
||||||
|
callback = function()
|
||||||
|
local next_item = visibility[index % #visibility + 1]
|
||||||
|
cfg.note_visibility = next_item.value
|
||||||
|
Settings.saveSource(SOURCE_ID, cfg)
|
||||||
|
if plugin and plugin.desktop then plugin.desktop:updateView() end
|
||||||
|
end })
|
||||||
|
end
|
||||||
rows[#rows + 1] = require("source.category_setting").row(SOURCE_ID, plugin)
|
rows[#rows + 1] = require("source.category_setting").row(SOURCE_ID, plugin)
|
||||||
if not Auth.hasSession() then return rows end
|
if not Auth.hasSession() then return rows end
|
||||||
rows[#rows + 1] = function(iw)
|
rows[#rows + 1] = function(iw)
|
||||||
|
|||||||
@@ -287,3 +287,46 @@ do -- 没记过可见范围的旧想法:修改不带 isPrivate,也不回读
|
|||||||
Assert.is_true(name ~= "reviewSingleAsync")
|
Assert.is_true(name ~= "reviewSingleAsync")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
do -- 设置成仅关注:新想法带 friendship,不再读私密阅读
|
||||||
|
require("moonsource_weread.context").clear()
|
||||||
|
local Settings = require("utils.settings")
|
||||||
|
local cfg = Settings.getSource("weread")
|
||||||
|
local old = cfg.note_visibility
|
||||||
|
cfg.note_visibility = "follow"
|
||||||
|
Settings.saveSource("weread", cfg)
|
||||||
|
local Toc = require("moonsource_weread.toc")
|
||||||
|
local Position = require("moonsource_weread.progress")
|
||||||
|
local old_read, old_load = Toc.read, Position.loadAsync
|
||||||
|
Toc.read = function() return { { uid = "c1" } } end
|
||||||
|
Position.loadAsync = function(_identity, _chapter, cb)
|
||||||
|
cb("<html><body><p>原文</p></body></html>", "html")
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
local item = {
|
||||||
|
drawer = "lighten", text = "原文", note = "给关注的人",
|
||||||
|
wr_range = "1-2", wr_review_only = true,
|
||||||
|
pos0 = "/html/body/p/text().0", pos1 = "/html/body/p/text().2",
|
||||||
|
}
|
||||||
|
local client = fakeClient({
|
||||||
|
bookmarkListAsync = { updated = {} },
|
||||||
|
myReviewsAsync = { reviews = {}, hasMore = 0, totalCount = 0 },
|
||||||
|
addReviewAsync = { reviewId = "rv-follow" },
|
||||||
|
reviewSingleAsync = { review = { isPrivate = 0, friendship = 1 } },
|
||||||
|
})
|
||||||
|
local ok, err
|
||||||
|
NotesPush.run(client, identity, "c1",
|
||||||
|
"<html><body><p>原文</p></body></html>", { item }, function(o, e) ok, err = o, e end)
|
||||||
|
Stubs.flush()
|
||||||
|
Toc.read, Position.loadAsync = old_read, old_load
|
||||||
|
cfg.note_visibility = old
|
||||||
|
Settings.saveSource("weread", cfg)
|
||||||
|
Assert.is_true(ok, tostring(err))
|
||||||
|
Assert.eq(client.sent.addReviewAsync[1].isPrivate, 0)
|
||||||
|
Assert.eq(client.sent.addReviewAsync[1].friendship, 1)
|
||||||
|
Assert.eq(item.wr_friendship, 1)
|
||||||
|
Assert.eq(item.wr_private, 0)
|
||||||
|
for _, name in ipairs(client.calls) do
|
||||||
|
Assert.is_true(name ~= "bookInfoAsync", "设置了范围就不必再读私密阅读")
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -58,9 +58,9 @@ local Setting = require("moonsource_weread.setting")
|
|||||||
local updates = 0
|
local updates = 0
|
||||||
local plugin = { desktop = { updateView = function() updates = updates + 1 end } }
|
local plugin = { desktop = { updateView = function() updates = updates + 1 end } }
|
||||||
|
|
||||||
-- 未登录:账号、合并本地阅读时长、显示段评、自定义分组代替分类四行。
|
-- 未登录:账号、合并时长、段评、想法可见范围、自定义分组五行。
|
||||||
local rows = Setting.rows(plugin)
|
local rows = Setting.rows(plugin)
|
||||||
Assert.len(rows, 4)
|
Assert.len(rows, 5)
|
||||||
Assert.eq(rows[1]().status, "未登录 · 点此扫码")
|
Assert.eq(rows[1]().status, "未登录 · 点此扫码")
|
||||||
|
|
||||||
-- 合并本地阅读时长默认关(云端优先);点按落盘开启并刷新设置页。
|
-- 合并本地阅读时长默认关(云端优先);点按落盘开启并刷新设置页。
|
||||||
@@ -82,23 +82,38 @@ reviews.callback()
|
|||||||
Assert.is_true(cfg.show_paragraph_reviews)
|
Assert.is_true(cfg.show_paragraph_reviews)
|
||||||
Assert.is_true(rows[3]().status_on)
|
Assert.is_true(rows[3]().status_on)
|
||||||
|
|
||||||
|
-- 想法默认可见:没设过是私有,点按在公开、仅关注、私有之间循环。
|
||||||
|
local visibility = rows[4]()
|
||||||
|
Assert.eq(visibility.title, "想法默认可见")
|
||||||
|
Assert.eq(visibility.status, "私有")
|
||||||
|
Assert.is_nil(cfg.note_visibility)
|
||||||
|
visibility.callback()
|
||||||
|
Assert.eq(cfg.note_visibility, "public")
|
||||||
|
Assert.eq(rows[4]().status, "公开")
|
||||||
|
rows[4]().callback()
|
||||||
|
Assert.eq(cfg.note_visibility, "follow")
|
||||||
|
Assert.eq(rows[4]().status, "仅关注")
|
||||||
|
rows[4]().callback()
|
||||||
|
Assert.eq(cfg.note_visibility, "private")
|
||||||
|
Assert.eq(rows[4]().status, "私有")
|
||||||
|
|
||||||
-- 自定义分组代替分类默认开;点按关闭并清增量游标。
|
-- 自定义分组代替分类默认开;点按关闭并清增量游标。
|
||||||
local groups = rows[4]()
|
local groups = rows[5]()
|
||||||
Assert.eq(groups.title, "使用自定义分组代替分类")
|
Assert.eq(groups.title, "使用自定义分组代替分类")
|
||||||
Assert.is_true(groups.status_on)
|
Assert.is_true(groups.status_on)
|
||||||
cfg.shelf_cursor = { vid = "1", synckey = 9 }
|
cfg.shelf_cursor = { vid = "1", synckey = 9 }
|
||||||
groups.callback()
|
groups.callback()
|
||||||
Assert.is_false(cfg.category_as_group)
|
Assert.is_false(cfg.category_as_group)
|
||||||
Assert.is_nil(cfg.shelf_cursor)
|
Assert.is_nil(cfg.shelf_cursor)
|
||||||
Assert.is_false(rows[4]().status_on)
|
Assert.is_false(rows[5]().status_on)
|
||||||
|
|
||||||
-- 已登录:追加续期与退出;退出先确认,确认后才清会话。
|
-- 已登录:追加续期与退出;退出先确认,确认后才清会话。
|
||||||
logged_in = true
|
logged_in = true
|
||||||
rows = Setting.rows(plugin)
|
rows = Setting.rows(plugin)
|
||||||
Assert.len(rows, 6)
|
Assert.len(rows, 7)
|
||||||
Assert.eq(rows[1]().status, "tester")
|
Assert.eq(rows[1]().status, "tester")
|
||||||
Assert.eq(rows[5]().title, "续期会话")
|
Assert.eq(rows[6]().title, "续期会话")
|
||||||
local logout = rows[6]()
|
local logout = rows[7]()
|
||||||
Assert.eq(logout.title, "退出登录")
|
Assert.eq(logout.title, "退出登录")
|
||||||
logout.callback()
|
logout.callback()
|
||||||
Assert.is_false(cleared, "未确认不退出")
|
Assert.is_false(cleared, "未确认不退出")
|
||||||
|
|||||||
@@ -357,7 +357,8 @@ do
|
|||||||
Assert.eq(review_body.abstract, "原文")
|
Assert.eq(review_body.abstract, "原文")
|
||||||
Assert.eq(review_body.range, "0-5")
|
Assert.eq(review_body.range, "0-5")
|
||||||
Assert.eq(review_body.chapterUid, 9)
|
Assert.eq(review_body.chapterUid, 9)
|
||||||
Assert.eq(review_body.isPrivate, 0, "非私密阅读的新想法明确公开")
|
Assert.eq(review_body.isPrivate, 1, "没选过时新想法默认私有")
|
||||||
|
Assert.eq(review_body.friendship, 0)
|
||||||
local secret_body = Notes.toReviewBody("1", 9, {
|
local secret_body = Notes.toReviewBody("1", 9, {
|
||||||
note = "想法", text = "原文", wr_range = "0-5",
|
note = "想法", text = "原文", wr_range = "0-5",
|
||||||
}, 1)
|
}, 1)
|
||||||
@@ -374,7 +375,24 @@ do
|
|||||||
note = "想法", text = "原文", wr_range = "0-5", wr_review_id = "rv1", wr_private = 1,
|
note = "想法", text = "原文", wr_range = "0-5", wr_review_id = "rv1", wr_private = 1,
|
||||||
}, 0)
|
}, 0)
|
||||||
Assert.eq(edit_private.isPrivate, 1)
|
Assert.eq(edit_private.isPrivate, 1)
|
||||||
|
Assert.is_nil(edit_private.friendship, "只记过私有时不改关注范围")
|
||||||
Assert.eq(edit_private.reviewId, "rv1")
|
Assert.eq(edit_private.reviewId, "rv1")
|
||||||
|
local chosen_public = Notes.toReviewBody("1", 9, {
|
||||||
|
note = "想法", text = "原文", wr_range = "0-5",
|
||||||
|
}, 1, "public")
|
||||||
|
Assert.eq(chosen_public.isPrivate, 0)
|
||||||
|
Assert.eq(chosen_public.friendship, 0)
|
||||||
|
local chosen_follow = Notes.toReviewBody("1", 9, {
|
||||||
|
note = "想法", text = "原文", wr_range = "0-5",
|
||||||
|
}, 0, "follow")
|
||||||
|
Assert.eq(chosen_follow.isPrivate, 0)
|
||||||
|
Assert.eq(chosen_follow.friendship, 1)
|
||||||
|
local kept_follow = Notes.toReviewEditBody("1", 9, {
|
||||||
|
note = "想法", text = "原文", wr_range = "0-5", wr_review_id = "rv1",
|
||||||
|
wr_private = 0, wr_friendship = 1,
|
||||||
|
}, 0, "public")
|
||||||
|
Assert.eq(kept_follow.friendship, 1, "已有想法的范围不被设置项改掉")
|
||||||
|
Assert.eq(kept_follow.isPrivate, 0)
|
||||||
local pulled_private = Notes.toAnnotations({ updated = {} }, "9", {
|
local pulled_private = Notes.toAnnotations({ updated = {} }, "9", {
|
||||||
reviews = { { review = {
|
reviews = { { review = {
|
||||||
reviewId = "rv-p", chapterUid = "9", range = "0-1",
|
reviewId = "rv-p", chapterUid = "9", range = "0-1",
|
||||||
@@ -382,6 +400,14 @@ do
|
|||||||
} } },
|
} } },
|
||||||
})
|
})
|
||||||
Assert.eq(pulled_private[1].wr_private, 1)
|
Assert.eq(pulled_private[1].wr_private, 1)
|
||||||
|
local pulled_follow = Notes.toAnnotations({ updated = {} }, "9", {
|
||||||
|
reviews = { { review = {
|
||||||
|
reviewId = "rv-f", chapterUid = "9", range = "0-1",
|
||||||
|
abstract = "原文", content = "关注", isPrivate = 0, friendship = 1,
|
||||||
|
} } },
|
||||||
|
})
|
||||||
|
Assert.eq(pulled_follow[1].wr_friendship, 1)
|
||||||
|
Assert.eq(pulled_follow[1].wr_private, 0)
|
||||||
local reconciled = { note = "想法", text = "原文", wr_range = "0-5", wr_review_id = "rv1" }
|
local reconciled = { note = "想法", text = "原文", wr_range = "0-5", wr_review_id = "rv1" }
|
||||||
Notes.reconcileReviews({ reconciled }, {
|
Notes.reconcileReviews({ reconciled }, {
|
||||||
reviews = { { review = { reviewId = "rv1", isPrivate = 1, range = "0-5", abstract = "原文", content = "想法" } } },
|
reviews = { { review = { reviewId = "rv1", isPrivate = 1, range = "0-5", abstract = "原文", content = "想法" } } },
|
||||||
|
|||||||
@@ -1085,7 +1085,7 @@ do
|
|||||||
return { cancel = function() end }
|
return { cancel = function() end }
|
||||||
end
|
end
|
||||||
fake_client.reviewSingleAsync = function(_, _, _, _, cb)
|
fake_client.reviewSingleAsync = function(_, _, _, _, cb)
|
||||||
cb({ review = { isPrivate = 0 } })
|
cb({ review = { isPrivate = 1 } })
|
||||||
return { cancel = function() end }
|
return { cancel = function() end }
|
||||||
end
|
end
|
||||||
fake_client.deleteReviewAsync = function(_, review_id, cb)
|
fake_client.deleteReviewAsync = function(_, review_id, cb)
|
||||||
|
|||||||
Reference in new issue
Block a user