this post was submitted on 15 Feb 2024
11 points (92.3% liked)

Learning Rust and Lemmy

372 readers
1 users here now

Welcome

A collaborative space for people to work together on learning Rust, learning about the Lemmy code base, discussing whatever confusions or difficulties we're having in these endeavours, and solving problems, including, hopefully, some contributions back to the Lemmy code base.

Rules TL;DR: Be nice, constructive, and focus on learning and working together on understanding Rust and Lemmy.


Running Projects


Policies and Purposes

  1. This is a place to learn and work together.
  2. Questions and curiosity is welcome and encouraged.
  3. This isn't a technical support community. Those with technical knowledge and experienced aren't obliged to help, though such is very welcome. This is closer to a library of study groups than stackoverflow. Though, forming a repository of useful information would be a good side effect.
  4. This isn't an issue tracker for Lemmy (or Rust) or a place for suggestions. Instead, it's where the nature of an issue, what possible solutions might exist and how they could be or were implemented can be discussed, or, where the means by which a particular suggestion could be implemented is discussed.

See also:

Rules

  1. Lemmy.ml rule 2 applies strongly: "Be respectful, even when disagreeing. Everyone should feel welcome" (see Dessalines's post). This is a constructive space.
  2. Don't demean, intimidate or do anything that isn't constructive and encouraging to anyone trying to learn or understand. People should feel free to ask questions, be curious, and fill their gaps knowledge and understanding.
  3. Posts and comments should be (more or less) within scope (on which see Policies and Purposes above).
  4. See the Lemmy Code of Conduct
  5. Where applicable, rules should be interpreted in light of the Policies and Purposes.

Relevant links and Related Communities


Thumbnail and banner generated by ChatGPT.

founded 7 months ago
MODERATORS
11
submitted 7 months ago* (last edited 7 months ago) by [email protected] to c/[email protected]
 

I'll reply in the comments with a example of what lemmy sends for each thing you can do (I think I've thought of everything, but you can probably guess the format if not, or I can always add it).

So, the setup for these is:
Our instance is called 'local.com'
Our user is called 'freamon'
The other instance is called 'remote.com'
The community on that instance is called 'interesting'

For many of these, remote.com will receive them, and rewraps them in an Announce to send out to all the other instances with a copy of the community, so everyone stays in sync.

Sort by 'Old' for the best hope of these making sense.
I'll follow this post up with a script, that can be used to send these activities from the command-line, as I think it can help to understand Lemmy if you're using something much simpler than Lemmy to do some of things Lemmy does.

EDIT: As nutomic as mentioned, a better list is in the docs. It's the kind of thing I should read first, I guess.

top 26 comments
sorted by: hot top controversial new old
[–] [email protected] 7 points 7 months ago (2 children)
[–] [email protected] 3 points 7 months ago (1 children)

Yea but repetition legitimises! (A reference/joke BTW)

Seriously though @[email protected] , how are you deriving all of these? From theoretical understanding of what should happen or actual observations of a test system?

[–] [email protected] 4 points 7 months ago (1 children)

Observation, mostly. Also guesswork and trial-and-error, because I never realised these were all in the docs.

The comments in here are from me running lemmy in a VM, and subscribing to a fake community on a VPS (you can mimic a community with a webfinger response and a bunch of static files). The activities sent by lemmy just went to a basic server, that dumped out the JSON files it received.

I mostly made this post so I could point to something when posting about a Ruby script that can be used to interact with lemmy from the command line. This provides the opportunity to learn about ActivityPub, separate from the more complicated applications that currently implement it.

[–] [email protected] 3 points 7 months ago (1 children)

Cool. So you’re writing a CLI of some sort for ActivityPub/lemmy interaction?

[–] [email protected] 3 points 7 months ago (1 children)

Hmmm. Nothing sophisticated, but I am replying to you right now from the command-line

[–] [email protected] 2 points 7 months ago

Very nice!

How many terminal fediverse clients are there?

[–] [email protected] 5 points 7 months ago (1 children)

Oh. I feel daft now. That's some nice, comprehensive documentation, that I hadn't seen before. I'll edit this post to point to it, and I guess people can maybe use it if they want to comment about a particular activity.

[–] [email protected] 6 points 7 months ago

Its also good to explore for yourself. Maybe you notice something missing/outdated in the documentation and can fix it. The docs are generated from these files which are also used in the unit tests.

[–] [email protected] 1 points 7 months ago* (last edited 7 months ago)

For an example of an Announce encapsulating these, I'll use this post. The format is always the same from what I've seen (the 'context' is moved to the top level, and the original activity is placed inside as an 'object').

curl --header 'accept: application/activity+json' https://lemmy.ml/c/learningrustandlemmy/outbox | jq .orderedItems[3]

{
  "actor": "https://lemmy.ml/c/learningrustandlemmy",
  "to": [
    "https://www.w3.org/ns/activitystreams#Public"
  ],
  "object": {
    "id": "https://lemmy.ml/activities/create/191df452-33a6-4861-8218-6f1702f39fe3",
    "actor": "https://endlesstalk.org/u/freamon",
    "to": [
      "https://www.w3.org/ns/activitystreams#Public"
    ],
    "object": {
      "type": "Page",
      "id": "https://endlesstalk.org/post/22923810",
      "attributedTo": "https://endlesstalk.org/u/freamon",
      "to": [
        "https://lemmy.ml/c/learningrustandlemmy",
        "https://www.w3.org/ns/activitystreams#Public"
      ],
      "name": "Lemmy's ActivityPub activities",
      "cc": [],
      "content": "<p>I’ll reply in the comments with a example of what lemmy sends for each thing you can do (I think I’ve t                                                                                                                                     hought of everything, but you can probably guess the format if not, or I can always add it).</p>\n<p>So, the setup for these                                                                                                                                      is:<br />\nOur instance is called ‘local.com’<br />\nOur user is called ‘freamon’<br />\nThe other instance is called ‘remo                                                                                                                                     te.com’<br />\nThe community on that instance is called ‘interesting’</p>\n<p>For many of these, remote.com will receive the                                                                                                                                     m, and rewraps them in an Announce to send out to all the other instances with a copy of the community, so everyone stays in                                                                                                                                      sync.</p>\n",
      "mediaType": "text/html",
      "source": {
        "content": "I'll reply in the comments with a example of what lemmy sends for each thing you can do (I think I've th                                                                                                                                     ought of everything, but you can probably guess the format if not, or I can always add it).\n\nSo, the setup for these is:                                                                                                                                          \nOur instance is called 'local.com'          \nOur user is called 'freamon'         \nThe other instance is called 'remo                                                                                                                                     te.com'     \nThe community on that instance is called 'interesting'          \n\nFor many of these, remote.com will receive                                                                                                                                      them, and rewraps them in an Announce to send out to all the other instances with a copy of the community, so everyone stay                                                                                                                                     s in sync.\n",
        "mediaType": "text/markdown"
      },
      "attachment": [],
      "commentsEnabled": true,
      "sensitive": false,
      "published": "2024-02-15T12:08:08.036884Z",
      "updated": "2024-02-15T12:42:34.861055Z",
      "language": {
        "identifier": "en",
        "name": "English"
      },
      "audience": "https://lemmy.ml/c/learningrustandlemmy"
    },
    "cc": [
      "https://lemmy.ml/c/learningrustandlemmy"
    ],
    "type": "Create",
    "audience": "https://lemmy.ml/c/learningrustandlemmy"
  },
  "cc": [
    "https://lemmy.ml/c/learningrustandlemmy/followers"
  ],
  "type": "Announce",
  "id": "https://lemmy.ml/activities/announce/create/6689f68f-1fc4-44d2-9d0a-0e200d469e48"
}
[–] [email protected] 1 points 7 months ago (6 children)

The community mod at remote.com decides to make freamon a moderator

{
  "@context": "https://www.w3.org/ns/activitystreams",
  "actor": "https://remote.com/u/mod",
  "to": "https://www.w3.org/ns/activitystreams#Public",
  "object": "https://local.com/u/freamon",
  "target": "https://remote.com/c/interesting/moderators",
  "cc": "https://remote.com/c/interesting",
  "type": "Add",
  "id": "https://remote.com/activities/add/390751ec-9b21-4585-875f-2fb088c69c5a",
  "audience": "https://remote.com/c/interesting"
}

Replies to this comment are all moderator actions.

[–] [email protected] 1 points 7 months ago

