diff options
Diffstat (limited to 'src/rttt/reddit.hpp')
-rw-r--r-- | src/rttt/reddit.hpp | 27 |
1 files changed, 13 insertions, 14 deletions
diff --git a/src/rttt/reddit.hpp b/src/rttt/reddit.hpp index db06273..76a93bd 100644 --- a/src/rttt/reddit.hpp +++ b/src/rttt/reddit.hpp @@ -26,6 +26,18 @@ namespace rttt { namespace reddit { +bool is_valid_path(std::string_view name) { + // TODO: Ideally we should not split it twice (here and in parse_path) + auto v = rttt::text::split(name, "/"); + return (v.size() > 0 && v[0] == "r"); +} + +bool is_valid_path(const rttt::Path &path) { + // TODO: should we rely on path.type if it is present? + return (path.parts.size() == 2 || path.parts.size() == 4) && + path.parts[0] == "r"; +} + struct credentials { cpr::Header header = cpr::Header{{"User-Agent", "rttt/1.1.1"}}; std::string client_id; @@ -385,7 +397,7 @@ bool update(state &state) { } inline rttt::Path updatePath(rttt::Path &&path) { - logger::log_ifnot(path.type == rttt::SiteType::Reddit); + logger::log_ifnot(reddit::is_valid_path(path)); if (!items.contains(path.name)) { items.insert({path.name, {}}); } @@ -474,21 +486,8 @@ bool catch_ui_event(state &state, ui::state &ui_state, const rttt::Path &path, return false; } -bool is_valid_path(std::string_view name) { - // TODO: Ideally we should not split it twice (here and in parse_path) - auto v = rttt::text::split(name, "/"); - return (v.size() > 0 && v[0] == "r"); -} - -bool is_valid_path(const rttt::Path &path) { - // TODO: should we rely on path.type if it is present? - return (path.parts.size() == 2 || path.parts.size() == 4) && - path.parts[0] == "r"; -} - Path parse_path(std::string_view name) { auto path = rttt::parse_path(name); - path.type = SiteType::Reddit; return path; } |