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().
This commit is contained in:
parent
5c94d23466
commit
507acc7e1c
|
@ -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
|
||||
// could become a burden.
|
||||
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)
|
||||
if err != nil {
|
||||
log.Error("Couldn't post! %v", err)
|
||||
|
|
11
database.go
11
database.go
|
@ -2652,6 +2652,17 @@ func handleFailedPostInsert(err error) error {
|
|||
func (db *datastore) GetProfilePageFromHandle(app *App, handle string) (string, error) {
|
||||
handle = strings.TrimLeft(handle, "@")
|
||||
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)
|
||||
if err != nil {
|
||||
// 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…
Reference in New Issue