Misskey

repository·main·Indexed 42 days ago

https://github.com/misskeyio/misskey

An open-source, federated social media platform supporting ActivityPub, featuring a built-in cloud storage (Drive) and an extensible Web UI powered by the AiScript programming language. Includes the misskey-js SDK for browsers and Node.js (requiring version 12 or higher) for API interaction and real-time streaming via Stream and Channel abstractions.

Tokens
32.2K
Snippets
70
Records
88
Agent score
53%

What's inside Misskey

  1. Overview of Misskey features

    main

    Misskey is an open-source, federated social media platform with the following core capabilities:

    • ActivityPub Support: Enables federation with other networks like Mastodon and Pixelfed.
    • Reactions: Supports emoji reactions on posts.
    • Drive: Built-in cloud storage for uploading files, managing folders, and accessing media from posts.
    • Rich Web UI: A highly customizable interface that supports custom themes, layout changes, and widgets.
    • Extensibility: Plugins can be developed using AiScript, an original programming language designed for Misskey.
  2. How streaming works with Stream and Channel

    main

    Streaming in misskey-js is managed by two primary abstractions:

    1. Stream: Manages the underlying connection to the server. It handles automatic reconnection if the connection is lost.
    2. Channel: Represents a specific stream channel (e.g., main, chat). You obtain a Channel instance by calling .useChannel() on a Stream instance.

    Lifecycle and Events:

    • Connection States: Check stream.state which can be initializing, connected, or reconnecting.
    • Connection Events: Listen to _connected_ and _disconnected_ on the Stream instance.
    • Message Reception: Channel extends EventEmitter. Listen for specific event names (like notification) to receive payloads from the server.
    • Message Transmission: Use channel.send(event, params) to send messages to the server.
    • Cleanup: Call channel.dispose() to disconnect from a specific channel.
    const stream = new Misskey.Stream('https://misskey.test', { token: 'TOKEN' });
    const mainChannel = stream.useChannel('main');
    
    // Listen for messages
    mainChannel.on('notification', notification => {
    	console.log('notification received', notification);
    });
    
    // Send a message
    mainChannel.send('read', { id: 'xxxxxxxxxx' });
    
    // Disconnect channel
    mainChannel.dispose();
  3. Handle SigninFlow for multi-step authentication

    main

    Misskey authentication often requires multiple steps (e.g., Captcha, TOTP, or Passkeys). The SigninFlowResponse type indicates whether the sign-in process is complete or if further action is required.

    Sign-in States

    • Finished: If finished: true, the response contains the user id and an authentication token i.
    • Requires Captcha: If next: 'captcha', the client must solve a captcha and provide the response.
    • Requires Password: If next: 'password', the client must provide the user's password.
    • Requires TOTP: If next: 'totp', the client must provide a Two-Factor Authentication code.
    • Requires Passkey: If next: 'passkey', the client must initiate a WebAuthn/Passkey request using the provided authRequest.
    export type SigninFlowResponse = {
        finished: true;
        id: User['id'];
        i: string;
    } | {
        finished: false;
        next: 'captcha' | 'password' | 'totp';
    } | {
        finished: false;
        next: 'passkey';
        authRequest: PublicKeyCredentialRequestOptionsJSON_2;
    };
  4. Available Real-time Channels in misskey-js

    main

    The Channels type defines the real-time communication streams available via misskey-js. Each channel consists of params (required to subscribe), events (callbacks triggered by the server), and receives (actions you can perform within that channel).

    Key channels include:

    • main: Global notifications like mention, follow, reply, and unreadNotification.
    • Timelines (homeTimeline, localTimeline, hybridTimeline, globalTimeline): Subscribe to note streams with optional parameters like withRenotes, withFiles, or minimize.
    • hashtag: Subscribe to notes containing specific hashtags using the q parameter.
    • drive: Monitor file system changes like fileCreated, fileDeleted, or folderUpdated.
    • reversiGame: A specialized channel for playing Reversi, supporting events like started, ended, and changeReadyStates, and receiving actions like putStone or cancel.
    • chatUser / chatRoom: Real-time messaging channels for specific users or rooms, supporting message, deleted, and react events.
    • antenna / channel / roleTimeline: Specialized timeline subscriptions based on specific IDs.
    // Example of the structure of a channel
    type Channels = {
        main: {
            params: null;
            events: {
                notification: (payload: Notification_2) => void;
                mention: (payload: Note) => void;
                // ...
            };
            receives: null;
        };
        // ...
    }
  5. Understand ModerationLogPayloads and moderationLogTypes

    main

    The ModerationLogPayloads type defines the structure of data payloads for various moderation actions recorded in the system. Each key in the type represents a specific type of moderation event (e.g., suspend, assignRole, deleteNote). The moderationLogTypes constant provides a runtime array of these event type strings, which can be used to identify or filter moderation logs.

    Common payload structures include:

    • User actions: suspend, unsuspend, resetPassword, deleteAccount (typically include userId, userUsername, and userHost).
    • Content actions: deleteNote, deleteDriveFile, deletePage (include identifiers for the content and the user responsible).
    • Role management: assignRole, unassignRole, createRole, updateRole, deleteRole.
    • Announcement management: createGlobalAnnouncement, updateGlobalAnnouncement, etc.
    export const moderationLogTypes: readonly ["updateServerSettings", "suspend", "unsuspend", ...];
    
    export type ModerationLogPayloads = {
        updateServerSettings: { before: MetaDetailed | null; after: MetaDetailed | null; };
        suspend: { userId: string; userUsername: string; userHost: string | null; };
        // ... other payloads
    };
  6. Generate type aliases for misskey-js from api.json

    main

    This module generates TypeScript type aliases used by misskey-js based on an OpenAPI-compliant api.json file exported by a Misskey backend.

    Note: This module is not intended to be bundled directly with misskey-js. Instead, you should generate the types and copy the resulting files into the src directory of your misskey-js implementation.

    pnpm generate
  7. How to use the misskey-js type generator

    main

    To generate types, follow these steps:

    1. Obtain api.json: You must first acquire the api.json file from a Misskey backend. You can:
      • Download it from the /api-doc endpoint of any Misskey instance.
      • Run pnpm generate-api-json within the backend module of the Misskey repository.
    2. Prepare the file: Place the downloaded api.json in the same directory as the generator.
    3. Run the generator: Execute the following command:
    pnpm generate
    1. Retrieve output: The generated TypeScript files will be located in the ./built directory.
  8. How to add new translations to Misskey

    main

    To add new text or translations to the Misskey project, you should only edit the ja-JP.yml file. When you add text to ja-JP.yml, the system automatically propagates these changes to other language files.

    Important Requirements:

    • Target File: Only edit ja-JP.yml.
    • Content: Translations added to the ja-JP.yml file must contain the original Japanese strings.