Skip to content

Commit

Permalink
Merge branch 'master' into snyk-upgrade-5eeaa187e11ac5f3cbe0771fda8ec424
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelfolaron authored May 25, 2024
2 parents cfb2dd1 + 17c825c commit 474f488
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 41 deletions.
69 changes: 33 additions & 36 deletions app/Domain/Notifications/Services/Messengers.php
Original file line number Diff line number Diff line change
Expand Up @@ -203,23 +203,28 @@ private function zulipWebhook(NotificationModel $notification): bool
*/
public function discordWebhook(NotificationModel $notification): bool
{
$converter = false;
$ticketService = app()->make(Tickets::class);

for ($i = 1; 3 >= $i; $i++) {
$discordWebhookURL = $this->settingsRepo->getSetting("projectsettings.{$notification->projectId}.discordWebhookURL{$i}");
if ($discordWebhookURL !== '' && $discordWebhookURL !== false) {
if (!$converter) {
$converter = new HtmlConverter();
}
$timestamp = date('c', strtotime('now'));
$fields = [
// Additional data to be sent; e.g.:
//[
// 'name' => $subject,
// 'value' => $message,
// 'inline' => FALSE
//],
[
'name' => $this->language->__("label.project"),
'value' => $this->projectName,
'inline' => true
],
];

$statusLabelsArray = $ticketService->getStatusLabels($notification->projectId);
if (!empty($notification->entity->status) && !empty($statusLabelsArray[$notification->entity->status])) {
$fields[] = [
'name' => $this->language->__("label.todo_status"),
'value' => $statusLabelsArray[$notification->entity->status]['name'],
'inline' => true
];
}

$url_link = (
empty($notification->url['url'])
? ''
Expand All @@ -228,29 +233,17 @@ public function discordWebhook(NotificationModel $notification): bool

// For details on the JSON layout: https://birdie0.github.io/discord-webhooks-guide/index.html
$data_string = json_encode([
'content' => 'Leantime' . ' - ' . $_SESSION["companysettings.sitename"],
'avatar_url' => 'https://s3-us-west-2.amazonaws.com/leantime-website/wp-content/uploads/2019/03/22224016/logoIcon.png',
'tts' => false,
'embeds' => [
[
'title' => $notification->subject,
'type' => 'rich',
'description' => html_entity_decode($converter->convert($notification->message)),
'url' => $url_link,
'timestamp' => $timestamp,
'color' => hexdec('1b75bb'),
'footer' => [
'text' => 'Leantime',
'icon_url' => $url_link,
],
'author' => [
'name' => $this->projectName,
'url' => $url_link,
],
'title' => $notification->message,
'url' => $url_link,
'timestamp' => date('c', strtotime('now')),
'fields' => $fields,
],
]
],

], JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);

try {
Expand Down Expand Up @@ -283,23 +276,27 @@ public function prepareMessage(NotificationModel $notification): array
$headline = $notification->entity->headline;
$status = $notification->entity->status;
}

$fields = [
'title' => $this->language->__("headlines.project_with_name") . ' ' . $this->projectName,
'short' => false,
];

$statusLabelsArray = $ticketService->getStatusLabels($notification->projectId);
$message = array(
if (!empty($statusLabelsArray[$status])) {
$fields['value'] = $this->language->__("label.todo_status") . ': '. $statusLabelsArray[$status]['name'];
}

$message = [
[
'color' => '#1b75bb',
'fallback' => $notification->message,
'pretext' => $notification->message,
'title' => $headline,
'title_link' => $notification->url['url'],
'fields' => array(
[
'title' => $this->language->__("headlines.project_with_name") . ' ' . $this->projectName,
'value' => $this->language->__("label.todo_status") . ': ' . empty($statusLabelsArray[$status]) ? '' : $statusLabelsArray[$status]['name'],
'short' => false,
],
),
'fields' => $fields,
],
);
];

return $message;
}
Expand Down
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"datatables.net-rowgroup": "^1.4.1",
"datatables.net-rowreorder": "^1.4.1",
"fullcalendar": "^6.1.11",
"htmx.org": "^1.9.11",
"htmx.org": "^1.9.12",
"gridstack": "^10.1.2",
"ical.js": "^1.5.0",
"imagesloaded": "^5.0.0",
Expand Down

0 comments on commit 474f488

Please sign in to comment.