🐛 (notes): 想法按私密阅读设置发表并回读

新想法跟这本书的私密阅读走,修改已有想法沿用原来的可见范围。
回读对不上就当这轮失败,不把 HTTP 成功当成已经私密。
This commit is contained in:
Garfield committed 2026-12-01 12:47:12 +08:00
1 parent 69a72f63c0
commit 352ee1bd99
11 files changed
+359 -57

No files matched your search

+123 -2
View File
@@ -13,12 +13,13 @@ local NotesPush = require("moonsource_weread.notes_push")
local function fakeClient(replies)
local calls = {}
---@type { calls: string[], [string]: any }
local client = { calls = calls }
local client = { calls = calls, sent = {} }
local function method(name)
return function(_self, ...)
local args = { ... }
local cb = args[#args]
calls[#calls + 1] = name
client.sent[name] = args
local reply = replies[name]
require("ui/uimanager"):nextTick(function()
if type(reply) == "function" then reply = reply() end
@@ -29,7 +30,7 @@ local function fakeClient(replies)
end
for _idx, name in ipairs({ "removeBookmarkAsync", "deleteReviewAsync", "bookmarkListAsync",
"myReviewsAsync", "addBookmarkAsync", "updateBookmarkAsync", "editReviewAsync",
"addReviewAsync", "bookInfoAsync" }) do
"addReviewAsync", "bookInfoAsync", "reviewSingleAsync" }) do
client[name] = method(name)
end
return client
@@ -166,3 +167,123 @@ do -- 想法清单拿不到:新想法不推(认不回上轮已成功的会
Assert.is_nil(item.wr_review_id)
for _, name in ipairs(client.calls) do Assert.is_true(name ~= "addReviewAsync", "不得重复新增想法") end
end
do -- 私密阅读的新想法带 isPrivate=1,回读确认后才算成功
require("moonsource_weread.context").clear()
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 },
bookInfoAsync = { book = { bookId = "b1", version = 1, secret = 1 } },
addReviewAsync = { reviewId = "rv-priv" },
reviewSingleAsync = { review = { reviewId = "rv-priv", isPrivate = 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
Assert.is_true(ok, tostring(err))
Assert.eq(client.sent.addReviewAsync[1].isPrivate, 1)
Assert.eq(item.wr_review_id, "rv-priv")
Assert.eq(item.wr_private, 1)
Assert.is_nil(item.wr_update_review)
end
do -- 回读不是私密:留下 reviewId,整轮失败,不再当成成功
require("moonsource_weread.context").clear()
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 },
bookInfoAsync = { book = { bookId = "b1", version = 1, secret = 1 } },
addReviewAsync = { reviewId = "rv-pub" },
reviewSingleAsync = { review = { isPrivate = 0 } },
})
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
Assert.is_nil(ok)
Assert.eq(err, "想法的可见范围没有按设置保存")
Assert.eq(item.wr_review_id, "rv-pub")
Assert.eq(item.wr_private, 0)
Assert.is_nil(item.wr_update_review)
end
do -- 改已有想法:沿用拉下来的 isPrivate,不按书籍公开设置改掉
require("moonsource_weread.context").clear()
local item = {
drawer = "lighten", text = "原文", note = "改过",
wr_range = "1-2", wr_bookmark_id = "bm1", wr_review_id = "rv1",
wr_private = 1, wr_update_review = true,
}
local client = fakeClient({
bookmarkListAsync = { updated = { {
chapterUid = "c1", range = "1-2", bookmarkId = "bm1", markText = "原文", type = 1,
} } },
myReviewsAsync = { reviews = { { review = {
reviewId = "rv1", isPrivate = 0, range = "1-2", abstract = "原文", content = "改过",
} } }, hasMore = 0, totalCount = 1 },
editReviewAsync = { succ = 1 },
reviewSingleAsync = { review = { isPrivate = 1 } },
})
local ok, err
NotesPush.run(client, identity, "c1", nil, { item }, function(o, e) ok, err = o, e end)
Stubs.flush()
Assert.is_true(ok, tostring(err))
Assert.eq(client.sent.editReviewAsync[1].isPrivate, 1)
for _, name in ipairs(client.calls) do
Assert.is_true(name ~= "bookInfoAsync", "已有可见范围不必再读私密阅读设置")
end
Assert.is_nil(item.wr_update_review)
end
do -- 没记过可见范围的旧想法:修改不带 isPrivate,也不回读
require("moonsource_weread.context").clear()
local item = {
drawer = "lighten", text = "原文", note = "改过",
wr_range = "1-2", wr_bookmark_id = "bm1", wr_review_id = "rv1",
wr_update_review = true,
}
local client = fakeClient({
bookmarkListAsync = { updated = { {
chapterUid = "c1", range = "1-2", bookmarkId = "bm1", markText = "原文", type = 1,
} } },
myReviewsAsync = { reviews = { { review = { reviewId = "rv1" } } }, hasMore = 0, totalCount = 1 },
editReviewAsync = { succ = 1 },
})
local ok, err
NotesPush.run(client, identity, "c1", nil, { item }, function(o, e) ok, err = o, e end)
Stubs.flush()
Assert.is_true(ok, tostring(err))
Assert.is_nil(client.sent.editReviewAsync[1].isPrivate)
for _, name in ipairs(client.calls) do
Assert.is_true(name ~= "reviewSingleAsync")
end
end