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

Allow creating posts #33

Closed
swentel opened this issue Oct 14, 2018 · 26 comments
Closed

Allow creating posts #33

swentel opened this issue Oct 14, 2018 · 26 comments

Comments

@swentel
Copy link
Contributor

swentel commented Oct 14, 2018

So replies work now, awesome!

A post is more or less the same as a reply with these differences:

  • it does not contain the 'inReplyTo' property
  • to should contain public, and the followers url , e.g. something like accounts/363584/followers (although I'm not 100% of the last part here)
  • (instance) url: this is the tricky part, but I presume it's safe to target mastodon.social by default and use the shared inbox.

another tricky part: fed bridgy doesn't really care to which federated service you want to post on. It could be diaspora or something else in the future too, so either

I will do some tests and see what the minimum object should be.

@snarfed
Copy link
Owner

snarfed commented Oct 14, 2018

heh. the difficulty here is definitely where to deliver to, since bridgy fed is only a proxy. it doesn't actually know where a user's followers are.

the current design is that followers' instances subscribe to user's atom feeds, OStatus style, with optional WebSub notifications. this obviously had problems, #18 etc.

AP inbox delivery would be great, but i still don't quite see how yet. hard coding mastodon.social doesn't seem right. manually including all followers in every post doesn't either.

@swentel
Copy link
Contributor Author

swentel commented Oct 15, 2018

Yeah, this is indeed a tricky one. So possibly a very stupid question: my atom feed (https://realize.be/fediverse.xml) uses https://bridgy-fed.superfeedr.com/ as the hub - I'm good at following setups heh. When I post something new, do I have to send a call to that hub to notify it exists ? I admit, I'm not entirely familiar with this hub and websub thing :/

If I understand it better, I can experiment more and have a better clue what to search for in mastodon's code :)

@snarfed
Copy link
Owner

snarfed commented Oct 15, 2018

@swentel heh, you're discovering all the embarrassing rough parts of bridgy fed.

i don't think https://bridgy-fed.superfeedr.com/ actually does anything right now 😆. when i first tested with mastodon - before activitypub - its ostatus required a websub hub in the atom feed, so i registered with superfeedr and pointed people there. i don't actually know much about websub, or whether or how the hub matters to mastodon. sorry!

@swentel
Copy link
Contributor Author

swentel commented Oct 15, 2018

Ah no problem at all :)

Mastodon stores the hub, so I'll dig in and see if I can come up with something!

@snarfed
Copy link
Owner

snarfed commented Oct 17, 2018

@aaronpk recently open sourced his site's AP code! https://github.com/aaronpk/Nautilus . he does what we've discussed doing: store every user's followers and send new posts to their instances over AP. i was hoping to avoid that, since mastodon supposedly supports atom + websub, but in practice they've been difficult enough that maybe we should just plan to store followers and go full AP ourselves too.

@swentel
Copy link
Contributor Author

swentel commented Oct 17, 2018

I'm looking into the atom + websub stuff now. Hopefully I can report back positive :)

@swentel
Copy link
Contributor Author

swentel commented Oct 22, 2018

This is the minimal object I've send to post a 'toot'. It showed up in the home timeline of my swentel mastodon user, even though I didn't cc that user, or followers or so, but not sure if that's something we can rely on. Posted to the shared inbox of mastodon.social. However bottom line, it's like a reply, but without inReplyTo ... that is the easy part :)

stdClass Object
(
    [type] => Create
    [@context] => https://www.w3.org/ns/activitystreams
    [actor] => https://fed.brid.gy/r/http://realize.be
    [object] => Array
        (
            [type] => Note
            [to] => Array
                (
                    [0] => https://www.w3.org/ns/activitystreams#Public
                )

            [id] => https://fed.brid.gy/r/http://realize.be/notes/1582
            [content] => I will be giving a session at @drupalcampbe about #indieweb ! A gentle 101 intro about the mission, specs and what the #drupal module already supports. Spoiler: a lot!
            [published] => 2018-10-22T14:14:39Z
        )

)

@swentel
Copy link
Contributor Author

swentel commented Oct 22, 2018

Dit another one with https://mastodon.technology/@snarfed in the to array. The post is The #indieweb module for #drupal is now in beta! Some smaller things can still go in, but what's left for a 1.0 release is a decent security review, anyone up for that ? :) Posted to the shared inbox of mastodon.social - crossing fingers it shows up there :)

@snarfed
Copy link
Owner

snarfed commented Oct 22, 2018

@swentel agreed! you've probably already looked at them, but just in case, you may be interested in https://www.w3.org/TR/activitypub/#shared-inbox-delivery and other parts of the spec.

snarfed added a commit that referenced this issue Nov 13, 2018
snarfed added a commit that referenced this issue Nov 16, 2018
snarfed added a commit that referenced this issue Nov 20, 2018
…bject

we don't create these any more, we always fetch and store full actor objects, but we have a few old ones lying around in the prod datastore.

for #33
@snarfed
Copy link
Owner

snarfed commented Nov 20, 2018

woo, this is working for original posts! example: https://mastodon.technology/web/statuses/101104510742043648 . (original post: https://snarfed.org/2018-11-10_30370 )

lots of polish remaining, of course. still, feel free to try if you want, @swentel!

@swentel
Copy link
Contributor Author

swentel commented Nov 20, 2018

WOW! I WILL :)

