From d49fcc3a345e77efa327b61c3590520f4cdd71cb Mon Sep 17 00:00:00 2001 From: munafio Date: Wed, 4 May 2022 05:39:00 +0300 Subject: [PATCH] v1.4.0 updates, fixes, and improvements --- CHANGELOG.md | 17 + src/ChatifyMessenger.php | 62 +++- .../Controllers/Api/MessagesController.php | 20 +- src/Http/Controllers/MessagesController.php | 22 +- src/assets/css/style.css | 62 ++-- src/assets/js/code.js | 309 ++++++++++-------- src/config/chatify.php | 20 +- src/views/layouts/favorite.blade.php | 2 +- src/views/layouts/footerLinks.blade.php | 6 + src/views/layouts/listItem.blade.php | 4 +- src/views/layouts/messageCard.blade.php | 53 ++- src/views/layouts/modals.blade.php | 2 +- 12 files changed, 334 insertions(+), 245 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index eaccbd1..af4b0df 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,23 @@ # Change log All notable changes to this project will be documented in this file. +v.1.4.0 + +## v1.4.0 (2022-05-02) + +### Added + +- [Gravatar](https:://gravatar.com) support (optional, can be changed at config/chatify.php). +- Delete Message by ID. +- Laravel's Storage disk now supported and can be changed from the config. + +### Changed + +- File upload (user avatar & attachments) `allowed files` and `max size` now can be changed from one place which is (config/chatify.php). + +### Fixed + +- Bugs and UI/UX design fixes/improvements. ## v1.3.4 (2022-02-04) diff --git a/src/ChatifyMessenger.php b/src/ChatifyMessenger.php index 9aee3bd..0e0623c 100644 --- a/src/ChatifyMessenger.php +++ b/src/ChatifyMessenger.php @@ -228,22 +228,27 @@ public function getContactItem($user) return view('Chatify::layouts.listItem', [ 'get' => 'users', - 'user' => $this->getUserWithGravatar($user), + 'user' => $this->getUserWithAvatar($user), 'lastMessage' => $lastMessage, 'unseenCounter' => $unseenCounter, ])->render(); } - public function getUserWithGravatar($user) + /** + * Get user with avatar (formatted). + * + * @param Collection $user + * @return Collection + */ + public function getUserWithAvatar($user) { - $imageSize = 200; - - if ($user->avatar == 'avatar.png') { - $user->avatar = 'https://www.gravatar.com/avatar/' . md5(strtolower(trim($user->email))) . '?s=' . $imageSize; + if ($user->avatar == 'avatar.png' && config('chatify.gravatar.enabled')) { + $imageSize = config('chatify.gravatar.image_size'); + $imageset = config('chatify.gravatar.imageset'); + $user->avatar = 'https://www.gravatar.com/avatar/' . md5(strtolower(trim($user->email))) . '?s=' . $imageSize . '&d=' . $imageset; } else { - $user->avatar = Storage::disk(config('chatify.disk_name'))->url(config('chatify.user_avatar.folder') . '/' . $user->avatar); + $user->avatar = self::getUserAvatarUrl($user->avatar); } - return $user; } @@ -322,8 +327,8 @@ public function deleteConversation($user_id) // delete file attached if exist if (isset($msg->attachment)) { $path = config('chatify.attachments.folder').'/'.json_decode($msg->attachment)->new_name; - if (Storage::disk(config('chatify.disk_name'))->exists($path)) { - Storage::disk(config('chatify.disk_name'))->delete($path); + if (self::storage()->exists($path)) { + self::storage()->delete($path); } } // delete from database @@ -336,7 +341,7 @@ public function deleteConversation($user_id) } /** - * Delete message + * Delete message by ID * * @param int $id * @return boolean @@ -349,8 +354,8 @@ public function deleteMessage($id) // delete file attached if exist if (isset($msg->attachment)) { $path = config('chatify.attachments.folder') . '/' . json_decode($msg->attachment)->new_name; - if (Storage::disk(config('chatify.disk_name'))->exists($path)) { - Storage::disk(config('chatify.disk_name'))->delete($path); + if (self::storage()->exists($path)) { + self::storage()->delete($path); } } // delete from database @@ -363,4 +368,35 @@ public function deleteMessage($id) return 0; } } + + /** + * Return a storage instance with disk name specified in the config. + * + */ + public function storage() + { + return Storage::disk(config('chatify.storage_disk_name')); + } + + /** + * Get user avatar url. + * + * @param string $user_avatar_name + * @return string + */ + public function getUserAvatarUrl($user_avatar_name) + { + return self::storage()->url(config('chatify.user_avatar.folder') . '/' . $user_avatar_name); + } + + /** + * Get attachment's url. + * + * @param string $attachment_name + * @return string + */ + public function getAttachmentUrl($attachment_name) + { + return self::storage()->url(config('chatify.attachments.folder') . '/' . $attachment_name); + } } diff --git a/src/Http/Controllers/Api/MessagesController.php b/src/Http/Controllers/Api/MessagesController.php index d826f99..cf2e2c5 100644 --- a/src/Http/Controllers/Api/MessagesController.php +++ b/src/Http/Controllers/Api/MessagesController.php @@ -62,7 +62,7 @@ public function idFetchData(Request $request) if ($request['type'] == 'user') { $fetch = User::where('id', $request['id'])->first(); if($fetch){ - $userAvatar = Chatify::getUserWithGravatar($fetch)->avatar; + $userAvatar = Chatify::getUserWithAvatar($fetch)->avatar; } } @@ -84,10 +84,10 @@ public function idFetchData(Request $request) public function download($fileName) { $path = config('chatify.attachments.folder') . '/' . $fileName; - if (Storage::disk(config('chatify.disk_name'))->exists($path)) { + if (Chatify::storage()->exists($path)) { return response()->json([ 'file_name' => $fileName, - 'download_path' => Storage::disk(config('chatify.disk_name'))->url($path) + 'download_path' => Chatify::storage()->url($path) ], 200); } else { return response()->json([ @@ -127,7 +127,7 @@ public function send(Request $request) $attachment_title = $file->getClientOriginalName(); // upload attachment and store the new name $attachment = Str::uuid() . "." . $file->getClientOriginalExtension(); - $file->storeAs(config('chatify.attachments.folder'), $attachment, config('chatify.disk_name')); + $file->storeAs(config('chatify.attachments.folder'), $attachment, config('chatify.storage_disk_name')); } else { $error->status = 1; $error->message = "File extension not allowed!"; @@ -291,13 +291,13 @@ public function getFavorites(Request $request) */ public function search(Request $request) { - $input = trim(filter_var($request['input'], FILTER_SANITIZE_STRING)); + $input = trim(filter_var($request['input'])); $records = User::where('id','!=',Auth::user()->id) ->where('name', 'LIKE', "%{$input}%") ->paginate($request->per_page ?? $this->perPage); foreach ($records->items() as $index => $record) { - $records[$index] += Chatify::getUserWithGravatar($record); + $records[$index] += Chatify::getUserWithAvatar($record); } return Response::json([ @@ -372,15 +372,15 @@ public function updateSettings(Request $request) if (in_array($file->getClientOriginalExtension(), $allowed_images)) { // delete the older one if (Auth::user()->avatar != config('chatify.user_avatar.default')) { - $path = Storage::disk(config('chatify.disk_name'))->path(config('chatify.user_avatar.folder') . '/' . Auth::user()->avatar); - if (Storage::disk(config('chatify.disk_name'))->exists($path)) { - Storage::disk(config('chatify.disk_name'))->delete($path); + $path = Chatify::getUserAvatarUrl(Auth::user()->avatar); + if (Chatify::storage()->exists($path)) { + Chatify::storage()->delete($path); } } // upload $avatar = Str::uuid() . "." . $file->getClientOriginalExtension(); $update = User::where('id', Auth::user()->id)->update(['avatar' => $avatar]); - $file->storeAs(config('chatify.user_avatar.folder'), $avatar, config('chatify.disk_name')); + $file->storeAs(config('chatify.user_avatar.folder'), $avatar, config('chatify.storage_disk_name')); $success = $update ? 1 : 0; } else { $msg = "File extension not allowed!"; diff --git a/src/Http/Controllers/MessagesController.php b/src/Http/Controllers/MessagesController.php index 96f4000..dc6b64d 100644 --- a/src/Http/Controllers/MessagesController.php +++ b/src/Http/Controllers/MessagesController.php @@ -86,7 +86,7 @@ public function idFetchData(Request $request) if ($request['type'] == 'user') { $fetch = User::where('id', $request['id'])->first(); if($fetch){ - $userAvatar = Chatify::getUserWithGravatar($fetch)->avatar; + $userAvatar = Chatify::getUserWithAvatar($fetch)->avatar; } } @@ -107,8 +107,8 @@ public function idFetchData(Request $request) */ public function download($fileName) { - if (Storage::disk(config('chatify.disk_name'))->exists(config('chatify.attachments.folder') . '/' . $fileName)) { - return Storage::disk(config('chatify.disk_name'))->download(config('chatify.attachments.folder') . '/' . $fileName); + if (Chatify::storage()->exists(config('chatify.attachments.folder') . '/' . $fileName)) { + return Chatify::storage()->download(config('chatify.attachments.folder') . '/' . $fileName); } else { return abort(404, "Sorry, File does not exist in our server or may have been deleted!"); } @@ -145,7 +145,7 @@ public function send(Request $request) $attachment_title = $file->getClientOriginalName(); // upload attachment and store the new name $attachment = Str::uuid() . "." . $file->getClientOriginalExtension(); - $file->storeAs(config('chatify.attachments.folder'), $attachment, config('chatify.disk_name')); + $file->storeAs(config('chatify.attachments.folder'), $attachment, config('chatify.storage_disk_name')); } else { $error->status = 1; $error->message = "File extension not allowed!"; @@ -369,7 +369,7 @@ public function getFavorites(Request $request) public function search(Request $request) { $getRecords = null; - $input = trim(filter_var($request['input'], FILTER_SANITIZE_STRING)); + $input = trim(filter_var($request['input'])); $records = User::where('id','!=',Auth::user()->id) ->where('name', 'LIKE', "%{$input}%") ->paginate($request->per_page ?? $this->perPage); @@ -377,7 +377,7 @@ public function search(Request $request) $getRecords .= view('Chatify::layouts.listItem', [ 'get' => 'search_item', 'type' => 'user', - 'user' => Chatify::getUserWithGravatar($record), + 'user' => Chatify::getUserWithAvatar($record), ])->render(); } if($records->total() < 1){ @@ -406,7 +406,7 @@ public function sharedPhotos(Request $request) for ($i = 0; $i < count($shared); $i++) { $sharedPhotos .= view('Chatify::layouts.listItem', [ 'get' => 'sharedPhoto', - 'image' => Storage::disk(config('chatify.disk_name'))->url(config('chatify.attachments.folder') .'/' . $shared[$i]), + 'image' => Chatify::getAttachmentUrl($shared[$i]), ])->render(); } // send the response @@ -463,7 +463,7 @@ public function updateSettings(Request $request) // If messenger color selected if ($request['messengerColor']) { - $messenger_color = trim(filter_var($request['messengerColor'], FILTER_SANITIZE_STRING)); + $messenger_color = trim(filter_var($request['messengerColor'])); User::where('id', Auth::user()->id) ->update(['messenger_color' => $messenger_color]); } @@ -479,14 +479,14 @@ public function updateSettings(Request $request) // delete the older one if (Auth::user()->avatar != config('chatify.user_avatar.default')) { $avatar = Auth::user()->avatar; - if (Storage::disk(config('chatify.disk_name'))->exists($avatar)) { - Storage::disk(config('chatify.disk_name'))->delete($avatar); + if (Chatify::storage()->exists($avatar)) { + Chatify::storage()->delete($avatar); } } // upload $avatar = Str::uuid() . "." . $file->getClientOriginalExtension(); $update = User::where('id', Auth::user()->id)->update(['avatar' => $avatar]); - $file->storeAs(config('chatify.user_avatar.folder'), $avatar, config('chatify.disk_name')); + $file->storeAs(config('chatify.user_avatar.folder'), $avatar, config('chatify.storage_disk_name')); $success = $update ? 1 : 0; } else { $msg = "File extension not allowed!"; diff --git a/src/assets/css/style.css b/src/assets/css/style.css index 64e3bea..5f9beac 100644 --- a/src/assets/css/style.css +++ b/src/assets/css/style.css @@ -329,6 +329,8 @@ body { padding: 6px 15px; padding-bottom: 5px; max-width: 80%; + width: fit-content; + width: -webkit-fit-content; border-radius: 20px; word-break: break-word; } @@ -751,9 +753,9 @@ div.loadingPlaceholder-date { } .imageModal-content { -webkit-animation-name: zoom; - -webkit-animation-duration: 0.6s; + -webkit-animation-duration: 0.15s; animation-name: zoom; - animation-duration: 0.6s; + animation-duration: 0.15s; } @-webkit-keyframes zoom { @@ -908,64 +910,64 @@ div.loadingPlaceholder-date { } @media (max-width: 576px) { - .user-name { - max-width: 150px; - white-space: nowrap; - overflow: hidden !important; - text-overflow: ellipsis; - } - .chatify-md-block { - display: block; - } + .user-name { + max-width: 150px; + white-space: nowrap; + overflow: hidden !important; + text-overflow: ellipsis; + } + .chatify-md-block { + display: block; + } } .chatify-d-flex { - display: flex !important; + display: flex !important; } .chatify-d-none { - display: none !important; + display: none !important; } .chatify-d-hidden { - visibility: hidden !important; + visibility: hidden !important; } .chatify-justify-content-between { - justify-content: space-between !important; + justify-content: space-between !important; } .chatify-align-items-center { - align-items: center !important; + align-items: center !important; } .chat-message-wrapper { - display: flex; - flex-direction: column; - align-items: end; - unicode-bidi: bidi-override; - direction: ltr; + display: flex; + flex-direction: column; + align-items: end; + unicode-bidi: bidi-override; + direction: ltr; } .pb-3 { - padding-bottom: 0.75rem; /* 12px */ + padding-bottom: 0.75rem; /* 12px */ } .mb-2 { - margin-bottom: 0.5rem; /* 8px */ + margin-bottom: 0.5rem; /* 8px */ } .messenger textarea:focus { - outline: none; - border: none; - box-shadow: none; + outline: none; + border: none; + box-shadow: none; } .chatify-hover-delete-btn { - display: none; - cursor: pointer; - color: #333333; + display: none; + cursor: pointer; + color: #333333; } .message-card:hover .chatify-hover-delete-btn { - display: block; + display: block; } diff --git a/src/assets/js/code.js b/src/assets/js/code.js index 8c20292..0dc9f16 100644 --- a/src/assets/js/code.js +++ b/src/assets/js/code.js @@ -64,14 +64,14 @@ function updateSelectedContact(user_id) { *------------------------------------------------------------- */ // Loading svg -function loadingSVG(w_h = "25px", className = "", style = "") { +function loadingSVG(size = "25px", className = "", style = "") { return ` - + - + @@ -93,17 +93,17 @@ function listItemLoading(items) { template += `
-
- - - - - -
-
-
-
-
+
+ + + + + +
+
+
+
+
`; @@ -118,15 +118,15 @@ function avatarLoading(items) { template += `
-
- - - - -
-
-
-
+
+ + + + +
+
+
+
`; @@ -135,18 +135,18 @@ function avatarLoading(items) { } // While sending a message, show this temporary message card. -function sendigCard(message, id) { - return ( - ` -
-

` + - message + - `

-
-` - ); +function sendTempMessageCard(message, id) { + console.log("message", message); + return ` +
+

+ ${message} + + + +

+
+ `; } // upload image preview card. function attachmentTemplate(fileType, fileName, imgURL = null) { @@ -154,8 +154,8 @@ function attachmentTemplate(fileType, fileName, imgURL = null) { return ( `
- -

` + + +

` + escapeHtml(fileName) + `

@@ -165,11 +165,11 @@ function attachmentTemplate(fileType, fileName, imgURL = null) { return ( `
- -
+
-

` + +

` + escapeHtml(fileName) + `

@@ -252,7 +252,7 @@ let app_modal = function ({ * Slide to bottom on [action] - e.g. [message received, sent, loaded] *------------------------------------------------------------- */ -function scrollBottom(container) { +function scrollToBottom(container) { $(container) .stop() .animate({ @@ -417,10 +417,10 @@ function IDinfo(id, type) { */ function sendMessage() { temporaryMsgId += 1; - let tempID = "temp_" + temporaryMsgId; - let hasFile = $(".upload-attachment").val() ? true : false; - - if ($.trim(messageInput.val()).length > 0 || hasFile) { + let tempID = `temp_${temporaryMsgId}`; + let hasFile = !!$(".upload-attachment").val(); + const inputValue = $.trim(messageInput.val()); + if (inputValue.length > 0 || hasFile) { const formData = new FormData($("#message-form")[0]); formData.append("id", getMessengerId()); formData.append("type", getMessengerType()); @@ -436,21 +436,23 @@ function sendMessage() { beforeSend: () => { // remove message hint $(".messages").find(".message-hint").remove(); - // append message - hasFile - ? messagesContainer - .find(".messages") - .append( - sendigCard( - messageInput.text() + "\n" + loadingSVG("28px"), - tempID - ) + // append a temporary message card + if (hasFile) { + messagesContainer + .find(".messages") + .append( + sendTempMessageCard( + inputValue + "\n" + loadingSVG("28px"), + tempID ) - : messagesContainer - .find(".messages") - .append(sendigCard(messageInput.text(), tempID)); + ); + } else { + messagesContainer + .find(".messages") + .append(sendTempMessageCard(inputValue, tempID)); + } // scroll to bottom - scrollBottom(messagesContainer); + scrollToBottom(messagesContainer); messageInput.css({ height: "42px" }); // form reset and focus $("#message-form").trigger("reset"); @@ -465,17 +467,16 @@ function sendMessage() { } else { // update contact item updateContactItem(getMessengerId()); - messagesContainer.find('.mc-sender[data-id="sending"]').remove(); - // get message before the sending one [temporary] - messagesContainer - .find(".message-card[data-id=" + data.tempID + "]") - .before(data.message); - // delete the temporary one - messagesContainer - .find(".message-card[data-id=" + data.tempID + "]") - .remove(); + // temporary message card + const tempMsgCardElement = messagesContainer.find( + `.message-card[data-id=${data.tempID}]` + ); + // add the message card coming from the server before the temp-card + tempMsgCardElement.before(data.message); + // then, remove the temporary message card + tempMsgCardElement.remove(); // scroll to bottom - scrollBottom(messagesContainer); + scrollToBottom(messagesContainer); // send contact item updates sendContactItemUpdates(true); } @@ -485,7 +486,7 @@ function sendMessage() { errorMessageCard(tempID); // error log console.error( - "Failed sending the message! Please, check your server response" + "Failed sending the message! Please, check your server response." ); }, }); @@ -535,7 +536,7 @@ function fetchMessages(id, type, newFetch = false) { setMessagesLoading(false); if (messagesPage == 1) { messagesElement.html(data.messages); - scrollBottom(messagesContainer); + scrollToBottom(messagesContainer); } else { const lastMsg = messagesElement.find( messagesElement.find(".message-card")[0] @@ -554,7 +555,6 @@ function fetchMessages(id, type, newFetch = false) { if (messenger != 0) { disableOnLoad(false); } - }, error: (error) => { setMessagesLoading(false); @@ -600,7 +600,7 @@ channel.bind("messaging", function (data) { if (data.from_id == getMessengerId() && data.to_id == auth_id) { $(".messages").find(".message-hint").remove(); messagesContainer.find(".messages").append(data.message); - scrollBottom(messagesContainer); + scrollToBottom(messagesContainer); makeSeen(true); // remove unseen counter for the user from the contacts list $(".messenger-list-item[data-contact=" + getMessengerId() + "]") @@ -617,7 +617,7 @@ channel.bind("client-typing", function (data) { : messagesContainer.find(".typing-indicator").hide(); } // scroll to bottom - scrollBottom(messagesContainer); + scrollToBottom(messagesContainer); }); // listen to seen event @@ -644,6 +644,11 @@ channel.bind("client-contactItem", function (data) { } }); +// listen on message delete event +channel.bind("client-messageDelete", function (data) { + $("body").find(`.message-card[data-id=${data.id}]`).remove(); +}); + // ------------------------------------- // presence channel [User Active Status] var activeStatusChannel = pusher.subscribe("presence-activeStatus"); @@ -720,6 +725,17 @@ function sendContactItemUpdates(status) { }); } +/** + *------------------------------------------------------------- + * Trigger message delete + *------------------------------------------------------------- + */ +function sendMessageDeleteEvent(messageId) { + return channel.trigger("client-messageDelete", { + id: messageId, + }); +} + /** *------------------------------------------------------------- * Check internet connection using pusher states @@ -831,6 +847,10 @@ function updateContactItem(user_id) { }, dataType: "JSON", success: (data) => { + const totalContacts = + $(".listOfContacts").find(".messenger-list-item")?.length || 0; + if (totalContacts < 1) + $(".listOfContacts").find(".message-hint").remove(); listItem.remove(); $(".listOfContacts").prepend(data.contactItem); // update data-action required with [responsive design] @@ -1007,7 +1027,54 @@ function deleteConversation(id) { // refresh info IDinfo(id, getMessengerType()); - data.deleted ? "" : console.error("Error occurred!"); + if (!data.deleted) + console.error("Error occurred, messages can not be deleted!"); + + // Hide waiting alert modal + app_modal({ + show: false, + name: "alert", + buttons: true, + body: "", + }); + }, + error: () => { + console.error("Server error, check your response"); + }, + }); +} + +/** + *------------------------------------------------------------- + * Delete Message By ID + *------------------------------------------------------------- + */ +function deleteMessage(id) { + $.ajax({ + url: url + "/deleteMessage", + method: "POST", + data: { _token: access_token, id: id }, + dataType: "JSON", + beforeSend: () => { + // hide delete modal + app_modal({ + show: false, + name: "delete", + }); + // Show waiting alert modal + app_modal({ + show: true, + name: "alert", + buttons: false, + body: loadingSVG("32px", null, "margin:auto"), + }); + }, + success: (data) => { + $(".messages").find(`.message-card[data-id=${id}]`).remove(); + if (!data.deleted) + console.error("Error occurred, message can not be deleted!"); + + sendMessageDeleteEvent(id); // Hide waiting alert modal app_modal({ @@ -1023,6 +1090,11 @@ function deleteConversation(id) { }); } +/** + *------------------------------------------------------------- + * Update Settings + *------------------------------------------------------------- + */ function updateSettings() { const formData = new FormData($("#update-settings")[0]); if (messengerColor) { @@ -1261,26 +1333,18 @@ $(document).ready(function () { function attachmentValidate(file) { const fileElement = $(".upload-attachment"); - const allowedExtensions = [ - "jpg", - "jpeg", - "png", - "gif", - "zip", - "rar", - "txt", - ]; - const sizeLimit = 5000000; // 5 megabyte const { name: fileName, size: fileSize } = file; const fileExtension = fileName.split(".").pop(); - if (!allowedExtensions.includes(fileExtension)) { + if ( + !getAllowedExtensions.includes(fileExtension.toString().toLowerCase()) + ) { alert("file type not allowed"); fileElement.val(""); return false; } // Validate file size. - if (fileSize > sizeLimit) { - alert("Please select file size less than 5 MiB"); + if (fileSize > getMaxUploadSize) { + alert("File is too large!"); return false; } return true; @@ -1350,11 +1414,26 @@ $(document).ready(function () { name: "delete", }); }); - // delete modal [delete button] + // Delete Message Button + $("body").on("click", ".chatify-hover-delete-btn", function () { + app_modal({ + name: "delete", + data: $(this).data("id"), + }); + }); + // Delete modal [on delete button click] $(".app-modal[data-name=delete]") .find(".app-modal-footer .delete") .on("click", function () { - deleteConversation(getMessengerId()); + const id = $("body") + .find(".app-modal[data-name=delete]") + .find(".app-modal-card") + .attr("data-modal"); + if (id == 0) { + deleteConversation(getMessengerId()); + } else { + deleteMessage(id); + } app_modal({ show: false, name: "delete", @@ -1462,56 +1541,4 @@ $(document).ready(function () { actionOnScroll(".messenger-tab.search-tab", function () { messengerSearch($(".messenger-search").val()); }); - - // show and hide message time - $('body').on('click', '.message-card', function () { - $(this).find('sub').slideToggle('300', function() { - $(this).toggleClass('chatify-d-none d-md-flex'); - }); - }) - - $('body').on('click', '.chatify-hover-delete-btn', function () { - deleteMessage($(this).data('id')) - }) - - function deleteMessage(id) { - $.ajax({ - url: url + "/deleteMessage", - method: "POST", - data: { _token: access_token, id: id }, - dataType: "JSON", - beforeSend: () => { - // hide delete modal - app_modal({ - show: false, - name: "delete", - }); - // Show waiting alert modal - app_modal({ - show: true, - name: "alert", - buttons: false, - body: loadingSVG("32px", null, "margin:auto"), - }); - }, - success: (data) => { - console.log($(".messages").find(`[data-message-id='${id}']`)) - $(".messages").find(`[data-message-id='${id}']`).remove() - console.log(data) - data.deleted ? "" : console.error("Error occurred!"); - - // Hide waiting alert modal - app_modal({ - show: false, - name: "alert", - buttons: true, - body: "", - }); - }, - error: () => { - console.error("Server error, check your response"); - }, - }); - } - }); diff --git a/src/config/chatify.php b/src/config/chatify.php index 9bc40a0..b4c77e7 100644 --- a/src/config/chatify.php +++ b/src/config/chatify.php @@ -1,7 +1,6 @@ env('CHATIFY_DISK', 'public'), + 'storage_disk_name' => env('CHATIFY_STORAGE_DISK', 'public'), /* |------------------------------------- @@ -57,6 +57,20 @@ 'default' => 'avatar.png', ], + /* + |------------------------------------- + | Gravatar + | + | imageset property options: + | [ 404 | mp | identicon (default) | monsterid | wavatar ] + |------------------------------------- + */ + 'gravatar' => [ + 'enabled' => false, + 'image_size' => 200, + 'imageset' => 'identicon' + ], + /* |------------------------------------- | Attachments diff --git a/src/views/layouts/favorite.blade.php b/src/views/layouts/favorite.blade.php index cde649a..38b195f 100644 --- a/src/views/layouts/favorite.blade.php +++ b/src/views/layouts/favorite.blade.php @@ -1,6 +1,6 @@
+ style="background-image: url('{{ Chatify::getUserWithAvatar($user)->avatar }}');">

{{ strlen($user->name) > 5 ? substr($user->name,0,6).'..' : $user->name }}

diff --git a/src/views/layouts/footerLinks.blade.php b/src/views/layouts/footerLinks.blade.php index a2e1453..3072d59 100644 --- a/src/views/layouts/footerLinks.blade.php +++ b/src/views/layouts/footerLinks.blade.php @@ -13,5 +13,11 @@ } } }); + + // Bellow are all the methods/variables that using php to assign globally. + const allowedImages = {!! json_encode(config('chatify.attachments.allowed_images')) !!} || []; + const allowedFiles = {!! json_encode(config('chatify.attachments.allowed_files')) !!} || []; + const getAllowedExtensions = [...allowedImages, ...allowedFiles]; + const getMaxUploadSize = {{ Chatify::getMaxUploadSize() }}; diff --git a/src/views/layouts/listItem.blade.php b/src/views/layouts/listItem.blade.php index cc29c28..a84002c 100644 --- a/src/views/layouts/listItem.blade.php +++ b/src/views/layouts/listItem.blade.php @@ -44,11 +44,11 @@ !!} {{-- Last message body --}} @if($lastMessage->attachment == null) - {{ + {!! strlen($lastMessage->body) > 30 ? trim(substr($lastMessage->body, 0, 30)).'..' : $lastMessage->body - }} + !!} @else Attachment @endif diff --git a/src/views/layouts/messageCard.blade.php b/src/views/layouts/messageCard.blade.php index e5bccb2..c08a900 100644 --- a/src/views/layouts/messageCard.blade.php +++ b/src/views/layouts/messageCard.blade.php @@ -6,53 +6,40 @@ {{ $time }} {{-- If attachment is a file --}} @if(@$attachment[2] == 'file') - + {{$attachment[1]}} @endif

-
- {{-- If attachment is an image --}} - @if(@$attachment[2] == 'image') -
-
-
-
+ {{-- If attachment is an image --}} + @if(@$attachment[2] == 'image') +
+ @endif
@endif - @endif @endif {{-- -------------------- Sender card (owner) -------------------- --}} @if($viewType == 'sender') -
-
-
- - @if($message == null && $attachment != null) -

{{ @$attachment[1] }}

- @elseif($message != null) -

{{ nl2br($message) }}

- @endif -
- - {{ $time }} - - {{-- If attachment is a file --}} - @if(@$attachment[2] == 'file') - + @endif diff --git a/src/views/layouts/modals.blade.php b/src/views/layouts/modals.blade.php index 2f51c9b..504aaac 100644 --- a/src/views/layouts/modals.blade.php +++ b/src/views/layouts/modals.blade.php @@ -39,7 +39,7 @@
{{-- Udate profile avatar --}}