freamon deletes the community from the local server

{
  "@context": [
    "https://join-lemmy.org/context.json",
    "https://www.w3.org/ns/activitystreams"
  ],
  "id": "https://local.com/activities/delete/a41b378b-fff8-45ae-80cd-ac923d4d7071",
  "actor": "https://local.com/u/freamon",
  "to": [
    "https://www.w3.org/ns/activitystreams#Public"
  ],
  "object": "https://remote.com/c/interesting",
  "type": "Delete",
  "audience": "https://remote.com/c/interesting",
  "cc": [
    "https://remote.com/c/interesting"
  ]
}
[–] [email protected] 1 points 7 months ago

freamon leaves the mod team

{
  "@context": [
    "https://join-lemmy.org/context.json",
    "https://www.w3.org/ns/activitystreams"
  ],
  "id": "https://local.com/activities/remove/535ac463-e306-48d1-9984-32d460b90e35",
  "actor": "https://local.com/u/freamon",
  "to": [
    "https://www.w3.org/ns/activitystreams#Public"
  ],
  "object": "https://local.com/u/freamon",
  "cc": [
    "https://remote.com/c/interesting"
  ],
  "type": "Remove",
  "target": "https://remote.com/c/interesting/moderators",
  "audience": "https://remote.com/c/interesting"
}
[–] [email protected] 1 points 7 months ago

A bad guy has joined and posted weird stuff. freamon bans him, and removes his content

{
  "@context": [
    "https://join-lemmy.org/context.json",
    "https://www.w3.org/ns/activitystreams"
  ],
  "id": "https://local.com/activities/block/ff2c17e1-cab6-48a5-9615-380c929ca268",
  "actor": "https://local.com/u/freamon",
  "to": [
    "https://www.w3.org/ns/activitystreams#Public"
  ],
  "object": "https://local.com/u/bad_guy",
  "cc": [
    "https://remote.com/c/interesting"
  ],
  "target": "https://remote.com/c/interesting",
  "type": "Block",
  "audience": "https://remote.com/c/interesting",
  "removeData": true,
  "summary": "Terrible Person"
}
[–] [email protected] 1 points 7 months ago (1 children)

As a moderator, freamon decides to remove a post

{
  "@context": [
    "https://join-lemmy.org/context.json",
    "https://www.w3.org/ns/activitystreams"
  ],
  "id": "https://local.com/activities/delete/2de802ce-f032-4327-985b-4078bc7fe2c5",
  "actor": "https://local.com/u/freamon",
  "to": [
    "https://www.w3.org/ns/activitystreams#Public"
  ],
  "object": "https://local.com/post/3",
  "type": "Delete",
  "audience": "https://remote.com/c/interesting",
  "cc": [
    "https://remote.com/c/interesting"
  ],
  "summary": "Post was bad."
}
[–] [email protected] 1 points 7 months ago

freamon changes his mind, and restores the post

{
  "@context": [
    "https://join-lemmy.org/context.json",
    "https://www.w3.org/ns/activitystreams"
  ],
  "id": "https://local.com/activities/undo/d9fb7304-74f2-4724-8c45-1871054ae334",
  "actor": "https://local.com/u/freamon",
  "to": [
    "https://www.w3.org/ns/activitystreams#Public"
  ],
  "object": {
    "actor": "https://local.com/u/freamon",
    "to": [
      "https://www.w3.org/ns/activitystreams#Public"
    ],
    "object": "https://local.com/post/3",
    "type": "Delete",
    "id": "https://local.com/activities/delete/11c44e39-e2b9-4649-b3ee-f8c602075f89",
    "audience": "https://remote.com/c/interesting",
    "cc": [
      "https://remote.com/c/interesting"
    ],
    "summary": "Post was actually Good"
  },
  "type": "Undo",
  "audience": "https://remote.com/c/interesting",
  "cc": [
    "https://remote.com/c/interesting"
  ]
}
[–] [email protected] 1 points 7 months ago

freamon likes his own post so much he stickies it, to feature it in the community

