refactor: Migrate from ActivityPub federation to native Swarm network
- Remove ActivityPub infrastructure (webfinger, nodeinfo, inbox, activities, signatures) - Implement native peer-to-peer Swarm network with gossip protocol - Replace federated timeline with Swarm timeline aggregating posts from all nodes - Migrate direct messaging to end-to-end encrypted Swarm Chat system - Update user interactions (follow, like, repost) to use Swarm protocol - Add cryptographic key management for DID-based identity system - Remove server-bound identity model in favor of portable DID identities - Update documentation to reflect Swarm architecture and capabilities - Add debug utilities and chat testing tools for Swarm network - Refactor database schema to support distributed user directory - Update bot framework to work with Swarm network interactions - Simplify API routes to use Swarm protocol instead of ActivityPub - This transition enables true peer-to-peer communication, instant interactions, and encrypted messaging while maintaining sovereign identity through DIDs
This commit is contained in:
@@ -179,26 +179,7 @@ export async function POST(request: Request, context: RouteContext) {
|
||||
})();
|
||||
}
|
||||
} else if (post.apId) {
|
||||
// FALLBACK: Use ActivityPub for non-swarm posts
|
||||
(async () => {
|
||||
try {
|
||||
const { createLikeActivity } = await import('@/lib/activitypub/activities');
|
||||
const { deliverActivity } = await import('@/lib/activitypub/outbox');
|
||||
|
||||
// Get the post author's actor URL
|
||||
const postWithAuthor = await db.query.posts.findFirst({
|
||||
where: eq(posts.id, postId),
|
||||
with: { author: true },
|
||||
});
|
||||
|
||||
if (!postWithAuthor?.author) return;
|
||||
|
||||
const author = postWithAuthor.author as { handle: string };
|
||||
console.log(`[Federation] Like activity for post ${post.apId} from @${user.handle}`);
|
||||
} catch (err) {
|
||||
console.error('[Federation] Error federating like:', err);
|
||||
}
|
||||
})();
|
||||
// Non-swarm posts with apId are legacy - no federation needed
|
||||
}
|
||||
|
||||
return NextResponse.json({ success: true, liked: true });
|
||||
|
||||
@@ -191,33 +191,7 @@ export async function POST(request: Request, context: RouteContext) {
|
||||
})();
|
||||
}
|
||||
} else if (originalPost.apId) {
|
||||
// FALLBACK: Use ActivityPub for non-swarm posts
|
||||
(async () => {
|
||||
try {
|
||||
const { createAnnounceActivity } = await import('@/lib/activitypub/activities');
|
||||
const { getFollowerInboxes, deliverToFollowers } = await import('@/lib/activitypub/outbox');
|
||||
|
||||
// Send Announce to our followers
|
||||
const followerInboxes = await getFollowerInboxes(user.id);
|
||||
if (followerInboxes.length > 0) {
|
||||
const announceActivity = createAnnounceActivity(
|
||||
user,
|
||||
originalPost.apId!,
|
||||
nodeDomain,
|
||||
repost.id
|
||||
);
|
||||
|
||||
const privateKey = user.privateKeyEncrypted;
|
||||
if (privateKey) {
|
||||
const keyId = `https://${nodeDomain}/users/${user.handle}#main-key`;
|
||||
const result = await deliverToFollowers(announceActivity, followerInboxes, privateKey, keyId);
|
||||
console.log(`[Federation] Announce for ${originalPost.apId} delivered to ${result.delivered}/${followerInboxes.length} inboxes`);
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('[Federation] Error federating repost:', err);
|
||||
}
|
||||
})();
|
||||
// Non-swarm posts with apId are legacy - no federation needed
|
||||
}
|
||||
|
||||
return NextResponse.json({ success: true, repost, reposted: true });
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { NextResponse } from 'next/server';
|
||||
import { db, posts, users, media, remotePosts } from '@/db';
|
||||
import { eq, desc, and } from 'drizzle-orm';
|
||||
import { fetchRemotePost } from '@/lib/activitypub/fetchRemotePost';
|
||||
|
||||
export async function GET(
|
||||
request: Request,
|
||||
@@ -219,12 +218,8 @@ export async function GET(
|
||||
isReposted: false,
|
||||
};
|
||||
} else {
|
||||
const postUrl = `https://${nodeDomain}/posts/${id}`;
|
||||
const result = await fetchRemotePost(postUrl, nodeDomain);
|
||||
|
||||
if (result.post) {
|
||||
mainPost = result.post;
|
||||
}
|
||||
// Remote posts are no longer supported outside of swarm
|
||||
return NextResponse.json({ error: 'Post not found' }, { status: 404 });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user