Software /
code /
verse
Annotate
plugins/browsing.lua @ 466:1eaec52ff71a
browsing: whitespace fixes
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Fri, 17 Mar 2023 09:23:56 +0000 |
parent | 403:6f4f60ebb796 |
rev | line source |
---|---|
403
6f4f60ebb796
Add plugin for XEP-0195: User Browsing
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
1 local verse = require "verse"; |
6f4f60ebb796
Add plugin for XEP-0195: User Browsing
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
2 |
6f4f60ebb796
Add plugin for XEP-0195: User Browsing
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
3 local xmlns_browsing = "urn:xmpp:browsing:0"; |
6f4f60ebb796
Add plugin for XEP-0195: User Browsing
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
4 |
6f4f60ebb796
Add plugin for XEP-0195: User Browsing
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
5 function verse.plugins.browsing(stream) |
6f4f60ebb796
Add plugin for XEP-0195: User Browsing
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
6 stream:add_plugin("pep"); |
6f4f60ebb796
Add plugin for XEP-0195: User Browsing
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
7 function stream:browsing(infos, callback) |
6f4f60ebb796
Add plugin for XEP-0195: User Browsing
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
8 if type(infos) == "string" then |
466 | 9 infos = {uri = infos}; |
403
6f4f60ebb796
Add plugin for XEP-0195: User Browsing
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
10 end |
6f4f60ebb796
Add plugin for XEP-0195: User Browsing
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
11 |
466 | 12 local link = verse.stanza("page", {xmlns = xmlns_browsing}) |
403
6f4f60ebb796
Add plugin for XEP-0195: User Browsing
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
13 for info, value in pairs(infos) do |
6f4f60ebb796
Add plugin for XEP-0195: User Browsing
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
14 link:tag(info):text(value):up(); |
6f4f60ebb796
Add plugin for XEP-0195: User Browsing
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
15 end |
6f4f60ebb796
Add plugin for XEP-0195: User Browsing
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
16 return stream:publish_pep(link, callback); |
6f4f60ebb796
Add plugin for XEP-0195: User Browsing
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
17 end |
6f4f60ebb796
Add plugin for XEP-0195: User Browsing
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
18 |
6f4f60ebb796
Add plugin for XEP-0195: User Browsing
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
19 stream:hook_pep(xmlns_browsing, function(event) |
6f4f60ebb796
Add plugin for XEP-0195: User Browsing
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
20 local item = event.item; |
6f4f60ebb796
Add plugin for XEP-0195: User Browsing
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
21 return stream:event("browsing", { |
6f4f60ebb796
Add plugin for XEP-0195: User Browsing
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
22 from = event.from; |
466 | 23 description = item:get_child_text "description"; |
24 keywords = item:get_child_text "keywords"; | |
25 title = item:get_child_text "title"; | |
26 uri = item:get_child_text "uri"; | |
403
6f4f60ebb796
Add plugin for XEP-0195: User Browsing
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
27 }); |
6f4f60ebb796
Add plugin for XEP-0195: User Browsing
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
28 end); |
6f4f60ebb796
Add plugin for XEP-0195: User Browsing
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
29 end |
6f4f60ebb796
Add plugin for XEP-0195: User Browsing
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
30 |