2024-10-15 19:26:12 +00:00
|
|
|
import QtQuick 2.15
|
|
|
|
|
|
|
|
import StatusQ.Core.Theme 0.1
|
|
|
|
|
2021-12-14 14:19:55 +00:00
|
|
|
import utils 1.0
|
2021-12-09 12:53:40 +00:00
|
|
|
|
|
|
|
QtObject {
|
|
|
|
id: root
|
|
|
|
|
|
|
|
property var messageModule
|
2022-01-11 23:16:17 +00:00
|
|
|
property var messagesModel
|
2022-02-22 20:48:57 +00:00
|
|
|
property var chatSectionModule
|
|
|
|
|
2022-12-05 07:52:41 +00:00
|
|
|
readonly property bool loadingHistoryMessagesInProgress: root.chatSectionModule? root.chatSectionModule.loadingHistoryMessagesInProgress : false
|
|
|
|
readonly property int newMessagesCount: messagesModel ? messagesModel.newMessagesCount : 0
|
|
|
|
readonly property bool messageSearchOngoing: messageModule ? messageModule.messageSearchOngoing : false
|
2023-04-14 09:32:06 +00:00
|
|
|
readonly property bool loading: messageModule ? messageModule.loading : false
|
2022-01-11 23:16:17 +00:00
|
|
|
|
2023-01-12 09:28:45 +00:00
|
|
|
readonly property bool amIChatAdmin: messageModule ? messageModule.amIChatAdmin : false
|
|
|
|
readonly property bool isPinMessageAllowedForMembers: messageModule ? messageModule.isPinMessageAllowedForMembers : false
|
|
|
|
readonly property string chatId: messageModule ? messageModule.getChatId() : ""
|
|
|
|
readonly property int chatType: messageModule ? messageModule.chatType : Constants.chatType.unknown
|
2024-10-15 19:26:12 +00:00
|
|
|
readonly property string chatColor: messageModule ? messageModule.chatColor : Theme.palette.primaryColor1
|
2023-01-12 09:28:45 +00:00
|
|
|
readonly property string chatIcon: messageModule ? messageModule.chatIcon : ""
|
2023-12-12 02:16:06 +00:00
|
|
|
readonly property bool keepUnread: messageModule ? messageModule.keepUnread : false
|
2023-01-12 09:28:45 +00:00
|
|
|
|
2022-01-11 23:16:17 +00:00
|
|
|
onMessageModuleChanged: {
|
|
|
|
if(!messageModule)
|
|
|
|
return
|
|
|
|
root.messagesModel = messageModule.model
|
|
|
|
}
|
2021-12-22 12:00:44 +00:00
|
|
|
|
|
|
|
function loadMoreMessages () {
|
|
|
|
if(!messageModule)
|
|
|
|
return
|
2022-02-07 21:55:14 +00:00
|
|
|
|
2023-04-14 09:32:06 +00:00
|
|
|
if(root.loading)
|
2021-12-22 12:00:44 +00:00
|
|
|
return
|
|
|
|
|
|
|
|
messageModule.loadMoreMessages()
|
|
|
|
}
|
2021-12-09 12:53:40 +00:00
|
|
|
|
2023-12-12 02:16:06 +00:00
|
|
|
function setKeepUnread(flag: bool) {
|
|
|
|
if (!messageModule) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
messageModule.updateKeepUnread(flag)
|
|
|
|
}
|
|
|
|
|
2021-12-09 12:53:40 +00:00
|
|
|
function getMessageByIdAsJson (id) {
|
2022-09-30 14:36:49 +00:00
|
|
|
if (!messageModule) {
|
|
|
|
console.warn("getMessageByIdAsJson: Failed to parse message, because messageModule is not set")
|
2021-12-09 12:53:40 +00:00
|
|
|
return false
|
2022-09-30 14:36:49 +00:00
|
|
|
}
|
2021-12-09 12:53:40 +00:00
|
|
|
|
2022-09-30 14:36:49 +00:00
|
|
|
const jsonObj = messageModule.getMessageByIdAsJson(id)
|
|
|
|
if (jsonObj === "") {
|
|
|
|
console.warn("getMessageByIdAsJson: Failed to get message, returned json is empty")
|
|
|
|
return undefined
|
|
|
|
}
|
2022-01-11 23:16:17 +00:00
|
|
|
|
2022-09-30 14:36:49 +00:00
|
|
|
const obj = JSON.parse(jsonObj)
|
2021-12-09 12:53:40 +00:00
|
|
|
if (obj.error) {
|
2021-12-17 12:53:10 +00:00
|
|
|
// This log is available only in debug mode, if it's annoying we can remove it
|
2022-09-30 14:36:49 +00:00
|
|
|
console.debug("getMessageByIdAsJson: Failed to parse message for index: ", id, " error: ", obj.error)
|
2021-12-09 12:53:40 +00:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
return obj
|
|
|
|
}
|
|
|
|
|
|
|
|
function getMessageByIndexAsJson (index) {
|
|
|
|
if(!messageModule)
|
|
|
|
return false
|
|
|
|
|
|
|
|
let jsonObj = messageModule.getMessageByIndexAsJson(index)
|
2022-01-11 23:16:17 +00:00
|
|
|
if(jsonObj === "")
|
|
|
|
return
|
|
|
|
|
2021-12-09 12:53:40 +00:00
|
|
|
let obj = JSON.parse(jsonObj)
|
|
|
|
if (obj.error) {
|
2021-12-17 12:53:10 +00:00
|
|
|
// This log is available only in debug mode, if it's annoying we can remove it
|
2021-12-09 12:53:40 +00:00
|
|
|
console.debug("error parsing message for index: ", index, " error: ", obj.error)
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
return obj
|
|
|
|
}
|
2021-12-14 14:19:55 +00:00
|
|
|
|
2022-02-22 20:48:57 +00:00
|
|
|
function getSectionId () {
|
|
|
|
if(!messageModule)
|
|
|
|
return ""
|
|
|
|
|
|
|
|
return messageModule.getSectionId()
|
|
|
|
}
|
|
|
|
|
|
|
|
function getChatId () {
|
|
|
|
if(!messageModule)
|
|
|
|
return ""
|
|
|
|
|
|
|
|
return messageModule.getChatId()
|
|
|
|
}
|
|
|
|
|
2021-12-14 14:19:55 +00:00
|
|
|
function getNumberOfPinnedMessages () {
|
|
|
|
if(!messageModule)
|
|
|
|
return 0
|
|
|
|
|
|
|
|
return messageModule.getNumberOfPinnedMessages()
|
|
|
|
}
|
|
|
|
|
|
|
|
function pinMessage (messageId) {
|
|
|
|
if(!messageModule)
|
|
|
|
return
|
|
|
|
|
|
|
|
return messageModule.pinMessage(messageId)
|
|
|
|
}
|
|
|
|
|
|
|
|
function unpinMessage (messageId) {
|
|
|
|
if(!messageModule)
|
|
|
|
return
|
|
|
|
|
|
|
|
return messageModule.unpinMessage(messageId)
|
|
|
|
}
|
2021-12-20 14:21:35 +00:00
|
|
|
|
|
|
|
function toggleReaction(messageId, emojiId) {
|
|
|
|
if(!messageModule)
|
|
|
|
return
|
|
|
|
|
|
|
|
return messageModule.toggleReaction(messageId, emojiId)
|
|
|
|
}
|
|
|
|
|
2022-01-13 15:14:34 +00:00
|
|
|
function deleteMessage(messageId) {
|
|
|
|
if(!messageModule)
|
|
|
|
return
|
|
|
|
messageModule.deleteMessage(messageId)
|
|
|
|
}
|
2022-01-17 18:46:46 +00:00
|
|
|
|
2023-12-12 02:16:06 +00:00
|
|
|
function markMessageAsUnread(messageId) {
|
|
|
|
if (!messageModule) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
messageModule.markMessageAsUnread(messageId)
|
|
|
|
}
|
|
|
|
|
2023-05-19 16:07:50 +00:00
|
|
|
function warnAndDeleteMessage(messageId) {
|
|
|
|
if (localAccountSensitiveSettings.showDeleteMessageWarning)
|
|
|
|
Global.openDeleteMessagePopup(messageId, this)
|
|
|
|
else
|
|
|
|
deleteMessage(messageId)
|
|
|
|
}
|
|
|
|
|
2022-01-17 18:46:46 +00:00
|
|
|
function setEditModeOn(messageId) {
|
|
|
|
if(!messageModule)
|
|
|
|
return
|
|
|
|
messageModule.setEditModeOn(messageId)
|
|
|
|
}
|
|
|
|
|
2022-12-21 12:52:52 +00:00
|
|
|
function setEditModeOnLastMessage(pubkey) {
|
|
|
|
if(!messageModule)
|
|
|
|
return
|
|
|
|
messageModule.setEditModeOnAndScrollToLastMessage(pubkey)
|
|
|
|
}
|
|
|
|
|
2022-01-17 18:46:46 +00:00
|
|
|
function setEditModeOff(messageId) {
|
|
|
|
if(!messageModule)
|
|
|
|
return
|
|
|
|
messageModule.setEditModeOff(messageId)
|
|
|
|
}
|
|
|
|
|
2024-12-04 16:11:56 +00:00
|
|
|
function editMessage(messageId, updatedMsg) {
|
2022-01-17 18:46:46 +00:00
|
|
|
if(!messageModule)
|
|
|
|
return
|
2024-12-04 16:11:56 +00:00
|
|
|
messageModule.editMessage(messageId, updatedMsg)
|
2022-01-17 18:46:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function interpretMessage(msg) {
|
|
|
|
if (msg.startsWith("/shrug")) {
|
2022-09-27 21:26:26 +00:00
|
|
|
return msg.replace("/shrug", "") + " ¯\\\\\\_(ツ)\\_/¯"
|
2022-01-17 18:46:46 +00:00
|
|
|
}
|
|
|
|
if (msg.startsWith("/tableflip")) {
|
|
|
|
return msg.replace("/tableflip", "") + " (╯°□°)╯︵ ┻━┻"
|
|
|
|
}
|
|
|
|
|
|
|
|
return msg
|
|
|
|
}
|
2022-01-25 12:56:53 +00:00
|
|
|
|
2022-01-28 23:18:30 +00:00
|
|
|
function requestMoreMessages() {
|
|
|
|
if(!messageModule)
|
|
|
|
return
|
2022-12-08 21:01:08 +00:00
|
|
|
return messageModule.requestMoreMessages()
|
2022-01-28 23:18:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function fillGaps(messageId) {
|
2022-12-08 21:01:08 +00:00
|
|
|
if(!messageModule)
|
2022-01-28 23:18:30 +00:00
|
|
|
return
|
2022-12-08 21:01:08 +00:00
|
|
|
return messageModule.fillGaps(messageId)
|
2022-01-28 23:18:30 +00:00
|
|
|
}
|
2022-02-11 16:01:36 +00:00
|
|
|
|
|
|
|
function leaveChat() {
|
2022-12-08 21:01:08 +00:00
|
|
|
if(!messageModule)
|
2022-02-11 16:01:36 +00:00
|
|
|
return
|
2022-12-08 21:01:08 +00:00
|
|
|
messageModule.leaveChat()
|
2022-02-11 16:01:36 +00:00
|
|
|
}
|
|
|
|
|
2022-12-05 07:52:41 +00:00
|
|
|
function addNewMessagesMarker() {
|
|
|
|
if(!messageModule)
|
|
|
|
return
|
|
|
|
messageModule.addNewMessagesMarker()
|
|
|
|
}
|
|
|
|
|
2024-10-04 11:01:08 +00:00
|
|
|
readonly property bool isChatActive: {
|
2023-01-27 15:24:00 +00:00
|
|
|
if (root.getSectionId() !== mainModule.activeSection.id)
|
2022-02-22 20:48:57 +00:00
|
|
|
return false
|
|
|
|
|
2023-01-27 15:24:00 +00:00
|
|
|
if (!root.chatSectionModule)
|
2022-02-22 20:48:57 +00:00
|
|
|
return false
|
|
|
|
|
2023-01-27 15:24:00 +00:00
|
|
|
if (root.getChatId() !== root.chatSectionModule.activeItem.id)
|
2022-02-22 20:48:57 +00:00
|
|
|
return false
|
|
|
|
|
|
|
|
return true
|
|
|
|
}
|
2022-12-08 21:01:08 +00:00
|
|
|
|
|
|
|
function resendMessage(messageId) {
|
|
|
|
if(!messageModule)
|
|
|
|
return
|
|
|
|
messageModule.resendMessage(messageId)
|
|
|
|
}
|
2023-04-11 21:24:10 +00:00
|
|
|
|
|
|
|
function jumpToMessage(messageId) {
|
|
|
|
if(!messageModule)
|
|
|
|
return
|
|
|
|
messageModule.jumpToMessage(messageId)
|
|
|
|
}
|
|
|
|
|
|
|
|
function firstUnseenMentionMessageId() {
|
|
|
|
if(!messageModule)
|
|
|
|
return ""
|
|
|
|
return messageModule.firstUnseenMentionMessageId()
|
|
|
|
}
|
2021-12-09 12:53:40 +00:00
|
|
|
}
|