fix: code review
This commit is contained in:
parent
649023bacf
commit
a342192f43
|
@ -76,23 +76,8 @@ QtObject:
|
||||||
proc getChannelColor*(self: ChatsView, channel: string): string {.slot.} =
|
proc getChannelColor*(self: ChatsView, channel: string): string {.slot.} =
|
||||||
self.chats.getChannelColor(channel)
|
self.chats.getChannelColor(channel)
|
||||||
|
|
||||||
proc replyAreaEnabled*(self: ChatsView, enable: bool, userName: string, message: string, identicon: string) {.signal.}
|
proc sendMessage*(self: ChatsView, message: string, replyTo: string) {.slot.} =
|
||||||
|
self.status.chat.sendMessage(self.activeChannel.id, message, replyTo)
|
||||||
proc setReplyTo(self: ChatsView, messageId: string) {.slot.} =
|
|
||||||
self.replyTo = messageId
|
|
||||||
|
|
||||||
proc enableReplyArea*(self: ChatsView, enable: bool, userName: string = "", message: string = "", identicon: string = "") {.slot.} =
|
|
||||||
if not enable:
|
|
||||||
self.replyTo = ""
|
|
||||||
self.replyAreaEnabled(enable, username, message, identicon)
|
|
||||||
|
|
||||||
proc disableReplyArea(self: ChatsView) =
|
|
||||||
self.replyTo = ""
|
|
||||||
self.replyAreaEnabled(false, "", "", "")
|
|
||||||
|
|
||||||
proc sendMessage*(self: ChatsView, message: string, isReply: bool) {.slot.} =
|
|
||||||
self.status.chat.sendMessage(self.activeChannel.id, message, if isReply: self.replyTo else: "")
|
|
||||||
self.disableReplyArea()
|
|
||||||
|
|
||||||
proc activeChannelChanged*(self: ChatsView) {.signal.}
|
proc activeChannelChanged*(self: ChatsView) {.signal.}
|
||||||
|
|
||||||
|
@ -105,7 +90,6 @@ QtObject:
|
||||||
if self.activeChannel.id == selectedChannel.id: return
|
if self.activeChannel.id == selectedChannel.id: return
|
||||||
self.activeChannel.setChatItem(selectedChannel)
|
self.activeChannel.setChatItem(selectedChannel)
|
||||||
self.status.chat.setActiveChannel(selectedChannel.id)
|
self.status.chat.setActiveChannel(selectedChannel.id)
|
||||||
self.disableReplyArea()
|
|
||||||
self.activeChannelChanged()
|
self.activeChannelChanged()
|
||||||
|
|
||||||
proc getActiveChannelIdx(self: ChatsView): QVariant {.slot.} =
|
proc getActiveChannelIdx(self: ChatsView): QVariant {.slot.} =
|
||||||
|
@ -135,7 +119,6 @@ QtObject:
|
||||||
proc setActiveChannel*(self: ChatsView, channel: string) =
|
proc setActiveChannel*(self: ChatsView, channel: string) =
|
||||||
if(channel == ""): return
|
if(channel == ""): return
|
||||||
self.activeChannel.setChatItem(self.chats.getChannel(self.chats.chats.findIndexById(channel)))
|
self.activeChannel.setChatItem(self.chats.getChannel(self.chats.chats.findIndexById(channel)))
|
||||||
self.disableReplyArea()
|
|
||||||
self.activeChannelChanged()
|
self.activeChannelChanged()
|
||||||
|
|
||||||
proc getActiveChannel*(self: ChatsView): QVariant {.slot.} =
|
proc getActiveChannel*(self: ChatsView): QVariant {.slot.} =
|
||||||
|
@ -150,8 +133,9 @@ QtObject:
|
||||||
if not self.messageList.hasKey(channel):
|
if not self.messageList.hasKey(channel):
|
||||||
self.messageList[channel] = newChatMessageList(channel, self.status)
|
self.messageList[channel] = newChatMessageList(channel, self.status)
|
||||||
# If there is only one channel, set is as active
|
# If there is only one channel, set is as active
|
||||||
if (self.activeChannel.chatItem == nil and self.chats.rowCount() == 1):
|
# if (self.activeChannel.chatItem == nil and self.chats.rowCount() == 1):
|
||||||
self.setActiveChannelByIndex(0)
|
# self.setActiveChannelByIndex(0)
|
||||||
|
# RRAMOS: commented because it was hanging the app on login
|
||||||
|
|
||||||
proc messagePushed*(self: ChatsView) {.signal.}
|
proc messagePushed*(self: ChatsView) {.signal.}
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,7 @@ proc renderBlock(self: ChatMessageList, message: Message): string =
|
||||||
for pMsg in message.parsedText:
|
for pMsg in message.parsedText:
|
||||||
case pMsg.textType:
|
case pMsg.textType:
|
||||||
of "paragraph":
|
of "paragraph":
|
||||||
result = "<p>"
|
result = result & "<p>"
|
||||||
for children in pMsg.children:
|
for children in pMsg.children:
|
||||||
result = result & self.renderInline(children)
|
result = result & self.renderInline(children)
|
||||||
result = result & "</p>"
|
result = result & "</p>"
|
||||||
|
@ -37,5 +37,5 @@ proc renderBlock(self: ChatMessageList, message: Message): string =
|
||||||
var color = if message.isCurrentUser: "#FFFFFF" else: "#666666"
|
var color = if message.isCurrentUser: "#FFFFFF" else: "#666666"
|
||||||
result = result & fmt("<span style=\"color: {color}\">▍ ") & pMsg.literal & "</span>"
|
result = result & fmt("<span style=\"color: {color}\">▍ ") & pMsg.literal & "</span>"
|
||||||
of "codeblock":
|
of "codeblock":
|
||||||
result = "<table style=\"background-color: #1a356b;\"><tr><td style=\"padding: 5px;\"><code style=\"color: #ffffff\">" & pMsg.literal & "</code></td></tr></table>"
|
result = result & "<table style=\"background-color: #1a356b;\"><tr><td style=\"padding: 5px;\"><code style=\"color: #ffffff\">" & pMsg.literal & "</code></td></tr></table>"
|
||||||
result = result.replace("\n", "<br />")
|
result = result.replace("\n", "<br />")
|
|
@ -80,7 +80,6 @@ QtObject:
|
||||||
of ChatMessageRoles.Id: result = newQVariant(message.id)
|
of ChatMessageRoles.Id: result = newQVariant(message.id)
|
||||||
of ChatMessageRoles.OutgoingStatus: result = newQVariant(message.outgoingStatus)
|
of ChatMessageRoles.OutgoingStatus: result = newQVariant(message.outgoingStatus)
|
||||||
of ChatMessageRoles.ResponseTo: result = newQVariant(message.responseTo)
|
of ChatMessageRoles.ResponseTo: result = newQVariant(message.responseTo)
|
||||||
of ChatMessageRoles.Text: result = newQVariant(message.text)
|
|
||||||
|
|
||||||
method roleNames(self: ChatMessageList): Table[int, string] =
|
method roleNames(self: ChatMessageList): Table[int, string] =
|
||||||
{
|
{
|
||||||
|
@ -98,8 +97,7 @@ QtObject:
|
||||||
ChatMessageRoles.SectionIdentifier.int: "sectionIdentifier",
|
ChatMessageRoles.SectionIdentifier.int: "sectionIdentifier",
|
||||||
ChatMessageRoles.Id.int: "messageId",
|
ChatMessageRoles.Id.int: "messageId",
|
||||||
ChatMessageRoles.OutgoingStatus.int: "outgoingStatus",
|
ChatMessageRoles.OutgoingStatus.int: "outgoingStatus",
|
||||||
ChatMessageRoles.ResponseTo.int: "responseTo",
|
ChatMessageRoles.ResponseTo.int: "responseTo"
|
||||||
ChatMessageRoles.Text.int: "text"
|
|
||||||
}.toTable
|
}.toTable
|
||||||
|
|
||||||
proc getMessageIndex(self: ChatMessageList, messageId: string): int {.slot.} =
|
proc getMessageIndex(self: ChatMessageList, messageId: string): int {.slot.} =
|
||||||
|
@ -111,6 +109,7 @@ QtObject:
|
||||||
case data:
|
case data:
|
||||||
of "userName": result = message.alias
|
of "userName": result = message.alias
|
||||||
of "message": result = message.text
|
of "message": result = message.text
|
||||||
|
of "identicon": result = message.identicon
|
||||||
else: result = ""
|
else: result = ""
|
||||||
|
|
||||||
proc add*(self: ChatMessageList, message: Message) =
|
proc add*(self: ChatMessageList, message: Message) =
|
||||||
|
|
|
@ -53,7 +53,10 @@ StackLayout {
|
||||||
}
|
}
|
||||||
Action {
|
Action {
|
||||||
text: qsTr("Reply to")
|
text: qsTr("Reply to")
|
||||||
onTriggered: chatsModel.enableReplyArea(true, profilePopup.userName, profilePopup.text, profilePopup.identicon)
|
onTriggered: {
|
||||||
|
isReply = true;
|
||||||
|
replyAreaContainer.setup()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -69,28 +72,18 @@ StackLayout {
|
||||||
|
|
||||||
|
|
||||||
ReplyArea {
|
ReplyArea {
|
||||||
id: replyArea
|
id: replyAreaContainer
|
||||||
visible: isReply
|
visible: isReply
|
||||||
}
|
}
|
||||||
|
|
||||||
ChatInput {
|
ChatInput {
|
||||||
height: 40
|
height: 40
|
||||||
anchors.top: !isReply ? inputArea.top : replyArea.bottom
|
anchors.top: !isReply ? inputArea.top : replyAreaContainer.bottom
|
||||||
anchors.topMargin: 4
|
anchors.topMargin: 4
|
||||||
anchors.left: parent.left
|
anchors.left: parent.left
|
||||||
anchors.right: parent.right
|
anchors.right: parent.right
|
||||||
anchors.bottom: parent.bottom
|
anchors.bottom: parent.bottom
|
||||||
}
|
}
|
||||||
|
|
||||||
Connections {
|
|
||||||
target: chatsModel
|
|
||||||
onReplyAreaEnabled: {
|
|
||||||
isReply = enable;
|
|
||||||
replyArea.userName = userName;
|
|
||||||
replyArea.identicon = identicon;
|
|
||||||
replyArea.message = message;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,7 @@ Item {
|
||||||
anchors.verticalCenter: parent.verticalCenter
|
anchors.verticalCenter: parent.verticalCenter
|
||||||
anchors.right: parent.right
|
anchors.right: parent.right
|
||||||
onClicked: {
|
onClicked: {
|
||||||
chatsModel.sendMessage(txtData.text, chatColumn.isReply)
|
chatsModel.sendMessage(txtData.text, SelectedMessage.messageId)
|
||||||
txtData.text = ""
|
txtData.text = ""
|
||||||
}
|
}
|
||||||
background: Rectangle {
|
background: Rectangle {
|
||||||
|
|
|
@ -33,7 +33,7 @@ Rectangle {
|
||||||
if (event.modifiers === Qt.NoModifier && (event.key === Qt.Key_Enter || event.key === Qt.Key_Return)) {
|
if (event.modifiers === Qt.NoModifier && (event.key === Qt.Key_Enter || event.key === Qt.Key_Return)) {
|
||||||
if(txtData.text.trim().length > 0){
|
if(txtData.text.trim().length > 0){
|
||||||
let msg = interpretMessage(txtData.text.trim())
|
let msg = interpretMessage(txtData.text.trim())
|
||||||
chatsModel.sendMessage(msg, chatColumn.isReply);
|
chatsModel.sendMessage(msg, SelectedMessage.messageId);
|
||||||
txtData.text = "";
|
txtData.text = "";
|
||||||
event.accepted = true;
|
event.accepted = true;
|
||||||
sendMessageSound.stop()
|
sendMessageSound.stop()
|
||||||
|
|
|
@ -39,12 +39,6 @@ ScrollView {
|
||||||
Qt.callLater( chatLogView.positionViewAtEnd )
|
Qt.callLater( chatLogView.positionViewAtEnd )
|
||||||
}
|
}
|
||||||
|
|
||||||
onReplyAreaEnabled: {
|
|
||||||
if (enable){
|
|
||||||
Qt.callLater( chatLogView.positionViewAtEnd )
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
onMessagePushed: {
|
onMessagePushed: {
|
||||||
if (!chatLogView.atYEnd) {
|
if (!chatLogView.atYEnd) {
|
||||||
// User has scrolled up, we don't want to scroll back
|
// User has scrolled up, we don't want to scroll back
|
||||||
|
|
|
@ -206,8 +206,8 @@ Item {
|
||||||
cursorShape: Qt.PointingHandCursor
|
cursorShape: Qt.PointingHandCursor
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
onClicked: {
|
onClicked: {
|
||||||
chatsModel.setReplyTo(messageId)
|
SelectedMessage.set(messageId, fromAuthor);
|
||||||
profileClick(userName, fromAuthor, identicon, text);
|
profileClick(userName, fromAuthor, identicon);
|
||||||
messageContextMenu.popup()
|
messageContextMenu.popup()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -230,8 +230,8 @@ Item {
|
||||||
cursorShape: Qt.PointingHandCursor
|
cursorShape: Qt.PointingHandCursor
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
onClicked: {
|
onClicked: {
|
||||||
chatsModel.setReplyTo(messageId)
|
SelectedMessage.set(messageId, fromAuthor);
|
||||||
profileClick(userName, fromAuthor, identicon, text)
|
profileClick(userName, fromAuthor, identicon)
|
||||||
messageContextMenu.popup()
|
messageContextMenu.popup()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -317,10 +317,11 @@ Item {
|
||||||
text: {
|
text: {
|
||||||
if(contentType === Constants.stickerType) return "";
|
if(contentType === Constants.stickerType) return "";
|
||||||
if(isEmoji){
|
if(isEmoji){
|
||||||
return Emoji.parse(message, "72x72");
|
return Emoji.parse(linkify(message), "72x72");
|
||||||
} else {
|
} else {
|
||||||
return Emoji.parse(linkify(message), "26x26");
|
return Emoji.parse(linkify(message), "26x26");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
anchors.left: parent.left
|
anchors.left: parent.left
|
||||||
anchors.leftMargin: parent.chatHorizontalPadding
|
anchors.leftMargin: parent.chatHorizontalPadding
|
||||||
|
@ -353,7 +354,15 @@ Item {
|
||||||
MouseArea {
|
MouseArea {
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
cursorShape: chatText.hoveredLink ? Qt.PointingHandCursor : Qt.ArrowCursor
|
cursorShape: chatText.hoveredLink ? Qt.PointingHandCursor : Qt.ArrowCursor
|
||||||
|
acceptedButtons: Qt.LeftButton | Qt.RightButton
|
||||||
onClicked: {
|
onClicked: {
|
||||||
|
if(mouse.button & Qt.RightButton) {
|
||||||
|
SelectedMessage.set(messageId, fromAuthor);
|
||||||
|
profileClick(userName, fromAuthor, identicon);
|
||||||
|
messageContextMenu.popup()
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
let link = chatText.hoveredLink;
|
let link = chatText.hoveredLink;
|
||||||
if(link.startsWith("#")){
|
if(link.startsWith("#")){
|
||||||
chatsModel.joinChat(link.substring(1), Constants.chatTypePublic);
|
chatsModel.joinChat(link.substring(1), Constants.chatTypePublic);
|
||||||
|
@ -362,17 +371,12 @@ Item {
|
||||||
|
|
||||||
if (link.startsWith('//')) {
|
if (link.startsWith('//')) {
|
||||||
let pk = link.replace("//", "");
|
let pk = link.replace("//", "");
|
||||||
profileClick(chatsModel.userNameOrAlias(pk), pk, chatsModel.generateIdenticon(pk), text)
|
profileClick(chatsModel.userNameOrAlias(pk), pk, chatsModel.generateIdenticon(pk))
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Qt.openUrlExternally(link)
|
Qt.openUrlExternally(link)
|
||||||
}
|
}
|
||||||
onPressAndHold: {
|
|
||||||
chatsModel.setReplyTo(messageId)
|
|
||||||
profileClick(userName, fromAuthor, identicon, text);
|
|
||||||
messageContextMenu.popup()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@ import "./"
|
||||||
|
|
||||||
Rectangle {
|
Rectangle {
|
||||||
property string userName: "Joseph Joestar"
|
property string userName: "Joseph Joestar"
|
||||||
property string message: "Your next line is: is this is a Jojo reference?"
|
property string message: "Your next line is: this is a Jojo reference"
|
||||||
property string identicon: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNk+A8AAQUBAScY42YAAAAASUVORK5CYII="
|
property string identicon: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNk+A8AAQUBAScY42YAAAAASUVORK5CYII="
|
||||||
|
|
||||||
id: replyArea
|
id: replyArea
|
||||||
|
@ -17,6 +17,21 @@ Rectangle {
|
||||||
anchors.top: parent.top
|
anchors.top: parent.top
|
||||||
color: "#00000000"
|
color: "#00000000"
|
||||||
|
|
||||||
|
function setup(){
|
||||||
|
let replyMessageIndex = chatsModel.messageList.getMessageIndex(SelectedMessage.messageId);
|
||||||
|
if (replyMessageIndex == -1) return;
|
||||||
|
|
||||||
|
userName = chatsModel.messageList.getReplyData(replyMessageIndex, "userName")
|
||||||
|
message = chatsModel.messageList.getReplyData(replyMessageIndex, "message")
|
||||||
|
identicon = chatsModel.messageList.getReplyData(replyMessageIndex, "identicon")
|
||||||
|
}
|
||||||
|
|
||||||
|
function reset(){
|
||||||
|
userName = "";
|
||||||
|
message= "";
|
||||||
|
identicon = "";
|
||||||
|
}
|
||||||
|
|
||||||
Rectangle {
|
Rectangle {
|
||||||
id: closeButton
|
id: closeButton
|
||||||
height: 32
|
height: 32
|
||||||
|
@ -37,7 +52,7 @@ Rectangle {
|
||||||
}
|
}
|
||||||
|
|
||||||
MouseArea {
|
MouseArea {
|
||||||
id: closeModalMouseArea
|
id: closeReplyArea
|
||||||
cursorShape: Qt.PointingHandCursor
|
cursorShape: Qt.PointingHandCursor
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
hoverEnabled: true
|
hoverEnabled: true
|
||||||
|
@ -47,7 +62,10 @@ Rectangle {
|
||||||
onEntered: {
|
onEntered: {
|
||||||
closeButton.color = Style.current.grey
|
closeButton.color = Style.current.grey
|
||||||
}
|
}
|
||||||
onClicked: chatsModel.enableReplyArea(false, "","","")
|
onClicked: {
|
||||||
|
reset();
|
||||||
|
chatColumn.isReply = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -61,6 +61,8 @@ Item {
|
||||||
target: chatsModel
|
target: chatsModel
|
||||||
onActiveChannelChanged: {
|
onActiveChannelChanged: {
|
||||||
chatGroupsListView.currentIndex = chatsModel.activeChannelIndex
|
chatGroupsListView.currentIndex = chatsModel.activeChannelIndex
|
||||||
|
SelectedMessage.reset();
|
||||||
|
chatColumn.isReply = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,18 @@
|
||||||
|
pragma Singleton
|
||||||
|
|
||||||
|
import QtQuick 2.13
|
||||||
|
|
||||||
|
QtObject {
|
||||||
|
property string messageId: ""
|
||||||
|
property string author: ""
|
||||||
|
|
||||||
|
function reset(){
|
||||||
|
messageId = "";
|
||||||
|
author = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
function set(_messageId, _author){
|
||||||
|
messageId = _messageId;
|
||||||
|
author = _author;
|
||||||
|
}
|
||||||
|
}
|
|
@ -3,3 +3,4 @@ singleton Style 1.0 ./Style.qml
|
||||||
singleton Constants 1.0 ./Constants.qml
|
singleton Constants 1.0 ./Constants.qml
|
||||||
singleton Utils 1.0 ./Utils.qml
|
singleton Utils 1.0 ./Utils.qml
|
||||||
singleton Emoji 1.0 ./Emoji.qml
|
singleton Emoji 1.0 ./Emoji.qml
|
||||||
|
singleton SelectedMessage 1.0 ./SelectedMessage.qml
|
||||||
|
|
Loading…
Reference in New Issue