refactor: replace global WAHA notifications with granular user and group-specific templates and dispatch logic

This commit is contained in:
root
2026-03-30 01:02:23 +07:00
parent 68a764c0df
commit 596a233898
8 changed files with 502 additions and 131 deletions

View File

@@ -57,8 +57,15 @@ if ($action === 'api') {
$stmt = $pdo->prepare("UPDATE tasks SET $set_clause WHERE id = ?");
$stmt->execute($params);
$task_to_upd = query("SELECT title FROM tasks WHERE id=?", [$task_id])->fetch();
if($task_to_upd) notify_waha('Moved to '.$status, 'Task Status', $task_to_upd['title']);
$t = query("SELECT title, assignee_type, assignee_id FROM tasks WHERE id=?", [$task_id])->fetch();
if($t) {
$ctx = ['action' => 'Moved to '.$status, 'module' => 'Task', 'item' => $t['title']];
if($t['assignee_type'] === 'user' && $t['assignee_id']) {
notify_user($t['assignee_id'], "Task '{$t['title']}' moved to $status", $ctx);
} elseif($t['assignee_type'] === 'group' && $t['assignee_id']) {
notify_group($t['assignee_id'], "Group task '{$t['title']}' moved to $status", $ctx);
}
}
echo json_encode(['status'=>'ok']);
exit;
}
@@ -71,8 +78,15 @@ if ($action === 'api') {
if($task_id && $comment) {
$stmt = $pdo->prepare("INSERT INTO task_comments (task_id, comment, created_by) VALUES (?, ?, ?)");
$stmt->execute([$task_id, $comment, $user_id]);
$t = query("SELECT title FROM tasks WHERE id=?", [$task_id])->fetch();
if($t) notify_waha('Commented on', 'Task', $t['title']);
$t = query("SELECT title, assignee_type, assignee_id FROM tasks WHERE id=?", [$task_id])->fetch();
if($t) {
$ctx = ['action' => 'New Comment', 'module' => 'Task', 'item' => $t['title']];
if($t['assignee_type'] === 'user' && $t['assignee_id']) {
notify_user($t['assignee_id'], "New comment on '{$t['title']}'", $ctx);
} elseif($t['assignee_type'] === 'group' && $t['assignee_id']) {
notify_group($t['assignee_id'], "New comment on group task '{$t['title']}'", $ctx);
}
}
}
echo json_encode(['status'=>'ok']);
exit;