diff --git a/src/apps/web/FeedReader.h b/src/apps/web/FeedReader.h new file mode 100644 index 0000000..1b0f50e --- /dev/null +++ b/src/apps/web/FeedReader.h @@ -0,0 +1,44 @@ +#pragma once + +struct FeedReader { + struct EventInfo { + uint64_t comments = 0; + double score = 0.0; + }; + + struct FeedEvent { + uint64_t levId; + std::string id; + + EventInfo info; + }; + + tao::json::value feedJson; + + FeedReader(lmdb::txn &txn, const std::string &feedId) { + size_t pos = feedId.find("."); + if (pos == std::string_view::npos) throw herr("bad feedId"); + std::string pubkey = FeedId.substr(0, pos); + std::string adminTopic = feedId.substr(pos + 1); + + tao::json::value filter = tao::json::value({ + { "authors", tao::json::value::array({ to_hex(authorPubkey) }) }, + { "kinds", tao::json::value::array({ uint64_t(33800) }) }, + { "#d", tao::json::value::array({ adminTopic }) }, + }); + + bool found = false; + + foreachByFilter(txn, filter, [&](uint64_t levId){ + feedJson = tao::json::from_string(getEventJson(txn, decomp, levId)); + found = true; + return false; + }); + + if (!found) throw herr("unable to lookup feedId: ", feedId); + } + + std::vector getEvents(lmdb::txn &txn, Decompressor &decomp) { + return {}; + } +}; diff --git a/src/apps/web/WebReader.cpp b/src/apps/web/WebReader.cpp index 192386e..7e025a6 100644 --- a/src/apps/web/WebReader.cpp +++ b/src/apps/web/WebReader.cpp @@ -94,9 +94,9 @@ void doSearch(lmdb::txn &txn, Decompressor &decomp, std::string_view search, std -TemplarResult renderCommunityEvents(lmdb::txn &txn, Decompressor &decomp, UserCache &userCache, const CommunitySpec &communitySpec) { - AlgoScanner a(txn, communitySpec.algo); - auto events = a.getEvents(txn, decomp, 60); +TemplarResult renderFeed(lmdb::txn &txn, Decompressor &decomp, UserCache &userCache, const std::string &feedId) { + FeedReader feedReader(txn, feedId); + auto events = feedReader.getEvents(txn, decomp); std::vector rendered; auto now = hoytech::curr_time_s(); @@ -120,11 +120,11 @@ TemplarResult renderCommunityEvents(lmdb::txn &txn, Decompressor &decomp, UserCa fe.info, }; - rendered.emplace_back(tmpl::community::item(ctx)); + rendered.emplace_back(tmpl::feed::item(ctx)); n++; } - return tmpl::community::list(rendered); + return tmpl::feed::list(rendered); } @@ -148,32 +148,16 @@ HTTPResponse WebServer::generateReadResponse(lmdb::txn &txn, Decompressor &decom // Normal frame: std::optional body; - std::optional communitySpec; std::string title; // Or, raw: std::optional rawBody; - if (u.path.size() == 0 || u.path[0] == "algo") { - communitySpec = lookupCommunitySpec(txn, decomp, userCache, cfg().web__homepageCommunity); - httpResp.extraHeaders += "Cache-Control: max-age=600\r\n"; - } - if (u.path.size() == 0) { - body = renderCommunityEvents(txn, decomp, userCache, *communitySpec); - } else if (u.path[0] == "algo") { - struct { - std::string community; - const CommunitySpec &communitySpec; - std::string_view descriptor; - } ctx = { - "homepage", - *communitySpec, - cfg().web__homepageCommunity, - }; + body = renderFeed(txn, decomp, userCache, cfg().web__homepageFeedId); - body = tmpl::community::communityInfo(ctx); + httpResp.extraHeaders += "Cache-Control: max-age=600\r\n"; } else if (u.path[0] == "e") { if (u.path.size() == 2) { EventThread et(txn, decomp, decodeBech32Simple(u.path[1])); @@ -320,7 +304,6 @@ HTTPResponse WebServer::generateReadResponse(lmdb::txn &txn, Decompressor &decom struct { const TemplarResult &body; - const std::optional &communitySpec; std::string_view title; std::string staticFilesPrefix; std::string_view staticOddbeanCssHash; @@ -328,7 +311,6 @@ HTTPResponse WebServer::generateReadResponse(lmdb::txn &txn, Decompressor &decom std::string_view staticOddbeanSvgHash; } ctx = { *body, - communitySpec, title, cfg().web__staticFilesPrefix.size() ? cfg().web__staticFilesPrefix : "/static", oddbeanStatic__oddbean_css__hash().substr(0, 16), diff --git a/src/apps/web/golpe.yaml b/src/apps/web/golpe.yaml index df06ead..fc76efd 100644 --- a/src/apps/web/golpe.yaml +++ b/src/apps/web/golpe.yaml @@ -7,8 +7,8 @@ config: desc: "Port to open for the http protocol" default: 8080 noReload: true - - name: web__homepageCommunity - desc: "Community descriptor for homepage" + - name: web__homepageFeedId + desc: "Homepage Feed ID (pubkey/feedName)" default: "" - name: web__staticFilesPrefix desc: "URL or relative path prefix to use for static files (empty string to use versions embedded in binary)" diff --git a/src/apps/web/tmpls/community/communityInfo.tmpl b/src/apps/web/tmpls/feed/communityInfo.tmpl similarity index 100% rename from src/apps/web/tmpls/community/communityInfo.tmpl rename to src/apps/web/tmpls/feed/communityInfo.tmpl diff --git a/src/apps/web/tmpls/community/item.tmpl b/src/apps/web/tmpls/feed/item.tmpl similarity index 100% rename from src/apps/web/tmpls/community/item.tmpl rename to src/apps/web/tmpls/feed/item.tmpl diff --git a/src/apps/web/tmpls/community/list.tmpl b/src/apps/web/tmpls/feed/list.tmpl similarity index 100% rename from src/apps/web/tmpls/community/list.tmpl rename to src/apps/web/tmpls/feed/list.tmpl