Browse Source

Merge pull request #1259 from movim/feature/mam-get-muc

Implement MAM history retrieval for MUCs and contacts
pull/1265/head
Jaussoin Timothée 2 years ago
committed by GitHub
parent
commit
0b264d795f
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      CHANGELOG.md
  2. 56
      app/widgets/Chat/Chat.php
  3. 158
      app/widgets/Chat/chat.css
  4. 29
      app/widgets/Chat/chat.js
  5. 2
      app/widgets/Chat/locales.ini
  6. 6
      app/widgets/Chats/Chats.php
  7. 3
      app/widgets/Presence/Presence.php
  8. 8
      app/widgets/Rooms/Rooms.php
  9. 29
      app/widgets/RoomsUtils/RoomsUtils.php
  10. 17
      src/Moxl/Xec/Action/MAM/Get.php
  11. 38
      src/Moxl/Xec/Payload/MAMResult.php

1
CHANGELOG.md

@ -16,6 +16,7 @@ v0.22.6 (trunk)
* Drop the Caps widget, replaced by the DOAP system by the XSF
* Upgrade the icon pack from MaterialIcons to MaterialSymbols
* Add support of online/offline browser events to quick disconnect/reconnect on network change
* Implement MAM history retrieval for MUCs and contacts
v0.22.5
---------------------------

56
app/widgets/Chat/Chat.php

