Skip to content

fix: register thread collection #212

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 11, 2025
Merged

fix: register thread collection #212

merged 4 commits into from
Jun 11, 2025

Conversation

Behzad-rabiei
Copy link
Member

@Behzad-rabiei Behzad-rabiei commented Jun 11, 2025

Summary by CodeRabbit

  • New Features
    • Enhanced thread management with support for detailed thread metadata, member info, reactions, tags, and layout options.
  • Chores
    • Updated internal model setup to include thread data management. No changes to user-facing functionality.

Copy link

coderabbitai bot commented Jun 11, 2025

Walkthrough

The changes update import statements in the database manager service to directly import certain entities and interfaces, including a new IThread interface and its schema. The setupModels method is modified to register a new Thread model in the guild database setup section. Thread-related interfaces are extensively refactored and expanded with new event and sub-interfaces. The thread schema is extended with new sub-schemas and fields, and the softDelete method and deletedAt field are removed. A new dependency on discord-api-types is added. No changes were made to exported APIs in the database manager.

Changes

File(s) Change Summary
src/services/databaseManager.ts Updated imports to include IThread and threadSchema; registered a new Thread model setup.
src/interfaces/Thread.interface.ts Refactored thread interfaces: split IThread into multiple granular interfaces, added event interfaces, renamed and expanded properties, removed IThreadMethods.
src/models/schemas/Thread.schema.ts Added new sub-schemas (threadMemberSchema, defaultReactionSchema, forumTagSchema); extended threadSchema with new fields; removed deletedAt and softDelete.
package.json Added dependency "discord-api-types": "^0.38.11".

Sequence Diagram(s)

sequenceDiagram
    participant App
    participant DatabaseManager
    participant GuildDB

    App->>DatabaseManager: setupModels()
    DatabaseManager->>GuildDB: Register model "Thread" (IThread, threadSchema)
    Note right of GuildDB: Thread model is now available
Loading

Poem

🐇 A thread weaves through the code so bright,
New schemas bloom in data's light.
Interfaces split, events arise,
Models grow before our eyes.
Dependencies hop in line,
CodeRabbit’s work, simply divine! 🌿

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

npm error Exit handler never called!
npm error This is an error with npm itself. Please report this error at:
npm error https://github.com/npm/cli/issues
npm error A complete log of this run can be found in: /.npm/_logs/2025-06-11T08_07_20_248Z-debug-0.log

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
src/services/databaseManager.ts (2)

2-5: Prefer import type for type-only symbols

Snowflake, Connection, and every I* interface are erased at runtime. Importing them as regular values pulls the corresponding modules into the compiled JS bundle (and can even trigger circular-dependency warnings in ESM loaders), while import type keeps the emit lean:

-import { Snowflake } from 'discord.js';
-import mongoose, { Connection } from 'mongoose';
-import { IChannel, IGuildMember, IHeatMap, IMemberActivity, IRawInfo, IRole, IThread } from '../interfaces';
+import type { Snowflake } from 'discord.js';
+import mongoose from 'mongoose';
+import type { Connection } from 'mongoose';
+import type {
+  IChannel,
+  IGuildMember,
+  IHeatMap,
+  IMemberActivity,
+  IRawInfo,
+  IRole,
+  IThread,
+} from '../interfaces';

No behaviour change, but cleaner byte-code and avoids accidental value-namespace collisions.


13-15: Schema import order nit

threadSchema breaks the existing alphabetical / logical grouping (rawInfoSchema, roleSchema, …). Re-ordering keeps diffs small and improves scan-ability for future contributors.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b3ee069 and 49fa75d.

📒 Files selected for processing (1)
  • src/services/databaseManager.ts (2 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
src/services/databaseManager.ts (2)
src/interfaces/Thread.interface.ts (1)
  • IThread (13-30)
src/models/schemas/index.ts (1)
  • threadSchema (29-29)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: ci / lint / Lint
🔇 Additional comments (1)
src/services/databaseManager.ts (1)

54-55: 👍 Thread model successfully registered

Registering Thread inside the guild branch is consistent with the other per-guild collections. Nothing else to flag here.

@Behzad-rabiei Behzad-rabiei merged commit 5be183a into main Jun 11, 2025
3 checks passed
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (4)
src/models/schemas/Thread.schema.ts (1)

58-61: Consider using a more specific schema type for the member field.

Using Schema.Types.Mixed provides flexibility but sacrifices type safety and validation. If the structure of the member data is known, consider defining a proper schema for it.

src/interfaces/Thread.interface.ts (3)

13-19: Consider defining a more specific type for the member field.

The member field is typed as any, which reduces type safety. If the structure is known, consider defining a proper interface for it. This could be a Discord GuildMember type or a custom interface.

Based on Discord API, this could potentially be:

-  member?: any;
+  member?: GuildMember | null;

Or define a custom interface if you need a subset of guild member properties.


64-64: Consider using a type alias for ThreadUpdateEvent.

Since ThreadUpdateEvent doesn't add any properties to BaseThread, a type alias would be more concise.

-export interface ThreadUpdateEvent extends BaseThread {}
+export type ThreadUpdateEvent = BaseThread;

92-92: Consider using a type alias for IThread.

Similar to ThreadUpdateEvent, since IThread doesn't add properties to BaseThread, a type alias would be cleaner.

-export interface IThread extends BaseThread {}
+export type IThread = BaseThread;
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 49fa75d and eaf3f6b.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (3)
  • package.json (1 hunks)
  • src/interfaces/Thread.interface.ts (4 hunks)
  • src/models/schemas/Thread.schema.ts (2 hunks)
✅ Files skipped from review due to trivial changes (1)
  • package.json
🔇 Additional comments (4)
src/models/schemas/Thread.schema.ts (3)

66-78: LGTM!

The defaultReactionSchema is well-structured with appropriate nullable fields for emoji data.


89-90: Verify if empty forum tag names should be allowed.

The minlength: 0 constraint allows empty strings for forum tag names. Please confirm if this is intentional, as empty tag names might not be meaningful in the UI.


181-217: LGTM! New forum channel fields are well-implemented.

The new fields properly support Discord's forum channel features with appropriate validations:

  • Enum constraints for archive duration, sort order, and forum layout
  • Min/max constraints for rate limits
  • Proper schema references for complex types
src/interfaces/Thread.interface.ts (1)

36-36:

✅ Verification successful

Verify thread type enum values match Discord API.

Please confirm that the thread type values (10, 11, 12) correspond to the current Discord API channel types for threads.


🌐 Web query:

What are the Discord API channel type values for threads (GUILD_PUBLIC_THREAD, GUILD_PRIVATE_THREAD, GUILD_NEWS_THREAD)?

💡 Result:

The Discord API assigns the following channel type values for thread channels:

  • GUILD_PUBLIC_THREAD: 11
  • GUILD_PRIVATE_THREAD: 12
  • GUILD_NEWS_THREAD: 10

These types correspond to temporary sub-channels created within existing guild text or announcement channels, used to organize conversations. Specifically:

  • GUILD_PUBLIC_THREAD (11): A public thread within a guild text channel, visible to anyone who can view the parent channel.
  • GUILD_PRIVATE_THREAD (12): A private thread within a guild text channel, only accessible to users who are invited or have the appropriate permission.
  • GUILD_NEWS_THREAD (10): A thread created within a guild announcement (news) channel[7][9][10].

Citations:


Thread type enum values align with Discord API

Confirmed that the values 10, 11, and 12 map to GUILD_NEWS_THREAD, GUILD_PUBLIC_THREAD, and GUILD_PRIVATE_THREAD respectively as per the official Discord API. No changes needed.

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