Support AP-style mentions of centralized social media accounts

This allows users to mention users on the following non-ActivityPub
social media sites:

- twitter.com
- medium.com

It also adds missing error handling in federatePost().
pull/319/head
Matt Baer 5 years ago
parent 5c94d23466
commit 507acc7e1c
  1. 4
      activitypub.go
  2. 11
      database.go
  3. 10
      silobridge.go

@ -699,6 +699,10 @@ func federatePost(app *App, p *PublicPost, collID int64, isUpdate bool) error {
// I don't believe we'd ever have too many mentions in a single post that this // I don't believe we'd ever have too many mentions in a single post that this
// could become a burden. // could become a burden.
remoteUser, err := getRemoteUser(app, tag.HRef) remoteUser, err := getRemoteUser(app, tag.HRef)
if err != nil {
log.Error("Unable to find remote user %s. Skipping: %v", tag.HRef, err)
continue
}
err = makeActivityPost(app.cfg.App.Host, actor, remoteUser.Inbox, activity) err = makeActivityPost(app.cfg.App.Host, actor, remoteUser.Inbox, activity)
if err != nil { if err != nil {
log.Error("Couldn't post! %v", err) log.Error("Couldn't post! %v", err)

@ -2652,6 +2652,17 @@ func handleFailedPostInsert(err error) error {
func (db *datastore) GetProfilePageFromHandle(app *App, handle string) (string, error) { func (db *datastore) GetProfilePageFromHandle(app *App, handle string) (string, error) {
handle = strings.TrimLeft(handle, "@") handle = strings.TrimLeft(handle, "@")
actorIRI := "" actorIRI := ""
parts := strings.Split(handle, "@")
if len(parts) != 2 {
return "", fmt.Errorf("invalid handle format")
}
domain := parts[1]
// Check non-AP instances
if prefix, ok := fakeAPInstances[domain]; ok {
return "https://" + domain + "/" + prefix + parts[0], nil
}
remoteUser, err := getRemoteUserFromHandle(app, handle) remoteUser, err := getRemoteUserFromHandle(app, handle)
if err != nil { if err != nil {
// can't find using handle in the table but the table may already have this user without // can't find using handle in the table but the table may already have this user without

@ -0,0 +1,10 @@
package writefreely
// fakeAPInstances contains a list of sites that we allow writers to mention
// with the @handle@instance.tld syntax, plus the corresponding prefix to
// insert between `https://instance.tld/` and `handle` (e.g.
// https://medium.com/@handle)
var fakeAPInstances = map[string]string{
"twitter.com": "",
"medium.com": "@",
}
Loading…
Cancel
Save