mirror of
https://github.com/vector-im/hydrogen-web.git
synced 2024-12-23 11:35:04 +01:00
Handle replies in EventEntry
This commit is contained in:
parent
711732200e
commit
242a9c209b
@ -155,7 +155,7 @@ export class RoomViewModel extends ViewModel {
|
||||
this._room.join();
|
||||
}
|
||||
|
||||
async _sendMessage(message, reply) {
|
||||
async _sendMessage(message, replyingTo) {
|
||||
if (!this._room.isArchived && message) {
|
||||
try {
|
||||
let msgtype = "m.text";
|
||||
@ -163,11 +163,11 @@ export class RoomViewModel extends ViewModel {
|
||||
message = message.substr(4).trim();
|
||||
msgtype = "m.emote";
|
||||
}
|
||||
const content = {msgtype, body: message};
|
||||
if (reply) {
|
||||
content["m.relates_to"] = reply;
|
||||
if (replyingTo) {
|
||||
await replyingTo.reply(msgtype, message);
|
||||
} else {
|
||||
await this._room.sendEvent("m.room.message", {msgtype, body: message});
|
||||
}
|
||||
await this._room.sendEvent("m.room.message", content);
|
||||
} catch (err) {
|
||||
console.error(`room.sendMessage(): ${err.message}:\n${err.stack}`);
|
||||
this._sendError = err;
|
||||
@ -336,7 +336,7 @@ class ComposerViewModel extends ViewModel {
|
||||
}
|
||||
|
||||
sendMessage(message) {
|
||||
const success = this._roomVM._sendMessage(message, this._replyVM?.reply());
|
||||
const success = this._roomVM._sendMessage(message, this._replyVM);
|
||||
if (success) {
|
||||
this._isEmpty = true;
|
||||
this.emitChange("canSend");
|
||||
|
@ -110,8 +110,8 @@ export class BaseMessageTile extends SimpleTile {
|
||||
this._roomVM.startReply(this);
|
||||
}
|
||||
|
||||
reply() {
|
||||
return this._entry.reply();
|
||||
reply(msgtype, body) {
|
||||
return this._room.sendEvent("m.room.message", this._entry.reply(msgtype, body));
|
||||
}
|
||||
|
||||
redact(reason, log) {
|
||||
|
@ -151,8 +151,8 @@ export class BaseEventEntry extends BaseEntry {
|
||||
return createAnnotation(this.id, key);
|
||||
}
|
||||
|
||||
reply() {
|
||||
return createReply(this.id);
|
||||
reply(msgtype, body) {
|
||||
return createReply(this.id, msgtype, body);
|
||||
}
|
||||
|
||||
/** takes both remote event id and local txn id into account, see overriding in PendingEventEntry */
|
||||
|
@ -29,11 +29,15 @@ export function createAnnotation(targetId, key) {
|
||||
};
|
||||
}
|
||||
|
||||
export function createReply(targetId) {
|
||||
export function createReply(targetId, msgtype, body) {
|
||||
return {
|
||||
msgtype,
|
||||
body,
|
||||
"m.relates_to": {
|
||||
"m.in_reply_to": {
|
||||
"event_id": targetId
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user