mirror of
https://github.com/hoytech/strfry.git
synced 2025-06-20 01:40:29 +00:00
wip
This commit is contained in:
@ -13,21 +13,20 @@ struct FeedReader {
|
|||||||
EventInfo info;
|
EventInfo info;
|
||||||
};
|
};
|
||||||
|
|
||||||
tao::json::value feedJson;
|
std::vector<FeedEvent> getEvents(lmdb::txn &txn, Decompressor &decomp, const std::string &feedId) {
|
||||||
|
|
||||||
FeedReader(lmdb::txn &txn, const std::string &feedId) {
|
|
||||||
size_t pos = feedId.find(".");
|
size_t pos = feedId.find(".");
|
||||||
if (pos == std::string_view::npos) throw herr("bad feedId");
|
if (pos == std::string_view::npos) throw herr("bad feedId: ", feedId);
|
||||||
std::string pubkey = FeedId.substr(0, pos);
|
std::string pubkey = from_hex(feedId.substr(0, pos));
|
||||||
std::string adminTopic = feedId.substr(pos + 1);
|
std::string adminTopic = feedId.substr(pos + 1);
|
||||||
|
|
||||||
tao::json::value filter = tao::json::value({
|
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) }) },
|
{ "kinds", tao::json::value::array({ uint64_t(33800) }) },
|
||||||
{ "#d", tao::json::value::array({ adminTopic }) },
|
{ "#d", tao::json::value::array({ adminTopic }) },
|
||||||
});
|
});
|
||||||
|
|
||||||
bool found = false;
|
bool found = false;
|
||||||
|
tao::json::value feedJson;
|
||||||
|
|
||||||
foreachByFilter(txn, filter, [&](uint64_t levId){
|
foreachByFilter(txn, filter, [&](uint64_t levId){
|
||||||
feedJson = tao::json::from_string(getEventJson(txn, decomp, 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);
|
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) {
|
EventInfo buildEventInfo(lmdb::txn &txn, const std::string &id) {
|
||||||
return {};
|
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;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -1,13 +1,11 @@
|
|||||||
#include "WebServer.h"
|
#include "WebServer.h"
|
||||||
#include "WebData.h"
|
#include "WebData.h"
|
||||||
|
|
||||||
|
#include "FeedReader.h"
|
||||||
#include "WebStaticFiles.h"
|
#include "WebStaticFiles.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
std::string exportUserEvents(lmdb::txn &txn, Decompressor &decomp, std::string_view pubkey) {
|
std::string exportUserEvents(lmdb::txn &txn, Decompressor &decomp, std::string_view pubkey) {
|
||||||
std::string output;
|
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) {
|
TemplarResult renderFeed(lmdb::txn &txn, Decompressor &decomp, UserCache &userCache, const std::string &feedId) {
|
||||||
FeedReader feedReader(txn, feedId);
|
FeedReader feedReader;
|
||||||
auto events = feedReader.getEvents(txn, decomp);
|
auto events = feedReader.getEvents(txn, decomp, feedId);
|
||||||
|
|
||||||
std::vector<TemplarResult> rendered;
|
std::vector<TemplarResult> rendered;
|
||||||
auto now = hoytech::curr_time_s();
|
auto now = hoytech::curr_time_s();
|
||||||
@ -111,7 +109,7 @@ TemplarResult renderFeed(lmdb::txn &txn, Decompressor &decomp, UserCache &userCa
|
|||||||
const Event &ev;
|
const Event &ev;
|
||||||
const User &user;
|
const User &user;
|
||||||
std::string timestamp;
|
std::string timestamp;
|
||||||
AlgoScanner::EventInfo &info;
|
FeedReader::EventInfo &info;
|
||||||
} ctx = {
|
} ctx = {
|
||||||
n,
|
n,
|
||||||
ev,
|
ev,
|
||||||
|
@ -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/;
|
|
||||||
}
|
|
Reference in New Issue
Block a user