Skip to content
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

add separate toggles for auto-skip categories #1253

Merged
merged 17 commits into from
Feb 11, 2024
Merged

add separate toggles for auto-skip categories #1253

merged 17 commits into from
Feb 11, 2024

Conversation

ceofil
Copy link
Contributor

@ceofil ceofil commented Jan 22, 2024

Resolves #1209

Copy link
Contributor

coderabbitai bot commented Jan 22, 2024

Walkthrough

The recent changes introduce a more granular control over auto-skipping content within a media platform, allowing users to individually toggle auto-skipping for different categories of segments such as sponsors, intros, etc. This is achieved by adding a new configuration option in the UI and updating the database schema and server logic to handle multiple auto-skip categories instead of a single auto-skip flag.

Changes

File Path Change Summary
client/src/components/RoomSettingsForm.vue Introduces a new section for auto-skip segment categories with default values and updated styling.
server/migrations/20240121172024-add-auto-skip-fields-to-rooms.js Adds "autoSkipSegmentCategories" field to "Rooms" table, removes "autoSkipSegments," and updates existing data.
server/room.ts Updates to use "autoSkipSegmentCategories," introduces Category type, and manages multiple skip categories.
server/tests/unit/api/room.spec.ts Updates test descriptions and variables for autoSkipSegmentCategories.
client/src/locales/en.ts Refines text related to auto-skipping video segments using SponsorBlock data by specifying segment types explicitly.

Assessment against linked issues

Objective Addressed Explanation
separate toggles for auto-skip categories (#1209)

Poem

On the field of code, the rabbit did play,
Enhancing features, bright as day.
Chiefs and 49ers in a Super Bowl bout,
CodeRabbit leaps, no room for doubt.
🐰🏈✨

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

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>.
    • Generate unit-tests for this file.
  • 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 generate unit tests for this file.
    • @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 generate interesting stats about this repository from git and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

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 as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • 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/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

@ceofil ceofil marked this pull request as ready for review January 22, 2024 21:43
@ceofil ceofil requested a review from dyc3 as a code owner January 22, 2024 21:43
Copy link
Contributor

@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.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 8b76b01 and 03f4b23.
Files ignored due to path filters (1)
  • docs/api.yaml is excluded by: !**/*.yaml
Files selected for processing (9)
  • client/src/components/RoomSettingsForm.vue (5 hunks)
  • client/src/locales/en.ts (1 hunks)
  • common/models/rest-api.ts (2 hunks)
  • common/models/types.ts (3 hunks)
  • server/api/room.ts (1 hunks)
  • server/migrations/20240121172024-add-auto-skip-fields-to-rooms.js (1 hunks)
  • server/models/room.ts (4 hunks)
  • server/room.ts (9 hunks)
  • server/storage/room.ts (3 hunks)
Additional comments: 23
server/migrations/20240121172024-add-auto-skip-fields-to-rooms.js (1)
  • 6-17: The migration script correctly adds a new autoSkipSegmentCategories column with a JSONB type and a default value. However, it's important to ensure that the default values align with the application's expected behavior and that the defaultValue object keys match the segment categories used by the application.
Verification successful

It seems that the default values for the autoSkipSegmentCategories are consistent across the application. The keys and usage of these categories are found in the RoomSettingsForm.vue component, API models, database migrations, and server logic. The default values match the expected behavior and are aligned with the segment categories used elsewhere in the application.

Given this information, it can be concluded that the default values align with the application's expected behavior and that the keys are consistent with the segment categories used elsewhere in the application.

Conclusion

The default values for the autoSkipSegmentCategories column are consistent with the application's expected behavior and the segment categories used elsewhere in the application.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify that the default values match the application's expected behavior
# and that the keys are consistent with the segment categories used elsewhere in the application.
# This script should be run in the repository root.
grep -r "autoSkipSegmentCategories" .

Length of output: 2988

common/models/rest-api.ts (1)
  • 56-56: The addition of autoSkipSegmentCategories to the OttApiResponseGetRoom interface is correct and aligns with the PR objectives to allow users to configure auto-skipping for individual segment categories.
common/models/types.ts (2)
  • 57-59: The SegmentCategories type is correctly defined using a mapped type over the Category type from the "sponsorblock-api" module. This ensures that the keys of SegmentCategories will match the categories defined by SponsorBlock.
  • 71-71: The autoSkipSegmentCategories property is correctly added to the RoomSettings interface, which is consistent with the PR's goal to provide granular control over auto-skipping of video segment categories.
server/models/room.ts (2)
  • 21-21: The autoSkipSegmentCategories property is correctly added to the RoomAttributes interface. This change is necessary for the ORM to recognize and interact with the new database column.
  • 107-118: The autoSkipSegmentCategories field is correctly added to the createModel function with the appropriate type and default value. This ensures that new rooms will have the autoSkipSegmentCategories property initialized correctly.
server/storage/room.ts (3)
  • 108-108: The autoSkipSegmentCategories property is correctly added to the RoomOptions interface, which is used when creating or updating room instances in the database.
  • 135-135: The autoSkipSegmentCategories property is correctly included in the roomToDb function, which is responsible for converting room state into a format that can be stored in the database.
  • 171-171: The autoSkipSegmentCategories property is correctly included in the roomToDbPartial function, ensuring that partial updates to the room state include changes to the auto-skip segment categories.
client/src/components/RoomSettingsForm.vue (4)
  • 74-117: The new section for auto-skip segment categories in the RoomSettingsForm.vue component is correctly implemented. It allows users to configure various segment types for automatic skipping, and the autoSkipSegmentCategories object is initialized with default values. Ensure that the labels used here match the keys in the autoSkipSegmentCategories object and that they are correctly localized.
Verification successful

The labels used in the RoomSettingsForm.vue component match the keys in the autoSkipSegmentCategories object and are correctly localized in the en.ts file. The verification process is successful, and the implementation aligns with the expected behavior.

Conclusion

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify that the labels used in the RoomSettingsForm.vue component match the keys in the autoSkipSegmentCategories object
# and that they are correctly localized in the en.ts file.
grep -r "auto-skip-text-" client/src/locales/en.ts

Length of output: 341

* 223-231: The initialization of `autoSkipSegmentCategories` with default values in the component's data is correct and aligns with the PR's objectives. * 255-255: The `autoSkipSegmentCategories` property is correctly picked from the API response and assigned to the component's state, ensuring that the room settings are loaded correctly. * 276-276: The `autoSkipSegmentCategories` property is correctly included in the `getRoomSettingsSubmit` function, which prepares the room settings for submission to the server.
client/src/locales/en.ts (1)
  • 247-254: The addition of specific auto-skip text options related to SponsorBlock data in the en.ts localization file is correct. This ensures that the new settings are properly described in the user interface.
server/api/room.ts (1)
  • 216-216: The addition of the "autoSkipSegmentCategories" property to the getRoom request handler is consistent with the PR's objective to allow users to configure the automatic skipping of various segment types individually.
server/room.ts (8)
  • 48-48: Import of SegmentCategories is correct and aligns with the PR objectives.
  • 231-239: The autoSkipSegmentCategories property is initialized with default values, which is consistent with the PR objectives to allow users to configure auto-skipping for individual segment categories.
  • 172-172: The inclusion of autoSkipSegmentCategories in syncableProps is correct, ensuring that the property is synchronized with clients.
  • 197-197: The inclusion of autoSkipSegmentCategories in storableProps is correct, ensuring that the property is stored in Redis.
  • 415-422: Getter and setter methods for autoSkipSegmentCategories have been implemented correctly, including marking the property as dirty when it is set, which is necessary for synchronization.
  • 821-821: The usage of autoSkipSegmentCategories in the update method correctly checks the category of the segment against the user's settings to determine if it should be skipped.
  • 890-890: The autoSkipSegmentCategories property is correctly included in the RoomStatePersistable type, ensuring it is part of the room's persistent state.
  • 1528-1528: The autoSkipSegmentCategories property is correctly checked in the applySettings method, ensuring that permissions are verified before applying changes to this setting.

Copy link
Owner

@dyc3 dyc3 left a comment

Choose a reason for hiding this comment

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

Thanks for the high quality PR! Love to see it. I'll give this a bit more scrutiny when the CI passes and these change requests are resolved.

The only major blocker I see is that there's no validation on the SegmentCategories before it is applied to the Room and saved in redis or database. A malicious client could DoS because they could add a bunch of items to the object and eat up a bunch of memory, and/or disk space. Preferably, this should be done in the handler for RoomRequest.ApplySettingsRequest.

Also, I'd like to have unit tests for storing and retrieving this new column in the database.

server/models/room.ts Outdated Show resolved Hide resolved
common/models/types.ts Outdated Show resolved Hide resolved
docs/api.yaml Outdated Show resolved Hide resolved
client/src/locales/en.ts Outdated Show resolved Hide resolved
@ceofil ceofil marked this pull request as draft January 26, 2024 13:28
Copy link
Owner

@dyc3 dyc3 left a comment

Choose a reason for hiding this comment

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

Looking good so far.

This still needs to validate incoming settings changes for autoSkipSegmentCategories, like I explained in my previous review.

client/src/components/RoomSettingsForm.vue Outdated Show resolved Hide resolved
common/models/rest-api.ts Outdated Show resolved Hide resolved
server/room.ts Outdated Show resolved Hide resolved
server/room.ts Outdated Show resolved Hide resolved
server/room.ts Outdated Show resolved Hide resolved
@dyc3 dyc3 changed the title separate toggles for auto-skip categories #1209 add separate toggles for auto-skip categories Jan 26, 2024
Copy link

codecov bot commented Jan 26, 2024

Codecov Report

Attention: 2 lines in your changes are missing coverage. Please review.

Comparison is base (c1fa167) 62.4673% compared to head (3f6f40d) 62.2464%.

Files Patch % Lines
common/constants.ts 0.0000% 1 Missing ⚠️
server/room.ts 95.8333% 1 Missing ⚠️
Additional details and impacted files
@@               Coverage Diff                @@
##             master      #1253        +/-   ##
================================================
- Coverage   62.4673%   62.2464%   -0.2210%     
================================================
  Files           118        118                
  Lines          8795       8823        +28     
  Branches       1174       1169         -5     
================================================
- Hits           5494       5492         -2     
- Misses         3301       3331        +30     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

server/room.ts Outdated Show resolved Hide resolved
@ceofil ceofil marked this pull request as ready for review January 29, 2024 15:06
Copy link
Contributor

@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.

Review Status

Actionable comments generated: 3

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 03f4b23 and 4267158.
Files ignored due to path filters (3)
  • docs/api.yaml is excluded by: !**/*.yaml
  • tests/e2e/fixtures/get-room-foo.json is excluded by: !**/*.json
  • tests/e2e/fixtures/patch-room-foo.json is excluded by: !**/*.json
Files selected for processing (11)
  • client/src/components/RoomSettingsForm.vue (8 hunks)
  • client/src/locales/en.ts (1 hunks)
  • common/constants.ts (1 hunks)
  • common/models/rest-api.ts (2 hunks)
  • common/models/types.ts (2 hunks)
  • server/api/room.ts (1 hunks)
  • server/migrations/20240121172024-add-auto-skip-fields-to-rooms.js (1 hunks)
  • server/models/room.ts (4 hunks)
  • server/room.ts (15 hunks)
  • server/storage/room.ts (3 hunks)
  • server/tests/unit/api/room.spec.ts (1 hunks)
Files skipped from review as they are similar to previous changes (8)
  • client/src/components/RoomSettingsForm.vue
  • client/src/locales/en.ts
  • common/models/rest-api.ts
  • common/models/types.ts
  • server/api/room.ts
  • server/migrations/20240121172024-add-auto-skip-fields-to-rooms.js
  • server/models/room.ts
  • server/storage/room.ts
Additional comments: 2
common/constants.ts (1)
  • 17-25: The addition of ALL_SKIP_CATEGORIES is aligned with the PR's objective to support individual toggles for auto-skipping different video segment categories. This constant provides a centralized list of all available categories, which is a good practice for maintainability and consistency across the application.
server/tests/unit/api/room.spec.ts (1)
  • 374-446: The test suite for validating autoSkipSegmentCategories effectively covers various scenarios, including duplicate categories, invalid categories, and empty arrays. This ensures that the application correctly filters and saves only unique and valid auto-skip segment categories. The use of it.each for parameterized tests enhances test readability and maintainability.

server/room.ts Outdated Show resolved Hide resolved
server/room.ts Outdated Show resolved Hide resolved
server/room.ts Show resolved Hide resolved
Copy link
Owner

@dyc3 dyc3 left a comment

Choose a reason for hiding this comment

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

I'll be able to give you better feedback once all the lints are fixed.

client/src/components/RoomSettingsForm.vue Outdated Show resolved Hide resolved
server/tests/unit/api/room.spec.ts Outdated Show resolved Hide resolved
client/src/components/RoomSettingsForm.vue Outdated Show resolved Hide resolved
server/tests/unit/api/room.spec.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@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.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 4267158 and bb40b34.
Files selected for processing (4)
  • client/src/components/RoomSettingsForm.vue (6 hunks)
  • server/migrations/20240121172024-add-auto-skip-fields-to-rooms.js (1 hunks)
  • server/room.ts (15 hunks)
  • server/tests/unit/api/room.spec.ts (1 hunks)
Files skipped from review as they are similar to previous changes (4)
  • client/src/components/RoomSettingsForm.vue
  • server/migrations/20240121172024-add-auto-skip-fields-to-rooms.js
  • server/room.ts
  • server/tests/unit/api/room.spec.ts

Copy link
Contributor

@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.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between bb40b34 and 9cd9949.
Files selected for processing (1)
  • server/tests/unit/api/room.spec.ts (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • server/tests/unit/api/room.spec.ts

@ceofil
Copy link
Contributor Author

ceofil commented Jan 30, 2024

When I run yarn lint locally I get a bunch of errors regarding "describe", "it" and "expect" not being defined and then it exits with code 1.

Is there something I should change in the config?

Output

....

/home/teofil/projects/opentogethertube/common/ts-out/tests/unit/voteskip.spec.js
2:1 error 'describe' is not defined no-undef
3:2 error 'it' is not defined no-undef
21:3 error 'expect' is not defined no-undef

✖ 110 problems (110 errors, 0 warnings)

error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
error Command failed.
Exit code: 1
Command: /usr/bin/node
Arguments: /usr/local/lib/node_modules/yarn/lib/cli.js run lint
Directory: /home/teofil/projects/opentogethertube/common
Output:

info Visit https://yarnpkg.com/en/docs/cli/workspaces for documentation about this command.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

@dyc3
Copy link
Owner

dyc3 commented Jan 30, 2024

Ah yeah I've fixed that on master. You can either rebase/merge master or delete the directories common/ts-out and server/ts-out

Copy link
Contributor

@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.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 9cd9949 and 38d11bf.
Files selected for processing (1)
  • server/room.ts (15 hunks)
Files skipped from review as they are similar to previous changes (1)
  • server/room.ts

Copy link
Owner

@dyc3 dyc3 left a comment

Choose a reason for hiding this comment

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

When I was doing manual testing using the dev server, I couldn't get in a room because of this error.

image

However, building the client manually it worked fine. I suspect this is yarn being stupid again. Does it work for you when using yarn run dev?

server/room.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@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.

Review Status

Actionable comments generated: 4

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 38d11bf and f690855.
Files selected for processing (2)
  • server/migrations/20240121172024-add-auto-skip-fields-to-rooms.js (1 hunks)
  • server/room.ts (15 hunks)
Additional comments: 7
server/migrations/20240121172024-add-auto-skip-fields-to-rooms.js (1)
  • 20-24: Ensure that setting "autoSkipSegmentCategories" to an empty array ('[]') for rooms where "autoSkipSegments" is false aligns with the application's expected behavior. This logic assumes all rooms with autoSkipSegments disabled should have no categories selected for auto-skipping, which might not be intuitive for end-users or consistent with future requirements.
server/room.ts (6)
  • 228-228: The initialization of _autoSkipSegmentCategories with Array.from(ALL_SKIP_CATEGORIES) ensures all categories are enabled by default. Confirm this default behavior aligns with user expectations and the application's requirements.
  • 394-400: Getter and setter for autoSkipSegmentCategories correctly manage the internal state and mark the property as dirty when changed. This is consistent with the class's design pattern for property management.
  • 543-543: The condition to set wantSponsorBlock to true based on the presence of auto-skip categories and a current source is logical. However, ensure that this logic is invoked at appropriate times to avoid unnecessary SponsorBlock requests, especially in scenarios where the current video does not support SponsorBlock data.
  • 1566-1578: The logic to filter autoSkipSegmentCategories against ALL_SKIP_CATEGORIES ensures that only valid categories are saved. This is a good practice for data integrity. However, ensure that the application's UI and backend validation align to prevent invalid categories from being submitted in the first place.
  • 1601-1606: The condition to fetch SponsorBlock segments upon enabling auto-skip categories during a live session is appropriate. This proactive approach enhances the user experience by applying the new settings immediately.
  • 1648-1648: Setting wantSponsorBlock to true in playNow when auto-skip categories are enabled ensures that the newly played video fetches relevant SponsorBlock segments. This maintains consistency with the auto-skip feature's behavior across different user actions.

@ceofil
Copy link
Contributor Author

ceofil commented Feb 8, 2024

When I was doing manual testing using the dev server, I couldn't get in a room because of this error.

image

However, building the client manually it worked fine. I suspect this is yarn being stupid again. Does it work for you when using yarn run dev?

Yup, everything works fine when I run yarn run dev

Copy link
Contributor

@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.

Review Status

Actionable comments generated: 1

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between f690855 and 810864d.
Files selected for processing (1)
  • client/src/locales/en.ts (1 hunks)

client/src/locales/en.ts Show resolved Hide resolved
@dyc3
Copy link
Owner

dyc3 commented Feb 10, 2024

I've resolved the import issues with ott-common. I don't have perms to push to this branch, can you merge master into here again?

Copy link
Owner

@dyc3 dyc3 left a comment

Choose a reason for hiding this comment

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

Looks good! Just merge master into here and I'll be able to get this deployed safely.

Copy link
Contributor

@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.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 810864d and 3f6f40d.
Files selected for processing (1)
  • server/room.ts (15 hunks)
Files skipped from review as they are similar to previous changes (1)
  • server/room.ts

@dyc3 dyc3 merged commit a8c02a5 into dyc3:master Feb 11, 2024
16 of 19 checks passed
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.

separate toggles for auto-skip categories
2 participants