From b64d9730d0b47c27c50348fe5026a41284af54f3 Mon Sep 17 00:00:00 2001 From: John Livingston Date: Mon, 19 Jul 2021 16:51:51 +0200 Subject: [PATCH] Adding last activity informations. --- client/admin-plugin-client-plugin.ts | 25 +++++++++++++++++-- .../mod_http_peertubelivechat_list_rooms.lua | 6 +++++ shared/lib/types.ts | 1 + 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/client/admin-plugin-client-plugin.ts b/client/admin-plugin-client-plugin.ts index 916b3d67..ea5b6cbd 100644 --- a/client/admin-plugin-client-plugin.ts +++ b/client/admin-plugin-client-plugin.ts @@ -63,7 +63,17 @@ function register ({ registerHook, registerSettingsScript, peertubeHelpers }: Re container.textContent = json.error container.classList.add('peertube-plugin-livechat-error') } else { - const rooms = json.rooms.sort((a, b) => a.name.localeCompare(b.name)) + const rooms = json.rooms.sort((a, b) => { + const timestampA = a.lasttimestamp ?? 0 + const timestampB = b.lasttimestamp ?? 0 + if (timestampA === timestampB) { + return a.name.localeCompare(b.name) + } else if (timestampA < timestampB) { + return 1 + } else { + return -1 + } + }) container.textContent = '' const table = document.createElement('table') @@ -74,8 +84,10 @@ function register ({ registerHook, registerSettingsScript, peertubeHelpers }: Re RoomName: 'Room name', RoomDescription: 'Room description', NotFound: 'Not found', - Video: 'Video' + Video: 'Video', + LastActivity: 'Last activity' } + const titleLineEl = document.createElement('tr') const titleNameEl = document.createElement('th') titleNameEl.textContent = labels.RoomName @@ -83,9 +95,12 @@ function register ({ registerHook, registerSettingsScript, peertubeHelpers }: Re titleDescriptionEl.textContent = labels.RoomDescription const titleVideoEl = document.createElement('th') titleVideoEl.textContent = labels.Video + const titleLastActivityEl = document.createElement('th') + titleLastActivityEl.textContent = labels.LastActivity titleLineEl.append(titleNameEl) titleLineEl.append(titleDescriptionEl) titleLineEl.append(titleVideoEl) + titleLineEl.append(titleLastActivityEl) table.append(titleLineEl) rooms.forEach(room => { const uuid = room.localpart @@ -98,10 +113,16 @@ function register ({ registerHook, registerSettingsScript, peertubeHelpers }: Re const descriptionEl = document.createElement('td') descriptionEl.textContent = room.description const videoEl = document.createElement('td') + const lastActivityEl = document.createElement('td') + if (room.lasttimestamp && (typeof room.lasttimestamp === 'number')) { + const date = new Date(room.lasttimestamp * 1000) + lastActivityEl.textContent = date.toLocaleDateString() + ' ' + date.toLocaleTimeString() + } nameEl.append(aEl) lineEl.append(nameEl) lineEl.append(descriptionEl) lineEl.append(videoEl) + lineEl.append(lastActivityEl) table.append(lineEl) if (/^[a-zA-A0-9-]+$/.test(uuid)) { diff --git a/prosody-modules/mod_http_peertubelivechat_list_rooms/mod_http_peertubelivechat_list_rooms.lua b/prosody-modules/mod_http_peertubelivechat_list_rooms/mod_http_peertubelivechat_list_rooms.lua index ca6c9e72..83ee98be 100644 --- a/prosody-modules/mod_http_peertubelivechat_list_rooms/mod_http_peertubelivechat_list_rooms.lua +++ b/prosody-modules/mod_http_peertubelivechat_list_rooms/mod_http_peertubelivechat_list_rooms.lua @@ -36,12 +36,18 @@ local function list_rooms(event) local rooms_json = array(); for room in all_rooms() do local localpart = jid_split(room.jid); + local history = room._history; + local lasttimestamp; + if history ~= nil and #history > 0 then + lasttimestamp = history[#history].timestamp; + end rooms_json:push({ jid = room.jid; localpart = localpart; name = room:get_name() or localpart; lang = room.get_language and room:get_language(); description = room:get_description(); + lasttimestamp = lasttimestamp; }) end diff --git a/shared/lib/types.ts b/shared/lib/types.ts index 9e00f40a..d21f4ab8 100644 --- a/shared/lib/types.ts +++ b/shared/lib/types.ts @@ -13,6 +13,7 @@ interface ProsodyListRoomsResultSuccess { name: string lang: string description: string + lasttimestamp?: number }> }