forked from fedify-dev/hollo
-
Notifications
You must be signed in to change notification settings - Fork 0
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
Update outbox format #19
Merged
Merged
Changes from all commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
a2c8b4d
Enhance post serialization with ActivityStreams format and update Pos…
0marSalah 44d5805
Refactor importOutbox method to handle ActivityStreams format and imp…
0marSalah 513ed9a
Simplify outbox URL in AccountExporter by using a static string
0marSalah 90bf081
Implement outbox generation and fetching for ActivityStreams in Accou…
0marSalah d7dd978
Add logging to fetchOutbox and clean up commented code in AccountExpo…
0marSalah 2e523a7
Refactor generateOutbox to simplify orderedItems mapping and improve …
0marSalah eeeb885
Enhance generateOutbox to include detailed logging and improve ordere…
0marSalah efcf4d9
Refactor fetchOutbox to improve item retrieval and add logging for be…
0marSalah b3d2634
Refactor fetchOutbox to use for-await loop for item retrieval and imp…
0marSalah 45221f5
Refactor fetchOutbox to use iterateCollection for item retrieval and …
0marSalah 69178cd
Refactor generateOutbox to enhance orderedItems mapping and improve o…
0marSalah 79b5fbd
Refactor generateOutbox to change object type to 'OrderedCollection' …
0marSalah 1bc88ef
Refactor generateOutbox to enhance object mapping and improve handlin…
0marSalah 75bc7d8
Refactor generateOutbox to improve object logging and ensure full obj…
0marSalah 567afc0
Refactor generateOutbox to enhance object serialization by converting…
0marSalah 97b5505
Refactor generateOutbox to improve object serialization by simplifyin…
0marSalah 7433d5c
Refactor generateOutbox to implement activity serialization, converti…
0marSalah 53c2761
Refactor generateOutbox to improve activity serialization by directly…
0marSalah 1a2b97c
Refactor generateOutbox to enhance object serialization by simplifyin…
0marSalah c6043ec
Refactor generateOutbox to enhance object serialization by improving …
0marSalah 6ce0c53
Refactor outbox handling by implementing helper functions for tags, t…
0marSalah 6b82907
Refactor generateOutbox by removing unused helper functions and addin…
0marSalah ff55ed3
Refactor generateOutbox by commenting out unused replies handling cod…
0marSalah 1394a5a
Refactor generateOutbox by commenting out unused replies handling cod…
0marSalah 1e22ea3
Refactor generateOutbox by commenting out unused shares, likes, and a…
0marSalah 3879dc9
Refactor generateOutbox by cleaning up object properties and ensuring…
0marSalah 25c6f80
Refactor generateOutbox by introducing safeToString function to ensur…
0marSalah ee14af2
Refactor generateOutbox by adding logging for debugging and commentin…
0marSalah b99f2f4
Refactor generateOutbox by removing unused helper functions for handl…
0marSalah 9b4b81a
Refactor outbox handling by improving type definitions, enhancing typ…
0marSalah 8e866e2
Refactor generateOutbox by adding getRepliesAsArray function to handl…
0marSalah 9ba53b8
Refactor generateOutbox by replacing getRepliesAsArray with direct ca…
0marSalah 51400c5
Refactor generateOutbox by adding logging for replies, likes, and sha…
0marSalah 75d93ec
Refactor generateOutbox to restructure replies object, improving data…
0marSalah b040444
Refactor generateOutbox to enhance likes and shares structure, improv…
0marSalah File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
import { | ||
Activity, | ||
type Actor, | ||
type Object as FedifyObject, | ||
} from "@fedify/fedify"; | ||
import { iterateCollection } from "../federation/collection"; | ||
|
||
// Helper to get tags as an array | ||
async function getTagsAsArray( | ||
object: FedifyObject, | ||
): Promise<Array<{ type: string; href: string; name: string }>> { | ||
const tags = []; | ||
for await (const tag of object.getTags() as any) { | ||
tags.push({ | ||
type: tag.id?.toString(), | ||
href: tag.href?.toString(), | ||
name: tag.name, | ||
}); | ||
} | ||
return tags; | ||
} | ||
|
||
async function getRepliesAsArray(object: any): Promise<Array<{ id: string; type: string, totalItems: number }>> { | ||
if (!object?.getReplies) return []; | ||
const replies = []; | ||
for await (const reply of object.getReplies()) { | ||
const id = safeToString(reply.id); | ||
const type = safeToString(reply.typeId); | ||
if (id && type) { | ||
replies.push({ | ||
id, | ||
type, | ||
totalItems: reply.totalItems, | ||
}); | ||
} | ||
} | ||
return replies.filter((reply) => reply.id && reply.type); // Remove incomplete entries | ||
} | ||
|
||
async function fetchOutbox(actor: Actor) { | ||
const outbox = await actor.getOutbox(); | ||
console.log("🚀 ~ fetchOutbox ~ outbox:", outbox); | ||
if (!outbox) return null; | ||
|
||
const activities: Activity[] = []; | ||
for await (const activity of iterateCollection(outbox)) { | ||
if (activity instanceof Activity) { | ||
activities.push(activity); | ||
} | ||
} | ||
|
||
console.log("🚀 ~ fetchOutbox ~ activities:", activities); | ||
return activities; | ||
} | ||
|
||
function safeToString(value: unknown): string | undefined { | ||
return value?.toString(); | ||
} | ||
|
||
function cleanObject(obj: Record<string, any>): Record<string, any> { | ||
const cleaned: Record<string, any> = {}; | ||
for (const [key, value] of Object.entries(obj)) { | ||
if (value !== null && value !== undefined) { | ||
cleaned[key] = value; | ||
} | ||
} | ||
return cleaned; | ||
} | ||
|
||
async function generateOutbox(actor: Actor, baseUrl: string | URL) { | ||
const activities = await fetchOutbox(actor); | ||
if (!activities) return null; | ||
|
||
const outbox = { | ||
"@context": [ | ||
"https://www.w3.org/ns/activitystreams", | ||
"https://w3id.org/security/v1", | ||
], | ||
id: new URL("/outbox.json", baseUrl).toString(), | ||
type: "OrderedCollection", | ||
totalItems: activities.length, | ||
orderedItems: await Promise.all( | ||
activities.map(async (activity) => { | ||
console.log("🚀 ~ Processing activity:", activity); | ||
|
||
const object = await activity.getObject(); | ||
console.log("🚀 ~ Retrieved object:", object); | ||
|
||
if (!object) { | ||
console.log("🚀 ~ Object is null, skipping activity"); | ||
return null; | ||
} | ||
|
||
const replies = await object.getReplies(); | ||
console.log("🚀 ~ activities.map ~ replies:", replies) | ||
const likes = await object.getLikes(); | ||
console.log("🚀 ~ activities.map ~ likes:", likes) | ||
const shares = await object.getShares(); | ||
console.log("🚀 ~ activities.map ~ shares:", shares | ||
|
||
) | ||
const to = object.toIds; | ||
const cc = object.ccIds; | ||
|
||
const tags = await getTagsAsArray(object); | ||
|
||
const fullObject = cleanObject({ | ||
id: safeToString(object.id), | ||
type: safeToString(object.id), | ||
content: object.content, | ||
published: safeToString(object.published), | ||
url: safeToString(object.url), | ||
to: to.length > 0 ? to : undefined, | ||
cc: cc.length > 0 ? cc : undefined, | ||
tags: tags.length > 0 ? tags : undefined, | ||
replies: { | ||
id: replies?.id, | ||
totalITems: replies?.totalItems, | ||
items: replies?.getItems | ||
}, | ||
likes: { | ||
id: likes?.id, | ||
totalItems: likes?.totalItems, | ||
items: likes?.getItems | ||
}, | ||
shares: { | ||
id: shares?.id, | ||
totalItems: shares?.totalItems, | ||
items: shares?.getItems | ||
}, | ||
}); | ||
|
||
return cleanObject({ | ||
id: safeToString(activity.id), | ||
type: "OrderedCollection", | ||
actor: safeToString(activity.actorId), | ||
published: safeToString(activity.published), | ||
to: activity.toIds, | ||
cc: activity.ccIds, | ||
object: fullObject, | ||
}); | ||
}), | ||
).then((items) => items.filter(Boolean)), // Remove null entries | ||
}; | ||
|
||
return outbox; | ||
} | ||
|
||
export { generateOutbox }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,45 +32,32 @@ interface ActorProfile { | |
|
||
// Define an interface for a Post | ||
interface Post { | ||
id: string | SQL<unknown> | ActorIdType; | ||
id: string; | ||
iri: string; | ||
created_at: string; | ||
in_reply_to_id: null | string; | ||
type: SQL<unknown> | "Article" | "Note" | "Question" | undefined; | ||
type: string; | ||
accountId: string; | ||
applicationId: string | null; // Allow null | ||
replyTargetId?: string | null; | ||
sharingId?: string | null; | ||
quoteTargetId?: `${string}-${string}-${string}-${string}-${string}` | null; | ||
visibility: string; | ||
summary?: string | null; | ||
contentHtml?: string | null; | ||
content?: string | null; | ||
pollId?: string | null; | ||
language?: string | null; | ||
tags: Record<string, string>; | ||
emojis: Record<string, string>; | ||
sensitive: boolean; | ||
spoiler_text: string; | ||
visibility: | ||
| SQL<unknown> | ||
| "public" | ||
| "unlisted" | ||
| "private" | ||
| "direct" | ||
| undefined; | ||
language: string; | ||
uri: string; | ||
url: null | string; | ||
replies_count: number; | ||
reblogs_count: number; | ||
favourites_count: number; | ||
favourited: boolean; | ||
reblogged: boolean; | ||
muted: boolean; | ||
bookmarked: boolean; | ||
pinned: boolean; | ||
content: string; | ||
reblog: null | Post; | ||
quote_id: null | string; | ||
quote: null | Post; | ||
application: null | string; | ||
account: ActorProfile; | ||
media_attachments: Array<{ url: string }>; | ||
mentions: Array<{ username: string; url: string }>; | ||
tags: Array<{ name: string }>; | ||
card: null | { url: string; title: string; description: string }; | ||
emojis: Array<{ shortcode: string; url: string }>; | ||
emoji_reactions: Array<{ emoji: string; count: number }>; | ||
poll: null | { options: Array<{ title: string; votes_count: number }> }; | ||
filtered: null | Array<{ filter: string }>; | ||
url?: string | null; | ||
previewCard?: any | null; | ||
repliesCount: number; | ||
sharesCount: number; | ||
likesCount: number; | ||
idempotenceKey?: string; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is this field for? |
||
published?: Date | null; | ||
updated: Date; | ||
media?: Array<{ id: string; url: string; contentType: string }> | null; | ||
} | ||
|
||
// Define an interface for FollowersData | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.