{
  "@context": [
    "https://join-lemmy.org/context.json",
    "https://www.w3.org/ns/activitystreams"
  ],
  "id": "https://local.com/activities/add/aaa2adb4-43b8-4c90-a734-5c108cedf420",
  "actor": "https://local.com/u/freamon",
  "to": [
    "https://www.w3.org/ns/activitystreams#Public"
  ],
  "object": "https://local.com/post/3",
  "target": "https://remote.com/c/interesting/featured",
  "cc": [
    "https://remote.com/c/interesting"
  ],
  "type": "Add",
  "audience": "https://remote.com/c/interesting"
}

Note: /c/interesting/featured is more for mastodon's benefit, I think.

[–] [email protected] 1 points 7 months ago

freamon uses his new-found powers to edit the sidebar

{
  "@context": [
    "https://join-lemmy.org/context.json",
    "https://www.w3.org/ns/activitystreams"
  ],
  "id": "https://local.com/activities/update/20f7397d-f124-45aa-a1b2-b8366c17f6db",
  "actor": "https://local.com/u/freamon",
  "to": [
    "https://www.w3.org/ns/activitystreams#Public"
  ],
  "object": {
    "type": "Group",
    "id": "https://remote.com/c/interesting",
    "preferredUsername": "interesting",
    "inbox": "https://remote.com/c/interesting/inbox",
    "followers": "https://remote.com/c/interesting/followers",
    "publicKey": {
      "id": "https://remote.com/c/interesting#main-key",
      "owner": "https://remote.com/c/interesting",
      "publicKeyPem": "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAovFqf5abQp7EpeiwTku9\nUkp5nzFIk6ny/89hfMOrZigJR5RUG44J+TFnT8mHompvViDSQXP4qwJ8bVqQySpU\nIXzm4pKy1ykmuh+Ez0yS3/VaUHLYYi8vXhq5yMc70lIBsZ36KnBspFQBNW7ToHMI\nJia9du/2shxq1huApgpUFbVq/I4FLHQSKYVStCxWkJhTakNxvBLvVBroFF8Izwur\n/d79mTV40scCJX/HkgFqlxFYmmrc1/M2P2Ci3VS5u0oebBHwivvm6QTOVCHIIIgc\n7JM1eo/TdJ0QNkSE6YqSAEbSF1M1KODUPmfvyVrOuUCNJ2V64anD2b6tWCIyHlDN\nvwIDAQAB\n-----END PUBLIC KEY-----\n"
    },
    "name": "An Interesting Community",
    "summary": "<h4>An interesting community</h4>\n",
    "source": {
      "content": "#### An interesting community",
      "mediaType": "text/markdown"
    },
    "sensitive": false,
    "attributedTo": "https://remote.com/c/interesting/moderators",
    "postingRestrictedToMods": false,
    "outbox": "https://remote.com/c/interesting/outbox",
    "endpoints": {
      "sharedInbox": "https://remote.com/inbox"
    },
    "featured": "https://remote.com/c/interesting/featured",
    "language": [
      {
        "identifier": "und",
        "name": "Undetermined"
      },
      {
        "identifier": "en",
        "name": "English"
      }
    ],
    "published": "2024-01-01T17:22:16Z",
    "updated": "2024-02-13T22:05:25.819020Z"
  },
  "cc": [
    "https://remote.com/c/interesting"
  ],
  "type": "Update",
  "audience": "https://remote.com/c/interesting"
}
[–] [email protected] 1 points 7 months ago (1 children)

freamon replies to his own post, with an inline link to the same image, and an emoji

{
  "@context": [
    "https://join-lemmy.org/context.json",
    "https://www.w3.org/ns/activitystreams"
  ],
  "id": "https://local.com/activities/create/c394a258-eac5-4555-8b98-823002cbb88c",
  "actor": "https://local.com/u/freamon",
  "to": [
    "https://www.w3.org/ns/activitystreams#Public"
  ],
  "object": {
    "type": "Note",
    "id": "https://local.com/comment/1",
    "attributedTo": "https://local.com/u/freamon",
    "to": [
      "https://www.w3.org/ns/activitystreams#Public"
    ],
    "cc": [
      "https://remote.com/c/interesting",
      "https://local.com/u/freamon"
    ],
    "content": "<p>Comment text<br />\n<img src=\"https://i.imgur.com/T7Z3vUU.jpeg\" alt=\"\" /></p>\n<p>😜</p>\n",
    "inReplyTo": "https://local.com/post/3",
    "mediaType": "text/html",
    "source": {
      "content": "Comment text              \n![](https://i.imgur.com/T7Z3vUU.jpeg)\n\n 😜 ",
      "mediaType": "text/markdown"
    },
    "published": "2024-02-13T21:48:18.776300Z",
    "tag": [
      {
        "href": "https://local.com/u/freamon",
        "name": "@[email protected]",
        "type": "Mention"
      }
    ],
    "distinguished": false,
    "audience": "https://remote.com/c/interesting"
  },
  "cc": [
    "https://remote.com/c/interesting",
    "https://local.com/u/freamon"
  ],
  "tag": [
    {
      "href": "https://local.com/u/freamon",
      "name": "@[email protected]",
      "type": "Mention"
    }
  ],
  "type": "Create",
  "audience": "https://remote.com/c/interesting"
}

