fixes mail notifications

This commit is contained in:
Christian Beutel
2025-06-27 11:51:23 +02:00
parent 277b435c65
commit 7b57252f7f
7 changed files with 22 additions and 17 deletions

View File

@@ -160,23 +160,23 @@ func ProcessActivity(e *core.RequestEvent) error {
switch activity.Type { switch activity.Type {
case pub.FollowType: case pub.FollowType:
ProcessFollowActivity(e.App, actor, activity) err = ProcessFollowActivity(e.App, actor, activity)
case pub.AcceptType: case pub.AcceptType:
ProcessAcceptActivity(e.App, actor, activity) err = ProcessAcceptActivity(e.App, actor, activity)
case pub.UndoType: case pub.UndoType:
ProcessUndoActivity(e.App, actor, activity) err = ProcessUndoActivity(e.App, actor, activity)
case pub.UpdateType: case pub.UpdateType:
fallthrough fallthrough
case pub.CreateType: case pub.CreateType:
ProcessCreateOrUpdateActivity(e.App, actor, activity) err = ProcessCreateOrUpdateActivity(e.App, actor, activity)
case pub.DeleteType: case pub.DeleteType:
ProcessDeleteActivity(e.App, actor, activity) err = ProcessDeleteActivity(e.App, actor, activity)
case pub.AnnounceType: case pub.AnnounceType:
ProcessAnnounceActivity(e.App, actor, activity) err = ProcessAnnounceActivity(e.App, actor, activity)
case pub.LikeType: case pub.LikeType:
ProcessLikeActivity(e.App, actor, activity) err = ProcessLikeActivity(e.App, actor, activity)
} }
return e.JSON(http.StatusOK, nil) return e.JSON(http.StatusOK, err)
} }
func verifySignature(app core.App, req *http.Request, publicKeyPem string) (bool, error) { func verifySignature(app core.App, req *http.Request, publicKeyPem string) (bool, error) {

View File

@@ -99,7 +99,7 @@ func GetActorByIRI(app core.App, actor *core.Record, iri string, includeFollows
func iriFromHandle(domain string, username string) (string, error) { func iriFromHandle(domain string, username string) (string, error) {
client := &http.Client{} client := &http.Client{}
webfingerURL := fmt.Sprintf("http://%s/.well-known/webfinger?resource=acct:%s@%s", domain, username, domain) webfingerURL := fmt.Sprintf("https://%s/.well-known/webfinger?resource=acct:%s@%s", domain, username, domain)
resp, err := client.Get(webfingerURL) resp, err := client.Get(webfingerURL)
if err != nil || resp.StatusCode != http.StatusOK { if err != nil || resp.StatusCode != http.StatusOK {
return "", fmt.Errorf("webfinger request failed: %v", err) return "", fmt.Errorf("webfinger request failed: %v", err)
@@ -140,12 +140,12 @@ func assembleActor(actor *core.Record, dbActor *core.Record, app core.App, inclu
dbActor.Set("icon", fmt.Sprintf("%s/api/v1/files/users/%s/%s", origin, user.Id, user.GetString("avatar"))) dbActor.Set("icon", fmt.Sprintf("%s/api/v1/files/users/%s/%s", origin, user.Id, user.GetString("avatar")))
} }
dbActor.Set("summary", settings.GetString("bio")) dbActor.Set("summary", settings.GetString("bio"))
followerCount, err := app.CountRecords("follows", dbx.NewExp("followee={:user}", dbx.Params{"user": dbActor.Id})) followerCount, err := app.CountRecords("follows", dbx.NewExp("followee={:user} AND status='accepted'", dbx.Params{"user": dbActor.Id}))
if err != nil { if err != nil {
return nil, err return nil, err
} }
dbActor.Set("followerCount", followerCount) dbActor.Set("followerCount", followerCount)
followingCount, err := app.CountRecords("follows", dbx.NewExp("follower={:user}", dbx.Params{"user": dbActor.Id})) followingCount, err := app.CountRecords("follows", dbx.NewExp("follower={:user} AND status='accepted'", dbx.Params{"user": dbActor.Id}))
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@@ -57,7 +57,7 @@
.button { .button {
display: inline-block; display: inline-block;
background-color: #242734; background-color: #242734;
color: #ffffff; color: #ffffff !important;
padding: 10px 20px; padding: 10px 20px;
border-radius: 5px; border-radius: 5px;
text-decoration: none; text-decoration: none;

View File

@@ -19,7 +19,7 @@ type EmailData struct {
var notificationTemplates = map[NotificationType]string{ var notificationTemplates = map[NotificationType]string{
TrailShare: "{{.Author}} has shared a trail with you: {{.trail}}.", TrailShare: "{{.Author}} has shared a trail with you: {{.trail}}.",
ListShare: "{{.Author}} has shared a list with you: {{.list}}.", ListShare: "{{.Author}} has shared a list with you: {{.list}}.",
NewFollower: "Good news! You have a new follower: {{.Author}}.", NewFollower: "Good news! You have a new follower: {{.follower}}.",
TrailComment: "{{.Author}} commented on your trail '{{.trail_name}}': '{{.comment}}'.", TrailComment: "{{.Author}} commented on your trail '{{.trail_name}}': '{{.comment}}'.",
SummitLogCreate: "{{.Author}} created a summit log on your trail '{{.trail_name}}'.", SummitLogCreate: "{{.Author}} created a summit log on your trail '{{.trail_name}}'.",
TrailLike: "{{.Author}} liked your trail '{{.trail_name}}'.", TrailLike: "{{.Author}} liked your trail '{{.trail_name}}'.",
@@ -59,7 +59,7 @@ func GenerateHTML(appUrl string, recipientName string, authorName string, notifi
} }
html, err := registry.LoadFiles( html, err := registry.LoadFiles(
"db/templates/mail/notification.html", "templates/mail/notification.html",
).Render(content) ).Render(content)
if err != nil { if err != nil {

View File

@@ -92,11 +92,15 @@ func SendNotification(app core.App, notification Notification, recipient *core.R
if err != nil { if err != nil {
return err return err
} }
recipientUser, err := app.FindRecordById("users", recipientActor.GetString("user"))
if err != nil {
return err
}
authorActor, err := app.FindRecordById("activitypub_actors", notification.Author) authorActor, err := app.FindRecordById("activitypub_actors", notification.Author)
if err != nil { if err != nil {
return err return err
} }
html, err := GenerateHTML(app.Settings().Meta.AppURL, recipientActor.GetString("preferred_username"), authorActor.GetString("preferred_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 { if err != nil {
return err return err
} }
@@ -106,7 +110,7 @@ func SendNotification(app core.App, notification Notification, recipient *core.R
Address: app.Settings().Meta.SenderAddress, Address: app.Settings().Meta.SenderAddress,
Name: app.Settings().Meta.SenderName, Name: app.Settings().Meta.SenderName,
}, },
To: []mail.Address{{Address: recipientActor.Email()}}, To: []mail.Address{{Address: recipientUser.Email()}},
Subject: "wanderer - New Notification", Subject: "wanderer - New Notification",
HTML: html, HTML: html,
} }

View File

@@ -127,6 +127,6 @@
} }
.mention { .mention {
@apply bg-blue-100 dark:bg-slate-700 rounded-md; @apply bg-blue-100 dark:bg-slate-700 rounded-md text-sm;
padding: 0.1rem 0.3rem; padding: 0.1rem 0.3rem;
} }

View File

@@ -29,6 +29,7 @@ export async function GET(event: RequestEvent) {
const r: APRoot<APActor & { publicKey: { id: string, owner: string, publicKeyPem: string } }> = { const r: APRoot<APActor & { publicKey: { id: string, owner: string, publicKeyPem: string } }> = {
"@context": [ "@context": [
"https://www.w3.org/ns/activitystreams", "https://www.w3.org/ns/activitystreams",
"https://w3id.org/security/v1",
], ],
id: id, id: id,
type: "Person", type: "Person",