✨ Notify to followers when their following account posted
This commit is contained in:
parent
c5ed5e8df6
commit
4690e8be10
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user