Note 1: lemmy uses 'Page' for a post, and 'Note' for a comment, whereas mastodon uses 'Note' for both, with 'inReplyTo' distinguishing between the two.
Note 2: this is sent to the main community at remote.com, and also to the post's author (it would appear in his inbox if they weren't the same person)

[–] [email protected] 1 points 7 months ago (1 children)

freamon regrets his comment, and deletes it.

{
  "@context": [
    "https://join-lemmy.org/context.json",
    "https://www.w3.org/ns/activitystreams"
  ],
  "id": "https://local.com/activities/delete/c08be088-fd16-47fe-a286-3e0c24abc15b",
  "actor": "https://local.com/u/freamon",
  "to": [
    "https://www.w3.org/ns/activitystreams#Public"
  ],
  "object": "https://local.com/comment/1",
  "type": "Delete",
  "audience": "https://remote.com/c/interesting",
  "cc": [
    "https://remote.com/c/interesting"
  ]
}
[–] [email protected] 1 points 7 months ago

freamon changes his mind again, and undoes the delete

{
  "@context": [
    "https://join-lemmy.org/context.json",
    "https://www.w3.org/ns/activitystreams"
  ],
  "id": "https://local.com/activities/undo/91bd96a3-9fb8-4dde-acfb-3d7ee682a41a",
  "actor": "https://local.com/u/freamon",
  "to": [
    "https://www.w3.org/ns/activitystreams#Public"
  ],
  "object": {
    "actor": "https://local.com/u/freamon",
    "to": [
      "https://www.w3.org/ns/activitystreams#Public"
    ],
    "object": "https://local.com/comment/1",
    "type": "Delete",
    "id": "https://local.com/activities/delete/55f2f17e-6c5d-44f2-ae53-e65c8496dfc3",
    "audience": "https://remote.com/c/interesting",
    "cc": [
      "https://remote.com/c/interesting"
    ]
  },
  "type": "Undo",
  "audience": "https://remote.com/c/interesting",
  "cc": [
    "https://remote.com/c/interesting"
  ]
}
[–] [email protected] 1 points 7 months ago

freamon creates a post in the interesting community. He adds a title, a body, links to an image, and tags it as in English.

{
  "@context": [
    "https://join-lemmy.org/context.json",
    "https://www.w3.org/ns/activitystreams"
  ],
  "id": "https://local.com/activities/create/37f46c10-9fc2-4228-b8ea-3803eb911485",
  "actor": "https://local.com/u/freamon",
  "to": [
    "https://www.w3.org/ns/activitystreams#Public"
  ],
  "object": {
    "type": "Page",
    "id": "https://local.com/post/3",
    "attributedTo": "https://local.com/u/freamon",
    "to": [
      "https://remote.com/c/interesting",
      "https://www.w3.org/ns/activitystreams#Public"
    ],
    "name": "Title Text",
    "cc": [],
    "content": "<p>Body Text</p>\n",
    "mediaType": "text/html",
    "source": {
      "content": "Body Text",
      "mediaType": "text/markdown"
    },
    "attachment": [
      {
        "href": "https://i.imgur.com/T7Z3vUU.jpeg",
        "type": "Link"
      }
    ],
    "commentsEnabled": true,
    "sensitive": false,
    "published": "2024-02-13T21:46:05.705099Z",
    "language": {
      "identifier": "en",
      "name": "English"
    },
    "audience": "https://remote.com/c/interesting"
  },
  "cc": [
    "https://remote.com/c/interesting"
  ],
  "type": "Create",
  "audience": "https://remote.com/c/interesting"
}
[–] [email protected] 1 points 7 months ago (1 children)

