From 85ac99d0f4e55bcdb41fbdb9dba3cf9ab5acf3e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Jaussoin?= Date: Mon, 8 Apr 2019 23:48:25 +0200 Subject: [PATCH] Use the MUC resource to check if the user is allowed to react or not Decorate the reactions buttons if already reacted (only based on full jid yet) --- app/widgets/Chat/Chat.php | 46 ++++++++++++++++++---------- app/widgets/Chat/_chat_reactions.tpl | 1 + app/widgets/Chat/chat.css | 5 +++ 3 files changed, 36 insertions(+), 16 deletions(-) diff --git a/app/widgets/Chat/Chat.php b/app/widgets/Chat/Chat.php index db0879b8b..b0402d610 100644 --- a/app/widgets/Chat/Chat.php +++ b/app/widgets/Chat/Chat.php @@ -439,20 +439,33 @@ class Chat extends \Movim\Widget\Base ->where('mid', $mid) ->first(); - if ($message - && $message->reactions() - ->where('emoji', $emoji) - ->where('jidfrom', ($message->type == 'groupchat') - ? $this->user->session->username - : $this->user->id) - ->count() == 0) { - $this->ajaxHttpSendMessage( - $message->jidfrom != $message->user_id - ? $message->jidfrom - : $message->jidto, - $emoji, $message->type == 'groupchat', - false, false, false, $message->replaceid - ); + if ($message) { + // Try to load the MUC presence and resolve the resource + $mucPresence = null; + if ($message->type == 'groupchat') { + $mucPresence = $this->user->session->presences() + ->where('jid', $message->jidfrom) + ->where('mucjid', $this->user->id) + ->where('muc', true) + ->first(); + + if (!$mucPresence) return; + } + + if ($message->reactions() + ->where('emoji', $emoji) + ->where('jidfrom', ($message->type == 'groupchat') + ? $mucPresence->resource + : $this->user->id) + ->count() == 0) { + $this->ajaxHttpSendMessage( + $message->jidfrom != $message->user_id + ? $message->jidfrom + : $message->jidto, + $emoji, $message->type == 'groupchat', + false, false, false, $message->replaceid + ); + } } } @@ -855,8 +868,9 @@ class Chat extends \Movim\Widget\Base $view->assign('message', $message); $start = Message::where( - ['type' =>'jingle_start', - 'thread'=> $message->thread + [ + 'type' =>'jingle_start', + 'thread'=> $message->thread ] )->first(); diff --git a/app/widgets/Chat/_chat_reactions.tpl b/app/widgets/Chat/_chat_reactions.tpl index 745bbc0c2..855c789ac 100644 --- a/app/widgets/Chat/_chat_reactions.tpl +++ b/app/widgets/Chat/_chat_reactions.tpl @@ -1,5 +1,6 @@ {loop="$reactions"}
  • {autoescape="off"} {$key|addEmojis:true} diff --git a/app/widgets/Chat/chat.css b/app/widgets/Chat/chat.css index ec352b46e..6fdcd5a69 100644 --- a/app/widgets/Chat/chat.css +++ b/app/widgets/Chat/chat.css @@ -286,6 +286,11 @@ table.emojis td:hover { background-color: rgba(var(--movim-font), 0.2); } +#chat_widget .bubble ul.reactions li.reacted { + border: 1px solid rgba(var(--movim-font), 0.3); + box-sizing: border-box; +} + #chat_widget .bubble ul.reactions li img { width: 2.25rem; height: 3rem;