🔒 (notes): 新想法默认私有,设置里可改可见范围
公开和仅关注只对新想法生效。已有想法沿用原来记下的范围。
This commit is contained in:
1 parent
352ee1bd99
commit
338e2d2d3c
10 files changed
+207
-61
No files matched your search
@@ -287,3 +287,46 @@ do -- 没记过可见范围的旧想法:修改不带 isPrivate,也不回读
|
||||
Assert.is_true(name ~= "reviewSingleAsync")
|
||||
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 plugin = { desktop = { updateView = function() updates = updates + 1 end } }
|
||||
|
||||
-- 未登录:账号、合并本地阅读时长、显示段评、自定义分组代替分类四行。
|
||||
-- 未登录:账号、合并时长、段评、想法可见范围、自定义分组五行。
|
||||
local rows = Setting.rows(plugin)
|
||||
Assert.len(rows, 4)
|
||||
Assert.len(rows, 5)
|
||||
Assert.eq(rows[1]().status, "未登录 · 点此扫码")
|
||||
|
||||
-- 合并本地阅读时长默认关(云端优先);点按落盘开启并刷新设置页。
|
||||
@@ -82,23 +82,38 @@ reviews.callback()
|
||||
Assert.is_true(cfg.show_paragraph_reviews)
|
||||
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.is_true(groups.status_on)
|
||||
cfg.shelf_cursor = { vid = "1", synckey = 9 }
|
||||
groups.callback()
|
||||
Assert.is_false(cfg.category_as_group)
|
||||
Assert.is_nil(cfg.shelf_cursor)
|
||||
Assert.is_false(rows[4]().status_on)
|
||||
Assert.is_false(rows[5]().status_on)
|
||||
|
||||
-- 已登录:追加续期与退出;退出先确认,确认后才清会话。
|
||||
logged_in = true
|
||||
rows = Setting.rows(plugin)
|
||||
Assert.len(rows, 6)
|
||||
Assert.len(rows, 7)
|
||||
Assert.eq(rows[1]().status, "tester")
|
||||
Assert.eq(rows[5]().title, "续期会话")
|
||||
local logout = rows[6]()
|
||||
Assert.eq(rows[6]().title, "续期会话")
|
||||
local logout = rows[7]()
|
||||
Assert.eq(logout.title, "退出登录")
|
||||
logout.callback()
|
||||
Assert.is_false(cleared, "未确认不退出")
|
||||
|
||||
@@ -357,7 +357,8 @@ do
|
||||
Assert.eq(review_body.abstract, "原文")
|
||||
Assert.eq(review_body.range, "0-5")
|
||||
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, {
|
||||
note = "想法", text = "原文", wr_range = "0-5",
|
||||
}, 1)
|
||||
@@ -374,7 +375,24 @@ do
|
||||
note = "想法", text = "原文", wr_range = "0-5", wr_review_id = "rv1", wr_private = 1,
|
||||
}, 0)
|
||||
Assert.eq(edit_private.isPrivate, 1)
|
||||
Assert.is_nil(edit_private.friendship, "只记过私有时不改关注范围")
|
||||
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", {
|
||||
reviews = { { review = {
|
||||
reviewId = "rv-p", chapterUid = "9", range = "0-1",
|
||||
@@ -382,6 +400,14 @@ do
|
||||
} } },
|
||||
})
|
||||
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" }
|
||||
Notes.reconcileReviews({ reconciled }, {
|
||||
reviews = { { review = { reviewId = "rv1", isPrivate = 1, range = "0-5", abstract = "原文", content = "想法" } } },
|
||||
|
||||
@@ -1085,7 +1085,7 @@ do
|
||||
return { cancel = function() end }
|
||||
end
|
||||
fake_client.reviewSingleAsync = function(_, _, _, _, cb)
|
||||
cb({ review = { isPrivate = 0 } })
|
||||
cb({ review = { isPrivate = 1 } })
|
||||
return { cancel = function() end }
|
||||
end
|
||||
fake_client.deleteReviewAsync = function(_, review_id, cb)
|
||||
|
||||
Reference in new issue
Block a user