diff --git a/src/apps/web/FeedReader.h b/src/apps/web/FeedReader.h index 1b0f50e..b39bbd8 100644 --- a/src/apps/web/FeedReader.h +++ b/src/apps/web/FeedReader.h @@ -13,21 +13,20 @@ struct FeedReader { EventInfo info; }; - tao::json::value feedJson; - - FeedReader(lmdb::txn &txn, const std::string &feedId) { + std::vector getEvents(lmdb::txn &txn, Decompressor &decomp, 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); + if (pos == std::string_view::npos) throw herr("bad feedId: ", feedId); + std::string pubkey = from_hex(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) }) }, + { "authors", tao::json::value::array({ to_hex(pubkey) }) }, { "kinds", tao::json::value::array({ uint64_t(33800) }) }, { "#d", tao::json::value::array({ adminTopic }) }, }); bool found = false; + tao::json::value feedJson; foreachByFilter(txn, filter, [&](uint64_t levId){ feedJson = tao::json::from_string(getEventJson(txn, decomp, levId)); @@ -36,9 +35,48 @@ struct FeedReader { }); if (!found) throw herr("unable to lookup feedId: ", feedId); + + std::vector output; + + const auto &tags = feedJson.at("tags").get_array(); + + for (const auto &tag : tags) { + if (tag[0] != "e") continue; + std::string id = from_hex(tag[1].get_string()); + + auto ev = lookupEventById(txn, id); + if (!ev) continue; + + output.push_back({ + ev->primaryKeyId, + id, + buildEventInfo(txn, id), + }); + } + + return output; } - std::vector getEvents(lmdb::txn &txn, Decompressor &decomp) { - return {}; + EventInfo buildEventInfo(lmdb::txn &txn, const std::string &id) { + EventInfo output; + + std::string prefix = "e"; + prefix += id; + + env.generic_foreachFull(txn, env.dbi_Event__tag, prefix, "", [&](std::string_view k, std::string_view v){ + ParsedKey_StringUint64 parsedKey(k); + if (parsedKey.s != prefix) return false; + + auto childLevId = lmdb::from_sv(v); + auto childEv = lookupEventByLevId(txn, childLevId); + + PackedEventView packed(childEv.buf); + if (packed.kind() == 1) output.comments++; + else if (packed.kind() == 7) output.score++; + + return true; + }); + + return output; } }; diff --git a/src/apps/web/WebReader.cpp b/src/apps/web/WebReader.cpp index 7e025a6..8b2c36c 100644 --- a/src/apps/web/WebReader.cpp +++ b/src/apps/web/WebReader.cpp @@ -1,13 +1,11 @@ #include "WebServer.h" #include "WebData.h" - +#include "FeedReader.h" #include "WebStaticFiles.h" - - std::string exportUserEvents(lmdb::txn &txn, Decompressor &decomp, std::string_view pubkey) { std::string output; @@ -95,8 +93,8 @@ void doSearch(lmdb::txn &txn, Decompressor &decomp, std::string_view search, std TemplarResult renderFeed(lmdb::txn &txn, Decompressor &decomp, UserCache &userCache, const std::string &feedId) { - FeedReader feedReader(txn, feedId); - auto events = feedReader.getEvents(txn, decomp); + FeedReader feedReader; + auto events = feedReader.getEvents(txn, decomp, feedId); std::vector rendered; auto now = hoytech::curr_time_s(); @@ -111,7 +109,7 @@ TemplarResult renderFeed(lmdb::txn &txn, Decompressor &decomp, UserCache &userCa const Event &ev; const User &user; std::string timestamp; - AlgoScanner::EventInfo &info; + FeedReader::EventInfo &info; } ctx = { n, ev, diff --git a/src/apps/web/homepage-community.yaml b/src/apps/web/homepage-community.yaml deleted file mode 100644 index 39ca116..0000000 --- a/src/apps/web/homepage-community.yaml +++ /dev/null @@ -1,19 +0,0 @@ -name: homepage - -desc: | - Oddbean.com's homepage - -algo: | - let doug = npub1yxprsscnjw2e6myxz73mmzvnqw5kvzd5ffjya9ecjypc5l0gvgksh8qud4; - let admins = doug.following; - let members = admins.following; - - posts { - threshold = 80; - - mods = admins; - voters = members; - - /10 if ~ /(?i)bitcoin|btc|crypto/; - *3.5 if ~ /(?i)#grownostr/; - }