Move feed notification service layer (#26908)

Extract from #22266
This commit is contained in:
Lunny Xiao 2023-09-05 21:00:52 +08:00 committed by GitHub
parent 65588b732c
commit f064d716c3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 14 additions and 13 deletions

View file

@ -12,7 +12,6 @@ import (
user_model "code.gitea.io/gitea/models/user" user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/notification/action"
"code.gitea.io/gitea/modules/notification/base" "code.gitea.io/gitea/modules/notification/base"
"code.gitea.io/gitea/modules/repository" "code.gitea.io/gitea/modules/repository"
) )
@ -25,11 +24,6 @@ func RegisterNotifier(notifier base.Notifier) {
notifiers = append(notifiers, notifier) notifiers = append(notifiers, notifier)
} }
// NewContext registers notification handlers
func NewContext() {
RegisterNotifier(action.NewNotifier())
}
// NotifyNewWikiPage notifies creating new wiki pages to notifiers // NotifyNewWikiPage notifies creating new wiki pages to notifiers
func NotifyNewWikiPage(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, page, comment string) { func NotifyNewWikiPage(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, page, comment string) {
for _, notifier := range notifiers { for _, notifier := range notifiers {

View file

@ -18,7 +18,6 @@ import (
"code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/markup" "code.gitea.io/gitea/modules/markup"
"code.gitea.io/gitea/modules/markup/external" "code.gitea.io/gitea/modules/markup/external"
"code.gitea.io/gitea/modules/notification"
"code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/ssh" "code.gitea.io/gitea/modules/ssh"
"code.gitea.io/gitea/modules/storage" "code.gitea.io/gitea/modules/storage"
@ -38,6 +37,7 @@ import (
"code.gitea.io/gitea/services/auth/source/oauth2" "code.gitea.io/gitea/services/auth/source/oauth2"
"code.gitea.io/gitea/services/automerge" "code.gitea.io/gitea/services/automerge"
"code.gitea.io/gitea/services/cron" "code.gitea.io/gitea/services/cron"
feed_service "code.gitea.io/gitea/services/feed"
indexer_service "code.gitea.io/gitea/services/indexer" indexer_service "code.gitea.io/gitea/services/indexer"
"code.gitea.io/gitea/services/mailer" "code.gitea.io/gitea/services/mailer"
mailer_incoming "code.gitea.io/gitea/services/mailer/incoming" mailer_incoming "code.gitea.io/gitea/services/mailer/incoming"
@ -119,7 +119,7 @@ func InitWebInstalled(ctx context.Context) {
mailer.NewContext(ctx) mailer.NewContext(ctx)
mustInit(cache.NewContext) mustInit(cache.NewContext)
notification.NewContext() mustInit(feed_service.Init)
mustInit(uinotification.Init) mustInit(uinotification.Init)
mustInit(archiver.Init) mustInit(archiver.Init)

View file

@ -1,7 +1,7 @@
// Copyright 2019 The Gitea Authors. All rights reserved. // Copyright 2019 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
package action package feed
import ( import (
"context" "context"
@ -16,6 +16,7 @@ import (
"code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/json" "code.gitea.io/gitea/modules/json"
"code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/notification"
"code.gitea.io/gitea/modules/notification/base" "code.gitea.io/gitea/modules/notification/base"
"code.gitea.io/gitea/modules/repository" "code.gitea.io/gitea/modules/repository"
"code.gitea.io/gitea/modules/util" "code.gitea.io/gitea/modules/util"
@ -27,6 +28,12 @@ type actionNotifier struct {
var _ base.Notifier = &actionNotifier{} var _ base.Notifier = &actionNotifier{}
func Init() error {
notification.RegisterNotifier(NewNotifier())
return nil
}
// NewNotifier create a new actionNotifier notifier // NewNotifier create a new actionNotifier notifier
func NewNotifier() base.Notifier { func NewNotifier() base.Notifier {
return &actionNotifier{} return &actionNotifier{}

View file

@ -1,7 +1,7 @@
// Copyright 2019 The Gitea Authors. All rights reserved. // Copyright 2019 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
package action package feed
import ( import (
"path/filepath" "path/filepath"
@ -19,7 +19,7 @@ import (
func TestMain(m *testing.M) { func TestMain(m *testing.M) {
unittest.MainTest(m, &unittest.TestOptions{ unittest.MainTest(m, &unittest.TestOptions{
GiteaRootPath: filepath.Join("..", "..", ".."), GiteaRootPath: filepath.Join("..", ".."),
}) })
} }

View file

@ -15,8 +15,8 @@ import (
"code.gitea.io/gitea/models/unittest" "code.gitea.io/gitea/models/unittest"
user_model "code.gitea.io/gitea/models/user" user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/notification" "code.gitea.io/gitea/modules/notification"
"code.gitea.io/gitea/modules/notification/action"
"code.gitea.io/gitea/modules/util" "code.gitea.io/gitea/modules/util"
"code.gitea.io/gitea/services/feed"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
) )
@ -25,7 +25,7 @@ var notifySync sync.Once
func registerNotifier() { func registerNotifier() {
notifySync.Do(func() { notifySync.Do(func() {
notification.RegisterNotifier(action.NewNotifier()) notification.RegisterNotifier(feed.NewNotifier())
}) })
} }