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:
@@ -20,6 +20,7 @@ export interface SwarmUserProfile {
|
||||
postsCount: number;
|
||||
createdAt: string;
|
||||
isBot?: boolean;
|
||||
botOwnerHandle?: string; // Handle of the bot's owner (e.g., "user" or "user@domain")
|
||||
nodeDomain: string;
|
||||
}
|
||||
|
||||
@@ -62,6 +63,9 @@ export async function GET(request: NextRequest, context: RouteContext) {
|
||||
// Find the user
|
||||
const user = await db.query.users.findFirst({
|
||||
where: eq(users.handle, cleanHandle),
|
||||
with: {
|
||||
botOwner: true, // Include bot owner if this is a bot
|
||||
},
|
||||
});
|
||||
|
||||
if (!user) {
|
||||
@@ -85,6 +89,7 @@ export async function GET(request: NextRequest, context: RouteContext) {
|
||||
postsCount: user.postsCount,
|
||||
createdAt: user.createdAt.toISOString(),
|
||||
isBot: user.isBot || undefined,
|
||||
botOwnerHandle: user.isBot && user.botOwner ? user.botOwner.handle : undefined,
|
||||
nodeDomain,
|
||||
};
|
||||
|
||||
|
||||
@@ -94,6 +94,16 @@ export async function GET(request: Request, context: RouteContext) {
|
||||
const swarmData = await fetchSwarmProfile(remoteHandle, remoteDomain);
|
||||
if (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({
|
||||
user: {
|
||||
id: `swarm:${remoteDomain}:${profile.handle}`,
|
||||
@@ -111,6 +121,7 @@ export async function GET(request: Request, context: RouteContext) {
|
||||
isSwarm: true,
|
||||
nodeDomain: remoteDomain,
|
||||
isBot: profile.isBot || false,
|
||||
botOwner,
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user