-
-
Notifications
You must be signed in to change notification settings - Fork 114
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
feat: daily stacked and spent sats notification #1756
Open
Soxasora
wants to merge
11
commits into
stackernews:master
Choose a base branch
from
Soxasora:daily_sats_summary_notifications
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
e80fa99
daily summary of stacked and spent sats
Soxasora 057fc59
scales of justice as icon
Soxasora d1663ee
cleanup: query follows satistics design; refactor: DailyStats to SatS…
Soxasora 5d12a90
hasNewNotes now supports noteSatSummary; web push notifications place…
Soxasora 6e4e4ff
enhance: slimmer query, satsummary notification links to full satistics
Soxasora 3795668
2 days interval workaround for different timezones; restore svg
Soxasora b73a0cd
push notifications, add dailySatSummary to pgboss scheduler
Soxasora fb61520
cleanup: typo, old comments
Soxasora 82553a2
hotfix: if stacked and spent are 0, don't show/push notification
Soxasora 421772e
hotfix: new push notification query, adjusted names and props
Soxasora 0bc1872
hotfix: convert msats to sats for push notification
Soxasora File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
prisma/migrations/20241222143219_daily_sats_summary_notifications/migration.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
-- AlterTable | ||
ALTER TABLE "users" ADD COLUMN "noteSatSummary" BOOLEAN NOT NULL DEFAULT false; |
16 changes: 16 additions & 0 deletions
16
prisma/migrations/20241223184742_satsummary_job/migration.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
CREATE OR REPLACE FUNCTION check_daily_sats_summary() | ||
RETURNS INTEGER | ||
LANGUAGE plpgsql | ||
AS $$ | ||
DECLARE | ||
BEGIN | ||
INSERT INTO pgboss.schedule (name, cron, timezone) | ||
VALUES ('dailySatSummary', '0 0 * * *', 'America/Chicago') ON CONFLICT DO NOTHING; | ||
return 0; | ||
EXCEPTION WHEN OTHERS THEN | ||
return 0; | ||
END; | ||
$$; | ||
|
||
SELECT check_daily_sats_summary(); | ||
DROP FUNCTION IF EXISTS check_daily_sats_summary; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { notifySatSummary } from '@/lib/webPush' | ||
import { msatsToSats } from '@/lib/format' | ||
export async function dailySatSummary ({ models }) { | ||
try { | ||
const stats = await models.$queryRaw` | ||
SELECT | ||
id as userId, sum(msats_stacked) as stacked, sum(msats_spent) as spent | ||
FROM user_stats_days | ||
WHERE t >= date_trunc('day', CURRENT_DATE - INTERVAL '1 day') | ||
AND t <= date_trunc('day', CURRENT_DATE) | ||
GROUP BY id | ||
HAVING sum(msats_stacked) != 0 OR sum(msats_spent) != 0 | ||
` | ||
|
||
if (stats.length) { | ||
for (const stat of stats) { | ||
const user = await models.user.findUnique({ where: { id: stat.userid } }) | ||
if (user && user.noteSatSummary) { | ||
await notifySatSummary( | ||
stat.userid, | ||
(stats.stacked && msatsToSats(stats.stacked)) || 0, | ||
(stats.spent && msatsToSats(stats.spent)) || 0 | ||
) | ||
} | ||
} | ||
} | ||
} catch (err) { | ||
console.error('failed to process daily sat summary', err) | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
realized I didn't push this before, sorry