refactor(@desktop/chat-messages): pin/unpin messages and pinned messages list updated

This commit is contained in:
Sale Djenic 2021-12-17 13:53:10 +01:00
parent b6b6d6b6c7
commit df5a5a627d
11 changed files with 93 additions and 121 deletions

View File

@ -130,7 +130,7 @@ proc buildPinnedMessageItem(self: Module, messageId: string, item: var pinned_ms
let contactDetails = self.controller.getContactDetails(m.`from`) let contactDetails = self.controller.getContactDetails(m.`from`)
var item = initItem( item = pinned_msg_item.initItem(
m.id, m.id,
m.responseTo, m.responseTo,
m.`from`, m.`from`,
@ -157,7 +157,7 @@ proc buildPinnedMessageItem(self: Module, messageId: string, item: var pinned_ms
return true return true
method newPinnedMessagesLoaded*(self: Module, pinnedMessages: seq[PinnedMessageDto]) = method newPinnedMessagesLoaded*(self: Module, pinnedMessages: seq[PinnedMessageDto]) =
var viewItems: seq[Item] var viewItems: seq[pinned_msg_item.Item]
for p in pinnedMessages: for p in pinnedMessages:
var item: pinned_msg_item.Item var item: pinned_msg_item.Item
if(not self.buildPinnedMessageItem(p.message.id, item)): if(not self.buildPinnedMessageItem(p.message.id, item)):

View File

@ -145,6 +145,9 @@ QtObject:
return -1 return -1
proc prependItems*(self: Model, items: seq[Item]) = proc prependItems*(self: Model, items: seq[Item]) =
if(items.len == 0):
return
let parentModelIndex = newQModelIndex() let parentModelIndex = newQModelIndex()
defer: parentModelIndex.delete defer: parentModelIndex.delete

View File

@ -194,20 +194,23 @@ QtObject:
proc pinUnpinMessage*(self: Service, chatId: string, messageId: string, pin: bool) = proc pinUnpinMessage*(self: Service, chatId: string, messageId: string, pin: bool) =
try: try:
let response = status_go.pinUnpinMessage(messageId, chatId, pin) let response = status_go.pinUnpinMessage(chatId, messageId, pin)
var pinMessagesObj: JsonNode var pinMessagesObj: JsonNode
if(response.result.getProp("pinMessages", pinMessagesObj)): if(response.result.getProp("pinMessages", pinMessagesObj)):
let data = MessagePinUnpinArgs(chatId: chatId, messageId: messageId) let pinnedMessagesArr = pinMessagesObj.getElems()
var pinned = false if(pinnedMessagesArr.len > 0): # an array is returned
if(pinMessagesObj.getProp("pinned", pinned)): let pinMessageObj = pinnedMessagesArr[0]
if(pinned and pin): let data = MessagePinUnpinArgs(chatId: chatId, messageId: messageId)
self.numOfPinnedMessagesPerChat[chatId] = self.numOfPinnedMessagesPerChat[chatId] + 1 var pinned = false
self.events.emit(SIGNAL_MESSAGE_PINNED, data) if(pinMessageObj.getProp("pinned", pinned)):
else: if(pinned and pin):
if(not pinned and not pin): self.numOfPinnedMessagesPerChat[chatId] = self.numOfPinnedMessagesPerChat[chatId] + 1
self.numOfPinnedMessagesPerChat[chatId] = self.numOfPinnedMessagesPerChat[chatId] - 1 self.events.emit(SIGNAL_MESSAGE_PINNED, data)
self.events.emit(SIGNAL_MESSAGE_UNPINNED, data) else:
if(not pinned and not pin):
self.numOfPinnedMessagesPerChat[chatId] = self.numOfPinnedMessagesPerChat[chatId] - 1
self.events.emit(SIGNAL_MESSAGE_UNPINNED, data)
except Exception as e: except Exception as e:
error "error: ", methodName="pinUnpinMessage", errName = e.name, errDesription = e.msg error "error: ", methodName="pinUnpinMessage", errName = e.name, errDesription = e.msg

View File

@ -17,26 +17,13 @@ import StatusQ.Controls 0.1 as StatusQControls
// TODO: replace with StatusMOdal // TODO: replace with StatusMOdal
ModalPopup { ModalPopup {
property var rootStore id: popup
property var messageStore property var messageStore
property var chatSectionModule property var pinnedMessagesModel //this doesn't belong to the messageStore, it is a part of the ChatContentStore, but we didn't introduce it yet.
property bool userCanPin: {
// Not Refactored Yet
return false
// switch (popup.rootStore.chatsModelInst.channelView.activeChannel.chatType) {
// case Constants.chatType.publicChat: return false
// case Constants.chatType.profile: return false
// case Constants.chatType.oneToOne: return true
// case Constants.chatType.privateGroupChat: return popup.rootStore.chatsModelInst.channelView.activeChannel.isAdmin(userProfile.pubKey)
// case Constants.chatType.communityChat: return popup.rootStore.chatsModelInst.communities.activeCommunity.admin
// default: return false
// }
}
property string messageToPin property string messageToPin
property string messageToUnpin property string messageToUnpin
id: popup
header: Item { header: Item {
height: childrenRect.height height: childrenRect.height
width: parent.width width: parent.width
@ -44,7 +31,7 @@ ModalPopup {
StyledText { StyledText {
id: title id: title
//% "Pin limit reached" //% "Pin limit reached"
text: !!messageToPin ? qsTrId("pin-limit-reached") : text: !!popup.messageToPin ? qsTrId("pin-limit-reached") :
//% "Pinned messages" //% "Pinned messages"
qsTrId("pinned-messages") qsTrId("pinned-messages")
anchors.top: parent.top anchors.top: parent.top
@ -58,7 +45,7 @@ ModalPopup {
id: nbPinnedMessages id: nbPinnedMessages
text: { text: {
if (!!messageToPin) { if (!!popup.messageToPin) {
//% "Unpin a previous message first" //% "Unpin a previous message first"
return qsTrId("unpin-a-previous-message-first") return qsTrId("unpin-a-previous-message-first")
} }
@ -102,8 +89,7 @@ ModalPopup {
ListView { ListView {
id: pinnedMessageListView id: pinnedMessageListView
// Not Refactored Yet model: popup.pinnedMessagesModel
// model: popup.rootStore.chatsModelInst.messageView.pinnedMessagesList
height: parent.height height: parent.height
anchors.left: parent.left anchors.left: parent.left
anchors.leftMargin: -Style.current.padding anchors.leftMargin: -Style.current.padding
@ -113,7 +99,7 @@ ModalPopup {
anchors.top: parent.top anchors.top: parent.top
anchors.topMargin: -Style.current.halfPadding anchors.topMargin: -Style.current.halfPadding
clip: true clip: true
delegate: Item { delegate: Item {
id: messageDelegate id: messageDelegate
property var listView: ListView.view property var listView: ListView.view
@ -122,74 +108,38 @@ ModalPopup {
MessageView { MessageView {
id: messageItem id: messageItem
// rootStore: popup.rootStore messageStore: popup.messageStore
// messageStore: popup.messageStore messageContextMenu: msgContextMenu
/////////////TODO Remove
// fromAuthor: model.fromAuthor messageId: model.id
// chatId: model.chatId responseToMessageWithId: model.responseToMessageWithId
// userName: model.userName senderId: model.senderId
// alias: model.alias senderDisplayName: model.senderDisplayName
// localName: model.localName senderLocalName: model.senderLocalName
// message: model.message senderIcon: model.senderIcon
// plainText: model.plainText isSenderIconIdenticon: model.isSenderIconIdenticon
// identicon: model.identicon amISender: model.amISender
// isCurrentUser: model.isCurrentUser message: model.messageText
// timestamp: model.timestamp messageImage: model.messageImage
// sticker: model.sticker messageTimestamp: model.timestamp
// contentType: model.contentType messageOutgoingStatus: model.outgoingStatus
// outgoingStatus: model.outgoingStatus messageContentType: model.contentType
// responseTo: model.responseTo pinnedMessage: model.pinned
// imageClick: imagePopup.openPopup.bind(imagePopup)
// messageId: model.messageId // This is possible since we have all data loaded before we load qml.
// emojiReactions: model.emojiReactions // When we fetch messages to fulfill a gap we have to set them at once.
// linkUrls: model.linkUrls prevMessageIndex: index - 1
// communityId: model.communityId prevMessageAsJsonObj: popup.messageStore? popup.messageStore.getMessageByIndexAsJson(index - 1) : {}
// hasMention: model.hasMention nextMessageIndex: index + 1
// stickerPackId: model.stickerPackId nextMessageAsJsonObj: popup.messageStore? popup.messageStore.messageStore.getMessageByIndexAsJson(index + 1) : {}
// timeout: model.timeout
// pinnedMessage: true // Additional params
// pinnedBy: model.pinnedBy forceHoverHandler: !popup.messageToPin
// forceHoverHandler: !messageToPin
// activityCenterMessage: false
// isEdited: model.isEdited
// showEdit: false
// messageContextMenu: msgContextMenu
// Component.onCompleted: {
// messageStore.fromAuthor = model.fromAuthor;
// messageStore.chatId = model.chatId;
// messageStore.userName = model.userName;
// messageStore.alias = model.alias;
// messageStore.localName = model.localName;
// messageStore.message = model.message;
// messageStore.plainText = model.plainText;
// messageStore.identicon = model.identicon;
// messageStore.isCurrentUser = model.isCurrentUser;
// messageStore.timestamp = model.timestamp;
// messageStore.sticker = model.sticker;
// messageStore.contentType = model.contentType;
// messageStore.outgoingStatus = model.outgoingStatus;
// messageStore.responseTo = model.responseTo;
// messageStore.imageClick = imagePopup.openPopup.bind(imagePopup);
// messageStore.messageId = model.messageId;
// messageStore.emojiReactions = model.emojiReactions;
// messageStore.linkUrls = model.linkUrls;
// messageStore.communityId = model.communityId;
// messageStore.hasMention = model.hasMention;
// messageStore.stickerPackId = model.stickerPackId;
// messageStore.timeout = model.timeout;
// messageStore.pinnedMessage = true;
// messageStore.pinnedBy = model.pinnedBy;
// messageStore.forceHoverHandler = !messageToPin;
// messageStore.activityCenterMessage = false;
// messageStore.isEdited = model.isEdited;
// messageStore.showEdit = false;
// messageStore.messageContextMenu = msgContextMenu;
// }
} }
MouseArea { MouseArea {
anchors.fill: parent anchors.fill: parent
enabled: !!messageToPin enabled: !!popup.messageToPin
cursorShape: Qt.PointingHandCursor cursorShape: Qt.PointingHandCursor
z: 55 z: 55
onClicked: radio.toggle() onClicked: radio.toggle()
@ -197,7 +147,7 @@ ModalPopup {
StatusQControls.StatusRadioButton { StatusQControls.StatusRadioButton {
id: radio id: radio
visible: !!messageToPin visible: !!popup.messageToPin
anchors.right: parent.right anchors.right: parent.right
anchors.rightMargin: 18 anchors.rightMargin: 18
anchors.verticalCenter: parent.verticalCenter anchors.verticalCenter: parent.verticalCenter
@ -205,7 +155,7 @@ ModalPopup {
function toggle() { function toggle() {
radio.checked = !radio.checked radio.checked = !radio.checked
if (radio.checked) { if (radio.checked) {
messageToUnpin = model.messageId popup.messageToUnpin = model.id
} }
} }
} }
@ -215,12 +165,17 @@ ModalPopup {
id: msgContextMenu id: msgContextMenu
pinnedPopup: true pinnedPopup: true
pinnedMessage: true pinnedMessage: true
// chatSectionModule: popup.chatSectionModule
// store: popup.rootStore
// reactionModel: popup.rootStore.emojiReactionsModel
onShouldCloseParentPopup: { onShouldCloseParentPopup: {
popup.close() popup.close()
} }
onPinMessage: {
popup.messageStore.pinMessage(messageId)
}
onUnpinMessage: {
popup.messageStore.unpinMessage(messageId)
}
} }
} }
@ -231,18 +186,16 @@ ModalPopup {
StatusQControls.StatusButton { StatusQControls.StatusButton {
id: btnUnpin id: btnUnpin
visible: !!messageToPin visible: !!popup.messageToPin
enabled: !!messageToUnpin enabled: !!popup.messageToUnpin
//% "Unpin" //% "Unpin"
text: qsTrId("unpin") text: qsTrId("unpin")
type: StatusQControls.StatusBaseButton.Type.Danger type: StatusQControls.StatusBaseButton.Type.Danger
anchors.right: parent.right anchors.right: parent.right
onClicked: { onClicked: {
// Not Refactored Yet popup.messageStore.unpinMessage(popup.messageToUnpin)
// const chatId = popup.rootStore.chatsModelInst.channelView.activeChannel.id popup.messageToUnpin = ""
// popup.rootStore.chatsModelInst.messageView.unPinMessage(messageToUnpin, chatId) popup.messageToPin = ""
// popup.rootStore.chatsModelInst.messageView.pinMessage(messageToPin, chatId)
messageToUnpin = messageToPin = ""
popup.close() popup.close()
} }
} }

View File

@ -13,6 +13,7 @@ QtObject {
let jsonObj = messageModule.getMessageByIdAsJson(id) let jsonObj = messageModule.getMessageByIdAsJson(id)
let obj = JSON.parse(jsonObj) let obj = JSON.parse(jsonObj)
if (obj.error) { if (obj.error) {
// This log is available only in debug mode, if it's annoying we can remove it
console.debug("error parsing message for index: ", id, " error: ", obj.error) console.debug("error parsing message for index: ", id, " error: ", obj.error)
return false return false
} }
@ -27,6 +28,7 @@ QtObject {
let jsonObj = messageModule.getMessageByIndexAsJson(index) let jsonObj = messageModule.getMessageByIndexAsJson(index)
let obj = JSON.parse(jsonObj) let obj = JSON.parse(jsonObj)
if (obj.error) { if (obj.error) {
// This log is available only in debug mode, if it's annoying we can remove it
console.debug("error parsing message for index: ", index, " error: ", obj.error) console.debug("error parsing message for index: ", index, " error: ", obj.error)
return false return false
} }

View File

@ -333,9 +333,6 @@ Item {
id: pinnedMessagesPopupComponent id: pinnedMessagesPopupComponent
PinnedMessagesPopup { PinnedMessagesPopup {
id: pinnedMessagesPopup id: pinnedMessagesPopup
chatSectionModule: root.parentModule
rootStore: root.rootStore
messageStore: root.rootStore.messageStore
onClosed: destroy() onClosed: destroy()
} }
} }

View File

@ -67,7 +67,13 @@ ColumnLayout {
chatInfoButton.pinnedMessagesCount: chatContentModule.pinnedMessagesModel.count chatInfoButton.pinnedMessagesCount: chatContentModule.pinnedMessagesModel.count
chatInfoButton.muted: chatContentModule.chatDetails.muted chatInfoButton.muted: chatContentModule.chatDetails.muted
chatInfoButton.onPinnedMessagesCountClicked: openPopup(pinnedMessagesPopupComponent) chatInfoButton.onPinnedMessagesCountClicked: {
Global.openPopup(pinnedMessagesPopupComponent, {
messageStore: messageStore,
pinnedMessagesModel: chatContentModule.pinnedMessagesModel,
messageToPin: ""
})
}
chatInfoButton.onUnmute: chatContentModule.unmuteChat() chatInfoButton.onUnmute: chatContentModule.unmuteChat()
chatInfoButton.sensor.enabled: chatContentModule.chatDetails.type !== Constants.chatType.publicChat && chatInfoButton.sensor.enabled: chatContentModule.chatDetails.type !== Constants.chatType.publicChat &&
@ -193,6 +199,14 @@ ColumnLayout {
onUnpinMessage: { onUnpinMessage: {
messageStore.unpinMessage(messageId) messageStore.unpinMessage(messageId)
} }
onPinnedMessagesLimitReached: {
Global.openPopup(pinnedMessagesPopupComponent, {
messageStore: messageStore,
pinnedMessagesModel: chatContentModule.pinnedMessagesModel,
messageToPin: messageId
})
}
} }
StatusImageModal { StatusImageModal {

View File

@ -319,9 +319,6 @@ Item {
prevMessageAsJsonObj: messageStore.getMessageByIndexAsJson(index - 1) prevMessageAsJsonObj: messageStore.getMessageByIndexAsJson(index - 1)
nextMessageIndex: index + 1 nextMessageIndex: index + 1
nextMessageAsJsonObj: messageStore.getMessageByIndexAsJson(index + 1) nextMessageAsJsonObj: messageStore.getMessageByIndexAsJson(index + 1)
Component.onCompleted: {
}
} }
} }

View File

@ -12,14 +12,15 @@ Rectangle {
property int contentType: 2 property int contentType: 2
property var messageContextMenu property var messageContextMenu
property bool showMoreButton: true property bool showMoreButton: true
property bool activityCenterMessage property bool activityCenterMsg
property bool placeholderMsg
property string fromAuthor property string fromAuthor
property alias editBtnActive: editBtn.active property alias editBtnActive: editBtn.active
signal hoverChanged(bool hovered) signal hoverChanged(bool hovered)
signal setMessageActive(string messageId, bool active) signal setMessageActive(string messageId, bool active)
signal clickMessage(bool isProfileClick, bool isSticker, bool isImage, var image, bool emojiOnly, bool hideEmojiPicker) signal clickMessage(bool isProfileClick, bool isSticker, bool isImage, var image, bool emojiOnly, bool hideEmojiPicker)
visible: !placeholderMessage && !activityCenterMessage && visible: !buttonsContainer.placeholderMsg && !buttonsContainer.activityCenterMsg &&
(buttonsContainer.parentIsHovered || isMessageActive) (buttonsContainer.parentIsHovered || isMessageActive)
&& contentType !== Constants.messageContentType.transactionType && contentType !== Constants.messageContentType.transactionType
width: buttonRow.width + buttonsContainer.containerMargin * 2 width: buttonRow.width + buttonsContainer.containerMargin * 2

View File

@ -83,6 +83,8 @@ Item {
showMoreButton: root.showMoreButton showMoreButton: root.showMoreButton
fromAuthor: senderId fromAuthor: senderId
editBtnActive: isText && !isEdit && isCurrentUser && showEdit editBtnActive: isText && !isEdit && isCurrentUser && showEdit
activityCenterMsg: activityCenterMessage
placeholderMsg: placeholderMessage
onClickMessage: { onClickMessage: {
root.clickMessage(isProfileClick, isSticker, isImage, image, emojiOnly, hideEmojiPicker, false, false, ""); root.clickMessage(isProfileClick, isSticker, isImage, image, emojiOnly, hideEmojiPicker, false, false, "");
} }
@ -479,7 +481,7 @@ Item {
z: 51 z: 51
sourceComponent: Component { sourceComponent: Component {
StatusChatImage { StatusChatImage {
imageSource: image imageSource: messageImage
imageWidth: 200 imageWidth: 200
onClicked: { onClicked: {
if (mouse.button === Qt.LeftButton) { if (mouse.button === Qt.LeftButton) {

View File

@ -185,7 +185,7 @@ Column {
messageContextMenu.messageSenderId = root.senderId messageContextMenu.messageSenderId = root.senderId
messageContextMenu.messageContentType = root.messageContentType messageContextMenu.messageContentType = root.messageContentType
messageContextMenu.pinnedMessage = root.pinnedMessage messageContextMenu.pinnedMessage = root.pinnedMessage
messageContextMenu.canPin = messageStore.getNumberOfPinnedMessages() <= Constants.maxNumberOfPins messageContextMenu.canPin = messageStore.getNumberOfPinnedMessages() < Constants.maxNumberOfPins
messageContextMenu.selectedUserPublicKey = root.senderId messageContextMenu.selectedUserPublicKey = root.senderId
messageContextMenu.selectedUserDisplayName = root.senderDisplayName messageContextMenu.selectedUserDisplayName = root.senderDisplayName