Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
hoytech committed Dec 9, 2024
1 parent 148ea0e commit 8cd981d
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 33 deletions.
54 changes: 46 additions & 8 deletions src/apps/web/FeedReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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),
});
}

return output;
}

std::vector<FeedEvent> 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<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;
}
};
10 changes: 4 additions & 6 deletions src/apps/web/WebReader.cpp
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -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();
Expand All @@ -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,
Expand Down
19 changes: 0 additions & 19 deletions src/apps/web/homepage-community.yaml

This file was deleted.

0 comments on commit 8cd981d

Please sign in to comment.