Fix #87: updating chat room title when video/channel title is changed:

* renaming module list_rooms to manage_rooms
* added some API to update room info
* when a video or a channel is updated, sending an API call to update
  the room
This commit is contained in:
John Livingston
2024-03-07 16:22:14 +01:00
parent 2115b352a4
commit 4dd4f18965
10 changed files with 205 additions and 51 deletions

View File

@ -1,5 +1,5 @@
# mod_http_peertubelivechat_list_rooms
# mod_http_peertubelivechat_manage_rooms
This module is a custom module that allows Peertube server to list chat rooms.
This module is a custom module that allows Peertube server to list chat rooms, and update some meta data.
This module is part of peertube-plugin-livechat, and is under the same LICENSE.

View File

@ -1,15 +1,17 @@
local json = require "util.json";
local jid_split = require"util.jid".split;
local array = require "util.array";
local st = require "util.stanza";
local mod_muc = module:depends"muc";
local all_rooms = rawget(mod_muc, "all_rooms")
local all_rooms = rawget(mod_muc, "all_rooms");
local get_room_from_jid = rawget(mod_muc, "get_room_from_jid");
module:depends"http";
function check_auth(routes)
local function check_request_auth(event)
local apikey = module:get_option_string("peertubelivechat_list_rooms_apikey", "")
local apikey = module:get_option_string("peertubelivechat_manage_rooms_apikey", "")
if apikey == "" then
return false, 500;
end
@ -55,8 +57,51 @@ local function list_rooms(event)
return json.encode_array(rooms_json);
end
local function update_room(event)
local request, response = event.request, event.response;
event.response.headers["Content-Type"] = "application/json";
local config = json.decode(request.body);
if not config.jid then
return json.encode({
result = "failed";
});
end
local room = get_room_from_jid(config.jid);
if not room then
return json.encode({
result = "failed";
});
end
local must104 = false;
if type(config.name) == "string" then
if room:get_name() ~= config.name then
room:set_name(config.name);
must104 = true;
end
end
if must104 then
-- we must broadcast a status 104 message, so that clients can update room info
local msg = st.message({type='groupchat', from=room.jid})
:tag('x', {xmlns='http://jabber.org/protocol/muc#user'})
msg:tag("status", {code = '104';}):up();
msg:up();
room:broadcast_message(msg);
end
return json.encode({
result = "ok";
changed = must104;
});
end
module:provides("http", {
route = check_auth {
["GET /list-rooms"] = list_rooms;
["POST /update-room"] = update_room;
};
});