Add initial draft of fresh-tile based replying

This commit is contained in:
Danila Fedorin 2021-08-04 11:57:06 -07:00
parent 2169f68a7f
commit 8befef4d28
3 changed files with 48 additions and 8 deletions

View file

@ -6,14 +6,46 @@ export class ComposerViewModel extends ViewModel {
this._roomVM = roomVM; this._roomVM = roomVM;
this._isEmpty = true; this._isEmpty = true;
this._replyVM = null; this._replyVM = null;
this._replySub = null;
this._replyingToId = null;
} }
setReplyingTo(tile) { setReplyingTo(id) {
const changed = this._replyVM !== tile; if (this._replyingToId === id) {
this._replyVM = tile; return;
if (changed) {
this.emitChange("replyViewModel");
} }
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() { clearReplyingTo() {

View file

@ -306,11 +306,19 @@ export class RoomViewModel extends ViewModel {
this.navigation.applyPath(path); this.navigation.applyPath(path);
} }
startReply(entry) { startReply(id) {
if (!this._room.isArchived) { 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) { function imageToInfo(image) {

View file

@ -107,7 +107,7 @@ export class BaseMessageTile extends SimpleTile {
} }
startReply() { startReply() {
this._roomVM.startReply(this); this._roomVM.startReply(this._entry.id);
} }
reply(msgtype, body, log = null) { reply(msgtype, body, log = null) {