feat: add way to autoregister with env variables

pull/2963/head
Audric Ackermann 1 year ago
parent 8d0bd84ef0
commit 5d467fd205

@ -341,7 +341,7 @@
"leaveAndRemoveForEveryone": "Leave Group and Remove for Everyone", "leaveAndRemoveForEveryone": "Leave Group and Remove for Everyone",
"leaveGroupConfirmation": "Are you sure you want to leave <b>$name$</b>?", "leaveGroupConfirmation": "Are you sure you want to leave <b>$name$</b>?",
"leaveGroupConfirmationAdmin": "As you are the admin of this group, if you leave it it will be removed for every current members. Are you sure you want to leave this group?", "leaveGroupConfirmationAdmin": "As you are the admin of this group, if you leave it it will be removed for every current members. Are you sure you want to leave this group?",
"leaveGroupConrirmationOnlyAdminLegacy": "Are you sure you want to leave <b>$name$</b>? This will deactivate the group for all members.", "leaveGroupConrirmationOnlyAdminLegacy": "Because you are the creator of this group it will be deleted for everyone. This cannot be undone.",
"leaveGroupConfirmationOnlyAdmin": "You are the only admin in <b>$name$</b>", "leaveGroupConfirmationOnlyAdmin": "You are the only admin in <b>$name$</b>",
"leaveGroupConfirmationOnlyAdminWarning": "Group settings and members cannot be changed without an admin", "leaveGroupConfirmationOnlyAdminWarning": "Group settings and members cannot be changed without an admin",
"leaveGroupFailed": "Failed to leave Group!", "leaveGroupFailed": "Failed to leave Group!",
@ -484,7 +484,7 @@
"closedGroupInviteSuccessMessage": "Successfully invited group members", "closedGroupInviteSuccessMessage": "Successfully invited group members",
"notificationForConvo": "Notifications", "notificationForConvo": "Notifications",
"notificationForConvo_all": "All", "notificationForConvo_all": "All",
"notificationForConvo_disabled": "Disabled", "notificationForConvo_disabled": "Mute",
"notificationForConvo_mentions_only": "Mentions only", "notificationForConvo_mentions_only": "Mentions only",
"onionPathIndicatorTitle": "Path", "onionPathIndicatorTitle": "Path",
"onionPathIndicatorDescription": "Session hides your IP by bouncing your messages through several Service Nodes in Session's decentralized network. These are the countries your connection is currently being bounced through:", "onionPathIndicatorDescription": "Session hides your IP by bouncing your messages through several Service Nodes in Session's decentralized network. These are the countries your connection is currently being bounced through:",
@ -582,7 +582,7 @@
"mustBeApproved": "This conversation must be accepted to use this feature", "mustBeApproved": "This conversation must be accepted to use this feature",
"youHaveANewFriendRequest": "You have a new friend request", "youHaveANewFriendRequest": "You have a new friend request",
"clearAllConfirmationTitle": "Clear All Message Requests", "clearAllConfirmationTitle": "Clear All Message Requests",
"clearAllConfirmationBody": "Are you sure you want to clear all message requests?", "clearAllConfirmationBody": "Are you sure you want to clear all message and group requests?",
"thereAreNoMessagesIn": "There are no messages in <b>$name$</b>.", "thereAreNoMessagesIn": "There are no messages in <b>$name$</b>.",
"noMessagesInBlindedDisabledMsgRequests": "<b>$name$</b> has message requests from Community conversations turned off, so you cannot send them a message.", "noMessagesInBlindedDisabledMsgRequests": "<b>$name$</b> has message requests from Community conversations turned off, so you cannot send them a message.",
"noMessagesInNoteToSelf": "You have no messages in <b>$name$</b>.", "noMessagesInNoteToSelf": "You have no messages in <b>$name$</b>.",

@ -199,7 +199,7 @@ const ResendInviteButton = ({
buttonType={SessionButtonType.Solid} buttonType={SessionButtonType.Solid}
text={window.i18n('resend')} text={window.i18n('resend')}
onClick={() => { onClick={() => {
void GroupInvite.addJob({ groupPk, member: pubkey }); void GroupInvite.addJob({ groupPk, member: pubkey }); // TODO audric: do we need to take care if that user was invited withHistory or not
}} }}
/> />
); );

@ -2,7 +2,7 @@ import React, { useState } from 'react';
import useKey from 'react-use/lib/useKey'; import useKey from 'react-use/lib/useKey';
import { PubkeyType } from 'libsession_util_nodejs'; import { PubkeyType } from 'libsession_util_nodejs';
import _ from 'lodash'; import _, { difference, uniq } from 'lodash';
import { useDispatch } from 'react-redux'; import { useDispatch } from 'react-redux';
import { ConversationTypeEnum } from '../../models/conversationAttributes'; import { ConversationTypeEnum } from '../../models/conversationAttributes';
import { VALIDATION } from '../../session/constants'; import { VALIDATION } from '../../session/constants';
@ -114,15 +114,14 @@ const InviteContactsDialogInner = (props: Props) => {
const { conversationId } = props; const { conversationId } = props;
const dispatch = useDispatch(); const dispatch = useDispatch();
const privateContactPubkeys = useContactsToInviteToGroup(); const privateContactPubkeys = useContactsToInviteToGroup() as Array<PubkeyType>;
let validContactsForInvite = _.clone(privateContactPubkeys) as Array<PubkeyType>;
const isProcessingUIChange = useMemberGroupChangePending(); const isProcessingUIChange = useMemberGroupChangePending();
const isPrivate = useIsPrivate(conversationId); const isPrivate = useIsPrivate(conversationId);
const isPublic = useIsPublic(conversationId); const isPublic = useIsPublic(conversationId);
const membersFromRedux = useSortedGroupMembers(conversationId); const membersFromRedux = useSortedGroupMembers(conversationId) || [];
const zombiesFromRedux = useZombies(conversationId); const zombiesFromRedux = useZombies(conversationId) || [];
const displayName = useConversationUsername(conversationId); const displayName = useConversationUsername(conversationId);
const isGroupV2 = useSelectedIsGroupV2(); const isGroupV2 = useSelectedIsGroupV2();
const [shareHistory, setShareHistory] = useState(false); const [shareHistory, setShareHistory] = useState(false);
@ -132,14 +131,12 @@ const InviteContactsDialogInner = (props: Props) => {
if (isPrivate) { if (isPrivate) {
throw new Error('InviteContactsDialogInner must be a group'); throw new Error('InviteContactsDialogInner must be a group');
} }
if (!isPublic) { const zombiesAndMembers = uniq([...membersFromRedux, ...zombiesFromRedux]);
// filter our zombies and current members from the list of contact we can add // filter our zombies and current members from the list of contact we can add
const members = membersFromRedux || [];
const zombies = zombiesFromRedux || []; const validContactsForInvite = isPublic
validContactsForInvite = validContactsForInvite.filter( ? privateContactPubkeys
d => !members.includes(d) && !zombies.includes(d) : difference(privateContactPubkeys, zombiesAndMembers);
);
}
const chatName = displayName || window.i18n('unknown'); const chatName = displayName || window.i18n('unknown');

@ -1,14 +1,40 @@
import classNames from 'classnames'; import classNames from 'classnames';
import React from 'react'; import React from 'react';
import useTimeoutFn from 'react-use/lib/useTimeoutFn';
import { MAX_USERNAME_BYTES } from '../../session/constants'; import { MAX_USERNAME_BYTES } from '../../session/constants';
import { isAutoLogin, isDevProd } from '../../shared/env_vars';
import { SessionInput } from '../basic/SessionInput'; import { SessionInput } from '../basic/SessionInput';
const DisplayNameInput = (props: { type DisplayNameProps = {
stealAutoFocus?: boolean; stealAutoFocus?: boolean;
displayName: string; displayName: string;
onDisplayNameChanged: (val: string) => any; onDisplayNameChanged: (val: string) => any;
handlePressEnter: () => any; handlePressEnter: () => any;
}) => { };
/**
* Can only be used with yarn start-prod. Auto creates a user with the NODE_APP_INSTANCE as username
*/
function useAutoRegister(props: DisplayNameProps) {
useTimeoutFn(() => {
if (isDevProd() && isAutoLogin() && !props.displayName) {
if (!process.env.NODE_APP_INSTANCE) {
throw new Error('NODE_APP_INSTANCE empty but devprod is true');
}
props.onDisplayNameChanged(process.env.NODE_APP_INSTANCE.replace('devprod', ''));
}
}, 100);
useTimeoutFn(() => {
if (isDevProd() && props.displayName) {
props.handlePressEnter();
}
}, 200);
}
const DisplayNameInput = (props: DisplayNameProps) => {
useAutoRegister(props);
return ( return (
<SessionInput <SessionInput
autoFocus={props.stealAutoFocus || false} autoFocus={props.stealAutoFocus || false}

@ -1,13 +1,15 @@
import React, { useContext, useEffect, useState } from 'react'; import React, { useContext, useEffect, useState } from 'react';
import useTimeoutFn from 'react-use/lib/useTimeoutFn';
import { isAutoLogin, isDevProd } from '../../shared/env_vars';
import { Noop } from '../../types/Util';
import { Flex } from '../basic/Flex'; import { Flex } from '../basic/Flex';
import { SessionButton } from '../basic/SessionButton'; import { SessionButton } from '../basic/SessionButton';
import { SessionIdEditable } from '../basic/SessionIdEditable'; import { SessionIdEditable } from '../basic/SessionIdEditable';
import { SessionIconButton } from '../icon'; import { SessionIconButton } from '../icon';
import { RegistrationContext, RegistrationPhase, signUp } from './RegistrationStages'; import { RegistrationContext, RegistrationPhase, signUp } from './RegistrationStages';
import { RegistrationUserDetails } from './RegistrationUserDetails'; import { RegistrationUserDetails } from './RegistrationUserDetails';
import { sanitizeDisplayNameOrToast, SignInMode } from './SignInTab'; import { SignInMode, sanitizeDisplayNameOrToast } from './SignInTab';
import { TermsAndConditions } from './TermsAndConditions'; import { TermsAndConditions } from './TermsAndConditions';
import { Noop } from '../../types/Util';
export enum SignUpMode { export enum SignUpMode {
Default, Default,
@ -19,8 +21,17 @@ const CreateSessionIdButton = ({ createSessionID }: { createSessionID: any }) =>
return <SessionButton onClick={createSessionID} text={window.i18n('createSessionID')} />; return <SessionButton onClick={createSessionID} text={window.i18n('createSessionID')} />;
}; };
const ContinueSignUpButton = ({ continueSignUp }: { continueSignUp: any }) => { function useAutoContinue(props: { continueSignUp: () => void }) {
return <SessionButton onClick={continueSignUp} text={window.i18n('continue')} />; useTimeoutFn(() => {
if (isDevProd() && isAutoLogin()) {
props.continueSignUp();
}
}, 100);
}
const ContinueSignUpButton = (props: { continueSignUp: () => void }) => {
useAutoContinue(props);
return <SessionButton onClick={props.continueSignUp} text={window.i18n('continue')} />;
}; };
const SignUpDefault = (props: { createSessionID: Noop }) => { const SignUpDefault = (props: { createSessionID: Noop }) => {

@ -152,7 +152,11 @@ export async function declineConversationWithoutConfirm({
// Note: do not set the active_at undefined as this would make that conversation not synced with the libsession wrapper // Note: do not set the active_at undefined as this would make that conversation not synced with the libsession wrapper
await conversationToDecline.setIsApproved(false, false); await conversationToDecline.setIsApproved(false, false);
await conversationToDecline.setDidApproveMe(false, false); await conversationToDecline.setDidApproveMe(false, false);
await conversationToDecline.setOriginConversationID('', false);
if (conversationToDecline.isClosedGroupV2()) {
// this can only be done for groupv2 convos
await conversationToDecline.setOriginConversationID('', false);
}
// this will update the value in the wrapper if needed but not remove the entry if we want it gone. The remove is done below with removeContactFromWrapper // this will update the value in the wrapper if needed but not remove the entry if we want it gone. The remove is done below with removeContactFromWrapper
await conversationToDecline.commit(); await conversationToDecline.commit();
if (alsoBlock) { if (alsoBlock) {

@ -8,9 +8,15 @@ function envAppInstanceIncludes(prefix: string) {
export function isDevProd() { export function isDevProd() {
return envAppInstanceIncludes('devprod'); return envAppInstanceIncludes('devprod');
} }
export function isAutoLogin() {
return !!process.env.SESSION_AUTO_REGISTER;
}
export function isTestNet() { export function isTestNet() {
return envAppInstanceIncludes('testnet'); return envAppInstanceIncludes('testnet');
} }
export function isTestIntegration() { export function isTestIntegration() {
return envAppInstanceIncludes('test-integration'); return envAppInstanceIncludes('test-integration');
} }

Loading…
Cancel
Save