Browse Source

Fix #1080 ensure that characters are counted in their non-html escaped form

Use origin-id as message id for chat messages if present
pull/1082/head
Timothée Jaussoin 3 years ago
parent
commit
02f85ac2c3
  1. 11
      app/Message.php
  2. 6
      app/widgets/Chat/Chat.php

11
app/Message.php

@ -204,12 +204,15 @@ class Message extends Model
}
// stanza-id
if ($stanza->{'stanza-id'} && $stanza->{'stanza-id'}->attributes()->id
if ($this->type == 'groupchat' && $stanza->{'stanza-id'} && $stanza->{'stanza-id'}->attributes()->id
&& ($stanza->{'stanza-id'}->attributes()->by == $this->jidfrom
|| $stanza->{'stanza-id'}->attributes()->by == \App\User::me()->id
)
) {
$this->id = (string)$stanza->{'stanza-id'}->attributes()->id;
// origin-id
} else if ($this->type == 'chat' && $stanza->{'origin-id'} && $stanza->{'origin-id'}->attributes()->id) {
$this->id = (string)$stanza->{'origin-id'}->attributes()->id;
}
// If it's a MUC message, we assume that the server already handled it
@ -257,11 +260,11 @@ class Message extends Model
if ($stanza->fallback && $stanza->fallback->attributes()->xmlns == 'urn:xmpp:feature-fallback:0'
&& $stanza->fallback->attributes()->for == 'urn:xmpp:reply:0') {
$this->body = trim(mb_substr(
$this->body,
$this->body = htmlspecialchars(trim(mb_substr(
htmlspecialchars_decode($this->body, ENT_NOQUOTES),
(int)$stanza->fallback->body->attributes()->end
// might need to handle start
));
)), ENT_NOQUOTES);
}
} else if ($stanza->thread) {
$this->thread = (string)$stanza->thread;

6
app/widgets/Chat/Chat.php

@ -591,12 +591,12 @@ class Chat extends \Movim\Widget\Base
if ($quotable) {
$p->setReplyto($reply->jidfrom.'/'.$reply->resource);
// Prepend quoted message body
$quotedBody = preg_replace('/^/m', '> ', $reply->body) . "\n";
$p->setReplyquotedbodylength(
mb_strlen(htmlspecialchars($quotedBody, ENT_NOQUOTES))
mb_strlen(htmlspecialchars($reply->body, ENT_NOQUOTES)) + 2 // 2 = > quote character
);
// Prepend quoted message body
$quotedBody = preg_replace('/^/m', '> ', $reply->body) . "\n";
$p->setContent($quotedBody . $body);
} else {
$p->setContent($body);

Loading…
Cancel
Save