forked from mystiq/hydrogen-web
hide sender name if previous message was by same sender
This commit is contained in:
parent
4a657b279d
commit
a09c3e7bed
4 changed files with 27 additions and 4 deletions
|
@ -95,8 +95,14 @@ export default class TilesCollection extends BaseObservableList {
|
||||||
|
|
||||||
const newTile = this._tileCreator(entry, this._emitSpontanousUpdate);
|
const newTile = this._tileCreator(entry, this._emitSpontanousUpdate);
|
||||||
if (newTile) {
|
if (newTile) {
|
||||||
prevTile && prevTile.updateNextSibling(newTile);
|
if (prevTile) {
|
||||||
nextTile && nextTile.updatePreviousSibling(newTile);
|
prevTile.updateNextSibling(newTile);
|
||||||
|
newTile.updatePreviousSibling(prevTile);
|
||||||
|
}
|
||||||
|
if (nextTile) {
|
||||||
|
newTile.updateNextSibling(nextTile);
|
||||||
|
nextTile.updatePreviousSibling(newTile);
|
||||||
|
}
|
||||||
this._tiles.splice(tileIdx, 0, newTile);
|
this._tiles.splice(tileIdx, 0, newTile);
|
||||||
this.emitAdd(tileIdx, newTile);
|
this.emitAdd(tileIdx, newTile);
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@ export default class MessageTile extends SimpleTile {
|
||||||
super(options);
|
super(options);
|
||||||
this._isOwn = this._entry.event.sender === options.ownUserId;
|
this._isOwn = this._entry.event.sender === options.ownUserId;
|
||||||
this._date = new Date(this._entry.event.origin_server_ts);
|
this._date = new Date(this._entry.event.origin_server_ts);
|
||||||
|
this._isContinuation = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
get shape() {
|
get shape() {
|
||||||
|
@ -28,8 +29,21 @@ export default class MessageTile extends SimpleTile {
|
||||||
return this._isOwn;
|
return this._isOwn;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get isContinuation() {
|
||||||
|
return this._isContinuation;
|
||||||
|
}
|
||||||
|
|
||||||
_getContent() {
|
_getContent() {
|
||||||
const event = this._entry.event;
|
const event = this._entry.event;
|
||||||
return event && event.content;
|
return event && event.content;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
updatePreviousSibling(prev) {
|
||||||
|
super.updatePreviousSibling(prev);
|
||||||
|
const isContinuation = prev && prev instanceof MessageTile && prev.sender === this.sender;
|
||||||
|
if (isContinuation !== this._isContinuation) {
|
||||||
|
this._isContinuation = isContinuation;
|
||||||
|
this.emitUpdate("isContinuation");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -125,7 +125,10 @@ export default class ListView {
|
||||||
}
|
}
|
||||||
|
|
||||||
onUpdate(i, value, params) {
|
onUpdate(i, value, params) {
|
||||||
this._childInstances[i].update(value, params);
|
if (this._childInstances) {
|
||||||
|
const instance = this._childInstances[i];
|
||||||
|
instance && instance.update(value, params);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onBeforeListChanged() {}
|
onBeforeListChanged() {}
|
||||||
|
|
|
@ -6,7 +6,7 @@ export default class TextMessageView extends TemplateView {
|
||||||
return t.li(
|
return t.li(
|
||||||
{className: {"TextMessageView": true, own: vm.isOwn}},
|
{className: {"TextMessageView": true, own: vm.isOwn}},
|
||||||
t.div({className: "message-container"}, [
|
t.div({className: "message-container"}, [
|
||||||
t.div({className: "sender"}, vm.sender),
|
t.div({className: "sender"}, vm => vm.isContinuation ? "" : vm.sender),
|
||||||
t.p([vm.text, t.time(vm.time)]),
|
t.p([vm.text, t.time(vm.time)]),
|
||||||
])
|
])
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in a new issue