Fix counters

This commit is contained in:
Thomas 2024-05-11 16:27:26 +02:00
parent f3be249bef
commit b8873a277d
3 changed files with 27 additions and 11 deletions

View file

@ -1400,13 +1400,14 @@ document = window.document || {};
self.editor.html(self.content = '');
}
source[sourceValFunc](self.getText());
let inputText;
inputText = self.getText();
inputText = inputText
.replace(/(^|[^\/\w])@(([a-z0-9_]+)@[a-z0-9.-]+[a-z0-9]+)/ig, '$1@$3')
.replace(/(http(s)?:\/\/.)?(www\.)?[-a-zA-Z0-9@:%._+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_+.~#?&/=]*)/g, 'xxxxxxxxxxxxxxxxxxxxxxx');
$("#count").text(inputText.length);
var count = 0;
$('.emojionearea-editor').each(function() {
var currentElement = $(this);
count += currentElement.text()
.replace(/(^|[^\/\w])@(([a-z0-9_]+)@[a-z0-9.-]+[a-z0-9]+)/ig, '$1@$3')
.replace(/(http(s)?:\/\/.)?(www\.)?[-a-zA-Z0-9@:%._+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_+.~#?&/=]*)/g, 'xxxxxxxxxxxxxxxxxxxxxxx').length;
});
$("#count").text(count);
});
if (options.shortcuts) {
self.on("@keydown", function(_, e) {
@ -1461,17 +1462,18 @@ document = window.document || {};
callback($.map(map, function (emoji) {
return emoji.indexOf(term) === 0 ? emoji : null;
}));
} else if (term.startsWith("@")){
} else if (term.startsWith("@") && term.substring(1).length > 2){
$.ajax({
url: "https://"+$('#data_api').attr('data-instance')+"/api/v2/search?type=accounts&q="+term.substring(1),
headers: {"Authorization": $('#data_api').attr('data-token')},
context: document.body
}).done(function(value) {
alert(value);
callback($.map(value.accounts, function (value) {
return value;
}));
});
}else if (term.startsWith("#")){
}else if (term.startsWith("#") && term.substring(1).length > 2){
$.ajax({
url: "https://"+$('#data_api').attr('data-instance')+"/api/v2/search?type=hashtags&q="+term.substring(1),
headers: {"Authorization": $('#data_api').attr('data-token')},

View file

@ -54,6 +54,20 @@ class MediaAttachments {
$this->supported_mime_types = $supported_mime_types;
}
public function getSupportedFiles() : string {
$values = "/(\.|\/)(gif|jpe?g|apng|png|mp4|mp3|avi|mov|webm|wmv|flv|wav|ogg)$/i";
if(isset($this->supported_mime_types) && count($this->supported_mime_types) >0) {
$values = "/(\.|\/)(";
foreach ($this->supported_mime_types as $value) {
$cleanedValue = preg_replace("#(image/)|(video/)|(audio/)#","",$value,);
if(!str_contains($cleanedValue, '.') && !str_contains($cleanedValue, '-')) {
$values .= $cleanedValue.'|';
}
}
$values .= "jpg)$/i";
}
return $values;
}
public function getImageSizeLimit(): int
{
return $this->image_size_limit;

View file

@ -56,7 +56,7 @@
<div class="row">
<div class="col-md-4 col-4" style="margin-top: 20px;">
<div class="form-inline has-feedback">
<label for="count">{{ 'common.counter'|trans }}</label>&nbsp;&nbsp;<span id="count" class="form-control">0</span>
<label for="count">{{ 'common.counter'|trans }}</label>&nbsp;&nbsp;<span id="count" >0</span>
&nbsp;/{{ instanceConfiguration.statuses.maxCharacters }}
</div>
</div>
@ -437,7 +437,7 @@
$('#media_container').append($(content));
},
acceptFileTypes: /(\.|\/)(gif|jpe?g|apng|png|mp4|mp3|avi|mov|webm|wmv|flv|wav|ogg)$/i
acceptFileTypes: {{ app.session.get("instance").getConfiguration().getMediaAttachments().getSupportedFiles() }}
});
// Enable iframe cross-domain access via redirect option: