From 2cfa3a71e2af3acdbfa8dc3d736223fe934732f4 Mon Sep 17 00:00:00 2001 From: Ted Unangst Date: Sat, 28 Sep 2019 00:12:50 -0400 Subject: [PATCH] location checkins! waaahahaha --- activity.go | 8 ++++++++ database.go | 36 +++++++++++++++++++++++++++++++++++- docs/changelog.txt | 2 ++ honk.go | 7 +++++++ schema.sql | 2 ++ upgradedb.go | 4 ++++ util.go | 2 +- views/honk.html | 3 +++ views/honkform.html | 6 ++++++ views/honkpage.js | 16 ++++++++++++++++ web.go | 11 +++++++++++ 11 files changed, 95 insertions(+), 2 deletions(-) diff --git a/activity.go b/activity.go index 2796681..3fea31e 100644 --- a/activity.go +++ b/activity.go @@ -914,6 +914,14 @@ func jonkjonk(user *WhatAbout, h *Honk) (junk.Junk, junk.Junk) { 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 } diff --git a/database.go b/database.go index 8204b6a..e8a54b8 100644 --- a/database.go +++ b/database.go @@ -250,6 +250,26 @@ func donksforhonks(honks []*Honk) { 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 @@ func saveextras(h *Honk) error { 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 } @@ -295,6 +323,10 @@ func deleteextras(honkid int64) { if err != nil { log.Printf("error deleting: %s", err) } + _, err = stmtDeletePlace.Exec(honkid) + if err != nil { + log.Printf("error deleting: %s", err) + } } func deletehonk(honkid int64) { @@ -348,7 +380,7 @@ var stmtAddDoover, stmtGetDoovers, stmtLoadDoover, stmtZapDoover, stmtOneHonker 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 @@ func prepareStatements(db *sql.DB) { 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 (?, ?)") diff --git a/docs/changelog.txt b/docs/changelog.txt index 992c000..dd0400f 100644 --- a/docs/changelog.txt +++ b/docs/changelog.txt @@ -2,6 +2,8 @@ changelog -- next ++ Location checkin. Welcome to the... danger zone! + +++ Editing honks (Update activity). + Quick mention @alias. diff --git a/honk.go b/honk.go index 7c3bb22..72e2b35 100644 --- a/honk.go +++ b/honk.go @@ -61,6 +61,7 @@ type Honk struct { Open string Donks []*Donk Onts []string + Place *Place } const ( @@ -87,6 +88,12 @@ type Donk struct { Content []byte } +type Place struct { + Name string + Latitude float64 + Longitude float64 +} + type Honker struct { ID int64 UserID int64 diff --git a/schema.sql b/schema.sql index 952f8be..4da0db1 100644 --- a/schema.sql +++ b/schema.sql @@ -8,6 +8,7 @@ create table zonkers (zonkerid integer primary key, userid integer, name text, w 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); diff --git a/upgradedb.go b/upgradedb.go index 7e242e2..c541701 100644 --- a/upgradedb.go +++ b/upgradedb.go @@ -186,6 +186,10 @@ func upgradedb() { 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) } diff --git a/util.go b/util.go index b3625a8..910f361 100644 --- a/util.go +++ b/util.go @@ -72,7 +72,7 @@ var dbtimeformat = "2006-01-02 15:04:05" 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") diff --git a/views/honk.html b/views/honk.html index 2214792..3c24ee3 100644 --- a/views/honk.html +++ b/views/honk.html @@ -42,6 +42,9 @@ in reply to: {{ .RID }} {{ .HTPrecis }}

{{ .HTPrecis }}

{{ .HTML }} +{{ with .Place }} +

Location: {{ .Name }} {{ .Latitude }} {{ .Longitude }} +{{ end }} {{ range .Donks }} {{ if .Local }} {{ if eq .Media "text/plain" }} diff --git a/views/honkform.html b/views/honkform.html index 35b60b5..d84b83e 100644 --- a/views/honkform.html +++ b/views/honkform.html @@ -10,6 +10,12 @@ in reply to:

description: +

+

diff --git a/views/honkpage.js b/views/honkpage.js index 0bdc52f..0e9147a 100644 --- a/views/honkpage.js +++ b/views/honkpage.js @@ -202,3 +202,19 @@ function updatedonker() { 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 + }) + } +} diff --git a/web.go b/web.go index ea98ce5..93696c9 100644 --- a/web.go +++ b/web.go @@ -1039,6 +1039,17 @@ func submithonk(w http.ResponseWriter, r *http.Request) { } 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 {