Compare commits

..

No commits in common. "6782362af1eb81060107ce4f05ab2f25c2377ccc" and "d89d63803f8dda494ae63347348cb05234660a06" have entirely different histories.

4 changed files with 28 additions and 49 deletions

View File

@ -44,8 +44,6 @@ func (ntfy NTFY) Send(uuid string, msg []byte) (err error) {
ackURL := fmt.Sprintf("http, OK, %s/notification/ack?uuid=%s", ntfy.AcknowledgeURL, uuid) ackURL := fmt.Sprintf("http, OK, %s/notification/ack?uuid=%s", ntfy.AcknowledgeURL, uuid)
req.Header.Add("X-Actions", ackURL) req.Header.Add("X-Actions", ackURL)
req.Header.Add("X-Priority", "5")
req.Header.Add("X-Tags", "calendar")
res, err = http.DefaultClient.Do(req) res, err = http.DefaultClient.Do(req)
if err != nil { if err != nil {

View File

@ -8,7 +8,6 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"regexp" "regexp"
"strconv"
"strings" "strings"
"time" "time"
) )
@ -23,7 +22,6 @@ type Schedule struct {
Node Node Node Node
ScheduleUUID string `db:"schedule_uuid"` ScheduleUUID string `db:"schedule_uuid"`
Time time.Time Time time.Time
RemindMinutes int `db:"remind_minutes"`
Description string Description string
Acknowledged bool Acknowledged bool
} }
@ -31,7 +29,7 @@ type Schedule struct {
func ScanForSchedules(timeOffset int, content string) (schedules []Schedule) {// {{{ func ScanForSchedules(timeOffset int, content string) (schedules []Schedule) {// {{{
schedules = []Schedule{} schedules = []Schedule{}
rxp := regexp.MustCompile(`\{\s*([0-9]{4}-[0-9]{2}-[0-9]{2}\s+[0-9]{2}:[0-9]{2}(?::[0-9]{2})?)\s*\,\s*(?:(\d+)\s*(h|min)\s*,)?\s*([^\]]+?)\s*\}`) rxp := regexp.MustCompile(`\{\s*([0-9]{4}-[0-9]{2}-[0-9]{2}\s+[0-9]{2}:[0-9]{2}(?::[0-9]{2})?)\s*\,\s*([^\]]+?)\s*\}`)
foundSchedules := rxp.FindAllStringSubmatch(content, -1) foundSchedules := rxp.FindAllStringSubmatch(content, -1)
for _, data := range foundSchedules { for _, data := range foundSchedules {
@ -40,7 +38,6 @@ func ScanForSchedules(timeOffset int, content string) (schedules []Schedule) { /
data[1] = data[1] + ":00" data[1] = data[1] + ":00"
} }
// Timezone calculations
var timeTZ string var timeTZ string
if timeOffset < 0 { if timeOffset < 0 {
hours := (-timeOffset) / 60 hours := (-timeOffset) / 60
@ -57,23 +54,9 @@ func ScanForSchedules(timeOffset int, content string) (schedules []Schedule) { /
continue continue
} }
// Reminder
var remindMinutes int
if data[2] != "" && data[3] != "" {
value, _ := strconv.Atoi(data[2])
unit := strings.ToLower(data[3])
switch unit {
case "min":
remindMinutes = value
case "h":
remindMinutes = value * 60
}
}
schedule := Schedule{ schedule := Schedule{
Time: timestamp, Time: timestamp,
RemindMinutes: remindMinutes, Description: data[2],
Description: data[4],
} }
schedules = append(schedules, schedule) schedules = append(schedules, schedule)
} }
@ -90,7 +73,7 @@ func RetrieveSchedules(userID int, nodeID int) (schedules []Schedule, err error)
user_id, user_id,
json_build_object('id', node_id) AS node, json_build_object('id', node_id) AS node,
schedule_uuid, schedule_uuid,
time - MAKE_INTERVAL(mins => remind_minutes) AS time, time,
description, description,
acknowledged acknowledged
FROM schedule FROM schedule
@ -127,14 +110,13 @@ func (a Schedule) IsEqual(b Schedule) bool { // {{{
}// }}} }// }}}
func (s *Schedule) Insert(queryable Queryable) error {// {{{ func (s *Schedule) Insert(queryable Queryable) error {// {{{
res := queryable.QueryRow(` res := queryable.QueryRow(`
INSERT INTO schedule(user_id, node_id, time, remind_minutes, description) INSERT INTO schedule(user_id, node_id, time, description)
VALUES($1, $2, $3, $4, $5) VALUES($1, $2, $3, $4)
RETURNING id RETURNING id
`, `,
s.UserID, s.UserID,
s.Node.ID, s.Node.ID,
s.Time, s.Time,
s.RemindMinutes,
s.Description, s.Description,
) )
@ -162,11 +144,11 @@ func ExpiredSchedules() (schedules []Schedule) { // {{{
user_id, user_id,
node_id, node_id,
schedule_uuid, schedule_uuid,
time - MAKE_INTERVAL(mins => remind_minutes) AS time, time,
description description
FROM schedule FROM schedule
WHERE WHERE
(time - MAKE_INTERVAL(mins => remind_minutes)) < NOW() AND time < NOW() AND
NOT acknowledged NOT acknowledged
ORDER BY ORDER BY
time ASC time ASC

View File

@ -1 +0,0 @@
ALTER TABLE public.schedule ADD COLUMN remind_minutes int NOT NULL DEFAULT 0;

View File

@ -1 +1 @@
v25 v24