Fix comments on T627 pull request

(https://github.com/writeas/writefreely/pull/195)
This commit is contained in:
Michael Demetriou 2019-10-11 10:05:18 +03:00
parent bc2016f00f
commit b9d2689828
6 changed files with 21 additions and 14 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -106,7 +106,22 @@ func RemoteLookup(handle string) string {
var result map[string]interface{}
json.Unmarshal(body, &result)
aliases := result["aliases"].([]interface{})
return aliases[len(aliases)-1].(string)
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 href
}