feat(users): Add bot owner tracking to user profiles

- Add botOwnerHandle field to SwarmUserProfile interface to track bot ownership
- Include botOwner relationship in swarm user profile queries for bot users
- Populate botOwnerHandle in swarm profile responses when user is a bot
- Build botOwner object in local user profile endpoint when fetching remote bot profiles
- Include botOwner data in user profile responses for better bot attribution
- Enables tracking and displaying which user owns each bot across federated instances
This commit is contained in:
Christomatt
2026-01-26 10:30:42 +01:00
parent 728dda6b52
commit fce820d59a
2 changed files with 16 additions and 0 deletions
@@ -20,6 +20,7 @@ export interface SwarmUserProfile {
postsCount: number; postsCount: number;
createdAt: string; createdAt: string;
isBot?: boolean; isBot?: boolean;
botOwnerHandle?: string; // Handle of the bot's owner (e.g., "user" or "user@domain")
nodeDomain: string; nodeDomain: string;
} }
@@ -62,6 +63,9 @@ export async function GET(request: NextRequest, context: RouteContext) {
// Find the user // Find the user
const user = await db.query.users.findFirst({ const user = await db.query.users.findFirst({
where: eq(users.handle, cleanHandle), where: eq(users.handle, cleanHandle),
with: {
botOwner: true, // Include bot owner if this is a bot
},
}); });
if (!user) { if (!user) {
@@ -85,6 +89,7 @@ export async function GET(request: NextRequest, context: RouteContext) {
postsCount: user.postsCount, postsCount: user.postsCount,
createdAt: user.createdAt.toISOString(), createdAt: user.createdAt.toISOString(),
isBot: user.isBot || undefined, isBot: user.isBot || undefined,
botOwnerHandle: user.isBot && user.botOwner ? user.botOwner.handle : undefined,
nodeDomain, nodeDomain,
}; };
+11
View File
@@ -94,6 +94,16 @@ export async function GET(request: Request, context: RouteContext) {
const swarmData = await fetchSwarmProfile(remoteHandle, remoteDomain); const swarmData = await fetchSwarmProfile(remoteHandle, remoteDomain);
if (swarmData?.profile) { if (swarmData?.profile) {
const profile = swarmData.profile; const profile = swarmData.profile;
// Build botOwner object if this is a bot with an owner
let botOwner = undefined;
if (profile.isBot && profile.botOwnerHandle) {
botOwner = {
id: `swarm:${remoteDomain}:${profile.botOwnerHandle}`,
handle: `${profile.botOwnerHandle}@${remoteDomain}`,
};
}
return NextResponse.json({ return NextResponse.json({
user: { user: {
id: `swarm:${remoteDomain}:${profile.handle}`, id: `swarm:${remoteDomain}:${profile.handle}`,
@@ -111,6 +121,7 @@ export async function GET(request: Request, context: RouteContext) {
isSwarm: true, isSwarm: true,
nodeDomain: remoteDomain, nodeDomain: remoteDomain,
isBot: profile.isBot || false, isBot: profile.isBot || false,
botOwner,
} }
}); });
} }