@ -48,9 +48,7 @@ class Chat extends \Movim\Widget\Base
$this->registerEvent('moderated', 'onRetracted');
$this->registerEvent('receiptack', 'onMessageReceipt');
$this->registerEvent('displayed', 'onMessage', 'chat');
$this->registerEvent('mam_get_handle', 'onMAMRetrieved');
$this->registerEvent('mam_get_handle_muc', 'onMAMMucRetrieved', 'chat');
$this->registerEvent('mam_get_handle_contact', 'onMAMContactRetrieved', 'chat');
$this->registerEvent('mam_get_handle', 'onMAMRetrieved', 'chat');
$this->registerEvent('chatstate', 'onChatState', 'chat');
//$this->registerEvent('subject', 'onConferenceSubject', 'chat'); Spam the UI during authentication
$this->registerEvent('muc_setsubject_handle', 'onConferenceSubject', 'chat');
@ -266,19 +264,15 @@ class Chat extends \Movim\Widget\Base
$this->ajaxGetRoom($packet->content->jidfrom, false, true);
}
public function onMAMRetrieved()
public function onMAMRetrieved($packet)
{
Toast::send($this->__('chat.mam_retrieval'));
}
$counter = $packet->content;
public function onMAMMucRetrieved($packet)
{
$this->ajaxGetRoom($packet->content, true, true);
}
$this->rpc('MovimUtils.removeClass', '#chat_widget .contained', 'loading');
public function onMAMContactRetrieved($packet)
{
$this->ajaxGet($packet->content, true);
if ($counter > 0) {
$this->rpc('Chat.getHistory', false);
}
}
public function onMucConnected($packet)
@ -333,6 +327,7 @@ class Chat extends \Movim\Widget\Base
$date = $view->draw('_chat_date');
$separator = $view->draw('_chat_separator');
$this->rpc('Chat.resetCurrentDateTime');
$this->rpc('Chat.setGeneralElements', $date, $separator);
$this->rpc(
'Chat.setConfig',
@ -395,6 +390,7 @@ class Chat extends \Movim\Widget\Base
}
$this->rpc('Chat.setObservers');
$this->rpc('Chat.resetCurrentDateTime');
$this->prepareMessages($jid);
$this->rpc('Notif.current', 'chat|' . $jid);
$this->rpc('Chat.scrollToSeparator');
@ -445,6 +441,7 @@ class Chat extends \Movim\Widget\Base
}
$this->rpc('Chat.setObservers');
$this->rpc('Chat.resetCurrentDateTime'); // TODO, not call there all the time ?!
$this->prepareMessages($room, true);
$this->rpc('Notif.current', 'chat|' . $room);
$this->rpc('Chat.scrollToSeparator');
@ -902,14 +899,17 @@ class Chat extends \Movim\Widget\Base
* @param string jid
* @param string time
*/
public function ajaxGetHistory($jid, $date, $muc = false, $prepend = true)
public function ajaxGetHistory(string $jid, ?string $date = null, bool $muc = false, bool $prepend = true, bool $tryMam = true)
{
if (!validateJid($jid) || !isset($date)) {
if (!validateJid($jid)) {
return;
}
$messages = \App\Message::jid($jid)
->where('published', $prepend ? '<' : '>', date(MOVIM_SQL_DATE, strtotime($date)));
$messages = \App\Message::jid($jid);
if ($date !== null) {
$messages = $messages->where('published', $prepend ? '<' : '>', date(MOVIM_SQL_DATE, strtotime($date)));
}
$messages = $muc
? $messages->whereIn('type', $this->_messageTypesMuc)->whereNull('subject')
@ -921,9 +921,7 @@ class Chat extends \Movim\Widget\Base
->get();
if ($messages->count() > 0) {
if ($prepend) {
Toast::send($this->__('message.history', $messages->count()));
} else {
if (!$prepend) {
$messages = $messages->reverse();
}
@ -934,6 +932,17 @@ class Chat extends \Movim\Widget\Base
$this->rpc('Chat.appendMessagesWrapper', $this->_wrapper, $prepend);
$this->_wrapper = [];
}
// Not enough messages from the DB, lets try to get more from MAM
if ($tryMam && ($messages->count() == 0 || $messages->count() < $this->_pagination)) {
$this->rpc('MovimUtils.addClass', '#chat_widget .contained', 'loading');
if ($muc) {
$this->rpc('RoomsUtils_ajaxGetMAMHistory', $jid);
} else {
$this->rpc('Chats_ajaxGetMAMHistory', $jid);
}
}
}
/**
@ -1134,14 +1143,10 @@ class Chat extends \Movim\Widget\Base
$this->rpc('Chat.appendMessagesWrapper', $this->_wrapper, false);
}
if ($messages->count() == 0 && !$muc) {
//$chats = new Chats;
//$chats->ajaxGetHistory($jid);
}
if ($event) {
$this->event($muc ? 'chat_open_room' : 'chat_open', $jid);
}
$this->event('chat_counter', $this->user->unreads());
if ($unreadsCount > 0) {
@ -1263,7 +1268,6 @@ class Chat extends \Movim\Widget\Base
if ($message->file['type'] != 'xmpp') {
$message->body = '';
}
}
if (

158
app/widgets/Chat/chat.css

@ -13,29 +13,63 @@ main:not(.enabled) #chat_widget {
width: 100%;
}
#chat_widget > div:not(#chat_explore),
#chat_widget > header {
#chat_widget>div:not(#chat_explore),
#chat_widget>header {
max-width: 100%;
width: 100%;
}
#chat_widget > header {
#chat_widget>header {
box-shadow: var(--elevation-1);
z-index: 1;
}
#chat_widget p.compose:not(.first):not(:empty),
#chat_widget p.compose:not(.first):empty + p {
#chat_widget p.compose:not(.first):empty+p {
animation: fadein 0.3s;
}
#chat_widget p.compose:not(:empty) + p {
#chat_widget p.compose:not(:empty)+p {
display: none;
}
#chat_widget .contained {
overflow-y: scroll;
overflow-x: hidden;
height: 100%;
position: relative;
}
#chat_widget .contained:before {
position: absolute;
display: block;
background-color: rgb(var(--movim-main));
width: 100%;
height: 0.25rem;
content: '';
top: 0;
left: 0;
transform-origin: 0% 50%;
opacity: 0;
}
#chat_widget .contained.loading:before {
animation: loadingBar 3s infinite linear;
opacity: 1;
}
@keyframes loadingBar {
0% {
transform: translateX(0) scaleX(0);
}
33% {
transform: translateX(0) scaleX(0.33);
}
100% {
transform: translateX(100%) scaleX(0.33);
}
}
#chat_widget .contained section {
@ -55,14 +89,14 @@ main:not(.enabled) #chat_widget {
pointer-events: none;
}
#chat_widget span.control.enabled + ul.list.actions {
#chat_widget span.control.enabled+ul.list.actions {
opacity: 1;
z-index: 2;
transform: translateY(0) scaleY(1);
pointer-events: initial;
}
#chat_widget ul.list.actions > li > div > p {
#chat_widget ul.list.actions>li>div>p {
border-radius: 0.65rem;
line-height: 4rem;
padding: 0 1.25rem;
@ -70,14 +104,14 @@ main:not(.enabled) #chat_widget {
float: right;
}
#chat_widget ul.list.actions > li > span.control,
#chat_widget ul.list.actions > li > div > p {
#chat_widget ul.list.actions>li>span.control,
#chat_widget ul.list.actions>li>div>p {
transition: box-shadow 0.3s ease, background 0.3s ease;
box-shadow: var(--elevation-1);
}
#chat_widget ul.list.actions > li > span.control:hover,
#chat_widget ul.list.actions > li > div > p:hover {
#chat_widget ul.list.actions>li>span.control:hover,
#chat_widget ul.list.actions>li>div>p:hover {
box-shadow: var(--elevation-2);
background-color: rgba(var(--movim-element-action), 0.1);
}
@ -112,7 +146,7 @@ main:not(.enabled) #chat_widget {
max-width: 100%;
}
#chat_widget .chat_box form > div {
#chat_widget .chat_box form>div {
min-height: 0;
top: -2rem;
}
@ -127,13 +161,13 @@ main:not(.enabled) #chat_widget {
width: calc(100% - 1.5rem);
}
#chat_widget .chat_box form textarea ~ span.encrypted,
#chat_widget .chat_box form textarea ~ span.encrypted_disabled,
#chat_widget .chat_box form textarea ~ span.encrypted_loading {
#chat_widget .chat_box form textarea~span.encrypted,
#chat_widget .chat_box form textarea~span.encrypted_disabled,
#chat_widget .chat_box form textarea~span.encrypted_loading {
display: none;
}
#chat_widget .chat_box form textarea ~ span.encrypted_loading {
#chat_widget .chat_box form textarea~span.encrypted_loading {
opacity: 0.5;
}
@ -143,9 +177,9 @@ main:not(.enabled) #chat_widget {
width: calc(100% - 5.5rem);
}
#chat_widget .chat_box form textarea[data-encryptedstate="yes"] ~ span.control.icon.encrypted,
#chat_widget .chat_box form textarea[data-encryptedstate="disabled"] ~ span.control.icon.encrypted_disabled,
#chat_widget .chat_box form textarea[data-encryptedstate="build"] ~ span.control.icon.encrypted_loading {
#chat_widget .chat_box form textarea[data-encryptedstate="yes"]~span.control.icon.encrypted,
#chat_widget .chat_box form textarea[data-encryptedstate="disabled"]~span.control.icon.encrypted_disabled,
#chat_widget .chat_box form textarea[data-encryptedstate="build"]~span.control.icon.encrypted_loading {
display: inline-block;
font-size: 2.75rem;
position: absolute;
@ -190,7 +224,7 @@ main:not(.enabled) #chat_widget {
}
#chat_widget .chat_box.finished:after {
transition: width 1s cubic-bezier(.68,0,0,1), opacity 1s ease-in-out;
transition: width 1s cubic-bezier(.68, 0, 0, 1), opacity 1s ease-in-out;
width: 100%;
opacity: 0;
}
@ -200,19 +234,19 @@ main:not(.enabled) #chat_widget {
pointer-events: none;
}
#chat_widget .chat_box > ul.list > li:not(:empty) {
#chat_widget .chat_box>ul.list>li:not(:empty) {
min-height: 0;
padding: 0.5rem;
}
#chat_widget .chat_box > ul.list > li form {
#chat_widget .chat_box>ul.list>li form {
position: relative;
margin: 0 0.5rem;
padding: 0;
padding-right: 0.5rem;
}
#chat_widget .chat_box > ul.list > li form:before {
#chat_widget .chat_box>ul.list>li form:before {
content: "";
display: block;
width: 100%;
@ -224,23 +258,23 @@ main:not(.enabled) #chat_widget {
border-radius: 1rem;
}
#chat_widget .chat_box > ul.list > li > .control {
#chat_widget .chat_box>ul.list>li>.control {
transition: transform 0.2s;
}
#chat_widget .chat_box > ul.list > li > .control.attach.enabled {
#chat_widget .chat_box>ul.list>li>.control.attach.enabled {
transform: rotate(45deg);
font-variation-settings: 'FILL' 1;
}
#chat_widget .chat_box.compose > ul.list > li > ul.list.actions,
#chat_widget .chat_box:not(.compose) > ul.list > li > .control.attach ~ .control.send:not(.emojis),
#chat_widget .chat_box.compose > ul.list > li > .control.attach ~ .control:not(.send):not(.emojis),
#chat_widget .chat_box.compose > ul.list > li > .control:not(.send):not(.emojis) {
#chat_widget .chat_box.compose>ul.list>li>ul.list.actions,
#chat_widget .chat_box:not(.compose)>ul.list>li>.control.attach~.control.send:not(.emojis),
#chat_widget .chat_box.compose>ul.list>li>.control.attach~.control:not(.send):not(.emojis),
#chat_widget .chat_box.compose>ul.list>li>.control:not(.send):not(.emojis) {
display: none;
}
#chat_widget section > ul.list > li.oppose {
#chat_widget section>ul.list>li.oppose {
flex-direction: row-reverse;
}
@ -250,7 +284,7 @@ main:not(.enabled) #chat_widget {
width: 100%;
}
#chat_widget section > ul.list > li.oppose > span.primary {
#chat_widget section>ul.list>li.oppose>span.primary {
display: none;
}
}
@ -294,7 +328,7 @@ main:not(.enabled) #chat_widget {
padding-left: 2rem;
}
#chat_widget div:not(.chat_box):not(#chat_explore) ul.conversation > li > span.icon {
#chat_widget div:not(.chat_box):not(#chat_explore) ul.conversation>li>span.icon {
align-self: flex-start;
margin: 0;
}
@ -335,26 +369,26 @@ main:not(.enabled) #chat_widget {
cursor: pointer;
}
#chat_widget .contained ul li.sequel > span.icon,
#chat_widget .contained ul li.sequel>span.icon,
#chat_widget .contained ul li.sequel .bubble::before,
#chat_widget .contained ul li.oppose + li.oppose > span.icon,
#chat_widget .contained ul li.oppose + li.oppose .bubble::before,
#chat_widget .contained:not(.muc) ul li:not(.oppose):not(.separator):not(.date) + li:not(.oppose) > span.icon,
#chat_widget .contained:not(.muc) ul li:not(.oppose):not(.separator):not(.date) + li:not(.oppose) .bubble::before {
#chat_widget .contained ul li.oppose+li.oppose>span.icon,
#chat_widget .contained ul li.oppose+li.oppose .bubble::before,
#chat_widget .contained:not(.muc) ul li:not(.oppose):not(.separator):not(.date)+li:not(.oppose)>span.icon,
#chat_widget .contained:not(.muc) ul li:not(.oppose):not(.separator):not(.date)+li:not(.oppose) .bubble::before {
opacity: 0;
pointer-events: none;
}
#chat_widget .contained section > ul > li {
#chat_widget .contained section>ul>li {
animation: fadein 0.2s;
padding: 0 1rem;
}
#chat_widget ul ~ .placeholder {
#chat_widget ul~.placeholder {
display: none;
}
#chat_widget ul:empty ~ .placeholder.show {
#chat_widget ul:empty~.placeholder.show {
display: block;
animation: fadein 1s;
}
@ -371,38 +405,38 @@ main:not(.enabled) #chat_widget {
padding-top: 2rem;
}
#emojisearchbar ~ .emojis {
#emojisearchbar~.emojis {
padding: 0 1rem;
display: grid;
grid-template-columns: repeat(6, 1fr);
}
#emojisearchbar ~ .emojis.results,
#emojisearchbar ~ .emojis:last-child {
#emojisearchbar~.emojis.results,
#emojisearchbar~.emojis:last-child {
margin-bottom: 1rem;
}
#emojisearchbar ~ .emojis img {
#emojisearchbar~.emojis img {
text-align: center;
padding: 1rem 1.5rem;
font-size: 0;
position: relative;
}
#emojisearchbar ~ .emojis.main {
#emojisearchbar~.emojis.main {
border-bottom: 1px solid rgba(var(--movim-font), 0.12);
padding-bottom: 0.5rem;
margin-bottom: 0.5rem;
}
#emojisearchbar ~ .emojis.results:empty,
#emojisearchbar ~ .emojis.results:not(:empty) ~ .emojis {
#emojisearchbar~.emojis.results:empty,
#emojisearchbar~.emojis.results:not(:empty)~.emojis {
display: none;
}
#chat_widget textarea#chat_textarea ~ span.control:hover,
#chat_widget textarea#chat_textarea~span.control:hover,
#chat_widget .primary_action:hover,
#emojisearchbar ~ .emojis img:hover {
#emojisearchbar~.emojis img:hover {
cursor: pointer;
background-color: rgba(var(--movim-font), 0.05);
border-radius: 0.5rem;
@ -424,7 +458,7 @@ main:not(.enabled) #chat_widget {
margin: 0.25rem 0;
}
#chat_widget .bubble div + div div.parent {
#chat_widget .bubble div+div div.parent {
margin-top: 1rem;
}
@ -517,12 +551,12 @@ li div.bubble.file:not(.audio):after {
padding: 0;
}
#chat_widget .bubble > div {
#chat_widget .bubble>div {
padding-right: 7rem;
margin-right: -7rem;
}
#chat_widget .bubble:not(.file) > div:last-child {
#chat_widget .bubble:not(.file)>div:last-child {
padding-right: 12rem;
}
@ -533,7 +567,8 @@ li div.bubble.file:not(.audio):after {
}
@media screen and (min-width: 1025px) {
#chat_widget li .bubble div:hover ul.reactions:empty ~ span.reaction,
#chat_widget li .bubble div:hover ul.reactions:empty~span.reaction,
#chat_widget li .bubble div:not(.encrypted):hover span.reply {
display: inline-flex;
position: absolute;
@ -541,16 +576,16 @@ li div.bubble.file:not(.audio):after {
transform: translate(-0.5rem, -0.5rem);
}
#chat_widget li .bubble.file div:hover ul.reactions:empty ~ span.reaction,
#chat_widget li .bubble.file div:hover ul.reactions:empty~span.reaction,
#chat_widget li .bubble.file div:not(.encrypted):hover span.reply {
transform: translate(-0.5rem, -5.5rem);
}
#chat_widget li .bubble div:hover ul.reactions:not(:empty) ~ span.reply {
#chat_widget li .bubble div:hover ul.reactions:not(:empty)~span.reply {
margin-top: -3rem;
}
#chat_widget li .bubble div:hover ul.reactions:empty ~ span.reaction ~ span.reply {
#chat_widget li .bubble div:hover ul.reactions:empty~span.reaction~span.reply {
left: calc(100% + 3.5rem);
}
}
@ -579,7 +614,7 @@ li .bubble.file div.file {
margin-bottom: 3rem;
}
li:not(.oppose) .bubble.file span.resource + div.file {
li:not(.oppose) .bubble.file span.resource+div.file {
margin-top: 1rem;
}
@ -722,7 +757,7 @@ li .bubble.file div.file a span.size:before {
display: inline-block;
}
#chat_widget .bubble span.resource + ul.card.list li {
#chat_widget .bubble span.resource+ul.card.list li {
margin-top: 0.5rem;
}
@ -738,13 +773,13 @@ li .bubble.file div.file a span.size:before {
float: right;
}
#chat_widget li.oppose .bubble ul.card.list + * {
#chat_widget li.oppose .bubble ul.card.list+* {
clear: both;
display: block;
text-align: right;
}
#chat_widget li .bubble ul.card.list + p {
#chat_widget li .bubble ul.card.list+p {
margin-right: 4.5rem;
margin-bottom: 0.25rem;
}
@ -776,6 +811,7 @@ li .bubble.file div.file a span.size:before {
/* Parent scroll */
@keyframes backgroundblink {
0%,
50%,
100% {
@ -790,4 +826,4 @@ li .bubble.file div.file a span.size:before {
#chat_widget .bubble.scroll_blink {
animation: backgroundblink 1s;
}
}

29
app/widgets/Chat/chat.js

@ -135,6 +135,18 @@ var Chat = {
Chat_ajaxGetRoom(jid);
},
getHistory: function(tryMam) {
var textarea = Chat.getTextarea();
if (textarea) {
Chat_ajaxGetHistory(
textarea.dataset.jid,
Chat.currentDateTime,
Boolean(textarea.dataset.muc),
true,
tryMam);
}
},
sendMessage: function () {
var textarea = Chat.getTextarea();
var text = textarea.value;
@ -580,11 +592,12 @@ var Chat = {
Chat.delivery_error = delivery_error;
Chat.action_impossible_encrypted_error = action_impossible_encrypted_error;
},
resetCurrentDateTime: function() {
Chat.currentDateTime = null;
},
setGeneralElements(date, separator) {
var div = document.createElement('div');
Chat.currentDateTime = null;
div.innerHTML = date;
Chat.date = div.firstChild.cloneNode(true);
div.innerHTML = separator;
@ -593,8 +606,6 @@ var Chat = {
setSpecificElements: function (left, right) {
var div = document.createElement('div');
Chat.currentDateTime = null;
div.innerHTML = left;
Chat.left = div.firstChild.cloneNode(true);
div.innerHTML = right;
@ -606,12 +617,8 @@ var Chat = {
discussion.onscroll = function () {
if (this.scrollTop < 1
&& discussion.querySelectorAll('li div.bubble p').length >= Chat.pagination && Chat.currentDateTime) {
Chat_ajaxGetHistory(
Chat.getTextarea().dataset.jid,
Chat.currentDateTime,
Chat.getTextarea().dataset.muc,
true);
&& Chat.currentDateTime) {
Chat.getHistory(true);
}
Chat.setScroll();
@ -881,7 +888,7 @@ var Chat = {
}
for (speakertime in page[date]) {
if (!Chat.currentDateTime) {
if (Chat.currentDateTime == null) {
Chat.currentDateTime = page[date][speakertime].published;
}

2
app/widgets/Chat/locales.ini

@ -11,7 +11,6 @@ composing = Composing…
invitation = Invitation
paused = Paused…
gone = Contact gone
history = %s messages retrieved
edit_help = ↑ to edit your previous message
emoji_help = :shortcut: to insert an emoji
visitor_help = You are not allowed to send messages in this conference
@ -43,7 +42,6 @@ muc_owner = %s is now owner
muc_outcast = %s is now banned
muc_member = %s is now member
publish_error = An error occurred when sending the message
mam_retrieval = Synchronizing the history, please wait…
clear_history = Clear the history
clear_history_text = "You are going to delete %s messages, are you sure?"
action_impossible_encrypted = Action impossible in encrypted chats

6
app/widgets/Chats/Chats.php

@ -115,9 +115,9 @@ class Chats extends Base
}
/**
* @brief Get history
* @brief Get MAM history
*/
public function ajaxGetHistory(?string $jid = null)
public function ajaxGetMAMHistory(?string $jid = null)
{
$g = new \Moxl\Xec\Action\MAM\Get;
@ -177,7 +177,7 @@ class Chats extends Base
$chats[$jid] = 1;
if ($history) {
$this->ajaxGetHistory($jid);
$this->ajaxGetMAMHistory($jid);
}
\App\Cache::c('chats', $chats);

3
app/widgets/Presence/Presence.php

@ -65,8 +65,7 @@ class Presence extends Base
$blocked->request();
// We refresh the messages
$c = new Chats;
$c->ajaxGetHistory();
(new Chats)->ajaxGetMAMHistory();
$this->ajaxServerCapsGet();
$this->ajaxBookmarksGet();
$this->ajaxPubsubSubscriptionsGet();

8
app/widgets/Rooms/Rooms.php

@ -97,7 +97,7 @@ class Rooms extends Base
->where('bookmarkversion', (int)$packet->content)
->get() as $room) {
if ($room->autojoin && !$room->connected) {
$this->ajaxJoin($room->conference, $room->nick, true);
$this->ajaxJoin($room->conference, $room->nick);
}
}
@ -191,7 +191,7 @@ class Rooms extends Base
/**
* @brief Join a chatroom
*/
public function ajaxJoin($room, $nickname = false, $noNotify = false)
public function ajaxJoin($room, $nickname = false)
{
if (!validateRoom($room)) {
return;
@ -229,10 +229,6 @@ class Rooms extends Base
$m->setTo($room)
->request();
if ($noNotify) {
$p->noNotify();
}
$p->setNickname($nickname);
$p->request();
}

29
app/widgets/RoomsUtils/RoomsUtils.php

@ -26,6 +26,8 @@ use Moxl\Xec\Action\Muc\ChangeAffiliation;
use Moxl\Xec\Action\Presence\Muc;
use Moxl\Xec\Action\Presence\Unavailable;
use Illuminate\Database\Capsule\Manager as DB;
include_once WIDGETS_PATH . 'Chat/Chat.php';
class RoomsUtils extends Base
@ -836,6 +838,33 @@ class RoomsUtils extends Base
->request();
}
/**
* @brief Get MAM history
*/
public function ajaxGetMAMHistory(string $jid)
{
$g = new \Moxl\Xec\Action\MAM\Get;
$message = \App\User::me()->messages()
->where('jidfrom', $jid)
->whereNull('subject');
$message = (DB::getDriverName() == 'pgsql')
? $message->orderByRaw('published asc nulls last')
: $message->orderBy('published', 'asc');
$message = $message->first();
$g->setTo($jid);
if ($message && $message->published) {
$g->setEnd(strtotime($message->published));
}
$g->setLimit(150);
$g->setBefore('');
$g->request();
}
public function onDiscoGateway($packet)
{
$view = $this->tpl();

17
src/Moxl/Xec/Action/MAM/Get.php

@ -25,7 +25,7 @@ class Get extends Action
// Generating the queryid key.
$this->_queryid = \generateKey(12);
$session->set('mamid' . $this->_queryid, true);
$session->set('mamid' . $this->_queryid, 0);
$this->store();
MAM::get(
@ -43,21 +43,14 @@ class Get extends Action
public function handle(?\SimpleXMLElement $stanza = null, ?\SimpleXMLElement $parent = null)
{
$session = Session::start();
$session->delete('mamid' . $this->_queryid);
//MessageBuffer::getInstance()->save();
if ($this->_to) {
$this->method('handle_muc');
$this->pack($this->_to);
}
$session = Session::start();
if ($this->_jid) {
$this->method('handle_contact');
$this->pack($this->_jid);
}
$messagesCounter = $session->get('mamid' . $this->_queryid);
$this->pack($messagesCounter);
$session->delete('mamid' . $this->_queryid);
$this->deliver();
if (

38
src/Moxl/Xec/Payload/MAMResult.php

@ -12,13 +12,21 @@ class MAMResult extends Payload
$to = baseJid((string)$parent->attributes()->to);
$session = Session::start();
if ($stanza->forwarded->delay
&& isset($stanza->attributes()->queryid)
&& $session->get('mamid'.(string)$stanza->attributes()->queryid) == true) {
if ($stanza->forwarded->message->{'apply-to'}
&& $stanza->forwarded->message->{'apply-to'}->attributes()->xmlns == 'urn:xmpp:fasten:0'
&& $stanza->forwarded->message->{'apply-to'}->moderated
&& $stanza->forwarded->message->{'apply-to'}->moderated->attributes()->xmlns == 'urn:xmpp:message-moderate:0') {
$messagesCounter = $session->get('mamid' . (string)$stanza->attributes()->queryid);
if (
$stanza->forwarded->delay
&& isset($stanza->attributes()->queryid)
&& $messagesCounter >= 0
) {
$session->set('mamid' . (string)$stanza->attributes()->queryid, $messagesCounter + 1);
if (
$stanza->forwarded->message->{'apply-to'}
&& $stanza->forwarded->message->{'apply-to'}->attributes()->xmlns == 'urn:xmpp:fasten:0'
&& $stanza->forwarded->message->{'apply-to'}->moderated
&& $stanza->forwarded->message->{'apply-to'}->moderated->attributes()->xmlns == 'urn:xmpp:message-moderate:0'
) {
(new Moderated)->handle($stanza->forwarded->message->{'apply-to'}->moderated, $stanza->forwarded->message);
return;
}
@ -39,20 +47,22 @@ class MAMResult extends Payload
$message->jidto = $to;
}
if (!$message->encrypted
&& $message->valid()
&& (!$message->isEmpty() || $message->isSubject())) {
if (
!$message->encrypted
&& $message->valid()
&& (!$message->isEmpty() || $message->isSubject())
) {
// Set the "old" message as seen
if (\Carbon\Carbon::createFromFormat('Y-m-d H:i:s', $message->published)->addWeek()->isBefore(\Carbon\Carbon::now())) {
$message->seen = true;
}
//MessageBuffer::getInstance()->append($message, function() use ($message) {
$message->save();
$message->clearUnreads();
$message->save();
$message->clearUnreads();
$this->pack($message);
$this->deliver();
$this->pack($message);
$this->deliver();
//});
}
}

Loading…
Cancel
Save