Misskey

repository·develop·Indexed 11 days ago

https://github.com/misskey-dev/misskey

An open source, federated social media platform. Documentation covers the core platform, the misskey-js SDK for browsers and Node.js (requiring version 12+), federation testing environments, and internal development utilities like icons-subsetter and diagnostics packages.

Tokens
42.1K
Snippets
85
Records
135
Agent score
95%

What's inside Misskey

  1. Overview of icons-subsetter

    develop

    The icons-subsetter is a tool designed to optimize the frontend by scanning for Tabler icon classes used across various frontend packages and extracting only the icons that are actually in use.

    Key features:

    • Optimization: Creates a subset of icons to reduce bundle size.
    • Fallback Mechanism: If an icon is called that does not exist in the generated subset, the system automatically falls back to the full Tabler icons font.
    • Build Integration: This tool is intended to run during production builds. (Note: It may run once during development mode to provide files necessary to suppress type errors).

    To include additional files in the scanning process, you must modify the filesToScan array in src/generator.ts.

  2. Generate type aliases for misskey-js

    develop

    This module generates TypeScript type aliases for use in misskey-js based on the OpenAPI-compliant api.json produced by the Misskey backend.

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

  3. Understand the Signin flow and response types

    develop

    The authentication process in misskey-js uses a multi-step flow. The SigninFlowResponse indicates whether the authentication is complete or if additional steps (like CAPTCHA, TOTP, or Passkeys) are required.

    Possible states in SigninFlowResponse:

    • finished: true: Authentication successful. Contains the user id and an authentication token i.
    • next: 'captcha' | 'password' | 'totp': The user must provide additional credentials or solve a challenge.
    • next: 'passkey': The user must perform a WebAuthn/Passkey authentication, providing an authRequest.
  4. Subscribe to real-time events using Channels

    develop

    The Channels type defines the real-time event system in misskey-js. You can subscribe to specific channels to receive live updates via events. Each channel has a set of params required to subscribe and a set of events that trigger when specific actions occur on the server.

    Common channels include:

    • main: Receives system-wide notifications like mention, reply, follow, and newChatMessage.
    • homeTimeline, localTimeline, hybridTimeline, globalTimeline: Receive note events for notes appearing in these timelines.
    • drive: Receives events related to file management like fileCreated, fileDeleted, and folderCreated.
    • chatUser / chatRoom: Receive message, deleted, react, and unreact events.
    • reversiGame: Provides full real-time interaction for Reversi games, including started, ended, and changeReadyStates events, as well as methods to putStone or updateSettings.
    // Example conceptual usage of the Channels structure
    // Note: Actual implementation details for subscribing depend on the misskey-js client instance
    
    // Subscribing to a timeline (conceptual)
    channels.localTimeline.params = { withRenotes: true, withReplies: true };
    channels.localTimeline.events.note = (note) => {
      console.log('New note in local timeline:', note);
    };
    
    // Subscribing to main notifications
    channels.main.events.mention = (note) => {
      console.log('You were mentioned in:', note);
    };
  5. How streaming works with Stream and Channel

    develop

    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 stream.useChannel() on a Stream instance.

    Connection States (Stream.state):

    • initializing: Connection not yet established.
    • connected: Connection successfully established.
    • reconnecting: Attempting to reconnect.

    Connection Events (Stream):

    • _connected_: Emitted when the connection is established.
    • _disconnected_: Emitted when the connection is lost.
    const stream = new Misskey.Stream('https://misskey.test', { token: 'TOKEN' });
    const mainChannel = stream.useChannel('main');
  6. Report issues and ask questions in misskey-js

    develop

    When interacting with the misskey-js repository:

    • Reporting Problems: Use GitHub Issues only for feature requests, suggestions, or reporting bugs. Always search for existing issues first to avoid duplicates.
    • Asking Questions: Do not use Issues for questions. Instead, use GitHub Discussions or Discord.
    • Language: While the project uses Japanese as a major language, you are encouraged to write Issues and PRs in English. This ensures better accuracy and allows others to use their preferred translation tools.
  7. Run federation tests in test-federation

    develop

    Once the environment is running, you can execute the federation tests using Docker Compose. You can either run the entire test suite or target a specific test file.

    Run all tests

    Execute the following command to run all tests within the tester service:

    NODE_VERSION=22 docker compose run --no-deps --rm tester

    Run a specific test file

    To run a single test file (e.g., user.test.ts), pass the pnpm command as an argument to the tester service:

    NODE_VERSION=22 docker compose run --no-deps --rm tester -- pnpm -F backend test:fed packages/backend/test-federation/test/user.test.ts
    # Run all tests
    NODE_VERSION=22 docker compose run --no-deps --rm tester
    
    # Run a specific file
    NODE_VERSION=22 docker compose run --no-deps --rm tester -- pnpm -F backend test:fed packages/backend/test-federation/test/user.test.ts