Updated the property list command and added a channel description only mode

This commit is contained in:
WolverinDEV
2020-10-04 15:04:25 +02:00
parent 6150957689
commit 1686ce095f
7 changed files with 207 additions and 20 deletions
+25 -1
View File
@@ -1078,7 +1078,31 @@ command_result ConnectedClient::handleCommandChannelEdit(Command &cmd) {
ACTION_REQUIRES_PERMISSION(permission::i_channel_create_modify_conversation_history_length, 1, channel_id);
}
} else if (key == "channel_flag_conversation_private") {
ACTION_REQUIRES_PERMISSION(permission::b_channel_create_modify_conversation_private, 1, channel_id);
auto value = cmd["channel_flag_conversation_private"].as<bool>();
if(value) {
ACTION_REQUIRES_PERMISSION(permission::b_channel_create_modify_conversation_mode_private, 1, channel_id);
cmd[property::name(property::CHANNEL_CONVERSATION_MODE)] = CHANNELCONVERSATIONMODE_PRIVATE;
} else {
ACTION_REQUIRES_PERMISSION(permission::b_channel_create_modify_conversation_mode_public, 1, channel_id);
cmd[property::name(property::CHANNEL_CONVERSATION_MODE)] = CHANNELCONVERSATIONMODE_PUBLIC;
}
keys.push_back(&property::describe(property::CHANNEL_CONVERSATION_MODE));
continue;
} else if (key == "channel_conversation_mode") {
auto value = cmd["channel_conversation_mode"].as<ChannelConversationMode>();
switch (value) {
case ChannelConversationMode::CHANNELCONVERSATIONMODE_PRIVATE:
ACTION_REQUIRES_PERMISSION(permission::b_channel_create_modify_conversation_mode_private, 1, channel_id);
break;
case ChannelConversationMode::CHANNELCONVERSATIONMODE_PUBLIC:
ACTION_REQUIRES_PERMISSION(permission::b_channel_create_modify_conversation_mode_public, 1, channel_id);
break;
case ChannelConversationMode::CHANNELCONVERSATIONMODE_NONE:
ACTION_REQUIRES_PERMISSION(permission::b_channel_create_modify_conversation_mode_none, 1, channel_id);
break;
default:
return command_result{error::parameter_invalid, "channel_conversation_mode"};
}
} else {
logCritical(
this->getServerId(),
+52 -15
View File
@@ -397,6 +397,8 @@ do { \
response[index]["name"] = prop->name; \
response[index]["flags"] = prop->flags; \
response[index]["type"] = property::PropertyType_Names[prop->type_property]; \
response[index]["value"] = prop->default_value; \
response[index]["value_type"] = property::ValueType_Names[(int) prop->type_value]; \
index++; \
} \
} while(0)
@@ -406,8 +408,11 @@ command_result ConnectedClient::handleCommandPropertyList(ts::Command& cmd) {
{
string pattern;
for (auto flag_name : property::flag_names)
pattern = flag_name + string("|") + pattern;
for (auto flag_name : property::flag_names) {
if(flag_name) {
pattern = flag_name + string("|") + pattern;
}
}
pattern = pattern.substr(0, pattern.length() - 1);
response["flag_set"] = pattern;
}
@@ -425,6 +430,8 @@ command_result ConnectedClient::handleCommandPropertyList(ts::Command& cmd) {
M(property::GroupProperties);
if(cmd.hasParm("all") || cmd.hasParm("connection"))
M(property::ConnectionProperties);
if(cmd.hasParm("all") || cmd.hasParm("playlist"))
M(property::PlaylistProperties);
this->sendCommand(response);
return command_result{error::ok};
@@ -579,8 +586,10 @@ command_result ConnectedClient::handleCommandSendTextMessage(Command &cmd) {
target->notifyTextMessage(ChatMessageMode::TEXTMODE_PRIVATE, _this.lock(), target->getClientId(), 0, timestamp, cmd["msg"].string());
this->notifyTextMessage(ChatMessageMode::TEXTMODE_PRIVATE, _this.lock(), target->getClientId(), 0, timestamp, cmd["msg"].string());
} else if (cmd["targetmode"] == ChatMessageMode::TEXTMODE_CHANNEL) {
if(!cmd[0].has("cid"))
if(!cmd[0].has("cid")) {
cmd["cid"] = 0;
}
RESOLVE_CHANNEL_R(cmd["cid"], false);
auto channel = l_channel ? dynamic_pointer_cast<BasicChannel>(l_channel->entry) : nullptr;
if(!channel) {
@@ -594,18 +603,23 @@ command_result ConnectedClient::handleCommandSendTextMessage(Command &cmd) {
if(channel == this->currentChannel) {
channel_tree_read_lock.unlock(); //Method may creates a music bot which modifies the channel tree
if(this->handleTextMessage(ChatMessageMode::TEXTMODE_CHANNEL, cmd["msg"], nullptr))
if(this->handleTextMessage(ChatMessageMode::TEXTMODE_CHANNEL, cmd["msg"], nullptr)) {
return command_result{error::ok};
}
channel_tree_read_lock.lock();
}
bool conversation_private = channel->properties()[property::CHANNEL_FLAG_CONVERSATION_PRIVATE].as<bool>();
if(channel != this->currentChannel) {
if(conversation_private)
auto conversation_mode = channel->properties()[property::CHANNEL_CONVERSATION_MODE].as<ChannelConversationMode>();
if(conversation_mode == ChannelConversationMode::CHANNELCONVERSATIONMODE_NONE) {
return command_result{error::conversation_not_exists};
} else if(channel != this->currentChannel) {
if(conversation_mode == ChannelConversationMode::CHANNELCONVERSATIONMODE_PRIVATE) {
return command_result{error::conversation_is_private};
}
if(auto fail_perm{this->calculate_and_get_join_state(channel)}; fail_perm != permission::ok)
if(auto fail_perm{this->calculate_and_get_join_state(channel)}; fail_perm != permission::ok) {
return command_result{fail_perm}; /* You're not allowed to send messages :) */
}
}
this->server->send_text_message(channel, this->ref(), cmd["msg"].string());
@@ -2547,8 +2561,17 @@ command_result ConnectedClient::handleCommandConversationHistory(ts::Command &co
if(!channel)
return command_result{error::conversation_invalid_id};
if(channel->channel()->properties()[property::CHANNEL_FLAG_CONVERSATION_PRIVATE].as<bool>())
return command_result{error::conversation_is_private};
auto conversation_mode = channel->channel()->properties()[property::CHANNEL_CONVERSATION_MODE].as<ChannelConversationMode>();
switch (conversation_mode) {
case ChannelConversationMode::CHANNELCONVERSATIONMODE_PRIVATE:
return command_result{error::conversation_is_private};
case ChannelConversationMode::CHANNELCONVERSATIONMODE_NONE:
return command_result{error::conversation_not_exists};
case ChannelConversationMode::CHANNELCONVERSATIONMODE_PUBLIC:
break;
}
}
/* test if there is a channel password or join power which denies that we see the conversation */
@@ -2667,11 +2690,25 @@ command_result ConnectedClient::handleCommandConversationFetch(ts::Command &cmd)
result_bulk["error_msg"] = error.message;
continue;
}
if(channel->channel()->properties()[property::CHANNEL_FLAG_CONVERSATION_PRIVATE].as<bool>()) {
auto error = findError("conversation_is_private");
result_bulk["error_id"] = error.errorId;
result_bulk["error_msg"] = error.message;
continue;
auto conversation_mode = channel->channel()->properties()[property::CHANNEL_CONVERSATION_MODE].as<ChannelConversationMode>();
switch (conversation_mode) {
case ChannelConversationMode::CHANNELCONVERSATIONMODE_PRIVATE: {
auto error = findError("conversation_is_private");
result_bulk["error_id"] = error.errorId;
result_bulk["error_msg"] = error.message;
continue;
}
case ChannelConversationMode::CHANNELCONVERSATIONMODE_NONE: {
auto error = findError("conversation_not_exists");
result_bulk["error_id"] = error.errorId;
result_bulk["error_msg"] = error.message;
continue;
}
case ChannelConversationMode::CHANNELCONVERSATIONMODE_PUBLIC:
break;
}
}