move AbstractPost definition to a separate header; add post source tracking

This commit is contained in:
Slavasil 2024-11-21 07:32:27 +03:00
parent 182ddffe41
commit aaef54f72e
5 changed files with 25 additions and 10 deletions

View File

@ -7,7 +7,7 @@ add_subdirectory(libuv)
add_subdirectory(spdlog) add_subdirectory(spdlog)
add_subdirectory(td) 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) target_compile_options(${PROJECT_NAME} PRIVATE -std=c++2b)

View File

@ -281,7 +281,7 @@ std::vector<AbstractPost> RepostManager::to_abstract_posts(std::vector<vk::Post>
std::vector<AbstractPost> result; std::vector<AbstractPost> result;
result.reserve(posts.size()); result.reserve(posts.size());
for (auto &post : posts) { 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; return result;
} }
@ -293,7 +293,7 @@ std::vector<AbstractPost> RepostManager::to_abstract_posts(std::vector<td::tl::u
// we don't want any posts other than plain text (yet) // we don't want any posts other than plain text (yet)
if (post->content_->get_id() == td_api::messageText::ID) { if (post->content_->get_id() == td_api::messageText::ID) {
auto &content = (td_api::messageText&) *post->content_; 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; return result;

View File

@ -1,22 +1,17 @@
#pragma once #pragma once
#include "config.h" #include "config.h"
#include "posts.h"
#include "state.h" #include "state.h"
#include "tg.h" #include "tg.h"
#include "vk.h" #include "vk.h"
#include <functional> #include <functional>
#include <string>
#include <vector> #include <vector>
namespace manager { namespace manager {
namespace td_api = td::td_api; namespace td_api = td::td_api;
struct AbstractPost { using posts::AbstractPost;
inline AbstractPost(long id, long date, std::string text) : id(id), date(date), text(text) {}
long id;
long date;
std::string text;
};
class RepostManager { class RepostManager {
public: public:

3
posts.cpp Normal file
View File

@ -0,0 +1,3 @@
#include "posts.h"
using namespace posts;

17
posts.h Normal file
View File

@ -0,0 +1,17 @@
#pragma once
#include <string>
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;
};
}