comparison src/lib/Notify.luan @ 45:e138343b2c76

unsubscribe and more
author Franklin Schmidt <fschmidt@gmail.com>
date Fri, 28 Feb 2025 14:37:11 -0700
parents 818697418dbe
children 246a792adedf
comparison
equal deleted inserted replaced
44:1aa50739475a 45:e138343b2c76
20 local logger = Logging.logger "Notify" 20 local logger = Logging.logger "Notify"
21 21
22 22
23 local Notify = {} 23 local Notify = {}
24 24
25 local url = Http.domain and "https://"..Http.domain.."/" or "http://localhost:8080/" 25 local base_url = Http.domain and "https://"..Http.domain or "http://localhost:8080"
26 26
27 local wait = Time.period{seconds=10} 27 local wait = Time.period{seconds=10}
28 28
29 local function set_notified(user,was_notified) 29 local function set_notified(user,was_notified)
30 run_in_transaction( function() 30 run_in_transaction( function()
60 for user_id, when in pairs(shallow_copy(users)) do 60 for user_id, when in pairs(shallow_copy(users)) do
61 if now - when > wait then 61 if now - when > wait then
62 local user = get_user_by_id(user_id) 62 local user = get_user_by_id(user_id)
63 -- logger.info("notify "..user.notify_email.." "..user_id) 63 -- logger.info("notify "..user.notify_email.." "..user_id)
64 send_mail { 64 send_mail {
65 From = "Web Chat <chat@luan.software>"
66 To = user.notify_email 65 To = user.notify_email
67 Subject = "New Messages" 66 Subject = "New Messages"
68 body = `%> 67 body = `%>
69 You have received new messages. 68 You have received new messages.
70 69
71 <%= url %> 70 <%= base_url %>/
71
72 To unsubscribe:
73 <%= base_url %>/unsubscribe.html?user=<%=user_id%>&password=<%=user.password%>
72 <% ` 74 <% `
73 } 75 }
74 users[user_id] = nil 76 users[user_id] = nil
75 set_notified(user,true) 77 set_notified(user,true)
76 end 78 end