Skip to content

Commit

Permalink
Merge pull request #251 from Nheko-Reborn/new-event-store
Browse files Browse the repository at this point in the history
New event store
  • Loading branch information
deepbluev7 authored Aug 26, 2020
2 parents 898297a + 3df4bde commit b58e370
Show file tree
Hide file tree
Showing 35 changed files with 2,257 additions and 1,211 deletions.
8 changes: 5 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,8 @@ set(SRC_FILES


# Timeline
src/timeline/ReactionsModel.cpp
src/timeline/EventStore.cpp
src/timeline/Reaction.cpp
src/timeline/TimelineViewManager.cpp
src/timeline/TimelineModel.cpp
src/timeline/DelegateChooser.cpp
Expand Down Expand Up @@ -340,7 +341,7 @@ if(USE_BUNDLED_MTXCLIENT)
FetchContent_Declare(
MatrixClient
GIT_REPOSITORY https://github.com/Nheko-Reborn/mtxclient.git
GIT_TAG 744018c86a8094acbda9821d6d7b5a890d4aac47
GIT_TAG d8666a3f1a5b709b78ccea2b545d540a8cb502ca
)
FetchContent_MakeAvailable(MatrixClient)
else()
Expand Down Expand Up @@ -463,7 +464,8 @@ qt5_wrap_cpp(MOC_HEADERS
src/emoji/Provider.h

# Timeline
src/timeline/ReactionsModel.h
src/timeline/EventStore.h
src/timeline/Reaction.h
src/timeline/TimelineViewManager.h
src/timeline/TimelineModel.h
src/timeline/DelegateChooser.h
Expand Down
2 changes: 1 addition & 1 deletion io.github.NhekoReborn.Nheko.json
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@
"name": "mtxclient",
"sources": [
{
"commit": "744018c86a8094acbda9821d6d7b5a890d4aac47",
"commit": "d8666a3f1a5b709b78ccea2b545d540a8cb502ca",
"type": "git",
"url": "https://github.com/Nheko-Reborn/mtxclient.git"
}
Expand Down
1 change: 1 addition & 0 deletions resources/qml/MatrixText.qml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ TextEdit {
readOnly: true
wrapMode: Text.Wrap
selectByMouse: true
activeFocusOnPress: false
color: colors.text

onLinkActivated: {
Expand Down
18 changes: 9 additions & 9 deletions resources/qml/Reactions.qml
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ Flow {
implicitHeight: contentItem.childrenRect.height

ToolTip.visible: hovered
ToolTip.text: model.users
ToolTip.text: modelData.users

onClicked: {
console.debug("Picked " + model.key + "in response to " + reactionFlow.eventId + " in room " + reactionFlow.roomId + ". selfReactedEvent: " + model.selfReactedEvent)
timelineManager.reactToMessage(reactionFlow.roomId, reactionFlow.eventId, model.key, model.selfReactedEvent)
console.debug("Picked " + modelData.key + "in response to " + reactionFlow.eventId + " in room " + reactionFlow.roomId + ". selfReactedEvent: " + modelData.selfReactedEvent)
timelineManager.queueReactionMessage(reactionFlow.eventId, modelData.key)
}


Expand All @@ -49,13 +49,13 @@ Flow {
font.family: settings.emojiFont
elide: Text.ElideRight
elideWidth: 150
text: model.key
text: modelData.key
}

Text {
anchors.baseline: reactionCounter.baseline
id: reactionText
text: textMetrics.elidedText + (textMetrics.elidedText == model.key ? "" : "")
text: textMetrics.elidedText + (textMetrics.elidedText == modelData.key ? "" : "")
font.family: settings.emojiFont
color: reaction.hovered ? colors.highlight : colors.text
maximumLineCount: 1
Expand All @@ -65,13 +65,13 @@ Flow {
id: divider
height: Math.floor(reactionCounter.implicitHeight * 1.4)
width: 1
color: (reaction.hovered || model.selfReactedEvent !== '') ? colors.highlight : colors.text
color: (reaction.hovered || modelData.selfReactedEvent !== '') ? colors.highlight : colors.text
}

Text {
anchors.verticalCenter: divider.verticalCenter
id: reactionCounter
text: model.counter
text: modelData.count
font: reaction.font
color: reaction.hovered ? colors.highlight : colors.text
}
Expand All @@ -82,8 +82,8 @@ Flow {

implicitWidth: reaction.implicitWidth
implicitHeight: reaction.implicitHeight
border.color: (reaction.hovered || model.selfReactedEvent !== '') ? colors.highlight : colors.text
color: model.selfReactedEvent !== '' ? Qt.hsla(highlightHue, highlightSat, highlightLight, 0.20) : colors.base
border.color: (reaction.hovered || modelData.selfReactedEvent !== '') ? colors.highlight : colors.text
color: modelData.selfReactedEvent !== '' ? Qt.hsla(highlightHue, highlightSat, highlightLight, 0.20) : colors.base
border.width: 1
radius: reaction.height / 2.0
}
Expand Down
2 changes: 1 addition & 1 deletion resources/qml/ScrollHelper.qml
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,6 @@ MouseArea {
//How long the scrollbar will remain visible
interval: 500
// Hide the scrollbars
onTriggered: flickable.cancelFlick();
onTriggered: { flickable.cancelFlick(); flickable.movementEnded(); }
}
}
33 changes: 18 additions & 15 deletions resources/qml/TimelineRow.qml
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,25 @@ import im.nheko 1.0
import "./delegates"
import "./emoji"

MouseArea {
Item {
anchors.left: parent.left
anchors.right: parent.right
height: row.height
propagateComposedEvents: true
preventStealing: true
hoverEnabled: true

acceptedButtons: Qt.LeftButton | Qt.RightButton
onClicked: {
if (mouse.button === Qt.RightButton)
messageContextMenu.show(model.id, model.type, model.isEncrypted, row)
}
onPressAndHold: {
if (mouse.source === Qt.MouseEventNotSynthesized)
messageContextMenu.show(model.id, model.type, model.isEncrypted, row)

MouseArea {
anchors.fill: parent
propagateComposedEvents: true
preventStealing: true
hoverEnabled: true

acceptedButtons: Qt.AllButtons
onClicked: {
if (mouse.button === Qt.RightButton)
messageContextMenu.show(model.id, model.type, model.isEncrypted, row)
}
onPressAndHold: {
messageContextMenu.show(model.id, model.type, model.isEncrypted, row, mapToItem(timelineRoot, mouse.x, mouse.y))
}
}
Rectangle {
color: (settings.messageHoverHighlight && parent.containsMouse) ? colors.base : "transparent"
Expand All @@ -45,7 +48,7 @@ MouseArea {
// fancy reply, if this is a reply
Reply {
visible: model.replyTo
modelData: chat.model.getDump(model.replyTo)
modelData: chat.model.getDump(model.replyTo, model.id)
userColor: timelineManager.userColor(modelData.userId, colors.window)
}

Expand Down Expand Up @@ -90,7 +93,6 @@ MouseArea {
ToolTip.visible: hovered
ToolTip.text: qsTr("React")
emojiPicker: emojiPopup
room_id: model.roomId
event_id: model.id
}
ImageButton {
Expand Down Expand Up @@ -128,6 +130,7 @@ MouseArea {
Label {
Layout.alignment: Qt.AlignRight | Qt.AlignTop
text: model.timestamp.toLocaleTimeString("HH:mm")
width: Math.max(implicitWidth, text.length*fontMetrics.maximumCharacterWidth)
color: inactiveColors.text

MouseArea{
Expand Down
68 changes: 36 additions & 32 deletions resources/qml/TimelineView.qml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import "./delegates"
import "./emoji"

Page {
id: timelineRoot

property var colors: currentActivePalette
property var systemInactive: SystemPalette { colorGroup: SystemPalette.Disabled }
property var inactiveColors: currentInactivePalette ? currentInactivePalette : systemInactive
Expand All @@ -25,34 +27,39 @@ Page {
id: fontMetrics
}

EmojiPicker {
id: emojiPopup
width: 7 * 52 + 20
height: 6 * 52
colors: palette
model: EmojiProxyModel {
category: EmojiCategory.People
sourceModel: EmojiModel {}
}
}
EmojiPicker {
id: emojiPopup
width: 7 * 52 + 20
height: 6 * 52
colors: palette
model: EmojiProxyModel {
category: EmojiCategory.People
sourceModel: EmojiModel {}
}
}

Menu {
id: messageContextMenu
modal: true

function show(eventId_, eventType_, isEncrypted_, showAt) {
function show(eventId_, eventType_, isEncrypted_, showAt_, position) {
eventId = eventId_
eventType = eventType_
isEncrypted = isEncrypted_
popup(showAt)

if (position)
popup(position, showAt_)
else
popup(showAt_)
}

property string eventId
property int eventType
property bool isEncrypted

MenuItem {
text: qsTr("React")
onClicked: chat.model.reactAction(messageContextMenu.eventId)
onClicked: emojiPopup.show(messageContextMenu.parent, messageContextMenu.eventId)
}
MenuItem {
text: qsTr("Reply")
Expand Down Expand Up @@ -87,8 +94,6 @@ Page {
}
}

id: timelineRoot

Rectangle {
anchors.fill: parent
color: colors.window
Expand All @@ -113,7 +118,7 @@ Page {
ListView {
id: chat

visible: timelineManager.timeline != null
visible: !!timelineManager.timeline

cacheBuffer: 400

Expand Down Expand Up @@ -181,7 +186,7 @@ Page {

id: wrapper
property Item section
anchors.horizontalCenter: parent.horizontalCenter
anchors.horizontalCenter: parent ? parent.horizontalCenter : undefined
width: chat.delegateMaxWidth
height: section ? section.height + timelinerow.height : timelinerow.height
color: "transparent"
Expand All @@ -205,14 +210,13 @@ Page {
}
}

Binding {
target: chat.model
property: "currentIndex"
when: y + height + 2 * chat.spacing > chat.contentY + chat.height && y < chat.contentY + chat.height
value: index
delayed: true
Connections {
target: chat
function onMovementEnded() {
if (y + height + 2 * chat.spacing > chat.contentY + chat.height && y < chat.contentY + chat.height)
chat.model.currentIndex = index;
}
}

}

section {
Expand Down Expand Up @@ -296,13 +300,13 @@ Page {
}
}

footer: BusyIndicator {
anchors.horizontalCenter: parent.horizontalCenter
running: chat.model && chat.model.paginationInProgress
height: 50
width: 50
z: 3
}
footer: BusyIndicator {
anchors.horizontalCenter: parent.horizontalCenter
running: chat.model && chat.model.paginationInProgress
height: 50
width: 50
z: 3
}
}

Rectangle {
Expand Down Expand Up @@ -354,7 +358,7 @@ Page {
anchors.rightMargin: 20
anchors.bottom: parent.bottom

modelData: chat.model ? chat.model.getDump(chat.model.reply) : {}
modelData: chat.model ? chat.model.getDump(chat.model.reply, chat.model.id) : {}
userColor: timelineManager.userColor(modelData.userId, colors.window)
}

Expand Down
4 changes: 2 additions & 2 deletions resources/qml/delegates/ImageMessage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ Item {
property double divisor: model.isReply ? 4 : 2
property bool tooHigh: tempHeight > timelineRoot.height / divisor

height: tooHigh ? timelineRoot.height / divisor : tempHeight
width: tooHigh ? (timelineRoot.height / divisor) / model.data.proportionalHeight : tempWidth
height: Math.round(tooHigh ? timelineRoot.height / divisor : tempHeight)
width: Math.round(tooHigh ? (timelineRoot.height / divisor) / model.data.proportionalHeight : tempWidth)

Image {
id: blurhash
Expand Down
12 changes: 12 additions & 0 deletions resources/qml/delegates/MessageDelegate.qml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ Item {
text: qsTr("redacted")
}
}
DelegateChoice {
roleValue: MtxEvent.Redaction
Pill {
text: qsTr("redacted")
}
}
DelegateChoice {
roleValue: MtxEvent.Encryption
Pill {
Expand Down Expand Up @@ -108,6 +114,12 @@ Item {
text: qsTr("%1 ended the call.").arg(model.data.userName)
}
}
DelegateChoice {
roleValue: MtxEvent.CallCandidates
NoticeMessage {
text: qsTr("Negotiating call...")
}
}
DelegateChoice {
// TODO: make a more complex formatter for the power levels.
roleValue: MtxEvent.PowerLevels
Expand Down
2 changes: 1 addition & 1 deletion resources/qml/delegates/PlayableMediaMessage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Rectangle {
id: bg
radius: 10
color: colors.dark
height: content.height + 24
height: Math.round(content.height + 24)
width: parent ? parent.width : undefined

Column {
Expand Down
2 changes: 1 addition & 1 deletion resources/qml/delegates/TextMessage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ MatrixText {
property string formatted: model.data.formattedBody
text: "<style type=\"text/css\">a { color:"+colors.link+";}</style>" + formatted.replace("<pre>", "<pre style='white-space: pre-wrap'>")
width: parent ? parent.width : undefined
height: isReply ? Math.min(chat.height / 8, implicitHeight) : undefined
height: isReply ? Math.round(Math.min(timelineRoot.height / 8, implicitHeight)) : undefined
clip: true
font.pointSize: (settings.enlargeEmojiOnlyMessages && model.data.isOnlyEmoji > 0 && model.data.isOnlyEmoji < 4) ? settings.fontSize * 3 : settings.fontSize
}
3 changes: 1 addition & 2 deletions resources/qml/emoji/EmojiButton.qml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@ import "../"
ImageButton {
property var colors: currentActivePalette
property var emojiPicker
property string room_id
property string event_id

image: ":/icons/icons/ui/smile.png"
id: emojiButton
onClicked: emojiPicker.visible ? emojiPicker.close() : emojiPicker.show(emojiButton, room_id, event_id)
onClicked: emojiPicker.visible ? emojiPicker.close() : emojiPicker.show(emojiButton, event_id)

}
Loading

0 comments on commit b58e370

Please sign in to comment.