-
Notifications
You must be signed in to change notification settings - Fork 188
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: jkoberg <[email protected]>
- Loading branch information
Showing
5 changed files
with
82 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,65 +1,50 @@ | ||
package service | ||
|
||
import "text/template" | ||
|
||
// the available templates | ||
var ( | ||
SpaceShared = "space-shared" | ||
SpaceSharedSubject = "Space shared" | ||
SpaceSharedMessage = "{{ .username }} added you to Space {{ .spacename }}" | ||
|
||
SpaceUnshared = "space-unshared" | ||
SpaceUnsharedSubject = "Removed from Space" | ||
SpaceUnsharedMessage = "{{ .username }} removed you from Space {{ .spacename }}" | ||
SpaceShared = NotificationTemplate{ | ||
Subject: "Space shared", | ||
Message: "{{ .username }} added you to Space {{ .spacename }}", | ||
} | ||
|
||
SpaceDisabled = "space-disabled" | ||
SpaceDisabledSubject = "Space disabled" | ||
SpaceDisabledMessage = "{{ .username }} disabled Space {{ .spacename }}" | ||
SpaceUnshared = NotificationTemplate{ | ||
Subject: "Removed from Space", | ||
Message: "{{ .username }} removed you from Space {{ .spacename }}", | ||
} | ||
|
||
SpaceDeleted = "space-deleted" | ||
SpaceDeletedSubject = "Space deleted" | ||
SpaceDeletedMessage = "{{ .username }} deleted Space {{ .spacename }}" | ||
SpaceDisabled = NotificationTemplate{ | ||
Subject: "Space disabled", | ||
Message: "{{ .username }} disabled Space {{ .spacename }}", | ||
} | ||
|
||
SpaceMembershipExpired = "space-membership-expired" | ||
SpaceMembershipExpiredSubject = "Membership expired" | ||
SpaceMembershipExpiredMessage = "Access to Space {{ .spacename }} lost" | ||
SpaceDeleted = NotificationTemplate{ | ||
Subject: "Space deleted", | ||
Message: "{{ .username }} deleted Space {{ .spacename }}", | ||
} | ||
|
||
ShareCreated = "item-shared" | ||
ShareCreatedSubject = "Resource shared" | ||
ShareCreatedMessage = "{{ .username }} shared {{ .resourcename }} with you" | ||
SpaceMembershipExpired = NotificationTemplate{ | ||
Subject: "Membership expired", | ||
Message: "Access to Space {{ .spacename }} lost", | ||
} | ||
|
||
ShareRemoved = "item-unshared" | ||
ShareRemovedSubject = "Resource unshared" | ||
ShareRemovedMessage = "{{ .username }} unshared {{ .resourcename }} with you" | ||
ShareCreated = NotificationTemplate{ | ||
Subject: "Resource shared", | ||
Message: "{{ .username }} shared {{ .resourcename }} with you", | ||
} | ||
|
||
ShareExpired = "share-expired" | ||
ShareExpiredSubject = "Share expired" | ||
ShareExpiredMessage = "Access to {{ .resourcename }} expired" | ||
) | ||
ShareRemoved = NotificationTemplate{ | ||
Subject: "Resource unshared", | ||
Message: "{{ .username }} unshared {{ .resourcename }} with you", | ||
} | ||
|
||
// rendered templates | ||
var ( | ||
_templates = map[string]NotificationTemplate{ | ||
SpaceShared: notiTmpl(SpaceSharedSubject, SpaceSharedMessage), | ||
SpaceUnshared: notiTmpl(SpaceUnsharedSubject, SpaceUnsharedMessage), | ||
SpaceDisabled: notiTmpl(SpaceDisabledSubject, SpaceDisabledMessage), | ||
SpaceDeleted: notiTmpl(SpaceDeletedSubject, SpaceDeletedMessage), | ||
SpaceMembershipExpired: notiTmpl(SpaceMembershipExpiredSubject, SpaceMembershipExpiredMessage), | ||
ShareCreated: notiTmpl(ShareCreatedSubject, ShareCreatedMessage), | ||
ShareRemoved: notiTmpl(ShareRemovedSubject, ShareRemovedMessage), | ||
ShareExpired: notiTmpl(ShareExpiredSubject, ShareExpiredMessage), | ||
ShareExpired = NotificationTemplate{ | ||
Subject: "Share expired", | ||
Message: "Access to {{ .resourcename }} expired", | ||
} | ||
) | ||
|
||
// NotificationTemplate is the data structure for the notifications | ||
type NotificationTemplate struct { | ||
Subject *template.Template | ||
Message *template.Template | ||
} | ||
|
||
func notiTmpl(subjectname string, messagename string) NotificationTemplate { | ||
return NotificationTemplate{ | ||
Subject: template.Must(template.New("").Parse(subjectname)), | ||
Message: template.Must(template.New("").Parse(messagename)), | ||
} | ||
Subject string | ||
Message string | ||
} |