2022-09-27 23:26:26 +02:00
|
|
|
import QtQuick 2.14
|
2021-12-14 15:19:55 +01:00
|
|
|
import utils 1.0
|
2021-12-09 13:53:40 +01:00
|
|
|
|
|
|
|
QtObject {
|
|
|
|
id: root
|
|
|
|
|
|
|
|
property var messageModule
|
2022-01-12 00:16:17 +01:00
|
|
|
property var messagesModel
|
2022-02-22 21:48:57 +01:00
|
|
|
property var chatSectionModule
|
|
|
|
|
|
|
|
property var loadingHistoryMessagesInProgress: root.chatSectionModule? root.chatSectionModule.loadingHistoryMessagesInProgress : false
|
2022-01-12 00:16:17 +01:00
|
|
|
|
|
|
|
onMessageModuleChanged: {
|
|
|
|
if(!messageModule)
|
|
|
|
return
|
|
|
|
root.messagesModel = messageModule.model
|
|
|
|
}
|
2021-12-22 13:00:44 +01:00
|
|
|
|
|
|
|
function loadMoreMessages () {
|
|
|
|
if(!messageModule)
|
|
|
|
return
|
2022-02-07 17:55:14 -04:00
|
|
|
|
2022-02-22 21:48:57 +01:00
|
|
|
if(!messageModule.initialMessagesLoaded ||
|
|
|
|
root.loadingHistoryMessagesInProgress? root.loadingHistoryMessagesInProgress : false)
|
2021-12-22 13:00:44 +01:00
|
|
|
return
|
|
|
|
|
|
|
|
messageModule.loadMoreMessages()
|
|
|
|
}
|
2021-12-09 13:53:40 +01:00
|
|
|
|
|
|
|
function getMessageByIdAsJson (id) {
|
2022-09-30 17:36:49 +03:00
|
|
|
if (!messageModule) {
|
|
|
|
console.warn("getMessageByIdAsJson: Failed to parse message, because messageModule is not set")
|
2021-12-09 13:53:40 +01:00
|
|
|
return false
|
2022-09-30 17:36:49 +03:00
|
|
|
}
|
2021-12-09 13:53:40 +01:00
|
|
|
|
2022-09-30 17:36:49 +03:00
|
|
|
const jsonObj = messageModule.getMessageByIdAsJson(id)
|
|
|
|
if (jsonObj === "") {
|
|
|
|
console.warn("getMessageByIdAsJson: Failed to get message, returned json is empty")
|
|
|
|
return undefined
|
|
|
|
}
|
2022-01-12 00:16:17 +01:00
|
|
|
|
2022-09-30 17:36:49 +03:00
|
|
|
const obj = JSON.parse(jsonObj)
|
2021-12-09 13:53:40 +01:00
|
|
|
if (obj.error) {
|
2021-12-17 13:53:10 +01:00
|
|
|
// This log is available only in debug mode, if it's annoying we can remove it
|
2022-09-30 17:36:49 +03:00
|
|
|
console.debug("getMessageByIdAsJson: Failed to parse message for index: ", id, " error: ", obj.error)
|
2021-12-09 13:53:40 +01:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
return obj
|
|
|
|
}
|
|
|
|
|
2022-11-21 15:27:17 +03:00
|
|
|
function getReplyMessageByIdAsJson(messageId: string) {
|
|
|
|
if (!messageModule) {
|
|
|
|
console.warn("getReplyMessageByIdAsJson: Failed to parse message, because messageModule is not set")
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
const jsonObj = messageModule.getReplyMessageByIdAsJson(messageId)
|
|
|
|
if (jsonObj === "") {
|
|
|
|
console.warn("getReplyMessageByIdAsJson: Failed to get message, returned json is empty")
|
|
|
|
return undefined
|
|
|
|
}
|
|
|
|
|
|
|
|
const obj = JSON.parse(jsonObj)
|
|
|
|
if (obj.error) {
|
|
|
|
// This log is available only in debug mode, if it's annoying we can remove it
|
|
|
|
console.debug("getReplyMessageByIdAsJson: Failed to parse message for index: ", messageId, " error: ", obj.error)
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
return obj
|
|
|
|
}
|
|
|
|
|
2021-12-09 13:53:40 +01:00
|
|
|
function getMessageByIndexAsJson (index) {
|
|
|
|
if(!messageModule)
|
|
|
|
return false
|
|
|
|
|
|
|
|
let jsonObj = messageModule.getMessageByIndexAsJson(index)
|
2022-01-12 00:16:17 +01:00
|
|
|
if(jsonObj === "")
|
|
|
|
return
|
|
|
|
|
2021-12-09 13:53:40 +01:00
|
|
|
let obj = JSON.parse(jsonObj)
|
|
|
|
if (obj.error) {
|
2021-12-17 13:53:10 +01:00
|
|
|
// This log is available only in debug mode, if it's annoying we can remove it
|
2021-12-09 13:53:40 +01:00
|
|
|
console.debug("error parsing message for index: ", index, " error: ", obj.error)
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
return obj
|
|
|
|
}
|
2021-12-14 15:19:55 +01:00
|
|
|
|
2022-02-22 21:48:57 +01:00
|
|
|
function getSectionId () {
|
|
|
|
if(!messageModule)
|
|
|
|
return ""
|
|
|
|
|
|
|
|
return messageModule.getSectionId()
|
|
|
|
}
|
|
|
|
|
|
|
|
function getChatId () {
|
|
|
|
if(!messageModule)
|
|
|
|
return ""
|
|
|
|
|
|
|
|
return messageModule.getChatId()
|
|
|
|
}
|
|
|
|
|
2021-12-14 15:19:55 +01:00
|
|
|
function getChatType () {
|
|
|
|
if(!messageModule)
|
|
|
|
return Constants.chatType.unknown
|
|
|
|
|
|
|
|
return messageModule.getChatType()
|
|
|
|
}
|
|
|
|
|
|
|
|
function getChatColor () {
|
|
|
|
if(!messageModule)
|
|
|
|
return Style.current.blue
|
|
|
|
|
|
|
|
return messageModule.getChatColor()
|
|
|
|
}
|
|
|
|
|
2022-08-11 12:58:09 +02:00
|
|
|
function getChatIcon () {
|
|
|
|
if(!messageModule)
|
|
|
|
return ""
|
|
|
|
|
|
|
|
return messageModule.getChatIcon()
|
|
|
|
}
|
|
|
|
|
2021-12-14 15:19:55 +01:00
|
|
|
function amIChatAdmin () {
|
|
|
|
if(!messageModule)
|
|
|
|
return false
|
|
|
|
|
|
|
|
return messageModule.amIChatAdmin()
|
|
|
|
}
|
|
|
|
|
2022-05-10 18:13:36 +02:00
|
|
|
function pinMessageAllowedForMembers() {
|
|
|
|
if(!messageModule)
|
|
|
|
return false
|
|
|
|
|
|
|
|
return messageModule.pinMessageAllowedForMembers()
|
|
|
|
}
|
|
|
|
|
2021-12-14 15:19:55 +01: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 15:21:35 +01:00
|
|
|
|
|
|
|
function toggleReaction(messageId, emojiId) {
|
|
|
|
if(!messageModule)
|
|
|
|
return
|
|
|
|
|
|
|
|
return messageModule.toggleReaction(messageId, emojiId)
|
|
|
|
}
|
|
|
|
|
2022-01-13 16:14:34 +01:00
|
|
|
function deleteMessage(messageId) {
|
|
|
|
if(!messageModule)
|
|
|
|
return
|
|
|
|
messageModule.deleteMessage(messageId)
|
|
|
|
}
|
2022-01-17 19:46:46 +01:00
|
|
|
|
|
|
|
function setEditModeOn(messageId) {
|
|
|
|
if(!messageModule)
|
|
|
|
return
|
|
|
|
messageModule.setEditModeOn(messageId)
|
|
|
|
}
|
|
|
|
|
|
|
|
function setEditModeOff(messageId) {
|
|
|
|
if(!messageModule)
|
|
|
|
return
|
|
|
|
messageModule.setEditModeOff(messageId)
|
|
|
|
}
|
|
|
|
|
2022-11-08 18:44:05 +03:00
|
|
|
function editMessage(messageId, contentType, updatedMsg) {
|
2022-01-17 19:46:46 +01:00
|
|
|
if(!messageModule)
|
|
|
|
return
|
2022-11-08 18:44:05 +03:00
|
|
|
messageModule.editMessage(messageId, contentType, updatedMsg)
|
2022-01-17 19:46:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function interpretMessage(msg) {
|
|
|
|
if (msg.startsWith("/shrug")) {
|
2022-09-27 23:26:26 +02:00
|
|
|
return msg.replace("/shrug", "") + " ¯\\\\\\_(ツ)\\_/¯"
|
2022-01-17 19:46:46 +01:00
|
|
|
}
|
|
|
|
if (msg.startsWith("/tableflip")) {
|
|
|
|
return msg.replace("/tableflip", "") + " (╯°□°)╯︵ ┻━┻"
|
|
|
|
}
|
|
|
|
|
|
|
|
return msg
|
|
|
|
}
|
2022-01-25 13:56:53 +01:00
|
|
|
|
|
|
|
function getLinkPreviewData(url, uuid) {
|
|
|
|
if(!messageModule)
|
|
|
|
return
|
|
|
|
return messageModule.getLinkPreviewData(url, uuid)
|
|
|
|
}
|
2022-01-28 19:18:30 -04:00
|
|
|
|
|
|
|
function requestMoreMessages() {
|
|
|
|
if(!messageModule)
|
|
|
|
return
|
2022-12-08 16:01:08 -05:00
|
|
|
return messageModule.requestMoreMessages()
|
2022-01-28 19:18:30 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
function fillGaps(messageId) {
|
2022-12-08 16:01:08 -05:00
|
|
|
if(!messageModule)
|
2022-01-28 19:18:30 -04:00
|
|
|
return
|
2022-12-08 16:01:08 -05:00
|
|
|
return messageModule.fillGaps(messageId)
|
2022-01-28 19:18:30 -04:00
|
|
|
}
|
2022-02-11 17:01:36 +01:00
|
|
|
|
|
|
|
function leaveChat() {
|
2022-12-08 16:01:08 -05:00
|
|
|
if(!messageModule)
|
2022-02-11 17:01:36 +01:00
|
|
|
return
|
2022-12-08 16:01:08 -05:00
|
|
|
messageModule.leaveChat()
|
2022-02-11 17:01:36 +01:00
|
|
|
}
|
|
|
|
|
2022-02-22 21:48:57 +01:00
|
|
|
property bool playAnimation: {
|
|
|
|
if(!Global.applicationWindow.active)
|
|
|
|
return false
|
|
|
|
|
|
|
|
if(root.getSectionId() !== mainModule.activeSection.id)
|
|
|
|
return false
|
|
|
|
|
|
|
|
if(!root.chatSectionModule)
|
|
|
|
return false
|
|
|
|
|
|
|
|
if(root.chatSectionModule.activeItem.isSubItemActive &&
|
|
|
|
root.getChatId() !== root.chatSectionModule.activeItem.activeSubItem.id ||
|
|
|
|
!root.chatSectionModule.activeItem.isSubItemActive &&
|
|
|
|
root.getChatId() !== root.chatSectionModule.activeItem.id)
|
|
|
|
return false
|
|
|
|
|
|
|
|
return true
|
|
|
|
}
|
2022-12-08 16:01:08 -05:00
|
|
|
|
|
|
|
function resendMessage(messageId) {
|
|
|
|
if(!messageModule)
|
|
|
|
return
|
|
|
|
messageModule.resendMessage(messageId)
|
|
|
|
}
|
2021-12-09 13:53:40 +01:00
|
|
|
}
|