Skip to content

Sync with upstream spacebarchat/server and reintroduce ticket system#135

Closed
devin-ai-integration[bot] wants to merge 60 commits intodefaultfrom
devin/1773598801-sync-upstream-spacebarchat
Closed

Sync with upstream spacebarchat/server and reintroduce ticket system#135
devin-ai-integration[bot] wants to merge 60 commits intodefaultfrom
devin/1773598801-sync-upstream-spacebarchat

Conversation

@devin-ai-integration
Copy link
Copy Markdown

@devin-ai-integration devin-ai-integration Bot commented Mar 15, 2026

Summary

Merges 1165 upstream commits from spacebarchat/server into erkinalp/anticensor, resolving 62 conflicted files while preserving all anticensor-specific features. Also reintroduces the ticket system with proper enum values, guild permissions, and route wiring.

Upstream sync

Major upstream changes incorporated: Express v5 upgrade, schema directory restructuring (src/util/schemassrc/schemas/uncategorised), new WebRTC implementation, automod system, lambert-server internalization, bulk-ban, forum/media channels, application commands, and more.

Anticensor features preserved

All 54 anticensor-specific commits were carried forward and adapted to the new upstream codebase:

  • Lobbies — In-memory LobbyStore, CRUD routes (/lobbies), channel linking, lobby events (LOBBY_CREATE, LOBBY_UPDATE, LOBBY_DELETE, LOBBY_MEMBER_ADD, LOBBY_MEMBER_REMOVE), LOBBY channel type (17)
  • Support ticketsTICKET_TRACKER channel type (19), MANAGE_TICKETS guild permission (BitFlag(53)), TicketFlags (RESOLVED, ARCHIVED), POST /channels/:id/tickets and PATCH /channels/:id/ticket endpoints
  • Doubly-linked repliesreply_ids column on Message entity, GET/DELETE /messages/:id/replies route, DOUBLY_LINKED_REPLIES capability flag
  • Consent managerUserConsent entity, GET/PUT/DELETE /users/@me/consents/:service_id, admin consent revocation
  • Connection privacy gatingConnectionPrivacy utility with VisibilityLevel enum, per-account visibility filtering
  • Thread promotionPOST /channels/:id/promote to convert thread → top-level channel
  • SlowmodeBYPASS_SLOWMODE permission (BitFlag(52))
  • PIN_MESSAGES permission (BitFlag(51))
  • Volatile mode — In-memory SQLite for testing
  • Guild templates — Extended template creation
  • Presence suppression — Rights-based bitmask filtering (shouldRoutePresenceFromRights)
  • EPHEMERAL_DM channel type (18)
  • Configurable length limits — Per-entity size constraints
  • AutomodAutomodEvaluator + AutomodActionExecutor with keyword filtering, regex patterns, mention spam detection

Post-merge adaptation fixes

  • UserConsent.ts: Simplified entity to {user_id, service_id, created_at} (removed fields not compatible with upstream entity model)
  • ConnectionPrivacy.ts: Uses show_activity, metadata_visibility, visibility from upstream ConnectedAccount
  • promote.ts: Updated imports (ChannelType from @spacebar/schemas)
  • Message.ts: Added reply_ids column for doubly-linked replies
  • Express req.params type narrowing (as string casts) in all anticensor routes
  • Exported LobbyStore, ConnectionPrivacy, ChannelPromoteSchema, TicketSchemas from package indexes

Build & CI fixes

  • @types/express-serve-static-core as direct devDependency (fixes 153 TS2742 errors under pnpm)
  • discord-protos patched with runtime stub via pnpm patch (npm package ships without built output)
  • @protobuf-ts/runtime and @types/ms as direct dependencies
  • AutomodActionExecutor.ts: EmbedType imported from @spacebar/schemas instead of entity
  • paper-recommender-extension/ added to eslint ignores
  • default.nix: Fixed configurePhase to only apply discord-protos pnpm patch (patch-package format patches are already applied by npm postinstall)
  • nix/testVm/vm.nix: Uncommented qemu-vm.nix module import (provides required fileSystems and bootloader config for nix flake check)
  • DoublyLinkedReplies migration: Fixed timestamp from 10-digit Unix seconds (1755848356) to 13-digit JS milliseconds (1755848356000) — TypeORM requires valid JS timestamps in migration class names

