-
Notifications
You must be signed in to change notification settings - Fork 3
Implement notification counts #1
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
Open
Fizzadar
wants to merge
6
commits into
main
Choose a base branch
from
nick/add-notification-counts
base: main
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 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
c459bfb
Implement notification counts
Fizzadar c868cfa
Add `Databases.SendToDeviceEvents` method
Fizzadar 66f95c3
Remove unncessary enabled configs
Fizzadar 699ca8f
Implement push rules
Fizzadar 9063fc8
Implement pushers and send push notifications
Fizzadar 7653f1e
Return full change to notifier subscribers
Fizzadar 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 hidden or 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,47 @@ | ||
| Add notification counting for events | ||
|
|
||
| - spec states "The updated notification count from a new event MUST appear in the same /sync response as the event itself." | ||
| - store as rooms.users.notificationVersions (userid, roomid, version) -> types.Notifications{notifs, highlights, ...} | ||
| - store types.Notifications as msgpack with single letter keys | ||
| - for every event send we must (SendLocalEvents, SendFederatedEvents): | ||
| - get local users in the room | ||
| - get all their push rules (stub these for now), before any write txn | ||
| - inside the txn for each event, eval each users rules, map eventsToUserNotifications[id.EventID]types.Notifications{} | ||
| - pass to txnStoreEvents, we apply notificationVersions (userid, roomid, eventVersion) -> types.Notifications{} | ||
| - version is the event version (so can get back to the eventid) | ||
| - on sync, just | ||
| - range notificationVersions (userid, roomid) => sum counts | ||
| - on receipt just | ||
| - clearrange up to (userid, roomid, eventVersionFromReceipt) | ||
|
|
||
| Explore the codebase and come up with a plan to implement the above changes. | ||
|
|
||
| ... implemented, second prompt: | ||
|
|
||
| Now we need to implement an EventNotificationIterator to compact notificationVersions: | ||
|
|
||
| - compact notificationVersions by aggregating old -> new (userid, roomid, version) | ||
| - just iter events constantly compact | ||
| - so should just be merging 2 -> 1 constantly, unless falls behind | ||
| - note: in future this worker will also actually turn each (unaggregated) notification into an actual notification for each of the users configured push targets | ||
|
|
||
| Explore the codebase and come up with a plan to implement the above changes. | ||
|
|
||
| ... implemented, third prompt | ||
|
|
||
| Let's extend notification counts to handle threads. We need to: | ||
|
|
||
| - add ThreadID to types.Notifications (already done) | ||
| - in eventsend.go, we: | ||
| - move the notification generation into a new read txn, just before each write txn | ||
| - include threadID in generated notifications, this is: | ||
| - "" if event has no relation | ||
| - $event_id of thread root (found by walking thread relations of m.thread type until no more) | ||
| - we need two ways to sum notifications: | ||
| - the current one is fine for non-threading clients | ||
| - new sum by threadID version | ||
| - update sync | ||
| - add SyncOption to enable threaded notification counts | ||
| - when set, sum by threadID and update sync response accordingly | ||
|
|
||
| Explore the codebase and come up with a plan to implement the above changes. |
This file contains hidden or 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,26 @@ | ||
| Add push rules to the accounts database | ||
|
|
||
| - store Matrix push rules in a new directory in the accounts database, keys: | ||
| - userPushRules (userID, groupName, kind, ruleID) -> partial mautrix.PushRule | ||
| - kind is one of: override, underride, sender, room, content | ||
| - userPushVersions (userID) -> versionstamp of last written rule | ||
| - new methods: | ||
| - AccountsDatabase.GetRulesForUser | ||
| - AccountsDatabase.GetRuleForUser | ||
| - AccountsDatabase.PutRuleForUser | ||
| - AccountsDatabase.DeleteRuleForUser | ||
| - sync must return all the users push rules if the userPushVersion > the sync token as m.push_rules account data event | ||
|
|
||
| Explore the codebase and come up with a plan to implement the above changes. | ||
|
|
||
| ... implemented, second prompt: | ||
|
|
||
| Now we need to evaluate the push rules during event sending. | ||
|
|
||
| - add databases.SendLocalEvents which calls rooms.SendLocalEvents | ||
| - modify rooms.SendLocalEvents to take userid -> pushrules map | ||
| - databases.SendLocalEvents fetches local users in room -> makes the map | ||
| - rooms.SendLocalEvents then uses push rules for evaluation | ||
| - same for databases.SendFederatedEvents -> rooms.SendFederatedEvents | ||
|
|
||
| Explore the codebase and come up with a plan to implement. |
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -5,4 +5,4 @@ ed25519-* | |
| *.pem | ||
| babbleserv | ||
| external/ | ||
| .claude/ | ||
| .claude/settings.local.json | ||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,64 @@ | ||
| package accounts | ||
|
|
||
| import ( | ||
| "context" | ||
|
|
||
| "github.com/apple/foundationdb/bindings/go/src/fdb" | ||
| "github.com/apple/foundationdb/bindings/go/src/fdb/tuple" | ||
| "maunium.net/go/mautrix/id" | ||
| "maunium.net/go/mautrix/pushrules" | ||
|
|
||
| "github.com/beeper/babbleserv/internal/notifier" | ||
| "github.com/beeper/babbleserv/internal/types" | ||
| "github.com/beeper/babbleserv/internal/util" | ||
| ) | ||
|
|
||
| func (a *AccountsDatabase) GetPushRulesForUser(ctx context.Context, userID id.UserID) (*pushrules.PushRuleset, error) { | ||
| return util.DoReadTransaction(ctx, a.db, func(txn fdb.ReadTransaction) (*pushrules.PushRuleset, error) { | ||
| return a.pushrules.TxnGetRulesForUser(txn, userID) | ||
| }) | ||
| } | ||
|
|
||
| func (a *AccountsDatabase) GetPushRulesForUserByKind(ctx context.Context, userID id.UserID, kind pushrules.PushRuleType) ([]*pushrules.PushRule, error) { | ||
| return util.DoReadTransaction(ctx, a.db, func(txn fdb.ReadTransaction) ([]*pushrules.PushRule, error) { | ||
| return a.pushrules.TxnGetRulesForUserByKind(txn, userID, kind) | ||
| }) | ||
| } | ||
|
|
||
| func (a *AccountsDatabase) GetPushRuleForUser(ctx context.Context, userID id.UserID, kind pushrules.PushRuleType, ruleID string) (*pushrules.PushRule, error) { | ||
| return util.DoReadTransaction(ctx, a.db, func(txn fdb.ReadTransaction) (*pushrules.PushRule, error) { | ||
| return a.pushrules.TxnGetRuleForUser(txn, userID, kind, ruleID) | ||
| }) | ||
| } | ||
|
|
||
| func (a *AccountsDatabase) PutPushRuleForUser(ctx context.Context, userID id.UserID, kind pushrules.PushRuleType, ruleID string, rule *types.StoredPushRule) error { | ||
| _, err := util.DoWriteTransactionWithVersion(ctx, a.db, func(txn fdb.Transaction) (types.Nil, error) { | ||
| a.pushrules.TxnPutRuleForUser(txn, userID, kind, ruleID, rule) | ||
| return nil, nil | ||
| }) | ||
| if err == nil { | ||
| a.notifier.SendChange(notifier.Change{ | ||
| UserIDs: []id.UserID{userID}, | ||
| }) | ||
| } | ||
| return err | ||
| } | ||
|
|
||
| func (a *AccountsDatabase) DeletePushRuleForUser(ctx context.Context, userID id.UserID, kind pushrules.PushRuleType, ruleID string) error { | ||
| _, err := util.DoWriteTransactionWithVersion(ctx, a.db, func(txn fdb.Transaction) (types.Nil, error) { | ||
| a.pushrules.TxnDeleteRuleForUser(txn, userID, kind, ruleID) | ||
| return nil, nil | ||
| }) | ||
| if err == nil { | ||
| a.notifier.SendChange(notifier.Change{ | ||
| UserIDs: []id.UserID{userID}, | ||
| }) | ||
| } | ||
| return err | ||
| } | ||
|
|
||
| func (a *AccountsDatabase) GetUserPushRulesVersion(ctx context.Context, userID id.UserID) (tuple.Versionstamp, error) { | ||
| return util.DoReadTransaction(ctx, a.db, func(txn fdb.ReadTransaction) (tuple.Versionstamp, error) { | ||
| return a.pushrules.TxnGetUserPushVersion(txn, userID), nil | ||
| }) | ||
| } |
Oops, something went wrong.
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.
Typo: "evens" should be "events".
📝 Committable suggestion
🧰 Tools
🪛 LanguageTool
[grammar] ~47-~47: Ensure spelling is correct
Context: ...ons
API will not returnm.annotationevens unless therel_type` is explicitly spe...(QB_NEW_EN_ORTHOGRAPHY_ERROR_IDS_1)
🤖 Prompt for AI Agents