Skip to content

Commit

Permalink
Send a push notification for sharing shortcuts (#4495)
Browse files Browse the repository at this point in the history
  • Loading branch information
nono authored Jan 2, 2025
2 parents 7bb3e0b + a374ea4 commit e3b7ee5
Show file tree
Hide file tree
Showing 8 changed files with 1,015 additions and 927 deletions.
6 changes: 6 additions & 0 deletions assets/locales/de.po
Original file line number Diff line number Diff line change
Expand Up @@ -1001,3 +1001,9 @@ msgstr ""
msgid "Onboarding Resend activation Detail"
msgstr ""
"We prefer to warn you, this mail can be found in Spam, Notification or Social folders. Do not hesitate to take a look at these folders to find it."

msgid "Push Sharing Shortcut Title"
msgstr "A new share is available in your Cozy"

msgid "Push Sharing Shortcut Message"
msgstr "%s has shared %s with you."
6 changes: 6 additions & 0 deletions assets/locales/en.po
Original file line number Diff line number Diff line change
Expand Up @@ -1319,3 +1319,9 @@ msgstr ""
msgid "Onboarding Resend activation Detail"
msgstr ""
"We prefer to warn you, this mail can be found in Spam, Notification or Social folders. Do not hesitate to take a look at these folders to find it."

msgid "Push Sharing Shortcut Title"
msgstr "A new share is available in your Cozy"

msgid "Push Sharing Shortcut Message"
msgstr "%s has shared %s with you."
6 changes: 6 additions & 0 deletions assets/locales/es.po
Original file line number Diff line number Diff line change
Expand Up @@ -1012,3 +1012,9 @@ msgstr ""
msgid "Onboarding Resend activation Detail"
msgstr ""
"We prefer to warn you, this mail can be found in Spam, Notification or Social folders. Do not hesitate to take a look at these folders to find it."

msgid "Push Sharing Shortcut Title"
msgstr "A new share is available in your Cozy"

msgid "Push Sharing Shortcut Message"
msgstr "%s has shared %s with you."
6 changes: 6 additions & 0 deletions assets/locales/fr.po
Original file line number Diff line number Diff line change
Expand Up @@ -1437,3 +1437,9 @@ msgstr ""
"Nous préférons vous prévenir : cet e-mail peut s'avérer un brin joueur et se"
" faufiler dans les dossiers Spam, Notifications ou Réseaux Sociaux. "
"N'hésitez donc pas à jeter un œil à tous vos dossiers pour le retrouver. "

msgid "Push Sharing Shortcut Title"
msgstr "Un nouveau partage est disponible dans votre Cozy"

msgid "Push Sharing Shortcut Message"
msgstr "%s vous a partagé %s."
6 changes: 6 additions & 0 deletions assets/locales/ja.po
Original file line number Diff line number Diff line change
Expand Up @@ -816,3 +816,9 @@ msgstr ""
msgid "Onboarding Resend activation Detail"
msgstr ""
"We prefer to warn you, this mail can be found in Spam, Notification or Social folders. Do not hesitate to take a look at these folders to find it."

msgid "Push Sharing Shortcut Title"
msgstr "A new share is available in your Cozy"

msgid "Push Sharing Shortcut Message"
msgstr "%s has shared %s with you."
6 changes: 6 additions & 0 deletions assets/locales/nl_NL.po
Original file line number Diff line number Diff line change
Expand Up @@ -1197,3 +1197,9 @@ msgstr ""
msgid "Onboarding Resend activation Detail"
msgstr ""
"We prefer to warn you, this mail can be found in Spam, Notification or Social folders. Do not hesitate to take a look at these folders to find it."

msgid "Push Sharing Shortcut Title"
msgstr "A new share is available in your Cozy"

msgid "Push Sharing Shortcut Message"
msgstr "%s has shared %s with you."
55 changes: 51 additions & 4 deletions model/sharing/invitation.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (

"github.com/cozy/cozy-stack/model/instance"
"github.com/cozy/cozy-stack/model/job"
"github.com/cozy/cozy-stack/model/notification/center"
"github.com/cozy/cozy-stack/model/oauth"
"github.com/cozy/cozy-stack/model/permission"
csettings "github.com/cozy/cozy-stack/model/settings"
"github.com/cozy/cozy-stack/model/vfs"
Expand Down Expand Up @@ -330,7 +332,7 @@ func (s *Sharing) CreateShortcut(inst *instance.Instance, previewURL string, see
inst.Logger().Warnf("Cannot save shortcut id %s: %s", s.ShortcutID, err)
}

return s.SendShortcutMail(inst, fileDoc, previewURL)
return s.SendShortcutNotification(inst, fileDoc, previewURL)
}

// SendShortcut sends the HTTP request to the cozy of the recipient for adding
Expand All @@ -353,13 +355,58 @@ func (m *Member) SendShortcut(inst *instance.Instance, s *Sharing, link string)
return m.CreateSharingRequest(inst, s, creds, u)
}

// SendShortcutMail will send a notification mail after a shortcut for a
// sharing has been created.
func (s *Sharing) SendShortcutMail(inst *instance.Instance, fileDoc *vfs.FileDoc, previewURL string) error {
func (s *Sharing) SendShortcutNotification(inst *instance.Instance, fileDoc *vfs.FileDoc, previewURL string) error {
sharerName := s.Members[0].PublicName
if sharerName == "" {
sharerName = inst.Translate("Sharing Empty name")
}
if err := s.SendShortcutPush(inst, fileDoc, previewURL, sharerName); err != nil {
inst.Logger().WithNamespace("sharing").
Warnf("Cannot send push notification: %s", err)
}
return s.SendShortcutMail(inst, fileDoc, previewURL, sharerName)
}

func (s *Sharing) SendShortcutPush(inst *instance.Instance, fileDoc *vfs.FileDoc, previewURL, sharerName string) error {
notifiables, err := oauth.GetNotifiables(inst)
if err != nil {
return err
}
hasFlagship := false
for _, notifiable := range notifiables {
if notifiable.Flagship {
hasFlagship = true
}
}
if !hasFlagship {
return nil
}

targetType := getTargetTitleType(inst, fileDoc.Metadata)
title := inst.Translate("Push Sharing Shortcut Title")
message := inst.Translate("Push Sharing Shortcut Message", sharerName, targetType)
push := center.PushMessage{
NotificationID: fileDoc.ID(),
Title: title,
Message: message,
Data: map[string]interface{}{
"redirectLink": previewURL,
},
}
msg, err := job.NewMessage(&push)
if err != nil {
return err
}
_, err = job.System().PushJob(inst, &job.JobRequest{
WorkerType: "push",
Message: msg,
})
return err
}

// SendShortcutMail will send a notification mail after a shortcut for a
// sharing has been created.
func (s *Sharing) SendShortcutMail(inst *instance.Instance, fileDoc *vfs.FileDoc, previewURL, sharerName string) error {
var action string
if s.ReadOnlyRules() {
action = inst.Translate("Mail Sharing Request Action Read")
Expand Down
Loading

0 comments on commit e3b7ee5

Please sign in to comment.