Updating the conversation stuff

This commit is contained in:
WolverinDEV
2019-07-21 17:02:32 +02:00
parent 345da8394b
commit c720a80bc0
5 changed files with 55 additions and 11 deletions
+20 -2
View File
@@ -1253,8 +1253,26 @@ void ConversationManager::delete_conversation(ts::ChannelId channel_id) {
}
}
void ConversationManager::cleanup_channels() {
//TODO: Check if the channel for the conversation still exists!
void ConversationManager::synchronize_channels() {
auto ref_server = this->ref_server();
if(!ref_server) {
logWarning(ref_server->getServerId(), "[Conversations][{}] Failed to synchronize conversations (server expired)");
return;
}
auto chan_tree = ref_server->getChannelTree();
deque<shared_ptr<Conversation>> channels{this->_conversations};
for(auto& channel : channels) {
auto schannel = chan_tree->findChannel(channel->channel_id());
if(!schannel) {
logMessage(ref_server->getServerId(), "[Conversations][{}] Deleting conversation because channel does not exists anymore.", channel->channel_id());
this->delete_conversation(channel->channel_id());
continue;
}
auto history_size = schannel->properties()[property::CHANNEL_CONVERSATION_HISTORY_LENGTH].as<size_t>();
channel->set_history_length(history_size);
}
}
void ConversationManager::cleanup_cache() {
+5 -4
View File
@@ -143,11 +143,11 @@ namespace ts {
inline ChannelId channel_id() { return this->_channel_id; }
/* if for some reason we're not able to open the file then we're in volatile mode */
inline bool volatile_only() { return this->_volatile; }
inline bool volatile_only() { return this->_volatile || this->_history_length < 0; }
void cleanup_cache();
//void set_history_length(ssize_t /* save length */);
//ssize_t history_length();
void set_history_length(ssize_t length) { this->_history_length = length; }
ssize_t history_length() { return this->_history_length; }
inline std::chrono::system_clock::time_point last_message() { return this->_last_message_timestamp; }
void register_message(ClientDbId sender_database_id, const std::string& sender_unique_id, const std::string& sender_name, const std::string& message);
@@ -210,6 +210,7 @@ namespace ts {
FILE* file_handle = nullptr;
ChannelId _channel_id;
ssize_t _history_length = 0;
bool _volatile = false;
std::chrono::system_clock::time_point _last_message_timestamp;
@@ -221,7 +222,7 @@ namespace ts {
virtual ~ConversationManager();
void initialize(const std::shared_ptr<ConversationManager>& _this);
void cleanup_channels();
void synchronize_channels();
void cleanup_cache();
bool conversation_exists(ChannelId /* channel */);