Route fixes

  • Removed redundant src/api/routes/lobbies.ts wrapper file (conflicted with auto-loader which already mounts lobbies/ directory)
  • Removed router.use(tickets) and router.use(ticket) from channels/#channel_id/index.ts — the auto-loader handles directory-based routing; router.use() calls caused TypeError: router.use is not a function during schema generation (the mock Router lacks .use())
  • Fixed route paths in tickets.ts and ticket.ts from /tickets//ticket to / to avoid double-prefixing (auto-loader already mounts them at /channels/:channel_id/tickets and /channels/:channel_id/ticket)

Bug fixes

  • reactions.ts DM guard: Member lookup now conditionally skipped for non-guild channels (DMs), preventing a crash when guild_id is null
  • reactions.ts guild_id filter: Added missing guild_id: channel.guild_id to Member.findOneOrFail query
  • country-code.ts: Fixed broken @spacebar/util* import; rewrote as stub endpoint

Review & Testing Checklist for Human

  • Reactions DM guard changes event payload shape. member is now undefined for DM reactions (was previously crashing). Verify the MessageReactionAddEvent type and downstream clients accept member: undefined for DM reactions — this is a runtime behavior change on a common code path.
  • MANAGE_TICKETS bit position changed from BitFlag(55)BitFlag(53). If any existing database rows or role configurations stored the old bit value, they will silently stop granting this permission. Verify no production data depends on the old position.
  • No creation path for TICKET_TRACKER channels. The ticket routes are now functional, but verify POST /guilds/:guild_id/channels accepts type: 19. The channel creation validation may whitelist only known upstream types.
  • UserConsent entity was heavily simplified — removed consent_type, item_id, target_user_id, status, basis_document_url, basis_document_hash, expires_at, extra_data, and toJSON(). If there's existing consent data in the database, a migration may be needed.
  • discord-protos patch uses JSON stub, NOT real protobuf. The fromBase64/toBase64 methods use JSON.stringify + base64, not protobuf wire format. /users/@me/settings-proto/1 and /2 will NOT interoperate with clients expecting real protobuf.
  • Recommended test plan: Run pnpm start, register a user, create a guild, send messages, add reactions in both a guild channel and a DM (verify no crash in DM), create a channel with type: 19, POST a ticket to it, PATCH the ticket, and test lobby CRUD via the API.

Notes

  • All build-nix CI checks now pass, including the NixOS VM integration test (nix flake check).
  • Two separate MANAGE_TICKETS definitions exist: Permissions.FLAGS.MANAGE_TICKETS at BitFlag(53) (guild-level, used by ticket routes) and Rights.MANAGE_TICKETS at BitFlag(6) (instance-level admin right). These are different systems; the ticket routes correctly use the guild-level permission.
  • Gateway listener now also subscribes to session_id events (this.events[this.session_id]), enabling session-targeted events (SB_SESSION_CLOSE, SB_SESSION_REMOVE).
  • Session deletion commented out in Close.ts — sessions won't be cleaned up on disconnect. This appears intentional (from default branch) but will cause session accumulation.

Link to Devin session: https://app.devin.ai/sessions/f545780544d4405180c5ff2dc94b892b
Requested by: @erkinalp


Open with Devin

erkinalp and others added 30 commits October 9, 2024 22:06
- Add new limit configuration classes: EmbedLimits, ComponentLimits, AttachmentLimits, AutomodLimits, ApplicationLimits
- Extend existing limit classes with new properties (UserLimits, ChannelLimits, MessageLimits, GuildLimits)
- Update LimitConfigurations to include all new limit classes
- Replace hardcoded username length limits with configurable values in bans.ts
- Update TODO comment about message content/embed length limits

This addresses 48 configuration-related issues by making hardcoded length limits configurable across the codebase.

Co-Authored-By: Erkin Alp Güney <erkinalp9035@gmail.com>
- Add maxMembersRequestLimit property to GuildLimits class with default value of 100
- Update RequestGuildMembers.ts to use configurable limit instead of hardcoded value
- Replace TODO comment about configurable limit with actual implementation
- Resolves TypeScript compilation error in gateway opcodes

Co-Authored-By: Erkin Alp Güney <erkinalp9035@gmail.com>
- Replace 'any' type with 'Record<string, string>' in stats.ts
- Add ESLint disable comment for intentionally empty interface in AutomodRuleSchema.ts
- These were pre-existing lint issues blocking CI, unrelated to configurable limits changes

Co-Authored-By: Erkin Alp Güney <erkinalp9035@gmail.com>
- Apply prettier --write to 7 files with formatting violations
- Fixes code style issues in pins/index.ts, start.ts, Identify.ts, Automod.ts, responses/index.ts, Logo.ts, and String.ts
- All files now pass prettier --check validation
- Resolves CI build failure in 'Run npx prettier --check .' step

