Skip to content

Commit

Permalink
Merge branch 'master' of github.com:freescout-helpdesk/freescout into…
Browse files Browse the repository at this point in the history
… dist
  • Loading branch information
freescout-helpdesk committed May 2, 2023
2 parents 309b832 + a67f35e commit 2fe0f51
Show file tree
Hide file tree
Showing 12 changed files with 89 additions and 9 deletions.
2 changes: 1 addition & 1 deletion app/Console/Kernel.php
Expand Up @@ -70,7 +70,7 @@ protected function schedule(Schedule $schedule)
->monthly();

$schedule->command('freescout:clean-tmp')
->weekly();
->daily();

// Logs monitoring.
$alert_logs_period = config('app.alert_logs_period');
Expand Down
5 changes: 5 additions & 0 deletions app/Conversation.php
Expand Up @@ -522,6 +522,11 @@ public function isPublished()
return $this->state == self::STATE_PUBLISHED;
}

public function isDraft()
{
return $this->state == self::STATE_DRAFT;
}

/**
* Get status name.
*
Expand Down
8 changes: 7 additions & 1 deletion app/Http/Controllers/ConversationsController.php
Expand Up @@ -298,7 +298,10 @@ public function view(Request $request, $id)
if (count($from_aliases) == 1) {
$from_aliases = [];
}
if (count($from_aliases)) {
if ($conversation->isDraft() && !empty($threads[0])) {
$from_alias = $threads[0]->from ?? '';
}
if (count($from_aliases) && !$from_alias) {
// Preset the last alias used.
$check_initial_thread = true;
foreach ($threads as $thread) {
Expand Down Expand Up @@ -412,6 +415,7 @@ public function create(Request $request, $mailbox_id)
'folders' => $mailbox->getAssesibleFolders(),
'after_send' => $after_send,
'to' => $to,
'from_aliases' => $mailbox->getAliases(),
]);
}

Expand Down Expand Up @@ -1450,6 +1454,7 @@ public function ajax(Request $request)
} else {
$thread->type = Thread::TYPE_MESSAGE;
}
$thread->from = $request->from_alias ?? null;
$thread->body = $request->body;
$thread->setTo($to);
// We save CC and BCC as is and filter emails when sending replies
Expand Down Expand Up @@ -1582,6 +1587,7 @@ public function ajax(Request $request)

$response['data'] = [
'thread_id' => $thread->id,
'from_alias' => $thread->from,
'to' => $thread->getToFirst(),
'cc' => $thread->getCcArray(),
'bcc' => $thread->getBccArray(),
Expand Down
4 changes: 3 additions & 1 deletion app/Jobs/SendNotificationToUsers.php
Expand Up @@ -59,7 +59,9 @@ public function handle()

// Threads has to be sorted here, if sorted before, they come here in wrong order
$this->threads = $this->threads->sortByDesc(function ($item, $key) {
return $item->id;
// Threads has to be sorted by created_at and not by id.
// https://github.com/freescout-helpdesk/freescout/issues/2938
return $item->created_at->getTimestamp();
});

$headers = [];
Expand Down
4 changes: 3 additions & 1 deletion app/Jobs/SendReplyToCustomer.php
Expand Up @@ -101,7 +101,9 @@ public function handle()

// Threads has to be sorted here, if sorted before, they come here in wrong order
$this->threads = $this->threads->sortByDesc(function ($item, $key) {
return $item->id;
// Threads has to be sorted by created_at and not by id.
// https://github.com/freescout-helpdesk/freescout/issues/2938
return $item->created_at->getTimestamp();
});

$new = false;
Expand Down
11 changes: 10 additions & 1 deletion app/Misc/Helper.php
Expand Up @@ -1791,7 +1791,9 @@ public static function phoneToNumeric($phone)
public static function checkRequiredExtensions()
{
$php_extensions = [];
foreach (\Config::get('installer.requirements.php') as $extension_name) {
$required_extensions = \Config::get('installer.requirements.php');

foreach ($required_extensions as $extension_name) {
$alternatives = explode('/', $extension_name);
if ($alternatives) {
foreach ($alternatives as $alternative) {
Expand Down Expand Up @@ -1847,4 +1849,11 @@ public static function maybeShowSendingProblemsAlert()

return $flashes;
}

public static function mbUcfirst($string, $encoding = 'UTF-8')
{
$first_char = mb_substr($string, 0, 1, $encoding);
$then = mb_substr($string, 1, null, $encoding);
return mb_strtoupper($first_char, $encoding) . $then;
}
}
33 changes: 32 additions & 1 deletion app/User.php
Expand Up @@ -505,7 +505,38 @@ public static function dateFormat($date, $format = 'M j, Y H:i', $user = null, $
$date->setTimezone($user->timezone);
}
}
return $date->format($format);

if (class_exists('IntlDateFormatter')) {

// Convert `strftime` format to `IntlDateFormatter` pattern.
// https://unicode-org.github.io/icu/userguide/format_parse/datetime/
$format = strtr($format, [
'M' => 'MMM',
'm' => 'MM',
'j' => 'd',
'd' => 'dd',
'H' => 'HH',
'h' => 'hh',
'i' => 'mm',
'l' => 'cccc',
'O' => 'xx',
]);

// Remove dot from month name.
$formatted = $date->formatLocalized($format);
if (!strstr($format, '.')) {
$formatted = str_replace('.', '', $formatted);
}

// AM/PM to am/pm
$formatted = preg_replace_callback('#\d(AM|PM)$#', function ($m) {
return strtolower($m[1] ?? '');
}, $formatted);

return \Helper::mbUcfirst($formatted);
} else {
return $date->format($format);
}
}

/**
Expand Down
2 changes: 1 addition & 1 deletion config/app.php
Expand Up @@ -18,7 +18,7 @@
| or any other location as required by the application or its packages.
*/

