-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
policyeval: actually evaluate rules on startup
- Loading branch information
Showing
10 changed files
with
449 additions
and
320 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package policyeval | ||
|
||
import ( | ||
"context" | ||
"maps" | ||
"slices" | ||
|
||
"github.com/rs/zerolog" | ||
"maunium.net/go/mautrix/id" | ||
|
||
"go.mau.fi/meowlnir/policylist" | ||
) | ||
|
||
func (pe *PolicyEvaluator) EvaluateAll(ctx context.Context) { | ||
pe.usersLock.RLock() | ||
users := slices.Collect(maps.Keys(pe.users)) | ||
pe.usersLock.RUnlock() | ||
pe.EvaluateAllMembers(ctx, users) | ||
} | ||
|
||
func (pe *PolicyEvaluator) EvaluateAllMembers(ctx context.Context, members []id.UserID) { | ||
for _, member := range members { | ||
pe.EvaluateNewMember(ctx, member) | ||
} | ||
} | ||
|
||
func (pe *PolicyEvaluator) EvaluateNewMember(ctx context.Context, userID id.UserID) { | ||
match := pe.Store.MatchUser(pe.GetWatchedLists(), userID) | ||
if match == nil { | ||
return | ||
} | ||
zerolog.Ctx(ctx).Info(). | ||
Stringer("user_id", userID). | ||
Any("recommendation", match.Recommendations()). | ||
Any("matches", match). | ||
Msg("Matched user in membership event") | ||
} | ||
|
||
func (pe *PolicyEvaluator) EvaluateRemovedRule(ctx context.Context, policy *policylist.Policy) { | ||
// TODO | ||
} | ||
|
||
func (pe *PolicyEvaluator) EvaluateAddedRule(ctx context.Context, policy *policylist.Policy) { | ||
// TODO | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.