From aaef54f72ed85b54a368186b34688fb3dbca3c71 Mon Sep 17 00:00:00 2001 From: Slavasil Date: Thu, 21 Nov 2024 07:32:27 +0300 Subject: [PATCH] move AbstractPost definition to a separate header; add post source tracking --- CMakeLists.txt | 2 +- manager.cpp | 4 ++-- manager.h | 9 ++------- posts.cpp | 3 +++ posts.h | 17 +++++++++++++++++ 5 files changed, 25 insertions(+), 10 deletions(-) create mode 100644 posts.cpp create mode 100644 posts.h diff --git a/CMakeLists.txt b/CMakeLists.txt index c860817..5adf34a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,7 +7,7 @@ add_subdirectory(libuv) add_subdirectory(spdlog) add_subdirectory(td) -add_executable(${PROJECT_NAME} main.cpp config.cpp http.cpp manager.cpp state.cpp tg.cpp vk.cpp) +add_executable(${PROJECT_NAME} main.cpp config.cpp http.cpp manager.cpp posts.cpp state.cpp tg.cpp vk.cpp) target_compile_options(${PROJECT_NAME} PRIVATE -std=c++2b) diff --git a/manager.cpp b/manager.cpp index 6870a81..3324161 100644 --- a/manager.cpp +++ b/manager.cpp @@ -281,7 +281,7 @@ std::vector RepostManager::to_abstract_posts(std::vector std::vector result; result.reserve(posts.size()); for (auto &post : posts) { - result.emplace_back(post.id, post.date, post.text); + result.emplace_back(posts::SRC_VK, post.id, post.date, post.text); } return result; } @@ -293,7 +293,7 @@ std::vector RepostManager::to_abstract_posts(std::vectorcontent_->get_id() == td_api::messageText::ID) { auto &content = (td_api::messageText&) *post->content_; - result.emplace_back(post->id_, post->date_, content.text_->text_); + result.emplace_back(posts::SRC_TELEGRAM, post->id_, post->date_, content.text_->text_); } } return result; diff --git a/manager.h b/manager.h index ab2cc79..d7f837e 100644 --- a/manager.h +++ b/manager.h @@ -1,22 +1,17 @@ #pragma once #include "config.h" +#include "posts.h" #include "state.h" #include "tg.h" #include "vk.h" #include -#include #include namespace manager { namespace td_api = td::td_api; - struct AbstractPost { - inline AbstractPost(long id, long date, std::string text) : id(id), date(date), text(text) {} - long id; - long date; - std::string text; - }; + using posts::AbstractPost; class RepostManager { public: diff --git a/posts.cpp b/posts.cpp new file mode 100644 index 0000000..dd3e59e --- /dev/null +++ b/posts.cpp @@ -0,0 +1,3 @@ +#include "posts.h" + +using namespace posts; \ No newline at end of file diff --git a/posts.h b/posts.h new file mode 100644 index 0000000..54669bd --- /dev/null +++ b/posts.h @@ -0,0 +1,17 @@ +#pragma once + +#include + +namespace posts { + enum PostSource { + SRC_VK, SRC_TELEGRAM + }; + + struct AbstractPost { + inline AbstractPost(PostSource src, long id, long date, std::string text) : source(src), id(id), date(date), text(text) {} + long id; + long date; + std::string text; + PostSource source; + }; +} \ No newline at end of file