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();
|
this._room.join();
|
||||||
}
|
}
|
||||||
|
|
||||||
async _sendMessage(message, reply) {
|
async _sendMessage(message, replyingTo) {
|
||||||
if (!this._room.isArchived && message) {
|
if (!this._room.isArchived && message) {
|
||||||
try {
|
try {
|
||||||
let msgtype = "m.text";
|
let msgtype = "m.text";
|
||||||
@ -163,11 +163,11 @@ export class RoomViewModel extends ViewModel {
|
|||||||
message = message.substr(4).trim();
|
message = message.substr(4).trim();
|
||||||
msgtype = "m.emote";
|
msgtype = "m.emote";
|
||||||
}
|
}
|
||||||
const content = {msgtype, body: message};
|
if (replyingTo) {
|
||||||
if (reply) {
|
await replyingTo.reply(msgtype, message);
|
||||||
content["m.relates_to"] = reply;
|
} else {
|
||||||
|
await this._room.sendEvent("m.room.message", {msgtype, body: message});
|
||||||
}
|
}
|
||||||
await this._room.sendEvent("m.room.message", content);
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(`room.sendMessage(): ${err.message}:\n${err.stack}`);
|
console.error(`room.sendMessage(): ${err.message}:\n${err.stack}`);
|
||||||
this._sendError = err;
|
this._sendError = err;
|
||||||
@ -336,7 +336,7 @@ class ComposerViewModel extends ViewModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
sendMessage(message) {
|
sendMessage(message) {
|
||||||
const success = this._roomVM._sendMessage(message, this._replyVM?.reply());
|
const success = this._roomVM._sendMessage(message, this._replyVM);
|
||||||
if (success) {
|
if (success) {
|
||||||
this._isEmpty = true;
|
this._isEmpty = true;
|
||||||
this.emitChange("canSend");
|
this.emitChange("canSend");
|
||||||
|
@ -110,8 +110,8 @@ export class BaseMessageTile extends SimpleTile {
|
|||||||
this._roomVM.startReply(this);
|
this._roomVM.startReply(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
reply() {
|
reply(msgtype, body) {
|
||||||
return this._entry.reply();
|
return this._room.sendEvent("m.room.message", this._entry.reply(msgtype, body));
|
||||||
}
|
}
|
||||||
|
|
||||||
redact(reason, log) {
|
redact(reason, log) {
|
||||||
|
@ -151,8 +151,8 @@ export class BaseEventEntry extends BaseEntry {
|
|||||||
return createAnnotation(this.id, key);
|
return createAnnotation(this.id, key);
|
||||||
}
|
}
|
||||||
|
|
||||||
reply() {
|
reply(msgtype, body) {
|
||||||
return createReply(this.id);
|
return createReply(this.id, msgtype, body);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** takes both remote event id and local txn id into account, see overriding in PendingEventEntry */
|
/** 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 {
|
return {
|
||||||
|
msgtype,
|
||||||
|
body,
|
||||||
|
"m.relates_to": {
|
||||||
"m.in_reply_to": {
|
"m.in_reply_to": {
|
||||||
"event_id": targetId
|
"event_id": targetId
|
||||||
}
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user