mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-08-19 17:01:12 +00:00
Federated user activity following: Isolated model changes (#8078)
This PR is part of https://codeberg.org/forgejo/forgejo/pulls/4767 This should not have an outside impact but bring all model changes needed & bring migrations. Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/8078 Reviewed-by: Earl Warren <earl-warren@noreply.codeberg.org> Co-authored-by: Michael Jerger <michael.jerger@meissa-gmbh.de> Co-committed-by: Michael Jerger <michael.jerger@meissa-gmbh.de>
This commit is contained in:
parent
1c0e9d8015
commit
25d596d387
19 changed files with 604 additions and 48 deletions
|
@ -39,6 +39,24 @@ func NewNotifier() notify_service.Notifier {
|
|||
return &actionNotifier{}
|
||||
}
|
||||
|
||||
func notifyAll(ctx context.Context, action *activities_model.Action) error {
|
||||
_, err := activities_model.NotifyWatchers(ctx, action)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return err
|
||||
// return federation_service.NotifyActivityPubFollowers(ctx, out)
|
||||
}
|
||||
|
||||
func notifyAllActions(ctx context.Context, acts []*activities_model.Action) error {
|
||||
_, err := activities_model.NotifyWatchersActions(ctx, acts)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
// return federation_service.NotifyActivityPubFollowers(ctx, out)
|
||||
}
|
||||
|
||||
func (a *actionNotifier) NewIssue(ctx context.Context, issue *issues_model.Issue, mentions []*user_model.User) {
|
||||
if err := issue.LoadPoster(ctx); err != nil {
|
||||
log.Error("issue.LoadPoster: %v", err)
|
||||
|
@ -50,7 +68,7 @@ func (a *actionNotifier) NewIssue(ctx context.Context, issue *issues_model.Issue
|
|||
}
|
||||
repo := issue.Repo
|
||||
|
||||
if err := activities_model.NotifyWatchers(ctx, &activities_model.Action{
|
||||
if err := notifyAll(ctx, &activities_model.Action{
|
||||
ActUserID: issue.Poster.ID,
|
||||
ActUser: issue.Poster,
|
||||
OpType: activities_model.ActionCreateIssue,
|
||||
|
@ -91,7 +109,7 @@ func (a *actionNotifier) IssueChangeStatus(ctx context.Context, doer *user_model
|
|||
}
|
||||
|
||||
// Notify watchers for whatever action comes in, ignore if no action type.
|
||||
if err := activities_model.NotifyWatchers(ctx, act); err != nil {
|
||||
if err := notifyAll(ctx, act); err != nil {
|
||||
log.Error("NotifyWatchers: %v", err)
|
||||
}
|
||||
}
|
||||
|
@ -127,7 +145,7 @@ func (a *actionNotifier) CreateIssueComment(ctx context.Context, doer *user_mode
|
|||
}
|
||||
|
||||
// Notify watchers for whatever action comes in, ignore if no action type.
|
||||
if err := activities_model.NotifyWatchers(ctx, act); err != nil {
|
||||
if err := notifyAll(ctx, act); err != nil {
|
||||
log.Error("NotifyWatchers: %v", err)
|
||||
}
|
||||
}
|
||||
|
@ -146,7 +164,7 @@ func (a *actionNotifier) NewPullRequest(ctx context.Context, pull *issues_model.
|
|||
return
|
||||
}
|
||||
|
||||
if err := activities_model.NotifyWatchers(ctx, &activities_model.Action{
|
||||
if err := notifyAll(ctx, &activities_model.Action{
|
||||
ActUserID: pull.Issue.Poster.ID,
|
||||
ActUser: pull.Issue.Poster,
|
||||
OpType: activities_model.ActionCreatePullRequest,
|
||||
|
@ -160,7 +178,7 @@ func (a *actionNotifier) NewPullRequest(ctx context.Context, pull *issues_model.
|
|||
}
|
||||
|
||||
func (a *actionNotifier) RenameRepository(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, oldRepoName string) {
|
||||
if err := activities_model.NotifyWatchers(ctx, &activities_model.Action{
|
||||
if err := notifyAll(ctx, &activities_model.Action{
|
||||
ActUserID: doer.ID,
|
||||
ActUser: doer,
|
||||
OpType: activities_model.ActionRenameRepo,
|
||||
|
@ -174,7 +192,7 @@ func (a *actionNotifier) RenameRepository(ctx context.Context, doer *user_model.
|
|||
}
|
||||
|
||||
func (a *actionNotifier) TransferRepository(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, oldOwnerName string) {
|
||||
if err := activities_model.NotifyWatchers(ctx, &activities_model.Action{
|
||||
if err := notifyAll(ctx, &activities_model.Action{
|
||||
ActUserID: doer.ID,
|
||||
ActUser: doer,
|
||||
OpType: activities_model.ActionTransferRepo,
|
||||
|
@ -188,7 +206,7 @@ func (a *actionNotifier) TransferRepository(ctx context.Context, doer *user_mode
|
|||
}
|
||||
|
||||
func (a *actionNotifier) CreateRepository(ctx context.Context, doer, u *user_model.User, repo *repo_model.Repository) {
|
||||
if err := activities_model.NotifyWatchers(ctx, &activities_model.Action{
|
||||
if err := notifyAll(ctx, &activities_model.Action{
|
||||
ActUserID: doer.ID,
|
||||
ActUser: doer,
|
||||
OpType: activities_model.ActionCreateRepo,
|
||||
|
@ -201,7 +219,7 @@ func (a *actionNotifier) CreateRepository(ctx context.Context, doer, u *user_mod
|
|||
}
|
||||
|
||||
func (a *actionNotifier) ForkRepository(ctx context.Context, doer *user_model.User, oldRepo, repo *repo_model.Repository) {
|
||||
if err := activities_model.NotifyWatchers(ctx, &activities_model.Action{
|
||||
if err := notifyAll(ctx, &activities_model.Action{
|
||||
ActUserID: doer.ID,
|
||||
ActUser: doer,
|
||||
OpType: activities_model.ActionCreateRepo,
|
||||
|
@ -266,13 +284,13 @@ func (a *actionNotifier) PullRequestReview(ctx context.Context, pr *issues_model
|
|||
actions = append(actions, action)
|
||||
}
|
||||
|
||||
if err := activities_model.NotifyWatchersActions(ctx, actions); err != nil {
|
||||
if err := notifyAllActions(ctx, actions); err != nil {
|
||||
log.Error("notify watchers '%d/%d': %v", review.Reviewer.ID, review.Issue.RepoID, err)
|
||||
}
|
||||
}
|
||||
|
||||
func (*actionNotifier) MergePullRequest(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest) {
|
||||
if err := activities_model.NotifyWatchers(ctx, &activities_model.Action{
|
||||
if err := notifyAll(ctx, &activities_model.Action{
|
||||
ActUserID: doer.ID,
|
||||
ActUser: doer,
|
||||
OpType: activities_model.ActionMergePullRequest,
|
||||
|
@ -286,7 +304,7 @@ func (*actionNotifier) MergePullRequest(ctx context.Context, doer *user_model.Us
|
|||
}
|
||||
|
||||
func (*actionNotifier) AutoMergePullRequest(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest) {
|
||||
if err := activities_model.NotifyWatchers(ctx, &activities_model.Action{
|
||||
if err := notifyAll(ctx, &activities_model.Action{
|
||||
ActUserID: doer.ID,
|
||||
ActUser: doer,
|
||||
OpType: activities_model.ActionAutoMergePullRequest,
|
||||
|
@ -304,7 +322,7 @@ func (*actionNotifier) NotifyPullRevieweDismiss(ctx context.Context, doer *user_
|
|||
if len(review.OriginalAuthor) > 0 {
|
||||
reviewerName = review.OriginalAuthor
|
||||
}
|
||||
if err := activities_model.NotifyWatchers(ctx, &activities_model.Action{
|
||||
if err := notifyAll(ctx, &activities_model.Action{
|
||||
ActUserID: doer.ID,
|
||||
ActUser: doer,
|
||||
OpType: activities_model.ActionPullReviewDismissed,
|
||||
|
@ -342,7 +360,7 @@ func (a *actionNotifier) PushCommits(ctx context.Context, pusher *user_model.Use
|
|||
opType = activities_model.ActionDeleteBranch
|
||||
}
|
||||
|
||||
if err = activities_model.NotifyWatchers(ctx, &activities_model.Action{
|
||||
if err = notifyAll(ctx, &activities_model.Action{
|
||||
ActUserID: pusher.ID,
|
||||
ActUser: pusher,
|
||||
OpType: opType,
|
||||
|
@ -362,7 +380,7 @@ func (a *actionNotifier) CreateRef(ctx context.Context, doer *user_model.User, r
|
|||
// has sent same action in `PushCommits`, so skip it.
|
||||
return
|
||||
}
|
||||
if err := activities_model.NotifyWatchers(ctx, &activities_model.Action{
|
||||
if err := notifyAll(ctx, &activities_model.Action{
|
||||
ActUserID: doer.ID,
|
||||
ActUser: doer,
|
||||
OpType: opType,
|
||||
|
@ -381,7 +399,7 @@ func (a *actionNotifier) DeleteRef(ctx context.Context, doer *user_model.User, r
|
|||
// has sent same action in `PushCommits`, so skip it.
|
||||
return
|
||||
}
|
||||
if err := activities_model.NotifyWatchers(ctx, &activities_model.Action{
|
||||
if err := notifyAll(ctx, &activities_model.Action{
|
||||
ActUserID: doer.ID,
|
||||
ActUser: doer,
|
||||
OpType: opType,
|
||||
|
@ -405,7 +423,7 @@ func (a *actionNotifier) SyncPushCommits(ctx context.Context, pusher *user_model
|
|||
return
|
||||
}
|
||||
|
||||
if err := activities_model.NotifyWatchers(ctx, &activities_model.Action{
|
||||
if err := notifyAll(ctx, &activities_model.Action{
|
||||
ActUserID: repo.OwnerID,
|
||||
ActUser: repo.MustOwner(ctx),
|
||||
OpType: activities_model.ActionMirrorSyncPush,
|
||||
|
@ -420,7 +438,7 @@ func (a *actionNotifier) SyncPushCommits(ctx context.Context, pusher *user_model
|
|||
}
|
||||
|
||||
func (a *actionNotifier) SyncCreateRef(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, refFullName git.RefName, refID string) {
|
||||
if err := activities_model.NotifyWatchers(ctx, &activities_model.Action{
|
||||
if err := notifyAll(ctx, &activities_model.Action{
|
||||
ActUserID: repo.OwnerID,
|
||||
ActUser: repo.MustOwner(ctx),
|
||||
OpType: activities_model.ActionMirrorSyncCreate,
|
||||
|
@ -434,7 +452,7 @@ func (a *actionNotifier) SyncCreateRef(ctx context.Context, doer *user_model.Use
|
|||
}
|
||||
|
||||
func (a *actionNotifier) SyncDeleteRef(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, refFullName git.RefName) {
|
||||
if err := activities_model.NotifyWatchers(ctx, &activities_model.Action{
|
||||
if err := notifyAll(ctx, &activities_model.Action{
|
||||
ActUserID: repo.OwnerID,
|
||||
ActUser: repo.MustOwner(ctx),
|
||||
OpType: activities_model.ActionMirrorSyncDelete,
|
||||
|
@ -452,7 +470,7 @@ func (a *actionNotifier) NewRelease(ctx context.Context, rel *repo_model.Release
|
|||
log.Error("LoadAttributes: %v", err)
|
||||
return
|
||||
}
|
||||
if err := activities_model.NotifyWatchers(ctx, &activities_model.Action{
|
||||
if err := notifyAll(ctx, &activities_model.Action{
|
||||
ActUserID: rel.PublisherID,
|
||||
ActUser: rel.Publisher,
|
||||
OpType: activities_model.ActionPublishRelease,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue