Web interface: Support Join room for Slack frontend
This commit is contained in:
parent
703af16e8b
commit
4e8042885f
4 changed files with 129 additions and 1 deletions
|
@ -119,6 +119,7 @@ void APIServer::serve_instances(Server *server, Server::session *session, struct
|
|||
usernames.push_back(username);
|
||||
instance.AddMember("registered", !username.empty(), json.GetAllocator());
|
||||
instance.AddMember("username", usernames.back().c_str(), json.GetAllocator());
|
||||
instance.AddMember("frontend", is_slack(m_config, id) ? "slack" : "xmpp", json.GetAllocator());
|
||||
|
||||
instances.PushBack(instance, json.GetAllocator());
|
||||
}
|
||||
|
@ -221,6 +222,50 @@ void APIServer::serve_instances_register(Server *server, Server::session *sessio
|
|||
}
|
||||
}
|
||||
|
||||
void APIServer::serve_instances_join_room(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);
|
||||
|
||||
UserInfo info;
|
||||
m_storage->getUser(session->user, info);
|
||||
|
||||
std::string username = "";
|
||||
int type = (int) TYPE_STRING;
|
||||
m_storage->getUserSetting(info.id, instance, type, username);
|
||||
|
||||
if (username.empty()) {
|
||||
send_ack(conn, true, "You are not registered to this Spectrum 2 instance.");
|
||||
return;
|
||||
}
|
||||
|
||||
std::string name = get_http_var(hm, "name");
|
||||
std::string legacy_room = get_http_var(hm, "legacy_room");
|
||||
std::string legacy_server = get_http_var(hm, "legacy_server");
|
||||
std::string frontend_room = get_http_var(hm, "frontend_room");
|
||||
|
||||
std::string response = server->send_command(instance, "join_room " +
|
||||
username + " " + name + " " + legacy_room + " " + legacy_server + " " + frontend_room);
|
||||
|
||||
if (response.find("Joined the room") == std::string::npos) {
|
||||
send_ack(conn, true, response);
|
||||
}
|
||||
else {
|
||||
send_ack(conn, false, response);
|
||||
}
|
||||
}
|
||||
|
||||
void APIServer::serve_instances_join_room_form(Server *server, Server::session *session, struct mg_connection *conn, struct http_message *hm) {
|
||||
// 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());
|
||||
send_json(conn, json);
|
||||
}
|
||||
|
||||
void APIServer::serve_instances_register_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);
|
||||
|
@ -330,6 +375,12 @@ void APIServer::handleRequest(Server *server, Server::session *sess, struct mg_c
|
|||
else if (has_prefix(&hm->uri, "/api/v1/instances/register/")) {
|
||||
serve_instances_register(server, sess, conn, hm);
|
||||
}
|
||||
else if (has_prefix(&hm->uri, "/api/v1/instances/join_room_form/")) {
|
||||
serve_instances_join_room_form(server, sess, conn, hm);
|
||||
}
|
||||
else if (has_prefix(&hm->uri, "/api/v1/instances/join_room/")) {
|
||||
serve_instances_join_room(server, sess, conn, hm);
|
||||
}
|
||||
else if (has_prefix(&hm->uri, "/api/v1/users/remove/")) {
|
||||
serve_users_remove(server, sess, conn, hm);
|
||||
}
|
||||
|
|
|
@ -58,6 +58,8 @@ class APIServer {
|
|||
void serve_instances_unregister(Server *server, Server::session *sess, struct mg_connection *conn, struct http_message *hm);
|
||||
void serve_instances_register(Server *server, Server::session *sess, struct mg_connection *conn, struct http_message *hm);
|
||||
void serve_instances_register_form(Server *server, Server::session *sess, struct mg_connection *conn, struct http_message *hm);
|
||||
void serve_instances_join_room(Server *server, Server::session *sess, struct mg_connection *conn, struct http_message *hm);
|
||||
void serve_instances_join_room_form(Server *server, Server::session *sess, struct mg_connection *conn, struct http_message *hm);
|
||||
void serve_users(Server *server, Server::session *sess, struct mg_connection *conn, struct http_message *hm);
|
||||
void serve_users_add(Server *server, Server::session *sess, struct mg_connection *conn, struct http_message *hm);
|
||||
void serve_users_remove(Server *server, Server::session *sess, struct mg_connection *conn, struct http_message *hm);
|
||||
|
|
37
spectrum_manager/src/html/instances/join_room.shtml
Normal file
37
spectrum_manager/src/html/instances/join_room.shtml
Normal file
|
@ -0,0 +1,37 @@
|
|||
<!--#include virtual="/header.shtml" -->
|
||||
|
||||
<h2>Join room</h2>
|
||||
<form action="/api/v1/instances/join_room" class="basic-grey" method="POST">
|
||||
<h1>Join room
|
||||
<span id="description">Join the room using this Spectrum 2 instance.</span>
|
||||
</h1>
|
||||
<label>
|
||||
<span id="name_desc"></span>
|
||||
<input type="text" id="name" name="name" placeholder=""></textarea>
|
||||
</label>
|
||||
<label>
|
||||
<span id="legacy_room_desc"></span>
|
||||
<input type="text" id="legacy_room" name="legacy_name" placeholder=""></textarea>
|
||||
</label>
|
||||
<label>
|
||||
<span id="legacy_server_desc"></span>
|
||||
<input type="text" id="legacy_server" name="legacy_server" placeholder=""></textarea>
|
||||
</label>
|
||||
<label>
|
||||
<span id="frontend_room_desc"></span>
|
||||
<input type="text" id="frontend_room" name="frontend_room" placeholder=""></textarea>
|
||||
</label>
|
||||
<label>
|
||||
<span> </span>
|
||||
<input type="submit" class="button_command" value="Join room" />
|
||||
</label>
|
||||
<input type="hidden" name="instance" id="instance" value=""></input>
|
||||
</form><br/>
|
||||
|
||||
<script type="text/javascript">
|
||||
$(function() {
|
||||
fill_instances_join_room_form();
|
||||
});
|
||||
</script>
|
||||
|
||||
<!--#include virtual="/footer.shtml" -->
|
|
@ -34,7 +34,12 @@ function show_instances() {
|
|||
$("#main_result > tbody:last-child").append(row);
|
||||
}
|
||||
else {
|
||||
row += '<td><a class="button_command" href="' + $.cookie("base_location") + 'api/v1/instances/' + command + '/' + instance.id + '">' + command + '</a>' + '</td></tr>';
|
||||
row += '<td>';
|
||||
if (command == 'unregister' && instance.frontend == "slack") {
|
||||
row += '<a href="' + $.cookie("base_location") + 'instances/join_room.shtml?id=' + instance.id + '">Join room</a> | ';
|
||||
}
|
||||
row += '<a class="button_command" href="' + $.cookie("base_location") + 'api/v1/instances/' + command + '/' + instance.id + '">' + command + '</a>';
|
||||
row += '</td></tr>';
|
||||
$("#main_result > tbody:last-child").append(row);
|
||||
$(".button_command").click(function(e) {
|
||||
e.preventDefault();
|
||||
|
@ -92,6 +97,39 @@ function getQueryParams(qs) {
|
|||
return params;
|
||||
}
|
||||
|
||||
function fill_instances_join_room_form() {
|
||||
var query = getQueryParams(document.location.search);
|
||||
$("#instance").attr("value", query.id);
|
||||
|
||||
$(".button_command").click(function(e) {
|
||||
e.preventDefault();
|
||||
$(this).parent().empty().progressbar( {value: false} ).css('height', '1em');
|
||||
|
||||
var postdata ={
|
||||
"name": $("#name").val(),
|
||||
"legacy_room": $("#legacy_room").val(),
|
||||
"legacy_server": $("#legacy_server").val()
|
||||
"frontend_room": $("#frontend_room").val()
|
||||
};
|
||||
|
||||
$.post($.cookie("base_location") + "api/v1/instances/join_room/" + $("#instance").val(), postdata, function(data) {
|
||||
window.location.replace("index.shtml");
|
||||
});
|
||||
})
|
||||
|
||||
$.get($.cookie("base_location") + "api/v1/instances/join_room_form/" + query.id, function(data) {
|
||||
$("#name_desc").html(data.name_label + ":");
|
||||
$("#legacy_room_desc").html(data.legacy_room_label + ":");
|
||||
$("#legacy_server_desc").html(data.legacy_server_label + ":");
|
||||
$("#frontend_room_desc").html(data.frontend_room_desc + ":");
|
||||
|
||||
$("#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_desc + ":");
|
||||
});
|
||||
}
|
||||
|
||||
function fill_instances_register_form() {
|
||||
var query = getQueryParams(document.location.search);
|
||||
$("#instance").attr("value", query.id);
|
||||
|
|
Loading…
Add table
Reference in a new issue