forked from mystiq/hydrogen-web
Add _replyTo field to ComposerViewModel that can be set from a message
This commit is contained in:
parent
13932bb480
commit
fdcafaf6d3
5 changed files with 30 additions and 2 deletions
|
@ -44,6 +44,7 @@ export class RoomViewModel extends ViewModel {
|
|||
const timeline = await this._room.openTimeline();
|
||||
const timelineVM = this.track(new TimelineViewModel(this.childOptions({
|
||||
room: this._room,
|
||||
roomVM: this,
|
||||
timeline,
|
||||
})));
|
||||
this._timelineVM = timelineVM;
|
||||
|
@ -294,12 +295,17 @@ export class RoomViewModel extends ViewModel {
|
|||
path = path.with(this.navigation.segment("details", true));
|
||||
this.navigation.applyPath(path);
|
||||
}
|
||||
|
||||
setReply(entry) {
|
||||
this._composerVM.setReply(entry);
|
||||
}
|
||||
}
|
||||
|
||||
class ComposerViewModel extends ViewModel {
|
||||
constructor(roomVM) {
|
||||
super();
|
||||
this._roomVM = roomVM;
|
||||
this._replyTo = null;
|
||||
this._isEmpty = true;
|
||||
}
|
||||
|
||||
|
@ -307,6 +313,19 @@ class ComposerViewModel extends ViewModel {
|
|||
return this._roomVM.isEncrypted;
|
||||
}
|
||||
|
||||
setReply(entry) {
|
||||
this._replyTo = entry;
|
||||
this.emitChange("replyTo");
|
||||
}
|
||||
|
||||
clearReply() {
|
||||
this.setReply(null);
|
||||
}
|
||||
|
||||
get replyTo() {
|
||||
return this._replyTo;
|
||||
}
|
||||
|
||||
sendMessage(message) {
|
||||
const success = this._roomVM._sendMessage(message);
|
||||
if (success) {
|
||||
|
|
|
@ -38,9 +38,9 @@ import {ViewModel} from "../../../ViewModel.js";
|
|||
export class TimelineViewModel extends ViewModel {
|
||||
constructor(options) {
|
||||
super(options);
|
||||
const {room, timeline} = options;
|
||||
const {room, timeline, roomVM} = options;
|
||||
this._timeline = this.track(timeline);
|
||||
this._tiles = new TilesCollection(timeline.entries, tilesCreator(this.childOptions({room, timeline})));
|
||||
this._tiles = new TilesCollection(timeline.entries, tilesCreator(this.childOptions({room, timeline, roomVM})));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -106,6 +106,10 @@ export class BaseMessageTile extends SimpleTile {
|
|||
return action;
|
||||
}
|
||||
|
||||
setReply() {
|
||||
this._roomVM.setReply(this._entry);
|
||||
}
|
||||
|
||||
redact(reason, log) {
|
||||
return this._room.sendRedaction(this._entry.id, reason, log);
|
||||
}
|
||||
|
|
|
@ -129,6 +129,10 @@ export class SimpleTile extends ViewModel {
|
|||
return this._options.room;
|
||||
}
|
||||
|
||||
get _roomVM() {
|
||||
return this._options.roomVM;
|
||||
}
|
||||
|
||||
get _timeline() {
|
||||
return this._options.timeline;
|
||||
}
|
||||
|
|
|
@ -113,6 +113,7 @@ export class BaseMessageView extends TemplateView {
|
|||
if (vm.canReact && vm.shape !== "redacted") {
|
||||
options.push(new QuickReactionsMenuOption(vm));
|
||||
}
|
||||
options.push(Menu.option(vm.i18n`Reply`, () => vm.setReply()));
|
||||
if (vm.canAbortSending) {
|
||||
options.push(Menu.option(vm.i18n`Cancel`, () => vm.abortSending()));
|
||||
} else if (vm.canRedact) {
|
||||
|
|
Loading…
Reference in a new issue