Some basic reply support.
This commit is contained in:
parent
d02c3f6e90
commit
5ca03fdea8
|
@ -82,7 +82,8 @@ RowLayout {
|
||||||
selectByMouse: true
|
selectByMouse: true
|
||||||
readOnly: true
|
readOnly: true
|
||||||
wrapMode: Label.Wrap
|
wrapMode: Label.Wrap
|
||||||
selectionColor: Material.accent
|
selectedTextColor: highlighted ? Material.accent : "white"
|
||||||
|
selectionColor: highlighted ? "white" : Material.accent
|
||||||
textFormat: Text.RichText
|
textFormat: Text.RichText
|
||||||
|
|
||||||
onLinkActivated: Qt.openUrlExternally(link)
|
onLinkActivated: Qt.openUrlExternally(link)
|
||||||
|
|
|
@ -332,12 +332,15 @@ Item {
|
||||||
onClicked: currentRoom.chooseAndUploadFile()
|
onClicked: currentRoom.chooseAndUploadFile()
|
||||||
}
|
}
|
||||||
|
|
||||||
TextField {
|
ScrollView {
|
||||||
property real progress: 0
|
|
||||||
|
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
Layout.preferredHeight: 48
|
Layout.preferredHeight: 48
|
||||||
|
|
||||||
|
clip: true
|
||||||
|
|
||||||
|
TextArea {
|
||||||
|
property real progress: 0
|
||||||
|
|
||||||
id: inputField
|
id: inputField
|
||||||
|
|
||||||
placeholderText: "Send a Message"
|
placeholderText: "Send a Message"
|
||||||
|
@ -345,6 +348,7 @@ Item {
|
||||||
topPadding: 0
|
topPadding: 0
|
||||||
bottomPadding: 0
|
bottomPadding: 0
|
||||||
selectByMouse: true
|
selectByMouse: true
|
||||||
|
verticalAlignment: TextEdit.AlignVCenter
|
||||||
|
|
||||||
text: currentRoom ? currentRoom.cachedInput : ""
|
text: currentRoom ? currentRoom.cachedInput : ""
|
||||||
|
|
||||||
|
@ -354,20 +358,19 @@ Item {
|
||||||
currentRoom.cachedInput = text
|
currentRoom.cachedInput = text
|
||||||
}
|
}
|
||||||
|
|
||||||
Keys.onReturnPressed: {
|
background: Rectangle { color: MSettings.darkTheme ? "#282828" : "#eaeaea" }
|
||||||
if (inputField.text) {
|
|
||||||
|
ToolTip.visible: currentRoom && currentRoom.hasUsersTyping
|
||||||
|
ToolTip.text: currentRoom ? currentRoom.usersTyping : ""
|
||||||
|
|
||||||
|
Shortcut {
|
||||||
|
sequence: "Ctrl+Return"
|
||||||
|
onActivated: {
|
||||||
inputField.postMessage(inputField.text)
|
inputField.postMessage(inputField.text)
|
||||||
inputField.text = ""
|
inputField.text = ""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
background: Rectangle {
|
|
||||||
color: MSettings.darkTheme ? "#282828" : "#eaeaea"
|
|
||||||
}
|
|
||||||
|
|
||||||
ToolTip.visible: currentRoom && currentRoom.hasUsersTyping
|
|
||||||
ToolTip.text: currentRoom ? currentRoom.usersTyping : ""
|
|
||||||
|
|
||||||
Timer {
|
Timer {
|
||||||
id: timeoutTimer
|
id: timeoutTimer
|
||||||
|
|
||||||
|
@ -398,6 +401,13 @@ Item {
|
||||||
var PREFIX_HTML = '/html '
|
var PREFIX_HTML = '/html '
|
||||||
var PREFIX_MARKDOWN = '/md '
|
var PREFIX_MARKDOWN = '/md '
|
||||||
|
|
||||||
|
var replyRe = new RegExp("^> <(.*)><(.*)> (.*)\n\n(.*)")
|
||||||
|
if (text.match(replyRe)) {
|
||||||
|
var matches = text.match(replyRe)
|
||||||
|
currentRoom.sendReply(matches[1], matches[2], matches[3], matches[4])
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if (text.indexOf(PREFIX_ME) === 0) {
|
if (text.indexOf(PREFIX_ME) === 0) {
|
||||||
text = text.substr(PREFIX_ME.length)
|
text = text.substr(PREFIX_ME.length)
|
||||||
currentRoom.postMessage(text, RoomMessageEvent.Emote)
|
currentRoom.postMessage(text, RoomMessageEvent.Emote)
|
||||||
|
@ -436,6 +446,7 @@ Item {
|
||||||
currentRoom.postPlainText(text)
|
currentRoom.postPlainText(text)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ItemDelegate {
|
ItemDelegate {
|
||||||
Layout.preferredWidth: 48
|
Layout.preferredWidth: 48
|
||||||
|
|
|
@ -41,6 +41,16 @@ Menu {
|
||||||
|
|
||||||
onTriggered: row.saveFileAs()
|
onTriggered: row.saveFileAs()
|
||||||
}
|
}
|
||||||
|
MenuItem {
|
||||||
|
visible: model && model.author !== currentRoom.localUser
|
||||||
|
height: visible ? undefined : 0
|
||||||
|
text: "Reply"
|
||||||
|
|
||||||
|
onTriggered: {
|
||||||
|
inputField.clear()
|
||||||
|
inputField.insert(0, "> <" + model.author.id + "><" + model.eventId + "> " + model.message + "\n\n")
|
||||||
|
}
|
||||||
|
}
|
||||||
MenuItem {
|
MenuItem {
|
||||||
visible: model && model.author === currentRoom.localUser
|
visible: model && model.author === currentRoom.localUser
|
||||||
height: visible ? undefined : 0
|
height: visible ? undefined : 0
|
||||||
|
|
|
@ -124,3 +124,18 @@ void MatriqueRoom::countChanged() {
|
||||||
resetHighlightCount();
|
resetHighlightCount();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MatriqueRoom::sendReply(QString userId, QString eventId,
|
||||||
|
QString replyContent, QString sendContent) {
|
||||||
|
QJsonObject json{
|
||||||
|
{"msgtype", "m.text"},
|
||||||
|
{"body", "> <" + userId + "> " + replyContent + "\n\n" + sendContent},
|
||||||
|
{"format", "org.matrix.custom.html"},
|
||||||
|
{"m.relates_to", QJsonObject{{"m.in_reply_to", QJsonObject{{"event_id", eventId}}}}},
|
||||||
|
{"formatted_body",
|
||||||
|
"<mx-reply><blockquote><a href=\"https://matrix.to/#/" + id() + "/" +
|
||||||
|
eventId + "\">In reply to</a> <a href=\"https://matrix.to/#/" +
|
||||||
|
userId + "\">" + userId + "</a><br>" + replyContent +
|
||||||
|
"</blockquote></mx-reply>" + sendContent}};
|
||||||
|
postJson("m.room.message", json);
|
||||||
|
}
|
||||||
|
|
|
@ -59,6 +59,7 @@ class MatriqueRoom : public Room {
|
||||||
void acceptInvitation();
|
void acceptInvitation();
|
||||||
void forget();
|
void forget();
|
||||||
void sendTypingNotification(bool isTyping);
|
void sendTypingNotification(bool isTyping);
|
||||||
|
void sendReply(QString userId, QString eventId, QString replyContent, QString sendContent);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // MATRIQUEROOM_H
|
#endif // MATRIQUEROOM_H
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
QHash<int, QByteArray> MessageEventModel::roleNames() const {
|
QHash<int, QByteArray> MessageEventModel::roleNames() const {
|
||||||
QHash<int, QByteArray> roles = QAbstractItemModel::roleNames();
|
QHash<int, QByteArray> roles = QAbstractItemModel::roleNames();
|
||||||
roles[EventTypeRole] = "eventType";
|
roles[EventTypeRole] = "eventType";
|
||||||
|
roles[MessageRole] = "message";
|
||||||
roles[AboveEventTypeRole] = "aboveEventType";
|
roles[AboveEventTypeRole] = "aboveEventType";
|
||||||
roles[EventIdRole] = "eventId";
|
roles[EventIdRole] = "eventId";
|
||||||
roles[TimeRole] = "time";
|
roles[TimeRole] = "time";
|
||||||
|
@ -415,6 +416,8 @@ QVariant MessageEventModel::data(const QModelIndex& idx, int role) const {
|
||||||
tr("Unknown Event"));
|
tr("Unknown Event"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (role == MessageRole) return evt.contentJson().value("body");
|
||||||
|
|
||||||
if (role == Qt::ToolTipRole) {
|
if (role == Qt::ToolTipRole) {
|
||||||
return evt.originalJson();
|
return evt.originalJson();
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,6 +13,7 @@ class MessageEventModel : public QAbstractListModel {
|
||||||
public:
|
public:
|
||||||
enum EventRoles {
|
enum EventRoles {
|
||||||
EventTypeRole = Qt::UserRole + 1,
|
EventTypeRole = Qt::UserRole + 1,
|
||||||
|
MessageRole,
|
||||||
AboveEventTypeRole,
|
AboveEventTypeRole,
|
||||||
EventIdRole,
|
EventIdRole,
|
||||||
TimeRole,
|
TimeRole,
|
||||||
|
|
Loading…
Reference in New Issue