[+] Добавлена поддержка фалов и картинок в диалогах
[*] поправлены миграции
This commit is contained in:
1 parent
95f0611022
commit
94f387b072
14 files changed
+104
-6
No files matched your search
@@ -202,11 +202,25 @@ body {
|
||||
color: white;
|
||||
}
|
||||
|
||||
|
||||
.main .messageBox .message a {
|
||||
color: inherit;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
img.dialogImage {
|
||||
max-width: 300px;
|
||||
max-height: 300px;
|
||||
}
|
||||
|
||||
a.fileLink {
|
||||
text-decoration: underline !important;
|
||||
}
|
||||
|
||||
a.fileLink:before {
|
||||
content: "📂 "
|
||||
}
|
||||
|
||||
.main .messageBox .message.fromCompanion:before {
|
||||
content: "";
|
||||
border: solid transparent;
|
||||
|
||||
@@ -14,6 +14,15 @@
|
||||
/** @var string Таблица с сообщениями */
|
||||
const TABLE_MESSAGES = DB_TABLE_PREFIX . 'messages';
|
||||
|
||||
/** @var string MESSAGE_TYPE_TEXT Тип сообщения: текст */
|
||||
const MESSAGE_TYPE_TEXT = 'text';
|
||||
|
||||
/** @var string MESSAGE_TYPE_FILE Тип сообщения: файл */
|
||||
const MESSAGE_TYPE_FILE = 'file';
|
||||
|
||||
/** @var string MESSAGE_TYPE_IMAGE Тип сообщения: изображение */
|
||||
const MESSAGE_TYPE_IMAGE = 'image';
|
||||
|
||||
/**
|
||||
* @var User $user Объект пользователя
|
||||
*/
|
||||
@@ -139,11 +148,11 @@
|
||||
}
|
||||
|
||||
/**
|
||||
* Отправка сообщения
|
||||
* Отправка тестовых сообщения
|
||||
*
|
||||
* @throws CoreException
|
||||
*/
|
||||
public function sendMessage(int $to, string $message)
|
||||
public function sendMessage(int $to, string $message): bool
|
||||
{
|
||||
if (!User::isUserExistsByParams(['id' => $to])) {
|
||||
throw new CoreException('Пользователь с идентификатором ' . $to . ' отсутствует в базе', CoreException::ERROR_USER_NOT_FOUND);
|
||||
@@ -157,7 +166,33 @@
|
||||
$DB->update(self::TABLE_DIALOGS, ['id' => $dialogId], ['viewed'=> CODE_VALUE_N, 'send' => $this->user->getId(), 'receive' => $to]);
|
||||
}
|
||||
|
||||
$result = $DB->addItem(self::TABLE_MESSAGES, ['dialog_id' => $dialogId, 'user_from' => $this->user->getId(), 'user_to' => $to, 'text' => $message]);
|
||||
$result = $DB->addItem(self::TABLE_MESSAGES, ['dialog_id' => $dialogId, 'type' => self::MESSAGE_TYPE_TEXT, 'user_from' => $this->user->getId(), 'user_to' => $to, 'text' => $message]);
|
||||
return (int)$result > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Отправка файлов
|
||||
*
|
||||
* @param int $fileId
|
||||
*
|
||||
*
|
||||
* @throws CoreException
|
||||
*/
|
||||
public function sendFile(int $to, int $fileId): bool
|
||||
{
|
||||
if (!User::isUserExistsByParams(['id' => $to])) {
|
||||
throw new CoreException('Пользователь с идентификатором ' . $to . ' отсутствует в базе', CoreException::ERROR_USER_NOT_FOUND);
|
||||
}
|
||||
/** @var $DB DB Объект базы данных */
|
||||
$DB = DB::getInstance();
|
||||
$dialogId = self::getDialogId($this->user->getId(), $to);
|
||||
if (empty($dialogId)) {
|
||||
$dialogId = $this->createDialog($to);
|
||||
} else {
|
||||
$DB->update(self::TABLE_DIALOGS, ['id' => $dialogId], ['viewed'=> CODE_VALUE_N, 'send' => $this->user->getId(), 'receive' => $to]);
|
||||
}
|
||||
|
||||
$result = $DB->addItem(self::TABLE_MESSAGES, ['dialog_id' => $dialogId, 'type' => self::MESSAGE_TYPE_FILE, 'user_from' => $this->user->getId(), 'user_to' => $to, 'text' => $fileId]);
|
||||
return (int)$result > 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -70,7 +70,7 @@
|
||||
{
|
||||
$this->folder = $_SERVER['DOCUMENT_ROOT'] . self::FOLDER;
|
||||
$this->DB = DB::getInstance();
|
||||
if (!empty($id)) {
|
||||
if (!empty($id) && $id > 0) {
|
||||
$this->id = $id;
|
||||
$this->loadFileProps();
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
use Core\CoreException;
|
||||
use Core\Helpers\{Cache, Log, Mail, Sanitize, SystemFunctions};
|
||||
use Core\DataBases\DB;
|
||||
use Throwable;
|
||||
|
||||
class User
|
||||
{
|
||||
@@ -925,6 +926,14 @@
|
||||
foreach ($messages as $key => $message) {
|
||||
$messages[$key]['user_from_data'] = (new self((int)$message['user_from']))->getAllUserData(true);
|
||||
$messages[$key]['user_to_data'] = (new self((int)$message['user_to']))->getAllUserData(true);
|
||||
if ($message['type'] !== Dialog::MESSAGE_TYPE_TEXT) {
|
||||
$messages[$key]['file'] = (new File((int)$message['text']))->getAllProps();
|
||||
if ($messages[$key]['file'] === null) {
|
||||
$messages[$key]['file']['error'] = true;
|
||||
} else {
|
||||
$messages[$key]['file']['error'] = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $messages;
|
||||
|
||||
@@ -5,6 +5,8 @@ use Phinx\Migration\AbstractMigration;
|
||||
|
||||
final class Users extends AbstractMigration
|
||||
{
|
||||
private $table;
|
||||
private $data;
|
||||
|
||||
public function init(): void
|
||||
{
|
||||
|
||||
@@ -5,6 +5,8 @@ use Phinx\Migration\AbstractMigration;
|
||||
|
||||
final class Roles extends AbstractMigration
|
||||
{
|
||||
private $table;
|
||||
private $data;
|
||||
public function init(): void
|
||||
{
|
||||
$this->table = 'd_roles';
|
||||
|
||||
@@ -5,6 +5,9 @@ use Phinx\Migration\AbstractMigration;
|
||||
|
||||
final class UserRoles extends AbstractMigration
|
||||
{
|
||||
private $table;
|
||||
private $data;
|
||||
|
||||
public function init(): void
|
||||
{
|
||||
$this->table = 'd_user_roles';
|
||||
|
||||
@@ -5,6 +5,8 @@ use Phinx\Migration\AbstractMigration;
|
||||
|
||||
final class UserMeta extends AbstractMigration
|
||||
{
|
||||
private $table;
|
||||
|
||||
public function init(): void
|
||||
{
|
||||
$this->table = 'd_user_meta';
|
||||
|
||||
@@ -5,6 +5,8 @@ use Phinx\Migration\AbstractMigration;
|
||||
|
||||
final class Threads extends AbstractMigration
|
||||
{
|
||||
private $table;
|
||||
|
||||
public function init()
|
||||
{
|
||||
$this->table = 'd_threads';
|
||||
|
||||
@@ -5,6 +5,8 @@ use Phinx\Migration\AbstractMigration;
|
||||
|
||||
final class ThreadsHistory extends AbstractMigration
|
||||
{
|
||||
private $table;
|
||||
|
||||
public function init()
|
||||
{
|
||||
$this->table = 'd_threads_history';
|
||||
|
||||
@@ -5,12 +5,16 @@ use Phinx\Migration\AbstractMigration;
|
||||
|
||||
final class Files extends AbstractMigration
|
||||
{
|
||||
private $table;
|
||||
private $data;
|
||||
|
||||
public function init()
|
||||
{
|
||||
$this->table = 'd_files';
|
||||
$this->data = [
|
||||
[
|
||||
'name' => 'system.png',
|
||||
'size' => 1024,
|
||||
'path' => '/uploads/users/system.png',
|
||||
],
|
||||
];
|
||||
@@ -20,6 +24,7 @@ final class Files extends AbstractMigration
|
||||
{
|
||||
$table = $this->table($this->table);
|
||||
$table->addColumn('name', 'string', ['limit' => 255, 'default' => null])
|
||||
->addColumn('size', 'integer', ['signed' => false, 'null' => true, 'default' => null])
|
||||
->addColumn('path', 'text', ['default' => null])
|
||||
->create();
|
||||
$table->insert($this->data);
|
||||
|
||||
@@ -5,6 +5,8 @@ use Phinx\Migration\AbstractMigration;
|
||||
|
||||
final class MailHistory extends AbstractMigration
|
||||
{
|
||||
private $table;
|
||||
|
||||
public function init()
|
||||
{
|
||||
$this->table = 'd_mail_history';
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
|
||||
final class UtmHistory extends AbstractMigration
|
||||
{
|
||||
private $table;
|
||||
|
||||
public function init()
|
||||
{
|
||||
$this->table = 'd_utm_history';
|
||||
|
||||
+20
-2
@@ -8,9 +8,27 @@
|
||||
{% for message in messages %}
|
||||
<div class="message {% if message.user_from == userId %}fromMe{% else %}fromCompanion{% endif %}">
|
||||
<div class="name"><a href="/users/{{ message.user_from_data.id }}">{{ message.user_from_data.name }}</a></div>
|
||||
<div class="text">{{ message.text }}</div>
|
||||
<div class="text">
|
||||
{% if message.type == 'text' %}
|
||||
{{ message.text }}
|
||||
{% elseif message.type == 'image' %}
|
||||
{% if message.file.error == false %}
|
||||
<a href="{{ message.file.path }}" target="_blank">
|
||||
<img class="dialogImage" src="{{ message.file.path }}" alt="{{ message.file.name }}">
|
||||
</a>
|
||||
{% else %}
|
||||
<b>Некорректное изображение</b>
|
||||
{% endif %}
|
||||
{% elseif message.type == 'file' %}
|
||||
{% if message.file.error == false %}
|
||||
<a class="fileLink" href="{{ message.file.path }}" target="_blank">{{ message.file.name }}</a>
|
||||
{% else %}
|
||||
<b>Некорректный файл</b>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
</div>
|
||||
<div class="date">{{ message.date }}</div>
|
||||
{% if message.user_from == userId%}
|
||||
{% if message.user_from == userId %}
|
||||
<div class="deliveryStatus {% if message.user_from == userId and message.viewed == "Y" %}viewed{% endif %}"> </div>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
Reference in new issue
Block a user