From 0303138358201337c5d78bdfb7d55419e85cd417 Mon Sep 17 00:00:00 2001 From: MuZhou233 Date: Thu, 21 Dec 2023 22:47:21 +0000 Subject: [PATCH] fix(netzach): tested with client --- app/porter/internal/biz/bizfeed/feed.go | 2 +- app/sephirah/internal/biz/bizangela/notify.go | 6 ++++ .../internal/biz/biznetzach/netzach.go | 20 ++++++++++++ app/sephirah/internal/data/netzach.go | 32 +++++++++---------- app/sephirah/internal/data/yesod.go | 6 ++-- 5 files changed, 46 insertions(+), 20 deletions(-) diff --git a/app/porter/internal/biz/bizfeed/feed.go b/app/porter/internal/biz/bizfeed/feed.go index cbf40263..94026d60 100644 --- a/app/porter/internal/biz/bizfeed/feed.go +++ b/app/porter/internal/biz/bizfeed/feed.go @@ -24,7 +24,7 @@ type RSSRepo interface { func NewFeed(rss RSSRepo) *FeedUseCase { return &FeedUseCase{ rss, - favicon.New(), + favicon.New(favicon.IgnoreManifest), } } diff --git a/app/sephirah/internal/biz/bizangela/notify.go b/app/sephirah/internal/biz/bizangela/notify.go index 9dfdf076..a724b479 100644 --- a/app/sephirah/internal/biz/bizangela/notify.go +++ b/app/sephirah/internal/biz/bizangela/notify.go @@ -40,6 +40,9 @@ func NewNotifyRouterTopic( //nolint:gocognit // TODO if err != nil { return err } + if flow.Status != modelnetzach.NotifyFlowStatusActive { + continue + } var messages []*modelfeed.Item for _, source := range flow.Sources { if source.SourceID == r.FeedID { @@ -78,6 +81,9 @@ func NewNotifyPushTopic( if err != nil { return err } + if target.Status != modelnetzach.NotifyTargetStatusActive { + return nil + } _, err = a.porter.PushFeedItems(ctx, &porter.PushFeedItemsRequest{ Destination: converter.ToPBFeedDestination(target.Type), ChannelId: p.Target.ChannelID, diff --git a/app/sephirah/internal/biz/biznetzach/netzach.go b/app/sephirah/internal/biz/biznetzach/netzach.go index a1748370..ef51b749 100644 --- a/app/sephirah/internal/biz/biznetzach/netzach.go +++ b/app/sephirah/internal/biz/biznetzach/netzach.go @@ -125,6 +125,16 @@ func (n *Netzach) CreateNotifyFlow(ctx context.Context, flow *modelnetzach.Notif return 0, pb.ErrorErrorReasonUnspecified("%s", err.Error()) } flow.ID = id + for _, source := range flow.Sources { + if source.Filter == nil { + source.Filter = &modelnetzach.NotifyFilter{} + } + } + for _, target := range flow.Targets { + if target.Filter == nil { + target.Filter = &modelnetzach.NotifyFilter{} + } + } err = n.repo.CreateNotifyFlow(ctx, claims.InternalID, flow) if err != nil { return 0, pb.ErrorErrorReasonUnspecified("%s", err.Error()) @@ -137,6 +147,16 @@ func (n *Netzach) UpdateNotifyFlow(ctx context.Context, flow *modelnetzach.Notif if claims == nil { return bizutils.NoPermissionError() } + for _, source := range flow.Sources { + if source.Filter == nil { + source.Filter = &modelnetzach.NotifyFilter{} + } + } + for _, target := range flow.Targets { + if target.Filter == nil { + target.Filter = &modelnetzach.NotifyFilter{} + } + } err := n.repo.UpdateNotifyFlow(ctx, claims.InternalID, flow) if err != nil { return pb.ErrorErrorReasonUnspecified("%s", err.Error()) diff --git a/app/sephirah/internal/data/netzach.go b/app/sephirah/internal/data/netzach.go index 3cb8cfa6..84c2bf2d 100644 --- a/app/sephirah/internal/data/netzach.go +++ b/app/sephirah/internal/data/netzach.go @@ -109,6 +109,16 @@ func (n *netzachRepo) GetNotifyTarget(ctx context.Context, id model.InternalID) func (n *netzachRepo) CreateNotifyFlow(ctx context.Context, userID model.InternalID, f *modelnetzach.NotifyFlow) error { err := n.data.WithTx(ctx, func(tx *ent.Tx) error { + err := tx.NotifyFlow.Create(). + SetID(f.ID). + SetOwnerID(userID). + SetName(f.Name). + SetDescription(f.Description). + SetStatus(converter.ToEntNotifySourceSource(f.Status)). + Exec(ctx) + if err != nil { + return err + } flowSources := make([]*ent.NotifyFlowSourceCreate, len(f.Sources)) for i, source := range f.Sources { flowSources[i] = tx.NotifyFlowSource.Create(). @@ -117,7 +127,7 @@ func (n *netzachRepo) CreateNotifyFlow(ctx context.Context, userID model.Interna SetFilterExcludeKeywords(source.Filter.ExcludeKeywords). SetFilterIncludeKeywords(source.Filter.IncludeKeywords) } - source, err := tx.NotifyFlowSource.CreateBulk(flowSources...).Save(ctx) + err = tx.NotifyFlowSource.CreateBulk(flowSources...).Exec(ctx) if err != nil { return err } @@ -130,19 +140,11 @@ func (n *netzachRepo) CreateNotifyFlow(ctx context.Context, userID model.Interna SetFilterExcludeKeywords(target.Filter.ExcludeKeywords). SetFilterIncludeKeywords(target.Filter.IncludeKeywords) } - target, err := tx.NotifyFlowTarget.CreateBulk(flowTargets...).Save(ctx) + err = tx.NotifyFlowTarget.CreateBulk(flowTargets...).Exec(ctx) if err != nil { return err } - q := n.data.db.NotifyFlow.Create(). - SetID(f.ID). - SetOwnerID(userID). - SetName(f.Name). - SetDescription(f.Description). - SetStatus(converter.ToEntNotifySourceSource(f.Status)). - AddNotifyFlowSource(source...). - AddNotifyFlowTarget(target...) - return q.Exec(ctx) + return nil }) if err != nil { return err @@ -183,11 +185,10 @@ func (n *netzachRepo) UpdateNotifyFlow( //nolint:gocognit // TODO SetFilterExcludeKeywords(source.Filter.ExcludeKeywords). SetFilterIncludeKeywords(source.Filter.IncludeKeywords) } - source, err := tx.NotifyFlowSource.CreateBulk(flowSources...).Save(ctx) + err = tx.NotifyFlowSource.CreateBulk(flowSources...).Exec(ctx) if err != nil { return err } - q.ClearFeedConfig().AddNotifyFlowSource(source...) } if f.Targets != nil { _, err := tx.NotifyFlowTarget.Delete().Where( @@ -207,11 +208,10 @@ func (n *netzachRepo) UpdateNotifyFlow( //nolint:gocognit // TODO SetFilterExcludeKeywords(target.Filter.ExcludeKeywords). SetFilterIncludeKeywords(target.Filter.IncludeKeywords) } - targets, err := tx.NotifyFlowTarget.CreateBulk(flowTargets...).Save(ctx) + err = tx.NotifyFlowTarget.CreateBulk(flowTargets...).Exec(ctx) if err != nil { return err } - q.ClearNotifyTarget().AddNotifyFlowTarget(targets...) } if f.Status != modelnetzach.NotifyFlowStatusUnspecified { q.SetStatus(converter.ToEntNotifySourceSource(f.Status)) @@ -259,7 +259,7 @@ func (n *netzachRepo) ListNotifyFlows( func (n *netzachRepo) GetNotifyFlow(ctx context.Context, id model.InternalID) (*modelnetzach.NotifyFlow, error) { res, err := n.data.db.NotifyFlow.Query(). Where(notifyflow.IDEQ(id)). - WithFeedConfig(). + WithNotifyFlowSource(). WithNotifyFlowTarget(). Only(ctx) if err != nil { diff --git a/app/sephirah/internal/data/yesod.go b/app/sephirah/internal/data/yesod.go index e89ae107..8a56b1a8 100644 --- a/app/sephirah/internal/data/yesod.go +++ b/app/sephirah/internal/data/yesod.go @@ -68,7 +68,7 @@ func (y *yesodRepo) UpdateFeedConfig(ctx context.Context, userID model.InternalI q.SetStatus(converter.ToEntFeedConfigStatus(c.Status)) } if c.PullInterval > 0 { - q.SetPullInterval(c.PullInterval) + q.SetPullInterval(c.PullInterval).SetNextPullBeginAt(time.Now()) } q.SetHideItems(c.HideItems) return q.Exec(ctx) @@ -214,7 +214,7 @@ func (y *yesodRepo) ListFeedItems( return err } fq := tx.User.QueryFeedConfig(u).Where( - feedconfig.HideItemsEQ(true), + feedconfig.HideItemsEQ(false), ).QueryFeed() if len(feedIDs) > 0 { fq.Where(feed.IDIn(feedIDs...)) @@ -278,7 +278,7 @@ func (y *yesodRepo) GroupFeedItems( //nolint:gocognit //TODO } for _, timeRange := range groups { fq := tx.User.QueryFeedConfig(u).Where( - feedconfig.HideItemsEQ(true), + feedconfig.HideItemsEQ(false), ).QueryFeed() if len(feedIDs) > 0 { fq.Where(feed.IDIn(feedIDs...))