mirror of https://github.com/vector-im/riot-web
Remove welcome bot `welcome_user_id` support (#12153)
* Remove welcome bot `welcome_user_id` support Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Iterate Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * i18n Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Remove unused prop Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --------- Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>pull/28217/head
parent
86b3564b54
commit
9b5401dcec
|
@ -136,8 +136,6 @@ export interface IConfigOptions {
|
|||
admin_message_md: string; // message for how to contact the server owner when reporting an event
|
||||
};
|
||||
|
||||
welcome_user_id?: string;
|
||||
|
||||
room_directory?: {
|
||||
servers: string[];
|
||||
};
|
||||
|
|
|
@ -57,13 +57,12 @@ import "../../stores/LifecycleStore";
|
|||
import "../../stores/AutoRageshakeStore";
|
||||
import PageType from "../../PageTypes";
|
||||
import createRoom, { IOpts } from "../../createRoom";
|
||||
import { _t, _td, getCurrentLanguage } from "../../languageHandler";
|
||||
import { _t, _td } from "../../languageHandler";
|
||||
import SettingsStore from "../../settings/SettingsStore";
|
||||
import ThemeController from "../../settings/controllers/ThemeController";
|
||||
import { startAnyRegistrationFlow } from "../../Registration";
|
||||
import ResizeNotifier from "../../utils/ResizeNotifier";
|
||||
import AutoDiscoveryUtils from "../../utils/AutoDiscoveryUtils";
|
||||
import DMRoomMap from "../../utils/DMRoomMap";
|
||||
import ThemeWatcher from "../../settings/watchers/ThemeWatcher";
|
||||
import { FontWatcher } from "../../settings/watchers/FontWatcher";
|
||||
import { storeRoomAliasInCache } from "../../RoomAliasCache";
|
||||
|
@ -122,7 +121,6 @@ import { ViewHomePagePayload } from "../../dispatcher/payloads/ViewHomePagePaylo
|
|||
import { AfterLeaveRoomPayload } from "../../dispatcher/payloads/AfterLeaveRoomPayload";
|
||||
import { DoAfterSyncPreparedPayload } from "../../dispatcher/payloads/DoAfterSyncPreparedPayload";
|
||||
import { ViewStartChatOrReusePayload } from "../../dispatcher/payloads/ViewStartChatOrReusePayload";
|
||||
import { SnakedObject } from "../../utils/SnakedObject";
|
||||
import { leaveRoomBehaviour } from "../../utils/leave-behaviour";
|
||||
import { CallStore } from "../../stores/CallStore";
|
||||
import { IRoomStateEventsActionPayload } from "../../actions/MatrixActionCreators";
|
||||
|
@ -1138,30 +1136,13 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
|
|||
}
|
||||
|
||||
private chatCreateOrReuse(userId: string): void {
|
||||
const snakedConfig = new SnakedObject(this.props.config);
|
||||
// Use a deferred action to reshow the dialog once the user has registered
|
||||
if (MatrixClientPeg.safeGet().isGuest()) {
|
||||
// No point in making 2 DMs with welcome bot. This assumes view_set_mxid will
|
||||
// result in a new DM with the welcome user.
|
||||
if (userId !== snakedConfig.get("welcome_user_id")) {
|
||||
dis.dispatch<DoAfterSyncPreparedPayload<ViewStartChatOrReusePayload>>({
|
||||
action: Action.DoAfterSyncPrepared,
|
||||
deferred_action: {
|
||||
action: Action.ViewStartChatOrReuse,
|
||||
user_id: userId,
|
||||
},
|
||||
});
|
||||
}
|
||||
dis.dispatch({
|
||||
action: "require_registration",
|
||||
// If the set_mxid dialog is cancelled, view /welcome because if the
|
||||
// browser was pointing at /user/@someone:domain?action=chat, the URL
|
||||
// needs to be reset so that they can revisit /user/.. // (and trigger
|
||||
// `_chatCreateOrReuse` again)
|
||||
go_welcome_on_cancel: true,
|
||||
screen_after: {
|
||||
screen: `user/${snakedConfig.get("welcome_user_id")}`,
|
||||
params: { action: "chat" },
|
||||
dis.dispatch<DoAfterSyncPreparedPayload<ViewStartChatOrReusePayload>>({
|
||||
action: Action.DoAfterSyncPrepared,
|
||||
deferred_action: {
|
||||
action: Action.ViewStartChatOrReuse,
|
||||
user_id: userId,
|
||||
},
|
||||
});
|
||||
return;
|
||||
|
@ -1290,57 +1271,6 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts a chat with the welcome user, if the user doesn't already have one
|
||||
* @returns {string} The room ID of the new room, or null if no room was created
|
||||
*/
|
||||
private async startWelcomeUserChat(): Promise<string | null> {
|
||||
const snakedConfig = new SnakedObject(this.props.config);
|
||||
const welcomeUserId = snakedConfig.get("welcome_user_id");
|
||||
if (!welcomeUserId) return null;
|
||||
|
||||
// We can end up with multiple tabs post-registration where the user
|
||||
// might then end up with a session and we don't want them all making
|
||||
// a chat with the welcome user: try to de-dupe.
|
||||
// We need to wait for the first sync to complete for this to
|
||||
// work though.
|
||||
let waitFor: Promise<void>;
|
||||
if (!this.firstSyncComplete) {
|
||||
waitFor = this.firstSyncPromise.promise;
|
||||
} else {
|
||||
waitFor = Promise.resolve();
|
||||
}
|
||||
await waitFor;
|
||||
|
||||
const welcomeUserRooms = DMRoomMap.shared().getDMRoomsForUserId(welcomeUserId);
|
||||
if (welcomeUserRooms.length === 0) {
|
||||
const roomId = await createRoom(MatrixClientPeg.safeGet(), {
|
||||
dmUserId: snakedConfig.get("welcome_user_id"),
|
||||
// Only view the welcome user if we're NOT looking at a room
|
||||
andView: !this.state.currentRoomId,
|
||||
spinner: false, // we're already showing one: we don't need another one
|
||||
});
|
||||
// This is a bit of a hack, but since the deduplication relies
|
||||
// on m.direct being up to date, we need to force a sync
|
||||
// of the database, otherwise if the user goes to the other
|
||||
// tab before the next save happens (a few minutes), the
|
||||
// saved sync will be restored from the db and this code will
|
||||
// run without the update to m.direct, making another welcome
|
||||
// user room (it doesn't wait for new data from the server, just
|
||||
// the saved sync to be loaded).
|
||||
const saveWelcomeUser = (ev: MatrixEvent): void => {
|
||||
if (ev.getType() === EventType.Direct && ev.getContent()[welcomeUserId]) {
|
||||
MatrixClientPeg.safeGet().store.save(true);
|
||||
MatrixClientPeg.safeGet().removeListener(ClientEvent.AccountData, saveWelcomeUser);
|
||||
}
|
||||
};
|
||||
MatrixClientPeg.safeGet().on(ClientEvent.AccountData, saveWelcomeUser);
|
||||
|
||||
return roomId;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a new logged in session has started
|
||||
*/
|
||||
|
@ -1390,15 +1320,7 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
|
|||
} else if (MatrixClientPeg.currentUserIsJustRegistered()) {
|
||||
MatrixClientPeg.setJustRegisteredUserId(null);
|
||||
|
||||
const snakedConfig = new SnakedObject(this.props.config);
|
||||
if (snakedConfig.get("welcome_user_id") && getCurrentLanguage().startsWith("en")) {
|
||||
const welcomeUserRoom = await this.startWelcomeUserChat();
|
||||
if (welcomeUserRoom === null) {
|
||||
// We didn't redirect to the welcome user room, so show
|
||||
// the homepage.
|
||||
dis.dispatch<ViewHomePagePayload>({ action: Action.ViewHomePage, justRegistered: true });
|
||||
}
|
||||
} else if (ThreepidInviteStore.instance.pickBestInvite()) {
|
||||
if (ThreepidInviteStore.instance.pickBestInvite()) {
|
||||
// The user has a 3pid invite pending - show them that
|
||||
const threepidInvite = ThreepidInviteStore.instance.pickBestInvite();
|
||||
|
||||
|
|
|
@ -27,7 +27,6 @@ import { _t, _td } from "../../../languageHandler";
|
|||
import { MatrixClientPeg } from "../../../MatrixClientPeg";
|
||||
import { makeRoomPermalink, makeUserPermalink } from "../../../utils/permalinks/Permalinks";
|
||||
import DMRoomMap from "../../../utils/DMRoomMap";
|
||||
import SdkConfig from "../../../SdkConfig";
|
||||
import * as Email from "../../../email";
|
||||
import { getDefaultIdentityServerUrl, setToDefaultIdentityServer } from "../../../utils/IdentityServerUtils";
|
||||
import { buildActivityScores, buildMemberScores, compareMembers } from "../../../utils/SortMembers";
|
||||
|
@ -369,9 +368,6 @@ export default class InviteDialog extends React.PureComponent<Props, IInviteDial
|
|||
this.profilesStore = SdkContextClass.instance.userProfilesStore;
|
||||
|
||||
const excludedIds = new Set([MatrixClientPeg.safeGet().getUserId()!]);
|
||||
const welcomeUserId = SdkConfig.get("welcome_user_id");
|
||||
if (welcomeUserId) excludedIds.add(welcomeUserId);
|
||||
|
||||
if (isRoomInvite(props)) {
|
||||
const room = MatrixClientPeg.safeGet().getRoom(props.roomId);
|
||||
const isFederated = room?.currentState.getStateEvents(EventType.RoomCreate, "")?.getContent()["m.federate"];
|
||||
|
|
|
@ -189,7 +189,7 @@ export default class UserSettingsDialog extends React.Component<IProps, IState>
|
|||
UserTab.Help,
|
||||
_td("setting|help_about|title"),
|
||||
"mx_UserSettingsDialog_helpIcon",
|
||||
<HelpUserSettingsTab closeSettingsFn={() => this.props.onFinished()} />,
|
||||
<HelpUserSettingsTab />,
|
||||
"UserSettingsHelpAbout",
|
||||
),
|
||||
);
|
||||
|
|
|
@ -18,9 +18,8 @@ import React, { ReactNode } from "react";
|
|||
import { logger } from "matrix-js-sdk/src/logger";
|
||||
|
||||
import AccessibleButton from "../../../elements/AccessibleButton";
|
||||
import { _t, getCurrentLanguage } from "../../../../../languageHandler";
|
||||
import { _t } from "../../../../../languageHandler";
|
||||
import SdkConfig from "../../../../../SdkConfig";
|
||||
import createRoom from "../../../../../createRoom";
|
||||
import Modal from "../../../../../Modal";
|
||||
import PlatformPeg from "../../../../../PlatformPeg";
|
||||
import UpdateCheckButton from "../../UpdateCheckButton";
|
||||
|
@ -32,9 +31,7 @@ import SettingsSubsection, { SettingsSubsectionText } from "../../shared/Setting
|
|||
import ExternalLink from "../../../elements/ExternalLink";
|
||||
import MatrixClientContext from "../../../../../contexts/MatrixClientContext";
|
||||
|
||||
interface IProps {
|
||||
closeSettingsFn: () => void;
|
||||
}
|
||||
interface IProps {}
|
||||
|
||||
interface IState {
|
||||
appVersion: string | null;
|
||||
|
@ -96,14 +93,6 @@ export default class HelpUserSettingsTab extends React.Component<IProps, IState>
|
|||
Modal.createDialog(BugReportDialog, {});
|
||||
};
|
||||
|
||||
private onStartBotChat = (): void => {
|
||||
this.props.closeSettingsFn();
|
||||
createRoom(this.context, {
|
||||
dmUserId: SdkConfig.get("welcome_user_id"),
|
||||
andView: true,
|
||||
});
|
||||
};
|
||||
|
||||
private renderLegal(): ReactNode {
|
||||
const tocLinks = SdkConfig.get().terms_and_conditions_links;
|
||||
if (!tocLinks) return null;
|
||||
|
@ -224,7 +213,7 @@ export default class HelpUserSettingsTab extends React.Component<IProps, IState>
|
|||
public render(): React.ReactNode {
|
||||
const brand = SdkConfig.get().brand;
|
||||
|
||||
let faqText = _t(
|
||||
const faqText = _t(
|
||||
"setting|help_about|help_link",
|
||||
{
|
||||
brand,
|
||||
|
@ -233,34 +222,6 @@ export default class HelpUserSettingsTab extends React.Component<IProps, IState>
|
|||
a: (sub) => <ExternalLink href={SdkConfig.get("help_url")}>{sub}</ExternalLink>,
|
||||
},
|
||||
);
|
||||
if (SdkConfig.get("welcome_user_id") && getCurrentLanguage().startsWith("en")) {
|
||||
faqText = (
|
||||
<div>
|
||||
{_t(
|
||||
"setting|help_about|help_link_chat_bot",
|
||||
{
|
||||
brand,
|
||||
},
|
||||
{
|
||||
a: (sub) => (
|
||||
<ExternalLink
|
||||
href={SdkConfig.get("help_url")}
|
||||
rel="noreferrer noopener"
|
||||
target="_blank"
|
||||
>
|
||||
{sub}
|
||||
</ExternalLink>
|
||||
),
|
||||
},
|
||||
)}
|
||||
<div>
|
||||
<AccessibleButton onClick={this.onStartBotChat} kind="primary">
|
||||
{_t("setting|help_about|chat_bot", { brand })}
|
||||
</AccessibleButton>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
let updateButton: JSX.Element | undefined;
|
||||
if (this.state.canUpdate) {
|
||||
|
|
|
@ -2397,11 +2397,9 @@
|
|||
"help_about": {
|
||||
"access_token_detail": "Your access token gives full access to your account. Do not share it with anyone.",
|
||||
"brand_version": "%(brand)s version:",
|
||||
"chat_bot": "Chat with %(brand)s Bot",
|
||||
"clear_cache_reload": "Clear cache and reload",
|
||||
"crypto_version": "Crypto version:",
|
||||
"help_link": "For help with using %(brand)s, click <a>here</a>.",
|
||||
"help_link_chat_bot": "For help with using %(brand)s, click <a>here</a> or start a chat with our bot using the button below.",
|
||||
"homeserver": "Homeserver is <code>%(homeserverUrl)s</code>",
|
||||
"identity_server": "Identity server is <code>%(identityServerUrl)s</code>",
|
||||
"title": "Help & About",
|
||||
|
|
|
@ -479,7 +479,6 @@ describe("InviteDialog", () => {
|
|||
});
|
||||
|
||||
it("should not suggest users from other server when room has m.federate=false", async () => {
|
||||
SdkConfig.add({ welcome_user_id: "@bot:example.org" });
|
||||
room.currentState.setStateEvents([mkRoomCreateEvent(bobId, roomId, { "m.federate": false })]);
|
||||
|
||||
render(
|
||||
|
|
Loading…
Reference in New Issue