From f58a1de6f3614c2615dd1232df352d847f429316 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Jaussoin?= Date: Fri, 21 Jun 2024 22:27:18 +0200 Subject: [PATCH] Improve Link and Image previews using thumbhash in the Chats widget Fix SendTo contact/chatroom Post sharing --- CHANGELOG.md | 2 ++ app/Message.php | 34 +------------------ app/widgets/Chat/chat.js | 2 +- app/widgets/Chats/_chats_item.tpl | 12 ++++++- app/widgets/Chats/chats.css | 7 ++++ app/widgets/Chats/chats.js | 10 ++++++ app/widgets/SendTo/SendTo.php | 13 ++----- app/widgets/SendTo/_sendto_share.tpl | 2 +- app/widgets/SendTo/_sendto_share_contacts.tpl | 2 +- 9 files changed, 37 insertions(+), 47 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4538daa18..96823ae58 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,8 @@ Movim Changelog --------------------------- * Fix #1327 Use string casting for senders attribute * Fix URL handling when path is containing empty values // +* Fix SendTo contact/chatroom Post sharing +* Improve Link and Image previews using thumbhash in the Chats widget v0.25 --------------------------- diff --git a/app/Message.php b/app/Message.php index 2e4a51da2..24ae904a9 100644 --- a/app/Message.php +++ b/app/Message.php @@ -523,39 +523,7 @@ class Message extends Model $this->picture = $messageFile->isPicture; $this->messageFiles->push($messageFile); } - } /*elseif ( - \in_array($stanza->reference->attributes()->type, ['mention', 'data']) - && $stanza->reference->attributes()->uri - ) { - - $uri = parse_url($stanza->reference->attributes()->uri); - - if ($uri['scheme'] === 'xmpp') { - $begin = ''; - - if ($stanza->reference->attributes()->begin && $stanza->reference->attributes()->end) { - $this->html = substr_replace( - $this->body, - $begin, - (int)$stanza->reference->attributes()->begin, - 0 - ); - $this->html = substr_replace( - $this->html, - '', - (int)$stanza->reference->attributes()->end + strlen($begin), - 0 - ); - } else { - $this->html = $begin . $this->body . ''; - } - - $this->file = [ - 'type' => 'xmpp', - 'uri' => (string)$stanza->reference->attributes()->uri, - ]; - } - }*/ + } } if ( diff --git a/app/widgets/Chat/chat.js b/app/widgets/Chat/chat.js index e01f89a4c..815ef2142 100644 --- a/app/widgets/Chat/chat.js +++ b/app/widgets/Chat/chat.js @@ -1338,7 +1338,7 @@ var Chat = { img.setAttribute('onclick', 'Preview_ajaxHttpShow("' + file.preview.url + '", ' + data.mid + ')'); } - if (file.preview.thumbnail_type = 'image/thumbhash' && file.preview.thumbnail_url) { + if (file.preview.thumbnail_type == 'image/thumbhash' && file.preview.thumbnail_url) { try { div.style.background = `center / cover url(${thumbHashToDataURL(MovimUtils.base64ToBinary(file.preview.thumbnail_url))})`; } catch (error) { diff --git a/app/widgets/Chats/_chats_item.tpl b/app/widgets/Chats/_chats_item.tpl index d94e16e51..ec6ab5436 100644 --- a/app/widgets/Chats/_chats_item.tpl +++ b/app/widgets/Chats/_chats_item.tpl @@ -82,7 +82,10 @@ {$c->__('chats.me')}: {/if} {if="$message->file->isPicture"} - image {$c->__('chats.picture')} + {if="$message->file->preview && $message->file->preview['thumbnail_type'] == 'image/thumbhash' && $message->file->preview['thumbnail_url']"} + + {/if} + {$c->__('chats.picture')} {elseif="$message->file->isAudio"} equalizer {$c->__('chats.audio')} {elseif="$message->file->isVideo"} @@ -96,9 +99,16 @@ {if="$message->jidfrom == $message->user_id"} {$c->__('chats.me')}: {/if} + {if="$message->resolvedUrl && $message->resolvedUrl->cache"} + link {$message->resolvedUrl->cache->title} + {if="!empty($message->resolvedUrl->cache->description)"} + | {$message->resolvedUrl->cache->description} + {/if} + {else} {autoescape="off"} {$message->body|stripTags|addEmojis} {/autoescape} + {/if}

{/if} {elseif="$roster && $roster->presence && $roster && $roster->presence->status"} diff --git a/app/widgets/Chats/chats.css b/app/widgets/Chats/chats.css index 6ac463244..7274ec259 100644 --- a/app/widgets/Chats/chats.css +++ b/app/widgets/Chats/chats.css @@ -13,6 +13,13 @@ ul#chats_widget_list li { max-height: 8rem; } +ul#chats_widget_list li img.tinythumb { + object-fit: cover; + width: 1.4rem; + height: 1.4rem; + margin-right: 0.25rem; +} + ul#chats_widget_list li.moving { will-change: transform; transition: transform 0.1s, max-height 0.2s ease-in-out 0.2s; diff --git a/app/widgets/Chats/chats.js b/app/widgets/Chats/chats.js index c9df60e4a..f5746b5ca 100644 --- a/app/widgets/Chats/chats.js +++ b/app/widgets/Chats/chats.js @@ -23,6 +23,16 @@ var Chats = { while(i < items.length) { + if (items[i].querySelector('img.tinythumb')) { + var img = items[i].querySelector('img.tinythumb'); + + try { + img.src = thumbHashToDataURL(MovimUtils.base64ToBinary(img.dataset.thumbhash)); + } catch (error) { + console.log('Cannot handle thumbhash hash'); + } + } + if (items[i].dataset.jid != null) { items[i].onclick = function(e) { Rooms.refresh(); diff --git a/app/widgets/SendTo/SendTo.php b/app/widgets/SendTo/SendTo.php index 380670367..abedf6d90 100644 --- a/app/widgets/SendTo/SendTo.php +++ b/app/widgets/SendTo/SendTo.php @@ -80,14 +80,8 @@ class SendTo extends Base $this->rpc('SendTo.init'); } - public function ajaxSend(string $to, $file, $muc = false, $message = false) + public function ajaxSend(string $to, bool $muc = false, string $message) { - $file->type = 'xmpp/uri'; // Internal placeholder - $file->name = $this->__('sendto.shared_with'); - - $messageFile = new MessageFile; - $messageFile->import($file); - Toast::send($muc ? $this->__('sendto.shared_chatroom') : $this->__('sendto.shared_contact') @@ -97,10 +91,9 @@ class SendTo extends Base $c = new Chat; $c->sendMessage( $to, - !empty($message) ? $message : $this->__('sendto.shared_with'), + $message, $muc, - null, - $messageFile + null ); } diff --git a/app/widgets/SendTo/_sendto_share.tpl b/app/widgets/SendTo/_sendto_share.tpl index 419980ae2..0b49346bd 100644 --- a/app/widgets/SendTo/_sendto_share.tpl +++ b/app/widgets/SendTo/_sendto_share.tpl @@ -25,7 +25,7 @@ - + send diff --git a/app/widgets/SendTo/_sendto_share_contacts.tpl b/app/widgets/SendTo/_sendto_share_contacts.tpl index e0ba96da9..656573164 100644 --- a/app/widgets/SendTo/_sendto_share_contacts.tpl +++ b/app/widgets/SendTo/_sendto_share_contacts.tpl @@ -13,7 +13,7 @@ {/if}"> - + send