'version' => '1.8.73',
'version' => '1.8.74',

/*
|--------------------------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions config/installer.php
Expand Up @@ -39,6 +39,7 @@
'ZIP',
'iconv',
'cURL',
//'intl',
],
// 'apache' => [
// 'mod_rewrite',
Expand Down
12 changes: 11 additions & 1 deletion overrides/nesbot/carbon/src/Carbon/Carbon.php
Expand Up @@ -1844,7 +1844,17 @@ public function formatLocalized($format)
$format = preg_replace('#(?<!%)((?:%%)*)%e#', '\1%#d', $format); // @codeCoverageIgnore
}

$formatted = strftime($format, strtotime($this->toDateTimeString()));
// https://php.watch/versions/8.1/strftime-gmstrftime-deprecated
//$formatted = strftime($format, strtotime($this->toDateTimeString()));
$formatter = new \IntlDateFormatter(
config('app.locale'),
\IntlDateFormatter::LONG,
\IntlDateFormatter::NONE,
config('app.timezone'),
\IntlDateFormatter::GREGORIAN,
$format
);
$formatted = datefmt_format($formatter, strtotime($this->toDateTimeString()));

return static::$utf8 ? utf8_encode($formatted) : $formatted;
}
Expand Down
14 changes: 14 additions & 0 deletions resources/views/conversations/create.blade.php
Expand Up @@ -133,6 +133,20 @@
</div>
</div>

@if (count($from_aliases))
<div class="form-group email-conv-fields">
<label class="col-sm-2 control-label">{{ __('From') }}</label>

<div class="col-sm-9">
<select name="from_alias" class="form-control">
@foreach ($from_aliases as $from_alias_email => $from_alias_name)
<option value="@if ($from_alias_email != $mailbox->email){{ $from_alias_email }}@endif" @if (!empty($from_alias) && $from_alias == $from_alias_email)selected="selected"@endif>@if ($from_alias_name){{ $from_alias_email }} ({{ $from_alias_name }})@else{{ $from_alias_email }}@endif</option>
@endforeach
</select>
</div>
</div>
@endif

<div class="form-group{{ $errors->has('to') ? ' has-error' : '' }}" id="field-to">
<label for="to" class="col-sm-2 control-label">{{ __('To') }}</label>

Expand Down
2 changes: 1 addition & 1 deletion resources/views/system/status.blade.php
Expand Up @@ -84,7 +84,7 @@
<tbody>
@foreach ($php_extensions as $extension_name => $extension_status)
<tr>
<th>{{ $extension_name }}</th>
<th>{{ $extension_name }}@if ($extension_name == 'intl' && !$extension_status) {{ __('(optional)') }}@endif</th>
<td class="table-main-col">
@if ($extension_status)
<strong class="text-success">OK</strong>
Expand Down

0 comments on commit 2fe0f51

Please sign in to comment.