From e3fdf87a00268c9189996aa7b23b4113d9f200aa Mon Sep 17 00:00:00 2001 From: Ted Unangst Date: Wed, 2 Oct 2019 18:20:14 -0400 Subject: [PATCH] events with start times. because... because. --- activity.go | 24 ++++++++++++++++++++++-- database.go | 16 ++++++++++++---- docs/changelog.txt | 2 ++ views/honk.html | 3 +++ views/honkform.html | 9 +++++++++ views/honkpage.js | 12 +++++++----- web.go | 19 +++++++++++++++++++ 7 files changed, 74 insertions(+), 11 deletions(-) diff --git a/activity.go b/activity.go index cee90e1..ba6a1b0 100644 --- a/activity.go +++ b/activity.go @@ -541,6 +541,9 @@ func xonksaver(user *WhatAbout, item junk.Junk, origin string) *Honk { case "Page": obj = item what = "honk" + case "Event": + obj = item + what = "event" default: log.Printf("unknown activity: %s", what) fd, _ := os.OpenFile("savedinbox.json", os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666) @@ -710,6 +713,16 @@ func xonksaver(user *WhatAbout, item junk.Junk, origin string) *Honk { xonk.Place = p } } + starttime, ok := obj.GetString("startTime") + if ok { + start, err := time.Parse(time.RFC3339, starttime) + if err == nil { + t := new(Time) + t.StartTime = start + xonk.Time = t + } + } + xonk.Onts = oneofakind(xonk.Onts) replyobj, ok := obj.GetMap("replies") if ok { @@ -878,16 +891,20 @@ func jonkjonk(user *WhatAbout, h *Honk) (junk.Junk, junk.Junk) { fallthrough case "tonk": fallthrough + case "event": + fallthrough case "honk": + j["type"] = "Create" if h.What == "update" { j["type"] = "Update" - } else { - j["type"] = "Create" } jo = junk.New() jo["id"] = h.XID jo["type"] = "Note" + if h.What == "event" { + jo["type"] = "Event" + } jo["published"] = dt jo["url"] = h.XID jo["attributedTo"] = user.URL @@ -967,6 +984,9 @@ func jonkjonk(user *WhatAbout, h *Honk) (junk.Junk, junk.Junk) { if len(tags) > 0 { jo["tag"] = tags } + if t := h.Time; t != nil { + jo["startTime"] = t.StartTime.Format(time.RFC3339) + } var atts []junk.Junk for _, d := range h.Donks { if re_emus.MatchString(d.Name) { diff --git a/database.go b/database.go index 57d59ca..70cbfe8 100644 --- a/database.go +++ b/database.go @@ -278,6 +278,14 @@ func donksforhonks(honks []*Honk) { continue } h.Place = p + case "time": + t := new(Time) + err = unjsonify(j, t) + if err != nil { + log.Printf("error parsing time: %s", err) + continue + } + h.Time = t case "oldrev": default: log.Printf("unknown meta genus: %s", genus) @@ -334,7 +342,7 @@ func saveextras(h *Honk) error { } if p := h.Place; p != nil { j, err := jsonify(p) - if err != nil { + if err == nil { _, err = stmtSaveMeta.Exec(h.ID, "place", j) } if err != nil { @@ -342,9 +350,9 @@ func saveextras(h *Honk) error { return err } } - if p := h.Time; p != nil { - j, err := jsonify(p) - if err != nil { + if t := h.Time; t != nil { + j, err := jsonify(t) + if err == nil { _, err = stmtSaveMeta.Exec(h.ID, "time", j) } if err != nil { diff --git a/docs/changelog.txt b/docs/changelog.txt index 7a57040..19a78b7 100644 --- a/docs/changelog.txt +++ b/docs/changelog.txt @@ -2,6 +2,8 @@ changelog -- next ++ Times for events. + + Split media database into separate blob.db. + Location checkin. Welcome to the... danger zone! diff --git a/views/honk.html b/views/honk.html index 066993f..9af2a88 100644 --- a/views/honk.html +++ b/views/honk.html @@ -42,6 +42,9 @@ in reply to: {{ .RID }} {{ .HTPrecis }}

{{ .HTPrecis }}

{{ .HTML }} +{{ with .Time }} +

Time: {{ .StartTime.Local }} +{{ end }} {{ with .Place }}

Location: {{ with .Url }}{{ end }}{{ .Name }}{{ if .Url }}{{ end }} {{ .Latitude }} {{ .Longitude }} {{ end }} diff --git a/views/honkform.html b/views/honkform.html index 2549d9a..3e0c667 100644 --- a/views/honkform.html +++ b/views/honkform.html @@ -5,6 +5,9 @@

+

+more options +

@@ -16,6 +19,12 @@ desc: lat: lon: +

+

+

diff --git a/views/honkpage.js b/views/honkpage.js index 94c4ee5..9b3a910 100644 --- a/views/honkpage.js +++ b/views/honkpage.js @@ -207,6 +207,10 @@ function showhonkform(elem, rid, hname) { } document.getElementById("honknoise").focus() } +function showelement(id) { + var el = document.getElementById(id) + el.style.display = "block" +} function updatedonker() { var el = document.getElementById("donker") el.children[1].textContent = el.children[0].value.slice(-20) @@ -217,16 +221,14 @@ var checkinprec = 500.0 function fillcheckin() { if (navigator.geolocation) { navigator.geolocation.getCurrentPosition(function(pos) { - var el = document.getElementById("placedescriptor") - el.style.display = "block" - el = document.getElementById("placelatinput") + showelement("placedescriptor") + var el = document.getElementById("placelatinput") el.value = Math.round(pos.coords.latitude * checkinprec) / checkinprec el = document.getElementById("placelonginput") el.value = Math.round(pos.coords.longitude * checkinprec) / checkinprec checkinprec = 10000.0 }, function(err) { - var el = document.getElementById("placedescriptor") - el.style.display = "block" + showelement("placedescriptor") el = document.getElementById("placenameinput") el.value = err.message }) diff --git a/web.go b/web.go index 86930f3..5c34eb1 100644 --- a/web.go +++ b/web.go @@ -1052,6 +1052,25 @@ func submithonk(w http.ResponseWriter, r *http.Request) { p.Url = r.FormValue("placeurl") honk.Place = p } + timestart := r.FormValue("timestart") + if timestart != "" { + t := new(Time) + now := time.Now().Local() + for _, layout := range []string{"3:04pm", "15:04"} { + start, err := time.Parse(layout, timestart) + if err == nil { + if start.Year() == 0 { + start = time.Date(now.Year(), now.Month(), now.Day(), start.Hour(), start.Minute(), 0, 0, now.Location()) + } + t.StartTime = start + break + } + } + if !t.StartTime.IsZero() { + honk.What = "event" + honk.Time = t + } + } if honk.Public { honk.Whofore = 2