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