For example, if you’re trying to figure out if a blog is mentioned, you look up the id of the blog in the tag array to see if a Mention tag exists for that blog.
It seems like you know this already, so I’m not sure I understand what you’re looking to accomplish.
The Note I receive is a command to my bot, where the order of mentions is significant, and I was attempting to use the structured activitypub object as a shortcut to get at the mentions. However the arrays don’t necessarily retain the order of the mentions as present in the content, in my testing. I am realizing now that this isn’t a solvable problem because the note content isn’t obligated to contain a textual representation of mentions either and the field is by definition unstructured. The answer is parse the Note content to the best of your ability and accept there will be failures sometimes.
This isn’t directly an activitypub question, I should have put this post under the programming subforum. apologies.
If the order of mentions is significant to you, then you can use the url or id of the ActivityPub actor to associate them with any appropriate textual content as follows:
If you resolve the Actor for the user https://mastodon.social/users/photomatt, you’ll see that it has the url property https://mastodon.social/@photomatt. That URL property will be in the HTML document. Some implementations use the id property instead, mostly ones that don’t have a url property.
So the logic would be something like:
Get list of users with a Mention tag
Create a map from url → user and id → user.
(e.g. const urlMap = Object.fromEntries(mentionedUsers.flatMap(user => [[user.id, user], [user.url, user]]);)
Process the HTML in whatever way you wish
When you come across an a tag, you can look up the href of the a tag to figure out which user is being referenced.