all repos — honk @ 0a3b3d52608fb9abda0651b5353421571102d8d0

my fork of honk

location checkins! waaahahaha
Ted Unangst tedu@tedunangst.com
Sat, 28 Sep 2019 00:12:50 -0400
commit

0a3b3d52608fb9abda0651b5353421571102d8d0

parent

facf1bba11595ec5a5e51801ae170755924f4c9c

M activity.goactivity.go

@@ -914,6 +914,14 @@ i["url"] = e.ID

t["icon"] = i tags = append(tags, t) } + if p := h.Place; p != nil { + t := junk.New() + t["type"] = "Place" + t["name"] = p.Name + t["latitude"] = p.Latitude + t["longitude"] = p.Longitude + tags = append(tags, t) + } if len(tags) > 0 { jo["tag"] = tags }
M database.godatabase.go

@@ -250,6 +250,26 @@ h := hmap[hid]

h.Onts = append(h.Onts, o) } rows.Close() + // grab places + q = fmt.Sprintf("select honkid, name, latitude, longitude from places where honkid in (%s)", strings.Join(ids, ",")) + rows, err = db.Query(q) + if err != nil { + log.Printf("error querying places: %s", err) + return + } + defer rows.Close() + for rows.Next() { + var hid int64 + p := new(Place) + err = rows.Scan(&hid, &p.Name, &p.Latitude, &p.Longitude) + if err != nil { + log.Printf("error scanning place: %s", err) + continue + } + h := hmap[hid] + h.Place = p + } + rows.Close() } func savehonk(h *Honk) error {

@@ -283,6 +303,14 @@ log.Printf("error saving ont: %s", err)

return err } } + if h.Place != nil { + _, err := stmtSavePlace.Exec(h.ID, h.Place.Name, h.Place.Latitude, h.Place.Longitude) + if err != nil { + log.Printf("error saving ont: %s", err) + return err + } + } + return nil }

@@ -292,6 +320,10 @@ if err != nil {

log.Printf("error deleting: %s", err) } _, err = stmtDeleteOnts.Exec(honkid) + if err != nil { + log.Printf("error deleting: %s", err) + } + _, err = stmtDeletePlace.Exec(honkid) if err != nil { log.Printf("error deleting: %s", err) }

@@ -348,7 +380,7 @@ var stmtAddDoover, stmtGetDoovers, stmtLoadDoover, stmtZapDoover, stmtOneHonker *sql.Stmt

var stmtThumbBiters, stmtDeleteHonk, stmtDeleteDonks, stmtDeleteOnts, stmtSaveZonker *sql.Stmt var stmtGetZonkers, stmtRecentHonkers, stmtGetXonker, stmtSaveXonker, stmtDeleteXonker *sql.Stmt var stmtSelectOnts, stmtSaveOnt, stmtUpdateFlags, stmtClearFlags *sql.Stmt -var stmtHonksForUserFirstClass, stmtSaveOld, stmtUpdateHonk *sql.Stmt +var stmtSavePlace, stmtDeletePlace, stmtHonksForUserFirstClass, stmtSaveOld, stmtUpdateHonk *sql.Stmt func preparetodie(db *sql.DB, s string) *sql.Stmt { stmt, err := db.Prepare(s)

@@ -387,6 +419,8 @@ stmtSaveOld = preparetodie(db, "insert into forsaken (honkid, precis, noise) values (?, ?, ?)")

stmtSaveHonk = preparetodie(db, "insert into honks (userid, what, honker, xid, rid, dt, url, audience, noise, convoy, whofore, format, precis, oonker, flags) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)") stmtDeleteHonk = preparetodie(db, "delete from honks where honkid = ?") stmtUpdateHonk = preparetodie(db, "update honks set precis = ?, noise = ?, format = ?, dt = ? where honkid = ?") + stmtSavePlace = preparetodie(db, "insert into places (honkid, name, latitude, longitude) values (?, ?, ?, ?)") + stmtDeletePlace = preparetodie(db, "delete from places where honkid = ?") stmtSaveOnt = preparetodie(db, "insert into onts (ontology, honkid) values (?, ?)") stmtDeleteOnts = preparetodie(db, "delete from onts where honkid = ?") stmtSaveDonk = preparetodie(db, "insert into donks (honkid, fileid) values (?, ?)")
M docs/changelog.txtdocs/changelog.txt

@@ -2,6 +2,8 @@ changelog

-- next ++ Location checkin. Welcome to the... danger zone! + +++ Editing honks (Update activity). + Quick mention @alias.
M honk.gohonk.go

@@ -61,6 +61,7 @@ Style string

Open string Donks []*Donk Onts []string + Place *Place } const (

@@ -85,6 +86,12 @@ URL string

Media string Local bool Content []byte +} + +type Place struct { + Name string + Latitude float64 + Longitude float64 } type Honker struct {
M schema.sqlschema.sql

@@ -8,6 +8,7 @@ create table zonkers (zonkerid integer primary key, userid integer, name text, wherefore text);

create table doovers(dooverid integer primary key, dt text, tries integer, username text, rcpt text, msg blob); create table onts (ontology text, honkid integer); create table forsaken (honkid integer, precis text, noise text); +create table places (honkid integer, name text, latitude real, longitude real); create index idx_honksxid on honks(xid); create index idx_honksconvoy on honks(convoy);

@@ -20,6 +21,7 @@ create index idx_filesxid on files(xid);

create index idx_filesurl on files(url); create index idx_ontology on onts(ontology); create index idx_onthonkid on onts(honkid); +create index idx_placehonkid on places(honkid); create table config (key text, value text);
M upgradedb.goupgradedb.go

@@ -186,6 +186,10 @@ case 18:

doordie(db, "create index idx_onthonkid on onts(honkid)") doordie(db, "update config set value = 19 where key = 'dbversion'") case 19: + doordie(db, "create table places (honkid integer, name text, latitude real, longitude real)") + doordie(db, "create index idx_placehonkid on places(honkid)") + doordie(db, "update config set value = 20 where key = 'dbversion'") + case 20: default: log.Fatalf("can't upgrade unknown version %d", dbversion) }
M util.goutil.go