(I have an article ready on my blog to promote this too, I'll publish that even if one post works !)

@swentel
Copy link
Contributor Author

swentel commented Nov 20, 2018

I've send a webmention for https://realize.be/notes/1638 - but not seeing anything in the logs of bridgy fed. Don't see an error on my end either, it even stores it as a 'send item' (Drupal specific implementation). Markup seems ok too. So not sure what goes wrong :)

@snarfed
Copy link
Owner

snarfed commented Nov 20, 2018

oops, thanks for the report! fixed, i think. i retried, but looks like you've deleted https://realize.be/notes/1638 .

@swentel
Copy link
Contributor Author

swentel commented Nov 20, 2018

@snarfed
Copy link
Owner

snarfed commented Nov 20, 2018

yay! congrats! and oh wow, funny, that mastodon.social link literally redirects to your original post. federation indeed. 😎

@swentel
Copy link
Contributor Author

swentel commented Nov 20, 2018

Yes, that link only works in the UI of Mastodon, but that's totally fine.

Did a test with https://realize.be/image/falling-leaves - which has an image, but that hasn't come through yet. This might call for a local debugging session :)

One other question (might be off topic and rather a follow-up). Does fed bridgy handle p-summary or something like 'p-bridgy-twitter-content'. According to @EdwardHinkle It seems 'p-summary' becomes a content warning in Mastodon. Ignore, see underneath

@swentel
Copy link
Contributor Author

swentel commented Nov 20, 2018

Ok regarding images. There might be two things:

screenshot from 2018-11-20 20-05-43

Note - can also be a follow up, I can do some local testing and see what the format needs to be, I like figuring out those things :)

@swentel
Copy link
Contributor Author

swentel commented Nov 20, 2018

As for p-summary - that works great - see https://mastodon.social/web/statuses/101105193204982078
It shows exactly which was in my summary, although the article is WAY longer. There's still a 'show more' button .. but I make sure the URL is in the summary too. One rule that could potentially be implemented is that content is send empty if there's a summary. However, some instances of mastodon allow larger posts, and who knows for other platforms out there, so this is fine! :)

@snarfed
Copy link
Owner

snarfed commented Nov 21, 2018

@swentel
Copy link
Contributor Author

swentel commented Nov 21, 2018

i'm curious about your post with an image. the image shows up in the mastodon post?

No, the image doesn't show up. Only the url to the post itself. And about five minutes later, some sort of embed card appeared too, but it just links to the same original url. Looking at the logs, the image is found, so I think discovery is fine. It's mastodon that just doesn't like it right now. Maybe we should check with aaron if he does something specific with u-photo or not.

@swentel
Copy link
Contributor Author

swentel commented Nov 21, 2018

Skimming through mastodons code, looks like images should be inside an 'attachments' property.
Not sure if that is specifically Mastodon or AP though.

@snarfed
Copy link
Owner

snarfed commented Nov 21, 2018

yeah searching https://www.w3.org/TR/activitypub/ for image, attachment, and photo doesn't turn up anything useful. AP may defer it to AS2 and individual implementations. maybe we just do what works for Mastodon (and maybe soon PixelFed) for now.

@swentel
Copy link
Contributor Author

swentel commented Nov 22, 2018

I was able to create a post with an image. Attachment is an array of arrays. The url is mandatory, name and focalPoint are optional. See https://mastodon.social/web/statuses/101114062630255773

I also tested with sending no content property and an attachment and that works fine too, so content isn't mandatory in case there are valid attachments.

stdClass Object
(
    [@context] => https://www.w3.org/ns/activitystreams
    [type] => Create
    [actor] => https://fed.brid.gy/r/http://realize.be
    [to] => Array
        (
            [0] => https://www.w3.org/ns/activitystreams#Public
            [1] => https://mastodon.social/users/swentel
        )

    [object] => stdClass Object
        (
            [id] => https://fed.brid.gy/r/http://realize.be/image/flying
            [type] => Note
            [published] => 2018-11-22T09:15:51Z
            [content] => Flying
            [attachment] => Array
                (
                    [0] => Array
                        (
                            [url] => https://realize.be/sites/default/files/styles/bigger/public/1533491412541.jpg?itok=rPTwkt2X
                        )

                )

            [to] => Array
                (
                    [0] => https://www.w3.org/ns/activitystreams#Public
                    [1] => https://mastodon.social/users/swentel
                )

        )
)

screenshot from 2018-11-22 10-19-29

For reference, the code from mastodon (app/lib/activitypub/activity/create.rb)

    as_array(@object['attachment']).each do |attachment|
      next if attachment['url'].blank?

      href             = Addressable::URI.parse(attachment['url']).normalize.to_s
      media_attachment = MediaAttachment.create(account: @account, remote_url: href, description: attachment['name'].presence, focus: attachment['focalPoint'])
      media_attachments << media_attachment

      next if unsupported_media_type?(attachment['mediaType']) || skip_download?

      media_attachment.file_remote_url = href
      media_attachment.save
    end

@snarfed
Copy link
Owner

snarfed commented Nov 22, 2018

woo, that's great! thanks again. i'll incorporate that.

@snarfed
Copy link
Owner

snarfed commented Nov 24, 2018

done! example: https://mastodon.technology/web/statuses/101124703242866136

image

i think all that's left to do here is update the docs.

@swentel
Copy link
Contributor Author

swentel commented Nov 24, 2018

Yes, works great!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants