location checkins! waaahahaha

This commit is contained in:
Ted Unangst 2019-09-28 00:12:50 -04:00
parent b25fb94be2
commit 2cfa3a71e2
11 changed files with 95 additions and 2 deletions

View File

@ -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
}

View File

@ -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 (?, ?)")

View File

@ -2,6 +2,8 @@ changelog
-- next
+ Location checkin. Welcome to the... danger zone!
+++ Editing honks (Update activity).
+ Quick mention @alias.

View File

@ -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

View File

@ -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);

View File

@ -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)
}

View File

@ -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")

View File

@ -42,6 +42,9 @@ in reply to: <a href="{{ .RID }}" rel=noreferrer>{{ .RID }}</a>
<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" }}

View File

@ -10,6 +10,12 @@ in reply to: <input type="text" name="rid" id="ridinput" value="{{ .InReplyTo }}
<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>

View File

@ -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
})
}
}

11
web.go
View File

@ -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 {