@@ -72,7 +72,7 @@

var alreadyopendb *sql.DB var dbname = "honk.db" var stmtConfig *sql.Stmt -var myVersion = 19 +var myVersion = 20 func initdb() { schema, err := ioutil.ReadFile("schema.sql")
M views/honk.htmlviews/honk.html

@@ -42,6 +42,9 @@ <details class="noise" {{ .Open }} >

<summary>{{ .HTPrecis }}</summary> <p>{{ .HTPrecis }} <p>{{ .HTML }} +{{ with .Place }} +<p>Location: {{ .Name }} <a href="https://www.openstreetmap.org/?mlat={{ .Latitude }}&mlon={{ .Longitude}}">{{ .Latitude }} {{ .Longitude }}</a> +{{ end }} {{ range .Donks }} {{ if .Local }} {{ if eq .Media "text/plain" }}
M views/honkform.htmlviews/honkform.html

@@ -10,6 +10,12 @@ <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 }}"> <p id="donkdescriptor"> description: <input type="text" name="donkdesc" value="{{ .DonkDesc }}" autocomplete=off> +<p><button id=checkinbutton type=button onclick="fillcheckin()">checkin</button> +<div id=placedescriptor style="display: none"> +<p>name: <input type="text" name="placename" id=placenameinput value=""> +<p>latitude: <input type="text" name="placelat" id=placelatinput value=""> +<p>longitude: <input type="text" name="placelong" id=placelonginput value=""> +</div> <p> <textarea name="noise" id="honknoise">{{ .Noise }}</textarea> <p>
M views/honkpage.jsviews/honkpage.js

@@ -202,3 +202,19 @@ el.children[1].textContent = el.children[0].value.slice(-20)

var el = document.getElementById("donkdescriptor") el.style.display = "" } +function fillcheckin() { + if (navigator.geolocation) { + navigator.geolocation.getCurrentPosition(function(pos) { + var precision = 500.0 + var el = document.getElementById("placedescriptor") + el.style.display = "block" + el = document.getElementById("placelatinput") + el.value = Math.round(pos.coords.latitude * precision) / precision + el = document.getElementById("placelonginput") + el.value = Math.round(pos.coords.longitude * precision) / precision + }, function(err) { + var el = document.getElementById("placenamenput") + el.innerHTML = err.message + }) + } +}
M web.goweb.go

@@ -1039,6 +1039,17 @@ }

} memetize(honk) + placename := r.FormValue("placename") + placelat := r.FormValue("placelat") + placelong := r.FormValue("placelong") + if placename != "" || placelat != "" || placelong != "" { + p := new(Place) + p.Name = placename + p.Latitude, _ = strconv.ParseFloat(placelat, 64) + p.Longitude, _ = strconv.ParseFloat(placelong, 64) + honk.Place = p + } + if honk.Public { honk.Whofore = 2 } else {