Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Send a push notification for sharing shortcuts #4495

Merged
merged 2 commits into from
Jan 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 {
zatteo marked this conversation as resolved.
Show resolved Hide resolved
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
Loading