Skip to content
Snippets Groups Projects
Commit c3984bd4 authored by Nicolas Werner's avatar Nicolas Werner
Browse files

Basic text message sending

parent b4962abb
No related branches found
No related tags found
No related merge requests found
......@@ -6,33 +6,41 @@ import dev.neko.spoon 1.0
Page {
id: chatPage
anchors.fill: parent
// The effective value will be restricted by ApplicationWindow.allowedOrientations
allowedOrientations: Orientation.All
property alias room: chatView.model
PageHeader {
title: room.roomName
}
SilicaListView {
id: chatView
ScrollDecorator { flickable: chatView }
boundsBehavior: Flickable.DragOverBounds
anchors.fill: parent
anchors.leftMargin: Theme.horizontalPageMargin
anchors.rightMargin: Theme.horizontalPageMargin
//ScrollDecorator { flickable: chatView }
header: PageHeader {
id: header
title: "Room: " + room.roomName
}
headerPositioning: ListView.PullBackHeader
property bool atEnd: false
ListView.onAdd: {
console.log("atYEnd::" + atYEnd)
console.log("atYEnd::" + atYEnd)
atEnd = atYEnd
}
onCountChanged: {
console.log("atEnd::" + atEnd)
if (atEnd)
scrollToBottom()
scrollToBottom()
}
onMovementEnded: {
......@@ -51,6 +59,7 @@ Page {
delegate: ListItem {
id: messageItem
contentHeight: loader.item.contentHeight
Loader {
id: loader
source: switch(model.Type) {
......@@ -72,7 +81,7 @@ Page {
property variant modelData: model
onLoaded: {
console.log("Loaded item with hight: " + item.height)
console.log("Loaded item with height: " + item.height)
messageItem.contentHeight = item.height
}
}
......@@ -84,5 +93,44 @@ Page {
text: room.userIdToUserName(section)
color: room.userColor(section, "#00000000")
}
footer: Item {
anchors.left: parent.left
anchors.right: parent.right
height: messageText.height
id: messageArea
TextArea {
anchors.left: parent.left
anchors.bottom: parent.bottom
id: messageText
placeholderText: qsTr("Enter your message")
//text: "asksfgjs afiguse aifdsvugsfd adfivuhsf aisdfuvs aiudsvhcas"
wrapMode: Text.Wrap
width: parent.width - sendButton.width
}
IconButton {
anchors.right: parent.right
anchors.top: parent.top
//anchors.left: messageText.right
id: sendButton
height: 100
width: 100
icon.source: "image://theme/icon-m-enter"
onClicked: {
if (messageText.text != "") {
room.sendTextMessage(messageText.text)
}
messageText.text = ""
}
}
}
}
}
......@@ -297,6 +297,24 @@ void Room::fetchOlderMessages() {
});
}
void Room::sendTextMessage(QString message) {
using mtx::events::EventType;
mtx::events::msg::Text text;
text.body = message.trimmed().toStdString();
http::client().send_room_message<msg::Text, EventType::RoomMessage>(
this->id, http::client().generate_txn_id(), text,
[this](const mtx::responses::EventId &res, mtx::http::RequestErr err) {
if (err) {
qDebug() << "failed to send message: " << *err;
return;
}
qDebug() << "send event as: $" << QString::fromStdString(res.event_id.to_string());
});
}
QHash<int, QByteArray> Room::roleNames() const {
QHash<int, QByteArray> roles;
roles[Type] = "Type";
......
......@@ -146,6 +146,7 @@ struct Room : public QAbstractListModel {
void addEvents(std::vector<mtx::events::collections::TimelineEvents> events, std::string prev_batch,
std::string next_batch);
void fetchOlderMessages();
void sendTextMessage(QString message);
private:
std::vector<mtx::events::collections::TimelineEvents> events;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment