Notify to followers when their following account posted

This commit is contained in:
LittleSheep 2024-02-12 17:24:17 +08:00
parent c5ed5e8df6
commit 4690e8be10
2 changed files with 23 additions and 0 deletions

View File

@ -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
}

View File

@ -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
}