more robust shortcut.. return hash of long xid instead of tail.

sometimes the suffix is common to many activities.
noticed by micropub.
This commit is contained in:
Ted Unangst 2019-10-22 13:06:43 -04:00
parent acd96f17ee
commit aebc6c8981
2 changed files with 18 additions and 12 deletions

View File

@ -1176,6 +1176,8 @@ func honkworldwide(user *WhatAbout, honk *Honk) {
jonk.Write(&buf)
msg := buf.Bytes()
log.Printf("obj for transmission: %s", msg)
rcpts := make(map[string]bool)
for _, a := range honk.Audience {
if a == thewholeworld || a == user.URL || strings.HasSuffix(a, "/followers") {

28
fun.go
View File

@ -18,8 +18,10 @@ package main
import (
"crypto/rand"
"crypto/rsa"
"crypto/sha512"
"fmt"
"html/template"
"io"
"log"
"net/http"
"os"
@ -230,25 +232,27 @@ func translate(honk *Honk, redoimages bool) {
}
}
func shortxid(xid string) string {
idx := strings.LastIndexByte(xid, '/')
if idx == -1 {
return xid
}
return xid[idx+1:]
}
func xfiltrate() string {
func xcelerate(b []byte) string {
letters := "BCDFGHJKLMNPQRSTVWXYZbcdfghjklmnpqrstvwxyz1234567891234567891234"
var b [18]byte
rand.Read(b[:])
for i, c := range b {
b[i] = letters[c&63]
}
s := string(b[:])
s := string(b)
return s
}
func shortxid(xid string) string {
h := sha512.New512_256()
io.WriteString(h, xid)
return xcelerate(h.Sum(nil)[:20])
}
func xfiltrate() string {
var b [18]byte
rand.Read(b[:])
return xcelerate(b[:])
}
var re_hashes = regexp.MustCompile(`(?:^| )#[[:alnum:]][[:alnum:]_-]*`)
func ontologies(s string) []string {