Co-Authored-By: Erkin Alp Güney <erkinalp9035@gmail.com>
- 5 new limit configuration classes created for different system components (embeds, components, attachments, automod, applications)
- Extended existing limit classes with missing properties for users, channels, messages, and guilds
- Updated configuration system to include all new limit classes in the main LimitConfigurations
- Replaced hardcoded limits with configurable values where they were found (currently in ban search functionality)
- Add ConnectionsConfiguration for instance-level controls
- Enhance ConnectedAccount entity with privacy fields (consent_given_at, data_sharing_level, last_activity_sync, privacy_override)
- Add connection privacy settings to UserSettings (connections_default_visibility, connections_activity_sharing, connections_metadata_sharing, connections_require_approval)
- Create ConnectionPrivacy utility for centralized filtering with visibility levels (0=private, 1=friends only, 2=mutual guilds, 3=public)
- Update schemas and DTOs for new privacy fields
- Implement privacy filtering in API routes and gateway events
- Add admin endpoint for connection policy management
- Create TypeORM migration for new database fields
- Update all exposure points with privacy controls

Addresses issue #31

Co-Authored-By: Erkin Alp Güney <erkinalp9035@gmail.com>
- Replace 'any' type with 'Record<string, any>' in connections index route
- Fix Config import path in ConnectionPrivacy utility

Co-Authored-By: Erkin Alp Güney <erkinalp9035@gmail.com>
…per typing

Co-Authored-By: Erkin Alp Güney <erkinalp9035@gmail.com>
- Export ConnectionPrivacy from util/index.ts to fix import path issues
- Update import statements to use @spacebar/util instead of relative paths
- Fix const assignment issue in gateway listener by using opts.data
- Remove unused @ts-expect-error directives that are no longer needed

All TypeScript compilation errors are now resolved and code passes prettier formatting.

Co-Authored-By: Erkin Alp Güney <erkinalp9035@gmail.com>
- Add reply_ids column to Message entity for forward links
- Create database migrations for postgres, mariadb, and mysql
- Implement lazy population of forward links from existing backlinks
- Add new /channels/:id/messages/:id/replies API endpoint
- Make reply_ids opt-in via x-client-capabilities and x-gateway-intents headers
- Handle forward link updates during message creation and deletion
- Support privileged deletion of messages with all replies
- Addresses issue #13

Co-Authored-By: Erkin Alp Güney <erkinalp9035@gmail.com>
- Add BitFlag(12) for doubly-linked replies feature
- Integrates with existing capabilities system
- Maintains consistency with established patterns

Co-Authored-By: Erkin Alp Güney <erkinalp9035@gmail.com>
- Move from BitFlag(12) to BitFlag(37) to avoid conflicts
- Maintains compatibility with existing Discord clients
- Places capability flag after bit 36 as requested

Co-Authored-By: Erkin Alp Güney <erkinalp9035@gmail.com>
…ring

- Add capability checking in gateway listener for MESSAGE_CREATE/MESSAGE_UPDATE
- Remove REST API header-based capability checking from all endpoints
- Simplify Message.toJSON to always include reply_ids
- Gateway now handles filtering based on client capabilities
- Centralizes capability logic in gateway following established patterns

Co-Authored-By: Erkin Alp Güney <erkinalp9035@gmail.com>
The /replies endpoint should always include reply_ids since clients
calling it already understand the doubly-linked replies concept

Co-Authored-By: Erkin Alp Güney <erkinalp9035@gmail.com>
Use permissions.has() instead of rights.has() for MANAGE_MESSAGES check
when deleting replies, consistent with other permission checks in the same function.

Addresses GitHub comment by @erkinalp

Co-Authored-By: Erkin Alp Güney <erkinalp9035@gmail.com>
- Add Channel and MessageDeleteBulkEvent imports
- Fetch Channel entity to get proper guild_id context
- Use MESSAGE_DELETE_BULK instead of individual MESSAGE_DELETE events
- Follow existing bulk delete patterns from bulk-delete.ts and purge.ts

Addresses GitHub comment by @erkinalp

Co-Authored-By: Erkin Alp Güney <erkinalp9035@gmail.com>
- Remove hardcoded MANAGE_MESSAGES permission from route decorator
- Add dynamic permission checking based on message ownership
- Check SELF_DELETE_MESSAGES for user-owned replies
- Check MANAGE_MESSAGES only for other users' replies
- Follow existing patterns from individual message deletion endpoint

