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