Compare commits

..

No commits in common. "3664b4e57bcc6b8c3df18cc5fd2331821234324e" and "947702e9598656b3a74842230770801c14ad013c" have entirely different histories.

15 changed files with 40 additions and 60 deletions

View file

@ -1,6 +1,6 @@
import { getValue, getJsonValue } from '../common/environmentmanager';
import Logger from '../common/util/logger'; import Logger from '../common/util/logger';
import gateway from "./gateway/globalGatewayConnection"; import gateway from "./gateway/globalGatewayConnection";
import { getToken } from "./tokenManager";
const { log: authLog } = Logger([ 'Authenticator' ]); const { log: authLog } = Logger([ 'Authenticator' ]);
@ -10,5 +10,5 @@ export function login() {
authLog("Gateway connection already exists, tearing down existing one..."); authLog("Gateway connection already exists, tearing down existing one...");
gateway.ws.close(); gateway.ws.close();
} }
return gateway.connect(getValue("token"), getJsonValue("gatewayConnectionAttributes")); return gateway.connect(getToken());
}; };

View file

@ -55,13 +55,12 @@ const getOpcodeByName = (name) => {
class GatewayConnection { class GatewayConnection {
constructor(gatewayUrl, attributes) { constructor(gatewayUrl) {
this.attributes = attributes;
this.gatewayUrl = gatewayUrl; this.gatewayUrl = gatewayUrl;
} }
} }
GatewayConnection.prototype.connect = function(token) { GatewayConnection.prototype.connect = function(token, attributes=["PRESENCE_UPDATES"]) {
if (token) this.token = token; if (token) this.token = token;
if (this.token) token = this.token; if (this.token) token = this.token;
@ -91,7 +90,7 @@ GatewayConnection.prototype.connect = function(token) {
logGateway("Got HELLO", packet.data); logGateway("Got HELLO", packet.data);
this.helloData = packet.data; this.helloData = packet.data;
logGateway("Sending YOO"); logGateway("Sending YOO");
this.ws.send(this.packet("YOO", { token, attributes: this.attributes })); this.ws.send(this.packet("YOO", { token, attributes }));
break; break;
} }
case "EVENT_CHANNEL_MEMBERS": { case "EVENT_CHANNEL_MEMBERS": {

View file

@ -1,12 +1,12 @@
import GatewayConnection from './GatewayConnection'; import GatewayConnection from './GatewayConnection';
import config from '../../config';
import store from '../../common/store'; import store from '../../common/store';
import logger from '../../common/util/logger'; import logger from '../../common/util/logger';
import { getValue, getJsonValue } from '../../common/environmentmanager';
const { log } = logger(["globalGatewayConnection"]); const { log } = logger(["globalGatewayConnection"]);
const { warn: experimentsWarn } = logger(["globalGatewayConnection", "Experiments"]); const { warn: experimentsWarn } = logger(["globalGatewayConnection", "Experiments"]);
const globalGatewayConnection = new GatewayConnection(getValue("gatewayUrl"), getJsonValue("gatewayConnectionAttributes")); const globalGatewayConnection = new GatewayConnection(config.gatewayUrl);
let currentlyReconnecting = false; let currentlyReconnecting = false;
const wsCloseCodes = { const wsCloseCodes = {
@ -39,9 +39,9 @@ globalGatewayConnection.onopen = (sessionData) => {
store.dispatch({ type: 'authenticator/updatelocaluserobject', user: sessionData.user }); store.dispatch({ type: 'authenticator/updatelocaluserobject', user: sessionData.user });
store.dispatch({ type: 'channels/updatechannellist', channels: sessionData.channels }); store.dispatch({ type: 'channels/updatechannellist', channels: sessionData.channels });
if (getValue("enableExperimentOverrides")) { if (localStorage.getItem("enableExperimentOverrides")) {
experimentsWarn("Experiment overrides are enabled"); experimentsWarn("Experiment overrides are enabled");
const experimentModifiers = JSON.parse(getValue("experimentOverrides")); const experimentModifiers = JSON.parse(localStorage.getItem("experimentOverrides"));
const experiments = { const experiments = {
...sessionData.__global_experiments || {}, ...sessionData.__global_experiments || {},
...experimentModifiers || {} ...experimentModifiers || {}

View file

@ -1,4 +1,5 @@
import { getValue } from '../common/environmentmanager'; import config from '../config';
import { getToken } from "./tokenManager";
export async function unauthenticated(endpoint, options) { export async function unauthenticated(endpoint, options) {
let res; let res;
@ -10,7 +11,7 @@ export async function unauthenticated(endpoint, options) {
if (!options.headers) options.headers = {}; if (!options.headers) options.headers = {};
try { try {
res = await fetch(`${getValue("apiUrl")}${endpoint}`, options); res = await fetch(`${config.apiUrl}${endpoint}`, options);
json = await res.json(); json = await res.json();
isOK = true; isOK = true;
} catch(e) { } catch(e) {
@ -37,12 +38,12 @@ export async function authenticated(endpoint, options) {
if (!options.headers) options.headers = {}; if (!options.headers) options.headers = {};
options.headers = { options.headers = {
"Authorization": getValue("token"), "Authorization": getToken(),
...options.headers ...options.headers
}; };
try { try {
res = await fetch(`${getValue("apiUrl")}${endpoint}`, options); res = await fetch(`${config.apiUrl}${endpoint}`, options);
json = await res.json(); json = await res.json();
isOK = true; isOK = true;
} catch(e) { } catch(e) {

7
src/api/tokenManager.js Normal file
View file

@ -0,0 +1,7 @@
export function getToken() {
return localStorage.getItem("token");
};
export function setToken(token) {
localStorage.setItem("token", token);
};

View file

@ -1,26 +0,0 @@
export function getValue(key) {
return localStorage.getItem(key);
};
export function setValue(key, value) {
if (typeof value === "object") {
value = JSON.stringify(value);
}
return localStorage.setItem(key, value);
};
export function getJsonValue(key) {
return JSON.parse(getValue(key));
}
export function setValueIfNull(key, value) {
if (getValue(key)) return false;
setValue(key, value);
return true;
};
export default function applyDefaultsObject(defaultsObject) {
for (const [key, value] of Object.entries(defaultsObject)) {
setValueIfNull(key, value);
}
};

View file

@ -3,7 +3,7 @@ import UserProfileLink from './user/UserProfileLink';
export default function Message({ message, hideUsername }) { export default function Message({ message, hideUsername }) {
return ( return (
<div className="message"> <div className="message">
<UserProfileLink bold={true} size="0" user={ message.author } hideName={ hideUsername } /> <UserProfileLink size="0" user={ message.author } hideName={ hideUsername } />
<span className="message-content">{ message.content }</span> <span className="message-content">{ message.content }</span>
</div> </div>
); );

View file

@ -4,8 +4,8 @@ import { useHistory } from 'react-router-dom';
import Notification from '../Notification'; import Notification from '../Notification';
import { unauthenticated } from '../../api/request'; import { unauthenticated } from '../../api/request';
import { login } from '../../api/authenticator'; import { login } from '../../api/authenticator';
import { setToken } from "../../api/tokenManager";
import { getLoginMessageFromError } from '../../common/util/errors' import { getLoginMessageFromError } from '../../common/util/errors'
import { setValue } from '../../common/environmentmanager';
export default function Login() { export default function Login() {
const history = useHistory(); const history = useHistory();
@ -42,7 +42,7 @@ export default function Login() {
return; return;
} }
setValue("token", json.token); setToken(json.token);
await login(); await login();
history.push('/'); history.push('/');

View file

@ -14,7 +14,6 @@ export default function ChannelCreateButton() {
const handleClose = () => { const handleClose = () => {
setIsDialogOpen(false); setIsDialogOpen(false);
setInfo(null); setInfo(null);
setChannelNameInput("");
}; };
const createChannel = async () => { const createChannel = async () => {

View file

@ -1,4 +1,4 @@
export default function UserProfileLink({ user, size, bold }) { export default function UserProfileLink({ user, size }) {
let picture = null; let picture = null;
if (size !== "0") { if (size !== "0") {
@ -11,7 +11,7 @@ export default function UserProfileLink({ user, size, bold }) {
return ( return (
<div className="profile-link"> <div className="profile-link">
{ picture } { picture }
<span className={`profile-username${bold ? "-bold" : ""}`}>{ user.username }</span> <span className="profile-username">{ user.username }</span>
</div> </div>
); );
}; };

View file

@ -1,7 +1,6 @@
const config = { const config = {
apiUrl: "http://localhost:3000", apiUrl: 'http://localhost:3000',
gatewayUrl: "ws://localhost:3005/gateway", gatewayUrl: 'ws://localhost:3005/gateway'
gatewayConnectionAttributes: ["PRESENCE_UPDATES"]
}; };
export default config; export default config;

View file

@ -1,14 +1,10 @@
import store from './common/store'; import store from './common/store';
import config from "./config";
import App from './components/main/App'; import App from './components/main/App';
import React from 'react'; import React from 'react';
import ReactDOM from 'react-dom'; import ReactDOM from 'react-dom';
import { Provider } from 'react-redux'; import { Provider } from 'react-redux';
import { LazyMotion, domAnimation } from "framer-motion" import { LazyMotion, domAnimation } from "framer-motion"
import applyDefaultsObject from './common/environmentmanager';
applyDefaultsObject(config);
ReactDOM.render( ReactDOM.render(
<React.StrictMode> <React.StrictMode>
@ -19,4 +15,4 @@ ReactDOM.render(
</Provider> </Provider>
</React.StrictMode>, </React.StrictMode>,
document.getElementById('root') document.getElementById('root')
); );

View file

@ -19,6 +19,14 @@
background: var(--default-scrollbar-color); background: var(--default-scrollbar-color);
} }
@font-face {
font-family: 'JetBrains Mono';
src: url('https://raw.githubusercontent.com/JetBrains/JetBrainsMono/master/fonts/webfonts/JetBrainsMono-Regular.woff2') format('woff2'),
url('https://raw.githubusercontent.com/JetBrains/JetBrainsMono/master/fonts/ttf/JetBrainsMono-Regular.ttf') format('truetype');
font-weight: normal;
font-style: normal;
}
body { body {
color: var(--default-text-color); color: var(--default-text-color);
background-color: var(--background-color); background-color: var(--background-color);

View file

@ -72,12 +72,9 @@
} }
.profile-username { .profile-username {
line-height: 1.256rem;
}
.profile-username-bold {
@extend .profile-username;
font-weight: 600; font-weight: 600;
font-size: 1rem;
line-height: 1.256rem;
} }
.darker-text { .darker-text {

View file

@ -5,7 +5,7 @@
--default-text-color: hsl(0, 0%, 80%); --default-text-color: hsl(0, 0%, 80%);
--darker-text-color: hsl(0, 0%, 65%); --darker-text-color: hsl(0, 0%, 65%);
--default-font-family: "Noto Sans", "Liberation Sans", sans-serif; --default-font-family: JetBrains Mono;
--glyph-font-family: Noto Sans,-apple-system,BlinkMacSystemFont,sans-serif; --glyph-font-family: Noto Sans,-apple-system,BlinkMacSystemFont,sans-serif;
--default-user-background: linear-gradient( --default-user-background: linear-gradient(