mirror of
https://github.com/vector-im/hydrogen-web.git
synced 2024-12-23 03:25:12 +01:00
Add the ability to reply
This commit is contained in:
parent
800b4785d1
commit
46215b3c51
@ -155,7 +155,7 @@ export class RoomViewModel extends ViewModel {
|
||||
this._room.join();
|
||||
}
|
||||
|
||||
async _sendMessage(message) {
|
||||
async _sendMessage(message, replyTo) {
|
||||
if (!this._room.isArchived && message) {
|
||||
try {
|
||||
let msgtype = "m.text";
|
||||
@ -163,7 +163,11 @@ export class RoomViewModel extends ViewModel {
|
||||
message = message.substr(4).trim();
|
||||
msgtype = "m.emote";
|
||||
}
|
||||
await this._room.sendEvent("m.room.message", {msgtype, body: message});
|
||||
const content = {msgtype, body: message};
|
||||
if (replyTo) {
|
||||
content["m.relates_to"] = replyTo.reply();
|
||||
}
|
||||
await this._room.sendEvent("m.room.message", content);
|
||||
} catch (err) {
|
||||
console.error(`room.sendMessage(): ${err.message}:\n${err.stack}`);
|
||||
this._sendError = err;
|
||||
@ -327,7 +331,7 @@ class ComposerViewModel extends ViewModel {
|
||||
}
|
||||
|
||||
sendMessage(message) {
|
||||
const success = this._roomVM._sendMessage(message);
|
||||
const success = this._roomVM._sendMessage(message, this._replyTo);
|
||||
if (success) {
|
||||
this._isEmpty = true;
|
||||
this.emitChange("canSend");
|
||||
|
@ -16,7 +16,7 @@ limitations under the License.
|
||||
|
||||
import {BaseEntry} from "./BaseEntry.js";
|
||||
import {REDACTION_TYPE} from "../../common.js";
|
||||
import {createAnnotation, ANNOTATION_RELATION_TYPE, getRelationFromContent} from "../relations.js";
|
||||
import {createAnnotation, createReply, ANNOTATION_RELATION_TYPE, getRelationFromContent} from "../relations.js";
|
||||
import {PendingAnnotation} from "../PendingAnnotation.js";
|
||||
|
||||
/** Deals mainly with local echo for relations and redactions,
|
||||
@ -151,6 +151,10 @@ export class BaseEventEntry extends BaseEntry {
|
||||
return createAnnotation(this.id, key);
|
||||
}
|
||||
|
||||
reply() {
|
||||
return createReply(this.id);
|
||||
}
|
||||
|
||||
/** takes both remote event id and local txn id into account, see overriding in PendingEventEntry */
|
||||
isRelatedToId(id) {
|
||||
return id && this.relatedEventId === id;
|
||||
|
@ -29,6 +29,14 @@ export function createAnnotation(targetId, key) {
|
||||
};
|
||||
}
|
||||
|
||||
export function createReply(targetId) {
|
||||
return {
|
||||
"m.in_reply_to": {
|
||||
"event_id": targetId
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export function getRelationTarget(relation) {
|
||||
return relation.event_id || relation["m.in_reply_to"]?.event_id
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user