Check for timeline in pre-join UISI path

Somehow, live events can be missing a timeline, even though that should not
happen... This restores @uhoreg's previous version where we test for this case.

Fixes https://github.com/vector-im/riot-web/issues/12120
This commit is contained in:
J. Ryan Stinnett 2020-01-29 12:00:02 +00:00
parent fa1f2cd7e0
commit 336f623aa9

View file

@ -1171,17 +1171,27 @@ const TimelinePanel = createReactClass({
// get the user's membership at the last event by getting the timeline // get the user's membership at the last event by getting the timeline
// that the event belongs to, and traversing the timeline looking for // that the event belongs to, and traversing the timeline looking for
// that event, while keeping track of the user's membership // that event, while keeping track of the user's membership
const lastEvent = events[events.length - 1]; let i;
const timeline = room.getTimelineForEvent(lastEvent.getId()); let userMembership = "leave";
for (i = events.length - 1; i >= 0; i--) {
const timeline = room.getTimelineForEvent(events[i].getId());
if (!timeline) {
// Somehow, it seems to be possible for live events to not have
// a timeline, even though that should not happen. :(
// https://github.com/vector-im/riot-web/issues/12120
console.warn(
`Event ${events[i].getId()} in room ${room.roomId} is live, ` +
`but it does not have a timeline`,
);
continue;
}
const userMembershipEvent = const userMembershipEvent =
timeline.getState(EventTimeline.FORWARDS).getMember(userId); timeline.getState(EventTimeline.FORWARDS).getMember(userId);
let userMembership = userMembershipEvent userMembership = userMembershipEvent ? userMembershipEvent.membership : "leave";
? userMembershipEvent.membership : "leave";
const timelineEvents = timeline.getEvents(); const timelineEvents = timeline.getEvents();
for (let i = timelineEvents.length - 1; i >= 0; i--) { for (let j = timelineEvents.length - 1; j >= 0; j--) {
const event = timelineEvents[i]; const event = timelineEvents[j];
if (event.getId() === lastEvent.getId()) { if (event.getId() === events[i].getId()) {
// found the last event, so we can stop looking through the timeline
break; break;
} else if (event.getStateKey() === userId } else if (event.getStateKey() === userId
&& event.getType() === "m.room.member") { && event.getType() === "m.room.member") {
@ -1189,10 +1199,12 @@ const TimelinePanel = createReactClass({
userMembership = prevContent.membership || "leave"; userMembership = prevContent.membership || "leave";
} }
} }
break;
}
// now go through the events that we have and find the first undecryptable // now go through the rest of the events and find the first undecryptable
// one that was sent when the user wasn't in the room // one that was sent when the user wasn't in the room
for (let i = events.length - 1; i >= 0; i--) { for (; i >= 0; i--) {
const event = events[i]; const event = events[i];
if (event.getStateKey() === userId if (event.getStateKey() === userId
&& event.getType() === "m.room.member") { && event.getType() === "m.room.member") {