diff --git a/pkg/models/accounts.go b/pkg/models/accounts.go index 0c32fa5..9e7a889 100644 --- a/pkg/models/accounts.go +++ b/pkg/models/accounts.go @@ -27,6 +27,8 @@ type AccountMembership struct { ID uint `json:"id" gorm:"primaryKey"` CreatedAt time.Time `json:"created_at"` UpdatedAt time.Time `json:"updated_at"` + Follower Account `json:"follower"` + Following Account `json:"following"` FollowerID uint FollowingID uint } diff --git a/pkg/services/posts.go b/pkg/services/posts.go index d71c709..1591b9e 100644 --- a/pkg/services/posts.go +++ b/pkg/services/posts.go @@ -209,6 +209,27 @@ func NewPost( } } + go func() { + var subscribers []models.AccountMembership + if err := database.C.Where(&models.AccountMembership{ + FollowingID: user.ID, + }).Preload("Follower").Find(&subscribers).Error; err != nil { + return + } + + accounts := lo.Map(subscribers, func(item models.AccountMembership, index int) models.Account { + return item.Follower + }) + + for _, account := range accounts { + _ = NotifyAccount( + account, + fmt.Sprintf("%s just posted a post", user.Name), + "Account you followed post a brand new post. Check it out!", + ) + } + }() + return post, nil }