Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Fix link modal not shown after access upgrade #12411

Merged
merged 2 commits into from
Apr 12, 2024

Conversation

toger5
Copy link
Contributor

@toger5 toger5 commented Apr 11, 2024

We dont show the modal since there was a mistake in the isRoomJoinable function. It used a state variable instead of reacomputing the join rule with room.getJoinRule() The state is a captured variable that from before the link share click -> does not update at that time.

Checklist

  • Tests written for new code (and old code if feasible).
  • New or updated public/exported symbols have accurate TSDoc documentation.
  • Linter and other CI checks pass.
  • Sign-off given on the changes (see CONTRIBUTING.md).

Copy link
Member

@AndrewFerr AndrewFerr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I confirmed locally that this works.

Non-code requests:

  • Could the commit message get a line break between after the first line? Without it, the commit title includes the description (and results in a very long title in git log).
  • Could this be rebased on top of develop instead of merging with it? The merge makes the commit history a bit more confusing.

src/hooks/room/useGuestAccessInformation.ts Outdated Show resolved Hide resolved
@toger5 toger5 force-pushed the toger5/fix-link-modal-not-shown-after-access-upgrade branch from 89fe0c5 to 8803f1f Compare April 11, 2024 16:14
@toger5 toger5 requested a review from AndrewFerr April 11, 2024 16:14
We dont show the modal since there was a mistake in the isRoomJoinable function.
It used a state variable instead of reacomputing the join rule with room.getJoinRule()
The state is a captured variable that from before the link share click -> does not update at that time.
@toger5 toger5 force-pushed the toger5/fix-link-modal-not-shown-after-access-upgrade branch from 8803f1f to 7baa85a Compare April 11, 2024 16:17
@toger5
Copy link
Contributor Author

toger5 commented Apr 11, 2024

Could the commit message get a line break between after the first line? Without it, the commit title includes the description (and results in a very long title in git log).

That is interesting. I was displayed correctly in the github commit list. I tried with an actual empty newline inbetween... Maybe that works. Its still shown in my gitlog however. (Is there even a way to show only part of the message in git log)

Could this be rebased on top of develop instead of merging with it? The merge makes the commit history a bit more confusing.

Sure! We do still merge squash + merge in the react sdk? or did that change?

const isRoomJoinableFunction = (): boolean =>
room.getJoinRule() === JoinRule.Public || (joinRule === JoinRule.Knock && room.canInvite(room.myUserId));
const isRoomJoinableFunction = (): boolean => {
const joinRule = room.getJoinRule();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

aren't you now shadowing joinRule? If it's the same thing, shouldn't this be a callback that depends on the value of joinRule?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AIUI not shadowing the joinRule is what caused the bug this PR aims to fix.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes we need this to be computed on the fly.
This method is called from a callback that gets created when we show the first modal (asking to change permission rules)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right, but if it's a different variable, it should generally have a different name rather than shadowing a variable in a higher scope. Wouldn't having it as a dependency make react do the right thing?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right, but if it's a different variable, it should generally have a different name rather than shadowing a variable in a higher scope.

That is 100% correct. I see your point now.

I think having the stateVar here does not work because of this

    const shareClick = useCallback(() => {
        if (isRoomJoinable()) {
            showLinkModal();
        } else {
            // the room needs to be set to public or knock to generate a link
            Modal.createDialog(JoinRuleDialog, {
                room,
                // If the user cannot invite the Knocking is not given as an option.
                canInvite,
            }).finished.then(() => {
                if (isRoomJoinable()) showLinkModal();
            });
        }
    }, [isRoomJoinable, showLinkModal, room, canInvite]);

this line if (isRoomJoinable()) showLinkModal(); would not update the state variable even if it is a dependency since it would capture the variable while it is awaiting.

Copy link
Member

@dbkr dbkr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you :)

@toger5 toger5 enabled auto-merge April 12, 2024 13:27
@toger5 toger5 disabled auto-merge April 12, 2024 13:27
@toger5 toger5 enabled auto-merge April 12, 2024 13:27
@toger5 toger5 added this pull request to the merge queue Apr 12, 2024
Merged via the queue into develop with commit 313b556 Apr 12, 2024
22 checks passed
@toger5 toger5 deleted the toger5/fix-link-modal-not-shown-after-access-upgrade branch April 12, 2024 13:49
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
T-Defect Bugs, crashes, hangs, vulnerabilities, or other reported problems
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants