This commit is contained in:
Doug Hoyte
2024-12-09 15:26:27 -05:00
parent 213e0d86f2
commit 584d92845a
3 changed files with 50 additions and 33 deletions

View File

@ -13,21 +13,20 @@ struct FeedReader {
EventInfo info;
};
tao::json::value feedJson;
FeedReader(lmdb::txn &txn, const std::string &feedId) {
std::vector<FeedEvent> 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<FeedEvent> 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),
});
}
std::vector<FeedEvent> getEvents(lmdb::txn &txn, Decompressor &decomp) {
return {};
return output;
}
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<uint64_t>(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;
}
};

View File

@ -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<TemplarResult> 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,

View File

@ -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/;
}