Posts
Creating Posts
The SDK provides comprehensive tools for creating and managing posts on the OpenMSCP protocol.
Basic Post Creation
// Create a simple text post
const post = await client.post.create({
content: 'Hello, OpenMSCP!',
type: 'text'
});
// Create a post with media
const mediaPost = await client.post.create({
content: 'Check out this image!',
type: 'media',
media: [{
type: 'image',
url: 'ipfs://QmHash...',
alt: 'Description'
}]
});
// Create a post with tags
const taggedPost = await client.post.create({
content: 'Discussing #blockchain and #web3',
type: 'text',
tags: ['blockchain', 'web3']
});
Post Types
enum PostType {
TEXT = 'text',
MEDIA = 'media',
LINK = 'link',
POLL = 'poll',
EVENT = 'event'
}
interface Post {
publicKey: PublicKey;
author: PublicKey;
content: string;
type: PostType;
createdAt: number;
updatedAt: number;
media?: MediaItem[];
tags?: string[];
metadata?: Record<string, any>;
}
Post Interactions
Basic Interactions
// Like a post
await client.post.like(postPublicKey);
// Unlike a post
await client.post.unlike(postPublicKey);
// Comment on a post
const comment = await client.post.comment(postPublicKey, 'Great post!');
// Reply to a comment
const reply = await client.post.reply(commentPublicKey, 'Thanks!');
Advanced Interactions
// Share a post
await client.post.share(postPublicKey, {
message: 'Check this out!',
visibility: 'public'
});
// Bookmark a post
await client.post.bookmark(postPublicKey);
// Report a post
await client.post.report(postPublicKey, {
reason: 'spam',
details: 'This post contains spam content'
});
Post Queries
Basic Queries
// Get a single post
const post = await client.post.get(postPublicKey);
// Get posts by author
const authorPosts = await client.post.getByAuthor(authorPublicKey);
// Get recent posts
const recentPosts = await client.post.getRecent({
limit: 20,
offset: 0
});
Advanced Queries
// Search posts
const searchResults = await client.post.search({
query: 'blockchain',
filters: {
type: PostType.TEXT,
dateRange: {
start: new Date('2023-01-01'),
end: new Date()
}
},
sort: 'recent'
});
// Get trending posts
const trending = await client.post.getTrending({
timeRange: 'day',
limit: 10
});
// Get posts by tag
const taggedPosts = await client.post.getByTag('blockchain');
Post Management
Updating Posts
// Update post content
await client.post.update(postPublicKey, {
content: 'Updated content'
});
// Update post metadata
await client.post.updateMetadata(postPublicKey, {
tags: ['new', 'tags'],
visibility: 'private'
});
// Delete a post
await client.post.delete(postPublicKey);
Post Moderation
// Hide a post
await client.post.hide(postPublicKey);
// Pin a post
await client.post.pin(postPublicKey);
// Archive a post
await client.post.archive(postPublicKey);
Post Analytics
View Statistics
// Get post statistics
const stats = await client.post.getStats(postPublicKey);
// Get engagement metrics
const engagement = await client.post.getEngagement(postPublicKey);
// Get reach metrics
const reach = await client.post.getReach(postPublicKey);
Analytics Interface
interface PostStats {
views: number;
likes: number;
comments: number;
shares: number;
bookmarks: number;
reach: number;
engagementRate: number;
}
interface PostEngagement {
likes: User[];
comments: Comment[];
shares: Share[];
bookmarks: User[];
}
Post Events
The SDK provides event listeners for post-related activities.
// Listen for new posts
client.post.onNew((post) => {
console.log('New post:', post);
});
// Listen for post updates
client.post.onUpdate((post) => {
console.log('Post updated:', post);
});
// Listen for post interactions
client.post.onInteraction((interaction) => {
console.log('Post interaction:', interaction);
});
Post Media Management
Media Upload
// Upload media
const media = await client.post.uploadMedia(file, {
type: 'image',
maxSize: 5 * 1024 * 1024 // 5MB
});
// Create post with uploaded media
const post = await client.post.create({
content: 'New media post',
type: 'media',
media: [media]
});
Media Interface
interface MediaItem {
type: 'image' | 'video' | 'audio' | 'document';
url: string;
thumbnail?: string;
alt?: string;
size?: number;
duration?: number;
format?: string;
}
Last updated