events with start times. because... because.

This commit is contained in:
Ted Unangst 2019-10-02 18:20:14 -04:00
parent 8af2bbe746
commit e3fdf87a00
7 changed files with 74 additions and 11 deletions

View File

@ -541,6 +541,9 @@ func xonksaver(user *WhatAbout, item junk.Junk, origin string) *Honk {
case "Page": case "Page":
obj = item obj = item
what = "honk" what = "honk"
case "Event":
obj = item
what = "event"
default: default:
log.Printf("unknown activity: %s", what) log.Printf("unknown activity: %s", what)
fd, _ := os.OpenFile("savedinbox.json", os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666) 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 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) xonk.Onts = oneofakind(xonk.Onts)
replyobj, ok := obj.GetMap("replies") replyobj, ok := obj.GetMap("replies")
if ok { if ok {
@ -878,16 +891,20 @@ func jonkjonk(user *WhatAbout, h *Honk) (junk.Junk, junk.Junk) {
fallthrough fallthrough
case "tonk": case "tonk":
fallthrough fallthrough
case "event":
fallthrough
case "honk": case "honk":
j["type"] = "Create"
if h.What == "update" { if h.What == "update" {
j["type"] = "Update" j["type"] = "Update"
} else {
j["type"] = "Create"
} }
jo = junk.New() jo = junk.New()
jo["id"] = h.XID jo["id"] = h.XID
jo["type"] = "Note" jo["type"] = "Note"
if h.What == "event" {
jo["type"] = "Event"
}
jo["published"] = dt jo["published"] = dt
jo["url"] = h.XID jo["url"] = h.XID
jo["attributedTo"] = user.URL jo["attributedTo"] = user.URL
@ -967,6 +984,9 @@ func jonkjonk(user *WhatAbout, h *Honk) (junk.Junk, junk.Junk) {
if len(tags) > 0 { if len(tags) > 0 {
jo["tag"] = tags jo["tag"] = tags
} }
if t := h.Time; t != nil {
jo["startTime"] = t.StartTime.Format(time.RFC3339)
}
var atts []junk.Junk var atts []junk.Junk
for _, d := range h.Donks { for _, d := range h.Donks {
if re_emus.MatchString(d.Name) { if re_emus.MatchString(d.Name) {

View File

@ -278,6 +278,14 @@ func donksforhonks(honks []*Honk) {
continue continue
} }
h.Place = p 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": case "oldrev":
default: default:
log.Printf("unknown meta genus: %s", genus) log.Printf("unknown meta genus: %s", genus)
@ -334,7 +342,7 @@ func saveextras(h *Honk) error {
} }
if p := h.Place; p != nil { if p := h.Place; p != nil {
j, err := jsonify(p) j, err := jsonify(p)
if err != nil { if err == nil {
_, err = stmtSaveMeta.Exec(h.ID, "place", j) _, err = stmtSaveMeta.Exec(h.ID, "place", j)
} }
if err != nil { if err != nil {
@ -342,9 +350,9 @@ func saveextras(h *Honk) error {
return err return err
} }
} }
if p := h.Time; p != nil { if t := h.Time; t != nil {
j, err := jsonify(p) j, err := jsonify(t)
if err != nil { if err == nil {
_, err = stmtSaveMeta.Exec(h.ID, "time", j) _, err = stmtSaveMeta.Exec(h.ID, "time", j)
} }
if err != nil { if err != nil {

View File

@ -2,6 +2,8 @@ changelog
-- next -- next
+ Times for events.
+ Split media database into separate blob.db. + Split media database into separate blob.db.
+ Location checkin. Welcome to the... danger zone! + Location checkin. Welcome to the... danger zone!

View File

@ -42,6 +42,9 @@ in reply to: <a href="{{ .RID }}" rel=noreferrer>{{ .RID }}</a>
<summary>{{ .HTPrecis }}<p></summary> <summary>{{ .HTPrecis }}<p></summary>
<p>{{ .HTPrecis }} <p>{{ .HTPrecis }}
<p>{{ .HTML }} <p>{{ .HTML }}
{{ with .Time }}
<p>Time: {{ .StartTime.Local }}
{{ end }}
{{ with .Place }} {{ with .Place }}
<p>Location: {{ with .Url }}<a href="{{ . }}" rel=noreferrer>{{ end }}{{ .Name }}{{ if .Url }}</a>{{ end }} <a href="https://www.openstreetmap.org/?mlat={{ .Latitude }}&mlon={{ .Longitude}}" rel=noreferrer>{{ .Latitude }} {{ .Longitude }}</a> <p>Location: {{ with .Url }}<a href="{{ . }}" rel=noreferrer>{{ end }}{{ .Name }}{{ if .Url }}</a>{{ end }} <a href="https://www.openstreetmap.org/?mlat={{ .Latitude }}&mlon={{ .Longitude}}" rel=noreferrer>{{ .Latitude }} {{ .Longitude }}</a>
{{ end }} {{ end }}

View File

@ -5,6 +5,9 @@
<input type="hidden" name="updatexid" value = "{{ .UpdateXID }}"> <input type="hidden" name="updatexid" value = "{{ .UpdateXID }}">
<input type="hidden" name="rid" id="ridinput" value="{{ .InReplyTo }}"> <input type="hidden" name="rid" id="ridinput" value="{{ .InReplyTo }}">
<p> <p>
<details>
<summary>more options</summary>
<p>
<label id="donker">attach: {{ if .SavedFile }} {{ .SavedFile }} {{ else }} <input onchange="updatedonker();" type="file" name="donk"><span></span> {{ end }}</label> <label id="donker">attach: {{ if .SavedFile }} {{ .SavedFile }} {{ else }} <input onchange="updatedonker();" type="file" name="donk"><span></span> {{ end }}</label>
<input type="hidden" name="donkxid" value="{{ .SavedFile }}"> <input type="hidden" name="donkxid" value="{{ .SavedFile }}">
<p id="donkdescriptor"> <p id="donkdescriptor">
@ -16,6 +19,12 @@ desc: <input type="text" name="donkdesc" value="{{ .DonkDesc }}" autocomplete=of
<p>lat: <input type="text" size=9 name="placelat" id=placelatinput value=""> <p>lat: <input type="text" size=9 name="placelat" id=placelatinput value="">
lon: <input type="text" size=9 name="placelong" id=placelonginput value=""> lon: <input type="text" size=9 name="placelong" id=placelonginput value="">
</div> </div>
<p><button id=addtimebutton type=button onclick="showelement('timedescriptor')">add time</button>
<div id=timedescriptor style="display: none">
<p>start: <input type="text" name="timestart" value="">
<p>end: <input type="text" name="timeend" value="">
</div>
</details>
<p> <p>
<textarea name="noise" id="honknoise">{{ .Noise }}</textarea> <textarea name="noise" id="honknoise">{{ .Noise }}</textarea>
<p> <p>

View File

@ -207,6 +207,10 @@ function showhonkform(elem, rid, hname) {
} }
document.getElementById("honknoise").focus() document.getElementById("honknoise").focus()
} }
function showelement(id) {
var el = document.getElementById(id)
el.style.display = "block"
}
function updatedonker() { function updatedonker() {
var el = document.getElementById("donker") var el = document.getElementById("donker")
el.children[1].textContent = el.children[0].value.slice(-20) el.children[1].textContent = el.children[0].value.slice(-20)
@ -217,16 +221,14 @@ var checkinprec = 500.0
function fillcheckin() { function fillcheckin() {
if (navigator.geolocation) { if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(pos) { navigator.geolocation.getCurrentPosition(function(pos) {
var el = document.getElementById("placedescriptor") showelement("placedescriptor")
el.style.display = "block" var el = document.getElementById("placelatinput")
el = document.getElementById("placelatinput")
el.value = Math.round(pos.coords.latitude * checkinprec) / checkinprec el.value = Math.round(pos.coords.latitude * checkinprec) / checkinprec
el = document.getElementById("placelonginput") el = document.getElementById("placelonginput")
el.value = Math.round(pos.coords.longitude * checkinprec) / checkinprec el.value = Math.round(pos.coords.longitude * checkinprec) / checkinprec
checkinprec = 10000.0 checkinprec = 10000.0
}, function(err) { }, function(err) {
var el = document.getElementById("placedescriptor") showelement("placedescriptor")
el.style.display = "block"
el = document.getElementById("placenameinput") el = document.getElementById("placenameinput")
el.value = err.message el.value = err.message
}) })

19
web.go
View File

@ -1052,6 +1052,25 @@ func submithonk(w http.ResponseWriter, r *http.Request) {
p.Url = r.FormValue("placeurl") p.Url = r.FormValue("placeurl")
honk.Place = p 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 { if honk.Public {
honk.Whofore = 2 honk.Whofore = 2