Compare commits
No commits in common. "5eb1c2d0ae66e27a4c2461b2a7d700bf14a39599" and "2b929bfd15f806674726aff0852e50f6ee29156f" have entirely different histories.
5eb1c2d0ae
...
2b929bfd15
19 changed files with 59 additions and 103 deletions
|
@ -1,10 +1,14 @@
|
|||
import Logger from '../common/util/logger';
|
||||
import Logger from '../common/util/Logger';
|
||||
import gateway from "./gateway/globalGatewayConnection";
|
||||
import { getToken } from "./tokenManager";
|
||||
import token from "./tokenManager";
|
||||
|
||||
const { log: authLog } = Logger([ 'Authenticator' ]);
|
||||
|
||||
export function login() {
|
||||
const Authenticator = {
|
||||
login: async function() {
|
||||
authLog('Logging in through gateway...');
|
||||
return gateway.connect(getToken());
|
||||
return gateway.connect(token.getToken());
|
||||
}
|
||||
};
|
||||
|
||||
export default Authenticator;
|
|
@ -1,4 +1,4 @@
|
|||
import logger from "../../common/util/logger";
|
||||
import logger from "../../common/util/Logger";
|
||||
|
||||
const { log: logGateway } = logger([ "Gateway" ]);
|
||||
const { log: logRtc } = logger([ "Gateway", "RTC" ]);
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import GatewayConnection from './GatewayConnection';
|
||||
import config from '../../config';
|
||||
import store from '../../common/store';
|
||||
import logger from '../../common/util/logger';
|
||||
import logger from '../../common/util/Logger';
|
||||
|
||||
const { log } = logger(["globalGatewayConnection"]);
|
||||
const { warn: experimentsWarn } = logger(["globalGatewayConnection", "Experiments"]);
|
||||
|
@ -18,7 +18,6 @@ const wsCloseCodes = {
|
|||
NOT_AUTHORIZED: [4006, "Not authorized"],
|
||||
FLOODING: [4007, "Flooding"],
|
||||
NO_PING: [4008, "No ping"],
|
||||
UNSUPPORTED_ATTRIBUTE: [4009, "Unsupported attribute."],
|
||||
};
|
||||
const cancelReconnectionForCodes = [
|
||||
wsCloseCodes.NOT_AUTHENTICATED[0],
|
||||
|
@ -26,7 +25,6 @@ const cancelReconnectionForCodes = [
|
|||
wsCloseCodes.SERVER_DENIED_CONNECTION[0],
|
||||
wsCloseCodes.TOO_MANY_SESSIONS[0],
|
||||
wsCloseCodes.FLOODING[0],
|
||||
wsCloseCodes.UNSUPPORTED_ATTRIBUTE[0],
|
||||
];
|
||||
|
||||
globalGatewayConnection.onopen = (sessionData) => {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import config from '../config';
|
||||
import { getToken } from "./tokenManager";
|
||||
import token from "./tokenManager";
|
||||
|
||||
export async function APIRequest(endpoint, options) {
|
||||
async function APIRequest(endpoint, options) {
|
||||
let res;
|
||||
let json;
|
||||
let isOK = false;
|
||||
|
@ -28,7 +28,7 @@ export async function APIRequest(endpoint, options) {
|
|||
return { res, json, isOK, err };
|
||||
}
|
||||
|
||||
export async function authenticated(endpoint, options) {
|
||||
APIRequest.authenticated = async function(endpoint, options) {
|
||||
let res;
|
||||
let json;
|
||||
let isOK = false;
|
||||
|
@ -38,7 +38,7 @@ export async function authenticated(endpoint, options) {
|
|||
if (!options.headers) options.headers = {};
|
||||
|
||||
options.headers = {
|
||||
"Authorization": getToken(),
|
||||
"Authorization": token.getToken(),
|
||||
...options.headers
|
||||
};
|
||||
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
export function getToken() {
|
||||
return localStorage.getItem("token");
|
||||
const tokenManager = {
|
||||
getToken: () => localStorage.getItem("token"),
|
||||
setToken: (token) => localStorage.setItem("token", token)
|
||||
};
|
||||
|
||||
export function setToken(token) {
|
||||
localStorage.setItem("token", token);
|
||||
};
|
||||
export default tokenManager;
|
|
@ -54,19 +54,6 @@ const reducer = (state = intitialState, payload) => {
|
|||
};
|
||||
}
|
||||
|
||||
case 'messagestore/addmessagesback': {
|
||||
return {
|
||||
...state,
|
||||
messages: {
|
||||
...state.messages,
|
||||
[payload.channelId]: [
|
||||
...payload.messages,
|
||||
...state.messages[payload.channelId] || []
|
||||
]
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
case 'channels/selectchannel': {
|
||||
return {
|
||||
...state,
|
||||
|
|
|
@ -1,13 +1,11 @@
|
|||
export default function FullMessage({ glyph, title, content }) {
|
||||
return (
|
||||
<div className="center grow col-flex">
|
||||
return (<div className="center grow col-flex">
|
||||
<div className="greeter-logo">
|
||||
<span className="greeter-logo-text">{glyph}</span>
|
||||
<span className="greeter-logo-text">{ glyph }</span>
|
||||
</div>
|
||||
<span className="greeter-branding-name">{title}</span>
|
||||
<span className="greeter-branding-name">{ title }</span>
|
||||
<div className="center">
|
||||
{content}
|
||||
{ content }
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
</div>)
|
||||
}
|
|
@ -3,7 +3,7 @@ import { useHistory } from 'react-router-dom';
|
|||
|
||||
import Notification from '../Notification';
|
||||
import APIRequest from '../../api/request';
|
||||
import { getSignupMessageFromError } from '../../common/util/errors'
|
||||
import { getSignupMessageFromError } from '../../common/util/Errors'
|
||||
|
||||
export default function Create() {
|
||||
const history = useHistory();
|
||||
|
@ -11,6 +11,7 @@ export default function Create() {
|
|||
const [ usernameInput, setUsernameInput ] = useState();
|
||||
const [ passwordInput, setPasswordInput ] = useState();
|
||||
const [ specialCodeInput, setSpecialCodeInput ] = useState();
|
||||
|
||||
const [ specialCodePrompt, setSpecialCodePrompt ] = useState();
|
||||
|
||||
const [ info, setInfo ] = useState();
|
||||
|
|
|
@ -3,9 +3,9 @@ import { useHistory } from 'react-router-dom';
|
|||
|
||||
import Notification from '../Notification';
|
||||
import APIRequest from '../../api/request';
|
||||
import { login } from '../../api/authenticator';
|
||||
import { setToken } from "../../api/tokenManager";
|
||||
import { getLoginMessageFromError } from '../../common/util/errors'
|
||||
import Authenticator from '../../api/authenticator';
|
||||
import token from "../../api/tokenManager";
|
||||
import { getLoginMessageFromError } from '../../common/util/Errors'
|
||||
|
||||
export default function Login() {
|
||||
const history = useHistory();
|
||||
|
@ -42,8 +42,8 @@ export default function Login() {
|
|||
return;
|
||||
}
|
||||
|
||||
setToken(json.token);
|
||||
await login();
|
||||
token.setToken(json.token);
|
||||
await Authenticator.login();
|
||||
|
||||
history.push('/');
|
||||
}
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
import { useHistory } from 'react-router-dom';
|
||||
|
||||
import ChannelProfile from './ChannelProfileLink';
|
||||
import gatewayConnection from '../../api/gateway/globalGatewayConnection';
|
||||
|
||||
import { useHistory } from 'react-router-dom';
|
||||
|
||||
export default function ChannelButton({ channel, selected }) {
|
||||
const history = useHistory();
|
||||
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
import { connect } from 'react-redux'
|
||||
|
||||
import ChannelListLoader from './ChannelListLoader';
|
||||
import ChannelButton from './ChannelButton';
|
||||
|
||||
import { connect } from 'react-redux'
|
||||
|
||||
function ChannelList({ selectedChannelId, channels }) {
|
||||
if (!channels) {
|
||||
return (
|
||||
|
|
|
@ -1,51 +1,21 @@
|
|||
import { useRef, useEffect, useState } from 'react';
|
||||
import { useDispatch } from "react-redux";
|
||||
|
||||
import { authenticated } from "../../api/request";
|
||||
import Message from "../Message";
|
||||
import { useRef, useEffect } from 'react';
|
||||
|
||||
export default function ChannelMessageView({ messages, channelId }) {
|
||||
export default function ChannelMessageView({messages}) {
|
||||
const invisibleBottomMessageRef = useRef();
|
||||
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
const dispatch = useDispatch();
|
||||
const scroller = useRef();
|
||||
|
||||
const loadOlderMessages = () => {
|
||||
if (isLoading) return;
|
||||
if (!channelId) return;
|
||||
setIsLoading(true);
|
||||
|
||||
const request = messages[0] ? `/api/v1/content/channel/${channelId}/messages?before=${messages[0]._id}` : `/api/v1/content/channel/${channelId}/messages`;
|
||||
|
||||
authenticated(request)
|
||||
.then((res) => {
|
||||
if (res.json.channelMessages)
|
||||
dispatch({
|
||||
type: "messagestore/addmessagesback",
|
||||
messages: res.json.channelMessages.reverse(),
|
||||
channelId
|
||||
})
|
||||
})
|
||||
.then(() => {
|
||||
setIsLoading(false);
|
||||
});
|
||||
};
|
||||
|
||||
const onScroll = () => {
|
||||
if (scroller.current.scrollTop === 0) {
|
||||
loadOlderMessages();
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(loadOlderMessages, [channelId, dispatch]);
|
||||
|
||||
useEffect(() => {
|
||||
invisibleBottomMessageRef.current.scrollIntoView(true);
|
||||
}, [messages]);
|
||||
|
||||
return <div className="message-list" id="message-list" ref={ scroller } onScroll={ onScroll }>
|
||||
{messages.map(message => <Message message={message} key={message._id} />)}
|
||||
let messagesView = messages.map((message) => (<Message key={message._id} message={message} />));
|
||||
if (messagesView === undefined || messagesView.length <= 0)
|
||||
messagesView = (<div className='no-messages-warning'>
|
||||
<span style={{ margin: "12px" }}>No messages yet...</span>
|
||||
</div>);
|
||||
|
||||
return <div className="message-list">
|
||||
{ messagesView }
|
||||
<div className="messages-scroll-div" ref={ invisibleBottomMessageRef }></div>
|
||||
</div>;
|
||||
}
|
|
@ -1,10 +1,10 @@
|
|||
import { connect, useDispatch } from 'react-redux';
|
||||
import { useState, useRef, useEffect } from 'react';
|
||||
|
||||
import ChannelProfile from './ChannelProfileLink';
|
||||
import gatewayConnection from '../../api/gateway/globalGatewayConnection';
|
||||
import ChannelUserList from "./ChannelUserList";
|
||||
import ProfileLinkLoader from "../ProfileLinkLoader";
|
||||
|
||||
import { connect, useDispatch } from 'react-redux';
|
||||
import { useState, useRef, useEffect } from 'react';
|
||||
import ChannelMessageView from './ChannelMessageView';
|
||||
|
||||
const ChannelView = ({ messages, channel, channelPresenceClientList }) => {
|
||||
|
@ -41,7 +41,7 @@ const ChannelView = ({ messages, channel, channelPresenceClientList }) => {
|
|||
|
||||
<div className="row-flex hidden-overflow">
|
||||
<div className="channel-message-panel">
|
||||
<ChannelMessageView messages={messages} channelId={channel._id}></ChannelMessageView>
|
||||
<ChannelMessageView messages={messages}></ChannelMessageView>
|
||||
<div className="col-flex">
|
||||
<input className="text-input message-input" type="text" placeholder="Go on, type something interesting!" ref={ textInputRef } onKeyDown={ handleTextboxKeydown } onChange={ ({ target }) => setTextInput(target.value) }></input>
|
||||
</div>
|
||||
|
|
|
@ -2,12 +2,12 @@ import { useEffect, useState } from 'react';
|
|||
import { connect } from 'react-redux'
|
||||
import { BrowserRouter, Switch, Route } from 'react-router-dom';
|
||||
|
||||
import './../../styles/App.scss';
|
||||
import Login from '../auth/Login';
|
||||
import Create from '../auth/Create';
|
||||
import Root from '../main/Root';
|
||||
import { login } from '../../api/authenticator';
|
||||
import Authenticator from '../../api/authenticator';
|
||||
import Notification from '../Notification';
|
||||
import './../../styles/App.scss';
|
||||
import LoggedInMount from './LoggedInMount';
|
||||
import FullMessage from '../FullMessage';
|
||||
|
||||
|
@ -16,7 +16,7 @@ function App({ user, fullscreenMessage }) {
|
|||
const [ hasError ] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
login();
|
||||
Authenticator.login();
|
||||
}, []);
|
||||
|
||||
if (user === null && !hasError) {
|
||||
|
|
|
@ -1,10 +1,9 @@
|
|||
import { connect } from "react-redux";
|
||||
import { useParams } from "react-router-dom";
|
||||
|
||||
import Sidebar from "../Sidebar";
|
||||
import ChannelView from "../channel/ChannelView";
|
||||
import GradientBanner from "../GradientBanner";
|
||||
import UserView from "../user/UserView";
|
||||
import { connect } from "react-redux";
|
||||
|
||||
function LoggedInMount({ gradientBannerNotificationText }) {
|
||||
const { channelId, userId } = useParams();
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { useEffect, useState } from "react";
|
||||
import { authenticated } from "../../api/request";
|
||||
import APIRequest from "../../api/request";
|
||||
import UserProfile from "./UserProfileLink";
|
||||
import ProfileLinkLoader from "../ProfileLinkLoader";
|
||||
|
||||
|
@ -7,7 +7,7 @@ export default function UserView({ userId }) {
|
|||
const [userObject, setUserObject] = useState(null);
|
||||
|
||||
useEffect(() => {
|
||||
authenticated(`/api/v1/users/user/${userId}/info`, {
|
||||
APIRequest.authenticated(`/api/v1/users/user/${userId}/info`, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
"Accept": "application/json"
|
||||
|
@ -23,8 +23,8 @@ export default function UserView({ userId }) {
|
|||
if (userObject) {
|
||||
view = <>
|
||||
<UserProfile user={ userObject } size="32" />
|
||||
{(userObject.role === "ADMIN") && <span style={{ padding: "12px" }}>Admin</span>}
|
||||
{(userObject.role === "USER") && <span style={{ padding: "12px" }}>User</span>}
|
||||
{(userObject.role === "ADMIN") && <span>Admin</span>}
|
||||
{(userObject.role === "USER") && <span>User</span>}
|
||||
</>
|
||||
} else {
|
||||
view = <>
|
||||
|
|
|
@ -69,7 +69,7 @@
|
|||
}
|
||||
|
||||
.profile-username {
|
||||
font-weight: 600;
|
||||
font-weight: 500;
|
||||
font-size: 1rem;
|
||||
line-height: 1.256rem;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue