Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Send out ActivityPub mentions (T627) #195

Open
wants to merge 8 commits into
base: develop
from

Conversation

@qwazix
Copy link

commented Oct 9, 2019

This pull request adds code that scans the text of each post to be published for handles of the type @username@domain.tld, uses webfinger to ask ActivityPub endpoints about them, gets their inbox and actor IRI's and adds mention tags to the post. Finally it adds the users to the CC list of the recipients of the activity.

This works in pleroma but not in mastodon unless we set the object type to "Note" instead of "Article"

T627

be Note to work but I will open an issue for them and see what their
reaction will be.
@thebaer

This comment has been minimized.

Copy link
Member

commented on posts.go in dccfae7 Oct 8, 2019

Note that this doesn't fully match domains like writing.exchange. I think we can use word boundary character (I believe it's \b?) instead of doing the {2,6} match at the end.

This comment has been minimized.

Copy link

replied Oct 9, 2019

Done

@thebaer

This comment has been minimized.

Copy link
Member

commented on webfinger.go in dccfae7 Oct 8, 2019

We should return here, otherwise the application crashes on line 100 with a nil resp when the request fails.

This comment has been minimized.

Copy link

replied Oct 9, 2019

Done

@thebaer

This comment has been minimized.

Copy link
Member

commented on posts.go in dccfae7 Oct 8, 2019

Looks like the cc field was wrong when posting to the inbox of an instance where I didn't have any followers -- it retained the list of users from the previous instance:

Oct 08 15:33:03 mangrove matt[26396]: {"@context":["https://www.w3.org/ns/activitystreams"],"type":"Create","id":"https://matt.writefreely.dev/api/posts/dluynq3dsb","actor":"https://matt.writefreely.dev/api/collections/devlog","published":"2019-10-08T15:32:57Z","to":["https://www.w3.org/ns/activitystreams#Public"],"cc":["https://pawoo.net/users/AriaLAnna8","https://pawoo.net/users/Naomii55","https://pawoo.net/users/Haanakko88"],"object":{"type":"Article","id":"https://matt.writefreely.dev/api/posts/dluynq3dsb","published":"2019-10-08T15:32:57Z","inReplyTo":null,"url":"https://matt.writefreely.dev/activitypub-mentions-part-deux","attributedTo":"https://matt.writefreely.dev/api/collections/devlog","to":["https://www.w3.org/ns/activitystreams#Public"],"cc":["https://pawoo.net/users/AriaLAnna8","https://pawoo.net/users/Naomii55","https://pawoo.net/users/Haanakko88"],"name":"ActivityPub mentions, part deux","content":"\u003cp\u003eWe\u0026#39;re working on supporting \u003ca href=\"https://matt.writefreely.dev/tag:ActivityPub\" class=\"hashtag\" rel=\"nofollow\"\u003e\u003cspan\u003e#\u003c/span\u003e\u003cspan class=\"p-category\"\u003eActivityPub\u003c/span\u003e\u003c/a\u003e mentions in \u003ca href=\"https://matt.writefreely.dev/tag:WriteFreely\" class=\"hashtag\" rel=\"nofollow\"\u003e\u003cspan\u003e#\u003c/span\u003e\u003cspan class=\"p-category\"\u003eWriteFreely\u003c/span\u003e\u003c/a\u003e now (\u003ca href=\"https://writefreely.org/tasks/627\" rel=\"nofollow\"\u003eT627\u003c/a\u003e). The work is in progress, and last post didn\u0026#39;t work.\u003c/p\u003e\n\n\u003cp\u003eTesting to see if @matt@pleroma.site gets this.\u003c/p\u003e\n\n\u003cp\u003eLet\u0026#39;s see.\u003c/p\u003e\n","contentMap":{"en":"\u003cp\u003eWe\u0026#39;re working on supporting \u003ca href=\"https://matt.writefreely.dev/tag:ActivityPub\" class=\"hashtag\" rel=\"nofollow\"\u003e\u003cspan\u003e#\u003c/span\u003e\u003cspan class=\"p-category\"\u003eActivityPub\u003c/span\u003e\u003c/a\u003e mentions in \u003ca href=\"https://matt.writefreely.dev/tag:WriteFreely\" class=\"hashtag\" rel=\"nofollow\"\u003e\u003cspan\u003e#\u003c/span\u003e\u003cspan class=\"p-category\"\u003eWriteFreely\u003c/span\u003e\u003c/a\u003e now (\u003ca href=\"https://writefreely.org/tasks/627\" rel=\"nofollow\"\u003eT627\u003c/a\u003e). The work is in progress, and last post didn\u0026#39;t work.\u003c/p\u003e\n\n\u003cp\u003eTesting to see if @matt@pleroma.site gets this.\u003c/p\u003e\n\n\u003cp\u003eLet\u0026#39;s see.\u003c/p\u003e\n"},"tag":[{"type":"Hashtag","href":"https://matt.writefreely.dev/tag:ActivityPub","name":"#ActivityPub"},{"type":"Hashtag","href":"https://matt.writefreely.dev/tag:WriteFreely","name":"#WriteFreely"},{"type":"Mention","href":"https://pleroma.site/users/matt","name":"@matt@pleroma.site"}]}}
Oct 08 15:33:04 mangrove matt[26396]: 2019/10/08 15:33:04 "GET /api/collections/devlog" 200 2.274673ms "Pleroma 1.0.0-1168-ge18c7866-pleroma-dot-site; https://pleroma.site <info@pleroma.site>"
Oct 08 15:33:04 mangrove matt[26396]: 2019/10/08 15:33:04 Status  : 500 Internal Server Error
Oct 08 15:33:04 mangrove matt[26396]: 2019/10/08 15:33:04 Response: "error"
@thebaer

This comment has been minimized.

Copy link
Member

commented Oct 9, 2019

Latest changes look good 👍 Confirmed that mentions work with Pleroma.

Michael Demetriou added 4 commits Oct 10, 2019
to the last because mastodon doesn't like

https://my.instance/@me but https://my.instance/users/me
intermediate page (WIP) that shows the user profile page url
there it updates the table to include the handle.

migrations WIP
Copy link
Member

left a comment

Just a few changes to make. Also getting this error during compilation:

./database.go:2476:61: remoteActor.GetSharedInbox undefined (type activityserve.RemoteActor has no field or method GetSharedInbox)
./database.go:2477:157: remoteActor.GetSharedInbox undefined (type activityserve.RemoteActor has no field or method GetSharedInbox)
routes.go Outdated
@@ -184,6 +184,7 @@ 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))

This comment has been minimized.

Copy link
@thebaer

thebaer Oct 10, 2019

Member

I believe we'll need to move this out of RouteCollections() -- on multi-user instances, this would put the route on every user, e.g. /matt/mention:{handle}

This comment has been minimized.

Copy link
@qwazix

qwazix Oct 11, 2019

Author

Done. I put that in initRoutes, is that the right place?

sqlite.sql Outdated
@@ -172,6 +172,7 @@ 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,

This comment has been minimized.

Copy link
@thebaer

thebaer Oct 10, 2019

Member

No need to add this to the schema files, as the migrations run on install and take care of this.

This comment has been minimized.

Copy link
@qwazix

qwazix Oct 11, 2019

Author

Reverted to previous

schema.sql Outdated
@@ -181,6 +181,7 @@ 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,

This comment has been minimized.

Copy link
@thebaer

thebaer Oct 10, 2019

Member

No need to add this to the schema files, as the migrations run on install and take care of this.

This comment has been minimized.

Copy link
@qwazix

qwazix Oct 11, 2019

Author

Reverted to previous

return nil
}

http.Redirect(w, r, remoteUser, http.StatusSeeOther)

This comment has been minimized.

Copy link
@thebaer

thebaer Oct 10, 2019

Member

We should use our common pattern of returning an impart.HTTPError instead of calling this method (for example):

return impart.HTTPError{http.StatusFound, redirectTo}

The handler.Web() method that wraps this takes care of the actual redirect.

This comment has been minimized.

Copy link
@qwazix
// could become a burden.

fmt.Println(tag.HRef)
fmt.Println("aaa")

This comment has been minimized.

Copy link
@thebaer

thebaer Oct 10, 2019

Member

Just need to clean these up (and the comment below)

@qwazix

This comment has been minimized.

Copy link
Author

commented Oct 10, 2019

Ack to all, will do.

@thebaer

This comment has been minimized.

Copy link
Member

commented Oct 10, 2019

Also, just saw the comments on the Mastodon issue. Is that fixed on our end?

@qwazix

This comment has been minimized.

Copy link
Author

commented Oct 10, 2019

Yes it works as expected, Gargron was right, I was thrown off because the first alias that webfinger returned was the @ version.

@thebaer thebaer added this to the 0.11 milestone Oct 10, 2019
@thebaer

This comment has been minimized.

Copy link
Member

commented Oct 10, 2019

Awesome -- works great with Mastodon 👍


Did some more testing and crashed the app with this post. Logs:

panic: interface conversion: interface {} is nil, not map[string]interface {}

goroutine 7763 [running]:
github.com/writeas/activityserve.NewRemoteActor(0xc0009a1860, 0x22, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, ...)
	/home/mattbaer/projects/go/src/github.com/writeas/activityserve/remoteActor.go:34 +0x41e
github.com/writeas/writefreely.(*datastore).getProfilePageFromHandle(0xc000687f00, 0xc000021ef0, 0xc000e20dcf, 0x15, 0xc000e6ee60, 0x2, 0xa, 0xc0009a0570)
	/home/mattbaer/projects/go/src/github.com/writeas/writefreely/database.go:2472 +0x11a
github.com/writeas/writefreely.(*PublicPost).ActivityObject(0xc00059e540, 0xc000021ef0, 0x1)
	/home/mattbaer/projects/go/src/github.com/writeas/writefreely/posts.go:1120 +0xc67
github.com/writeas/writefreely.federatePost(0xc000021ef0, 0xc00059e540, 0x65, 0x2cd9a00, 0x0, 0x0)
	/home/mattbaer/projects/go/src/github.com/writeas/writefreely/activitypub.go:574 +0xf6
created by github.com/writeas/writefreely.newPost
	/home/mattbaer/projects/go/src/github.com/writeas/writefreely/posts.go:593 +0x792
@qwazix

This comment has been minimized.

Copy link
Author

commented Oct 11, 2019

The crash was due to prismo and pixelfed not having sharedInboxes. I made GetSharedInbox() to return the inbox of the user so implementation won't need to care whether there is a sharedInbox or not (this is in activityserve)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.