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
@@ -1395,6 +1395,15 @@ CommandResult ConnectedClient::handleCommandChannelCreate(Command &cmd) {
auto& tree_lock = this->server ? this->server->channel_tree_lock : serverInstance->getChannelTreeLock();
unique_lock tree_channel_lock(tree_lock);
if(cmd[0].has("channel_conversation_history_length")) {
auto value = cmd["channel_conversation_history_length"].as<int64_t>();
if(value == 0) {
CACHED_PERM_CHECK(permission::b_channel_create_modify_conversation_history_unlimited, 1);
} else {
CACHED_PERM_CHECK(permission::i_channel_create_modify_conversation_history_length, 1);
}
}
{
auto delete_delay = cmd[0].has("channel_delete_delay") ? cmd["channel_delete_delay"].as<permission::PermissionValue>() : 0UL;
if(delete_delay == 0) {
@@ -1785,6 +1794,13 @@ CommandResult ConnectedClient::handleCommandChannelEdit(Command &cmd) {
} else if (key == "channel_password" || key == "channel_flag_password") {
CHANNEL_PERM_TEST(permission::b_channel_modify_password, 1, true);
update_password = true;
} else if (key == "channel_conversation_history_length") {
auto value = cmd["channel_conversation_history_length"].as<int64_t>();
if(value == 0) {
CHANNEL_PERM_TEST(permission::b_channel_create_modify_conversation_history_unlimited, 1, true);
} else {
CHANNEL_PERM_TEST(permission::i_channel_create_modify_conversation_history_length, 1, true);
}
} else {
logCritical(
this->getServerId(),
@@ -2066,6 +2082,14 @@ CommandResult ConnectedClient::handleCommandChannelEdit(Command &cmd) {
}
}
}
} else if(*key == property::CHANNEL_CONVERSATION_HISTORY_LENGTH) {
//channel_conversation_history_length
auto conversation_manager = this->server->conversation_manager();
if(conversation_manager) {
auto conversation = conversation_manager->get(channel->channelId());
if(conversation)
conversation->set_history_length(cmd[key->name]);
}
}
channel->properties()[key] = cmd[key->name].string();
@@ -7314,8 +7338,10 @@ CommandResult ConnectedClient::handleCommandConversationHistory(ts::Command &com
size_t length = 0;
bool merge = command.hasParm("merge");
for(auto& message : messages) {
if(index == 0)
if(index == 0) {
notify[index]["cid"] = conversation_id;
notify[index]["flag_volatile"] = conversation->volatile_only();
}
notify[index]["timestamp"] = duration_cast<milliseconds>(message->message_timestamp.time_since_epoch()).count();
notify[index]["sender_database_id"] = message->sender_database_id;
@@ -7415,6 +7441,7 @@ CommandResult ConnectedClient::handleCommandConversationFetch(ts::Command &cmd)
result_bulk["timestamp"] = duration_cast<milliseconds>(conversation->last_message().time_since_epoch()).count();
else
result_bulk["timestamp"] = 0;
result_bulk["flag_volatile"] = conversation->volatile_only();
}
if(result_index == 0)
return {ErrorType::DBEmpty};