From fe5a081c376ac3b6a4395371c0e548518d64b20b Mon Sep 17 00:00:00 2001 From: Doug Hoyte Date: Sun, 15 Dec 2024 23:56:00 -0500 Subject: [PATCH] title --- src/apps/web/WebData.h | 15 +++++++++++++-- src/apps/web/WebReader.cpp | 1 + 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/apps/web/WebData.h b/src/apps/web/WebData.h index afeb185..7ac3ed7 100644 --- a/src/apps/web/WebData.h +++ b/src/apps/web/WebData.h @@ -241,7 +241,7 @@ struct Event { // FIXME: Don't truncate UTF-8 mid-sequence // FIXME: Don't put ellipsis if truncated text ends in punctuation - std::string summaryHtml() const { + std::string summaryHtml(bool withLink = true) const { std::string content = json.at("content").get_string(); auto firstUrl = stripUrls(content); @@ -252,7 +252,7 @@ struct Event { textAbbrev(content, 100); templarInternal::htmlEscape(content, true); - if (firstUrl.size()) { + if (withLink && firstUrl.size()) { while (content.size() && isspace(content.back())) content.pop_back(); if (content.empty()) { content = firstUrl; @@ -513,6 +513,17 @@ struct EventThread { } + std::string getSummary() { + if (!rootEventId.size()) return ""; + + auto p = eventCache.find(rootEventId); + if (p == eventCache.end()) return ""; + + const auto &elem = p->second; + return elem.summaryHtml(false); + } + + TemplarResult render(lmdb::txn &txn, Decompressor &decomp, UserCache &userCache, std::optional focusOnPubkey = std::nullopt) { auto now = hoytech::curr_time_s(); flat_hash_set processedLevIds; diff --git a/src/apps/web/WebReader.cpp b/src/apps/web/WebReader.cpp index 87ab92a..9a8b1b5 100644 --- a/src/apps/web/WebReader.cpp +++ b/src/apps/web/WebReader.cpp @@ -178,6 +178,7 @@ HTTPResponse WebServer::generateReadResponse(lmdb::txn &txn, Decompressor &decom if (u.path.size() == 2) { EventThread et(txn, decomp, decodeBech32Simple(u.path[1])); body = et.render(txn, decomp, userCache); + title = et.getSummary(); } else if (u.path.size() == 3) { if (u.path[2] == "reply") { auto ev = Event::fromIdExternal(txn, u.path[1]);