Support showing examples in web interface join room dialog
This commit is contained in:
parent
b11cb99ccd
commit
47bc0f5ac5
3 changed files with 57 additions and 9 deletions
|
@ -28,6 +28,7 @@
|
|||
#include "transport/Transport.h"
|
||||
#include "transport/StorageBackend.h"
|
||||
#include "transport/Logging.h"
|
||||
#include "transport/Config.h"
|
||||
|
||||
#include <boost/algorithm/string.hpp>
|
||||
#include <boost/foreach.hpp>
|
||||
|
@ -133,6 +134,30 @@ bool SlackUserManager::handleAdminMessage(Swift::Message::ref message) {
|
|||
return true;
|
||||
}
|
||||
}
|
||||
else if (body.find("join_room_fields") == 0) {
|
||||
std::string ret;
|
||||
|
||||
Config *cfg = m_component->getConfig();
|
||||
ret += CONFIG_STRING_DEFAULTED(cfg, "service.join_room_nickname_label", "Nickname in 3rd-party room") + "\n";
|
||||
std::string room_name = CONFIG_STRING_DEFAULTED(cfg, "service.join_room_room_label", "3rd-party room name");
|
||||
if (room_name[0] == '%') {
|
||||
room_name[0] = '#';
|
||||
}
|
||||
ret += room_name + "\n";
|
||||
ret += CONFIG_STRING_DEFAULTED(cfg, "service.join_room_server_label", "3rd-party server") + "\n";
|
||||
ret += "Slack Channel\n";
|
||||
ret += CONFIG_STRING_DEFAULTED(cfg, "service.join_room_nickname_example", "BotNickname") + "\n";
|
||||
room_name = CONFIG_STRING_DEFAULTED(cfg, "service.join_room_room_example", "3rd-party room name");
|
||||
if (room_name[0] == '%') {
|
||||
room_name[0] = '#';
|
||||
}
|
||||
ret += room_name + "\n";
|
||||
ret += CONFIG_STRING_DEFAULTED(cfg, "service.join_room_server_example", "3rd.party.server.org") + "\n";
|
||||
ret += "mychannel";
|
||||
|
||||
message->setBody(ret);
|
||||
return true;
|
||||
}
|
||||
else if (body.find("join_room ") == 0) {
|
||||
std::vector<std::string> args;
|
||||
boost::split(args, body, boost::is_any_of(" "));
|
||||
|
|
|
@ -358,14 +358,37 @@ void APIServer::serve_instances_leave_room(Server *server, Server::session *sess
|
|||
}
|
||||
|
||||
void APIServer::serve_instances_join_room_form(Server *server, Server::session *session, struct mg_connection *conn, struct http_message *hm) {
|
||||
std::string uri(hm->uri.p, hm->uri.len);
|
||||
std::string instance = uri.substr(uri.rfind("/") + 1);
|
||||
|
||||
// So far we support just Slack here. For XMPP, it is up to user to initiate the join room request.
|
||||
Document json;
|
||||
json.SetObject();
|
||||
json.AddMember("error", 0, json.GetAllocator());
|
||||
json.AddMember("name_label", "Nickname in 3rd-party room", json.GetAllocator());
|
||||
json.AddMember("legacy_room_label", "3rd-party room name", json.GetAllocator());
|
||||
json.AddMember("legacy_server_label", "3rd-party server", json.GetAllocator());
|
||||
json.AddMember("frontend_room_label", "Slack channel", json.GetAllocator());
|
||||
|
||||
std::string response = server->send_command(instance, "join_room_fields");
|
||||
std::vector<std::string> fields;
|
||||
boost::split(fields, response, boost::is_any_of("\n"));
|
||||
|
||||
if (fields.size() != 8) {
|
||||
fields.push_back("Nickname in 3rd-party room");
|
||||
fields.push_back("3rd-party room name");
|
||||
fields.push_back("3rd-party server");
|
||||
fields.push_back("Slack Channel");
|
||||
fields.push_back("BotNickname");
|
||||
fields.push_back("room_name");
|
||||
fields.push_back("3rd.party.server.org");
|
||||
fields.push_back("mychannel");
|
||||
}
|
||||
|
||||
json.AddMember("name_label", fields[0].c_str(), json.GetAllocator());
|
||||
json.AddMember("legacy_room_label", fields[1].c_str(), json.GetAllocator());
|
||||
json.AddMember("legacy_server_label", fields[2].c_str(), json.GetAllocator());
|
||||
json.AddMember("frontend_room_label", fields[3].c_str(), json.GetAllocator());
|
||||
json.AddMember("name_example", fields[4].c_str(), json.GetAllocator());
|
||||
json.AddMember("legacy_room_example", fields[5].c_str(), json.GetAllocator());
|
||||
json.AddMember("legacy_server_example", fields[6].c_str(), json.GetAllocator());
|
||||
json.AddMember("frontend_room_example", fields[7].c_str(), json.GetAllocator());
|
||||
send_json(conn, json);
|
||||
}
|
||||
|
||||
|
|
|
@ -40,7 +40,7 @@ function show_instances() {
|
|||
row += '<td>' + instance.status + '</td>'
|
||||
|
||||
if (command == 'register') {
|
||||
row += '<td><a class="button_command" href="' + $.cookie("base_location") + 'instances/register.shtml?id=' + instance.id + '">' + command + '</a>' + '</td></tr>';
|
||||
row += '<td><a href="' + $.cookie("base_location") + 'instances/register.shtml?id=' + instance.id + '">' + command + '</a>' + '</td></tr>';
|
||||
$("#main_result > tbody:last-child").append(row);
|
||||
}
|
||||
else if (command == "") {
|
||||
|
@ -152,10 +152,10 @@ function fill_instances_join_room_form() {
|
|||
$("#legacy_server_desc").html(data.legacy_server_label + ":");
|
||||
$("#frontend_room_desc").html(data.frontend_room_label + ":");
|
||||
|
||||
$("#name").attr("placeholder", data.name_label + ":");
|
||||
$("#legacy_room").attr("placeholder", data.legacy_room_label + ":");
|
||||
$("#legacy_server").attr("placeholder", data.legacy_server_label + ":");
|
||||
$("#frontend_room").attr("placeholder", data.frontend_room_label + ":");
|
||||
$("#name").attr("placeholder", data.name_example);
|
||||
$("#legacy_room").attr("placeholder", data.legacy_room_example);
|
||||
$("#legacy_server").attr("placeholder", data.legacy_server_example);
|
||||
$("#frontend_room").attr("placeholder", data.frontend_room_example);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue