49 Commits

Author SHA1 Message Date
d27dbd5fba add nostr_event to notification data 2025-05-22 13:11:29 +01:00
cbe9a65ccf chore: update readme 2025-05-21 18:05:43 +01:00
e2bdbf3c0c feat: setup alt backends
feat: FCM backend
2025-05-21 18:03:42 +01:00
e73f5ce70e Do not send notifications for future notes
Changelog-Fixed: Do not send notifications for future notes

Closes: https://github.com/damus-io/damus/issues/2949
Signed-off-by: Terry Yiu <git@tyiu.xyz>
2025-04-21 17:17:15 -07:00
11ee57f0bb Add hellthread notification filtering based on settings
Changelog-Added: Add hellthread notification filtering based on settings
Closes: https://github.com/damus-io/damus/issues/2943
Signed-off-by: Terry Yiu <git@tyiu.xyz>
2025-04-18 16:13:06 -07:00
63c5f7e723 fix clippy issues
Signed-off-by: William Casarin <jb55@jb55.com>
2025-02-11 10:48:54 -08:00
7bca5bb8ab remove dubious notification logic
Signed-off-by: William Casarin <jb55@jb55.com>
2025-02-11 10:37:57 -08:00
e00dc0b8b0 test: add self zap test
it passes! very strange

Signed-off-by: William Casarin <jb55@jb55.com>
2025-02-11 10:37:57 -08:00
ee445f34d8 makefile: switch to rustytags
Signed-off-by: William Casarin <jb55@jb55.com>
2025-02-11 10:37:57 -08:00
6d4638e653 nix: switch to rustup
Signed-off-by: William Casarin <jb55@jb55.com>
2025-02-11 10:37:57 -08:00
bfcc6e27e9 rustfmt
Signed-off-by: William Casarin <jb55@jb55.com>
2024-12-09 09:35:34 -08:00
c67a0b5e06 cache: switch to Instant-based timestamps and improve test coverage
- Replaced `nostr::Timestamp` usage with `Instant` to streamline
  expiration checks.

- Adjusted `CacheEntry::is_expired()` to rely on `Instant::elapsed()`,
  simplifying logic.

- Added comprehensive tests for:
	- Contact lists, mute lists, relay lists retrieval.
	- Handling of expired entries.
	- Proper behavior with empty entries.
	- Re-insertion of events after empty entries.

- Fixed previously failing tests by ensuring expiration logic aligns
  with real-time durations.

Signed-off-by: William Casarin <jb55@jb55.com>
2024-12-09 13:49:08 +09:00
e3c9e2834e cache: refactor cache structure and reduce allocations
This commit reworks the cache data structures and operations to
significantly cut down on unnecessary allocations and improve overall
cache management logic.

Key changes include:

- Replacing event-specific CacheEntry types with a generic CacheEntry<T>
  that stores values and timestamps.

- Removing the old Arc references in HashMap entries, reducing
  reference-counted pointer overhead.

- Providing helper methods (new(), maybe(), empty(), value()) on
  CacheEntry for more ergonomic and explicit value handling.

- Simplifying the retrieval functions (get_mute_list, get_relay_list,
  get_contact_list) by using a shared helper (get_cache_entry) that
  checks for expiration and removes stale entries automatically.

- Streamlining add_event and related cache insertion methods to insert
  the correct CacheEntry variant depending on the event kind.

- Removing unnecessary methods (e.g., references_pubkey) and simplifying
  extensions in nostr_event_extensions.rs.

- Enhancing code clarity by separating expiration logic from retrieval
  and insertion, making the cache easier to maintain, debug, and extend.

These improvements should reduce runtime memory overhead and increase
code clarity, while maintaining the existing external behavior of the
cache. Future changes will be easier to implement, as the new generic
CacheEntry abstraction and simplified code paths provide a more
maintainable foundation.

Signed-off-by: William Casarin <jb55@jb55.com>
2024-12-09 13:49:08 +09:00
88939ba2d1 Better mute handling
This commit improves the robustness of mute list handling:
1. It listens to new mute lists from the relay interface, and saves them whenever there is a new one
2. It uses the user's own relay lists to fetch events (such as mute lists), helping to ensure we get their mute lists even when they are not stored in the Damus relay
3. It saves events it sees when fetching them from the network, if applicable

Changelog-Changed: Improved robustness of mute handling
Signed-off-by: Daniel D’Aquino <daniel@daquino.me>
2024-12-09 13:49:08 +09:00
f6bbc9e1fe Merge pull request #7 from danieldaquino/#2434
Fix issue with multiple device tokens
2024-09-07 14:01:39 -07:00
f9885b01aa Fix issue with multiple device tokens
Testing
-------

Device: iPhone 15 simulator
iOS: 17.5
Damus: 1.10 (8) 3902fe7b30f38ec104c13087948799e38e26fa91 (Local build)
notepush: This commit
Setup:
1. Open app in two separate simulator devices under the same nostr account
2. On both, setup the environment to be local, pointing to the same local notepush
Steps:
1. Go to notification settings and try to set notification mode to "push" on both devices
2. Ensure both can be set to push without displaying an error
3. Ensure preferences can be changed without displaying an error
4. When changing one setting, on both devices go back and forth on the
   notification setting screen and ensure both are independent
5. Send some notifications to this account. Ensure both get the
   notification
6. Disable DM notifications on one device and send a DM. Ensure only one
   device gets the notification
7. Try step 6 again, but with likes (and disabling it on the other device)

Results: PASS
- Can register with both devices
- Both devices get new push notifications
- Settings are independent and get respected on each device.

Signed-off-by: Daniel D’Aquino <daniel@daquino.me>
Closes: https://github.com/damus-io/damus/issues/2434
2024-09-06 18:42:51 -07:00
60450e85da Merge pull request #6 from danieldaquino/2024-08-30-fix
Improvements to caching and APNS token error handling
2024-09-05 14:29:56 -07:00
aff6e0f8ba Improve default fallback reaction formatting
Signed-off-by: Daniel D’Aquino <daniel@daquino.me>
Closes: https://github.com/damus-io/damus/issues/2420
2024-09-04 18:14:41 -07:00
abb3283eaa Do not override user info row on registration endpoint if it already exists
This commit fixes an issue where notification settings would be lost
after restarting Damus, causing unwanted notifications

Signed-off-by: Daniel D’Aquino <daniel@daquino.me>
Closes: https://github.com/damus-io/damus/issues/2417
2024-09-04 14:25:07 -07:00
11568aa628 Make max cache age adjustable in env, and change default to 1 hour
Signed-off-by: Daniel D’Aquino <daniel@daquino.me>
2024-09-02 15:53:13 -07:00
9ec713b807 Fix empty cache entry state
There was an issue where an empty cache entry would get interpreted as a
"no cache entry found" situation and cause notepush to always fetch a
new mutelist

Signed-off-by: Daniel D’Aquino <daniel@daquino.me>
2024-09-02 15:32:59 -07:00
b548665b70 Handle APNS request errors to ensure all device tokens receive a notification
This commit fixes an issue where having one invalid device token
registered can cause other device tokens to not receive push
notifications.

The issue was fixed by improving error handling around APNS requests

Signed-off-by: Daniel D’Aquino <daniel@daquino.me>
Closes: https://github.com/damus-io/damus/issues/2408
2024-08-30 11:34:37 -07:00
2abecf66c2 Switch license to GPL
Signed-off-by: Daniel D’Aquino <daniel@daquino.me>
2024-08-26 12:02:06 -07:00
079d06dddf performance: Check if pubkey is registered before mutelist lookup
Signed-off-by: Daniel D’Aquino <daniel@daquino.me>
2024-08-23 15:06:00 -07:00
2d87c3bcd0 Add more build tools to shell.nix
Signed-off-by: Daniel D’Aquino <daniel@daquino.me>
2024-08-23 14:31:03 -07:00
34cdb6d180 Merge pull request #5 from damus-io/#3
Improve performance with nostr event caching and better mutex design
2024-08-09 14:59:23 -07:00
946ddb0f96 Remove Mutex in front of nostr_network_helper for better performance.
This commit drastically improves the performance of notification manager
by changing the mutex architecture to be only around the cache, instead
of the entire nostr_network_helper.

Furthermore, the lock is acquired twice when getting events that may be
cached (or need caching), to avoid having the cache locked across Nostr fetch requests,
which can take up to 10 seconds each in the worst case scenario.

Testing
--------

Quickly smoke tested sending some events to ensure push notifications
are still working overall

Signed-off-by: Daniel D’Aquino <daniel@daquino.me>
2024-08-05 18:37:06 -07:00
71258e3736 Add Nostr event cache
This commit adds a simple in-memory Nostr Event cache, to reduce the
amount of bandwidth used as well as to improve performance.

Testing
-------

Setup:
  - Two iPhone simulators running Damus and on different accounts
  - Damus version: 774da239b92ed630fbf91fce42d9e233661c0d7f
  - Notepush: This commit
  - Push notifications turned on, setup to connect to localhost, and configured to receive DM notifications
  - Run Notepush with `RUST_LOG=DEBUG` env variable for debug logging
Steps:
1. Send a DM from one account to another.
  - Push notification should arrive with a few seconds delay
  - Push notification logs should mention that the event was cached
2. Send a DM again.
  - Push notification should arrive immediately
3. Wait for more than a minute
4. Send a DM again.
  - Push notification should take a few seconds again
  - Push notification logs should mention that the cache item expired and was deleted

Signed-off-by: Daniel D’Aquino <daniel@daquino.me>
Closes: https://github.com/damus-io/notepush/issues/3
2024-08-05 18:01:52 -07:00
388d49927b Move TimeDelta to its own file for better reusability
Signed-off-by: Daniel D’Aquino <daniel@daquino.me>
2024-08-05 17:57:40 -07:00
384e458118 nostr_network_helper refactor
This commit refactors nostr_network_helper code without substantial business logic changes.

It improves the code by separating concerns, making it more concise, and less repetitive

Signed-off-by: Daniel D’Aquino <daniel@daquino.me>
2024-08-05 15:54:54 -07:00
3ca3a83257 Add support to "only notifications from following" setting
Testing
-------

PASS

Devices: Mix of iPhone simulators and real devices
notepush: This commit
Damus: 4ea6c360e6e33747cb09ecf085049948ec1dadd1 (WIP change from GH issue #2360)
Setup:
  - Account A with push notifications enabled, DM notifications enabled,
    and "only notifications from following enabled"
  - Account A follows B but not C
Steps:
1. Send DM to A from B. Push notification appears
2. Send DM to A from C. Push notification does not appear

Signed-off-by: Daniel D’Aquino <daniel@daquino.me>
Closes: https://github.com/damus-io/damus/issues/2360
2024-08-04 11:57:43 -07:00
c51f37e6ea Push notification preferences
This commit implements basic push notification preferences as well as
the interface to change them.

Furthermore, the API interface was reworked to follow better REST API
conventions.

Testing
--------

PASS

Device: iPhone 15 simulators
iOS: 17.5
Damus: 4ea6c360e6e33747cb09ecf085049948ec1dadd1 (A commit from GH issue #2360)
notepush: This commit
Steps:
1. Disable all types of notifications, except for DMs.
2. Send a like to this user's post. Push notification should not appear. PASS
3. Send a DM to this user's post. Push notification should appear. PASS

Signed-off-by: Daniel D’Aquino <daniel@daquino.me>
2024-08-04 11:55:02 -07:00
d9f8f93e83 Do not send notifications about unsupported nostr event kinds
Signed-off-by: Daniel D’Aquino <daniel@daquino.me>
2024-08-02 18:54:59 -07:00
ee79f04d24 Improve message formatting fallbacks
to something more user-friendly

Signed-off-by: Daniel D’Aquino <daniel@daquino.me>
2024-08-02 18:49:01 -07:00
94778cdf70 Fix nostr event payload on custom data
Previously, the nostr event data was being transformed into
serde::Value, which is incompatible with the current notification
extension implementation. This commit fixes that by serializing it all
into a single JSON string

Signed-off-by: Daniel D’Aquino <daniel@daquino.me>
2024-08-02 18:34:26 -07:00
31ab709b1c Improve logging verbosity
Signed-off-by: Daniel D’Aquino <daniel@daquino.me>
2024-08-02 18:18:43 -07:00
73a7dc1e4a Reduce shared resource contention
This commit should drastically improve performance of the relay.

It reduces contention by removing the mutex on NotificationManager and
replacing it with several smaller mutexes for each shared resource, so
that more operations can happen concurrently.

Signed-off-by: Daniel D’Aquino <daniel@daquino.me>
2024-08-02 17:32:44 -07:00
82c28abff7 Add timeout to mute list fetching
If a relay does not have a user's mutelist, a function in our pipeline
would wait indefinitely, causing all other requests to be locked as
well.

This commit adds a timeout to avoid this issue

Signed-off-by: Daniel D’Aquino <daniel@daquino.me>
2024-08-02 16:49:30 -07:00
697bd4eb83 Add more debug logging for better troubleshooting
Signed-off-by: Daniel D’Aquino <daniel@daquino.me>
2024-08-02 16:49:30 -07:00
db088b1aa3 Unified API + Websockets server
Both API and Websockets are running on the same port

Signed-off-by: Daniel D’Aquino <daniel@daquino.me>
2024-08-02 16:48:56 -07:00
daa2408cfd Remove unused code to fix cargo warnings
Signed-off-by: Daniel D’Aquino <daniel@daquino.me>
2024-08-02 10:24:25 -07:00
8d5c9475ab Merge pull request #2 from damus-io/fmt
run cargo fmt --all
2024-08-02 10:17:42 -07:00
36cc9f8742 run cargo fmt --all
we should try to stick to rustfmt style, many editors save it like this
by default.

Signed-off-by: William Casarin <jb55@jb55.com>
2024-07-31 17:44:48 -07:00
e704f6e24c Make APNS client persistent across sends + better logging
Previously, the APNS client would be reinitialized in every send.
This commit makes it so that the client is initialized with the rest of
Notification manager, to avoid performance and token management issues.
2024-07-31 14:12:23 -07:00
1e591217c5 Web API interface
First implementation of the Web API interface, which can be used to
manage pubkey to APNS token relationships.
2024-07-31 14:11:42 -07:00
3d447e9527 Merge branch 'master' of github.com:damus-io/damus-push-notification-relay
Manually solved conflicts:
- In README.md
- In Cargo.lock, by completely regenerating it.
2024-07-19 22:03:22 -07:00
c0cded7255 Improve relay draft
This commit brings a compilable, runnable relay draft, with logging
setup, basic README instructions, Mutex protection around shared
resources, implemented with code safety in mind

Notes:
- This is not fully tested
- The mutex design is not the most efficient, and could cause some contention on high traffic
- The REST API is not yet integrated
2024-07-19 20:52:30 -07:00
0a6ba2ee11 rename to notepush
Signed-off-by: William Casarin <jb55@jb55.com>
2024-07-11 10:04:44 -07:00
e11c636ce3 Initial draft commit 2024-07-11 09:53:43 -07:00