mirror of
https://github.com/vector-im/hydrogen-web.git
synced 2024-12-23 11:35:04 +01:00
Add initial draft of fresh-tile based replying
This commit is contained in:
parent
2169f68a7f
commit
8befef4d28
@ -6,14 +6,46 @@ export class ComposerViewModel extends ViewModel {
|
||||
this._roomVM = roomVM;
|
||||
this._isEmpty = true;
|
||||
this._replyVM = null;
|
||||
this._replySub = null;
|
||||
this._replyingToId = null;
|
||||
}
|
||||
|
||||
setReplyingTo(tile) {
|
||||
const changed = this._replyVM !== tile;
|
||||
this._replyVM = tile;
|
||||
if (changed) {
|
||||
this.emitChange("replyViewModel");
|
||||
setReplyingTo(id) {
|
||||
if (this._replyingToId === id) {
|
||||
return;
|
||||
}
|
||||
this._replyingToId = id;
|
||||
// Dispose of event subscription
|
||||
if (this._replySub) {
|
||||
this._replySub();
|
||||
this.untrack(this._replySub);
|
||||
}
|
||||
// replyVM may not be created yet even if subscribed.
|
||||
if (this._replyVM) {
|
||||
this._replyVM.dispose();
|
||||
}
|
||||
// Early return if we don't have an ID to reply to.
|
||||
if (!id) {
|
||||
this._replyVM = null;
|
||||
this._replySub = null;
|
||||
this.emitChange("replyViewModel");
|
||||
return;
|
||||
}
|
||||
const observable = this._roomVM._observeEvent(id);
|
||||
const entry = observable.get();
|
||||
if (entry) {
|
||||
this._replyVM = this._roomVM._createTile(entry);
|
||||
}
|
||||
this._replySub = observable.subscribe(entry => {
|
||||
if (!this._replyVM) {
|
||||
this._replyVM = this._roomVM._createTile(entry);
|
||||
} else {
|
||||
this._replyVM.updateEntry(entry);
|
||||
}
|
||||
this.emitChange("replyViewModel");
|
||||
});
|
||||
this.track(this._replySub);
|
||||
this.emitChange("replyViewModel");
|
||||
}
|
||||
|
||||
clearReplyingTo() {
|
||||
|
@ -306,11 +306,19 @@ export class RoomViewModel extends ViewModel {
|
||||
this.navigation.applyPath(path);
|
||||
}
|
||||
|
||||
startReply(entry) {
|
||||
startReply(id) {
|
||||
if (!this._room.isArchived) {
|
||||
this._composerVM.setReplyingTo(entry);
|
||||
this._composerVM.setReplyingTo(id);
|
||||
}
|
||||
}
|
||||
|
||||
_createTile(entry) {
|
||||
return this._tilesCreator(entry);
|
||||
}
|
||||
|
||||
_observeEvent(eventId) {
|
||||
return this._room.observeEvent(eventId);
|
||||
}
|
||||
}
|
||||
|
||||
function imageToInfo(image) {
|
||||
|
@ -107,7 +107,7 @@ export class BaseMessageTile extends SimpleTile {
|
||||
}
|
||||
|
||||
startReply() {
|
||||
this._roomVM.startReply(this);
|
||||
this._roomVM.startReply(this._entry.id);
|
||||
}
|
||||
|
||||
reply(msgtype, body, log = null) {
|
||||
|
Loading…
Reference in New Issue
Block a user