forked from mystiq/hydrogen-web
Add the ability to reply
This commit is contained in:
parent
800b4785d1
commit
46215b3c51
3 changed files with 20 additions and 4 deletions
|
@ -155,7 +155,7 @@ export class RoomViewModel extends ViewModel {
|
||||||
this._room.join();
|
this._room.join();
|
||||||
}
|
}
|
||||||
|
|
||||||
async _sendMessage(message) {
|
async _sendMessage(message, replyTo) {
|
||||||
if (!this._room.isArchived && message) {
|
if (!this._room.isArchived && message) {
|
||||||
try {
|
try {
|
||||||
let msgtype = "m.text";
|
let msgtype = "m.text";
|
||||||
|
@ -163,7 +163,11 @@ export class RoomViewModel extends ViewModel {
|
||||||
message = message.substr(4).trim();
|
message = message.substr(4).trim();
|
||||||
msgtype = "m.emote";
|
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) {
|
} 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;
|
||||||
|
@ -327,7 +331,7 @@ class ComposerViewModel extends ViewModel {
|
||||||
}
|
}
|
||||||
|
|
||||||
sendMessage(message) {
|
sendMessage(message) {
|
||||||
const success = this._roomVM._sendMessage(message);
|
const success = this._roomVM._sendMessage(message, this._replyTo);
|
||||||
if (success) {
|
if (success) {
|
||||||
this._isEmpty = true;
|
this._isEmpty = true;
|
||||||
this.emitChange("canSend");
|
this.emitChange("canSend");
|
||||||
|
|
|
@ -16,7 +16,7 @@ limitations under the License.
|
||||||
|
|
||||||
import {BaseEntry} from "./BaseEntry.js";
|
import {BaseEntry} from "./BaseEntry.js";
|
||||||
import {REDACTION_TYPE} from "../../common.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";
|
import {PendingAnnotation} from "../PendingAnnotation.js";
|
||||||
|
|
||||||
/** Deals mainly with local echo for relations and redactions,
|
/** Deals mainly with local echo for relations and redactions,
|
||||||
|
@ -151,6 +151,10 @@ export class BaseEventEntry extends BaseEntry {
|
||||||
return createAnnotation(this.id, key);
|
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 */
|
/** takes both remote event id and local txn id into account, see overriding in PendingEventEntry */
|
||||||
isRelatedToId(id) {
|
isRelatedToId(id) {
|
||||||
return id && this.relatedEventId === 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) {
|
export function getRelationTarget(relation) {
|
||||||
return relation.event_id || relation["m.in_reply_to"]?.event_id
|
return relation.event_id || relation["m.in_reply_to"]?.event_id
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue