Skip to content

Commit

Permalink
v1.4.0 updates, fixes, and improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
munafio committed May 4, 2022
1 parent 6962187 commit d49fcc3
Show file tree
Hide file tree
Showing 12 changed files with 334 additions and 245 deletions.
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)

Expand Down
62 changes: 49 additions & 13 deletions src/ChatifyMessenger.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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
Expand All @@ -336,7 +341,7 @@ public function deleteConversation($user_id)
}

/**
* Delete message
* Delete message by ID
*
* @param int $id
* @return boolean
Expand All @@ -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
Expand All @@ -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);
}
}
20 changes: 10 additions & 10 deletions src/Http/Controllers/Api/MessagesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand All @@ -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([
Expand Down Expand Up @@ -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!";
Expand Down Expand Up @@ -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([
Expand Down Expand Up @@ -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!";
Expand Down
22 changes: 11 additions & 11 deletions src/Http/Controllers/MessagesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand All @@ -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!");
}
Expand Down Expand Up @@ -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!";
Expand Down Expand Up @@ -369,15 +369,15 @@ 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);
foreach ($records->items() as $record) {
$getRecords .= view('Chatify::layouts.listItem', [
'get' => 'search_item',
'type' => 'user',
'user' => Chatify::getUserWithGravatar($record),
'user' => Chatify::getUserWithAvatar($record),
])->render();
}
if($records->total() < 1){
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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]);
}
Expand All @@ -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!";
Expand Down
62 changes: 32 additions & 30 deletions src/assets/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
}
Loading

0 comments on commit d49fcc3

Please sign in to comment.