mirror of https://github.com/vector-im/riot-web
Tidy checkForPreJoinUISI and add some logging (#8567)
* Tidy checkForPreJoinUISI * Add some loggingpull/28788/head^2
parent
0951a766aa
commit
25428b0415
|
@ -1456,25 +1456,24 @@ class TimelinePanel extends React.Component<IProps, IState> {
|
||||||
* such events were found, then it returns 0.
|
* such events were found, then it returns 0.
|
||||||
*/
|
*/
|
||||||
private checkForPreJoinUISI(events: MatrixEvent[]): number {
|
private checkForPreJoinUISI(events: MatrixEvent[]): number {
|
||||||
|
const cli = MatrixClientPeg.get();
|
||||||
const room = this.props.timelineSet.room;
|
const room = this.props.timelineSet.room;
|
||||||
|
|
||||||
const isThreadTimeline = [TimelineRenderingType.Thread, TimelineRenderingType.ThreadsList]
|
const isThreadTimeline = [TimelineRenderingType.Thread, TimelineRenderingType.ThreadsList]
|
||||||
.includes(this.context.timelineRenderingType);
|
.includes(this.context.timelineRenderingType);
|
||||||
if (events.length === 0
|
if (events.length === 0 || !room || !cli.isRoomEncrypted(room.roomId) || isThreadTimeline) {
|
||||||
|| !room
|
logger.info("checkForPreJoinUISI: showing all messages, skipping check");
|
||||||
|| !MatrixClientPeg.get().isRoomEncrypted(room.roomId)
|
|
||||||
|| isThreadTimeline) {
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
const userId = MatrixClientPeg.get().credentials.userId;
|
const userId = cli.credentials.userId;
|
||||||
|
|
||||||
// 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
|
||||||
let i;
|
let i = events.length - 1;
|
||||||
let userMembership = "leave";
|
let userMembership = "leave";
|
||||||
for (i = events.length - 1; i >= 0; i--) {
|
for (; i >= 0; i--) {
|
||||||
const timeline = room.getTimelineForEvent(events[i].getId());
|
const timeline = room.getTimelineForEvent(events[i].getId());
|
||||||
if (!timeline) {
|
if (!timeline) {
|
||||||
// Somehow, it seems to be possible for live events to not have
|
// Somehow, it seems to be possible for live events to not have
|
||||||
|
@ -1486,18 +1485,15 @@ class TimelinePanel extends React.Component<IProps, IState> {
|
||||||
);
|
);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
const userMembershipEvent =
|
|
||||||
timeline.getState(EventTimeline.FORWARDS).getMember(userId);
|
userMembership = timeline.getState(EventTimeline.FORWARDS).getMember(userId)?.membership ?? "leave";
|
||||||
userMembership = userMembershipEvent ? userMembershipEvent.membership : "leave";
|
|
||||||
const timelineEvents = timeline.getEvents();
|
const timelineEvents = timeline.getEvents();
|
||||||
for (let j = timelineEvents.length - 1; j >= 0; j--) {
|
for (let j = timelineEvents.length - 1; j >= 0; j--) {
|
||||||
const event = timelineEvents[j];
|
const event = timelineEvents[j];
|
||||||
if (event.getId() === events[i].getId()) {
|
if (event.getId() === events[i].getId()) {
|
||||||
break;
|
break;
|
||||||
} else if (event.getStateKey() === userId
|
} else if (event.getStateKey() === userId && event.getType() === EventType.RoomMember) {
|
||||||
&& event.getType() === "m.room.member") {
|
userMembership = event.getPrevContent().membership || "leave";
|
||||||
const prevContent = event.getPrevContent();
|
|
||||||
userMembership = prevContent.membership || "leave";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -1507,19 +1503,18 @@ class TimelinePanel extends React.Component<IProps, IState> {
|
||||||
// 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 (; 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() === EventType.RoomMember) {
|
||||||
&& event.getType() === "m.room.member") {
|
userMembership = event.getPrevContent().membership || "leave";
|
||||||
const prevContent = event.getPrevContent();
|
} else if (userMembership === "leave" && (event.isDecryptionFailure() || event.isBeingDecrypted())) {
|
||||||
userMembership = prevContent.membership || "leave";
|
// reached an undecryptable message when the user wasn't in the room -- don't try to load any more
|
||||||
} else if (userMembership === "leave" &&
|
|
||||||
(event.isDecryptionFailure() || event.isBeingDecrypted())) {
|
|
||||||
// reached an undecryptable message when the user wasn't in
|
|
||||||
// the room -- don't try to load any more
|
|
||||||
// Note: for now, we assume that events that are being decrypted are
|
// Note: for now, we assume that events that are being decrypted are
|
||||||
// not decryptable
|
// not decryptable - we will be called once more when it is decrypted.
|
||||||
|
logger.info("checkForPreJoinUISI: reached a pre-join UISI at index ", i);
|
||||||
return i + 1;
|
return i + 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
logger.info("checkForPreJoinUISI: did not find pre-join UISI");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue