2022-11-23 09:50:53 -05:00
|
|
|
/*
|
2023-02-06 01:47:15 -05:00
|
|
|
* Copyright (C) 2022-2023 Savoir-faire Linux Inc.
|
2022-11-23 09:50:53 -05:00
|
|
|
* Author: Nicolas Vengeon <nicolas.vengeon@savoirfairelinux.com>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
import QtQuick
|
|
|
|
import Qt5Compat.GraphicalEffects
|
|
|
|
import net.jami.Models 1.1
|
|
|
|
import net.jami.Adapters 1.1
|
|
|
|
import net.jami.Constants 1.1
|
|
|
|
|
|
|
|
Item {
|
|
|
|
id: root
|
|
|
|
|
|
|
|
property var emojiReaction
|
|
|
|
property real contentHeight: bubble.height
|
|
|
|
property real contentWidth: bubble.width
|
2022-11-23 09:50:53 -05:00
|
|
|
property var emojiTexts: ownEmojiList
|
2022-11-23 09:50:53 -05:00
|
|
|
|
2023-01-30 16:43:49 -05:00
|
|
|
visible: emojis.length && Body !== ""
|
2022-11-23 09:50:53 -05:00
|
|
|
|
|
|
|
property string emojis: {
|
2023-04-13 16:18:26 -04:00
|
|
|
var space = "";
|
|
|
|
var emojiList = [];
|
|
|
|
var emojiNumberList = [];
|
2022-11-23 09:50:53 -05:00
|
|
|
for (const reactions of Object.entries(emojiReaction)) {
|
2023-04-13 16:18:26 -04:00
|
|
|
var authorEmojiList = reactions[1];
|
2022-11-23 09:50:53 -05:00
|
|
|
for (var emojiIndex in authorEmojiList) {
|
2023-04-13 16:18:26 -04:00
|
|
|
var emoji = authorEmojiList[emojiIndex];
|
2022-11-23 09:50:53 -05:00
|
|
|
if (emojiList.includes(emoji)) {
|
2023-04-13 16:18:26 -04:00
|
|
|
var findIndex = emojiList.indexOf(emoji);
|
2022-11-23 09:50:53 -05:00
|
|
|
if (findIndex != -1)
|
2023-04-13 16:18:26 -04:00
|
|
|
emojiNumberList[findIndex] += 1;
|
2022-11-23 09:50:53 -05:00
|
|
|
} else {
|
2023-04-13 16:18:26 -04:00
|
|
|
emojiList.push(emoji);
|
|
|
|
emojiNumberList.push(1);
|
2022-11-23 09:50:53 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-04-13 16:18:26 -04:00
|
|
|
var cur = "";
|
2022-11-23 09:50:53 -05:00
|
|
|
for (var i in emojiList) {
|
|
|
|
if (emojiNumberList[i] !== 1)
|
2023-04-13 16:18:26 -04:00
|
|
|
cur = cur + space + emojiList[i] + emojiNumberList[i] + "";
|
2022-11-23 09:50:53 -05:00
|
|
|
else
|
2023-04-13 16:18:26 -04:00
|
|
|
cur = cur + space + emojiList[i] + "";
|
|
|
|
space = " ";
|
2022-11-23 09:50:53 -05:00
|
|
|
}
|
2023-04-13 16:18:26 -04:00
|
|
|
return cur;
|
2022-11-23 09:50:53 -05:00
|
|
|
}
|
|
|
|
|
2022-11-23 09:50:53 -05:00
|
|
|
property var ownEmojiList: {
|
2023-04-13 16:18:26 -04:00
|
|
|
var list = [];
|
|
|
|
var index = 0;
|
2022-11-23 09:50:53 -05:00
|
|
|
for (const reactions of Object.entries(emojiReaction)) {
|
2023-04-13 16:18:26 -04:00
|
|
|
var authorUri = reactions[0];
|
|
|
|
var authorEmojiList = reactions[1];
|
2022-11-23 09:50:53 -05:00
|
|
|
if (CurrentAccount.uri === authorUri) {
|
|
|
|
for (var emojiIndex in authorEmojiList) {
|
2023-04-13 16:18:26 -04:00
|
|
|
list[index] = authorEmojiList[emojiIndex];
|
|
|
|
index++;
|
2022-11-23 09:50:53 -05:00
|
|
|
}
|
2023-04-13 16:18:26 -04:00
|
|
|
return list;
|
2022-11-23 09:50:53 -05:00
|
|
|
}
|
|
|
|
}
|
2023-04-13 16:18:26 -04:00
|
|
|
return [];
|
2022-11-23 09:50:53 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
Rectangle {
|
|
|
|
id: bubble
|
|
|
|
|
|
|
|
color: JamiTheme.emojiReactBubbleBgColor
|
|
|
|
width: textEmojis.width + 6
|
|
|
|
height: textEmojis.height + 6
|
|
|
|
radius: 10
|
|
|
|
|
|
|
|
Text {
|
|
|
|
id: textEmojis
|
|
|
|
|
|
|
|
anchors.margins: 10
|
|
|
|
anchors.centerIn: bubble
|
|
|
|
font.pointSize: JamiTheme.emojiReactSize
|
|
|
|
color: JamiTheme.chatviewTextColor
|
|
|
|
text: root.emojis
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
DropShadow {
|
|
|
|
z: -1
|
|
|
|
|
|
|
|
width: bubble.width
|
|
|
|
height: bubble.height
|
|
|
|
horizontalOffset: 3.0
|
|
|
|
verticalOffset: 3.0
|
|
|
|
radius: bubble.radius * 4
|
|
|
|
color: JamiTheme.shadowColor
|
|
|
|
source: bubble
|
|
|
|
transparentBorder: true
|
2023-04-26 14:58:35 -04:00
|
|
|
samples: radius + 1
|
2022-11-23 09:50:53 -05:00
|
|
|
}
|
|
|
|
}
|