Mercurial > prosody-modules
annotate mod_http_muc_log/mod_http_muc_log.lua @ 5860:fdff8cb54302
mod_report_forward: fix address detection when there are multiple field values
author | Stephen Paul Weber <singpolyma@singpolyma.net> |
---|---|
date | Mon, 11 Mar 2024 19:28:19 -0500 |
parents | 0ee77be396b9 |
children |
rev | line source |
---|---|
1606
2c8b985ebde5
mod_http_muc_log: Switch to a calendar view for selecting dates
Kim Alvefur <zash@zash.se>
parents:
1605
diff
changeset
|
1 local mt = require"util.multitable"; |
1549
f9f8bf82ece7
mod_http_muc_log: MUC log module using new archive API
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
2 local datetime = require"util.datetime"; |
f9f8bf82ece7
mod_http_muc_log: MUC log module using new archive API
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
3 local jid_split = require"util.jid".split; |
f9f8bf82ece7
mod_http_muc_log: MUC log module using new archive API
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
4 local nodeprep = require"util.encodings".stringprep.nodeprep; |
1581
9f6cd252d233
mod_http_muc_log: Revamp template system
Kim Alvefur <zash@zash.se>
parents:
1580
diff
changeset
|
5 local url = require"socket.url"; |
1606
2c8b985ebde5
mod_http_muc_log: Switch to a calendar view for selecting dates
Kim Alvefur <zash@zash.se>
parents:
1605
diff
changeset
|
6 local os_time, os_date = os.time, os.date; |
3485
181561d0aae5
mod_http_muc_log: Add functionality for hiding joins and parts
Kim Alvefur <zash@zash.se>
parents:
3283
diff
changeset
|
7 local httplib = require "util.http"; |
3750
9002c8a2165f
mod_http_muc_log: Refactor calendarization of date list into a template filter BC
Kim Alvefur <zash@zash.se>
parents:
3749
diff
changeset
|
8 local render_funcs = {}; |
9002c8a2165f
mod_http_muc_log: Refactor calendarization of date list into a template filter BC
Kim Alvefur <zash@zash.se>
parents:
3749
diff
changeset
|
9 local render = require"util.interpolation".new("%b{}", require"util.stanza".xml_escape, render_funcs); |
1549
f9f8bf82ece7
mod_http_muc_log: MUC log module using new archive API
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
10 |
1571
eed7db9f3157
mod_mam_muc, mod_http_muc_log: Change store name from 'archive2' to 'muc_log' to distinguish it from personal MAM archives. Old data will require migration.
Kim Alvefur <zash@zash.se>
parents:
1564
diff
changeset
|
11 local archive = module:open_store("muc_log", "archive"); |
1549
f9f8bf82ece7
mod_http_muc_log: MUC log module using new archive API
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
12 |
4970
8c7b7db69f5b
mod_http_muc_log: Drop support for pre-0.11 MUC API
Kim Alvefur <zash@zash.se>
parents:
4963
diff
changeset
|
13 -- Prosody 0.11+ MUC API |
1549
f9f8bf82ece7
mod_http_muc_log: MUC log module using new archive API
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
14 local mod_muc = module:depends"muc"; |
4970
8c7b7db69f5b
mod_http_muc_log: Drop support for pre-0.11 MUC API
Kim Alvefur <zash@zash.se>
parents:
4963
diff
changeset
|
15 local each_room = mod_muc.each_room; |
8c7b7db69f5b
mod_http_muc_log: Drop support for pre-0.11 MUC API
Kim Alvefur <zash@zash.se>
parents:
4963
diff
changeset
|
16 local get_room_from_jid = mod_muc.get_room_from_jid; |
1549
f9f8bf82ece7
mod_http_muc_log: MUC log module using new archive API
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
17 |
f9f8bf82ece7
mod_http_muc_log: MUC log module using new archive API
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
18 local function get_room(name) |
f9f8bf82ece7
mod_http_muc_log: MUC log module using new archive API
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
19 local jid = name .. '@' .. module.host; |
f9f8bf82ece7
mod_http_muc_log: MUC log module using new archive API
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
20 return get_room_from_jid(jid); |
f9f8bf82ece7
mod_http_muc_log: MUC log module using new archive API
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
21 end |
f9f8bf82ece7
mod_http_muc_log: MUC log module using new archive API
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
22 |
3582
444e2306c99a
mod_http_muc_log: Add option to show OOB images
Kim Alvefur <zash@zash.se>
parents:
3578
diff
changeset
|
23 local use_oob = module:get_option_boolean(module.name .. "_show_images", false); |
1549
f9f8bf82ece7
mod_http_muc_log: MUC log module using new archive API
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
24 module:depends"http"; |
f9f8bf82ece7
mod_http_muc_log: MUC log module using new archive API
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
25 |
1654
1a6d6221c5f6
mod_http_muc_log: Cleanup [luacheck]
Kim Alvefur <zash@zash.se>
parents:
1625
diff
changeset
|
26 local template; |
1582
8e282eb0c70c
mod_http_muc_log: Split out template into a configurable file.
Kim Alvefur <zash@zash.se>
parents:
1581
diff
changeset
|
27 do |
4182
1890115b2773
mod_http_muc_log: Move template into a directory to ease packaging
Kim Alvefur <zash@zash.se>
parents:
4034
diff
changeset
|
28 local template_filename = module:get_option_string(module.name .. "_template", "res/" .. module.name .. ".html"); |
3066
cefc375d0929
mod_http_muc_log: Handle errors while loading template file in a more graceful manner
Kim Alvefur <zash@zash.se>
parents:
3064
diff
changeset
|
29 local template_file, err = module:load_resource(template_filename); |
cefc375d0929
mod_http_muc_log: Handle errors while loading template file in a more graceful manner
Kim Alvefur <zash@zash.se>
parents:
3064
diff
changeset
|
30 if template_file then |
cefc375d0929
mod_http_muc_log: Handle errors while loading template file in a more graceful manner
Kim Alvefur <zash@zash.se>
parents:
3064
diff
changeset
|
31 template, err = template_file:read("*a"); |
cefc375d0929
mod_http_muc_log: Handle errors while loading template file in a more graceful manner
Kim Alvefur <zash@zash.se>
parents:
3064
diff
changeset
|
32 template_file:close(); |
cefc375d0929
mod_http_muc_log: Handle errors while loading template file in a more graceful manner
Kim Alvefur <zash@zash.se>
parents:
3064
diff
changeset
|
33 end |
cefc375d0929
mod_http_muc_log: Handle errors while loading template file in a more graceful manner
Kim Alvefur <zash@zash.se>
parents:
3064
diff
changeset
|
34 if not template then |
cefc375d0929
mod_http_muc_log: Handle errors while loading template file in a more graceful manner
Kim Alvefur <zash@zash.se>
parents:
3064
diff
changeset
|
35 module:log("error", "Error loading template: %s", err); |
3486
887ce59cf396
mod_http_muc_log: Split long line [luacheck]
Kim Alvefur <zash@zash.se>
parents:
3485
diff
changeset
|
36 template = render("<h1>mod_{module} could not read the template</h1>\ |
887ce59cf396
mod_http_muc_log: Split long line [luacheck]
Kim Alvefur <zash@zash.se>
parents:
3485
diff
changeset
|
37 <p>Tried to open <b>{filename}</b></p>\ |
887ce59cf396
mod_http_muc_log: Split long line [luacheck]
Kim Alvefur <zash@zash.se>
parents:
3485
diff
changeset
|
38 <pre>{error}</pre>", |
3066
cefc375d0929
mod_http_muc_log: Handle errors while loading template file in a more graceful manner
Kim Alvefur <zash@zash.se>
parents:
3064
diff
changeset
|
39 { module = module.name, filename = template_filename, error = err }); |
cefc375d0929
mod_http_muc_log: Handle errors while loading template file in a more graceful manner
Kim Alvefur <zash@zash.se>
parents:
3064
diff
changeset
|
40 end |
1582
8e282eb0c70c
mod_http_muc_log: Split out template into a configurable file.
Kim Alvefur <zash@zash.se>
parents:
1581
diff
changeset
|
41 end |
1549
f9f8bf82ece7
mod_http_muc_log: MUC log module using new archive API
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
42 |
5104
d4b0a995e5e3
mod_http_muc_log: Move CSS and JS out of template
Kim Alvefur <zash@zash.se>
parents:
4993
diff
changeset
|
43 local resources = module:get_option_path(module.name .. "_resources", "static"); |
d4b0a995e5e3
mod_http_muc_log: Move CSS and JS out of template
Kim Alvefur <zash@zash.se>
parents:
4993
diff
changeset
|
44 |
1654
1a6d6221c5f6
mod_http_muc_log: Cleanup [luacheck]
Kim Alvefur <zash@zash.se>
parents:
1625
diff
changeset
|
45 -- local base_url = module:http_url() .. '/'; -- TODO: Generate links in a smart way |
1581
9f6cd252d233
mod_http_muc_log: Revamp template system
Kim Alvefur <zash@zash.se>
parents:
1580
diff
changeset
|
46 local get_link do |
9f6cd252d233
mod_http_muc_log: Revamp template system
Kim Alvefur <zash@zash.se>
parents:
1580
diff
changeset
|
47 local link, path = { path = '/' }, { "", "", is_directory = true }; |
9f6cd252d233
mod_http_muc_log: Revamp template system
Kim Alvefur <zash@zash.se>
parents:
1580
diff
changeset
|
48 function get_link(room, date) |
9f6cd252d233
mod_http_muc_log: Revamp template system
Kim Alvefur <zash@zash.se>
parents:
1580
diff
changeset
|
49 path[1], path[2] = room, date; |
9f6cd252d233
mod_http_muc_log: Revamp template system
Kim Alvefur <zash@zash.se>
parents:
1580
diff
changeset
|
50 path.is_directory = not date; |
9f6cd252d233
mod_http_muc_log: Revamp template system
Kim Alvefur <zash@zash.se>
parents:
1580
diff
changeset
|
51 link.path = url.build_path(path); |
9f6cd252d233
mod_http_muc_log: Revamp template system
Kim Alvefur <zash@zash.se>
parents:
1580
diff
changeset
|
52 return url.build(link); |
9f6cd252d233
mod_http_muc_log: Revamp template system
Kim Alvefur <zash@zash.se>
parents:
1580
diff
changeset
|
53 end |
9f6cd252d233
mod_http_muc_log: Revamp template system
Kim Alvefur <zash@zash.se>
parents:
1580
diff
changeset
|
54 end |
1549
f9f8bf82ece7
mod_http_muc_log: MUC log module using new archive API
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
55 |
3593
0b670831ace3
mod_http_muc_log: Correctly build absolute URLs
Kim Alvefur <zash@zash.se>
parents:
3592
diff
changeset
|
56 local function get_absolute_link(room, date) |
0b670831ace3
mod_http_muc_log: Correctly build absolute URLs
Kim Alvefur <zash@zash.se>
parents:
3592
diff
changeset
|
57 local link = url.parse(module:http_url()); |
0b670831ace3
mod_http_muc_log: Correctly build absolute URLs
Kim Alvefur <zash@zash.se>
parents:
3592
diff
changeset
|
58 local path = url.parse_path(link.path); |
0b670831ace3
mod_http_muc_log: Correctly build absolute URLs
Kim Alvefur <zash@zash.se>
parents:
3592
diff
changeset
|
59 if room then |
0b670831ace3
mod_http_muc_log: Correctly build absolute URLs
Kim Alvefur <zash@zash.se>
parents:
3592
diff
changeset
|
60 table.insert(path, room); |
0b670831ace3
mod_http_muc_log: Correctly build absolute URLs
Kim Alvefur <zash@zash.se>
parents:
3592
diff
changeset
|
61 if date then |
0b670831ace3
mod_http_muc_log: Correctly build absolute URLs
Kim Alvefur <zash@zash.se>
parents:
3592
diff
changeset
|
62 table.insert(path, date) |
0b670831ace3
mod_http_muc_log: Correctly build absolute URLs
Kim Alvefur <zash@zash.se>
parents:
3592
diff
changeset
|
63 path.is_directory = false; |
0b670831ace3
mod_http_muc_log: Correctly build absolute URLs
Kim Alvefur <zash@zash.se>
parents:
3592
diff
changeset
|
64 else |
0b670831ace3
mod_http_muc_log: Correctly build absolute URLs
Kim Alvefur <zash@zash.se>
parents:
3592
diff
changeset
|
65 path.is_directory = true; |
0b670831ace3
mod_http_muc_log: Correctly build absolute URLs
Kim Alvefur <zash@zash.se>
parents:
3592
diff
changeset
|
66 end |
0b670831ace3
mod_http_muc_log: Correctly build absolute URLs
Kim Alvefur <zash@zash.se>
parents:
3592
diff
changeset
|
67 end |
0b670831ace3
mod_http_muc_log: Correctly build absolute URLs
Kim Alvefur <zash@zash.se>
parents:
3592
diff
changeset
|
68 link.path = url.build_path(path) |
0b670831ace3
mod_http_muc_log: Correctly build absolute URLs
Kim Alvefur <zash@zash.se>
parents:
3592
diff
changeset
|
69 return url.build(link) |
0b670831ace3
mod_http_muc_log: Correctly build absolute URLs
Kim Alvefur <zash@zash.se>
parents:
3592
diff
changeset
|
70 end |
0b670831ace3
mod_http_muc_log: Correctly build absolute URLs
Kim Alvefur <zash@zash.se>
parents:
3592
diff
changeset
|
71 |
3059
14d8f2a9d5f4
mod_http_muc_log: Base read-access on whether anyone would be able to join (like MUC)
Kim Alvefur <zash@zash.se>
parents:
3058
diff
changeset
|
72 -- Whether room can be joined by anyone |
14d8f2a9d5f4
mod_http_muc_log: Base read-access on whether anyone would be able to join (like MUC)
Kim Alvefur <zash@zash.se>
parents:
3058
diff
changeset
|
73 local function open_room(room) -- : boolean |
1549
f9f8bf82ece7
mod_http_muc_log: MUC log module using new archive API
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
74 if type(room) == "string" then |
f9f8bf82ece7
mod_http_muc_log: MUC log module using new archive API
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
75 room = get_room(room); |
3061
25eecbb195d9
mod_http_muc_log: Add comment about argument to policy function
Kim Alvefur <zash@zash.se>
parents:
3060
diff
changeset
|
76 -- assumed to be a room object otherwise |
1549
f9f8bf82ece7
mod_http_muc_log: MUC log module using new archive API
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
77 end |
3057
f69a2e97d912
mod_http_muc_log: Improve readability of policy function
Kim Alvefur <zash@zash.se>
parents:
2846
diff
changeset
|
78 if not room then |
f69a2e97d912
mod_http_muc_log: Improve readability of policy function
Kim Alvefur <zash@zash.se>
parents:
2846
diff
changeset
|
79 return nil; |
f69a2e97d912
mod_http_muc_log: Improve readability of policy function
Kim Alvefur <zash@zash.se>
parents:
2846
diff
changeset
|
80 end |
f69a2e97d912
mod_http_muc_log: Improve readability of policy function
Kim Alvefur <zash@zash.se>
parents:
2846
diff
changeset
|
81 |
3059
14d8f2a9d5f4
mod_http_muc_log: Base read-access on whether anyone would be able to join (like MUC)
Kim Alvefur <zash@zash.se>
parents:
3058
diff
changeset
|
82 if (room.get_members_only or room.is_members_only)(room) then |
14d8f2a9d5f4
mod_http_muc_log: Base read-access on whether anyone would be able to join (like MUC)
Kim Alvefur <zash@zash.se>
parents:
3058
diff
changeset
|
83 return false; |
3057
f69a2e97d912
mod_http_muc_log: Improve readability of policy function
Kim Alvefur <zash@zash.se>
parents:
2846
diff
changeset
|
84 end |
f69a2e97d912
mod_http_muc_log: Improve readability of policy function
Kim Alvefur <zash@zash.se>
parents:
2846
diff
changeset
|
85 |
3059
14d8f2a9d5f4
mod_http_muc_log: Base read-access on whether anyone would be able to join (like MUC)
Kim Alvefur <zash@zash.se>
parents:
3058
diff
changeset
|
86 if room:get_password() then |
3057
f69a2e97d912
mod_http_muc_log: Improve readability of policy function
Kim Alvefur <zash@zash.se>
parents:
2846
diff
changeset
|
87 return false; |
f69a2e97d912
mod_http_muc_log: Improve readability of policy function
Kim Alvefur <zash@zash.se>
parents:
2846
diff
changeset
|
88 end |
f69a2e97d912
mod_http_muc_log: Improve readability of policy function
Kim Alvefur <zash@zash.se>
parents:
2846
diff
changeset
|
89 |
f69a2e97d912
mod_http_muc_log: Improve readability of policy function
Kim Alvefur <zash@zash.se>
parents:
2846
diff
changeset
|
90 return true; |
1549
f9f8bf82ece7
mod_http_muc_log: MUC log module using new archive API
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
91 end |
f9f8bf82ece7
mod_http_muc_log: MUC log module using new archive API
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
92 |
3596
6e529f53b3c3
mod_http_muc_log: Allow specifying the default view
Kim Alvefur <zash@zash.se>
parents:
3595
diff
changeset
|
93 -- Can be set to "latest" |
6e529f53b3c3
mod_http_muc_log: Allow specifying the default view
Kim Alvefur <zash@zash.se>
parents:
3595
diff
changeset
|
94 local default_view = module:get_option_string(module.name .. "_default_view", nil); |
6e529f53b3c3
mod_http_muc_log: Allow specifying the default view
Kim Alvefur <zash@zash.se>
parents:
3595
diff
changeset
|
95 |
3064
ce61f1826f1f
mod_http_muc_log: Include URL in disco#info for public rooms
Kim Alvefur <zash@zash.se>
parents:
3063
diff
changeset
|
96 module:hook("muc-disco#info", function (event) |
ce61f1826f1f
mod_http_muc_log: Include URL in disco#info for public rooms
Kim Alvefur <zash@zash.se>
parents:
3063
diff
changeset
|
97 local room = event.room; |
ce61f1826f1f
mod_http_muc_log: Include URL in disco#info for public rooms
Kim Alvefur <zash@zash.se>
parents:
3063
diff
changeset
|
98 if open_room(room) then |
ce61f1826f1f
mod_http_muc_log: Include URL in disco#info for public rooms
Kim Alvefur <zash@zash.se>
parents:
3063
diff
changeset
|
99 table.insert(event.form, { name = "muc#roominfo_logs", type="text-single" }); |
3596
6e529f53b3c3
mod_http_muc_log: Allow specifying the default view
Kim Alvefur <zash@zash.se>
parents:
3595
diff
changeset
|
100 event.formdata["muc#roominfo_logs"] = get_absolute_link(jid_split(event.room.jid), default_view); |
3064
ce61f1826f1f
mod_http_muc_log: Include URL in disco#info for public rooms
Kim Alvefur <zash@zash.se>
parents:
3063
diff
changeset
|
101 end |
ce61f1826f1f
mod_http_muc_log: Include URL in disco#info for public rooms
Kim Alvefur <zash@zash.se>
parents:
3063
diff
changeset
|
102 end); |
ce61f1826f1f
mod_http_muc_log: Include URL in disco#info for public rooms
Kim Alvefur <zash@zash.se>
parents:
3063
diff
changeset
|
103 |
1606
2c8b985ebde5
mod_http_muc_log: Switch to a calendar view for selecting dates
Kim Alvefur <zash@zash.se>
parents:
1605
diff
changeset
|
104 local function sort_Y(a,b) return a.year > b.year end |
2c8b985ebde5
mod_http_muc_log: Switch to a calendar view for selecting dates
Kim Alvefur <zash@zash.se>
parents:
1605
diff
changeset
|
105 local function sort_m(a,b) return a.n > b.n end |
2c8b985ebde5
mod_http_muc_log: Switch to a calendar view for selecting dates
Kim Alvefur <zash@zash.se>
parents:
1605
diff
changeset
|
106 |
2590
63dd3e525f13
mod_http_muc_log: Add some comments
Kim Alvefur <zash@zash.se>
parents:
2236
diff
changeset
|
107 -- Time zone hack? |
1606
2c8b985ebde5
mod_http_muc_log: Switch to a calendar view for selecting dates
Kim Alvefur <zash@zash.se>
parents:
1605
diff
changeset
|
108 local t_diff = os_time(os_date("*t")) - os_time(os_date("!*t")); |
2c8b985ebde5
mod_http_muc_log: Switch to a calendar view for selecting dates
Kim Alvefur <zash@zash.se>
parents:
1605
diff
changeset
|
109 local function time(t) |
2c8b985ebde5
mod_http_muc_log: Switch to a calendar view for selecting dates
Kim Alvefur <zash@zash.se>
parents:
1605
diff
changeset
|
110 return os_time(t) + t_diff; |
2c8b985ebde5
mod_http_muc_log: Switch to a calendar view for selecting dates
Kim Alvefur <zash@zash.se>
parents:
1605
diff
changeset
|
111 end |
2836
52a7c0f6aea1
mod_http_muc_log: Add a function for rounding timestamps down to midnight
Kim Alvefur <zash@zash.se>
parents:
2826
diff
changeset
|
112 local function date_floor(t) |
52a7c0f6aea1
mod_http_muc_log: Add a function for rounding timestamps down to midnight
Kim Alvefur <zash@zash.se>
parents:
2826
diff
changeset
|
113 return t - t % 86400; |
52a7c0f6aea1
mod_http_muc_log: Add a function for rounding timestamps down to midnight
Kim Alvefur <zash@zash.se>
parents:
2826
diff
changeset
|
114 end |
1606
2c8b985ebde5
mod_http_muc_log: Switch to a calendar view for selecting dates
Kim Alvefur <zash@zash.se>
parents:
1605
diff
changeset
|
115 |
2590
63dd3e525f13
mod_http_muc_log: Add some comments
Kim Alvefur <zash@zash.se>
parents:
2236
diff
changeset
|
116 -- Fetch one item |
1654
1a6d6221c5f6
mod_http_muc_log: Cleanup [luacheck]
Kim Alvefur <zash@zash.se>
parents:
1625
diff
changeset
|
117 local function find_once(room, query, retval) |
1a6d6221c5f6
mod_http_muc_log: Cleanup [luacheck]
Kim Alvefur <zash@zash.se>
parents:
1625
diff
changeset
|
118 if query then query.limit = 1; else query = { limit = 1 }; end |
1a6d6221c5f6
mod_http_muc_log: Cleanup [luacheck]
Kim Alvefur <zash@zash.se>
parents:
1625
diff
changeset
|
119 local iter, err = archive:find(room, query); |
1a6d6221c5f6
mod_http_muc_log: Cleanup [luacheck]
Kim Alvefur <zash@zash.se>
parents:
1625
diff
changeset
|
120 if not iter then return iter, err; end |
1a6d6221c5f6
mod_http_muc_log: Cleanup [luacheck]
Kim Alvefur <zash@zash.se>
parents:
1625
diff
changeset
|
121 if retval then |
1a6d6221c5f6
mod_http_muc_log: Cleanup [luacheck]
Kim Alvefur <zash@zash.se>
parents:
1625
diff
changeset
|
122 return select(retval, iter()); |
1a6d6221c5f6
mod_http_muc_log: Cleanup [luacheck]
Kim Alvefur <zash@zash.se>
parents:
1625
diff
changeset
|
123 end |
1a6d6221c5f6
mod_http_muc_log: Cleanup [luacheck]
Kim Alvefur <zash@zash.se>
parents:
1625
diff
changeset
|
124 return iter(); |
1a6d6221c5f6
mod_http_muc_log: Cleanup [luacheck]
Kim Alvefur <zash@zash.se>
parents:
1625
diff
changeset
|
125 end |
1a6d6221c5f6
mod_http_muc_log: Cleanup [luacheck]
Kim Alvefur <zash@zash.se>
parents:
1625
diff
changeset
|
126 |
2826
ed26608920d4
mod_http_muc_log: Switch to an inaccurate but O(1) method of producing the calendar view
Kim Alvefur <zash@zash.se>
parents:
2763
diff
changeset
|
127 local lazy = module:get_option_boolean(module.name .. "_lazy_calendar", true); |
ed26608920d4
mod_http_muc_log: Switch to an inaccurate but O(1) method of producing the calendar view
Kim Alvefur <zash@zash.se>
parents:
2763
diff
changeset
|
128 |
3597
da7ec4ed6ddf
mod_http_muc_log: Hide join/part controls if they are not stored by mod_muc_mam
Kim Alvefur <zash@zash.se>
parents:
3596
diff
changeset
|
129 local presence_logged = module:get_option_boolean("muc_log_presences", false); |
da7ec4ed6ddf
mod_http_muc_log: Hide join/part controls if they are not stored by mod_muc_mam
Kim Alvefur <zash@zash.se>
parents:
3596
diff
changeset
|
130 |
5581
df483d9056f5
mod_http_muc_log: Hide joins and parts by default
Kim Alvefur <zash@zash.se>
parents:
5118
diff
changeset
|
131 local function show_presence(request) --> boolean|nil |
df483d9056f5
mod_http_muc_log: Hide joins and parts by default
Kim Alvefur <zash@zash.se>
parents:
5118
diff
changeset
|
132 -- boolean -> yes or no |
df483d9056f5
mod_http_muc_log: Hide joins and parts by default
Kim Alvefur <zash@zash.se>
parents:
5118
diff
changeset
|
133 -- nil -> dunno |
3597
da7ec4ed6ddf
mod_http_muc_log: Hide join/part controls if they are not stored by mod_muc_mam
Kim Alvefur <zash@zash.se>
parents:
3596
diff
changeset
|
134 if not presence_logged then |
5581
df483d9056f5
mod_http_muc_log: Hide joins and parts by default
Kim Alvefur <zash@zash.se>
parents:
5118
diff
changeset
|
135 -- No presence stored, skip |
df483d9056f5
mod_http_muc_log: Hide joins and parts by default
Kim Alvefur <zash@zash.se>
parents:
5118
diff
changeset
|
136 return nil; |
3597
da7ec4ed6ddf
mod_http_muc_log: Hide join/part controls if they are not stored by mod_muc_mam
Kim Alvefur <zash@zash.se>
parents:
3596
diff
changeset
|
137 end |
3485
181561d0aae5
mod_http_muc_log: Add functionality for hiding joins and parts
Kim Alvefur <zash@zash.se>
parents:
3283
diff
changeset
|
138 if request.url.query then |
181561d0aae5
mod_http_muc_log: Add functionality for hiding joins and parts
Kim Alvefur <zash@zash.se>
parents:
3283
diff
changeset
|
139 local data = httplib.formdecode(request.url.query); |
5581
df483d9056f5
mod_http_muc_log: Hide joins and parts by default
Kim Alvefur <zash@zash.se>
parents:
5118
diff
changeset
|
140 if type(data) == "table" then |
df483d9056f5
mod_http_muc_log: Hide joins and parts by default
Kim Alvefur <zash@zash.se>
parents:
5118
diff
changeset
|
141 if data.p == "s" or data.p == "h" then |
df483d9056f5
mod_http_muc_log: Hide joins and parts by default
Kim Alvefur <zash@zash.se>
parents:
5118
diff
changeset
|
142 return data.p == "s"; |
df483d9056f5
mod_http_muc_log: Hide joins and parts by default
Kim Alvefur <zash@zash.se>
parents:
5118
diff
changeset
|
143 end |
3485
181561d0aae5
mod_http_muc_log: Add functionality for hiding joins and parts
Kim Alvefur <zash@zash.se>
parents:
3283
diff
changeset
|
144 end |
181561d0aae5
mod_http_muc_log: Add functionality for hiding joins and parts
Kim Alvefur <zash@zash.se>
parents:
3283
diff
changeset
|
145 end |
5581
df483d9056f5
mod_http_muc_log: Hide joins and parts by default
Kim Alvefur <zash@zash.se>
parents:
5118
diff
changeset
|
146 end |
df483d9056f5
mod_http_muc_log: Hide joins and parts by default
Kim Alvefur <zash@zash.se>
parents:
5118
diff
changeset
|
147 |
df483d9056f5
mod_http_muc_log: Hide joins and parts by default
Kim Alvefur <zash@zash.se>
parents:
5118
diff
changeset
|
148 local function presence_with(request) |
df483d9056f5
mod_http_muc_log: Hide joins and parts by default
Kim Alvefur <zash@zash.se>
parents:
5118
diff
changeset
|
149 local show = show_presence(request); |
df483d9056f5
mod_http_muc_log: Hide joins and parts by default
Kim Alvefur <zash@zash.se>
parents:
5118
diff
changeset
|
150 if show == true then |
df483d9056f5
mod_http_muc_log: Hide joins and parts by default
Kim Alvefur <zash@zash.se>
parents:
5118
diff
changeset
|
151 return nil; -- no filter, everything |
df483d9056f5
mod_http_muc_log: Hide joins and parts by default
Kim Alvefur <zash@zash.se>
parents:
5118
diff
changeset
|
152 elseif show == false or show == nil then |
df483d9056f5
mod_http_muc_log: Hide joins and parts by default
Kim Alvefur <zash@zash.se>
parents:
5118
diff
changeset
|
153 -- only messages |
df483d9056f5
mod_http_muc_log: Hide joins and parts by default
Kim Alvefur <zash@zash.se>
parents:
5118
diff
changeset
|
154 return "message<groupchat"; |
df483d9056f5
mod_http_muc_log: Hide joins and parts by default
Kim Alvefur <zash@zash.se>
parents:
5118
diff
changeset
|
155 end |
df483d9056f5
mod_http_muc_log: Hide joins and parts by default
Kim Alvefur <zash@zash.se>
parents:
5118
diff
changeset
|
156 end |
df483d9056f5
mod_http_muc_log: Hide joins and parts by default
Kim Alvefur <zash@zash.se>
parents:
5118
diff
changeset
|
157 |
df483d9056f5
mod_http_muc_log: Hide joins and parts by default
Kim Alvefur <zash@zash.se>
parents:
5118
diff
changeset
|
158 local function presence_query(request) -- > ?p=[sh] |
df483d9056f5
mod_http_muc_log: Hide joins and parts by default
Kim Alvefur <zash@zash.se>
parents:
5118
diff
changeset
|
159 local show = show_presence(request); |
df483d9056f5
mod_http_muc_log: Hide joins and parts by default
Kim Alvefur <zash@zash.se>
parents:
5118
diff
changeset
|
160 if show == true then |
df483d9056f5
mod_http_muc_log: Hide joins and parts by default
Kim Alvefur <zash@zash.se>
parents:
5118
diff
changeset
|
161 return { p = "s" } |
df483d9056f5
mod_http_muc_log: Hide joins and parts by default
Kim Alvefur <zash@zash.se>
parents:
5118
diff
changeset
|
162 elseif show == false then |
df483d9056f5
mod_http_muc_log: Hide joins and parts by default
Kim Alvefur <zash@zash.se>
parents:
5118
diff
changeset
|
163 return { p = "h" } |
df483d9056f5
mod_http_muc_log: Hide joins and parts by default
Kim Alvefur <zash@zash.se>
parents:
5118
diff
changeset
|
164 else |
df483d9056f5
mod_http_muc_log: Hide joins and parts by default
Kim Alvefur <zash@zash.se>
parents:
5118
diff
changeset
|
165 return nil; |
df483d9056f5
mod_http_muc_log: Hide joins and parts by default
Kim Alvefur <zash@zash.se>
parents:
5118
diff
changeset
|
166 end |
3485
181561d0aae5
mod_http_muc_log: Add functionality for hiding joins and parts
Kim Alvefur <zash@zash.se>
parents:
3283
diff
changeset
|
167 end |
181561d0aae5
mod_http_muc_log: Add functionality for hiding joins and parts
Kim Alvefur <zash@zash.se>
parents:
3283
diff
changeset
|
168 |
3750
9002c8a2165f
mod_http_muc_log: Refactor calendarization of date list into a template filter BC
Kim Alvefur <zash@zash.se>
parents:
3749
diff
changeset
|
169 local function get_dates(room) --> { integer, ... } |
9002c8a2165f
mod_http_muc_log: Refactor calendarization of date list into a template filter BC
Kim Alvefur <zash@zash.se>
parents:
3749
diff
changeset
|
170 local date_list = archive.dates and archive:dates(room); |
9002c8a2165f
mod_http_muc_log: Refactor calendarization of date list into a template filter BC
Kim Alvefur <zash@zash.se>
parents:
3749
diff
changeset
|
171 if date_list then |
9002c8a2165f
mod_http_muc_log: Refactor calendarization of date list into a template filter BC
Kim Alvefur <zash@zash.se>
parents:
3749
diff
changeset
|
172 for i = 1, #date_list do |
9002c8a2165f
mod_http_muc_log: Refactor calendarization of date list into a template filter BC
Kim Alvefur <zash@zash.se>
parents:
3749
diff
changeset
|
173 date_list[i] = datetime.parse(date_list[i].."T00:00:00Z"); |
9002c8a2165f
mod_http_muc_log: Refactor calendarization of date list into a template filter BC
Kim Alvefur <zash@zash.se>
parents:
3749
diff
changeset
|
174 end |
9002c8a2165f
mod_http_muc_log: Refactor calendarization of date list into a template filter BC
Kim Alvefur <zash@zash.se>
parents:
3749
diff
changeset
|
175 return date_list; |
3059
14d8f2a9d5f4
mod_http_muc_log: Base read-access on whether anyone would be able to join (like MUC)
Kim Alvefur <zash@zash.se>
parents:
3058
diff
changeset
|
176 end |
1549
f9f8bf82ece7
mod_http_muc_log: MUC log module using new archive API
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
177 |
3750
9002c8a2165f
mod_http_muc_log: Refactor calendarization of date list into a template filter BC
Kim Alvefur <zash@zash.se>
parents:
3749
diff
changeset
|
178 if lazy then |
2826
ed26608920d4
mod_http_muc_log: Switch to an inaccurate but O(1) method of producing the calendar view
Kim Alvefur <zash@zash.se>
parents:
2763
diff
changeset
|
179 -- Lazy with many false positives |
3750
9002c8a2165f
mod_http_muc_log: Refactor calendarization of date list into a template filter BC
Kim Alvefur <zash@zash.se>
parents:
3749
diff
changeset
|
180 date_list = {}; |
2826
ed26608920d4
mod_http_muc_log: Switch to an inaccurate but O(1) method of producing the calendar view
Kim Alvefur <zash@zash.se>
parents:
2763
diff
changeset
|
181 local first_day = find_once(room, nil, 3); |
ed26608920d4
mod_http_muc_log: Switch to an inaccurate but O(1) method of producing the calendar view
Kim Alvefur <zash@zash.se>
parents:
2763
diff
changeset
|
182 local last_day = find_once(room, { reverse = true }, 3); |
2839
7738d7158dd0
mod_http_muc_log: Return a 404 page if there are no messages to derive a time span from
Kim Alvefur <zash@zash.se>
parents:
2838
diff
changeset
|
183 if first_day and last_day then |
7738d7158dd0
mod_http_muc_log: Return a 404 page if there are no messages to derive a time span from
Kim Alvefur <zash@zash.se>
parents:
2838
diff
changeset
|
184 first_day = date_floor(first_day); |
7738d7158dd0
mod_http_muc_log: Return a 404 page if there are no messages to derive a time span from
Kim Alvefur <zash@zash.se>
parents:
2838
diff
changeset
|
185 last_day = date_floor(last_day); |
7738d7158dd0
mod_http_muc_log: Return a 404 page if there are no messages to derive a time span from
Kim Alvefur <zash@zash.se>
parents:
2838
diff
changeset
|
186 for when = first_day, last_day, 86400 do |
3750
9002c8a2165f
mod_http_muc_log: Refactor calendarization of date list into a template filter BC
Kim Alvefur <zash@zash.se>
parents:
3749
diff
changeset
|
187 table.insert(date_list, when); |
2839
7738d7158dd0
mod_http_muc_log: Return a 404 page if there are no messages to derive a time span from
Kim Alvefur <zash@zash.se>
parents:
2838
diff
changeset
|
188 end |
7738d7158dd0
mod_http_muc_log: Return a 404 page if there are no messages to derive a time span from
Kim Alvefur <zash@zash.se>
parents:
2838
diff
changeset
|
189 else |
7738d7158dd0
mod_http_muc_log: Return a 404 page if there are no messages to derive a time span from
Kim Alvefur <zash@zash.se>
parents:
2838
diff
changeset
|
190 return; -- 404 |
2826
ed26608920d4
mod_http_muc_log: Switch to an inaccurate but O(1) method of producing the calendar view
Kim Alvefur <zash@zash.se>
parents:
2763
diff
changeset
|
191 end |
3750
9002c8a2165f
mod_http_muc_log: Refactor calendarization of date list into a template filter BC
Kim Alvefur <zash@zash.se>
parents:
3749
diff
changeset
|
192 return date_list; |
1832
48125f2c358b
mod_http_muc_log: If archive driver provides the dates method, use it
Kim Alvefur <zash@zash.se>
parents:
1750
diff
changeset
|
193 end |
1606
2c8b985ebde5
mod_http_muc_log: Switch to a calendar view for selecting dates
Kim Alvefur <zash@zash.se>
parents:
1605
diff
changeset
|
194 |
3750
9002c8a2165f
mod_http_muc_log: Refactor calendarization of date list into a template filter BC
Kim Alvefur <zash@zash.se>
parents:
3749
diff
changeset
|
195 -- Collect date the hard way |
9002c8a2165f
mod_http_muc_log: Refactor calendarization of date list into a template filter BC
Kim Alvefur <zash@zash.se>
parents:
3749
diff
changeset
|
196 module:log("debug", "Find all dates with messages"); |
9002c8a2165f
mod_http_muc_log: Refactor calendarization of date list into a template filter BC
Kim Alvefur <zash@zash.se>
parents:
3749
diff
changeset
|
197 date_list = {}; |
9002c8a2165f
mod_http_muc_log: Refactor calendarization of date list into a template filter BC
Kim Alvefur <zash@zash.se>
parents:
3749
diff
changeset
|
198 local next_day; |
9002c8a2165f
mod_http_muc_log: Refactor calendarization of date list into a template filter BC
Kim Alvefur <zash@zash.se>
parents:
3749
diff
changeset
|
199 repeat |
9002c8a2165f
mod_http_muc_log: Refactor calendarization of date list into a template filter BC
Kim Alvefur <zash@zash.se>
parents:
3749
diff
changeset
|
200 local when = find_once(room, { start = next_day; }, 3); |
9002c8a2165f
mod_http_muc_log: Refactor calendarization of date list into a template filter BC
Kim Alvefur <zash@zash.se>
parents:
3749
diff
changeset
|
201 if not when then break; end |
9002c8a2165f
mod_http_muc_log: Refactor calendarization of date list into a template filter BC
Kim Alvefur <zash@zash.se>
parents:
3749
diff
changeset
|
202 table.insert(date_list, when); |
9002c8a2165f
mod_http_muc_log: Refactor calendarization of date list into a template filter BC
Kim Alvefur <zash@zash.se>
parents:
3749
diff
changeset
|
203 next_day = date_floor(when) + 86400; |
9002c8a2165f
mod_http_muc_log: Refactor calendarization of date list into a template filter BC
Kim Alvefur <zash@zash.se>
parents:
3749
diff
changeset
|
204 until not next_day; |
9002c8a2165f
mod_http_muc_log: Refactor calendarization of date list into a template filter BC
Kim Alvefur <zash@zash.se>
parents:
3749
diff
changeset
|
205 return date_list; |
9002c8a2165f
mod_http_muc_log: Refactor calendarization of date list into a template filter BC
Kim Alvefur <zash@zash.se>
parents:
3749
diff
changeset
|
206 end |
1606
2c8b985ebde5
mod_http_muc_log: Switch to a calendar view for selecting dates
Kim Alvefur <zash@zash.se>
parents:
1605
diff
changeset
|
207 |
3750
9002c8a2165f
mod_http_muc_log: Refactor calendarization of date list into a template filter BC
Kim Alvefur <zash@zash.se>
parents:
3749
diff
changeset
|
208 function render_funcs.calendarize(date_list) |
9002c8a2165f
mod_http_muc_log: Refactor calendarization of date list into a template filter BC
Kim Alvefur <zash@zash.se>
parents:
3749
diff
changeset
|
209 -- convert array of timestamps to a year / month / day tree |
9002c8a2165f
mod_http_muc_log: Refactor calendarization of date list into a template filter BC
Kim Alvefur <zash@zash.se>
parents:
3749
diff
changeset
|
210 local dates = mt.new(); |
9002c8a2165f
mod_http_muc_log: Refactor calendarization of date list into a template filter BC
Kim Alvefur <zash@zash.se>
parents:
3749
diff
changeset
|
211 for _, when in ipairs(date_list) do |
9002c8a2165f
mod_http_muc_log: Refactor calendarization of date list into a template filter BC
Kim Alvefur <zash@zash.se>
parents:
3749
diff
changeset
|
212 local t = os_date("!*t", when); |
9002c8a2165f
mod_http_muc_log: Refactor calendarization of date list into a template filter BC
Kim Alvefur <zash@zash.se>
parents:
3749
diff
changeset
|
213 dates:set(t.year, t.month, t.day, when); |
9002c8a2165f
mod_http_muc_log: Refactor calendarization of date list into a template filter BC
Kim Alvefur <zash@zash.se>
parents:
3749
diff
changeset
|
214 end |
2590
63dd3e525f13
mod_http_muc_log: Add some comments
Kim Alvefur <zash@zash.se>
parents:
2236
diff
changeset
|
215 -- Wrangle Y/m/d tree into year / month / week / day tree for calendar view |
3750
9002c8a2165f
mod_http_muc_log: Refactor calendarization of date list into a template filter BC
Kim Alvefur <zash@zash.se>
parents:
3749
diff
changeset
|
216 local years = {}; |
1654
1a6d6221c5f6
mod_http_muc_log: Cleanup [luacheck]
Kim Alvefur <zash@zash.se>
parents:
1625
diff
changeset
|
217 for current_year, months_t in pairs(dates.data) do |
1a6d6221c5f6
mod_http_muc_log: Cleanup [luacheck]
Kim Alvefur <zash@zash.se>
parents:
1625
diff
changeset
|
218 local t = { year = current_year, month = 1, day = 1 }; |
1a6d6221c5f6
mod_http_muc_log: Cleanup [luacheck]
Kim Alvefur <zash@zash.se>
parents:
1625
diff
changeset
|
219 local months = { }; |
1a6d6221c5f6
mod_http_muc_log: Cleanup [luacheck]
Kim Alvefur <zash@zash.se>
parents:
1625
diff
changeset
|
220 local year = { year = current_year, months = months }; |
1606
2c8b985ebde5
mod_http_muc_log: Switch to a calendar view for selecting dates
Kim Alvefur <zash@zash.se>
parents:
1605
diff
changeset
|
221 years[#years+1] = year; |
1654
1a6d6221c5f6
mod_http_muc_log: Cleanup [luacheck]
Kim Alvefur <zash@zash.se>
parents:
1625
diff
changeset
|
222 for current_month, days_t in pairs(months_t) do |
1606
2c8b985ebde5
mod_http_muc_log: Switch to a calendar view for selecting dates
Kim Alvefur <zash@zash.se>
parents:
1605
diff
changeset
|
223 t.day = 1; |
1654
1a6d6221c5f6
mod_http_muc_log: Cleanup [luacheck]
Kim Alvefur <zash@zash.se>
parents:
1625
diff
changeset
|
224 t.month = current_month; |
1a6d6221c5f6
mod_http_muc_log: Cleanup [luacheck]
Kim Alvefur <zash@zash.se>
parents:
1625
diff
changeset
|
225 local tmp = os_date("!*t", time(t)); |
1a6d6221c5f6
mod_http_muc_log: Cleanup [luacheck]
Kim Alvefur <zash@zash.se>
parents:
1625
diff
changeset
|
226 local days = {}; |
1a6d6221c5f6
mod_http_muc_log: Cleanup [luacheck]
Kim Alvefur <zash@zash.se>
parents:
1625
diff
changeset
|
227 local week = { days = days } |
1a6d6221c5f6
mod_http_muc_log: Cleanup [luacheck]
Kim Alvefur <zash@zash.se>
parents:
1625
diff
changeset
|
228 local weeks = { week }; |
1a6d6221c5f6
mod_http_muc_log: Cleanup [luacheck]
Kim Alvefur <zash@zash.se>
parents:
1625
diff
changeset
|
229 local month = { year = year.year, month = os_date("!%B", time(t)), n = current_month, weeks = weeks }; |
1606
2c8b985ebde5
mod_http_muc_log: Switch to a calendar view for selecting dates
Kim Alvefur <zash@zash.se>
parents:
1605
diff
changeset
|
230 months[#months+1] = month; |
1654
1a6d6221c5f6
mod_http_muc_log: Cleanup [luacheck]
Kim Alvefur <zash@zash.se>
parents:
1625
diff
changeset
|
231 local current_day = 1; |
1a6d6221c5f6
mod_http_muc_log: Cleanup [luacheck]
Kim Alvefur <zash@zash.se>
parents:
1625
diff
changeset
|
232 for _=1, (tmp.wday+5)%7 do |
1a6d6221c5f6
mod_http_muc_log: Cleanup [luacheck]
Kim Alvefur <zash@zash.se>
parents:
1625
diff
changeset
|
233 days[current_day], current_day = {}, current_day+1; |
1606
2c8b985ebde5
mod_http_muc_log: Switch to a calendar view for selecting dates
Kim Alvefur <zash@zash.se>
parents:
1605
diff
changeset
|
234 end |
2c8b985ebde5
mod_http_muc_log: Switch to a calendar view for selecting dates
Kim Alvefur <zash@zash.se>
parents:
1605
diff
changeset
|
235 for i = 1, 31 do |
2c8b985ebde5
mod_http_muc_log: Switch to a calendar view for selecting dates
Kim Alvefur <zash@zash.se>
parents:
1605
diff
changeset
|
236 t.day = i; |
2c8b985ebde5
mod_http_muc_log: Switch to a calendar view for selecting dates
Kim Alvefur <zash@zash.se>
parents:
1605
diff
changeset
|
237 tmp = os_date("!*t", time(t)); |
1654
1a6d6221c5f6
mod_http_muc_log: Cleanup [luacheck]
Kim Alvefur <zash@zash.se>
parents:
1625
diff
changeset
|
238 if tmp.month ~= current_month then break end |
1606
2c8b985ebde5
mod_http_muc_log: Switch to a calendar view for selecting dates
Kim Alvefur <zash@zash.se>
parents:
1605
diff
changeset
|
239 if i > 1 and tmp.wday == 2 then |
2c8b985ebde5
mod_http_muc_log: Switch to a calendar view for selecting dates
Kim Alvefur <zash@zash.se>
parents:
1605
diff
changeset
|
240 days = {}; |
2c8b985ebde5
mod_http_muc_log: Switch to a calendar view for selecting dates
Kim Alvefur <zash@zash.se>
parents:
1605
diff
changeset
|
241 weeks[#weeks+1] = { days = days }; |
1654
1a6d6221c5f6
mod_http_muc_log: Cleanup [luacheck]
Kim Alvefur <zash@zash.se>
parents:
1625
diff
changeset
|
242 current_day = 1; |
1606
2c8b985ebde5
mod_http_muc_log: Switch to a calendar view for selecting dates
Kim Alvefur <zash@zash.se>
parents:
1605
diff
changeset
|
243 end |
2685
cd5781ca782d
mod_http_muc_log: Remove caching
Kim Alvefur <zash@zash.se>
parents:
2593
diff
changeset
|
244 days[current_day] = { |
cd5781ca782d
mod_http_muc_log: Remove caching
Kim Alvefur <zash@zash.se>
parents:
2593
diff
changeset
|
245 wday = tmp.wday, day = i, href = days_t[i] and datetime.date(days_t[i]) |
cd5781ca782d
mod_http_muc_log: Remove caching
Kim Alvefur <zash@zash.se>
parents:
2593
diff
changeset
|
246 }; |
cd5781ca782d
mod_http_muc_log: Remove caching
Kim Alvefur <zash@zash.se>
parents:
2593
diff
changeset
|
247 current_day = current_day+1; |
1606
2c8b985ebde5
mod_http_muc_log: Switch to a calendar view for selecting dates
Kim Alvefur <zash@zash.se>
parents:
1605
diff
changeset
|
248 end |
2c8b985ebde5
mod_http_muc_log: Switch to a calendar view for selecting dates
Kim Alvefur <zash@zash.se>
parents:
1605
diff
changeset
|
249 end |
3749
cb61f0e06de3
mod_http_muc_log: Fix sorting months
Kim Alvefur <zash@zash.se>
parents:
3722
diff
changeset
|
250 table.sort(months, sort_m); |
1606
2c8b985ebde5
mod_http_muc_log: Switch to a calendar view for selecting dates
Kim Alvefur <zash@zash.se>
parents:
1605
diff
changeset
|
251 end |
2c8b985ebde5
mod_http_muc_log: Switch to a calendar view for selecting dates
Kim Alvefur <zash@zash.se>
parents:
1605
diff
changeset
|
252 table.sort(years, sort_Y); |
3750
9002c8a2165f
mod_http_muc_log: Refactor calendarization of date list into a template filter BC
Kim Alvefur <zash@zash.se>
parents:
3749
diff
changeset
|
253 return years; |
9002c8a2165f
mod_http_muc_log: Refactor calendarization of date list into a template filter BC
Kim Alvefur <zash@zash.se>
parents:
3749
diff
changeset
|
254 end |
9002c8a2165f
mod_http_muc_log: Refactor calendarization of date list into a template filter BC
Kim Alvefur <zash@zash.se>
parents:
3749
diff
changeset
|
255 |
9002c8a2165f
mod_http_muc_log: Refactor calendarization of date list into a template filter BC
Kim Alvefur <zash@zash.se>
parents:
3749
diff
changeset
|
256 -- Produce the calendar view |
9002c8a2165f
mod_http_muc_log: Refactor calendarization of date list into a template filter BC
Kim Alvefur <zash@zash.se>
parents:
3749
diff
changeset
|
257 local function years_page(event, path) |
9002c8a2165f
mod_http_muc_log: Refactor calendarization of date list into a template filter BC
Kim Alvefur <zash@zash.se>
parents:
3749
diff
changeset
|
258 local request, response = event.request, event.response; |
9002c8a2165f
mod_http_muc_log: Refactor calendarization of date list into a template filter BC
Kim Alvefur <zash@zash.se>
parents:
3749
diff
changeset
|
259 |
9002c8a2165f
mod_http_muc_log: Refactor calendarization of date list into a template filter BC
Kim Alvefur <zash@zash.se>
parents:
3749
diff
changeset
|
260 local room = nodeprep(path:match("^(.*)/$")); |
9002c8a2165f
mod_http_muc_log: Refactor calendarization of date list into a template filter BC
Kim Alvefur <zash@zash.se>
parents:
3749
diff
changeset
|
261 local is_open = open_room(room); |
9002c8a2165f
mod_http_muc_log: Refactor calendarization of date list into a template filter BC
Kim Alvefur <zash@zash.se>
parents:
3749
diff
changeset
|
262 if is_open == nil then |
9002c8a2165f
mod_http_muc_log: Refactor calendarization of date list into a template filter BC
Kim Alvefur <zash@zash.se>
parents:
3749
diff
changeset
|
263 return -- implicit 404 |
9002c8a2165f
mod_http_muc_log: Refactor calendarization of date list into a template filter BC
Kim Alvefur <zash@zash.se>
parents:
3749
diff
changeset
|
264 elseif is_open == false then |
9002c8a2165f
mod_http_muc_log: Refactor calendarization of date list into a template filter BC
Kim Alvefur <zash@zash.se>
parents:
3749
diff
changeset
|
265 return 403; |
9002c8a2165f
mod_http_muc_log: Refactor calendarization of date list into a template filter BC
Kim Alvefur <zash@zash.se>
parents:
3749
diff
changeset
|
266 end |
9002c8a2165f
mod_http_muc_log: Refactor calendarization of date list into a template filter BC
Kim Alvefur <zash@zash.se>
parents:
3749
diff
changeset
|
267 |
9002c8a2165f
mod_http_muc_log: Refactor calendarization of date list into a template filter BC
Kim Alvefur <zash@zash.se>
parents:
3749
diff
changeset
|
268 local date_list = get_dates(room); |
9002c8a2165f
mod_http_muc_log: Refactor calendarization of date list into a template filter BC
Kim Alvefur <zash@zash.se>
parents:
3749
diff
changeset
|
269 if not date_list then |
9002c8a2165f
mod_http_muc_log: Refactor calendarization of date list into a template filter BC
Kim Alvefur <zash@zash.se>
parents:
3749
diff
changeset
|
270 return; -- 404 |
9002c8a2165f
mod_http_muc_log: Refactor calendarization of date list into a template filter BC
Kim Alvefur <zash@zash.se>
parents:
3749
diff
changeset
|
271 end |
1549
f9f8bf82ece7
mod_http_muc_log: MUC log module using new archive API
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
272 |
2590
63dd3e525f13
mod_http_muc_log: Add some comments
Kim Alvefur <zash@zash.se>
parents:
2236
diff
changeset
|
273 -- Phew, all wrangled, all that's left is rendering it with the template |
63dd3e525f13
mod_http_muc_log: Add some comments
Kim Alvefur <zash@zash.se>
parents:
2236
diff
changeset
|
274 |
1579
9e784ddac236
mod_http_muc_log: Include charset in Content-Type header
Kim Alvefur <zash@zash.se>
parents:
1578
diff
changeset
|
275 response.headers.content_type = "text/html; charset=utf-8"; |
3892
96a2e5097fc4
mod_http_muc_log: Reduce hashtable lookups
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
3757
diff
changeset
|
276 local room_obj = get_room(room); |
1581
9f6cd252d233
mod_http_muc_log: Revamp template system
Kim Alvefur <zash@zash.se>
parents:
1580
diff
changeset
|
277 return render(template, { |
5104
d4b0a995e5e3
mod_http_muc_log: Move CSS and JS out of template
Kim Alvefur <zash@zash.se>
parents:
4993
diff
changeset
|
278 static = "../@static"; |
3892
96a2e5097fc4
mod_http_muc_log: Reduce hashtable lookups
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
3757
diff
changeset
|
279 room = room_obj._data; |
96a2e5097fc4
mod_http_muc_log: Reduce hashtable lookups
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
3757
diff
changeset
|
280 jid = room_obj.jid; |
96a2e5097fc4
mod_http_muc_log: Reduce hashtable lookups
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
3757
diff
changeset
|
281 jid_node = jid_split(room_obj.jid); |
5581
df483d9056f5
mod_http_muc_log: Hide joins and parts by default
Kim Alvefur <zash@zash.se>
parents:
5118
diff
changeset
|
282 q = presence_query(request); |
df483d9056f5
mod_http_muc_log: Hide joins and parts by default
Kim Alvefur <zash@zash.se>
parents:
5118
diff
changeset
|
283 show_presence = show_presence(request); |
3597
da7ec4ed6ddf
mod_http_muc_log: Hide join/part controls if they are not stored by mod_muc_mam
Kim Alvefur <zash@zash.se>
parents:
3596
diff
changeset
|
284 presence_available = presence_logged; |
3750
9002c8a2165f
mod_http_muc_log: Refactor calendarization of date list into a template filter BC
Kim Alvefur <zash@zash.se>
parents:
3749
diff
changeset
|
285 dates = date_list; |
1581
9f6cd252d233
mod_http_muc_log: Revamp template system
Kim Alvefur <zash@zash.se>
parents:
1580
diff
changeset
|
286 links = { |
2840
683a2f25223d
mod_http_muc_log: Reword "back" links
Kim Alvefur <zash@zash.se>
parents:
2839
diff
changeset
|
287 { href = "../", rel = "up", text = "Room list" }, |
3718
cc6f7e2e4a59
mod_http_muc_log: Add arrow to 'latest' link like on other navigation
Kim Alvefur <zash@zash.se>
parents:
3715
diff
changeset
|
288 { href = "latest", rel = "last", text = "Latest" }, |
1581
9f6cd252d233
mod_http_muc_log: Revamp template system
Kim Alvefur <zash@zash.se>
parents:
1580
diff
changeset
|
289 }; |
9f6cd252d233
mod_http_muc_log: Revamp template system
Kim Alvefur <zash@zash.se>
parents:
1580
diff
changeset
|
290 }); |
1549
f9f8bf82ece7
mod_http_muc_log: MUC log module using new archive API
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
291 end |
f9f8bf82ece7
mod_http_muc_log: MUC log module using new archive API
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
292 |
2590
63dd3e525f13
mod_http_muc_log: Add some comments
Kim Alvefur <zash@zash.se>
parents:
2236
diff
changeset
|
293 -- Produce the chat log view |
1549
f9f8bf82ece7
mod_http_muc_log: MUC log module using new archive API
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
294 local function logs_page(event, path) |
3485
181561d0aae5
mod_http_muc_log: Add functionality for hiding joins and parts
Kim Alvefur <zash@zash.se>
parents:
3283
diff
changeset
|
295 local request, response = event.request, event.response; |
1549
f9f8bf82ece7
mod_http_muc_log: MUC log module using new archive API
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
296 |
5590
b681948a01f1
mod_http_muc_log: Fix redirect bug
Kim Alvefur <zash@zash.se>
parents:
5581
diff
changeset
|
297 -- /room --> 303 /room/ |
b681948a01f1
mod_http_muc_log: Fix redirect bug
Kim Alvefur <zash@zash.se>
parents:
5581
diff
changeset
|
298 -- /room/ --> calendar view |
b681948a01f1
mod_http_muc_log: Fix redirect bug
Kim Alvefur <zash@zash.se>
parents:
5581
diff
changeset
|
299 -- /room/yyyy-mm-dd --> logs view |
b681948a01f1
mod_http_muc_log: Fix redirect bug
Kim Alvefur <zash@zash.se>
parents:
5581
diff
changeset
|
300 -- /room/yyyy-mm-dd/* --> 404 |
b681948a01f1
mod_http_muc_log: Fix redirect bug
Kim Alvefur <zash@zash.se>
parents:
5581
diff
changeset
|
301 local room, date = path:match("^([^/]+)/([^/]*)$"); |
b681948a01f1
mod_http_muc_log: Fix redirect bug
Kim Alvefur <zash@zash.se>
parents:
5581
diff
changeset
|
302 if not room and not path:find"/" then |
4931
13070c6a7ce8
mod_http_muc_log: Fix exception on lack of trailing slash in room path
Kim Alvefur <zash@zash.se>
parents:
4781
diff
changeset
|
303 response.headers.location = url.build({ path = path .. "/" }); |
13070c6a7ce8
mod_http_muc_log: Fix exception on lack of trailing slash in room path
Kim Alvefur <zash@zash.se>
parents:
4781
diff
changeset
|
304 return 303; |
5590
b681948a01f1
mod_http_muc_log: Fix redirect bug
Kim Alvefur <zash@zash.se>
parents:
5581
diff
changeset
|
305 elseif not room then |
b681948a01f1
mod_http_muc_log: Fix redirect bug
Kim Alvefur <zash@zash.se>
parents:
5581
diff
changeset
|
306 return 404; |
4931
13070c6a7ce8
mod_http_muc_log: Fix exception on lack of trailing slash in room path
Kim Alvefur <zash@zash.se>
parents:
4781
diff
changeset
|
307 end |
1549
f9f8bf82ece7
mod_http_muc_log: MUC log module using new archive API
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
308 room = nodeprep(room); |
f9f8bf82ece7
mod_http_muc_log: MUC log module using new archive API
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
309 if not room then |
3591 | 310 return 400; |
311 elseif date == "" then | |
1606
2c8b985ebde5
mod_http_muc_log: Switch to a calendar view for selecting dates
Kim Alvefur <zash@zash.se>
parents:
1605
diff
changeset
|
312 return years_page(event, path); |
1549
f9f8bf82ece7
mod_http_muc_log: MUC log module using new archive API
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
313 end |
3059
14d8f2a9d5f4
mod_http_muc_log: Base read-access on whether anyone would be able to join (like MUC)
Kim Alvefur <zash@zash.se>
parents:
3058
diff
changeset
|
314 local is_open = open_room(room); |
14d8f2a9d5f4
mod_http_muc_log: Base read-access on whether anyone would be able to join (like MUC)
Kim Alvefur <zash@zash.se>
parents:
3058
diff
changeset
|
315 if is_open == nil then |
14d8f2a9d5f4
mod_http_muc_log: Base read-access on whether anyone would be able to join (like MUC)
Kim Alvefur <zash@zash.se>
parents:
3058
diff
changeset
|
316 return -- implicit 404 |
14d8f2a9d5f4
mod_http_muc_log: Base read-access on whether anyone would be able to join (like MUC)
Kim Alvefur <zash@zash.se>
parents:
3058
diff
changeset
|
317 elseif is_open == false then |
14d8f2a9d5f4
mod_http_muc_log: Base read-access on whether anyone would be able to join (like MUC)
Kim Alvefur <zash@zash.se>
parents:
3058
diff
changeset
|
318 return 403; |
14d8f2a9d5f4
mod_http_muc_log: Base read-access on whether anyone would be able to join (like MUC)
Kim Alvefur <zash@zash.se>
parents:
3058
diff
changeset
|
319 end |
3592
61a9c087730a
mod_http_muc_log: Provide a redirect to 'latest' day with logs (fixes #1360)
Kim Alvefur <zash@zash.se>
parents:
3591
diff
changeset
|
320 if date == "latest" then |
61a9c087730a
mod_http_muc_log: Provide a redirect to 'latest' day with logs (fixes #1360)
Kim Alvefur <zash@zash.se>
parents:
3591
diff
changeset
|
321 local last_day = find_once(room, { reverse = true }, 3); |
3595
00a848ede42d
mod_http_muc_log: Preserve ?query part in redirect
Kim Alvefur <zash@zash.se>
parents:
3594
diff
changeset
|
322 response.headers.location = url.build({ path = datetime.date(last_day), query = request.url.query }); |
3592
61a9c087730a
mod_http_muc_log: Provide a redirect to 'latest' day with logs (fixes #1360)
Kim Alvefur <zash@zash.se>
parents:
3591
diff
changeset
|
323 return 303; |
61a9c087730a
mod_http_muc_log: Provide a redirect to 'latest' day with logs (fixes #1360)
Kim Alvefur <zash@zash.se>
parents:
3591
diff
changeset
|
324 end |
2841
462dece0a3c2
mod_http_muc_log: Parse date out of path once
Kim Alvefur <zash@zash.se>
parents:
2840
diff
changeset
|
325 local day_start = datetime.parse(date.."T00:00:00Z"); |
3591 | 326 if not day_start then |
327 module:log("debug", "Invalid date format: %q", date); | |
328 return 400; | |
329 end | |
1549
f9f8bf82ece7
mod_http_muc_log: MUC log module using new archive API
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
330 |
f9f8bf82ece7
mod_http_muc_log: MUC log module using new archive API
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
331 local logs, i = {}, 1; |
f9f8bf82ece7
mod_http_muc_log: MUC log module using new archive API
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
332 local iter, err = archive:find(room, { |
2841
462dece0a3c2
mod_http_muc_log: Parse date out of path once
Kim Alvefur <zash@zash.se>
parents:
2840
diff
changeset
|
333 ["start"] = day_start; |
462dece0a3c2
mod_http_muc_log: Parse date out of path once
Kim Alvefur <zash@zash.se>
parents:
2840
diff
changeset
|
334 ["end"] = day_start + 86399; |
5581
df483d9056f5
mod_http_muc_log: Hide joins and parts by default
Kim Alvefur <zash@zash.se>
parents:
5118
diff
changeset
|
335 ["with"] = presence_with(request); |
1549
f9f8bf82ece7
mod_http_muc_log: MUC log module using new archive API
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
336 }); |
1654
1a6d6221c5f6
mod_http_muc_log: Cleanup [luacheck]
Kim Alvefur <zash@zash.se>
parents:
1625
diff
changeset
|
337 if not iter then |
1a6d6221c5f6
mod_http_muc_log: Cleanup [luacheck]
Kim Alvefur <zash@zash.se>
parents:
1625
diff
changeset
|
338 module:log("warn", "Could not search archive: %s", err or "no error"); |
1a6d6221c5f6
mod_http_muc_log: Cleanup [luacheck]
Kim Alvefur <zash@zash.se>
parents:
1625
diff
changeset
|
339 return 500; |
1a6d6221c5f6
mod_http_muc_log: Cleanup [luacheck]
Kim Alvefur <zash@zash.se>
parents:
1625
diff
changeset
|
340 end |
1549
f9f8bf82ece7
mod_http_muc_log: MUC log module using new archive API
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
341 |
1577
0a6974f2cb55
mod_http_muc_log: Use archive IDs to find next and previous dates that contain messages
Kim Alvefur <zash@zash.se>
parents:
1576
diff
changeset
|
342 local first, last; |
4990
d55b10878e43
mod_http_muc_log: Rename variable for improved clarity
Kim Alvefur <zash@zash.se>
parents:
4989
diff
changeset
|
343 for archive_id, item, when in iter do |
3703
7244ff1d62a8
mod_http_muc_log: Expose xml:lang from each message/body #a11y
Kim Alvefur <zash@zash.se>
parents:
3702
diff
changeset
|
344 local body_tag = item:get_child("body"); |
7244ff1d62a8
mod_http_muc_log: Expose xml:lang from each message/body #a11y
Kim Alvefur <zash@zash.se>
parents:
3702
diff
changeset
|
345 local body = body_tag and body_tag:get_text(); |
2591
3e1a85c5194c
mod_http_muc_log: Move scope of variables into loop
Kim Alvefur <zash@zash.se>
parents:
2590
diff
changeset
|
346 local subject = item:get_child_text("subject"); |
3e1a85c5194c
mod_http_muc_log: Move scope of variables into loop
Kim Alvefur <zash@zash.se>
parents:
2590
diff
changeset
|
347 local verb = nil; |
3703
7244ff1d62a8
mod_http_muc_log: Expose xml:lang from each message/body #a11y
Kim Alvefur <zash@zash.se>
parents:
3702
diff
changeset
|
348 local lang = body_tag and body_tag.attr["xml:lang"] or item.attr["xml:lang"]; |
4589
45ab9152a51c
mod_http_muc_log: Add some spacing around code for readability
Kim Alvefur <zash@zash.se>
parents:
4182
diff
changeset
|
349 |
4991
b17d63ef5bdf
mod_http_muc_log: Use XEP-0359 ID if available
Kim Alvefur <zash@zash.se>
parents:
4990
diff
changeset
|
350 -- XEP-0359: Unique and Stable Stanza IDs |
b17d63ef5bdf
mod_http_muc_log: Use XEP-0359 ID if available
Kim Alvefur <zash@zash.se>
parents:
4990
diff
changeset
|
351 local message_id = item:find("{urn:xmpp:sid:0}origin-id@id") or item.attr.id; |
b17d63ef5bdf
mod_http_muc_log: Use XEP-0359 ID if available
Kim Alvefur <zash@zash.se>
parents:
4990
diff
changeset
|
352 |
1555 | 353 if subject then |
1578
a68ec7a2dc02
mod_http_muc_log: Show only messages with presentable content
Kim Alvefur <zash@zash.se>
parents:
1577
diff
changeset
|
354 verb, body = "set the topic to", subject; |
1555 | 355 elseif body and body:sub(1,4) == "/me " then |
356 verb, body = body:sub(5), nil; | |
357 elseif item.name == "presence" then | |
3060
982668000163
mod_http_muc_log: Add a note about changing how presence is treated
Kim Alvefur <zash@zash.se>
parents:
3059
diff
changeset
|
358 -- TODO Distinguish between join and presence update |
1555 | 359 verb = item.attr.type == "unavailable" and "has left" or "has joined"; |
3703
7244ff1d62a8
mod_http_muc_log: Expose xml:lang from each message/body #a11y
Kim Alvefur <zash@zash.se>
parents:
3702
diff
changeset
|
360 lang = "en"; |
1549
f9f8bf82ece7
mod_http_muc_log: MUC log module using new archive API
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
361 end |
4589
45ab9152a51c
mod_http_muc_log: Add some spacing around code for readability
Kim Alvefur <zash@zash.se>
parents:
4182
diff
changeset
|
362 |
4590
3145823992cb
mod_http_muc_log: Move out nickname into a variable for future reuse
Kim Alvefur <zash@zash.se>
parents:
4589
diff
changeset
|
363 local nick = select(3, jid_split(item.attr.from)); |
4992
ed5abb8b8fa8
mod_http_muc_log: Use XEP-0421 ID over nickname for XEP-0308
Kim Alvefur <zash@zash.se>
parents:
4991
diff
changeset
|
364 local occupant_id = item:find("{urn:xmpp:occupant-id:0}occupant-id@id") or nick; |
4986
3bcefa9cf1ca
mod_http_muc_log: Mention relevant XEPs in comments
Kim Alvefur <zash@zash.se>
parents:
4970
diff
changeset
|
365 |
3bcefa9cf1ca
mod_http_muc_log: Mention relevant XEPs in comments
Kim Alvefur <zash@zash.se>
parents:
4970
diff
changeset
|
366 -- XEP-0066: Out of Band Data |
3582
444e2306c99a
mod_http_muc_log: Add option to show OOB images
Kim Alvefur <zash@zash.se>
parents:
3578
diff
changeset
|
367 local oob = use_oob and item:get_child("x", "jabber:x:oob"); |
4589
45ab9152a51c
mod_http_muc_log: Add some spacing around code for readability
Kim Alvefur <zash@zash.se>
parents:
4182
diff
changeset
|
368 |
4986
3bcefa9cf1ca
mod_http_muc_log: Mention relevant XEPs in comments
Kim Alvefur <zash@zash.se>
parents:
4970
diff
changeset
|
369 -- XEP-0425: Message Moderation |
4781
306066898e5f
mod_http_muc_log: Show messages moderated using XEP-0425
Kim Alvefur <zash@zash.se>
parents:
4677
diff
changeset
|
370 local moderated = item:get_child("moderated", "urn:xmpp:message-moderate:0"); |
306066898e5f
mod_http_muc_log: Show messages moderated using XEP-0425
Kim Alvefur <zash@zash.se>
parents:
4677
diff
changeset
|
371 if moderated then |
306066898e5f
mod_http_muc_log: Show messages moderated using XEP-0425
Kim Alvefur <zash@zash.se>
parents:
4677
diff
changeset
|
372 local actor = moderated.attr.by; |
306066898e5f
mod_http_muc_log: Show messages moderated using XEP-0425
Kim Alvefur <zash@zash.se>
parents:
4677
diff
changeset
|
373 if actor then actor = select(3, jid_split(actor)); end |
306066898e5f
mod_http_muc_log: Show messages moderated using XEP-0425
Kim Alvefur <zash@zash.se>
parents:
4677
diff
changeset
|
374 verb = "removed by " .. (actor or "moderator"); |
306066898e5f
mod_http_muc_log: Show messages moderated using XEP-0425
Kim Alvefur <zash@zash.se>
parents:
4677
diff
changeset
|
375 body = moderated:get_child_text("reason") or ""; |
306066898e5f
mod_http_muc_log: Show messages moderated using XEP-0425
Kim Alvefur <zash@zash.se>
parents:
4677
diff
changeset
|
376 end |
306066898e5f
mod_http_muc_log: Show messages moderated using XEP-0425
Kim Alvefur <zash@zash.se>
parents:
4677
diff
changeset
|
377 |
306066898e5f
mod_http_muc_log: Show messages moderated using XEP-0425
Kim Alvefur <zash@zash.se>
parents:
4677
diff
changeset
|
378 local moderation = item:find("{urn:xmpp:fasten:0}apply-to/{urn:xmpp:message-moderate:0}moderated"); |
306066898e5f
mod_http_muc_log: Show messages moderated using XEP-0425
Kim Alvefur <zash@zash.se>
parents:
4677
diff
changeset
|
379 if moderation then |
306066898e5f
mod_http_muc_log: Show messages moderated using XEP-0425
Kim Alvefur <zash@zash.se>
parents:
4677
diff
changeset
|
380 nick = nick or "a moderator"; |
306066898e5f
mod_http_muc_log: Show messages moderated using XEP-0425
Kim Alvefur <zash@zash.se>
parents:
4677
diff
changeset
|
381 verb = "removed a message"; |
306066898e5f
mod_http_muc_log: Show messages moderated using XEP-0425
Kim Alvefur <zash@zash.se>
parents:
4677
diff
changeset
|
382 body = moderation:get_child_text("reason") or ""; |
306066898e5f
mod_http_muc_log: Show messages moderated using XEP-0425
Kim Alvefur <zash@zash.se>
parents:
4677
diff
changeset
|
383 end |
306066898e5f
mod_http_muc_log: Show messages moderated using XEP-0425
Kim Alvefur <zash@zash.se>
parents:
4677
diff
changeset
|
384 |
4986
3bcefa9cf1ca
mod_http_muc_log: Mention relevant XEPs in comments
Kim Alvefur <zash@zash.se>
parents:
4970
diff
changeset
|
385 -- XEP-0308: Last Message Correction |
4592
38f501dca618
mod_http_muc_log: Find edit relations using XEP-0308
Kim Alvefur <zash@zash.se>
parents:
4590
diff
changeset
|
386 local edit = item:find("{urn:xmpp:message-correct:0}replace/@id"); |
38f501dca618
mod_http_muc_log: Find edit relations using XEP-0308
Kim Alvefur <zash@zash.se>
parents:
4590
diff
changeset
|
387 if edit then |
38f501dca618
mod_http_muc_log: Find edit relations using XEP-0308
Kim Alvefur <zash@zash.se>
parents:
4590
diff
changeset
|
388 local found = false; |
38f501dca618
mod_http_muc_log: Find edit relations using XEP-0308
Kim Alvefur <zash@zash.se>
parents:
4590
diff
changeset
|
389 for n = i-1, 1, -1 do |
4992
ed5abb8b8fa8
mod_http_muc_log: Use XEP-0421 ID over nickname for XEP-0308
Kim Alvefur <zash@zash.se>
parents:
4991
diff
changeset
|
390 if logs[n].message_id == edit and occupant_id == logs[n].occupant_id then |
4592
38f501dca618
mod_http_muc_log: Find edit relations using XEP-0308
Kim Alvefur <zash@zash.se>
parents:
4590
diff
changeset
|
391 found = true; |
4990
d55b10878e43
mod_http_muc_log: Rename variable for improved clarity
Kim Alvefur <zash@zash.se>
parents:
4989
diff
changeset
|
392 logs[n].edited = archive_id; |
d55b10878e43
mod_http_muc_log: Rename variable for improved clarity
Kim Alvefur <zash@zash.se>
parents:
4989
diff
changeset
|
393 edit = logs[n].archive_id; |
4592
38f501dca618
mod_http_muc_log: Find edit relations using XEP-0308
Kim Alvefur <zash@zash.se>
parents:
4590
diff
changeset
|
394 break; |
38f501dca618
mod_http_muc_log: Find edit relations using XEP-0308
Kim Alvefur <zash@zash.se>
parents:
4590
diff
changeset
|
395 end |
38f501dca618
mod_http_muc_log: Find edit relations using XEP-0308
Kim Alvefur <zash@zash.se>
parents:
4590
diff
changeset
|
396 end |
38f501dca618
mod_http_muc_log: Find edit relations using XEP-0308
Kim Alvefur <zash@zash.se>
parents:
4590
diff
changeset
|
397 if not found then |
38f501dca618
mod_http_muc_log: Find edit relations using XEP-0308
Kim Alvefur <zash@zash.se>
parents:
4590
diff
changeset
|
398 -- Ignore unresolved edit. |
38f501dca618
mod_http_muc_log: Find edit relations using XEP-0308
Kim Alvefur <zash@zash.se>
parents:
4590
diff
changeset
|
399 edit = nil; |
38f501dca618
mod_http_muc_log: Find edit relations using XEP-0308
Kim Alvefur <zash@zash.se>
parents:
4590
diff
changeset
|
400 end |
38f501dca618
mod_http_muc_log: Find edit relations using XEP-0308
Kim Alvefur <zash@zash.se>
parents:
4590
diff
changeset
|
401 end |
38f501dca618
mod_http_muc_log: Find edit relations using XEP-0308
Kim Alvefur <zash@zash.se>
parents:
4590
diff
changeset
|
402 |
4986
3bcefa9cf1ca
mod_http_muc_log: Mention relevant XEPs in comments
Kim Alvefur <zash@zash.se>
parents:
4970
diff
changeset
|
403 -- XEP-0444: Message Reactions |
4963
479d618c9e6d
mod_http_muc_log: Show XEP-0444 reactions
Kim Alvefur <zash@zash.se>
parents:
4931
diff
changeset
|
404 local reactions = item:get_child("reactions", "urn:xmpp:reactions:0"); |
479d618c9e6d
mod_http_muc_log: Show XEP-0444 reactions
Kim Alvefur <zash@zash.se>
parents:
4931
diff
changeset
|
405 if reactions then |
479d618c9e6d
mod_http_muc_log: Show XEP-0444 reactions
Kim Alvefur <zash@zash.se>
parents:
4931
diff
changeset
|
406 -- COMPAT Movim uses an @to attribute instead of the correct @id |
479d618c9e6d
mod_http_muc_log: Show XEP-0444 reactions
Kim Alvefur <zash@zash.se>
parents:
4931
diff
changeset
|
407 local target_id = reactions.attr.id or reactions.attr.to; |
479d618c9e6d
mod_http_muc_log: Show XEP-0444 reactions
Kim Alvefur <zash@zash.se>
parents:
4931
diff
changeset
|
408 for n = i - 1, 1, -1 do |
4990
d55b10878e43
mod_http_muc_log: Rename variable for improved clarity
Kim Alvefur <zash@zash.se>
parents:
4989
diff
changeset
|
409 if logs[n].archive_id == target_id then |
5656
c20b77e5e032
mod_http_muc_log: Correctly handle changed or retracted reactions
Kim Alvefur <zash@zash.se>
parents:
5590
diff
changeset
|
410 local react_map = logs[n].reactions; -- [occupant_id][emoji]boolean |
4963
479d618c9e6d
mod_http_muc_log: Show XEP-0444 reactions
Kim Alvefur <zash@zash.se>
parents:
4931
diff
changeset
|
411 if not react_map then |
479d618c9e6d
mod_http_muc_log: Show XEP-0444 reactions
Kim Alvefur <zash@zash.se>
parents:
4931
diff
changeset
|
412 react_map = {}; |
479d618c9e6d
mod_http_muc_log: Show XEP-0444 reactions
Kim Alvefur <zash@zash.se>
parents:
4931
diff
changeset
|
413 logs[n].reactions = react_map; |
479d618c9e6d
mod_http_muc_log: Show XEP-0444 reactions
Kim Alvefur <zash@zash.se>
parents:
4931
diff
changeset
|
414 end |
5656
c20b77e5e032
mod_http_muc_log: Correctly handle changed or retracted reactions
Kim Alvefur <zash@zash.se>
parents:
5590
diff
changeset
|
415 local reacts = {}; |
4963
479d618c9e6d
mod_http_muc_log: Show XEP-0444 reactions
Kim Alvefur <zash@zash.se>
parents:
4931
diff
changeset
|
416 for reaction_tag in reactions:childtags("reaction") do |
479d618c9e6d
mod_http_muc_log: Show XEP-0444 reactions
Kim Alvefur <zash@zash.se>
parents:
4931
diff
changeset
|
417 local reaction_text = reaction_tag:get_text() or "�"; |
5656
c20b77e5e032
mod_http_muc_log: Correctly handle changed or retracted reactions
Kim Alvefur <zash@zash.se>
parents:
5590
diff
changeset
|
418 reacts[reaction_text] = true; |
4963
479d618c9e6d
mod_http_muc_log: Show XEP-0444 reactions
Kim Alvefur <zash@zash.se>
parents:
4931
diff
changeset
|
419 end |
5656
c20b77e5e032
mod_http_muc_log: Correctly handle changed or retracted reactions
Kim Alvefur <zash@zash.se>
parents:
5590
diff
changeset
|
420 react_map[occupant_id] = reacts; |
4963
479d618c9e6d
mod_http_muc_log: Show XEP-0444 reactions
Kim Alvefur <zash@zash.se>
parents:
4931
diff
changeset
|
421 break |
479d618c9e6d
mod_http_muc_log: Show XEP-0444 reactions
Kim Alvefur <zash@zash.se>
parents:
4931
diff
changeset
|
422 end |
479d618c9e6d
mod_http_muc_log: Show XEP-0444 reactions
Kim Alvefur <zash@zash.se>
parents:
4931
diff
changeset
|
423 end |
479d618c9e6d
mod_http_muc_log: Show XEP-0444 reactions
Kim Alvefur <zash@zash.se>
parents:
4931
diff
changeset
|
424 end |
479d618c9e6d
mod_http_muc_log: Show XEP-0444 reactions
Kim Alvefur <zash@zash.se>
parents:
4931
diff
changeset
|
425 |
4987
8a8ec909ac20
mod_http_muc_log: Link to replied-to message using XEP-0461: Message Replies
Kim Alvefur <zash@zash.se>
parents:
4986
diff
changeset
|
426 -- XEP-0461: Message Replies |
4993
f36d15107c15
mod_http_muc_log: Use stanza:find to save a few bytes
Kim Alvefur <zash@zash.se>
parents:
4992
diff
changeset
|
427 local reply = item:find("{urn:xmpp:reply:0}reply@id"); |
4987
8a8ec909ac20
mod_http_muc_log: Link to replied-to message using XEP-0461: Message Replies
Kim Alvefur <zash@zash.se>
parents:
4986
diff
changeset
|
428 |
3582
444e2306c99a
mod_http_muc_log: Add option to show OOB images
Kim Alvefur <zash@zash.se>
parents:
3578
diff
changeset
|
429 if body or verb or oob then |
444e2306c99a
mod_http_muc_log: Add option to show OOB images
Kim Alvefur <zash@zash.se>
parents:
3578
diff
changeset
|
430 local line = { |
4991
b17d63ef5bdf
mod_http_muc_log: Use XEP-0359 ID if available
Kim Alvefur <zash@zash.se>
parents:
4990
diff
changeset
|
431 message_id = message_id; |
4990
d55b10878e43
mod_http_muc_log: Rename variable for improved clarity
Kim Alvefur <zash@zash.se>
parents:
4989
diff
changeset
|
432 archive_id = archive_id; |
4992
ed5abb8b8fa8
mod_http_muc_log: Use XEP-0421 ID over nickname for XEP-0308
Kim Alvefur <zash@zash.se>
parents:
4991
diff
changeset
|
433 occupant_id = occupant_id; |
1578
a68ec7a2dc02
mod_http_muc_log: Show only messages with presentable content
Kim Alvefur <zash@zash.se>
parents:
1577
diff
changeset
|
434 datetime = datetime.datetime(when); |
a68ec7a2dc02
mod_http_muc_log: Show only messages with presentable content
Kim Alvefur <zash@zash.se>
parents:
1577
diff
changeset
|
435 time = datetime.time(when); |
a68ec7a2dc02
mod_http_muc_log: Show only messages with presentable content
Kim Alvefur <zash@zash.se>
parents:
1577
diff
changeset
|
436 verb = verb; |
a68ec7a2dc02
mod_http_muc_log: Show only messages with presentable content
Kim Alvefur <zash@zash.se>
parents:
1577
diff
changeset
|
437 body = body; |
3703
7244ff1d62a8
mod_http_muc_log: Expose xml:lang from each message/body #a11y
Kim Alvefur <zash@zash.se>
parents:
3702
diff
changeset
|
438 lang = lang; |
4590
3145823992cb
mod_http_muc_log: Move out nickname into a variable for future reuse
Kim Alvefur <zash@zash.se>
parents:
4589
diff
changeset
|
439 nick = nick; |
1578
a68ec7a2dc02
mod_http_muc_log: Show only messages with presentable content
Kim Alvefur <zash@zash.se>
parents:
1577
diff
changeset
|
440 st_name = item.name; |
a68ec7a2dc02
mod_http_muc_log: Show only messages with presentable content
Kim Alvefur <zash@zash.se>
parents:
1577
diff
changeset
|
441 st_type = item.attr.type; |
4592
38f501dca618
mod_http_muc_log: Find edit relations using XEP-0308
Kim Alvefur <zash@zash.se>
parents:
4590
diff
changeset
|
442 edit = edit; |
4993
f36d15107c15
mod_http_muc_log: Use stanza:find to save a few bytes
Kim Alvefur <zash@zash.se>
parents:
4992
diff
changeset
|
443 reply = reply; |
4990
d55b10878e43
mod_http_muc_log: Rename variable for improved clarity
Kim Alvefur <zash@zash.se>
parents:
4989
diff
changeset
|
444 -- COMPAT |
d55b10878e43
mod_http_muc_log: Rename variable for improved clarity
Kim Alvefur <zash@zash.se>
parents:
4989
diff
changeset
|
445 key = archive_id; |
3582
444e2306c99a
mod_http_muc_log: Add option to show OOB images
Kim Alvefur <zash@zash.se>
parents:
3578
diff
changeset
|
446 }; |
444e2306c99a
mod_http_muc_log: Add option to show OOB images
Kim Alvefur <zash@zash.se>
parents:
3578
diff
changeset
|
447 if oob then |
444e2306c99a
mod_http_muc_log: Add option to show OOB images
Kim Alvefur <zash@zash.se>
parents:
3578
diff
changeset
|
448 line.oob = { |
444e2306c99a
mod_http_muc_log: Add option to show OOB images
Kim Alvefur <zash@zash.se>
parents:
3578
diff
changeset
|
449 url = oob:get_child_text("url"); |
444e2306c99a
mod_http_muc_log: Add option to show OOB images
Kim Alvefur <zash@zash.se>
parents:
3578
diff
changeset
|
450 desc = oob:get_child_text("desc"); |
444e2306c99a
mod_http_muc_log: Add option to show OOB images
Kim Alvefur <zash@zash.se>
parents:
3578
diff
changeset
|
451 } |
444e2306c99a
mod_http_muc_log: Add option to show OOB images
Kim Alvefur <zash@zash.se>
parents:
3578
diff
changeset
|
452 end |
444e2306c99a
mod_http_muc_log: Add option to show OOB images
Kim Alvefur <zash@zash.se>
parents:
3578
diff
changeset
|
453 logs[i], i = line, i + 1; |
1578
a68ec7a2dc02
mod_http_muc_log: Show only messages with presentable content
Kim Alvefur <zash@zash.se>
parents:
1577
diff
changeset
|
454 end |
4589
45ab9152a51c
mod_http_muc_log: Add some spacing around code for readability
Kim Alvefur <zash@zash.se>
parents:
4182
diff
changeset
|
455 |
4990
d55b10878e43
mod_http_muc_log: Rename variable for improved clarity
Kim Alvefur <zash@zash.se>
parents:
4989
diff
changeset
|
456 first = first or archive_id; |
d55b10878e43
mod_http_muc_log: Rename variable for improved clarity
Kim Alvefur <zash@zash.se>
parents:
4989
diff
changeset
|
457 last = archive_id; |
1549
f9f8bf82ece7
mod_http_muc_log: MUC log module using new archive API
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
458 end |
2846
7eb23a4e7fde
mod_http_muc_log: Generate empty pages in lazy mode, so that one can navigate past quiet days
Kim Alvefur <zash@zash.se>
parents:
2845
diff
changeset
|
459 if i == 1 and not lazy then return end -- No items |
1549
f9f8bf82ece7
mod_http_muc_log: MUC log module using new archive API
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
460 |
5656
c20b77e5e032
mod_http_muc_log: Correctly handle changed or retracted reactions
Kim Alvefur <zash@zash.se>
parents:
5590
diff
changeset
|
461 -- collapse reactions[occupant-id][reaction]boolean into reactions[reaction]integer |
c20b77e5e032
mod_http_muc_log: Correctly handle changed or retracted reactions
Kim Alvefur <zash@zash.se>
parents:
5590
diff
changeset
|
462 for n = 1, #logs do |
c20b77e5e032
mod_http_muc_log: Correctly handle changed or retracted reactions
Kim Alvefur <zash@zash.se>
parents:
5590
diff
changeset
|
463 local reactions = logs[n].reactions; |
c20b77e5e032
mod_http_muc_log: Correctly handle changed or retracted reactions
Kim Alvefur <zash@zash.se>
parents:
5590
diff
changeset
|
464 if reactions then |
c20b77e5e032
mod_http_muc_log: Correctly handle changed or retracted reactions
Kim Alvefur <zash@zash.se>
parents:
5590
diff
changeset
|
465 local collated = {}; |
c20b77e5e032
mod_http_muc_log: Correctly handle changed or retracted reactions
Kim Alvefur <zash@zash.se>
parents:
5590
diff
changeset
|
466 for _, reacts in pairs(reactions) do |
c20b77e5e032
mod_http_muc_log: Correctly handle changed or retracted reactions
Kim Alvefur <zash@zash.se>
parents:
5590
diff
changeset
|
467 for reaction_text in pairs(reacts) do |
c20b77e5e032
mod_http_muc_log: Correctly handle changed or retracted reactions
Kim Alvefur <zash@zash.se>
parents:
5590
diff
changeset
|
468 collated[reaction_text] = (collated[reaction_text] or 0) + 1; |
c20b77e5e032
mod_http_muc_log: Correctly handle changed or retracted reactions
Kim Alvefur <zash@zash.se>
parents:
5590
diff
changeset
|
469 end |
c20b77e5e032
mod_http_muc_log: Correctly handle changed or retracted reactions
Kim Alvefur <zash@zash.se>
parents:
5590
diff
changeset
|
470 end |
c20b77e5e032
mod_http_muc_log: Correctly handle changed or retracted reactions
Kim Alvefur <zash@zash.se>
parents:
5590
diff
changeset
|
471 logs[n].reactions = collated; |
c20b77e5e032
mod_http_muc_log: Correctly handle changed or retracted reactions
Kim Alvefur <zash@zash.se>
parents:
5590
diff
changeset
|
472 end |
c20b77e5e032
mod_http_muc_log: Correctly handle changed or retracted reactions
Kim Alvefur <zash@zash.se>
parents:
5590
diff
changeset
|
473 end |
c20b77e5e032
mod_http_muc_log: Correctly handle changed or retracted reactions
Kim Alvefur <zash@zash.se>
parents:
5590
diff
changeset
|
474 |
2236
86bc6e1d9d4d
mod_http_muc_log: Find next and previous date with date index if this is supported by the storage driver
Kim Alvefur <zash@zash.se>
parents:
2235
diff
changeset
|
475 local next_when, prev_when = "", ""; |
86bc6e1d9d4d
mod_http_muc_log: Find next and previous date with date index if this is supported by the storage driver
Kim Alvefur <zash@zash.se>
parents:
2235
diff
changeset
|
476 local date_list = archive.dates and archive:dates(room); |
86bc6e1d9d4d
mod_http_muc_log: Find next and previous date with date index if this is supported by the storage driver
Kim Alvefur <zash@zash.se>
parents:
2235
diff
changeset
|
477 if date_list then |
2592
fb1987d4ac62
mod_http_muc_log: Rename loop variable to avoid name clash
Kim Alvefur <zash@zash.se>
parents:
2591
diff
changeset
|
478 for j = 1, #date_list do |
fb1987d4ac62
mod_http_muc_log: Rename loop variable to avoid name clash
Kim Alvefur <zash@zash.se>
parents:
2591
diff
changeset
|
479 if date_list[j] == date then |
fb1987d4ac62
mod_http_muc_log: Rename loop variable to avoid name clash
Kim Alvefur <zash@zash.se>
parents:
2591
diff
changeset
|
480 next_when = date_list[j+1] or ""; |
fb1987d4ac62
mod_http_muc_log: Rename loop variable to avoid name clash
Kim Alvefur <zash@zash.se>
parents:
2591
diff
changeset
|
481 prev_when = date_list[j-1] or ""; |
2236
86bc6e1d9d4d
mod_http_muc_log: Find next and previous date with date index if this is supported by the storage driver
Kim Alvefur <zash@zash.se>
parents:
2235
diff
changeset
|
482 break; |
86bc6e1d9d4d
mod_http_muc_log: Find next and previous date with date index if this is supported by the storage driver
Kim Alvefur <zash@zash.se>
parents:
2235
diff
changeset
|
483 end |
86bc6e1d9d4d
mod_http_muc_log: Find next and previous date with date index if this is supported by the storage driver
Kim Alvefur <zash@zash.se>
parents:
2235
diff
changeset
|
484 end |
2844
9fac07bba402
mod_http_muc_log: Lazy nex/prev link generation
Kim Alvefur <zash@zash.se>
parents:
2843
diff
changeset
|
485 elseif lazy then |
9fac07bba402
mod_http_muc_log: Lazy nex/prev link generation
Kim Alvefur <zash@zash.se>
parents:
2843
diff
changeset
|
486 next_when = datetime.date(day_start + 86400); |
9fac07bba402
mod_http_muc_log: Lazy nex/prev link generation
Kim Alvefur <zash@zash.se>
parents:
2843
diff
changeset
|
487 prev_when = datetime.date(day_start - 86400); |
2845
0de6ed2ae9bd
mod_http_muc_log: Check that there are timestamps to work with
Kim Alvefur <zash@zash.se>
parents:
2844
diff
changeset
|
488 elseif first and last then |
1549
f9f8bf82ece7
mod_http_muc_log: MUC log module using new archive API
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
489 |
2236
86bc6e1d9d4d
mod_http_muc_log: Find next and previous date with date index if this is supported by the storage driver
Kim Alvefur <zash@zash.se>
parents:
2235
diff
changeset
|
490 module:log("debug", "Find next date with messages"); |
2593
b61b0ff1c0f9
mod_http_muc_log: Fix prev/next date finding
Kim Alvefur <zash@zash.se>
parents:
2592
diff
changeset
|
491 next_when = find_once(room, { after = last }, 3); |
2236
86bc6e1d9d4d
mod_http_muc_log: Find next and previous date with date index if this is supported by the storage driver
Kim Alvefur <zash@zash.se>
parents:
2235
diff
changeset
|
492 if next_when then |
86bc6e1d9d4d
mod_http_muc_log: Find next and previous date with date index if this is supported by the storage driver
Kim Alvefur <zash@zash.se>
parents:
2235
diff
changeset
|
493 next_when = datetime.date(next_when); |
86bc6e1d9d4d
mod_http_muc_log: Find next and previous date with date index if this is supported by the storage driver
Kim Alvefur <zash@zash.se>
parents:
2235
diff
changeset
|
494 module:log("debug", "Next message: %s", next_when); |
86bc6e1d9d4d
mod_http_muc_log: Find next and previous date with date index if this is supported by the storage driver
Kim Alvefur <zash@zash.se>
parents:
2235
diff
changeset
|
495 end |
86bc6e1d9d4d
mod_http_muc_log: Find next and previous date with date index if this is supported by the storage driver
Kim Alvefur <zash@zash.se>
parents:
2235
diff
changeset
|
496 |
86bc6e1d9d4d
mod_http_muc_log: Find next and previous date with date index if this is supported by the storage driver
Kim Alvefur <zash@zash.se>
parents:
2235
diff
changeset
|
497 module:log("debug", "Find prev date with messages"); |
2593
b61b0ff1c0f9
mod_http_muc_log: Fix prev/next date finding
Kim Alvefur <zash@zash.se>
parents:
2592
diff
changeset
|
498 prev_when = find_once(room, { before = first, reverse = true }, 3); |
2236
86bc6e1d9d4d
mod_http_muc_log: Find next and previous date with date index if this is supported by the storage driver
Kim Alvefur <zash@zash.se>
parents:
2235
diff
changeset
|
499 if prev_when then |
86bc6e1d9d4d
mod_http_muc_log: Find next and previous date with date index if this is supported by the storage driver
Kim Alvefur <zash@zash.se>
parents:
2235
diff
changeset
|
500 prev_when = datetime.date(prev_when); |
86bc6e1d9d4d
mod_http_muc_log: Find next and previous date with date index if this is supported by the storage driver
Kim Alvefur <zash@zash.se>
parents:
2235
diff
changeset
|
501 module:log("debug", "Previous message: %s", prev_when); |
86bc6e1d9d4d
mod_http_muc_log: Find next and previous date with date index if this is supported by the storage driver
Kim Alvefur <zash@zash.se>
parents:
2235
diff
changeset
|
502 end |
1549
f9f8bf82ece7
mod_http_muc_log: MUC log module using new archive API
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
503 end |
f9f8bf82ece7
mod_http_muc_log: MUC log module using new archive API
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
504 |
3690
8c0a6d4541d5
mod_http_muc_log: Wrap navigation in unorderded lists (thanks jonas’)
Kim Alvefur <zash@zash.se>
parents:
3597
diff
changeset
|
505 local links = { |
4034
a359972d246e
mod_http_muc_log: Add link to room list from logs page
Kim Alvefur <zash@zash.se>
parents:
3893
diff
changeset
|
506 { href = "../", rel = "up", text = "Room list" }, |
3690
8c0a6d4541d5
mod_http_muc_log: Wrap navigation in unorderded lists (thanks jonas’)
Kim Alvefur <zash@zash.se>
parents:
3597
diff
changeset
|
507 { href = "./", rel = "up", text = "Calendar" }, |
8c0a6d4541d5
mod_http_muc_log: Wrap navigation in unorderded lists (thanks jonas’)
Kim Alvefur <zash@zash.se>
parents:
3597
diff
changeset
|
508 }; |
8c0a6d4541d5
mod_http_muc_log: Wrap navigation in unorderded lists (thanks jonas’)
Kim Alvefur <zash@zash.se>
parents:
3597
diff
changeset
|
509 if prev_when ~= "" then |
8c0a6d4541d5
mod_http_muc_log: Wrap navigation in unorderded lists (thanks jonas’)
Kim Alvefur <zash@zash.se>
parents:
3597
diff
changeset
|
510 table.insert(links, { href = prev_when, rel = "prev", text = prev_when}); |
8c0a6d4541d5
mod_http_muc_log: Wrap navigation in unorderded lists (thanks jonas’)
Kim Alvefur <zash@zash.se>
parents:
3597
diff
changeset
|
511 end |
8c0a6d4541d5
mod_http_muc_log: Wrap navigation in unorderded lists (thanks jonas’)
Kim Alvefur <zash@zash.se>
parents:
3597
diff
changeset
|
512 if next_when ~= "" then |
8c0a6d4541d5
mod_http_muc_log: Wrap navigation in unorderded lists (thanks jonas’)
Kim Alvefur <zash@zash.se>
parents:
3597
diff
changeset
|
513 table.insert(links, { href = next_when, rel = "next", text = next_when}); |
8c0a6d4541d5
mod_http_muc_log: Wrap navigation in unorderded lists (thanks jonas’)
Kim Alvefur <zash@zash.se>
parents:
3597
diff
changeset
|
514 end |
8c0a6d4541d5
mod_http_muc_log: Wrap navigation in unorderded lists (thanks jonas’)
Kim Alvefur <zash@zash.se>
parents:
3597
diff
changeset
|
515 |
1579
9e784ddac236
mod_http_muc_log: Include charset in Content-Type header
Kim Alvefur <zash@zash.se>
parents:
1578
diff
changeset
|
516 response.headers.content_type = "text/html; charset=utf-8"; |
3892
96a2e5097fc4
mod_http_muc_log: Reduce hashtable lookups
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
3757
diff
changeset
|
517 local room_obj = get_room(room); |
1581
9f6cd252d233
mod_http_muc_log: Revamp template system
Kim Alvefur <zash@zash.se>
parents:
1580
diff
changeset
|
518 return render(template, { |
5104
d4b0a995e5e3
mod_http_muc_log: Move CSS and JS out of template
Kim Alvefur <zash@zash.se>
parents:
4993
diff
changeset
|
519 static = "../@static"; |
3714
04ff0de40ba9
mod_http_muc_log: Add date metadata to log pages
Kim Alvefur <zash@zash.se>
parents:
3703
diff
changeset
|
520 date = date; |
3892
96a2e5097fc4
mod_http_muc_log: Reduce hashtable lookups
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
3757
diff
changeset
|
521 room = room_obj._data; |
96a2e5097fc4
mod_http_muc_log: Reduce hashtable lookups
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
3757
diff
changeset
|
522 jid = room_obj.jid; |
96a2e5097fc4
mod_http_muc_log: Reduce hashtable lookups
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
3757
diff
changeset
|
523 jid_node = jid_split(room_obj.jid); |
5581
df483d9056f5
mod_http_muc_log: Hide joins and parts by default
Kim Alvefur <zash@zash.se>
parents:
5118
diff
changeset
|
524 q = presence_query(request); |
df483d9056f5
mod_http_muc_log: Hide joins and parts by default
Kim Alvefur <zash@zash.se>
parents:
5118
diff
changeset
|
525 show_presence = show_presence(request); |
3597
da7ec4ed6ddf
mod_http_muc_log: Hide join/part controls if they are not stored by mod_muc_mam
Kim Alvefur <zash@zash.se>
parents:
3596
diff
changeset
|
526 presence_available = presence_logged; |
3892
96a2e5097fc4
mod_http_muc_log: Reduce hashtable lookups
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
3757
diff
changeset
|
527 lang = room_obj.get_language and room_obj:get_language(); |
1581
9f6cd252d233
mod_http_muc_log: Revamp template system
Kim Alvefur <zash@zash.se>
parents:
1580
diff
changeset
|
528 lines = logs; |
3690
8c0a6d4541d5
mod_http_muc_log: Wrap navigation in unorderded lists (thanks jonas’)
Kim Alvefur <zash@zash.se>
parents:
3597
diff
changeset
|
529 links = links; |
3750
9002c8a2165f
mod_http_muc_log: Refactor calendarization of date list into a template filter BC
Kim Alvefur <zash@zash.se>
parents:
3749
diff
changeset
|
530 dates = {}; -- COMPAT util.interpolation {nil|func#...} bug |
1581
9f6cd252d233
mod_http_muc_log: Revamp template system
Kim Alvefur <zash@zash.se>
parents:
1580
diff
changeset
|
531 }); |
1549
f9f8bf82ece7
mod_http_muc_log: MUC log module using new archive API
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
532 end |
f9f8bf82ece7
mod_http_muc_log: MUC log module using new archive API
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
533 |
4676
a2cf3b69a3d6
mod_http_muc_log: Add way to list certain rooms in a specified order
Kim Alvefur <zash@zash.se>
parents:
4592
diff
changeset
|
534 local room_weights = setmetatable(module:get_option_array(module.name.."_list_order", {}):reverse(), nil); |
a2cf3b69a3d6
mod_http_muc_log: Add way to list certain rooms in a specified order
Kim Alvefur <zash@zash.se>
parents:
4592
diff
changeset
|
535 for i = #room_weights, 1, -1 do |
a2cf3b69a3d6
mod_http_muc_log: Add way to list certain rooms in a specified order
Kim Alvefur <zash@zash.se>
parents:
4592
diff
changeset
|
536 local room_jid = room_weights[i]; |
a2cf3b69a3d6
mod_http_muc_log: Add way to list certain rooms in a specified order
Kim Alvefur <zash@zash.se>
parents:
4592
diff
changeset
|
537 room_weights[i] = nil; |
a2cf3b69a3d6
mod_http_muc_log: Add way to list certain rooms in a specified order
Kim Alvefur <zash@zash.se>
parents:
4592
diff
changeset
|
538 room_weights[room_jid] = i; |
a2cf3b69a3d6
mod_http_muc_log: Add way to list certain rooms in a specified order
Kim Alvefur <zash@zash.se>
parents:
4592
diff
changeset
|
539 end |
a2cf3b69a3d6
mod_http_muc_log: Add way to list certain rooms in a specified order
Kim Alvefur <zash@zash.se>
parents:
4592
diff
changeset
|
540 |
1549
f9f8bf82ece7
mod_http_muc_log: MUC log module using new archive API
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
541 local function list_rooms(event) |
3485
181561d0aae5
mod_http_muc_log: Add functionality for hiding joins and parts
Kim Alvefur <zash@zash.se>
parents:
3283
diff
changeset
|
542 local request, response = event.request, event.response; |
1549
f9f8bf82ece7
mod_http_muc_log: MUC log module using new archive API
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
543 local room_list, i = {}, 1; |
f9f8bf82ece7
mod_http_muc_log: MUC log module using new archive API
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
544 for room in each_room() do |
5828
0ee77be396b9
mod_http_muc_log: Remove compat for very old MUC API
Kim Alvefur <zash@zash.se>
parents:
5656
diff
changeset
|
545 if room:get_public() then |
3893
3f20b7c88afb
mod_http_muc_log: Expose JID localpart to the template
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
3892
diff
changeset
|
546 local localpart = jid_split(room.jid); |
1581
9f6cd252d233
mod_http_muc_log: Revamp template system
Kim Alvefur <zash@zash.se>
parents:
1580
diff
changeset
|
547 room_list[i], i = { |
3578
ea63dc0cc824
mod_http_muc_log: Sort room listing by jid for stable order
Kim Alvefur <zash@zash.se>
parents:
3560
diff
changeset
|
548 jid = room.jid; |
3893
3f20b7c88afb
mod_http_muc_log: Expose JID localpart to the template
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
3892
diff
changeset
|
549 localpart = localpart; |
3f20b7c88afb
mod_http_muc_log: Expose JID localpart to the template
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
3892
diff
changeset
|
550 href = get_link(localpart, default_view); |
4182
1890115b2773
mod_http_muc_log: Move template into a directory to ease packaging
Kim Alvefur <zash@zash.se>
parents:
4034
diff
changeset
|
551 name = room:get_name() or localpart; |
3702
caf27826c7b2
mod_http_muc_log: Use configured room language in room title/desc #a11y
Kim Alvefur <zash@zash.se>
parents:
3692
diff
changeset
|
552 lang = room.get_language and room:get_language(); |
1549
f9f8bf82ece7
mod_http_muc_log: MUC log module using new archive API
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
553 description = room:get_description(); |
4676
a2cf3b69a3d6
mod_http_muc_log: Add way to list certain rooms in a specified order
Kim Alvefur <zash@zash.se>
parents:
4592
diff
changeset
|
554 priority = room_weights[ room.jid ] or 0; |
1549
f9f8bf82ece7
mod_http_muc_log: MUC log module using new archive API
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
555 }, i + 1; |
f9f8bf82ece7
mod_http_muc_log: MUC log module using new archive API
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
556 end |
f9f8bf82ece7
mod_http_muc_log: MUC log module using new archive API
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
557 end |
1576
91b91052e0e8
mod_http_muc_log: Send a HTML mime type with responses
Kim Alvefur <zash@zash.se>
parents:
1575
diff
changeset
|
558 |
3578
ea63dc0cc824
mod_http_muc_log: Sort room listing by jid for stable order
Kim Alvefur <zash@zash.se>
parents:
3560
diff
changeset
|
559 table.sort(room_list, function (a, b) |
4676
a2cf3b69a3d6
mod_http_muc_log: Add way to list certain rooms in a specified order
Kim Alvefur <zash@zash.se>
parents:
4592
diff
changeset
|
560 if a.priority ~= b.priority then return a.priority > b.priority; end |
4677
823370bc2e4c
mod_http_muc_log: Sort rooms with a description before those without
Kim Alvefur <zash@zash.se>
parents:
4676
diff
changeset
|
561 if a.description ~= nil and b.description == nil then |
823370bc2e4c
mod_http_muc_log: Sort rooms with a description before those without
Kim Alvefur <zash@zash.se>
parents:
4676
diff
changeset
|
562 return true; |
823370bc2e4c
mod_http_muc_log: Sort rooms with a description before those without
Kim Alvefur <zash@zash.se>
parents:
4676
diff
changeset
|
563 elseif a.description == nil and b.description ~= nil then |
823370bc2e4c
mod_http_muc_log: Sort rooms with a description before those without
Kim Alvefur <zash@zash.se>
parents:
4676
diff
changeset
|
564 return false; |
823370bc2e4c
mod_http_muc_log: Sort rooms with a description before those without
Kim Alvefur <zash@zash.se>
parents:
4676
diff
changeset
|
565 end |
3583
a36412d4fafd
mod_http_muc_log: Trim trailing whitespace [luacheck]
Kim Alvefur <zash@zash.se>
parents:
3582
diff
changeset
|
566 return a.jid < b.jid; |
3578
ea63dc0cc824
mod_http_muc_log: Sort room listing by jid for stable order
Kim Alvefur <zash@zash.se>
parents:
3560
diff
changeset
|
567 end); |
ea63dc0cc824
mod_http_muc_log: Sort room listing by jid for stable order
Kim Alvefur <zash@zash.se>
parents:
3560
diff
changeset
|
568 |
1581
9f6cd252d233
mod_http_muc_log: Revamp template system
Kim Alvefur <zash@zash.se>
parents:
1580
diff
changeset
|
569 response.headers.content_type = "text/html; charset=utf-8"; |
9f6cd252d233
mod_http_muc_log: Revamp template system
Kim Alvefur <zash@zash.se>
parents:
1580
diff
changeset
|
570 return render(template, { |
5104
d4b0a995e5e3
mod_http_muc_log: Move CSS and JS out of template
Kim Alvefur <zash@zash.se>
parents:
4993
diff
changeset
|
571 static = "./@static"; |
1581
9f6cd252d233
mod_http_muc_log: Revamp template system
Kim Alvefur <zash@zash.se>
parents:
1580
diff
changeset
|
572 title = module:get_option_string("name", "Prosody Chatrooms"); |
9f6cd252d233
mod_http_muc_log: Revamp template system
Kim Alvefur <zash@zash.se>
parents:
1580
diff
changeset
|
573 jid = module.host; |
5581
df483d9056f5
mod_http_muc_log: Hide joins and parts by default
Kim Alvefur <zash@zash.se>
parents:
5118
diff
changeset
|
574 q = presence_query(request); |
df483d9056f5
mod_http_muc_log: Hide joins and parts by default
Kim Alvefur <zash@zash.se>
parents:
5118
diff
changeset
|
575 show_presence = show_presence(request); |
3597
da7ec4ed6ddf
mod_http_muc_log: Hide join/part controls if they are not stored by mod_muc_mam
Kim Alvefur <zash@zash.se>
parents:
3596
diff
changeset
|
576 presence_available = presence_logged; |
1581
9f6cd252d233
mod_http_muc_log: Revamp template system
Kim Alvefur <zash@zash.se>
parents:
1580
diff
changeset
|
577 rooms = room_list; |
3750
9002c8a2165f
mod_http_muc_log: Refactor calendarization of date list into a template filter BC
Kim Alvefur <zash@zash.se>
parents:
3749
diff
changeset
|
578 dates = {}; -- COMPAT util.interpolation {nil|func#...} bug |
1581
9f6cd252d233
mod_http_muc_log: Revamp template system
Kim Alvefur <zash@zash.se>
parents:
1580
diff
changeset
|
579 }); |
1549
f9f8bf82ece7
mod_http_muc_log: MUC log module using new archive API
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
580 end |
f9f8bf82ece7
mod_http_muc_log: MUC log module using new archive API
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
581 |
5104
d4b0a995e5e3
mod_http_muc_log: Move CSS and JS out of template
Kim Alvefur <zash@zash.se>
parents:
4993
diff
changeset
|
582 local serve_static |
d4b0a995e5e3
mod_http_muc_log: Move CSS and JS out of template
Kim Alvefur <zash@zash.se>
parents:
4993
diff
changeset
|
583 do |
d4b0a995e5e3
mod_http_muc_log: Move CSS and JS out of template
Kim Alvefur <zash@zash.se>
parents:
4993
diff
changeset
|
584 if prosody.process_type == "prosody" then |
d4b0a995e5e3
mod_http_muc_log: Move CSS and JS out of template
Kim Alvefur <zash@zash.se>
parents:
4993
diff
changeset
|
585 -- Prosody >= 0.12 |
d4b0a995e5e3
mod_http_muc_log: Move CSS and JS out of template
Kim Alvefur <zash@zash.se>
parents:
4993
diff
changeset
|
586 local http_files = require "net.http.files"; |
d4b0a995e5e3
mod_http_muc_log: Move CSS and JS out of template
Kim Alvefur <zash@zash.se>
parents:
4993
diff
changeset
|
587 serve = http_files.serve; |
d4b0a995e5e3
mod_http_muc_log: Move CSS and JS out of template
Kim Alvefur <zash@zash.se>
parents:
4993
diff
changeset
|
588 else |
d4b0a995e5e3
mod_http_muc_log: Move CSS and JS out of template
Kim Alvefur <zash@zash.se>
parents:
4993
diff
changeset
|
589 -- Prosody <= 0.11 |
d4b0a995e5e3
mod_http_muc_log: Move CSS and JS out of template
Kim Alvefur <zash@zash.se>
parents:
4993
diff
changeset
|
590 serve = module:depends "http_files".serve; |
d4b0a995e5e3
mod_http_muc_log: Move CSS and JS out of template
Kim Alvefur <zash@zash.se>
parents:
4993
diff
changeset
|
591 end |
d4b0a995e5e3
mod_http_muc_log: Move CSS and JS out of template
Kim Alvefur <zash@zash.se>
parents:
4993
diff
changeset
|
592 local mime_map = module:shared("/*/http_files/mime").types or { css = "text/css"; js = "application/javascript" }; |
d4b0a995e5e3
mod_http_muc_log: Move CSS and JS out of template
Kim Alvefur <zash@zash.se>
parents:
4993
diff
changeset
|
593 serve_static = serve({ path = resources; mime_map = mime_map }); |
d4b0a995e5e3
mod_http_muc_log: Move CSS and JS out of template
Kim Alvefur <zash@zash.se>
parents:
4993
diff
changeset
|
594 end |
d4b0a995e5e3
mod_http_muc_log: Move CSS and JS out of template
Kim Alvefur <zash@zash.se>
parents:
4993
diff
changeset
|
595 |
1549
f9f8bf82ece7
mod_http_muc_log: MUC log module using new archive API
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
596 module:provides("http", { |
3757
971417eedfee
mod_http_muc_log: Set a http app title
Kim Alvefur <zash@zash.se>
parents:
3750
diff
changeset
|
597 title = module:get_option_string("name", "Chatroom logs"); |
1549
f9f8bf82ece7
mod_http_muc_log: MUC log module using new archive API
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
598 route = { |
f9f8bf82ece7
mod_http_muc_log: MUC log module using new archive API
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
599 ["GET /"] = list_rooms; |
2685
cd5781ca782d
mod_http_muc_log: Remove caching
Kim Alvefur <zash@zash.se>
parents:
2593
diff
changeset
|
600 ["GET /*"] = logs_page; |
3722
bdbbf11eac0c
mod_http_muc_log: Add comment about the routing of years and logs pages
Kim Alvefur <zash@zash.se>
parents:
3718
diff
changeset
|
601 -- mod_http only supports one wildcard so logs_page will dispatch to years_page if the path contains no date |
bdbbf11eac0c
mod_http_muc_log: Add comment about the routing of years and logs pages
Kim Alvefur <zash@zash.se>
parents:
3718
diff
changeset
|
602 -- thus: |
bdbbf11eac0c
mod_http_muc_log: Add comment about the routing of years and logs pages
Kim Alvefur <zash@zash.se>
parents:
3718
diff
changeset
|
603 -- GET /room --> years_page (via logs_page) |
bdbbf11eac0c
mod_http_muc_log: Add comment about the routing of years and logs pages
Kim Alvefur <zash@zash.se>
parents:
3718
diff
changeset
|
604 -- GET /room/yyyy-mm-dd --> logs_page (for real) |
5104
d4b0a995e5e3
mod_http_muc_log: Move CSS and JS out of template
Kim Alvefur <zash@zash.se>
parents:
4993
diff
changeset
|
605 |
d4b0a995e5e3
mod_http_muc_log: Move CSS and JS out of template
Kim Alvefur <zash@zash.se>
parents:
4993
diff
changeset
|
606 ["GET /@static/*"] = serve_static; |
d4b0a995e5e3
mod_http_muc_log: Move CSS and JS out of template
Kim Alvefur <zash@zash.se>
parents:
4993
diff
changeset
|
607 -- There are not many ASCII characters that are safe to use in URLs but not |
d4b0a995e5e3
mod_http_muc_log: Move CSS and JS out of template
Kim Alvefur <zash@zash.se>
parents:
4993
diff
changeset
|
608 -- valid in JID localparts, '@' seemed the only option. |
1549
f9f8bf82ece7
mod_http_muc_log: MUC log module using new archive API
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
609 }; |
f9f8bf82ece7
mod_http_muc_log: MUC log module using new archive API
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
610 }); |
f9f8bf82ece7
mod_http_muc_log: MUC log module using new archive API
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
611 |