Addresses GitHub feedback by @erkinalp

Co-Authored-By: Erkin Alp Güney <erkinalp9035@gmail.com>
    Added reply_ids column to Message entity to store forward links
    Created database migrations for PostgreSQL, MariaDB, and MySQL
    Implemented lazy population of forward links from existing backlinks during message retrieval
    Added new /channels/:id/messages/:id/replies API endpoint to fetch replies to a message
    Made reply data opt-in on client side
    Added cleanup logic for forward links when messages are deleted
    Support for privileged deletion of messages with all their replies (requires MANAGE_MESSAGES permission)
…ts\n\n- New entity: UserConsent { user_id, service_id, created_at }\n- Self endpoints:\n - GET /users/@me/consents\n - PUT /users/@me/consents/:service_id (idempotent)\n - DELETE /users/@me/consents/:service_id (silent if missing)\n- Admin endpoints (requires MANAGE_USERS):\n - GET /users/:id/consents\n - PUT /users/:id/consents/:service_id\n - DELETE /users/:id/consents/:service_id\n- OpenAPI updated

Co-Authored-By: Erkin Alp Güney <erkinalp9035@gmail.com>
…x route syntax and OpenAPI

Co-Authored-By: Erkin Alp Güney <erkinalp9035@gmail.com>
Implements a comprehensive consent management system for Anticensor server based on requirements from spacebarchat#1003. This adds:

    New UserConsent entity with TypeORM, including unique constraint on (user_id, service_id)
    Self-service endpoints under /users/@me/consents for users to manage their own consents
    Admin endpoints under /users/:id/consents for admins to view and revoke user consents
    Operator-only bulk revoke endpoint to revoke all consents for a user

Key design decisions:

    Admins can only view and revoke consents, not grant them on behalf of users
    Bulk "revoke all consents" requires OPERATOR permissions (highest privilege level)
    Individual consent revocation requires MANAGE_USERS permissions
    Self-service consent management has no special permission requirements
…channel with permissions continuity and ordering

Co-Authored-By: Erkin Alp Güney <erkinalp9035@gmail.com>
Co-Authored-By: Erkin Alp Güney <erkinalp9035@gmail.com>
…OR && !PRESENCE) || (OPERATOR && PRESENCE); bypass Rights.has for PRESENCE checks

Co-Authored-By: Erkin Alp Güney <erkinalp9035@gmail.com>
devin-ai-integration Bot and others added 13 commits August 30, 2025 13:07
…tisfy lint in /-/version and VoiceStateUpdate

Co-Authored-By: Erkin Alp Güney <erkinalp9035@gmail.com>
…ons filtering per review

Co-Authored-By: Erkin Alp Güney <erkinalp9035@gmail.com>
…lity

Co-Authored-By: Erkin Alp Güney <erkinalp9035@gmail.com>
- Add PIN_MESSAGES permission flag at bit 38 following Discord's API change
- Update pin/unpin routes to check for both PIN_MESSAGES and MANAGE_MESSAGES permissions
- Maintain backward compatibility by allowing either permission for pin operations
- Remove completed TODO comment about pin messages permission

Follows Discord's pin permission split specification:
https://discord.com/developers/docs/change-log#pin-permission-split

Co-Authored-By: Erkin Alp Güney <erkinalp9035@gmail.com>
- Fix formatting issues in Permissions.ts, pins.ts, and pins/index.ts
- Resolve CI build failure caused by Prettier formatting checks

Co-Authored-By: Erkin Alp Güney <erkinalp9035@gmail.com>
 Implement Discord lobby feature with in-memory storage
- Add LobbyStore for ephemeral lobby management with timeout cleanup
- Implement all lobby API endpoints following Discord specification
- Add lobby gateway events for real-time updates
- Support metadata limits, member limits, and idle timeout functionality
- Add proper TypeScript interfaces and schema validation
- Integrate lobby routes into main API server
- Add lobby event types to EVENT union for proper type safety
* also fixes formatting errors in pins/index.ts

Co-authored-by: Devin AI <devin@app.devin.ai>
Co-authored-by: openhands <openhands@all-hands.dev>
…scord: and external: codes); reuse config flags for template usage

Co-Authored-By: Erkin Alp Güney <erkinalp9035@gmail.com>
…T /guilds template logic

Co-Authored-By: Erkin Alp Güney <erkinalp9035@gmail.com>
Implements support for the existing guild_template_code field in GuildCreateSchema for POST /guilds. Previously this field was ignored; now it honors discord:, external:, and local template codes by fetching the template data and merging it into guild creation, mirroring the logic from the existing GET/POST /guilds/templates/:code routes.

