comparison mod_rest/jsonmap.lib.lua @ 4743:0a501df823fd

mod_rest: Add some convenience mapping to make MAM queries easier
author Kim Alvefur <zash@zash.se>
date Thu, 04 Nov 2021 20:04:13 +0100
parents b7df2c61a144
children f478855f4565
comparison
equal deleted inserted replaced
4742:b7df2c61a144 4743:0a501df823fd
382 disco = "iq", 382 disco = "iq",
383 items = "iq", 383 items = "iq",
384 ping = "iq", 384 ping = "iq",
385 version = "iq", 385 version = "iq",
386 command = "iq", 386 command = "iq",
387 archive = "iq",
387 388
388 body = "message", 389 body = "message",
389 html = "message", 390 html = "message",
390 replace = "message", 391 replace = "message",
391 state = "message", 392 state = "message",
494 t_type = nil; 495 t_type = nil;
495 elseif kind == "iq" and not t_type then 496 elseif kind == "iq" and not t_type then
496 t_type = "get"; 497 t_type = "get";
497 end 498 end
498 499
500 -- XEP-0313 conveninece mapping
501 if kind == "iq" and t_type == "set" and type(t.archive) == "table" and not t.archive.form then
502 local archive = t.archive;
503 if archive["with"] or archive["start"] or archive["end"] or archive["before-id"] or archive["after-id"]
504 or archive["ids"] then
505 archive.form = {
506 type = "submit";
507 fields = {
508 { var = "FORM_TYPE"; values = { "urn:xmpp:mam:2" } };
509 { var = "with"; values = { archive["with"] } };
510 { var = "start"; values = { archive["start"] } };
511 { var = "end"; values = { archive["end"] } };
512 { var = "before-id"; values = { archive["before-id"] } };
513 { var = "after-id"; values = { archive["after-id"] } };
514 { var = "ids"; values = archive["ids"] };
515 };
516 };
517 archive["with"] = nil;
518 archive["start"] = nil;
519 archive["end"] = nil;
520 archive["before-id"] = nil;
521 archive["after-id"] = nil;
522 archive["ids"] = nil;
523 end
524
525 if archive["after"] or archive["before"] or archive["max"] then
526 archive.page = { after = archive["after"]; before = archive["before"]; max = tonumber(archive["max"]) }
527 archive["after"] = nil;
528 archive["before"] = nil;
529 archive["max"] = nil;
530 end
531 end
532
499 local s = map.unparse(schema.properties[kind or "message"], t); 533 local s = map.unparse(schema.properties[kind or "message"], t);
500 534
501 s.attr.type = t_type; 535 s.attr.type = t_type;
502 s.attr.to = str(t.to) and jid.prep(t.to); 536 s.attr.to = str(t.to) and jid.prep(t.to);
503 s.attr.from = str(t.to) and jid.prep(t.from); 537 s.attr.from = str(t.to) and jid.prep(t.from);