Skip to content

Nostr Cross Posting Delay #2206

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

Draft
wants to merge 22 commits into
base: master
Choose a base branch
from
Draft

Conversation

axelvyrn
Copy link

@axelvyrn axelvyrn commented Jun 4, 2025

Description

Closes #2194

This PR implements delayed crossposting from Stacker News (SN) to Nostr. When a user creates a post and selects "crosspost to Nostr," the post is not immediately sent to Nostr. Instead, the backend schedules the crosspost to occur 10 minutes after creation, allowing the user to edit the post within that window. Only the final version after 10 minutes is sent to Nostr.

What I changed and Why:

  • Editing a post within the 10-minute window does not result in multiple Nostr posts; only the latest version is sent.
  • The frontend no longer triggers the crosspost directly; it only passes the crosspost flag to the backend.
  • The backend handles scheduling, rescheduling (on edit), and execution of the crosspost.
  • A background worker processes and sends eligible posts to Nostr after the delay.

Code references:

  • schema.prisma and migration: Added pendingNostrCrosspost and nostrCrosspostAt fields to the Item model.
  • item.js:
    • On post creation with crosspost, sets the pending flag and schedules the crosspost.
    • On edit within the 10-minute window, reschedules the crosspost to ensure only the final version is sent.
  • nostrCrosspost.js: New worker to process and send delayed crossposts.
  • index.js: Registers the new worker.
  • scheduleNostrCrosspost.js: Schedules the worker to run every minute.
  • use-item-submit.js: No longer calls the crossposter directly; relies on backend scheduling.
  • nostrCrosspost.test.js: Automated test verifies the worker logic.
  • Removed: Obsolete test file use-item-submit.test.js (see diff).

Screenshots

Screenshot 2025-06-10 124631

update

Additional Context

  • This was not easy, lol. The tag should really be updated for Duplicate post send to Nostr when editing SN #2194 . The logic required careful backend and worker coordination to ensure only one Nostr post is sent, even if the SN post is edited multiple times within the window.
  • The test for the old frontend-driven crosspost logic (use-item-submit.test.js) is now obsolete and should be removed when merging.
  • No related packages or dependencies remain in package.json or package-lock.json.
    Additional Context
  • The following test and mock folders/files were created for verification and should be removed when merging:
    use-item-submit.test.js (already removed)
    nostrCrosspost.test.js
    nostr.js
    The entire __tests__ and __mocks__ folders
    No related packages or dependencies remain in package.json or package-lock.json.

Checklist

Are your changes backwards compatible? Please answer below:

  • Yep. Existing posts and edits are unaffected; only the crosspost workflow is updated.

On a scale of 1-10 how well and how have you QA'd this change and any features it might affect? Please answer below:

  • 9/10. Automated tests for the worker logic pass, and manual review confirms the frontend no longer triggers immediate crossposts.

For frontend changes: Tested on mobile, light and dark mode? Please answer below:

  • N/A for UI, but the frontend logic is tested and does not trigger crossposts directly.

Did you introduce any new environment variables? If so, call them out explicitly here:

  • None

axelvyrn added 2 commits June 4, 2025 16:47
added info tooltip for LNURL-auth button
Copy link
Member

@huumn huumn left a comment

Choose a reason for hiding this comment

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

this is not passing linting. run sndev lint to see errors.

Copy link
Member

@huumn huumn left a comment

Choose a reason for hiding this comment

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

You cannot zap after auth'ing from lightning. its just auth .............

@axelvyrn
Copy link
Author

axelvyrn commented Jun 5, 2025

this is not passing linting. run sndev lint to see errors.

checked. fixed the errors.

@axelvyrn axelvyrn requested a review from huumn June 5, 2025 07:08
Copy link
Member

@huumn huumn left a comment

Choose a reason for hiding this comment

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

Screenshot 2025-06-05 at 8 18 20 PM

There is asymmetrical padding around this button now. Also, the info icon is not vertically centered with the button.

@axelvyrn
Copy link
Author

axelvyrn commented Jun 6, 2025

how can that be there is d-flex align-items-center on the parent div.
anyways i'll try something else.

removed extra padding
@axelvyrn
Copy link
Author

axelvyrn commented Jun 6, 2025

this should do

@ekzyis
Copy link
Member

ekzyis commented Jun 6, 2025

Can you post screenshots like mentioned in the PR template?

@axelvyrn
Copy link
Author

axelvyrn commented Jun 6, 2025

i wanted to but i could not.
i was not able to load up the environment :(

@ekzyis
Copy link
Member

ekzyis commented Jun 6, 2025

You weren't able to run the code?

@axelvyrn
Copy link
Author

axelvyrn commented Jun 6, 2025

no. my pc doesn't support docker, and codespaces doesn't open the ports idk why

@ekzyis
Copy link
Member

ekzyis commented Jun 6, 2025

How do you explain your 9 in the QA question?

On a scale of 1-10 how well and how have you QA'd this change and any features it might affect? Please answer below:
9 - it affects the settings UI

@axelvyrn
Copy link
Author

axelvyrn commented Jun 6, 2025

through dev console, i edited the code live

@ekzyis
Copy link
Member

ekzyis commented Jun 6, 2025

That doesn't mean you tested your code which is what QA means ...

@axelvyrn
Copy link
Author

axelvyrn commented Jun 6, 2025

if it was wrong, it would not have showed up on the page right?
even k00b sent the ss here, there were only some padding issues

@axelvyrn
Copy link
Author

axelvyrn commented Jun 8, 2025

is this fine? symmetrical padding on both sides and centered info button?

@axelvyrn axelvyrn requested a review from huumn June 8, 2025 04:04
Copy link

socket-security bot commented Jun 10, 2025

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Addedjest-environment-jsdom@​30.0.0-beta.31001005994100
Added@​testing-library/​react-hooks@​8.0.19910010084100

View full report

@axelvyrn axelvyrn changed the title Settings LNURL UI Update Settings LNURL UI Update & Nostr Cross Posting Delay Jun 10, 2025
Copy link
Member

@ekzyis ekzyis left a comment

Choose a reason for hiding this comment

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

very sorry for 2 PRs in one but Github does not let commit 2 pull requests from 1 branch and I had changed the master branch itself

Create another branch.

@axelvyrn axelvyrn changed the title Settings LNURL UI Update & Nostr Cross Posting Delay Nostr Cross Posting Delay Jun 10, 2025
@axelvyrn axelvyrn requested a review from ekzyis June 10, 2025 17:49
@axelvyrn
Copy link
Author

using user's nostrPubkey now

Copy link
Member

@ekzyis ekzyis left a comment

Choose a reason for hiding this comment

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

Did you read AND understand this comment?

@huumn huumn marked this pull request as draft June 10, 2025 20:20
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.

Duplicate post send to Nostr when editing SN
3 participants