diff --git a/views/honk.html b/views/honk.html
index a10b329..96d4201 100644
--- a/views/honk.html
+++ b/views/honk.html
@@ -32,7 +32,7 @@ in reply to: {{ .RID }}
{{ end }}
{{ if $bonkcsrf }}
-convoy: {{ .Convoy }}
+convoy: {{ .Convoy }}
{{ else }}
convoy: {{ .Convoy }}
{{ end }}
diff --git a/views/honkpage.html b/views/honkpage.html
index 951631a..541865f 100644
--- a/views/honkpage.html
+++ b/views/honkpage.html
@@ -13,138 +13,19 @@
{{ $BonkCSRF := .HonkCSRF }}
{{ if .TopXID }}
+
{{ range .Honks }}
{{ template "honk.html" map "Honk" . "BonkCSRF" $BonkCSRF }}
{{ end }}
+
{{ if $BonkCSRF }}
{{ end }}
diff --git a/views/honkpage.js b/views/honkpage.js
new file mode 100644
index 0000000..0e2ee9a
--- /dev/null
+++ b/views/honkpage.js
@@ -0,0 +1,139 @@
+{{ $BonkCSRF := .HonkCSRF }}
+function encode(hash) {
+ var s = []
+ for (var key in hash) {
+ var val = hash[key]
+ s.push(escape(key) + "=" + escape(val))
+ }
+ return s.join("&")
+}
+function post(url, data) {
+ var x = new XMLHttpRequest()
+ x.open("POST", url)
+ x.setRequestHeader("Content-Type", "application/x-www-form-urlencoded")
+ x.send(data)
+}
+function get(url, whendone) {
+ var x = new XMLHttpRequest()
+ x.open("GET", url)
+ x.responseType = "document"
+ x.onload = function() { whendone(x) }
+ x.send()
+}
+function bonk(el, xid) {
+ el.innerHTML = "bonked"
+ el.disabled = true
+ post("/bonk", "CSRF={{ $BonkCSRF }}&xid=" + escape(xid))
+}
+function unbonk(el, xid) {
+ el.innerHTML = "unbonked"
+ el.disabled = true
+ post("/zonkit", "CSRF={{ $BonkCSRF }}&wherefore=unbonk&what=" + escape(xid))
+}
+function muteit(el, convoy) {
+ el.innerHTML = "muted"
+ el.disabled = true
+ post("/zonkit", "CSRF={{ $BonkCSRF }}&wherefore=zonvoy&what=" + escape(convoy))
+ var els = document.querySelectorAll('article.honk')
+ for (var i = 0; i < els.length; i++) {
+ var e = els[i]
+ if (e.getAttribute("data-convoy") == convoy) {
+ e.remove()
+ }
+ }
+}
+function zonkit(el, xid) {
+ el.innerHTML = "zonked"
+ el.disabled = true
+ post("/zonkit", "CSRF={{ $BonkCSRF }}&wherefore=zonk&what=" + escape(xid))
+ var p = el
+ while (p && p.tagName != "ARTICLE") {
+ p = p.parentElement
+ }
+ if (p) {
+ p.remove()
+ }
+}
+function ackit(el, xid) {
+ el.innerHTML = "acked"
+ el.disabled = true
+ post("/zonkit", "CSRF={{ $BonkCSRF }}&wherefore=ack&what=" + escape(xid))
+}
+function deackit(el, xid) {
+ el.innerHTML = "deacked"
+ el.disabled = true
+ post("/zonkit", "CSRF={{ $BonkCSRF }}&wherefore=deack&what=" + escape(xid))
+}
+var topxid = { "{{ .PageName }}" : "{{ .TopXID }}" }
+var honksforpage = { }
+var thispagename = "{{ .PageName }}"
+function fillinhonks(xhr) {
+ var doc = xhr.responseXML
+ topxid[thispagename] = doc.children[0].children[1].children[0].innerText
+ var honks = doc.children[0].children[1].children[1].children
+ var honksonpage = document.getElementById("honksonpage")
+ var holder = honksonpage.children[0]
+ var lenhonks = honks.length
+ for (var i = honks.length; i > 0; i--) {
+ holder.prepend(honks[i-1])
+ }
+ relinkconvoys()
+ return lenhonks
+}
+function refreshhonks(btn) {
+ btn.innerHTML = "refreshing"
+ btn.disabled = true
+ var args = { "page" : thispagename }
+ args["topxid"] = topxid[thispagename]
+ get("/hydra?" + encode(args), function(xhr) {
+ var lenhonks = fillinhonks(xhr)
+ btn.innerHTML = "refresh"
+ btn.disabled = false
+ btn.parentElement.children[1].innerHTML = " " + lenhonks + " new"
+ })
+}
+function pageswitcher(name) {
+ return function(evt) {
+ if (name == thispagename) {
+ return false
+ }
+ var honksonpage = document.getElementById("honksonpage")
+ var holder = honksonpage.children[0]
+ holder.remove()
+ if (thispagename != "convoy") {
+ honksforpage[thispagename] = holder
+ }
+
+ thispagename = name
+ holder = honksforpage[name]
+ if (holder) {
+ honksonpage.prepend(holder)
+ } else {
+ honksonpage.prepend(document.createElement("div"))
+ var args = { "page" : name }
+ if (name == "convoy") {
+ console.log("convoy page")
+ var c = evt.srcElement.text
+ args["c"] = c
+ } else {
+ args["topxid"] = topxid[name]
+ }
+ get("/hydra?" + encode(args), fillinhonks)
+ }
+ return false
+ }
+}
+function relinkconvoys() {
+ var els = document.getElementsByClassName("convoylink")
+ for (var i = 0; i < els.length; i++) {
+ els[i].onclick = pageswitcher("convoy")
+ }
+}
+(function() {
+ console.log("ok")
+ var el = document.getElementById("homelink")
+ el.onclick = pageswitcher("home")
+ var el = document.getElementById("atmelink")
+ el.onclick = pageswitcher("atme")
+ relinkconvoys()
+})();
diff --git a/web.go b/web.go
index 878a9dc..3236fe2 100644
--- a/web.go
+++ b/web.go
@@ -107,17 +107,6 @@ func homepage(w http.ResponseWriter, r *http.Request) {
}
tname := "honkpage.html"
- if topxid := r.FormValue("topxid"); topxid != "" {
- for i, h := range honks {
- if h.XID == topxid {
- honks = honks[0:i]
- break
- }
- }
- log.Printf("topxid %d frags", len(honks))
- tname = "honkfrags.html"
- }
-
reverbolate(userid, honks)
templinfo["Honks"] = honks
@@ -1357,6 +1346,46 @@ func nomoroboto(w http.ResponseWriter, r *http.Request) {
}
}
+func webhydra(w http.ResponseWriter, r *http.Request) {
+ u := login.GetUserInfo(r)
+ userid := u.UserID
+ templinfo := getInfo(r)
+ templinfo["HonkCSRF"] = login.GetCSRF("honkhonk", r)
+ page := r.FormValue("page")
+ var honks []*Honk
+ switch page {
+ case "atme":
+ honks = gethonksforme(userid)
+ case "home":
+ honks = gethonksforuser(userid)
+ honks = osmosis(honks, userid)
+ case "convoy":
+ c := r.FormValue("c")
+ honks = gethonksbyconvoy(userid, c)
+ default:
+ http.NotFound(w, r)
+ }
+ if len(honks) > 0 {
+ templinfo["TopXID"] = honks[0].XID
+ }
+ if topxid := r.FormValue("topxid"); topxid != "" {
+ for i, h := range honks {
+ if h.XID == topxid {
+ honks = honks[0:i]
+ break
+ }
+ }
+ log.Printf("topxid %d frags", len(honks))
+ }
+ reverbolate(userid, honks)
+ templinfo["Honks"] = honks
+ w.Header().Set("Content-Type", "text/html; charset=utf-8")
+ err := readviews.Execute(w, "honkfrags.html", templinfo)
+ if err != nil {
+ log.Printf("frag error: %s", err)
+ }
+}
+
func serve() {
db := opendatabase()
login.Init(db)
@@ -1384,6 +1413,7 @@ func serve() {
"views/xzone.html",
"views/header.html",
"views/onts.html",
+ "views/honkpage.js",
)
if !debug {
s := "views/style.css"
@@ -1448,6 +1478,7 @@ func serve() {
loggedin.HandleFunc("/c", showcombos)
loggedin.HandleFunc("/t", showconvoy)
loggedin.HandleFunc("/q", showsearch)
+ loggedin.HandleFunc("/hydra", webhydra)
loggedin.Handle("/submithonker", login.CSRFWrap("submithonker", http.HandlerFunc(submithonker)))
err = http.Serve(listener, mux)