The interesting community came with 2 posts. freamon upvotes post 1, and downvotes post 2

{
  "@context": [
    "https://join-lemmy.org/context.json",
    "https://www.w3.org/ns/activitystreams"
  ],
  "id": "https://local.com/activities/like/16e6a46e-b80b-4d13-8258-2f724c53ed1c",
  "actor": "https://local.com/u/freamon",
  "object": "https://remote.com/post/1",
  "type": "Like",
  "audience": "https://remote.com/c/interesting"
}
{
  "@context": [
    "https://join-lemmy.org/context.json",
    "https://www.w3.org/ns/activitystreams"
  ],
  "id": "https://local.com/activities/dislike/576f119f-5aa5-4f5e-ba48-a79b26f0fae3",
  "actor": "https://local.com/u/freamon",
  "object": "https://remote.com/post/2",
  "type": "Dislike",
  "audience": "https://remote.com/c/interesting"
}
[–] [email protected] 1 points 7 months ago

freamon changes his mind about post 2, and undoes his downvote

{
  "@context": [
    "https://join-lemmy.org/context.json",
    "https://www.w3.org/ns/activitystreams"
  ],
  "id": "https://local.com/activities/undo/e677b1ba-caaf-4a2f-9472-681705f337a3",
  "actor": "https://local.com/u/freamon",
  "object": {
    "actor": "https://local.com/u/freamon",
    "object": "https://remote.com/post/2",
    "type": "Like",
    "id": "https://local.com/activities/like/70edfad8-dcbb-42cd-8fd2-f674844b8801",
    "audience": "https://remote.com/c/interesting"
  },
  "type": "Undo",
  "audience": "https://remote.com/c/interesting"
}

Note: due the expection of unique 'id' fields, the encapsulated object isn't the same, so this is probably best read as 'undo vote'

[–] [email protected] 1 points 7 months ago (2 children)

freamon subscribes to the interesting community
The subscription status changes to 'pending'

{
  "@context": [
    "https://join-lemmy.org/context.json",
    "https://www.w3.org/ns/activitystreams"
  ],
  "actor": "https://local.com/u/freamon",
  "to": [
    "https://remote.com/c/interesting"
  ],
  "object": "https://remote.com/c/interesting",
  "type": "Follow",
  "id": "https://local.com/activities/follow/5cc358b8-9eae-49ef-8b5c-05d98504bda1"
}
[–] [email protected] 1 points 7 months ago

freamon changes his mind. He doesn't want to subscribe anymore

{
  "@context": [
    "https://join-lemmy.org/context.json",
    "https://www.w3.org/ns/activitystreams"
  ],
  "actor": "https://local.com/u/freamon",
  "to": [
    "https://remote.com/c/interesting"
  ],
  "object": {
    "actor": "https://local.com/u/freamon",
    "to": [
      "https://remote.com/c/interesting"
    ],
    "object": "https://remote.com/c/interesting",
    "type": "Follow",
    "id": "https://local.com/activities/follow/c934a27e-0dad-4641-85f5-a83e04d672a4"
  },
  "type": "Undo",
  "id": "https://local.com/activities/undo/a9047cfc-ed0e-49c2-86da-9a0b3dbdc463"
}

Note 1: lemmy expects these 'id' fields to be unique, so the encapulated 'Follow' isn't the same as the one that was sent.
Note 2: lemmy also sends a Undo/Follow if you block a community

[–] [email protected] 1 points 7 months ago

The interesting community accepts freamon's subscription request
The subscription status changes to 'joined'

{
  "actor": "https://remote.com/c/interesting",
  "to": "https://local.com/u/freamon",
  "object": {
    "actor": "https://local.com/u/freamon",
    "to": null,
    "object": "https://remote.com/c/interesting",
    "type": "Follow",
    "id": "https://local.com/activities/follow/c66515bd-6f81-44e0-8af9-c4c4ae307051"
  },
  "type": "Accept",
  "id": "https://remote.com/activities/accept/4ca771e6-0213-478a-83ba-d957984b98c5"
}