Add support for overriding completion buttons

This commit is contained in:
2025-06-04 22:13:43 +02:00
parent 612285d91c
commit 61e78a85d8

View File

@@ -13,6 +13,12 @@ type NtfyConfig = {
map?: string;
combineMap?: string;
topic?: string;
completion?: {
completeButton?: string;
completeButton1?: string;
completeButton2?: string;
completeButton3?: string;
}
} & BackendSettings;
type NtfyDTO = {
@@ -41,7 +47,7 @@ export class NtfySH extends Backend<NtfyConfig> {
const dto = mapper(task);
const actions = task && profileConfig.completion?.enable && config.server?.baseUrl && !task.recurrenceRule
? [buildCompleteAction(task, profileConfig.name, config.server.baseUrl, "✅")]
? [buildCompleteAction(task, profileConfig.name, config.server.baseUrl, backendConfig?.completion?.completeButton ?? "✅")]
: [];
this.#doNotify(backendConfig, dto, actions);
@@ -49,6 +55,11 @@ export class NtfySH extends Backend<NtfyConfig> {
protected async notifyCombined(config: Config, profileConfig: ProfileConfig, backendConfig: NtfyConfig, tasks: Task[]): Promise<void> {
const chunks = chunkArray(tasks, 3);
const completionLabels = [
backendConfig?.completion?.completeButton1 ?? "✅1⃣",
backendConfig?.completion?.completeButton2 ?? "✅2⃣",
backendConfig?.completion?.completeButton3 ?? "✅3⃣"
];
const context = {
mapPriority,
@@ -63,7 +74,7 @@ export class NtfySH extends Backend<NtfyConfig> {
const dto = mapper(chunk);
const actions = profileConfig.completion?.enable && config.server?.baseUrl
? chunk.map((t, i) => buildCompleteAction(t, profileConfig.name, config.server!.baseUrl!, ["✅1⃣", "✅2⃣", "✅3⃣"][i] ?? "✅"))
? chunk.map((t, i) => buildCompleteAction(t, profileConfig.name, config.server!.baseUrl!, completionLabels[i] ?? "✅"))
: [];
await this.#doNotify(backendConfig, dto, actions);
@@ -101,7 +112,7 @@ function buildCompleteAction(task: Task, profile: string, baseUrl: string, label
return {
action: "http",
label: "✅",
label,
url: `${baseUrl}/complete`,
method: "POST",
headers: {