Software /
code /
verse
Annotate
plugins/browsing.lua @ 409:171c4a8cc3de
plugins.archive: Update to XEP-0313 v0.6
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Fri, 07 Apr 2017 19:38:52 +0200 |
parent | 403:6f4f60ebb796 |
child | 466:1eaec52ff71a |
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 |
6f4f60ebb796
Add plugin for XEP-0195: User Browsing
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
9 infos = { uri = infos; }; |
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 |
6f4f60ebb796
Add plugin for XEP-0195: User Browsing
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
12 local link = verse.stanza("page", {xmlns=xmlns_browsing}) |
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; |
6f4f60ebb796
Add plugin for XEP-0195: User Browsing
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
23 description = item:get_child_text"description"; |
6f4f60ebb796
Add plugin for XEP-0195: User Browsing
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
24 keywords = item:get_child_text"keywords"; |
6f4f60ebb796
Add plugin for XEP-0195: User Browsing
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
25 title = item:get_child_text"title"; |
6f4f60ebb796
Add plugin for XEP-0195: User Browsing
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
26 uri = item:get_child_text"uri"; |
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 |