···3131 Id string `json:"id"`
3232 // When to push the notification
3333 SendAt time.Time `json:"send_at"`
3434- // Clear scheduled jobs for the object_id before scheduling notifications
3535- ClearSchedule bool `json:"clear_schedule"`
3434+ // Clear scheduled jobs for the given event types on the object_id before scheduling notifications
3535+ // TODO: generate jsonschema annotation
3636+ ClearScheduleFor []Event `json:"clear_schedule_for"`
3637 // Type of event that triggered the notification
3738 // next-line-generate event-enum-jsonschema-values
3839 Event Event `json:"event" jsonschema:"enum=clear_stored_schedule,enum=show_scheduled_jobs,enum=save_schedule,enum=restore_schedule,enum=restore_schedule_eager,enum=clear_schedule,enum=new_post,enum=godchild_request,enum=custom,enum=test,enum=godchild_accepted,enum=godchild_rejected,enum=pending_signup,enum=login_stuck,enum=booking_paid,enum=contribution_paid,enum=shotgun_opens_soon,enum=shotgun_closes_soon"`
···1818 cmap.ConcurrentMap[string, Message]
1919}
20202121+// schedules stores the scheduled messages in memory, as a mapping of job.Id -> job
2122var schedules Schedule = Schedule{cmap.New[Message]()}
22232324func (job Message) Unschedule() {
···9091 }
9192}
92939393-func UnscheduleAllForObject(objectId string) {
9494- ll.Log("Unscheduling", "yellow", "all jobs for %s", objectId)
9494+// UnscheduleAllForObject unschedules all jobs for a given object ID. If any ofType is provided, only events of the types given will be unscheduled
9595+func UnscheduleAllForObject(objectId string, ofType ...Event) {
9696+ var filter func(Message) bool
9797+ if len(ofType) > 0 {
9898+ ll.Log("Unscheduling", "yellow", "all jobs for %s of type %v", objectId, ofType)
9999+100100+ filter = func(job Message) bool {
101101+ for _, t := range ofType {
102102+ if job.Event == t {
103103+ return true
104104+ }
105105+ }
106106+ return false
107107+ }
108108+109109+ } else {
110110+ ll.Log("Unscheduling", "yellow", "all jobs for %s", objectId)
111111+112112+ filter = func(Message) bool { return true }
113113+ }
114114+95115 for _, job := range schedules.Items() {
9696- if job.ChurrosObjectId == objectId {
116116+ if job.ChurrosObjectId == objectId && filter(job) {
117117+ ll.Log("Unscheduling", "yellow", "%s | %s", job.Id, job.String())
97118 job.Unschedule()
98119 }
99120 }
+2-2
typescript-dist/index.js.map
···11{
22 "version": 3,
33 "sources": ["../typescript/message.ts", "../typescript/constants.ts"],
44- "sourcesContent": ["export interface Message {\n /**\n * URL to go to when the action button is clicked\n */\n action: string;\n /**\n * Additional action buttons\n */\n actions?: Action[];\n /**\n * Notification body\n */\n body: string;\n /**\n * Clear scheduled jobs for the object_id before scheduling notifications\n */\n clear_schedule: boolean;\n /**\n * Type of event that triggered the notification\n * next-line-generate event-enum-jsonschema-values\n */\n event: Event;\n /**\n * Unique ID for the notification scheduling request.\n */\n id: string;\n /**\n * URL to an image to display in the notification\n */\n image?: string;\n /**\n * Churros ID of the ressource (the ticket, the post, the comment, etc)\n * Used to determine to whom the notification should be sent\n * For godchild_request, this is not a user id, but a godparent request id.\n */\n object_id: string;\n /**\n * When to push the notification\n */\n send_at: Date;\n /**\n * Notification title\n */\n title: string;\n}\n\nexport interface Action {\n action: string;\n label: string;\n}\n\n/**\n * Type of event that triggered the notification\n * next-line-generate event-enum-jsonschema-values\n */\nexport enum Event {\n BookingPaid = \"booking_paid\",\n ClearSchedule = \"clear_schedule\",\n ClearStoredSchedule = \"clear_stored_schedule\",\n ContributionPaid = \"contribution_paid\",\n Custom = \"custom\",\n GodchildAccepted = \"godchild_accepted\",\n GodchildRejected = \"godchild_rejected\",\n GodchildRequest = \"godchild_request\",\n LoginStuck = \"login_stuck\",\n NewPost = \"new_post\",\n PendingSignup = \"pending_signup\",\n RestoreSchedule = \"restore_schedule\",\n RestoreScheduleEager = \"restore_schedule_eager\",\n SaveSchedule = \"save_schedule\",\n ShotgunClosesSoon = \"shotgun_closes_soon\",\n ShotgunOpensSoon = \"shotgun_opens_soon\",\n ShowScheduledJobs = \"show_scheduled_jobs\",\n Test = \"test\",\n}\n", "export const STREAM_NAME = 'notella:stream';\nexport const SUBJECT_NAME = 'notella:notification';\nexport const CONSUMER_NAME = 'NotellaConsumer';"],
55- "mappings": ";AAuDO,IAAK,QAAL,kBAAKA,WAAL;AACH,EAAAA,OAAA,iBAAc;AACd,EAAAA,OAAA,mBAAgB;AAChB,EAAAA,OAAA,yBAAsB;AACtB,EAAAA,OAAA,sBAAmB;AACnB,EAAAA,OAAA,YAAS;AACT,EAAAA,OAAA,sBAAmB;AACnB,EAAAA,OAAA,sBAAmB;AACnB,EAAAA,OAAA,qBAAkB;AAClB,EAAAA,OAAA,gBAAa;AACb,EAAAA,OAAA,aAAU;AACV,EAAAA,OAAA,mBAAgB;AAChB,EAAAA,OAAA,qBAAkB;AAClB,EAAAA,OAAA,0BAAuB;AACvB,EAAAA,OAAA,kBAAe;AACf,EAAAA,OAAA,uBAAoB;AACpB,EAAAA,OAAA,sBAAmB;AACnB,EAAAA,OAAA,uBAAoB;AACpB,EAAAA,OAAA,UAAO;AAlBC,SAAAA;AAAA,GAAA;;;ACvDL,IAAM,cAAc;AACpB,IAAM,eAAe;AACrB,IAAM,gBAAgB;",
44+ "sourcesContent": ["export interface Message {\n /**\n * URL to go to when the action button is clicked\n */\n action: string;\n /**\n * Additional action buttons\n */\n actions?: Action[];\n /**\n * Notification body\n */\n body: string;\n /**\n * Clear scheduled jobs for the given event types on the object_id before scheduling\n * notifications\n * TODO: generate jsonschema annotation\n */\n clear_schedule_for: string[];\n /**\n * Type of event that triggered the notification\n * next-line-generate event-enum-jsonschema-values\n */\n event: Event;\n /**\n * Unique ID for the notification scheduling request.\n */\n id: string;\n /**\n * URL to an image to display in the notification\n */\n image?: string;\n /**\n * Churros ID of the ressource (the ticket, the post, the comment, etc)\n * Used to determine to whom the notification should be sent\n * For godchild_request, this is not a user id, but a godparent request id.\n */\n object_id: string;\n /**\n * When to push the notification\n */\n send_at: Date;\n /**\n * Notification title\n */\n title: string;\n}\n\nexport interface Action {\n action: string;\n label: string;\n}\n\n/**\n * Type of event that triggered the notification\n * next-line-generate event-enum-jsonschema-values\n */\nexport enum Event {\n BookingPaid = \"booking_paid\",\n ClearSchedule = \"clear_schedule\",\n ClearStoredSchedule = \"clear_stored_schedule\",\n ContributionPaid = \"contribution_paid\",\n Custom = \"custom\",\n GodchildAccepted = \"godchild_accepted\",\n GodchildRejected = \"godchild_rejected\",\n GodchildRequest = \"godchild_request\",\n LoginStuck = \"login_stuck\",\n NewPost = \"new_post\",\n PendingSignup = \"pending_signup\",\n RestoreSchedule = \"restore_schedule\",\n RestoreScheduleEager = \"restore_schedule_eager\",\n SaveSchedule = \"save_schedule\",\n ShotgunClosesSoon = \"shotgun_closes_soon\",\n ShotgunOpensSoon = \"shotgun_opens_soon\",\n ShowScheduledJobs = \"show_scheduled_jobs\",\n Test = \"test\",\n}\n", "export const STREAM_NAME = 'notella:stream';\nexport const SUBJECT_NAME = 'notella:notification';\nexport const CONSUMER_NAME = 'NotellaConsumer';"],
55+ "mappings": ";AAyDO,IAAK,QAAL,kBAAKA,WAAL;AACH,EAAAA,OAAA,iBAAc;AACd,EAAAA,OAAA,mBAAgB;AAChB,EAAAA,OAAA,yBAAsB;AACtB,EAAAA,OAAA,sBAAmB;AACnB,EAAAA,OAAA,YAAS;AACT,EAAAA,OAAA,sBAAmB;AACnB,EAAAA,OAAA,sBAAmB;AACnB,EAAAA,OAAA,qBAAkB;AAClB,EAAAA,OAAA,gBAAa;AACb,EAAAA,OAAA,aAAU;AACV,EAAAA,OAAA,mBAAgB;AAChB,EAAAA,OAAA,qBAAkB;AAClB,EAAAA,OAAA,0BAAuB;AACvB,EAAAA,OAAA,kBAAe;AACf,EAAAA,OAAA,uBAAoB;AACpB,EAAAA,OAAA,sBAAmB;AACnB,EAAAA,OAAA,uBAAoB;AACpB,EAAAA,OAAA,UAAO;AAlBC,SAAAA;AAAA,GAAA;;;ACzDL,IAAM,cAAc;AACpB,IAAM,eAAe;AACrB,IAAM,gBAAgB;",
66 "names": ["Event"]
77}
+4-2
typescript/message.ts
···1212 */
1313 body: string;
1414 /**
1515- * Clear scheduled jobs for the object_id before scheduling notifications
1515+ * Clear scheduled jobs for the given event types on the object_id before scheduling
1616+ * notifications
1717+ * TODO: generate jsonschema annotation
1618 */
1717- clear_schedule: boolean;
1919+ clear_schedule_for: string[];
1820 /**
1921 * Type of event that triggered the notification
2022 * next-line-generate event-enum-jsonschema-values