diff --git a/activitypub.go b/activitypub.go index 081fcea..a6ef1da 100644 --- a/activitypub.go +++ b/activitypub.go @@ -637,16 +637,11 @@ func federatePost(app *App, p *PublicPost, collID int64, isUpdate bool) error { // much logic to catch this at the expense of the odd extra request. // I don't believe we'd ever have too many mentions in a single post that this // could become a burden. - - fmt.Println(tag.HRef) - fmt.Println("aaa") remoteUser, err := getRemoteUser(app, tag.HRef) err = makeActivityPost(app.cfg.App.Host, actor, remoteUser.Inbox, activity) if err != nil { log.Error("Couldn't post! %v", err) } - // log.Info("Activity", activity) - } } diff --git a/collections.go b/collections.go index 431afd1..f0450b5 100644 --- a/collections.go +++ b/collections.go @@ -830,10 +830,7 @@ func handleViewMention(app *App, w http.ResponseWriter, r *http.Request) error { return nil } - http.Redirect(w, r, remoteUser, http.StatusSeeOther) - w.Write([]byte("go to " + remoteUser)) - - return nil + return impart.HTTPError{Status: http.StatusFound, Message: remoteUser} } func handleViewCollectionTag(app *App, w http.ResponseWriter, r *http.Request) error { diff --git a/routes.go b/routes.go index 4c26f47..6f6bd58 100644 --- a/routes.go +++ b/routes.go @@ -70,6 +70,9 @@ func InitRoutes(apper Apper, r *mux.Router) *mux.Router { write.HandleFunc(nodeinfo.NodeInfoPath, handler.LogHandlerFunc(http.HandlerFunc(ni.NodeInfoDiscover))) write.HandleFunc(niCfg.InfoURL, handler.LogHandlerFunc(http.HandlerFunc(ni.NodeInfo))) + // handle mentions + write.HandleFunc("/mention:{handle}", handler.Web(handleViewMention, UserLevelReader)) + // Set up dyamic page handlers // Handle auth auth := write.PathPrefix("/api/auth/").Subrouter() @@ -184,7 +187,6 @@ func InitRoutes(apper Apper, r *mux.Router) *mux.Router { func RouteCollections(handler *Handler, r *mux.Router) { r.HandleFunc("/page/{page:[0-9]+}", handler.Web(handleViewCollection, UserLevelReader)) - r.HandleFunc("/mention:{handle}", handler.Web(handleViewMention, UserLevelReader)) r.HandleFunc("/tag:{tag}", handler.Web(handleViewCollectionTag, UserLevelReader)) r.HandleFunc("/tag:{tag}/feed/", handler.Web(ViewFeed, UserLevelReader)) r.HandleFunc("/tags/{tag}", handler.Web(handleViewCollectionTag, UserLevelReader)) diff --git a/schema.sql b/schema.sql index ca8ec71..b3fae97 100644 --- a/schema.sql +++ b/schema.sql @@ -181,7 +181,6 @@ CREATE TABLE IF NOT EXISTS `remoteusers` ( `actor_id` varchar(255) NOT NULL, `inbox` varchar(255) NOT NULL, `shared_inbox` varchar(255) NOT NULL, - `handle` varchar(255) DEFAULT '' NOT NULL, PRIMARY KEY (`id`), UNIQUE KEY `collection_id` (`actor_id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1; diff --git a/sqlite.sql b/sqlite.sql index e1a6b96..90989ed 100644 --- a/sqlite.sql +++ b/sqlite.sql @@ -172,7 +172,6 @@ CREATE TABLE IF NOT EXISTS `remoteusers` ( actor_id TEXT NOT NULL, inbox TEXT NOT NULL, shared_inbox TEXT NOT NULL, - handle TEXT DEFAULT '' NOT NULL, CONSTRAINT collection_id UNIQUE (actor_id) ); diff --git a/webfinger.go b/webfinger.go index 715e1cf..72c3f95 100644 --- a/webfinger.go +++ b/webfinger.go @@ -106,7 +106,22 @@ func RemoteLookup(handle string) string { var result map[string]interface{} json.Unmarshal(body, &result) - aliases := result["aliases"].([]interface{}) + var href string + for _, link := range result["links"].([]interface{}) { + if link.(map[string]interface{})["rel"] == "self" { + href = link.(map[string]interface{})["href"].(string) + } + } + + // if we didn't find it with the above then + // try using aliases + if href == "" { + aliases := result["aliases"].([]interface{}) + // take the last alias because mastodon has the + // https://instance.tld/@user first which + // doesn't work as an href + href = aliases[len(aliases)-1].(string) + } - return aliases[len(aliases)-1].(string) + return href }