Skip to content

Commit

Permalink
Merge pull request #65 from verji/jts/fix-verji-onbaording
Browse files Browse the repository at this point in the history
Fix bug where Create DM with existing user returns empty room
  • Loading branch information
JohnSimonsen authored Jul 2, 2024
2 parents ebd2918 + 2f54c6f commit 1692afa
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions src/components/views/dialogs/InviteDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ limitations under the License.

import React, { createRef, ReactNode, SyntheticEvent } from "react";
import classNames from "classnames";
import { RoomMember, Room } from "matrix-js-sdk/src/matrix"; //VERJI remove: MatrixError, EventType
import { RoomMember, Room, EventType } from "matrix-js-sdk/src/matrix"; //VERJI remove: MatrixError, EventType
import { KnownMembership } from "matrix-js-sdk/src/types";
import { MatrixCall } from "matrix-js-sdk/src/webrtc/call";
import { logger } from "matrix-js-sdk/src/logger";
Expand Down Expand Up @@ -618,21 +618,24 @@ export default class InviteDialog extends React.PureComponent<Props, IInviteDial
this.setState({ busy: true });

let foundUser = false;
await MatrixClientPeg.get()
?.searchUserDirectory({ term: this.state.filterText.trim().split(":")[0] ?? this.state.filterText })
.then(async (r) => {
this.setState({ busy: false });
try {
await MatrixClientPeg.get()
?.searchUserDirectory({ term: this.state.filterText.trim().split(":")[0] ?? this.state.filterText })
.then(async (r) => {
this.setState({ busy: false });

if (r.results.find((e) => e.user_id == this.state.filterText.trim())) {
foundUser = true;
}
});
if (r.results.find((e) => e.user_id == this.state.filterText.trim())) {
foundUser = true;
}
});
} catch (error) {
console.error("Failed to searchUserDirectory: ", error);
}

const currentUserId: string | undefined = MatrixClientPeg.getCredentials()?.userId.trim();

if (currentUserId && currentUserId == this.state.filterText.trim()) {
this.setState({ busy: false });
return [] as Member[];
return [{ userId: currentUserId }] as Member[];
}

if (foundUser == false) {
Expand All @@ -643,7 +646,6 @@ export default class InviteDialog extends React.PureComponent<Props, IInviteDial
...this.state.serverResultsMixin,
...this.state.threepidResultsMixin,
];

const toAdd = [];
const potentialAddresses = this.state.filterText
.split(/[\s,]+/)
Expand All @@ -658,7 +660,7 @@ export default class InviteDialog extends React.PureComponent<Props, IInviteDial
}

if (!toAdd?.length || toAdd?.length == 0) {
return [] as Member[];
//return [] as Member[];
}
}
// Check to see if there's anything to convert first
Expand Down

0 comments on commit 1692afa

Please sign in to comment.