Federation (#327)
* initial commit federation * more federation * more federation * more federation * completes follow, accept, undo * add trail create activity * process trail create activity * more trail create activity * adds missing endpoints * adds update and delete activity * adds comment activities * adds activities back * adds summit logs activities * deletes follow counts table * fixes migrations * fixes migrations * fixes migrations * fixes migrations * adds remote profiles * ctd * ctd * we are getting closer... * adds public summit logs * fixes federated trails in lists * adds remote lists * adds list activites * fixes lists * adds notifications * adds iri redirect * fixes comments and summitlogs * fixes follows and profiles * adds asynchronous send * fixes list search * adds encryption key * bug fixes * fixes activity signing * removes custon activity object types * adds html editor * fixes html editor * fixes display issues on mastodon * adds federated sharing * finishes announcements * fixes small summit log issues * adds trail likes * finalizes likes * fixes images for komoot * add disable federation option * adds private profiles * updates docs * adds federated comments * adds trail and comments actvitiypub routes * adds mentions to editor * adds mentions to trails, comments, summit logs * updates theme * updates theme * update docs * update docs * updates docs * fixes various frontend problems * fixes activitypub follows api * updates docs * updates docs --------- Co-authored-by: Christian Beutel <>
This commit is contained in:
@@ -11,12 +11,15 @@ import (
|
||||
type NotificationType string
|
||||
|
||||
const (
|
||||
TrailCreate NotificationType = "trail_create"
|
||||
TrailShare NotificationType = "trail_share"
|
||||
ListCreate NotificationType = "list_create"
|
||||
ListShare NotificationType = "list_share"
|
||||
NewFollower NotificationType = "new_follower"
|
||||
TrailComment NotificationType = "trail_comment"
|
||||
TrailShare NotificationType = "trail_share"
|
||||
ListShare NotificationType = "list_share"
|
||||
NewFollower NotificationType = "new_follower"
|
||||
TrailComment NotificationType = "trail_comment"
|
||||
TrailLike NotificationType = "trail_like"
|
||||
SummitLogCreate NotificationType = "summit_log_create"
|
||||
CommentMention NotificationType = "comment_mention"
|
||||
TrailMention NotificationType = "trail_mention"
|
||||
SummitLogMention NotificationType = "summit_log_mention"
|
||||
)
|
||||
|
||||
type Notification struct {
|
||||
@@ -54,11 +57,14 @@ func getNotificationPermissions(app core.App, user string, notificationType Noti
|
||||
return &settingsForType, nil
|
||||
}
|
||||
|
||||
func SendNotification(app core.App, notification Notification, recipient string) error {
|
||||
if notification.Author == recipient {
|
||||
func SendNotification(app core.App, notification Notification, recipient *core.Record) error {
|
||||
if notification.Author == recipient.Id {
|
||||
return nil
|
||||
}
|
||||
permissions, err := getNotificationPermissions(app, recipient, notification.Type)
|
||||
if !recipient.GetBool("isLocal") {
|
||||
return nil
|
||||
}
|
||||
permissions, err := getNotificationPermissions(app, recipient.GetString("user"), notification.Type)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -73,7 +79,7 @@ func SendNotification(app core.App, notification Notification, recipient string)
|
||||
n.Set("type", string(notification.Type))
|
||||
n.Set("metadata", notification.Metadata)
|
||||
n.Set("seen", notification.Seen)
|
||||
n.Set("recipient", recipient)
|
||||
n.Set("recipient", recipient.Id)
|
||||
n.Set("author", notification.Author)
|
||||
|
||||
if err := app.Save(n); err != nil {
|
||||
@@ -82,15 +88,15 @@ func SendNotification(app core.App, notification Notification, recipient string)
|
||||
}
|
||||
|
||||
if permissions.Email {
|
||||
recipientUser, err := app.FindRecordById("users", recipient)
|
||||
recipientActor, err := app.FindRecordById("activitypub_actors", recipient.Id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
authorUser, err := app.FindRecordById("users", notification.Author)
|
||||
authorActor, err := app.FindRecordById("activitypub_actors", notification.Author)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
html, err := GenerateHTML(app.Settings().Meta.AppURL, recipientUser.GetString("username"), authorUser.GetString("username"), notification.Type, notification.Metadata)
|
||||
html, err := GenerateHTML(app.Settings().Meta.AppURL, recipientActor.GetString("username"), authorActor.GetString("username"), notification.Type, notification.Metadata)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -100,27 +106,12 @@ func SendNotification(app core.App, notification Notification, recipient string)
|
||||
Address: app.Settings().Meta.SenderAddress,
|
||||
Name: app.Settings().Meta.SenderName,
|
||||
},
|
||||
To: []mail.Address{{Address: recipientUser.Email()}},
|
||||
To: []mail.Address{{Address: recipientActor.Email()}},
|
||||
Subject: "wanderer - New Notification",
|
||||
HTML: html,
|
||||
}
|
||||
|
||||
app.NewMailClient().Send(message)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func SendNotificationToFollowers(app core.App, notification Notification) error {
|
||||
followers, err := app.FindRecordsByFilter("follows", "followee={:user}", "", -1, 0, dbx.Params{"user": notification.Author})
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, f := range followers {
|
||||
recipient := f.GetString("follower")
|
||||
SendNotification(app, notification, recipient)
|
||||
|
||||
return app.NewMailClient().Send(message)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user