This resolves spacebarchat#1282 by enabling guild creation from Discord templates directly through the main guild creation endpoint.

Key changes:

    Added template fetching logic to POST /guilds route
    Supports discord: prefixed templates (fetches from Discord API)
    Supports external: prefixed templates (parses embedded JSON)
    Supports local template codes (looks up in database)
    Respects existing config flags (templates.enabled, allowDiscordTemplates, allowRaws)
    Template data is merged first, then request body overrides (preserving user customizations)
Merge 1165 commits from spacebarchat/server upstream/master into
erkinalp/anticensor, preserving all 54 anticensor-specific commits
and features.

Resolved 62 conflicted files during merge. Post-merge fixes include:
- Fix UserConsent entity (removed non-existent dbEngine import)
- Fix ConnectionPrivacy to work with upstream ConnectedAccount
- Add lobby event types to CUSTOMEVENTS in Event.ts
- Export LobbyStore and ConnectionPrivacy from @spacebar/util
- Export ChannelPromoteSchema from schemas index
- Add reply_ids column to Message entity for doubly-linked replies
- Fix promote.ts imports (ChannelType from schemas, remove ENCRYPTED)
- Fix connections.ts (remove non-existent Config.connections ref)
- Fix Express req.params type narrowing in all anticensor routes
- Add @types/express-serve-static-core as direct dep (fix TS2742)
- Patch discord-protos with runtime stub (npm package missing built output)
- Remove deprecated husky v10 lines from pre-commit hook
- Install missing direct dependencies (@protobuf-ts/runtime, @types/ms)

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@devin-ai-integration
Copy link
Copy Markdown
Author

Original prompt from Erkin

Sync the erkinalp/anticensor repository with the spacebarchat/server repository. Ensure that all existing features and changes in erkinalp/anticensor are preserved during the synchronization process.

  • Identify the differences between the two repositories.
  • Merge changes from spacebarchat/server into erkinalp/anticensor.
  • Resolve any conflicts that arise, prioritizing the preservation of features and changes unique to erkinalp/anticensor.
  • Verify that all existing functionalities in erkinalp/anticensor still work as expected after the sync.

Submit your work by creating a pull request to the erkinalp/anticensor repository with the synchronized changes. Make sure all automated tests pass.

You only need to look in the following repo: erkinalp/anticensor

@devin-ai-integration
Copy link
Copy Markdown
Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

@devin-ai-integration
Copy link
Copy Markdown
Author

Closing this PR - it was created targeting the default branch instead of master. The correct PR is #136 which targets master.

erkinalp and others added 4 commits March 15, 2026 20:39
… default-only files

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
…e.ts import

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@erkinalp
Copy link
Copy Markdown
Owner

devin, use this pr

@devin-ai-integration
Copy link
Copy Markdown
Author

Done — pushed all latest changes to this PR's branch, including:

  • Merge with origin/default for base branch compatibility
  • Compilation fixes for files from the default branch (ticket routes, location-info, country-code, automod)
  • guild_id filter fix in reactions.ts (from review bot feedback)
  • country-code.ts stub rewrite (invalid @spacebar/util* import)
  • Regenerated openapi.json and schemas.json

PR description has been updated.

Copy link
Copy Markdown
Author

@devin-ai-integration devin-ai-integration Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Open in Devin Review

…ETS permission, and fix reactions DM guard

- Add TICKET_TRACKER = 19 to ChannelType enum
- Add MANAGE_TICKETS = BitFlag(53) guild permission
- Update ticket.ts to use ChannelType.TICKET_TRACKER directly (was dead code with dynamic lookup)
- Update ticket.ts permission checks from MANAGE_THREADS to MANAGE_TICKETS
- Update tickets.ts to use ChannelType.TICKET_TRACKER directly
- Wire ticket and tickets routes back into channel router (index.ts)
- Export TicketSchemas from schemas/uncategorised/index.ts
- Fix reactions.ts DM channel guard: skip Member lookup for non-guild channels

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@erkinalp erkinalp closed this Mar 16, 2026
@erkinalp erkinalp removed their request for review March 16, 2026 14:54
@erkinalp erkinalp removed their assignment Mar 16, 2026
@devin-ai-integration devin-ai-integration Bot changed the title Sync with upstream spacebarchat/server (1165 commits) Sync with upstream spacebarchat/server and reintroduce ticket system Mar 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant