re-order ReplyThread methods for readability
Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
This commit is contained in:
parent
f0bd4a54e7
commit
11ae0805b0
1 changed files with 37 additions and 37 deletions
|
@ -59,43 +59,6 @@ export default class ReplyThread extends React.Component {
|
||||||
this.collapse = this.collapse.bind(this);
|
this.collapse = this.collapse.bind(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
async initialize() {
|
|
||||||
const {parentEv} = this.props;
|
|
||||||
// at time of making this component we checked that props.parentEv has a parentEventId
|
|
||||||
const ev = await ReplyThread.getEvent(this.room, ReplyThread.getParentEventId(parentEv));
|
|
||||||
if (this.unmounted) return;
|
|
||||||
|
|
||||||
if (ev) {
|
|
||||||
this.setState({
|
|
||||||
events: [ev],
|
|
||||||
}, this.loadNextEvent);
|
|
||||||
} else {
|
|
||||||
this.setState({err: true});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async loadNextEvent() {
|
|
||||||
if (this.unmounted) return;
|
|
||||||
const ev = this.state.events[0];
|
|
||||||
const inReplyToEventId = ReplyThread.getParentEventId(ev);
|
|
||||||
|
|
||||||
if (!inReplyToEventId) {
|
|
||||||
this.setState({
|
|
||||||
loading: false,
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const loadedEv = await ReplyThread.getEvent(this.room, inReplyToEventId);
|
|
||||||
if (this.unmounted) return;
|
|
||||||
|
|
||||||
if (loadedEv) {
|
|
||||||
this.setState({loadedEv});
|
|
||||||
} else {
|
|
||||||
this.setState({err: true});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static async getEvent(room, eventId) {
|
static async getEvent(room, eventId) {
|
||||||
const event = room.findEventById(eventId);
|
const event = room.findEventById(eventId);
|
||||||
if (event) return event;
|
if (event) return event;
|
||||||
|
@ -233,6 +196,43 @@ export default class ReplyThread extends React.Component {
|
||||||
this.unmounted = true;
|
this.unmounted = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async initialize() {
|
||||||
|
const {parentEv} = this.props;
|
||||||
|
// at time of making this component we checked that props.parentEv has a parentEventId
|
||||||
|
const ev = await ReplyThread.getEvent(this.room, ReplyThread.getParentEventId(parentEv));
|
||||||
|
if (this.unmounted) return;
|
||||||
|
|
||||||
|
if (ev) {
|
||||||
|
this.setState({
|
||||||
|
events: [ev],
|
||||||
|
}, this.loadNextEvent);
|
||||||
|
} else {
|
||||||
|
this.setState({err: true});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async loadNextEvent() {
|
||||||
|
if (this.unmounted) return;
|
||||||
|
const ev = this.state.events[0];
|
||||||
|
const inReplyToEventId = ReplyThread.getParentEventId(ev);
|
||||||
|
|
||||||
|
if (!inReplyToEventId) {
|
||||||
|
this.setState({
|
||||||
|
loading: false,
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const loadedEv = await ReplyThread.getEvent(this.room, inReplyToEventId);
|
||||||
|
if (this.unmounted) return;
|
||||||
|
|
||||||
|
if (loadedEv) {
|
||||||
|
this.setState({loadedEv});
|
||||||
|
} else {
|
||||||
|
this.setState({err: true});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
canCollapse() {
|
canCollapse() {
|
||||||
return this.state.events.length > 1;
|
return this.state.events.length > 1;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue