Comparison

mod_reminders/mod_reminders.lua @ 3921:9eabd68b8e48

mod_reminders: add id to sent reminder Update the acknowledgement of reminder's creation with ProtoXEP comments.
author marc0s <marcos@tenak.net>
date Fri, 28 Feb 2020 16:22:37 +0100
parent 3917:3e19c25ff93e
comparison
equal deleted inserted replaced
3920:cf92e3b30c18 3921:9eabd68b8e48
62 local function send_reminder (reminder) 62 local function send_reminder (reminder)
63 -- actually delivers the <message /> with the reminder to the user 63 -- actually delivers the <message /> with the reminder to the user
64 local bare = jid.bare(reminder.jid); 64 local bare = jid.bare(reminder.jid);
65 module:log("debug", "Sending reminder %s to %s", reminder.id, bare); 65 module:log("debug", "Sending reminder %s to %s", reminder.id, bare);
66 local message = st.message({ from = "localhost"; to = bare; id = id.short() }) 66 local message = st.message({ from = "localhost"; to = bare; id = id.short() })
67 :tag("reminder", {xmlns = xmlns_reminders}) 67 :tag("reminder", {id = reminder.id; xmlns = xmlns_reminders})
68 :add_child(reminder.text) 68 :add_child(reminder.text)
69 :tag("date"):text(datetime.datetime(reminder.date)):up(); 69 :tag("date"):text(datetime.datetime(reminder.date)):up();
70 module:send(message); 70 module:send(message);
71 return delete_reminder(reminder.id) 71 return delete_reminder(reminder.id)
72 end 72 end
108 end 108 end
109 end 109 end
110 end 110 end
111 111
112 local function create_reminder (jid, reminder) 112 local function create_reminder (jid, reminder)
113 local rem = st.clone(reminder);
114 local date = reminder:get_child("date"); 113 local date = reminder:get_child("date");
115 local text = reminder:get_child("text"); 114 local text = reminder:get_child("text");
116 if date == nil or text == nil then 115 if date == nil or text == nil then
117 return nil, reminder_error("missing_fields") 116 return nil, reminder_error("missing_fields")
118 end 117 end
121 if parsed_date == nil then 120 if parsed_date == nil then
122 return nil, reminder_error("invalid_dateformat") 121 return nil, reminder_error("invalid_dateformat")
123 end 122 end
124 if parsed_date < now then 123 if parsed_date < now then
125 return nil, reminder_error("past_date"), nil 124 return nil, reminder_error("past_date"), nil
126 end 125 end
127 rem.attr.id = id.medium(); 126 local reminder_id = id.medium();
127 local rem = st.stanza("reminder", {xmlns = xmlns_reminders; id = reminder_id});
128 local data = { 128 local data = {
129 id = rem.attr.id; 129 id = reminder_id;
130 jid = jid; 130 jid = jid;
131 text = text; 131 text = text;
132 date = parsed_date; 132 date = parsed_date;
133 } 133 }
134 local stored = store_reminder(data); 134 local stored = store_reminder(data);