Merge pull request #672 from Dirk-Kokx/master

Add Conversation History option to conversations
This commit is contained in:
FreeScout
2020-07-15 11:38:46 +03:00
committed by GitHub
6 changed files with 175 additions and 7 deletions

View File

@@ -19,7 +19,7 @@ class Conversation extends Model
use Rememberable;
// This is obligatory.
public $rememberCacheDriver = 'array';
/**
* Max length of the preview.
*/
@@ -125,6 +125,50 @@ class Conversation extends Model
self::SOURCE_TYPE_API => 'api',
];
/**
* Email history types
*/
const EMAIL_HISTORY_GLOBAL = 0;
const EMAIL_HISTORY_NONE = 1;
const EMAIL_HISTORY_LAST = 2;
const EMAIL_HISTORY_FULL = 3;
public static $email_history_types = [
self::EMAIL_HISTORY_GLOBAL => 'global',
self::EMAIL_HISTORY_NONE => 'none',
self::EMAIL_HISTORY_LAST => 'last',
self::EMAIL_HISTORY_FULL => 'full',
];
public static function getEmailConvHistoryName($type) {
$label = '';
$globalstring = false;
$global = env('APP_EMAIL_CONV_HISTORY', false);
if($global) {
$globalstring = self::getEmailConvHistoryName($global);
}
switch ($type) {
case 'global':
$label = __('Default');
if ($globalstring)
$label .= ' ('.$globalstring.')';
break;
case 'none':
$label = __('Do not include previous messages');
break;
case 'last':
$label = __('Include the last message');
break;
case 'full':
$label = __('Send full conversation history');
break;
}
return $label;
}
/**
* Assignee.
*/
@@ -729,7 +773,7 @@ class Conversation extends Model
*/
public static function sanitizeEmails($emails)
{
// Create customers if needed: Test <test1@example.com>
// Create customers if needed: Test <test1@example.com>
if (is_array($emails)) {
foreach ($emails as $i => $email) {
preg_match("/^(.+)\s+([^\s]+)$/", $email, $m);
@@ -773,7 +817,7 @@ class Conversation extends Model
/**
* Static function for retrieving URL.
*
*
* @param [type] $id [description]
* @param [type] $folder_id [description]
* @param [type] $thread_id [description]
@@ -1410,7 +1454,7 @@ class Conversation extends Model
public function changeUser($new_user_id, $user, $create_thread = true)
{
$prev_user_id = $this->user_id;
$this->setUser($new_user_id);
$this->save();
@@ -1436,7 +1480,7 @@ class Conversation extends Model
public function deleteToFolder($user)
{
$folder_id = $this->getCurrentFolder();
$this->state = Conversation::STATE_DELETED;
$this->user_updated_at = date('Y-m-d H:i:s');
$this->updateFolder();
@@ -1563,7 +1607,7 @@ class Conversation extends Model
$thread->subtype = Thread::SUBTYPE_FORWARD;
$thread->setMeta('forward_child_conversation_number', $forwarded_conversation->number);
$thread->setMeta('forward_child_conversation_id', $forwarded_conversation->id);
$thread->save();
// Save forwarded thread.

View File

@@ -1736,6 +1736,24 @@ class ConversationsController extends Controller
break;
case 'save_settings':
$conversation = Conversation::find($request->conversation_id);
if (!$conversation) {
$response['msg'] = __('Conversation not found');
break;
}
if (!$response['msg'] && !$conversation->mailbox->userHasAccess($user->id)) {
$response['msg'] = __('Not enough permissions');
break;
}
$conversation->email_conv_history = $request->email_conv_history;
$conversation->save();
$response['status'] = 'success';
break;
default:
$response['msg'] = 'Unknown action';
break;

View File

@@ -114,10 +114,19 @@ class SendReplyToCustomer implements ShouldQueue
}
}
if (config('app.email_conv_history') == 'full') {
$email_conv_history = $this->conversation->email_conv_history;
if(!$email_conv_history || $email_conv_history === 'global')
$email_conv_history = config('app.email_conv_history');
if ($email_conv_history == 'full') {
$send_previous_messages = true;
}
if ($email_conv_history == 'last') {
$send_previous_messages = true;
$this->threads = $this->threads->slice(0, 2);
}
if (config('app.email_conv_history') == 'last') {
$send_previous_messages = true;
$this->threads = $this->threads->slice(0, 2);

View File

@@ -0,0 +1,33 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class ConversationsAddHistorySetting extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('conversations', function (Blueprint $table) {
// Mute notifications for events not directly related to the user
$table->unsignedTinyInteger('email_conv_history')->default(0);
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('conversations', function (Blueprint $table) {
$table->dropColumn('email_conv_history');
});
}
}

View File

@@ -0,0 +1,57 @@
<div class="modal fade" tabindex="-1" role="dialog" id="settingsModal">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<h4 class="modal-title">{{ __('Conversation Settings') }}</h4>
</div>
<div class="modal-body">
<form action="">
<div class="form-group">
<label for="setting_email_conv_history">{{ __('Conversation History') }}</label>
<select id="setting_email_conv_history" class="form-control" name="email_conv_history" required autofocus>
@foreach(\App\Conversation::$email_history_types as $key => $type)
<option value="{{ $key }}" @if (old('email_conv_history', $conversation->email_conv_history) == $key)selected="selected"@endif>{{ \App\Conversation::getEmailConvHistoryName($type) }}</option>
@endforeach
</select>
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">{{ __('Cancel') }}</button>
<button type="button" id="save_button" class="btn btn-primary">{{ __('Save') }}</button>
</div>
</div>
</div>
</div>
@section('javascript')
@parent
var $settingsModal = jQuery('#settingsModal');
var $historySelect = jQuery('#setting_email_conv_history', $settingsModal);
jQuery('#save_button', $settingsModal).on('click', function(e) {
e.preventDefault();
$settingsModal.modal('hide');
console.log('sending settings');
fsAjax(
{
action: 'save_settings',
conversation_id: {{ $conversation->id }},
email_conv_history: $historySelect.children("option:selected").val(),
},
laroute.route('conversations.ajax'),
function(response) {
if (typeof(response.status) != "undefined" && response.status !== 'success') {
if (typeof (response.msg) != "undefined") {
showFloatingAlert('error', response.msg);
} else {
showFloatingAlert('error', Lang.get("messages.error_occured"));
}
loaderHide();
}
},
true
);
});
@append

View File

@@ -47,6 +47,9 @@
@else
<li class="hidden-lg hidden-md hidden-sm"><a href="#" class="conv-delete-forever"><i class="glyphicon glyphicon-trash"></i> {{ __("Delete Forever") }}</a></li>
@endif
<li>
<a href="#" class="conv-settings" data-toggle="modal" data-target="#settingsModal"><i class="glyphicon glyphicon-cog"></i> {{ __('Settings') }}</a>
</li>
@action('conversation.append_action_buttons', $conversation, $mailbox)
</ul>
</div>
@@ -261,6 +264,10 @@
</div>
@endsection
@section('body_bottom')
@include('conversations.partials.settings_modal', ['conversation' => $conversation])
@append
@include('partials/editor')
@section('javascript')