Compare commits
61 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1487dcbadc | ||
|
|
a4b27fdeab | ||
|
|
1137c11c59 | ||
|
|
14cd84dab7 | ||
|
|
b5c5cd9586 | ||
|
|
85cc4cb8f7 | ||
|
|
cf6732fb29 | ||
|
|
1207f5abad | ||
|
|
6e9394ec7a | ||
|
|
2c9e32b6c4 | ||
|
|
fc470d0622 | ||
|
|
a3270041e3 | ||
|
|
956068d0d6 | ||
|
|
3776e32364 | ||
|
|
fb5a54dd17 | ||
|
|
916d564f82 | ||
|
|
364def188a | ||
|
|
d1228a085b | ||
|
|
6c5a29fb48 | ||
|
|
a83aecaa69 | ||
|
|
3d885ec262 | ||
|
|
6fdace07c8 | ||
|
|
8711658e75 | ||
|
|
e25dc46863 | ||
|
|
f53f54af7f | ||
|
|
763aa8865b | ||
|
|
2194cb65a2 | ||
|
|
60435d505f | ||
|
|
af983c76b8 | ||
|
|
ef161bbb31 | ||
|
|
ac364e5ab7 | ||
|
|
2e2b1c6f18 | ||
|
|
1fa1496d7f | ||
|
|
8fb9365eaa | ||
|
|
92ab8331d0 | ||
|
|
603d373cee | ||
|
|
aca2c3a9dd | ||
|
|
f544dab3e0 | ||
|
|
c489940f8b | ||
|
|
dc7ddeaa9b | ||
|
|
9b5f42cda9 | ||
|
|
4022e4969d | ||
|
|
ed62d06b5e | ||
|
|
f11e4f6626 | ||
|
|
59eec5241a | ||
|
|
d287486165 | ||
|
|
f70270a0b3 | ||
|
|
36380fe5fd | ||
|
|
dc7fca4f4c | ||
|
|
977759145e | ||
|
|
76c3660cb2 | ||
|
|
fa10a67811 | ||
|
|
8d95fd0ca0 | ||
|
|
332e95701e | ||
|
|
124b24ab76 | ||
|
|
6ccd1e43bc | ||
|
|
5c09d04912 | ||
|
|
119325c3a2 | ||
|
|
462a559bd3 | ||
|
|
1bd58a0103 | ||
|
|
6c97d08027 |
32
.github/workflows/build-pull-request.yml
vendored
Normal file
32
.github/workflows/build-pull-request.yml
vendored
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
name: 'Build PR'
|
||||||
|
|
||||||
|
on:
|
||||||
|
pull_request:
|
||||||
|
types: ['opened', 'synchronize']
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
env:
|
||||||
|
PR_NUMBER: ${{github.event.number}}
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- name: Build
|
||||||
|
run: npm install && npm run build
|
||||||
|
- name: Upload Artifact
|
||||||
|
uses: actions/upload-artifact@v2
|
||||||
|
with:
|
||||||
|
name: previewbuild
|
||||||
|
path: dist
|
||||||
|
retention-days: 1
|
||||||
|
- uses: actions/github-script@v3.1.0
|
||||||
|
with:
|
||||||
|
script: |
|
||||||
|
var fs = require('fs');
|
||||||
|
fs.writeFileSync('${{github.workspace}}/pr.json', JSON.stringify(context.payload.pull_request));
|
||||||
|
- name: Upload PR Info
|
||||||
|
uses: actions/upload-artifact@v2
|
||||||
|
with:
|
||||||
|
name: pr.json
|
||||||
|
path: pr.json
|
||||||
|
retention-days: 1
|
||||||
78
.github/workflows/deploy-pull-request.yml
vendored
Normal file
78
.github/workflows/deploy-pull-request.yml
vendored
Normal file
@@ -0,0 +1,78 @@
|
|||||||
|
name: Upload Preview Build to Netlify
|
||||||
|
on:
|
||||||
|
workflow_run:
|
||||||
|
workflows: ["Build PR"]
|
||||||
|
types:
|
||||||
|
- completed
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
if: >
|
||||||
|
${{ github.event.workflow_run.conclusion == 'success' }}
|
||||||
|
steps:
|
||||||
|
# There's a 'download artifact' action but it hasn't been updated for the
|
||||||
|
# workflow_run action (https://github.com/actions/download-artifact/issues/60)
|
||||||
|
# so instead we get this mess:
|
||||||
|
- name: 'Download artifact'
|
||||||
|
uses: actions/github-script@v3.1.0
|
||||||
|
with:
|
||||||
|
script: |
|
||||||
|
var artifacts = await github.actions.listWorkflowRunArtifacts({
|
||||||
|
owner: context.repo.owner,
|
||||||
|
repo: context.repo.repo,
|
||||||
|
run_id: ${{github.event.workflow_run.id }},
|
||||||
|
});
|
||||||
|
var matchArtifact = artifacts.data.artifacts.filter((artifact) => {
|
||||||
|
return artifact.name == "previewbuild"
|
||||||
|
})[0];
|
||||||
|
var download = await github.actions.downloadArtifact({
|
||||||
|
owner: context.repo.owner,
|
||||||
|
repo: context.repo.repo,
|
||||||
|
artifact_id: matchArtifact.id,
|
||||||
|
archive_format: 'zip',
|
||||||
|
});
|
||||||
|
var fs = require('fs');
|
||||||
|
fs.writeFileSync('${{github.workspace}}/previewbuild.zip', Buffer.from(download.data));
|
||||||
|
var prInfoArtifact = artifacts.data.artifacts.filter((artifact) => {
|
||||||
|
return artifact.name == "pr.json"
|
||||||
|
})[0];
|
||||||
|
var download = await github.actions.downloadArtifact({
|
||||||
|
owner: context.repo.owner,
|
||||||
|
repo: context.repo.repo,
|
||||||
|
artifact_id: prInfoArtifact.id,
|
||||||
|
archive_format: 'zip',
|
||||||
|
});
|
||||||
|
var fs = require('fs');
|
||||||
|
fs.writeFileSync('${{github.workspace}}/pr.json.zip', Buffer.from(download.data));
|
||||||
|
- name: Extract Artifacts
|
||||||
|
run: unzip -d dist previewbuild.zip && rm previewbuild.zip && unzip pr.json.zip && rm pr.json.zip
|
||||||
|
- name: 'Read PR Info'
|
||||||
|
id: readctx
|
||||||
|
uses: actions/github-script@v3.1.0
|
||||||
|
with:
|
||||||
|
script: |
|
||||||
|
var fs = require('fs');
|
||||||
|
var pr = JSON.parse(fs.readFileSync('${{github.workspace}}/pr.json'));
|
||||||
|
console.log(`::set-output name=prnumber::${pr.number}`);
|
||||||
|
- name: Deploy to Netlify
|
||||||
|
id: netlify
|
||||||
|
uses: nwtgck/actions-netlify@v1.2
|
||||||
|
with:
|
||||||
|
publish-dir: dist
|
||||||
|
deploy-message: "Deploy from GitHub Actions"
|
||||||
|
# These don't work because we're in workflow_run
|
||||||
|
enable-pull-request-comment: false
|
||||||
|
enable-commit-comment: false
|
||||||
|
env:
|
||||||
|
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
|
||||||
|
NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE3_ID }}
|
||||||
|
timeout-minutes: 1
|
||||||
|
- name: Edit PR Description
|
||||||
|
uses: velas/pr-description@v1.0.1
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
with:
|
||||||
|
pull-request-number: ${{ steps.readctx.outputs.prnumber }}
|
||||||
|
description-message: |
|
||||||
|
Preview: ${{ steps.netlify.outputs.deploy-url }}
|
||||||
|
⚠️ Do you trust the author of this PR? Maybe this build will steal your keys or give you malware. Exercise caution. Use test accounts.
|
||||||
30
.github/workflows/pull-request.yml
vendored
30
.github/workflows/pull-request.yml
vendored
@@ -1,30 +0,0 @@
|
|||||||
name: 'Netlify Preview Deploy'
|
|
||||||
|
|
||||||
on:
|
|
||||||
pull_request_target:
|
|
||||||
types: ['opened', 'synchronize']
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
deploy:
|
|
||||||
name: "Deploy to Netlify"
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v1
|
|
||||||
- uses: jsmrcaga/action-netlify-deploy@master
|
|
||||||
with:
|
|
||||||
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
|
|
||||||
NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE3_ID }}
|
|
||||||
BUILD_DIRECTORY: "dist"
|
|
||||||
- name: Post on PR
|
|
||||||
uses: nwtgck/actions-netlify@v1.1
|
|
||||||
with:
|
|
||||||
publish-dir: "dist"
|
|
||||||
github-token: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
deploy-message: "Deploy from GitHub Actions"
|
|
||||||
enable-pull-request-comment: true
|
|
||||||
enable-commit-comment: false
|
|
||||||
overwrites-pull-request-comment: true
|
|
||||||
env:
|
|
||||||
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
|
|
||||||
NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE3_ID }}
|
|
||||||
@@ -51,9 +51,13 @@ navigating to `http://localhost:8080`.
|
|||||||
|
|
||||||
Alternatively you can just pull the [DockerHub image](https://hub.docker.com/r/ajbura/cinny) by `docker pull ajbura/cinny`.
|
Alternatively you can just pull the [DockerHub image](https://hub.docker.com/r/ajbura/cinny) by `docker pull ajbura/cinny`.
|
||||||
|
|
||||||
|
### Configuring default Homeserver
|
||||||
|
|
||||||
|
To set default Homeserver on login and register page, place a customized [`config.json`](config.json) in webroot of your choice.
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
Copyright (c) 2021 Ajay Bura (ajbura) and other contributors
|
Copyright (c) 2021 Ajay Bura (ajbura) and contributors
|
||||||
|
|
||||||
Code licensed under the MIT License: <http://opensource.org/licenses/MIT>
|
Code licensed under the MIT License: <http://opensource.org/licenses/MIT>
|
||||||
|
|
||||||
|
|||||||
12
config.json
Normal file
12
config.json
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
{
|
||||||
|
"defaultHomeserver": 5,
|
||||||
|
"homeserverList": [
|
||||||
|
"boba.best",
|
||||||
|
"converser.eu",
|
||||||
|
"envs.net",
|
||||||
|
"halogen.city",
|
||||||
|
"kde.org",
|
||||||
|
"matrix.org",
|
||||||
|
"mozilla.modular.im"
|
||||||
|
]
|
||||||
|
}
|
||||||
26266
package-lock.json
generated
26266
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
12
package.json
12
package.json
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "cinny",
|
"name": "cinny",
|
||||||
"version": "1.4.0",
|
"version": "1.5.1",
|
||||||
"description": "Yet another matrix client",
|
"description": "Yet another matrix client",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"engines": {
|
"engines": {
|
||||||
@@ -22,8 +22,10 @@
|
|||||||
"dateformat": "^4.5.1",
|
"dateformat": "^4.5.1",
|
||||||
"emojibase-data": "^6.2.0",
|
"emojibase-data": "^6.2.0",
|
||||||
"flux": "^4.0.1",
|
"flux": "^4.0.1",
|
||||||
|
"formik": "^2.2.9",
|
||||||
"html-react-parser": "^1.2.7",
|
"html-react-parser": "^1.2.7",
|
||||||
"linkifyjs": "^3.0.0-beta.3",
|
"linkify-react": "^3.0.3",
|
||||||
|
"linkifyjs": "^3.0.3",
|
||||||
"matrix-js-sdk": "^12.4.1",
|
"matrix-js-sdk": "^12.4.1",
|
||||||
"micromark": "^3.0.3",
|
"micromark": "^3.0.3",
|
||||||
"micromark-extension-gfm": "^1.0.0",
|
"micromark-extension-gfm": "^1.0.0",
|
||||||
@@ -71,9 +73,9 @@
|
|||||||
"stream-browserify": "^3.0.0",
|
"stream-browserify": "^3.0.0",
|
||||||
"style-loader": "^2.0.0",
|
"style-loader": "^2.0.0",
|
||||||
"util": "^0.12.4",
|
"util": "^0.12.4",
|
||||||
"webpack": "^5.28.0",
|
"webpack": "^5.62.1",
|
||||||
"webpack-cli": "^4.5.0",
|
"webpack-cli": "^4.9.1",
|
||||||
"webpack-dev-server": "^3.11.2",
|
"webpack-dev-server": "^4.4.0",
|
||||||
"webpack-merge": "^5.7.3"
|
"webpack-merge": "^5.7.3"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0 maximum-scale=1.0 user-scalable=no">
|
||||||
<link href="https://api.fontshare.com/css?f[]=supreme@300,301,400,401,500,501,700,701&display=swap" rel="stylesheet">
|
<link href="https://api.fontshare.com/css?f[]=supreme@300,301,400,401,500,501,700,701&display=swap" rel="stylesheet">
|
||||||
<title>Cinny</title>
|
<title>Cinny</title>
|
||||||
<meta name="name" content="Cinny">
|
<meta name="name" content="Cinny">
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ function Avatar({
|
|||||||
{
|
{
|
||||||
iconSrc !== null
|
iconSrc !== null
|
||||||
? <RawIcon size={size} src={iconSrc} />
|
? <RawIcon size={size} src={iconSrc} />
|
||||||
: text !== null && <Text variant={textSize}>{text}</Text>
|
: text !== null && <Text variant={textSize}>{[...text][0]}</Text>
|
||||||
}
|
}
|
||||||
</span>
|
</span>
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -6,13 +6,14 @@ import Text from '../text/Text';
|
|||||||
import RawIcon from '../system-icons/RawIcon';
|
import RawIcon from '../system-icons/RawIcon';
|
||||||
import { blurOnBubbling } from './script';
|
import { blurOnBubbling } from './script';
|
||||||
|
|
||||||
function Button({
|
const Button = React.forwardRef(({
|
||||||
id, className, variant, iconSrc,
|
id, className, variant, iconSrc,
|
||||||
type, onClick, children, disabled,
|
type, onClick, children, disabled,
|
||||||
}) {
|
}, ref) => {
|
||||||
const iconClass = (iconSrc === null) ? '' : `btn-${variant}--icon`;
|
const iconClass = (iconSrc === null) ? '' : `btn-${variant}--icon`;
|
||||||
return (
|
return (
|
||||||
<button
|
<button
|
||||||
|
ref={ref}
|
||||||
id={id === '' ? undefined : id}
|
id={id === '' ? undefined : id}
|
||||||
className={`${className ? `${className} ` : ''}btn-${variant} ${iconClass} noselect`}
|
className={`${className ? `${className} ` : ''}btn-${variant} ${iconClass} noselect`}
|
||||||
onMouseUp={(e) => blurOnBubbling(e, `.btn-${variant}`)}
|
onMouseUp={(e) => blurOnBubbling(e, `.btn-${variant}`)}
|
||||||
@@ -26,7 +27,7 @@ function Button({
|
|||||||
{typeof children !== 'string' && children }
|
{typeof children !== 'string' && children }
|
||||||
</button>
|
</button>
|
||||||
);
|
);
|
||||||
}
|
});
|
||||||
|
|
||||||
Button.defaultProps = {
|
Button.defaultProps = {
|
||||||
id: '',
|
id: '',
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import './Input.scss';
|
|||||||
import TextareaAutosize from 'react-autosize-textarea';
|
import TextareaAutosize from 'react-autosize-textarea';
|
||||||
|
|
||||||
function Input({
|
function Input({
|
||||||
id, label, value, placeholder,
|
id, label, name, value, placeholder,
|
||||||
required, type, onChange, forwardRef,
|
required, type, onChange, forwardRef,
|
||||||
resizable, minHeight, onResize, state,
|
resizable, minHeight, onResize, state,
|
||||||
onKeyDown,
|
onKeyDown,
|
||||||
@@ -17,6 +17,7 @@ function Input({
|
|||||||
? (
|
? (
|
||||||
<TextareaAutosize
|
<TextareaAutosize
|
||||||
style={{ minHeight: `${minHeight}px` }}
|
style={{ minHeight: `${minHeight}px` }}
|
||||||
|
name={name}
|
||||||
id={id}
|
id={id}
|
||||||
className={`input input--resizable${state !== 'normal' ? ` input--${state}` : ''}`}
|
className={`input input--resizable${state !== 'normal' ? ` input--${state}` : ''}`}
|
||||||
ref={forwardRef}
|
ref={forwardRef}
|
||||||
@@ -33,6 +34,7 @@ function Input({
|
|||||||
<input
|
<input
|
||||||
ref={forwardRef}
|
ref={forwardRef}
|
||||||
id={id}
|
id={id}
|
||||||
|
name={name}
|
||||||
className={`input ${state !== 'normal' ? ` input--${state}` : ''}`}
|
className={`input ${state !== 'normal' ? ` input--${state}` : ''}`}
|
||||||
type={type}
|
type={type}
|
||||||
placeholder={placeholder}
|
placeholder={placeholder}
|
||||||
@@ -49,6 +51,7 @@ function Input({
|
|||||||
|
|
||||||
Input.defaultProps = {
|
Input.defaultProps = {
|
||||||
id: null,
|
id: null,
|
||||||
|
name: '',
|
||||||
label: '',
|
label: '',
|
||||||
value: '',
|
value: '',
|
||||||
placeholder: '',
|
placeholder: '',
|
||||||
@@ -65,6 +68,7 @@ Input.defaultProps = {
|
|||||||
|
|
||||||
Input.propTypes = {
|
Input.propTypes = {
|
||||||
id: PropTypes.string,
|
id: PropTypes.string,
|
||||||
|
name: PropTypes.string,
|
||||||
label: PropTypes.string,
|
label: PropTypes.string,
|
||||||
value: PropTypes.string,
|
value: PropTypes.string,
|
||||||
placeholder: PropTypes.string,
|
placeholder: PropTypes.string,
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
display: block;
|
display: block;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
min-width: 0px;
|
min-width: 0px;
|
||||||
|
margin: 0;
|
||||||
padding: var(--sp-tight) var(--sp-normal);
|
padding: var(--sp-tight) var(--sp-normal);
|
||||||
background-color: var(--bg-surface-low);
|
background-color: var(--bg-surface-low);
|
||||||
color: var(--tc-surface-normal);
|
color: var(--tc-surface-normal);
|
||||||
|
|||||||
@@ -32,6 +32,7 @@
|
|||||||
|
|
||||||
@mixin scroll {
|
@mixin scroll {
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
|
overscroll-behavior: none;
|
||||||
@extend .firefox-scrollbar;
|
@extend .firefox-scrollbar;
|
||||||
@extend .webkit-scrollbar;
|
@extend .webkit-scrollbar;
|
||||||
@extend .webkit-scrollbar-track;
|
@extend .webkit-scrollbar-track;
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ function ImageUpload({
|
|||||||
>
|
>
|
||||||
<Avatar
|
<Avatar
|
||||||
imageSrc={imageSrc}
|
imageSrc={imageSrc}
|
||||||
text={text.slice(0, 1)}
|
text={text}
|
||||||
bgColor={bgColor}
|
bgColor={bgColor}
|
||||||
size="large"
|
size="large"
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -11,6 +11,10 @@
|
|||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
text-overflow: ellipsis;
|
text-overflow: ellipsis;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
& a {
|
||||||
|
line-height: 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.file-container {
|
.file-container {
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import React, { useRef } from 'react';
|
|||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import './Message.scss';
|
import './Message.scss';
|
||||||
|
|
||||||
import Linkify from 'linkifyjs/react';
|
import Linkify from 'linkify-react';
|
||||||
import ReactMarkdown from 'react-markdown';
|
import ReactMarkdown from 'react-markdown';
|
||||||
import gfm from 'remark-gfm';
|
import gfm from 'remark-gfm';
|
||||||
import { Prism as SyntaxHighlighter } from 'react-syntax-highlighter';
|
import { Prism as SyntaxHighlighter } from 'react-syntax-highlighter';
|
||||||
@@ -106,10 +106,17 @@ MessageReply.propTypes = {
|
|||||||
content: PropTypes.string.isRequired,
|
content: PropTypes.string.isRequired,
|
||||||
};
|
};
|
||||||
|
|
||||||
function MessageContent({ content, isMarkdown, isEdited }) {
|
function MessageContent({
|
||||||
|
senderName,
|
||||||
|
content,
|
||||||
|
isMarkdown,
|
||||||
|
isEdited,
|
||||||
|
msgType,
|
||||||
|
}) {
|
||||||
return (
|
return (
|
||||||
<div className="message__content">
|
<div className="message__content">
|
||||||
<div className="text text-b1">
|
<div className="text text-b1">
|
||||||
|
{ msgType === 'm.emote' && `* ${senderName} ` }
|
||||||
{ isMarkdown ? genMarkdown(content) : linkifyContent(content) }
|
{ isMarkdown ? genMarkdown(content) : linkifyContent(content) }
|
||||||
</div>
|
</div>
|
||||||
{ isEdited && <Text className="message__content-edited" variant="b3">(edited)</Text>}
|
{ isEdited && <Text className="message__content-edited" variant="b3">(edited)</Text>}
|
||||||
@@ -121,9 +128,11 @@ MessageContent.defaultProps = {
|
|||||||
isEdited: false,
|
isEdited: false,
|
||||||
};
|
};
|
||||||
MessageContent.propTypes = {
|
MessageContent.propTypes = {
|
||||||
|
senderName: PropTypes.string.isRequired,
|
||||||
content: PropTypes.node.isRequired,
|
content: PropTypes.node.isRequired,
|
||||||
isMarkdown: PropTypes.bool,
|
isMarkdown: PropTypes.bool,
|
||||||
isEdited: PropTypes.bool,
|
isEdited: PropTypes.bool,
|
||||||
|
msgType: PropTypes.string.isRequired,
|
||||||
};
|
};
|
||||||
|
|
||||||
function MessageEdit({ content, onSave, onCancel }) {
|
function MessageEdit({ content, onSave, onCancel }) {
|
||||||
@@ -228,10 +237,27 @@ MessageOptions.propTypes = {
|
|||||||
|
|
||||||
function Message({
|
function Message({
|
||||||
avatar, header, reply, content, editContent, reactions, options,
|
avatar, header, reply, content, editContent, reactions, options,
|
||||||
|
msgType,
|
||||||
}) {
|
}) {
|
||||||
const msgClass = header === null ? ' message--content-only' : ' message--full';
|
const className = [
|
||||||
|
'message',
|
||||||
|
header === null ? ' message--content-only' : ' message--full',
|
||||||
|
];
|
||||||
|
switch (msgType) {
|
||||||
|
case 'm.text':
|
||||||
|
className.push('message--type-text');
|
||||||
|
break;
|
||||||
|
case 'm.emote':
|
||||||
|
className.push('message--type-emote');
|
||||||
|
break;
|
||||||
|
case 'm.notice':
|
||||||
|
className.push('message--type-notice');
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={`message${msgClass}`}>
|
<div className={className.join(' ')}>
|
||||||
<div className="message__avatar-container">
|
<div className="message__avatar-container">
|
||||||
{avatar !== null && avatar}
|
{avatar !== null && avatar}
|
||||||
</div>
|
</div>
|
||||||
@@ -254,6 +280,7 @@ Message.defaultProps = {
|
|||||||
editContent: null,
|
editContent: null,
|
||||||
reactions: null,
|
reactions: null,
|
||||||
options: null,
|
options: null,
|
||||||
|
msgType: 'm.text',
|
||||||
};
|
};
|
||||||
Message.propTypes = {
|
Message.propTypes = {
|
||||||
avatar: PropTypes.node,
|
avatar: PropTypes.node,
|
||||||
@@ -263,6 +290,7 @@ Message.propTypes = {
|
|||||||
editContent: PropTypes.node,
|
editContent: PropTypes.node,
|
||||||
reactions: PropTypes.node,
|
reactions: PropTypes.node,
|
||||||
options: PropTypes.node,
|
options: PropTypes.node,
|
||||||
|
msgType: PropTypes.string,
|
||||||
};
|
};
|
||||||
|
|
||||||
export {
|
export {
|
||||||
|
|||||||
@@ -160,7 +160,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
& a {
|
& a {
|
||||||
word-break: break-all;
|
word-break: break-word;
|
||||||
}
|
}
|
||||||
&-edited {
|
&-edited {
|
||||||
color: var(--tc-surface-low);
|
color: var(--tc-surface-low);
|
||||||
@@ -410,3 +410,14 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.message.message--type-emote {
|
||||||
|
.message__content {
|
||||||
|
font-style: italic;
|
||||||
|
|
||||||
|
// Remove blockness of first `<p>` so that markdown emotes stay on one line.
|
||||||
|
p:first-of-type {
|
||||||
|
display: inline;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -2,8 +2,6 @@ import React from 'react';
|
|||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import './TimelineChange.scss';
|
import './TimelineChange.scss';
|
||||||
|
|
||||||
// import Linkify from 'linkifyjs/react';
|
|
||||||
|
|
||||||
import Text from '../../atoms/text/Text';
|
import Text from '../../atoms/text/Text';
|
||||||
import RawIcon from '../../atoms/system-icons/RawIcon';
|
import RawIcon from '../../atoms/system-icons/RawIcon';
|
||||||
|
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ function PeopleSelector({
|
|||||||
onClick={onClick}
|
onClick={onClick}
|
||||||
type="button"
|
type="button"
|
||||||
>
|
>
|
||||||
<Avatar imageSrc={avatarSrc} text={name.slice(0, 1)} bgColor={color} size="extra-small" />
|
<Avatar imageSrc={avatarSrc} text={name} bgColor={color} size="extra-small" />
|
||||||
<Text className="people-selector__name" variant="b1">{name}</Text>
|
<Text className="people-selector__name" variant="b1">{name}</Text>
|
||||||
{peopleRole !== null && <Text className="people-selector__role" variant="b3">{peopleRole}</Text>}
|
{peopleRole !== null && <Text className="people-selector__role" variant="b3">{peopleRole}</Text>}
|
||||||
</button>
|
</button>
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import React from 'react';
|
|||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import './RoomIntro.scss';
|
import './RoomIntro.scss';
|
||||||
|
|
||||||
import Linkify from 'linkifyjs/react';
|
import Linkify from 'linkify-react';
|
||||||
import colorMXID from '../../../util/colorMXID';
|
import colorMXID from '../../../util/colorMXID';
|
||||||
|
|
||||||
import Text from '../../atoms/text/Text';
|
import Text from '../../atoms/text/Text';
|
||||||
@@ -17,7 +17,7 @@ function RoomIntro({
|
|||||||
}) {
|
}) {
|
||||||
return (
|
return (
|
||||||
<div className="room-intro">
|
<div className="room-intro">
|
||||||
<Avatar imageSrc={avatarSrc} text={name.slice(0, 1)} bgColor={colorMXID(roomId)} size="large" />
|
<Avatar imageSrc={avatarSrc} text={name} bgColor={colorMXID(roomId)} size="large" />
|
||||||
<div className="room-intro__content">
|
<div className="room-intro__content">
|
||||||
<Text className="room-intro__name" variant="h1">{heading}</Text>
|
<Text className="room-intro__name" variant="h1">{heading}</Text>
|
||||||
<Text className="room-intro__desc" variant="b1">{linkifyContent(desc)}</Text>
|
<Text className="room-intro__desc" variant="b1">{linkifyContent(desc)}</Text>
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ function RoomSelector({
|
|||||||
content={(
|
content={(
|
||||||
<>
|
<>
|
||||||
<Avatar
|
<Avatar
|
||||||
text={name.slice(0, 1)}
|
text={name}
|
||||||
bgColor={colorMXID(roomId)}
|
bgColor={colorMXID(roomId)}
|
||||||
imageSrc={imageSrc}
|
imageSrc={imageSrc}
|
||||||
iconSrc={iconSrc}
|
iconSrc={iconSrc}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import React from 'react';
|
|||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import './RoomTile.scss';
|
import './RoomTile.scss';
|
||||||
|
|
||||||
import Linkify from 'linkifyjs/react';
|
import Linkify from 'linkify-react';
|
||||||
import colorMXID from '../../../util/colorMXID';
|
import colorMXID from '../../../util/colorMXID';
|
||||||
|
|
||||||
import Text from '../../atoms/text/Text';
|
import Text from '../../atoms/text/Text';
|
||||||
@@ -22,7 +22,7 @@ function RoomTile({
|
|||||||
<Avatar
|
<Avatar
|
||||||
imageSrc={avatarSrc}
|
imageSrc={avatarSrc}
|
||||||
bgColor={colorMXID(id)}
|
bgColor={colorMXID(id)}
|
||||||
text={name.slice(0, 1)}
|
text={name}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div className="room-tile__content">
|
<div className="room-tile__content">
|
||||||
|
|||||||
@@ -1,98 +1,41 @@
|
|||||||
import React, { useEffect, useState } from 'react';
|
import React from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import './SSOButtons.scss';
|
import './SSOButtons.scss';
|
||||||
|
|
||||||
import { createTemporaryClient, getLoginFlows, startSsoLogin } from '../../../client/action/auth';
|
import { createTemporaryClient, startSsoLogin } from '../../../client/action/auth';
|
||||||
|
|
||||||
import Text from '../../atoms/text/Text';
|
import Button from '../../atoms/button/Button';
|
||||||
|
|
||||||
function SSOButtons({ homeserver }) {
|
|
||||||
const [identityProviders, setIdentityProviders] = useState([]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
// If the homeserver passed in is not a fully-qualified domain name, do not update.
|
|
||||||
if (!homeserver.match('^[a-zA-Z0-9][a-zA-Z0-9-]{1,61}[a-zA-Z0-9](?:\\.[a-zA-Z]{2,})+$')) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO Check that there is a Matrix server at homename before making requests.
|
|
||||||
// This will prevent the CORS errors that happen when a user changes their homeserver.
|
|
||||||
createTemporaryClient(homeserver).then((client) => {
|
|
||||||
const providers = [];
|
|
||||||
getLoginFlows(client).then((flows) => {
|
|
||||||
if (flows.flows !== undefined) {
|
|
||||||
const ssoFlows = flows.flows.filter((flow) => flow.type === 'm.login.sso' || flow.type === 'm.login.cas');
|
|
||||||
ssoFlows.forEach((flow) => {
|
|
||||||
if (flow.identity_providers !== undefined) {
|
|
||||||
const type = flow.type.substring(8);
|
|
||||||
flow.identity_providers.forEach((idp) => {
|
|
||||||
const imageSrc = client.mxcUrlToHttp(idp.icon);
|
|
||||||
providers.push({
|
|
||||||
homeserver, id: idp.id, name: idp.name, type, imageSrc,
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
setIdentityProviders(providers);
|
|
||||||
}).catch(() => {});
|
|
||||||
}).catch(() => {
|
|
||||||
setIdentityProviders([]);
|
|
||||||
});
|
|
||||||
}, [homeserver]);
|
|
||||||
|
|
||||||
if (identityProviders.length === 0) return <></>;
|
|
||||||
|
|
||||||
|
function SSOButtons({ type, identityProviders, baseUrl }) {
|
||||||
|
const tempClient = createTemporaryClient(baseUrl);
|
||||||
|
function handleClick(id) {
|
||||||
|
startSsoLogin(baseUrl, type, id);
|
||||||
|
}
|
||||||
return (
|
return (
|
||||||
<div className="sso-buttons">
|
<div className="sso-buttons">
|
||||||
<div className="sso-buttons__divider">
|
{identityProviders
|
||||||
<Text>OR</Text>
|
.sort((idp, idp2) => {
|
||||||
</div>
|
if (typeof idp.icon !== 'string') return -1;
|
||||||
<div className="sso-buttons__container">
|
return idp.name.toLowerCase() > idp2.name.toLowerCase() ? 1 : -1;
|
||||||
{identityProviders.sort((idp) => !!idp.imageSrc).map((idp) => (
|
})
|
||||||
<SSOButton
|
.map((idp) => (
|
||||||
key={idp.id}
|
idp.icon
|
||||||
homeserver={idp.homeserver}
|
? (
|
||||||
id={idp.id}
|
<button key={idp.id} type="button" className="sso-btn" onClick={() => handleClick(idp.id)}>
|
||||||
name={idp.name}
|
<img className="sso-btn__img" src={tempClient.mxcUrlToHttp(idp.icon)} alt={idp.name} />
|
||||||
type={idp.type}
|
</button>
|
||||||
imageSrc={idp.imageSrc}
|
) : <Button key={idp.id} className="sso-btn__text-only" onClick={() => handleClick(idp.id)}>{`Login with ${idp.name}`}</Button>
|
||||||
/>
|
|
||||||
))}
|
))}
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function SSOButton({
|
|
||||||
homeserver, id, name, type, imageSrc,
|
|
||||||
}) {
|
|
||||||
const isImageAvail = !!imageSrc;
|
|
||||||
function handleClick() {
|
|
||||||
startSsoLogin(homeserver, type, id);
|
|
||||||
}
|
|
||||||
return (
|
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
className={`sso-btn${!isImageAvail ? ' sso-btn__text-only' : ''}`}
|
|
||||||
onClick={handleClick}
|
|
||||||
>
|
|
||||||
{isImageAvail && <img className="sso-btn__img" src={imageSrc} alt={name} />}
|
|
||||||
{!isImageAvail && <Text>{`Login with ${name}`}</Text>}
|
|
||||||
</button>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
SSOButtons.propTypes = {
|
SSOButtons.propTypes = {
|
||||||
homeserver: PropTypes.string.isRequired,
|
identityProviders: PropTypes.arrayOf(
|
||||||
};
|
PropTypes.shape({}),
|
||||||
|
).isRequired,
|
||||||
SSOButton.propTypes = {
|
baseUrl: PropTypes.string.isRequired,
|
||||||
homeserver: PropTypes.string.isRequired,
|
type: PropTypes.oneOf(['sso', 'cas']).isRequired,
|
||||||
id: PropTypes.string.isRequired,
|
|
||||||
name: PropTypes.string.isRequired,
|
|
||||||
type: PropTypes.string.isRequired,
|
|
||||||
imageSrc: PropTypes.string.isRequired,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export default SSOButtons;
|
export default SSOButtons;
|
||||||
|
|||||||
@@ -1,22 +1,7 @@
|
|||||||
.sso-buttons {
|
.sso-buttons {
|
||||||
&__divider {
|
display: flex;
|
||||||
display: flex;
|
justify-content: center;
|
||||||
align-items: center;
|
flex-wrap: wrap;
|
||||||
|
|
||||||
&::before,
|
|
||||||
&::after {
|
|
||||||
flex: 1;
|
|
||||||
content: '';
|
|
||||||
margin: var(--sp-tight);
|
|
||||||
border-bottom: 1px solid var(--bg-surface-border);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
&__container {
|
|
||||||
margin-bottom: var(--sp-extra-loose);
|
|
||||||
display: flex;
|
|
||||||
justify-content: center;
|
|
||||||
flex-wrap: wrap;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.sso-btn {
|
.sso-btn {
|
||||||
@@ -31,11 +16,8 @@
|
|||||||
width: var(--av-small);
|
width: var(--av-small);
|
||||||
}
|
}
|
||||||
&__text-only {
|
&__text-only {
|
||||||
|
margin-top: var(--sp-normal);
|
||||||
flex-basis: 100%;
|
flex-basis: 100%;
|
||||||
text-align: center;
|
|
||||||
|
|
||||||
margin: var(--sp-tight) 0px;
|
|
||||||
cursor: pointer;
|
|
||||||
& .text {
|
& .text {
|
||||||
color: var(--tc-link);
|
color: var(--tc-link);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import './CreateRoom.scss';
|
|||||||
import initMatrix from '../../../client/initMatrix';
|
import initMatrix from '../../../client/initMatrix';
|
||||||
import { isRoomAliasAvailable } from '../../../util/matrixUtil';
|
import { isRoomAliasAvailable } from '../../../util/matrixUtil';
|
||||||
import * as roomActions from '../../../client/action/room';
|
import * as roomActions from '../../../client/action/room';
|
||||||
|
import { selectRoom } from '../../../client/action/navigation';
|
||||||
|
|
||||||
import Text from '../../atoms/text/Text';
|
import Text from '../../atoms/text/Text';
|
||||||
import Button from '../../atoms/button/Button';
|
import Button from '../../atoms/button/Button';
|
||||||
@@ -12,6 +13,7 @@ import Toggle from '../../atoms/button/Toggle';
|
|||||||
import IconButton from '../../atoms/button/IconButton';
|
import IconButton from '../../atoms/button/IconButton';
|
||||||
import Input from '../../atoms/input/Input';
|
import Input from '../../atoms/input/Input';
|
||||||
import Spinner from '../../atoms/spinner/Spinner';
|
import Spinner from '../../atoms/spinner/Spinner';
|
||||||
|
import SegmentControl from '../../atoms/segmented-controls/SegmentedControls';
|
||||||
import PopupWindow from '../../molecules/popup-window/PopupWindow';
|
import PopupWindow from '../../molecules/popup-window/PopupWindow';
|
||||||
import SettingTile from '../../molecules/setting-tile/SettingTile';
|
import SettingTile from '../../molecules/setting-tile/SettingTile';
|
||||||
|
|
||||||
@@ -28,6 +30,7 @@ function CreateRoom({ isOpen, onRequestClose }) {
|
|||||||
const [titleValue, updateTitleValue] = useState(undefined);
|
const [titleValue, updateTitleValue] = useState(undefined);
|
||||||
const [topicValue, updateTopicValue] = useState(undefined);
|
const [topicValue, updateTopicValue] = useState(undefined);
|
||||||
const [addressValue, updateAddressValue] = useState(undefined);
|
const [addressValue, updateAddressValue] = useState(undefined);
|
||||||
|
const [roleIndex, setRoleIndex] = useState(0);
|
||||||
|
|
||||||
const addressRef = useRef(null);
|
const addressRef = useRef(null);
|
||||||
const topicRef = useRef(null);
|
const topicRef = useRef(null);
|
||||||
@@ -45,6 +48,7 @@ function CreateRoom({ isOpen, onRequestClose }) {
|
|||||||
updateTitleValue(undefined);
|
updateTitleValue(undefined);
|
||||||
updateTopicValue(undefined);
|
updateTopicValue(undefined);
|
||||||
updateAddressValue(undefined);
|
updateAddressValue(undefined);
|
||||||
|
setRoleIndex(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function createRoom() {
|
async function createRoom() {
|
||||||
@@ -60,12 +64,15 @@ function CreateRoom({ isOpen, onRequestClose }) {
|
|||||||
if (roomAlias.trim() === '') roomAlias = undefined;
|
if (roomAlias.trim() === '') roomAlias = undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const powerLevel = roleIndex === 1 ? 101 : undefined;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await roomActions.create({
|
const result = await roomActions.create({
|
||||||
name, topic, isPublic, roomAlias, isEncrypted,
|
name, topic, isPublic, roomAlias, isEncrypted, powerLevel,
|
||||||
});
|
});
|
||||||
|
|
||||||
resetForm();
|
resetForm();
|
||||||
|
selectRoom(result.room_id);
|
||||||
onRequestClose();
|
onRequestClose();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (e.message === 'M_UNKNOWN: Invalid characters in room alias') {
|
if (e.message === 'M_UNKNOWN: Invalid characters in room alias') {
|
||||||
@@ -139,6 +146,19 @@ function CreateRoom({ isOpen, onRequestClose }) {
|
|||||||
content={<Text variant="b3">You can’t disable this later. Bridges & most bots won’t work yet.</Text>}
|
content={<Text variant="b3">You can’t disable this later. Bridges & most bots won’t work yet.</Text>}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
<SettingTile
|
||||||
|
title="Select your role"
|
||||||
|
options={(
|
||||||
|
<SegmentControl
|
||||||
|
selected={roleIndex}
|
||||||
|
segments={[{ text: 'Admin' }, { text: 'Founder' }]}
|
||||||
|
onSelect={setRoleIndex}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
content={(
|
||||||
|
<Text variant="b3">Override the default (100) power level.</Text>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
<Input value={topicValue} onChange={handleTopicChange} forwardRef={topicRef} minHeight={174} resizable label="Topic (optional)" />
|
<Input value={topicValue} onChange={handleTopicChange} forwardRef={topicRef} minHeight={174} resizable label="Topic (optional)" />
|
||||||
<div className="create-room__name-wrapper">
|
<div className="create-room__name-wrapper">
|
||||||
<Input value={titleValue} onChange={handleTitleChange} forwardRef={nameRef} label="Room name" required />
|
<Input value={titleValue} onChange={handleTitleChange} forwardRef={nameRef} label="Room name" required />
|
||||||
|
|||||||
@@ -9,6 +9,13 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
& .segment-btn {
|
||||||
|
padding: var(--sp-ultra-tight) 0;
|
||||||
|
&__base {
|
||||||
|
padding: 0 var(--sp-tight);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
&__address {
|
&__address {
|
||||||
display: flex;
|
display: flex;
|
||||||
&__label {
|
&__label {
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import './InviteList.scss';
|
|||||||
import initMatrix from '../../../client/initMatrix';
|
import initMatrix from '../../../client/initMatrix';
|
||||||
import cons from '../../../client/state/cons';
|
import cons from '../../../client/state/cons';
|
||||||
import * as roomActions from '../../../client/action/room';
|
import * as roomActions from '../../../client/action/room';
|
||||||
|
import { selectRoom, selectSpace } from '../../../client/action/navigation';
|
||||||
|
|
||||||
import Text from '../../atoms/text/Text';
|
import Text from '../../atoms/text/Text';
|
||||||
import Button from '../../atoms/button/Button';
|
import Button from '../../atoms/button/Button';
|
||||||
@@ -29,13 +30,18 @@ function InviteList({ isOpen, onRequestClose }) {
|
|||||||
roomActions.leave(roomId, isDM);
|
roomActions.leave(roomId, isDM);
|
||||||
}
|
}
|
||||||
function updateInviteList(roomId) {
|
function updateInviteList(roomId) {
|
||||||
if (procInvite.has(roomId)) {
|
if (procInvite.has(roomId)) procInvite.delete(roomId);
|
||||||
procInvite.delete(roomId);
|
changeProcInvite(new Set(Array.from(procInvite)));
|
||||||
changeProcInvite(new Set(Array.from(procInvite)));
|
|
||||||
} else changeProcInvite(new Set(Array.from(procInvite)));
|
|
||||||
|
|
||||||
const rl = initMatrix.roomList;
|
const rl = initMatrix.roomList;
|
||||||
const totalInvites = rl.inviteDirects.size + rl.inviteRooms.size;
|
const totalInvites = rl.inviteDirects.size + rl.inviteRooms.size + rl.inviteSpaces.size;
|
||||||
|
const room = initMatrix.matrixClient.getRoom(roomId);
|
||||||
|
const isRejected = room === null || room?.getMyMembership() !== 'join';
|
||||||
|
if (!isRejected) {
|
||||||
|
if (room.isSpaceRoom()) selectSpace(roomId);
|
||||||
|
else selectRoom(roomId);
|
||||||
|
onRequestClose();
|
||||||
|
}
|
||||||
if (totalInvites === 0) onRequestClose();
|
if (totalInvites === 0) onRequestClose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ function ProfileAvatarMenu() {
|
|||||||
tooltip={profile.displayName}
|
tooltip={profile.displayName}
|
||||||
imageSrc={profile.avatarUrl !== null ? mx.mxcUrlToHttp(profile.avatarUrl, 42, 42, 'crop') : null}
|
imageSrc={profile.avatarUrl !== null ? mx.mxcUrlToHttp(profile.avatarUrl, 42, 42, 'crop') : null}
|
||||||
bgColor={colorMXID(mx.getUserId())}
|
bgColor={colorMXID(mx.getUserId())}
|
||||||
text={profile.displayName.slice(0, 1)}
|
text={profile.displayName}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
@@ -121,6 +121,7 @@ function SideBar() {
|
|||||||
let noti = null;
|
let noti = null;
|
||||||
|
|
||||||
orphans.forEach((roomId) => {
|
orphans.forEach((roomId) => {
|
||||||
|
if (roomList.spaceShortcut.has(roomId)) return;
|
||||||
if (!notifications.hasNoti(roomId)) return;
|
if (!notifications.hasNoti(roomId)) return;
|
||||||
if (noti === null) noti = { total: 0, highlight: 0 };
|
if (noti === null) noti = { total: 0, highlight: 0 };
|
||||||
const childNoti = notifications.getNoti(roomId);
|
const childNoti = notifications.getNoti(roomId);
|
||||||
@@ -189,7 +190,7 @@ function SideBar() {
|
|||||||
tooltip={room.name}
|
tooltip={room.name}
|
||||||
bgColor={colorMXID(room.roomId)}
|
bgColor={colorMXID(room.roomId)}
|
||||||
imageSrc={room.getAvatarUrl(initMatrix.matrixClient.baseUrl, 42, 42, 'crop') || null}
|
imageSrc={room.getAvatarUrl(initMatrix.matrixClient.baseUrl, 42, 42, 'crop') || null}
|
||||||
text={room.name.slice(0, 1)}
|
text={room.name}
|
||||||
isUnread={notifications.hasNoti(sRoomId)}
|
isUnread={notifications.hasNoti(sRoomId)}
|
||||||
notificationCount={abbreviateNumber(notifications.getTotalNoti(sRoomId))}
|
notificationCount={abbreviateNumber(notifications.getTotalNoti(sRoomId))}
|
||||||
isAlert={notifications.getHighlightNoti(sRoomId) !== 0}
|
isAlert={notifications.getHighlightNoti(sRoomId) !== 0}
|
||||||
|
|||||||
@@ -78,19 +78,30 @@ SessionInfo.propTypes = {
|
|||||||
userId: PropTypes.string.isRequired,
|
userId: PropTypes.string.isRequired,
|
||||||
};
|
};
|
||||||
|
|
||||||
function ProfileFooter({ userId, onRequestClose }) {
|
function ProfileFooter({ roomId, userId, onRequestClose }) {
|
||||||
const [isCreatingDM, setIsCreatingDM] = useState(false);
|
const [isCreatingDM, setIsCreatingDM] = useState(false);
|
||||||
const [isIgnoring, setIsIgnoring] = useState(false);
|
const [isIgnoring, setIsIgnoring] = useState(false);
|
||||||
const [isUserIgnored, setIsUserIgnored] = useState(initMatrix.matrixClient.isUserIgnored(userId));
|
const [isUserIgnored, setIsUserIgnored] = useState(initMatrix.matrixClient.isUserIgnored(userId));
|
||||||
|
|
||||||
const mx = initMatrix.matrixClient;
|
|
||||||
const isMountedRef = useRef(true);
|
const isMountedRef = useRef(true);
|
||||||
|
const mx = initMatrix.matrixClient;
|
||||||
|
const room = mx.getRoom(roomId);
|
||||||
|
const member = room.getMember(userId);
|
||||||
|
const isInvitable = member?.membership !== 'join' && member?.membership !== 'ban';
|
||||||
|
|
||||||
|
const [isInviting, setIsInviting] = useState(false);
|
||||||
|
const [isInvited, setIsInvited] = useState(member?.membership === 'invite');
|
||||||
|
|
||||||
|
const myPowerlevel = room.getMember(mx.getUserId()).powerLevel;
|
||||||
|
const canIKick = room.currentState.hasSufficientPowerLevelFor('kick', myPowerlevel);
|
||||||
|
|
||||||
useEffect(() => () => {
|
useEffect(() => () => {
|
||||||
isMountedRef.current = false;
|
isMountedRef.current = false;
|
||||||
}, []);
|
}, []);
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setIsUserIgnored(initMatrix.matrixClient.isUserIgnored(userId));
|
setIsUserIgnored(initMatrix.matrixClient.isUserIgnored(userId));
|
||||||
|
setIsIgnoring(false);
|
||||||
|
setIsInviting(false);
|
||||||
}, [userId]);
|
}, [userId]);
|
||||||
|
|
||||||
async function openDM() {
|
async function openDM() {
|
||||||
@@ -144,6 +155,24 @@ function ProfileFooter({ userId, onRequestClose }) {
|
|||||||
setIsIgnoring(false);
|
setIsIgnoring(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function toggleInvite() {
|
||||||
|
try {
|
||||||
|
setIsInviting(true);
|
||||||
|
let isInviteSent = false;
|
||||||
|
if (isInvited) await roomActions.kick(roomId, userId);
|
||||||
|
else {
|
||||||
|
await roomActions.invite(roomId, userId);
|
||||||
|
isInviteSent = true;
|
||||||
|
}
|
||||||
|
if (isMountedRef.current === false) return;
|
||||||
|
setIsInvited(isInviteSent);
|
||||||
|
setIsInviting(false);
|
||||||
|
} catch {
|
||||||
|
setIsInviting(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="profile-viewer__buttons">
|
<div className="profile-viewer__buttons">
|
||||||
<Button
|
<Button
|
||||||
@@ -153,7 +182,19 @@ function ProfileFooter({ userId, onRequestClose }) {
|
|||||||
>
|
>
|
||||||
{isCreatingDM ? 'Creating room...' : 'Message'}
|
{isCreatingDM ? 'Creating room...' : 'Message'}
|
||||||
</Button>
|
</Button>
|
||||||
<Button>Mention</Button>
|
{ member?.membership === 'join' && <Button>Mention</Button>}
|
||||||
|
{ (isInvited ? canIKick : room.canInvite(mx.getUserId())) && isInvitable && (
|
||||||
|
<Button
|
||||||
|
onClick={toggleInvite}
|
||||||
|
disabled={isInviting}
|
||||||
|
>
|
||||||
|
{
|
||||||
|
isInvited
|
||||||
|
? `${isInviting ? 'Disinviting...' : 'Disinvite'}`
|
||||||
|
: `${isInviting ? 'Inviting...' : 'Invite'}`
|
||||||
|
}
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
<Button
|
<Button
|
||||||
variant={isUserIgnored ? 'positive' : 'danger'}
|
variant={isUserIgnored ? 'positive' : 'danger'}
|
||||||
onClick={toggleIgnore}
|
onClick={toggleIgnore}
|
||||||
@@ -169,6 +210,7 @@ function ProfileFooter({ userId, onRequestClose }) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
ProfileFooter.propTypes = {
|
ProfileFooter.propTypes = {
|
||||||
|
roomId: PropTypes.string.isRequired,
|
||||||
userId: PropTypes.string.isRequired,
|
userId: PropTypes.string.isRequired,
|
||||||
onRequestClose: PropTypes.func.isRequired,
|
onRequestClose: PropTypes.func.isRequired,
|
||||||
};
|
};
|
||||||
@@ -207,15 +249,15 @@ function ProfileViewer() {
|
|||||||
}, [isOpen]);
|
}, [isOpen]);
|
||||||
|
|
||||||
function renderProfile() {
|
function renderProfile() {
|
||||||
const member = room.getMember(userId) || mx.getUser(userId);
|
const member = room.getMember(userId) || mx.getUser(userId) || {};
|
||||||
const avatarMxc = member.getMxcAvatarUrl() || member.avatarUrl;
|
const avatarMxc = member.getMxcAvatarUrl?.() || member.avatarUrl;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="profile-viewer">
|
<div className="profile-viewer">
|
||||||
<div className="profile-viewer__user">
|
<div className="profile-viewer__user">
|
||||||
<Avatar
|
<Avatar
|
||||||
imageSrc={!avatarMxc ? null : mx.mxcUrlToHttp(avatarMxc, 80, 80, 'crop')}
|
imageSrc={!avatarMxc ? null : mx.mxcUrlToHttp(avatarMxc, 80, 80, 'crop')}
|
||||||
text={username.slice(0, 1)}
|
text={username}
|
||||||
bgColor={colorMXID(userId)}
|
bgColor={colorMXID(userId)}
|
||||||
size="large"
|
size="large"
|
||||||
/>
|
/>
|
||||||
@@ -231,6 +273,7 @@ function ProfileViewer() {
|
|||||||
<SessionInfo userId={userId} />
|
<SessionInfo userId={userId} />
|
||||||
{ userId !== mx.getUserId() && (
|
{ userId !== mx.getUserId() && (
|
||||||
<ProfileFooter
|
<ProfileFooter
|
||||||
|
roomId={roomId}
|
||||||
userId={userId}
|
userId={userId}
|
||||||
onRequestClose={() => setIsOpen(false)}
|
onRequestClose={() => setIsOpen(false)}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -103,30 +103,35 @@ function PeopleDrawer({ roomId }) {
|
|||||||
}, [memberList]);
|
}, [memberList]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
searchRef.current.value = '';
|
let isGettingMembers = true;
|
||||||
setMemberList(
|
const updateMemberList = (event) => {
|
||||||
simplyfiMembers(
|
if (isGettingMembers) return;
|
||||||
getMembersWithMembership(membership)
|
console.log(event?.event?.room_id);
|
||||||
.sort(AtoZ).sort(sortByPowerLevel),
|
if (event && event?.event?.room_id !== roomId) return;
|
||||||
),
|
|
||||||
);
|
|
||||||
room.loadMembersIfNeeded().then(() => {
|
|
||||||
if (isRoomChanged) return;
|
|
||||||
setMemberList(
|
setMemberList(
|
||||||
simplyfiMembers(
|
simplyfiMembers(
|
||||||
getMembersWithMembership(membership)
|
getMembersWithMembership(membership)
|
||||||
.sort(AtoZ).sort(sortByPowerLevel),
|
.sort(AtoZ).sort(sortByPowerLevel),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
};
|
||||||
|
searchRef.current.value = '';
|
||||||
|
updateMemberList();
|
||||||
|
room.loadMembersIfNeeded().then(() => {
|
||||||
|
isGettingMembers = false;
|
||||||
|
if (isRoomChanged) return;
|
||||||
|
updateMemberList();
|
||||||
});
|
});
|
||||||
|
|
||||||
asyncSearch.on(asyncSearch.RESULT_SENT, handleSearchData);
|
asyncSearch.on(asyncSearch.RESULT_SENT, handleSearchData);
|
||||||
|
mx.on('RoomMember.membership', updateMemberList);
|
||||||
return () => {
|
return () => {
|
||||||
isRoomChanged = true;
|
isRoomChanged = true;
|
||||||
setMemberList([]);
|
setMemberList([]);
|
||||||
setSearchedMembers(null);
|
setSearchedMembers(null);
|
||||||
setItemCount(PER_PAGE_MEMBER);
|
setItemCount(PER_PAGE_MEMBER);
|
||||||
asyncSearch.removeListener(asyncSearch.RESULT_SENT, handleSearchData);
|
asyncSearch.removeListener(asyncSearch.RESULT_SENT, handleSearchData);
|
||||||
|
mx.removeListener('RoomMember.membership', updateMemberList);
|
||||||
};
|
};
|
||||||
}, [roomId, membership]);
|
}, [roomId, membership]);
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import dateFormat from 'dateformat';
|
|||||||
import initMatrix from '../../../client/initMatrix';
|
import initMatrix from '../../../client/initMatrix';
|
||||||
import cons from '../../../client/state/cons';
|
import cons from '../../../client/state/cons';
|
||||||
import { redactEvent, sendReaction } from '../../../client/action/roomTimeline';
|
import { redactEvent, sendReaction } from '../../../client/action/roomTimeline';
|
||||||
import { getUsername, getUsernameOfRoomMember, doesRoomHaveUnread } from '../../../util/matrixUtil';
|
import { getUsername, getUsernameOfRoomMember } from '../../../util/matrixUtil';
|
||||||
import colorMXID from '../../../util/colorMXID';
|
import colorMXID from '../../../util/colorMXID';
|
||||||
import { diffMinutes, isNotInSameDay, getEventCords } from '../../../util/common';
|
import { diffMinutes, isNotInSameDay, getEventCords } from '../../../util/common';
|
||||||
import { openEmojiBoard, openProfileViewer, openReadReceipts } from '../../../client/action/navigation';
|
import { openEmojiBoard, openProfileViewer, openReadReceipts } from '../../../client/action/navigation';
|
||||||
@@ -191,6 +191,7 @@ function RoomViewContent({
|
|||||||
const [onPagination, setOnPagination] = useState(null);
|
const [onPagination, setOnPagination] = useState(null);
|
||||||
const [editEvent, setEditEvent] = useState(null);
|
const [editEvent, setEditEvent] = useState(null);
|
||||||
const mx = initMatrix.matrixClient;
|
const mx = initMatrix.matrixClient;
|
||||||
|
const noti = initMatrix.notifications;
|
||||||
|
|
||||||
function autoLoadTimeline() {
|
function autoLoadTimeline() {
|
||||||
if (timelineScroll.isScrollable() === true) return;
|
if (timelineScroll.isScrollable() === true) return;
|
||||||
@@ -199,7 +200,7 @@ function RoomViewContent({
|
|||||||
function trySendingReadReceipt() {
|
function trySendingReadReceipt() {
|
||||||
const { room, timeline } = roomTimeline;
|
const { room, timeline } = roomTimeline;
|
||||||
if (
|
if (
|
||||||
(doesRoomHaveUnread(room) || initMatrix.notifications.hasNoti(roomId))
|
(noti.doesRoomHaveUnread(room) || noti.hasNoti(roomId))
|
||||||
&& timeline.length !== 0) {
|
&& timeline.length !== 0) {
|
||||||
mx.sendReadReceipt(timeline[timeline.length - 1]);
|
mx.sendReadReceipt(timeline[timeline.length - 1]);
|
||||||
}
|
}
|
||||||
@@ -282,6 +283,7 @@ function RoomViewContent({
|
|||||||
|
|
||||||
let content = mEvent.getContent().body;
|
let content = mEvent.getContent().body;
|
||||||
if (typeof content === 'undefined') return null;
|
if (typeof content === 'undefined') return null;
|
||||||
|
const msgType = mEvent.getContent()?.msgtype;
|
||||||
let reply = null;
|
let reply = null;
|
||||||
let reactions = null;
|
let reactions = null;
|
||||||
let isMarkdown = mEvent.getContent().format === 'org.matrix.custom.html';
|
let isMarkdown = mEvent.getContent().format === 'org.matrix.custom.html';
|
||||||
@@ -356,7 +358,7 @@ function RoomViewContent({
|
|||||||
<button type="button" onClick={() => openProfileViewer(mEvent.sender.userId, roomId)}>
|
<button type="button" onClick={() => openProfileViewer(mEvent.sender.userId, roomId)}>
|
||||||
<Avatar
|
<Avatar
|
||||||
imageSrc={mEvent.sender.getAvatarUrl(initMatrix.matrixClient.baseUrl, 36, 36, 'crop')}
|
imageSrc={mEvent.sender.getAvatarUrl(initMatrix.matrixClient.baseUrl, 36, 36, 'crop')}
|
||||||
text={getUsernameOfRoomMember(mEvent.sender).slice(0, 1)}
|
text={getUsernameOfRoomMember(mEvent.sender)}
|
||||||
bgColor={senderMXIDColor}
|
bgColor={senderMXIDColor}
|
||||||
size="small"
|
size="small"
|
||||||
/>
|
/>
|
||||||
@@ -379,8 +381,10 @@ function RoomViewContent({
|
|||||||
);
|
);
|
||||||
const userContent = (
|
const userContent = (
|
||||||
<MessageContent
|
<MessageContent
|
||||||
|
senderName={getUsernameOfRoomMember(mEvent.sender)}
|
||||||
isMarkdown={isMarkdown}
|
isMarkdown={isMarkdown}
|
||||||
content={isMedia(mEvent) ? genMediaContent(mEvent) : content}
|
content={isMedia(mEvent) ? genMediaContent(mEvent) : content}
|
||||||
|
msgType={msgType}
|
||||||
isEdited={isEdited}
|
isEdited={isEdited}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
@@ -496,6 +500,7 @@ function RoomViewContent({
|
|||||||
header={userHeader}
|
header={userHeader}
|
||||||
reply={userReply}
|
reply={userReply}
|
||||||
content={editEvent !== null && isEditingEvent ? null : userContent}
|
content={editEvent !== null && isEditingEvent ? null : userContent}
|
||||||
|
msgType={msgType}
|
||||||
editContent={editEvent !== null && isEditingEvent ? (
|
editContent={editEvent !== null && isEditingEvent ? (
|
||||||
<MessageEdit
|
<MessageEdit
|
||||||
content={content}
|
content={content}
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ function RoomViewHeader({ roomId }) {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<Header>
|
<Header>
|
||||||
<Avatar imageSrc={avatarSrc} text={roomName.slice(0, 1)} bgColor={colorMXID(roomId)} size="small" />
|
<Avatar imageSrc={avatarSrc} text={roomName} bgColor={colorMXID(roomId)} size="small" />
|
||||||
<TitleWrapper>
|
<TitleWrapper>
|
||||||
<Text variant="h2">{roomName}</Text>
|
<Text variant="h2">{roomName}</Text>
|
||||||
{ typeof roomTopic !== 'undefined' && <p title={roomTopic} className="text text-b3">{roomTopic}</p>}
|
{ typeof roomTopic !== 'undefined' && <p title={roomTopic} className="text text-b3">{roomTopic}</p>}
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ import MarkdownIC from '../../../../public/res/ic/outlined/markdown.svg';
|
|||||||
import FileIC from '../../../../public/res/ic/outlined/file.svg';
|
import FileIC from '../../../../public/res/ic/outlined/file.svg';
|
||||||
import CrossIC from '../../../../public/res/ic/outlined/cross.svg';
|
import CrossIC from '../../../../public/res/ic/outlined/cross.svg';
|
||||||
|
|
||||||
const CMD_REGEX = /(\/|>[#*@]|:|@)(\S*)$/;
|
const CMD_REGEX = /(^\/|^>[#*@]|:|@)(\S*)$/;
|
||||||
let isTyping = false;
|
let isTyping = false;
|
||||||
let isCmdActivated = false;
|
let isCmdActivated = false;
|
||||||
let cmdCursorPos = null;
|
let cmdCursorPos = null;
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import PropTypes from 'prop-types';
|
|||||||
import './Settings.scss';
|
import './Settings.scss';
|
||||||
|
|
||||||
import initMatrix from '../../../client/initMatrix';
|
import initMatrix from '../../../client/initMatrix';
|
||||||
|
import cons from '../../../client/state/cons';
|
||||||
import settings from '../../../client/state/settings';
|
import settings from '../../../client/state/settings';
|
||||||
import { toggleMarkdown } from '../../../client/action/settings';
|
import { toggleMarkdown } from '../../../client/action/settings';
|
||||||
|
|
||||||
@@ -104,7 +105,7 @@ function AboutSection() {
|
|||||||
<div>
|
<div>
|
||||||
<Text variant="h2">
|
<Text variant="h2">
|
||||||
Cinny
|
Cinny
|
||||||
<span className="text text-b3" style={{ margin: '0 var(--sp-extra-tight)' }}>v1.4.0</span>
|
<span className="text text-b3" style={{ margin: '0 var(--sp-extra-tight)' }}>{`v${cons.version}`}</span>
|
||||||
</Text>
|
</Text>
|
||||||
<Text>Yet another matrix client</Text>
|
<Text>Yet another matrix client</Text>
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,14 @@
|
|||||||
import React, { useState, useRef } from 'react';
|
/* eslint-disable react/prop-types */
|
||||||
|
import React, { useState, useEffect, useRef } from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import './Auth.scss';
|
import './Auth.scss';
|
||||||
import ReCAPTCHA from 'react-google-recaptcha';
|
import ReCAPTCHA from 'react-google-recaptcha';
|
||||||
|
import { Formik } from 'formik';
|
||||||
|
|
||||||
import { useLocation } from 'react-router-dom';
|
|
||||||
import * as auth from '../../../client/action/auth';
|
import * as auth from '../../../client/action/auth';
|
||||||
import cons from '../../../client/state/cons';
|
import cons from '../../../client/state/cons';
|
||||||
|
import { Debounce, getUrlPrams } from '../../../util/common';
|
||||||
|
import { getBaseUrl } from '../../../util/matrixUtil';
|
||||||
|
|
||||||
import Text from '../../atoms/text/Text';
|
import Text from '../../atoms/text/Text';
|
||||||
import Button from '../../atoms/button/Button';
|
import Button from '../../atoms/button/Button';
|
||||||
@@ -13,356 +16,556 @@ import IconButton from '../../atoms/button/IconButton';
|
|||||||
import Input from '../../atoms/input/Input';
|
import Input from '../../atoms/input/Input';
|
||||||
import Spinner from '../../atoms/spinner/Spinner';
|
import Spinner from '../../atoms/spinner/Spinner';
|
||||||
import ScrollView from '../../atoms/scroll/ScrollView';
|
import ScrollView from '../../atoms/scroll/ScrollView';
|
||||||
|
import Header, { TitleWrapper } from '../../atoms/header/Header';
|
||||||
|
import Avatar from '../../atoms/avatar/Avatar';
|
||||||
|
import ContextMenu, { MenuItem, MenuHeader } from '../../atoms/context-menu/ContextMenu';
|
||||||
|
|
||||||
import EyeIC from '../../../../public/res/ic/outlined/eye.svg';
|
import ChevronBottomIC from '../../../../public/res/ic/outlined/chevron-bottom.svg';
|
||||||
import CinnySvg from '../../../../public/res/svg/cinny.svg';
|
import CinnySvg from '../../../../public/res/svg/cinny.svg';
|
||||||
import SSOButtons from '../../molecules/sso-buttons/SSOButtons';
|
import SSOButtons from '../../molecules/sso-buttons/SSOButtons';
|
||||||
|
|
||||||
// This regex validates historical usernames, which don't satisfy today's username requirements.
|
|
||||||
// See https://matrix.org/docs/spec/appendices#id13 for more info.
|
|
||||||
const LOCALPART_LOGIN_REGEX = /.*/;
|
|
||||||
const LOCALPART_SIGNUP_REGEX = /^[a-z0-9_\-.=/]+$/;
|
const LOCALPART_SIGNUP_REGEX = /^[a-z0-9_\-.=/]+$/;
|
||||||
const BAD_LOCALPART_ERROR = 'Username must contain only a-z, 0-9, ., _, =, -, and /.';
|
const BAD_LOCALPART_ERROR = 'Username can only contain characters a-z, 0-9, or \'=_-./\'';
|
||||||
const USER_ID_TOO_LONG_ERROR = 'Your user ID, including the hostname, can\'t be more than 255 characters long.';
|
const USER_ID_TOO_LONG_ERROR = 'Your user ID, including the hostname, can\'t be more than 255 characters long.';
|
||||||
|
|
||||||
const PASSWORD_REGEX = /.+/;
|
|
||||||
const PASSWORD_STRENGHT_REGEX = /^(?=.*\d)(?=.*[A-Z])(?=.*[a-z])(?=.*[^\w\d\s:])([^\s]){8,127}$/;
|
const PASSWORD_STRENGHT_REGEX = /^(?=.*\d)(?=.*[A-Z])(?=.*[a-z])(?=.*[^\w\d\s:])([^\s]){8,127}$/;
|
||||||
const BAD_PASSWORD_ERROR = 'Password must contain at least 1 number, 1 uppercase letter, 1 lowercase letter, 1 non-alphanumeric character. Passwords can range from 8-127 characters with no whitespaces.';
|
const BAD_PASSWORD_ERROR = 'Password must contain at least 1 lowercase, 1 uppercase, 1 number, 1 non-alphanumeric character, 8-127 characters with no space.';
|
||||||
const CONFIRM_PASSWORD_ERROR = 'Passwords don\'t match.';
|
const CONFIRM_PASSWORD_ERROR = 'Passwords don\'t match.';
|
||||||
|
|
||||||
const EMAIL_REGEX = /([a-z0-9]+[_a-z0-9.-][a-z0-9]+)@([a-z0-9-]+(?:.[a-z0-9-]+).[a-z]{2,4})/;
|
const EMAIL_REGEX = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}$/i;
|
||||||
const BAD_EMAIL_ERROR = 'Invalid email address';
|
const BAD_EMAIL_ERROR = 'Invalid email address';
|
||||||
|
|
||||||
function isValidInput(value, regex) {
|
function isValidInput(value, regex) {
|
||||||
if (typeof regex === 'string') return regex === value;
|
if (typeof regex === 'string') return regex === value;
|
||||||
return regex.test(value);
|
return regex.test(value);
|
||||||
}
|
}
|
||||||
function renderErrorMessage(error) {
|
|
||||||
const $error = document.getElementById('auth_error');
|
|
||||||
$error.textContent = error;
|
|
||||||
$error.style.display = 'block';
|
|
||||||
}
|
|
||||||
function showBadInputError($input, error, stopAutoFocus) {
|
|
||||||
renderErrorMessage(error);
|
|
||||||
if (!stopAutoFocus) $input.focus();
|
|
||||||
const myInput = $input;
|
|
||||||
myInput.style.border = '1px solid var(--bg-danger)';
|
|
||||||
myInput.style.boxShadow = 'none';
|
|
||||||
document.getElementById('auth_submit-btn').disabled = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
function validateOnChange(targetInput, regex, error, stopAutoFocus) {
|
|
||||||
if (!isValidInput(targetInput.value, regex) && targetInput.value) {
|
|
||||||
showBadInputError(targetInput, error, stopAutoFocus);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
document.getElementById('auth_error').style.display = 'none';
|
|
||||||
targetInput.style.removeProperty('border');
|
|
||||||
targetInput.style.removeProperty('box-shadow');
|
|
||||||
document.getElementById('auth_submit-btn').disabled = false;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Normalizes a username into a standard format.
|
|
||||||
*
|
|
||||||
* Removes leading and trailing whitespaces and leading "@" symbols.
|
|
||||||
* @param {string} rawUsername A raw-input username, which may include invalid characters.
|
|
||||||
* @returns {string}
|
|
||||||
*/
|
|
||||||
function normalizeUsername(rawUsername) {
|
function normalizeUsername(rawUsername) {
|
||||||
const noLeadingAt = rawUsername.indexOf('@') === 0 ? rawUsername.substr(1) : rawUsername;
|
const noLeadingAt = rawUsername.indexOf('@') === 0 ? rawUsername.substr(1) : rawUsername;
|
||||||
return noLeadingAt.trim();
|
return noLeadingAt.trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
function Auth() {
|
let searchingHs = null;
|
||||||
const [type, setType] = useState('login');
|
function Homeserver({ onChange }) {
|
||||||
const [process, changeProcess] = useState(null);
|
const [hs, setHs] = useState(null);
|
||||||
const [homeserver, changeHomeserver] = useState('matrix.org');
|
const [debounce] = useState(new Debounce());
|
||||||
|
const [process, setProcess] = useState({ isLoading: true, message: 'Loading homeserver list...' });
|
||||||
|
const hsRef = useRef();
|
||||||
|
|
||||||
const usernameRef = useRef(null);
|
const setupHsConfig = async (servername) => {
|
||||||
const homeserverRef = useRef(null);
|
setProcess({ isLoading: true, message: 'Looking for homeserver...' });
|
||||||
const passwordRef = useRef(null);
|
let baseUrl = null;
|
||||||
const confirmPasswordRef = useRef(null);
|
try {
|
||||||
const emailRef = useRef(null);
|
baseUrl = await getBaseUrl(servername);
|
||||||
|
} catch (e) {
|
||||||
const { search } = useLocation();
|
baseUrl = e.message;
|
||||||
const searchParams = new URLSearchParams(search);
|
|
||||||
if (searchParams.has('loginToken')) {
|
|
||||||
const loginToken = searchParams.get('loginToken');
|
|
||||||
if (loginToken !== undefined) {
|
|
||||||
if (localStorage.getItem(cons.secretKey.BASE_URL) !== undefined) {
|
|
||||||
const baseUrl = localStorage.getItem(cons.secretKey.BASE_URL);
|
|
||||||
auth.loginWithToken(baseUrl, loginToken)
|
|
||||||
.then(() => {
|
|
||||||
const { href } = window.location;
|
|
||||||
window.location.replace(href.slice(0, href.indexOf('?')));
|
|
||||||
})
|
|
||||||
.catch((error) => {
|
|
||||||
changeProcess(null);
|
|
||||||
if (!error.contains('CORS request rejected')) {
|
|
||||||
renderErrorMessage(error);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
if (searchingHs !== servername) return;
|
||||||
|
setProcess({ isLoading: true, message: `Connecting to ${baseUrl}...` });
|
||||||
|
const tempClient = auth.createTemporaryClient(baseUrl);
|
||||||
|
|
||||||
function register(recaptchaValue, terms, verified) {
|
Promise.allSettled([tempClient.loginFlows(), tempClient.register()])
|
||||||
auth.register(
|
.then((values) => {
|
||||||
usernameRef.current.value,
|
const loginFlow = values[0].status === 'fulfilled' ? values[0]?.value : undefined;
|
||||||
homeserverRef.current.value,
|
const registerFlow = values[1].status === 'rejected' ? values[1]?.reason?.data : undefined;
|
||||||
passwordRef.current.value,
|
if (loginFlow === undefined || registerFlow === undefined) throw new Error();
|
||||||
emailRef.current.value,
|
|
||||||
recaptchaValue,
|
|
||||||
terms,
|
|
||||||
verified,
|
|
||||||
).then((res) => {
|
|
||||||
document.getElementById('auth_submit-btn').disabled = false;
|
|
||||||
if (res.type === 'recaptcha') {
|
|
||||||
changeProcess({ type: res.type, sitekey: res.public_key });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (res.type === 'terms') {
|
|
||||||
changeProcess({ type: res.type, en: res.en });
|
|
||||||
}
|
|
||||||
if (res.type === 'email') {
|
|
||||||
changeProcess({ type: res.type });
|
|
||||||
}
|
|
||||||
if (res.type === 'done') {
|
|
||||||
window.location.replace('/');
|
|
||||||
}
|
|
||||||
}).catch((error) => {
|
|
||||||
changeProcess(null);
|
|
||||||
renderErrorMessage(error);
|
|
||||||
document.getElementById('auth_submit-btn').disabled = false;
|
|
||||||
});
|
|
||||||
if (terms) {
|
|
||||||
changeProcess({ type: 'loading', message: 'Sending email verification link...' });
|
|
||||||
} else changeProcess({ type: 'loading', message: 'Registration in progress...' });
|
|
||||||
}
|
|
||||||
|
|
||||||
function handleLogin(e) {
|
if (searchingHs !== servername) return;
|
||||||
e.preventDefault();
|
onChange({ baseUrl, login: loginFlow, register: registerFlow });
|
||||||
document.getElementById('auth_submit-btn').disabled = true;
|
setProcess({ isLoading: false });
|
||||||
document.getElementById('auth_error').style.display = 'none';
|
}).catch(() => {
|
||||||
|
if (searchingHs !== servername) return;
|
||||||
/** @type {string} */
|
onChange(null);
|
||||||
const rawUsername = usernameRef.current.value;
|
setProcess({ isLoading: false, error: 'Unable to connect. Please check your input.' });
|
||||||
/** @type {string} */
|
|
||||||
const normalizedUsername = normalizeUsername(rawUsername);
|
|
||||||
|
|
||||||
auth.login(normalizedUsername, homeserverRef.current.value, passwordRef.current.value)
|
|
||||||
.then(() => {
|
|
||||||
document.getElementById('auth_submit-btn').disabled = false;
|
|
||||||
window.location.replace('/');
|
|
||||||
})
|
|
||||||
.catch((error) => {
|
|
||||||
changeProcess(null);
|
|
||||||
renderErrorMessage(error);
|
|
||||||
document.getElementById('auth_submit-btn').disabled = false;
|
|
||||||
});
|
});
|
||||||
changeProcess({ type: 'loading', message: 'Login in progress...' });
|
};
|
||||||
}
|
|
||||||
|
|
||||||
function handleRegister(e) {
|
useEffect(() => {
|
||||||
e.preventDefault();
|
onChange(null);
|
||||||
document.getElementById('auth_submit-btn').disabled = true;
|
if (hs === null || hs?.selected.trim() === '') return;
|
||||||
document.getElementById('auth_error').style.display = 'none';
|
searchingHs = hs.selected;
|
||||||
|
setupHsConfig(hs.selected);
|
||||||
|
}, [hs]);
|
||||||
|
|
||||||
if (!isValidInput(usernameRef.current.value, LOCALPART_SIGNUP_REGEX)) {
|
useEffect(async () => {
|
||||||
showBadInputError(usernameRef.current, BAD_LOCALPART_ERROR);
|
const link = window.location.href;
|
||||||
return;
|
const configFileUrl = `${link}${link[link.length - 1] === '/' ? '' : '/'}config.json`;
|
||||||
|
try {
|
||||||
|
const result = await (await fetch(configFileUrl, { method: 'GET' })).json();
|
||||||
|
const selectedHs = result?.defaultHomeserver;
|
||||||
|
const hsList = result?.homeserverList;
|
||||||
|
if (!hsList?.length > 0 || selectedHs < 0 || selectedHs >= hsList?.length) {
|
||||||
|
throw new Error();
|
||||||
|
}
|
||||||
|
setHs({ selected: hsList[selectedHs], list: hsList });
|
||||||
|
} catch {
|
||||||
|
setHs({ selected: 'matrix.org', list: ['matrix.org'] });
|
||||||
}
|
}
|
||||||
if (!isValidInput(passwordRef.current.value, PASSWORD_STRENGHT_REGEX)) {
|
}, []);
|
||||||
showBadInputError(passwordRef.current, BAD_PASSWORD_ERROR);
|
|
||||||
return;
|
const handleHsInput = (e) => {
|
||||||
}
|
const { value } = e.target;
|
||||||
if (passwordRef.current.value !== confirmPasswordRef.current.value) {
|
setProcess({ isLoading: false });
|
||||||
showBadInputError(confirmPasswordRef.current, CONFIRM_PASSWORD_ERROR);
|
debounce._(async () => {
|
||||||
return;
|
setHs({ selected: value, list: hs.list });
|
||||||
}
|
}, 700)();
|
||||||
if (!isValidInput(emailRef.current.value, EMAIL_REGEX)) {
|
};
|
||||||
showBadInputError(emailRef.current, BAD_EMAIL_ERROR);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (`@${usernameRef.current.value}:${homeserverRef.current.value}`.length > 255) {
|
|
||||||
showBadInputError(usernameRef.current, USER_ID_TOO_LONG_ERROR);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
register();
|
|
||||||
}
|
|
||||||
|
|
||||||
const handleAuth = (type === 'login') ? handleLogin : handleRegister;
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{process?.type === 'loading' && <LoadingScreen message={process.message} />}
|
<div className="homeserver-form">
|
||||||
{process?.type === 'recaptcha' && <Recaptcha message="Please check the box below to proceed." sitekey={process.sitekey} onChange={(v) => { if (typeof v === 'string') register(v); }} />}
|
<Input name="homeserver" onChange={handleHsInput} value={hs?.selected} forwardRef={hsRef} label="Homeserver" />
|
||||||
{process?.type === 'terms' && <Terms url={process.en.url} onSubmit={register} />}
|
<ContextMenu
|
||||||
{process?.type === 'email' && (
|
placement="right"
|
||||||
<ProcessWrapper>
|
content={(hideMenu) => (
|
||||||
<div style={{ margin: 'var(--sp-normal)', maxWidth: '450px' }}>
|
<>
|
||||||
<Text variant="h2">Verify email</Text>
|
<MenuHeader>Homeserver list</MenuHeader>
|
||||||
<div style={{ margin: 'var(--sp-normal) 0' }}>
|
{
|
||||||
<Text variant="b1">
|
hs?.list.map((hsName) => (
|
||||||
Please check your email
|
<MenuItem
|
||||||
{' '}
|
key={hsName}
|
||||||
<b>{`(${emailRef.current.value})`}</b>
|
|
||||||
{' '}
|
|
||||||
and validate before continuing further.
|
|
||||||
</Text>
|
|
||||||
</div>
|
|
||||||
<Button variant="primary" onClick={() => register(undefined, undefined, true)}>Continue</Button>
|
|
||||||
</div>
|
|
||||||
</ProcessWrapper>
|
|
||||||
)}
|
|
||||||
<StaticWrapper>
|
|
||||||
<div className="auth-form__wrapper flex-v--center">
|
|
||||||
<form onSubmit={handleAuth} className="auth-form">
|
|
||||||
<Text variant="h2">{ type === 'login' ? 'Login' : 'Register' }</Text>
|
|
||||||
<div className="username__wrapper">
|
|
||||||
<Input
|
|
||||||
forwardRef={usernameRef}
|
|
||||||
onChange={(e) => (type === 'login'
|
|
||||||
? validateOnChange(e.target, LOCALPART_LOGIN_REGEX, BAD_LOCALPART_ERROR)
|
|
||||||
: validateOnChange(e.target, LOCALPART_SIGNUP_REGEX, BAD_LOCALPART_ERROR))}
|
|
||||||
id="auth_username"
|
|
||||||
label="Username"
|
|
||||||
required
|
|
||||||
/>
|
|
||||||
<Input
|
|
||||||
forwardRef={homeserverRef}
|
|
||||||
onChange={(e) => changeHomeserver(e.target.value)}
|
|
||||||
id="auth_homeserver"
|
|
||||||
placeholder="Homeserver"
|
|
||||||
value="matrix.org"
|
|
||||||
required
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
<div className="password__wrapper">
|
|
||||||
<Input
|
|
||||||
forwardRef={passwordRef}
|
|
||||||
onChange={(e) => {
|
|
||||||
const isValidPass = validateOnChange(e.target, ((type === 'login') ? PASSWORD_REGEX : PASSWORD_STRENGHT_REGEX), BAD_PASSWORD_ERROR);
|
|
||||||
if (type === 'register' && isValidPass) {
|
|
||||||
validateOnChange(
|
|
||||||
confirmPasswordRef.current, passwordRef.current.value,
|
|
||||||
CONFIRM_PASSWORD_ERROR, true,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
id="auth_password"
|
|
||||||
type="password"
|
|
||||||
label="Password"
|
|
||||||
required
|
|
||||||
/>
|
|
||||||
<IconButton
|
|
||||||
onClick={() => {
|
|
||||||
if (passwordRef.current.type === 'password') {
|
|
||||||
passwordRef.current.type = 'text';
|
|
||||||
} else passwordRef.current.type = 'password';
|
|
||||||
}}
|
|
||||||
size="extra-small"
|
|
||||||
src={EyeIC}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
{type === 'register' && (
|
|
||||||
<>
|
|
||||||
<div className="password__wrapper">
|
|
||||||
<Input
|
|
||||||
forwardRef={confirmPasswordRef}
|
|
||||||
onChange={(e) => {
|
|
||||||
validateOnChange(e.target, passwordRef.current.value, CONFIRM_PASSWORD_ERROR);
|
|
||||||
}}
|
|
||||||
id="auth_confirmPassword"
|
|
||||||
type="password"
|
|
||||||
label="Confirm password"
|
|
||||||
required
|
|
||||||
/>
|
|
||||||
<IconButton
|
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
if (confirmPasswordRef.current.type === 'password') {
|
hideMenu();
|
||||||
confirmPasswordRef.current.type = 'text';
|
hsRef.current.value = hsName;
|
||||||
} else confirmPasswordRef.current.type = 'password';
|
setHs({ selected: hsName, list: hs.list });
|
||||||
}}
|
}}
|
||||||
size="extra-small"
|
>
|
||||||
src={EyeIC}
|
{hsName}
|
||||||
/>
|
</MenuItem>
|
||||||
</div>
|
))
|
||||||
<Input
|
}
|
||||||
forwardRef={emailRef}
|
</>
|
||||||
onChange={(e) => validateOnChange(e.target, EMAIL_REGEX, BAD_EMAIL_ERROR)}
|
)}
|
||||||
id="auth_email"
|
render={(toggleMenu) => <IconButton onClick={toggleMenu} src={ChevronBottomIC} />}
|
||||||
type="email"
|
/>
|
||||||
label="Email"
|
</div>
|
||||||
required
|
{process.error !== undefined && <Text className="homeserver-form__error" variant="b3">{process.error}</Text>}
|
||||||
/>
|
{process.isLoading && (
|
||||||
</>
|
<div className="homeserver-form__status flex--center">
|
||||||
)}
|
<Spinner size="small" />
|
||||||
<div className="submit-btn__wrapper flex--end">
|
<Text variant="b2">{process.message}</Text>
|
||||||
<Text id="auth_error" className="error-message" variant="b3">Error</Text>
|
|
||||||
<Button
|
|
||||||
id="auth_submit-btn"
|
|
||||||
variant="primary"
|
|
||||||
type="submit"
|
|
||||||
>
|
|
||||||
{type === 'login' ? 'Login' : 'Register' }
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
{type === 'login' && (
|
|
||||||
<SSOButtons homeserver={homeserver} />
|
|
||||||
)}
|
|
||||||
</form>
|
|
||||||
</div>
|
</div>
|
||||||
|
)}
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
Homeserver.propTypes = {
|
||||||
|
onChange: PropTypes.func.isRequired,
|
||||||
|
};
|
||||||
|
|
||||||
<div style={{ flexDirection: 'column' }} className="flex--center">
|
function Login({ loginFlow, baseUrl }) {
|
||||||
<Text variant="b2">
|
const [typeIndex, setTypeIndex] = useState(0);
|
||||||
{`${(type === 'login' ? 'Don\'t have' : 'Already have')} an account?`}
|
const loginTypes = ['Username', 'Email'];
|
||||||
<button
|
const isPassword = loginFlow?.filter((flow) => flow.type === 'm.login.password')[0];
|
||||||
type="button"
|
const ssoProviders = loginFlow?.filter((flow) => flow.type === 'm.login.sso')[0];
|
||||||
style={{ color: 'var(--tc-link)', cursor: 'pointer', margin: '0 var(--sp-ultra-tight)' }}
|
|
||||||
onClick={() => {
|
const initialValues = {
|
||||||
if (type === 'login') setType('register');
|
username: '', password: '', email: '', other: '',
|
||||||
else setType('login');
|
};
|
||||||
}}
|
|
||||||
>
|
const validator = (values) => {
|
||||||
{ type === 'login' ? ' Register' : ' Login' }
|
const errors = {};
|
||||||
</button>
|
if (typeIndex === 0 && values.username.length > 0 && values.username.indexOf(':') > -1) {
|
||||||
</Text>
|
errors.username = 'Username must contain local-part only';
|
||||||
<span style={{ marginTop: 'var(--sp-extra-tight)' }}>
|
}
|
||||||
<Text variant="b3">v1.4.0</Text>
|
if (typeIndex === 1 && values.email.length > 0 && !isValidInput(values.email, EMAIL_REGEX)) {
|
||||||
</span>
|
errors.email = BAD_EMAIL_ERROR;
|
||||||
</div>
|
}
|
||||||
</StaticWrapper>
|
return errors;
|
||||||
|
};
|
||||||
|
const submitter = (values, actions) => auth.login(
|
||||||
|
baseUrl,
|
||||||
|
typeIndex === 0 ? normalizeUsername(values.username) : undefined,
|
||||||
|
typeIndex === 1 ? values.email : undefined,
|
||||||
|
values.password,
|
||||||
|
).then(() => {
|
||||||
|
actions.setSubmitting(true);
|
||||||
|
window.location.reload();
|
||||||
|
}).catch((error) => {
|
||||||
|
let msg = error.message;
|
||||||
|
if (msg === 'Unknown message') msg = 'Please check your credentials';
|
||||||
|
actions.setErrors({
|
||||||
|
password: msg === 'Invalid password' ? msg : undefined,
|
||||||
|
other: msg !== 'Invalid password' ? msg : undefined,
|
||||||
|
});
|
||||||
|
actions.setSubmitting(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<div className="auth-form__heading">
|
||||||
|
<Text variant="h2">Login</Text>
|
||||||
|
{isPassword && (
|
||||||
|
<ContextMenu
|
||||||
|
placement="right"
|
||||||
|
content={(hideMenu) => (
|
||||||
|
loginTypes.map((type, index) => (
|
||||||
|
<MenuItem
|
||||||
|
key={type}
|
||||||
|
onClick={() => {
|
||||||
|
hideMenu();
|
||||||
|
setTypeIndex(index);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{type}
|
||||||
|
</MenuItem>
|
||||||
|
))
|
||||||
|
)}
|
||||||
|
render={(toggleMenu) => (
|
||||||
|
<Button onClick={toggleMenu} iconSrc={ChevronBottomIC}>
|
||||||
|
{loginTypes[typeIndex]}
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
{isPassword && (
|
||||||
|
<Formik
|
||||||
|
initialValues={initialValues}
|
||||||
|
onSubmit={submitter}
|
||||||
|
validate={validator}
|
||||||
|
>
|
||||||
|
{({
|
||||||
|
values, errors, handleChange, handleSubmit, isSubmitting,
|
||||||
|
}) => (
|
||||||
|
<>
|
||||||
|
{isSubmitting && <LoadingScreen message="Login in progress..." />}
|
||||||
|
<form className="auth-form" onSubmit={handleSubmit}>
|
||||||
|
{typeIndex === 0 && <Input values={values.username} name="username" onChange={handleChange} label="Username" type="username" required />}
|
||||||
|
{errors.username && <Text className="auth-form__error" variant="b3">{errors.username}</Text>}
|
||||||
|
{typeIndex === 1 && <Input values={values.email} name="email" onChange={handleChange} label="Email" type="email" required />}
|
||||||
|
{errors.email && <Text className="auth-form__error" variant="b3">{errors.email}</Text>}
|
||||||
|
<Input values={values.password} name="password" onChange={handleChange} label="Password" type="password" required />
|
||||||
|
{errors.password && <Text className="auth-form__error" variant="b3">{errors.password}</Text>}
|
||||||
|
{errors.other && <Text className="auth-form__error" variant="b3">{errors.other}</Text>}
|
||||||
|
<div className="auth-form__btns">
|
||||||
|
<Button variant="primary" type="submit" disabled={isSubmitting}>Login</Button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</Formik>
|
||||||
|
)}
|
||||||
|
{ssoProviders && isPassword && <Text className="sso__divider">OR</Text>}
|
||||||
|
{ssoProviders && (
|
||||||
|
<SSOButtons
|
||||||
|
type="sso"
|
||||||
|
identityProviders={ssoProviders.identity_providers}
|
||||||
|
baseUrl={baseUrl}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
Login.propTypes = {
|
||||||
|
loginFlow: PropTypes.arrayOf(
|
||||||
|
PropTypes.shape({}),
|
||||||
|
).isRequired,
|
||||||
|
baseUrl: PropTypes.string.isRequired,
|
||||||
|
};
|
||||||
|
|
||||||
|
let sid;
|
||||||
|
let clientSecret;
|
||||||
|
function Register({ registerInfo, loginFlow, baseUrl }) {
|
||||||
|
const [process, setProcess] = useState({});
|
||||||
|
const formRef = useRef();
|
||||||
|
|
||||||
|
const ssoProviders = loginFlow?.filter((flow) => flow.type === 'm.login.sso')[0];
|
||||||
|
const isDisabled = registerInfo.errcode !== undefined;
|
||||||
|
const { flows, params, session } = registerInfo;
|
||||||
|
|
||||||
|
let isEmail = false;
|
||||||
|
let isEmailRequired = true;
|
||||||
|
let isRecaptcha = false;
|
||||||
|
let isTerms = false;
|
||||||
|
let isDummy = false;
|
||||||
|
|
||||||
|
flows?.forEach((flow) => {
|
||||||
|
if (isEmailRequired && flow.stages.indexOf('m.login.email.identity') === -1) isEmailRequired = false;
|
||||||
|
if (!isEmail) isEmail = flow.stages.indexOf('m.login.email.identity') > -1;
|
||||||
|
if (!isRecaptcha) isRecaptcha = flow.stages.indexOf('m.login.recaptcha') > -1;
|
||||||
|
if (!isTerms) isTerms = flow.stages.indexOf('m.login.terms') > -1;
|
||||||
|
if (!isDummy) isDummy = flow.stages.indexOf('m.login.dummy') > -1;
|
||||||
|
});
|
||||||
|
|
||||||
|
const initialValues = {
|
||||||
|
username: '', password: '', confirmPassword: '', email: '', other: '',
|
||||||
|
};
|
||||||
|
|
||||||
|
const validator = (values) => {
|
||||||
|
const errors = {};
|
||||||
|
if (values.username.list > 255) errors.username = USER_ID_TOO_LONG_ERROR;
|
||||||
|
if (values.username.length > 0 && !isValidInput(values.username, LOCALPART_SIGNUP_REGEX)) {
|
||||||
|
errors.username = BAD_LOCALPART_ERROR;
|
||||||
|
}
|
||||||
|
if (values.password.length > 0 && !isValidInput(values.password, PASSWORD_STRENGHT_REGEX)) {
|
||||||
|
errors.password = BAD_PASSWORD_ERROR;
|
||||||
|
}
|
||||||
|
if (values.confirmPassword.length > 0
|
||||||
|
&& !isValidInput(values.confirmPassword, values.password)) {
|
||||||
|
errors.confirmPassword = CONFIRM_PASSWORD_ERROR;
|
||||||
|
}
|
||||||
|
if (values.email.length > 0 && !isValidInput(values.email, EMAIL_REGEX)) {
|
||||||
|
errors.email = BAD_EMAIL_ERROR;
|
||||||
|
}
|
||||||
|
return errors;
|
||||||
|
};
|
||||||
|
const submitter = (values, actions) => {
|
||||||
|
const tempClient = auth.createTemporaryClient(baseUrl);
|
||||||
|
clientSecret = tempClient.generateClientSecret();
|
||||||
|
return tempClient.isUsernameAvailable(values.username)
|
||||||
|
.then(async (isAvail) => {
|
||||||
|
if (!isAvail) {
|
||||||
|
actions.setErrors({ username: 'Username is already taken' });
|
||||||
|
actions.setSubmitting(false);
|
||||||
|
}
|
||||||
|
if (isEmail && values.email.length > 0) {
|
||||||
|
const result = await auth.verifyEmail(baseUrl, values.email, clientSecret, 1);
|
||||||
|
if (result.errcode) {
|
||||||
|
if (result.errcode === 'M_THREEPID_IN_USE') actions.setErrors({ email: result.error });
|
||||||
|
else actions.setErrors({ others: result.error || result.message });
|
||||||
|
actions.setSubmitting(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
sid = result.sid;
|
||||||
|
}
|
||||||
|
setProcess({ type: 'processing', message: 'Registration in progress....' });
|
||||||
|
actions.setSubmitting(false);
|
||||||
|
}).catch((err) => {
|
||||||
|
const msg = err.message || err.error;
|
||||||
|
if (['M_USER_IN_USE', 'M_INVALID_USERNAME', 'M_EXCLUSIVE'].indexOf(err.errcode) > -1) {
|
||||||
|
actions.setErrors({ username: err.errcode === 'M_USER_IN_USE' ? 'Username is already taken' : msg });
|
||||||
|
} else if (msg) actions.setErrors({ other: msg });
|
||||||
|
|
||||||
|
actions.setSubmitting(false);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const refreshWindow = () => window.location.reload();
|
||||||
|
|
||||||
|
const getInputs = () => {
|
||||||
|
const f = formRef.current;
|
||||||
|
return [f.username.value, f.password.value, f?.email?.value];
|
||||||
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (process.type !== 'processing') return;
|
||||||
|
const asyncProcess = async () => {
|
||||||
|
const [username, password, email] = getInputs();
|
||||||
|
const d = await auth.completeRegisterStage(baseUrl, username, password, { session });
|
||||||
|
|
||||||
|
if (isRecaptcha && !d.completed.includes('m.login.recaptcha')) {
|
||||||
|
const sitekey = params['m.login.recaptcha'].public_key;
|
||||||
|
setProcess({ type: 'm.login.recaptcha', sitekey });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (isTerms && !d.completed.includes('m.login.terms')) {
|
||||||
|
const pp = params['m.login.terms'].policies.privacy_policy;
|
||||||
|
const url = pp?.en.url || pp[Object.keys(pp)[0]].url;
|
||||||
|
setProcess({ type: 'm.login.terms', url });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (isEmail && email.length > 0) {
|
||||||
|
setProcess({ type: 'm.login.email.identity', email });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (isDummy) {
|
||||||
|
const data = await auth.completeRegisterStage(baseUrl, username, password, {
|
||||||
|
type: 'm.login.dummy',
|
||||||
|
session,
|
||||||
|
});
|
||||||
|
if (data.done) refreshWindow();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
asyncProcess();
|
||||||
|
}, [process]);
|
||||||
|
|
||||||
|
const handleRecaptcha = async (value) => {
|
||||||
|
if (typeof value !== 'string') return;
|
||||||
|
const [username, password] = getInputs();
|
||||||
|
const d = await auth.completeRegisterStage(baseUrl, username, password, {
|
||||||
|
type: 'm.login.recaptcha',
|
||||||
|
response: value,
|
||||||
|
session,
|
||||||
|
});
|
||||||
|
if (d.done) refreshWindow();
|
||||||
|
else setProcess({ type: 'processing', message: 'Registration in progress...' });
|
||||||
|
};
|
||||||
|
const handleTerms = async () => {
|
||||||
|
const [username, password] = getInputs();
|
||||||
|
const d = await auth.completeRegisterStage(baseUrl, username, password, {
|
||||||
|
type: 'm.login.terms',
|
||||||
|
session,
|
||||||
|
});
|
||||||
|
if (d.done) refreshWindow();
|
||||||
|
else setProcess({ type: 'processing', message: 'Registration in progress...' });
|
||||||
|
};
|
||||||
|
const handleEmailVerify = async () => {
|
||||||
|
const [username, password] = getInputs();
|
||||||
|
const d = await auth.completeRegisterStage(baseUrl, username, password, {
|
||||||
|
type: 'm.login.email.identity',
|
||||||
|
threepidCreds: { sid, client_secret: clientSecret },
|
||||||
|
threepid_creds: { sid, client_secret: clientSecret },
|
||||||
|
session,
|
||||||
|
});
|
||||||
|
if (d.done) refreshWindow();
|
||||||
|
else setProcess({ type: 'processing', message: 'Registration in progress...' });
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
{process.type === 'processing' && <LoadingScreen message={process.message} />}
|
||||||
|
{process.type === 'm.login.recaptcha' && <Recaptcha message="Please check the box below to proceed." sitekey={process.sitekey} onChange={handleRecaptcha} />}
|
||||||
|
{process.type === 'm.login.terms' && <Terms url={process.url} onSubmit={handleTerms} />}
|
||||||
|
{process.type === 'm.login.email.identity' && <EmailVerify email={process.email} onContinue={handleEmailVerify} />}
|
||||||
|
<div className="auth-form__heading">
|
||||||
|
{!isDisabled && <Text variant="h2">Register</Text>}
|
||||||
|
{isDisabled && <Text className="auth-form__error">{registerInfo.error}</Text>}
|
||||||
|
</div>
|
||||||
|
{!isDisabled && (
|
||||||
|
<Formik
|
||||||
|
initialValues={initialValues}
|
||||||
|
onSubmit={submitter}
|
||||||
|
validate={validator}
|
||||||
|
>
|
||||||
|
{({
|
||||||
|
values, errors, handleChange, handleSubmit, isSubmitting,
|
||||||
|
}) => (
|
||||||
|
<>
|
||||||
|
{process.type === undefined && isSubmitting && <LoadingScreen message="Registration in progress..." />}
|
||||||
|
<form className="auth-form" ref={formRef} onSubmit={handleSubmit}>
|
||||||
|
<Input values={values.username} name="username" onChange={handleChange} label="Username" type="username" required />
|
||||||
|
{errors.username && <Text className="auth-form__error" variant="b3">{errors.username}</Text>}
|
||||||
|
<Input values={values.password} name="password" onChange={handleChange} label="Password" type="password" required />
|
||||||
|
{errors.password && <Text className="auth-form__error" variant="b3">{errors.password}</Text>}
|
||||||
|
<Input values={values.confirmPassword} name="confirmPassword" onChange={handleChange} label="Confirm password" type="password" required />
|
||||||
|
{errors.confirmPassword && <Text className="auth-form__error" variant="b3">{errors.confirmPassword}</Text>}
|
||||||
|
{isEmail && <Input values={values.email} name="email" onChange={handleChange} label={`Email${isEmailRequired ? '' : ' (optional)'}`} type="email" required={isEmailRequired} />}
|
||||||
|
{errors.email && <Text className="auth-form__error" variant="b3">{errors.email}</Text>}
|
||||||
|
{errors.other && <Text className="auth-form__error" variant="b3">{errors.other}</Text>}
|
||||||
|
<div className="auth-form__btns">
|
||||||
|
<Button variant="primary" type="submit" disabled={isSubmitting}>Register</Button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</Formik>
|
||||||
|
)}
|
||||||
|
{isDisabled && ssoProviders && (
|
||||||
|
<SSOButtons
|
||||||
|
type="sso"
|
||||||
|
identityProviders={ssoProviders.identity_providers}
|
||||||
|
baseUrl={baseUrl}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
Register.propTypes = {
|
||||||
|
registerInfo: PropTypes.shape({}).isRequired,
|
||||||
|
loginFlow: PropTypes.arrayOf(
|
||||||
|
PropTypes.shape({}),
|
||||||
|
).isRequired,
|
||||||
|
baseUrl: PropTypes.string.isRequired,
|
||||||
|
};
|
||||||
|
|
||||||
|
function AuthCard() {
|
||||||
|
const [hsConfig, setHsConfig] = useState(null);
|
||||||
|
const [type, setType] = useState('login');
|
||||||
|
|
||||||
|
const handleHsChange = (info) => {
|
||||||
|
console.log(info);
|
||||||
|
setHsConfig(info);
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Homeserver onChange={handleHsChange} />
|
||||||
|
{ hsConfig !== null && (
|
||||||
|
type === 'login'
|
||||||
|
? <Login loginFlow={hsConfig.login.flows} baseUrl={hsConfig.baseUrl} />
|
||||||
|
: (
|
||||||
|
<Register
|
||||||
|
registerInfo={hsConfig.register}
|
||||||
|
loginFlow={hsConfig.login.flows}
|
||||||
|
baseUrl={hsConfig.baseUrl}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
)}
|
||||||
|
{ hsConfig !== null && (
|
||||||
|
<Text variant="b2" className="auth-card__switch flex--center">
|
||||||
|
{`${(type === 'login' ? 'Don\'t have' : 'Already have')} an account?`}
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
style={{ color: 'var(--tc-link)', cursor: 'pointer', margin: '0 var(--sp-ultra-tight)' }}
|
||||||
|
onClick={() => setType((type === 'login') ? 'register' : 'login')}
|
||||||
|
>
|
||||||
|
{ type === 'login' ? ' Register' : ' Login' }
|
||||||
|
</button>
|
||||||
|
</Text>
|
||||||
|
)}
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function StaticWrapper({ children }) {
|
function Auth() {
|
||||||
|
const [loginToken, setLoginToken] = useState(getUrlPrams('loginToken'));
|
||||||
|
|
||||||
|
useEffect(async () => {
|
||||||
|
if (!loginToken) return;
|
||||||
|
if (localStorage.getItem(cons.secretKey.BASE_URL) === undefined) {
|
||||||
|
setLoginToken(null);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const baseUrl = localStorage.getItem(cons.secretKey.BASE_URL);
|
||||||
|
try {
|
||||||
|
await auth.loginWithToken(baseUrl, loginToken);
|
||||||
|
|
||||||
|
const { href } = window.location;
|
||||||
|
window.location.replace(href.slice(0, href.indexOf('?')));
|
||||||
|
} catch {
|
||||||
|
setLoginToken(null);
|
||||||
|
}
|
||||||
|
}, []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ScrollView invisible>
|
<ScrollView invisible>
|
||||||
<div className="auth__wrapper flex--center">
|
<div className="auth__base">
|
||||||
<div className="auth-card">
|
<div className="auth__wrapper">
|
||||||
<div className="auth-card__interactive flex-v">
|
{loginToken && <LoadingScreen message="Redirecting..." />}
|
||||||
<div className="app-ident flex">
|
{!loginToken && (
|
||||||
<img className="app-ident__logo noselect" src={CinnySvg} alt="Cinny logo" />
|
<div className="auth-card flex-v">
|
||||||
<div className="app-ident__text flex-v--center">
|
<Header>
|
||||||
<Text variant="h2">Cinny</Text>
|
<Avatar size="extra-small" imageSrc={CinnySvg} />
|
||||||
<Text variant="b2">Yet another matrix client</Text>
|
<TitleWrapper>
|
||||||
|
<Text variant="h2">Cinny</Text>
|
||||||
|
</TitleWrapper>
|
||||||
|
</Header>
|
||||||
|
<div className="auth-card__content">
|
||||||
|
<AuthCard />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{ children }
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div className="auth-footer">
|
||||||
|
<Text variant="b2">
|
||||||
|
<a href="https://cinny.in" target="_blank" rel="noreferrer">About</a>
|
||||||
|
</Text>
|
||||||
|
<Text variant="b2">
|
||||||
|
<a href="https://github.com/ajbura/cinny/releases" target="_blank" rel="noreferrer">{`v${cons.version}`}</a>
|
||||||
|
</Text>
|
||||||
|
<Text variant="b2">
|
||||||
|
<a href="https://twitter.com/cinnyapp" target="_blank" rel="noreferrer">Twitter</a>
|
||||||
|
</Text>
|
||||||
|
<Text variant="b2">
|
||||||
|
<a href="https://matrix.org" target="_blank" rel="noreferrer">Powered by Matrix</a>
|
||||||
|
</Text>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</ScrollView>
|
</ScrollView>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
StaticWrapper.propTypes = {
|
|
||||||
children: PropTypes.node.isRequired,
|
|
||||||
};
|
|
||||||
|
|
||||||
function LoadingScreen({ message }) {
|
function LoadingScreen({ message }) {
|
||||||
return (
|
return (
|
||||||
<ProcessWrapper>
|
<ProcessWrapper>
|
||||||
@@ -396,7 +599,7 @@ Recaptcha.propTypes = {
|
|||||||
function Terms({ url, onSubmit }) {
|
function Terms({ url, onSubmit }) {
|
||||||
return (
|
return (
|
||||||
<ProcessWrapper>
|
<ProcessWrapper>
|
||||||
<form onSubmit={() => onSubmit(undefined, true)}>
|
<form onSubmit={(e) => { e.preventDefault(); onSubmit(); }}>
|
||||||
<div style={{ margin: 'var(--sp-normal)', maxWidth: '450px' }}>
|
<div style={{ margin: 'var(--sp-normal)', maxWidth: '450px' }}>
|
||||||
<Text variant="h2">Agree with terms</Text>
|
<Text variant="h2">Agree with terms</Text>
|
||||||
<div style={{ marginBottom: 'var(--sp-normal)' }} />
|
<div style={{ marginBottom: 'var(--sp-normal)' }} />
|
||||||
@@ -419,6 +622,27 @@ Terms.propTypes = {
|
|||||||
onSubmit: PropTypes.func.isRequired,
|
onSubmit: PropTypes.func.isRequired,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function EmailVerify({ email, onContinue }) {
|
||||||
|
return (
|
||||||
|
<ProcessWrapper>
|
||||||
|
<div style={{ margin: 'var(--sp-normal)', maxWidth: '450px' }}>
|
||||||
|
<Text variant="h2">Verify email</Text>
|
||||||
|
<div style={{ margin: 'var(--sp-normal) 0' }}>
|
||||||
|
<Text variant="b1">
|
||||||
|
{'Please check your email '}
|
||||||
|
<b>{`(${email})`}</b>
|
||||||
|
{' and validate before continuing further.'}
|
||||||
|
</Text>
|
||||||
|
</div>
|
||||||
|
<Button variant="primary" onClick={onContinue}>Continue</Button>
|
||||||
|
</div>
|
||||||
|
</ProcessWrapper>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
EmailVerify.propTypes = {
|
||||||
|
email: PropTypes.string.isRequired,
|
||||||
|
};
|
||||||
|
|
||||||
function ProcessWrapper({ children }) {
|
function ProcessWrapper({ children }) {
|
||||||
return (
|
return (
|
||||||
<div className="process-wrapper">
|
<div className="process-wrapper">
|
||||||
|
|||||||
@@ -1,156 +1,144 @@
|
|||||||
.auth__wrapper {
|
.auth__base {
|
||||||
min-height: 100vh;
|
--pattern-size: 48px;
|
||||||
padding: var(--sp-loose);
|
min-height: 100%;
|
||||||
background-color: var(--bg-surface-low);
|
background-color: var(--bg-surface-low);
|
||||||
|
|
||||||
background-image: url("https://images.unsplash.com/photo-1562619371-b67725b6fde2?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=1950&q=80");
|
background-image: radial-gradient(rgba(0, 0, 0, 6%) 2px, rgba(0, 0, 0, 0%) 2px);
|
||||||
background-size: cover;
|
background-size: var(--pattern-size) var(--pattern-size);
|
||||||
background-repeat: no-repeat;
|
|
||||||
background-position: center;
|
|
||||||
|
|
||||||
.auth-card {
|
display: flex;
|
||||||
width: 462px;
|
flex-direction: column;
|
||||||
min-height: 644px;
|
}
|
||||||
background-color: var(--bg-surface-low);
|
.auth__wrapper {
|
||||||
border-radius: var(--bo-radius);
|
flex: 1;
|
||||||
box-shadow: var(--bs-popup);
|
padding: var(--sp-loose);
|
||||||
overflow: hidden;
|
padding-bottom: 0;
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-flow: row nowrap;
|
justify-content: center;
|
||||||
|
align-items: flex-start;
|
||||||
|
}
|
||||||
|
.auth-footer {
|
||||||
|
padding: var(--sp-normal) 0;
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
|
||||||
&__interactive{
|
& > *:nth-child(2n) {
|
||||||
flex: 1;
|
margin: 0 var(--sp-loose);
|
||||||
min-width: 0;
|
}
|
||||||
}
|
& a {
|
||||||
|
color: var(--tc-surface-normal);
|
||||||
&__interactive {
|
&:hover { text-decoration: underline; }
|
||||||
padding: calc(var(--sp-normal) + var(--sp-extra-loose));
|
}
|
||||||
padding-bottom: var(--sp-extra-loose);
|
}
|
||||||
background-color: var(--bg-surface);
|
.auth-card {
|
||||||
}
|
width: 462px;
|
||||||
|
background-color: var(--bg-surface);
|
||||||
|
border-radius: var(--bo-radius);
|
||||||
|
box-shadow: var(--bs-popup);
|
||||||
|
overflow: hidden;
|
||||||
|
|
||||||
|
&__content {
|
||||||
|
padding: var(--sp-extra-loose) calc(var(--sp-normal) + var(--sp-extra-loose));
|
||||||
|
}
|
||||||
|
&__switch {
|
||||||
|
margin-top: var(--sp-loose) !important;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.app-ident {
|
.homeserver-form,
|
||||||
margin-bottom: var(--sp-extra-loose);
|
.auth-form__heading {
|
||||||
|
& .context-menu .btn-surface .ic-raw {
|
||||||
&__logo {
|
width: 0;
|
||||||
width: 60px;
|
|
||||||
height: 60px;
|
|
||||||
}
|
}
|
||||||
&__text {
|
}
|
||||||
margin-left: calc(var(--sp-loose) + var(--sp-ultra-tight));
|
|
||||||
|
|
||||||
.text-s1 {
|
.homeserver-form {
|
||||||
margin-top: var(--sp-tight);
|
display: flex;
|
||||||
color: var(--tc-surface-normal);
|
margin-bottom: var(--sp-extra-tight);
|
||||||
|
align-items: flex-end;
|
||||||
|
& > .input-container {
|
||||||
|
flex: 1;
|
||||||
|
& .input {
|
||||||
|
border-right: unset;
|
||||||
|
border-radius: var(--bo-radius) 0 0 var(--bo-radius);
|
||||||
|
background-color: var(--bg-surface);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
& .ic-btn {
|
||||||
|
height: 46px;
|
||||||
|
border: 1px solid var(--bg-surface-border);
|
||||||
|
border-radius: 0 var(--bo-radius) var(--bo-radius) 0;
|
||||||
|
}
|
||||||
|
[dir=rtl] & {
|
||||||
|
& .input {
|
||||||
|
border-radius: 0 var(--bo-radius) var(--bo-radius) 0;
|
||||||
|
border-radius: 1px;
|
||||||
|
border-left: unset;
|
||||||
|
}
|
||||||
|
.ic-btn {
|
||||||
|
border-radius: var(--bo-radius) 0 0 var(--bo-radius);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
[dir=rtl] & {
|
&__status {
|
||||||
margin-left: 0;
|
margin-top: var(--sp-normal);
|
||||||
margin-right: calc(var(--sp-loose) + var(--sp-ultra-tight));
|
& .donut-spinner {
|
||||||
|
min-width: 28px;
|
||||||
}
|
}
|
||||||
|
& .text {
|
||||||
|
margin: 0 var(--sp-tight);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
&__error {
|
||||||
|
margin-bottom: var(--sp-normal) !important;
|
||||||
|
color: var(--tc-danger-normal) !important;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.auth-form {
|
.auth-form {
|
||||||
|
|
||||||
& > .text {
|
|
||||||
margin-bottom: var(--sp-loose);
|
|
||||||
margin-top: var(--sp-loose);
|
|
||||||
}
|
|
||||||
& > .input-container {
|
& > .input-container {
|
||||||
margin-top: var(--sp-tight);
|
margin: var(--sp-tight) 0 var(--sp-ultra-tight);
|
||||||
}
|
}
|
||||||
|
|
||||||
.submit-btn__wrapper {
|
&__heading {
|
||||||
margin-top: var(--sp-extra-loose);
|
display: flex;
|
||||||
margin-bottom: var(--sp-loose);
|
justify-content: space-between;
|
||||||
align-items: flex-start;
|
margin-top: calc(var(--sp-extra-loose) + var(--sp-tight));
|
||||||
|
|
||||||
& > .error-message {
|
|
||||||
display: none;
|
|
||||||
flex: 1;
|
|
||||||
color: var(--tc-danger-normal);
|
|
||||||
margin-right: var(--sp-normal);
|
|
||||||
word-break: break;
|
|
||||||
|
|
||||||
[dir=rtl] & {
|
|
||||||
margin: {
|
|
||||||
right: 0;
|
|
||||||
left: var(--sp-normal);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
&__wrapper {
|
&__btns {
|
||||||
height: 100%;
|
padding-top: var(--sp-loose);
|
||||||
|
margin-bottom: var(--sp-extra-loose);
|
||||||
|
display: flex;
|
||||||
|
justify-content: flex-end;
|
||||||
|
}
|
||||||
|
|
||||||
|
&__error {
|
||||||
|
color: var(--tc-danger-normal) !important;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
.sso__divider {
|
||||||
.username__wrapper {
|
margin-bottom: var(--sp-tight);
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: flex-end;
|
align-items: center;
|
||||||
|
|
||||||
& > :first-child {
|
&::before,
|
||||||
|
&::after {
|
||||||
flex: 1;
|
flex: 1;
|
||||||
|
content: '';
|
||||||
.input {
|
margin: var(--sp-tight);
|
||||||
border-radius: var(--bo-radius) 0 0 var(--bo-radius);
|
border-bottom: 1px solid var(--bg-surface-border);
|
||||||
|
|
||||||
[dir=rtl] & {
|
|
||||||
border-radius: 0 var(--bo-radius) var(--bo-radius) 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
& > :last-child {
|
|
||||||
width: 110px;
|
|
||||||
|
|
||||||
.input {
|
|
||||||
border-left-width: 0;
|
|
||||||
background-color: var(--bg-surface);
|
|
||||||
border-radius: 0 var(--bo-radius) var(--bo-radius) 0;
|
|
||||||
|
|
||||||
[dir=rtl] & {
|
|
||||||
border-left-width: 1px;
|
|
||||||
border-right-width: 0;
|
|
||||||
border-radius: var(--bo-radius) 0 0 var(--bo-radius);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.password__wrapper {
|
|
||||||
margin-top: var(--sp-tight);
|
|
||||||
position: relative;
|
|
||||||
|
|
||||||
& .ic-btn {
|
|
||||||
position: absolute;
|
|
||||||
right: 6px;
|
|
||||||
bottom: 6px;
|
|
||||||
border-radius: calc(var(--bo-radius) / 2);
|
|
||||||
[dir=rtl] & {
|
|
||||||
left: 6px;
|
|
||||||
right: unset;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@media (max-width: 462px) {
|
@media (max-width: 462px) {
|
||||||
.auth__wrapper {
|
.auth__wrapper {
|
||||||
padding: 0;
|
padding: var(--sp-tight);
|
||||||
background-image: none;
|
}
|
||||||
background-color: var(--bg-surface);
|
.auth-card {
|
||||||
|
&__content {
|
||||||
.auth-card {
|
padding: var(--sp-loose) var(--sp-normal);
|
||||||
border-radius: 0;
|
|
||||||
box-shadow: none;
|
|
||||||
|
|
||||||
&__interactive {
|
|
||||||
padding: var(--sp-extra-loose);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,14 +9,31 @@ import Windows from '../../organisms/pw/Windows';
|
|||||||
import Dialogs from '../../organisms/pw/Dialogs';
|
import Dialogs from '../../organisms/pw/Dialogs';
|
||||||
import EmojiBoardOpener from '../../organisms/emoji-board/EmojiBoardOpener';
|
import EmojiBoardOpener from '../../organisms/emoji-board/EmojiBoardOpener';
|
||||||
import RoomOptions from '../../organisms/room-optons/RoomOptions';
|
import RoomOptions from '../../organisms/room-optons/RoomOptions';
|
||||||
|
import logout from '../../../client/action/logout';
|
||||||
|
|
||||||
import initMatrix from '../../../client/initMatrix';
|
import initMatrix from '../../../client/initMatrix';
|
||||||
|
|
||||||
function Client() {
|
function Client() {
|
||||||
const [isLoading, changeLoading] = useState(true);
|
const [isLoading, changeLoading] = useState(true);
|
||||||
|
const [loadingMsg, setLoadingMsg] = useState('Heating up');
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
let counter = 0;
|
||||||
|
const iId = setInterval(() => {
|
||||||
|
const msgList = [
|
||||||
|
'Sometimes it takes a while...',
|
||||||
|
'Looks like you have a lot of stuff to heat up!',
|
||||||
|
];
|
||||||
|
if (counter === msgList.length - 1) {
|
||||||
|
setLoadingMsg(msgList[msgList.length - 1]);
|
||||||
|
clearInterval(iId);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
setLoadingMsg(msgList[counter]);
|
||||||
|
counter += 1;
|
||||||
|
}, 9000);
|
||||||
initMatrix.once('init_loading_finished', () => {
|
initMatrix.once('init_loading_finished', () => {
|
||||||
|
clearInterval(iId);
|
||||||
changeLoading(false);
|
changeLoading(false);
|
||||||
});
|
});
|
||||||
initMatrix.init();
|
initMatrix.init();
|
||||||
@@ -25,8 +42,11 @@ function Client() {
|
|||||||
if (isLoading) {
|
if (isLoading) {
|
||||||
return (
|
return (
|
||||||
<div className="loading-display">
|
<div className="loading-display">
|
||||||
|
<button className="loading__logout" onClick={logout} type="button">
|
||||||
|
<Text variant="b3">Logout</Text>
|
||||||
|
</button>
|
||||||
<Spinner />
|
<Spinner />
|
||||||
<Text className="loading__message" variant="b2">Heating up</Text>
|
<Text className="loading__message" variant="b2">{loadingMsg}</Text>
|
||||||
|
|
||||||
<div className="loading__appname">
|
<div className="loading__appname">
|
||||||
<Text variant="h2">Cinny</Text>
|
<Text variant="h2">Cinny</Text>
|
||||||
|
|||||||
@@ -18,7 +18,7 @@
|
|||||||
top: 0;
|
top: 0;
|
||||||
left: 0;
|
left: 0;
|
||||||
width: 100vw;
|
width: 100vw;
|
||||||
height: 100vh;
|
height: 100%;
|
||||||
|
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
@@ -27,8 +27,19 @@
|
|||||||
}
|
}
|
||||||
.loading__message {
|
.loading__message {
|
||||||
margin-top: var(--sp-normal);
|
margin-top: var(--sp-normal);
|
||||||
|
max-width: 350px;
|
||||||
|
text-align: center;
|
||||||
}
|
}
|
||||||
.loading__appname {
|
.loading__appname {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
bottom: var(--sp-normal);
|
bottom: var(--sp-normal);
|
||||||
}
|
}
|
||||||
|
.loading__logout {
|
||||||
|
position: absolute;
|
||||||
|
bottom: var(--sp-extra-tight);
|
||||||
|
right: var(--sp-extra-tight);
|
||||||
|
cursor: pointer;
|
||||||
|
.text {
|
||||||
|
color: var(--tc-link);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,189 +1,104 @@
|
|||||||
import * as sdk from 'matrix-js-sdk';
|
import * as sdk from 'matrix-js-sdk';
|
||||||
import cons from '../state/cons';
|
import cons from '../state/cons';
|
||||||
import { getBaseUrl } from '../../util/matrixUtil';
|
|
||||||
|
|
||||||
// This method inspired by a similar one in matrix-react-sdk
|
function updateLocalStore(accessToken, deviceId, userId, baseUrl) {
|
||||||
async function createTemporaryClient(homeserver) {
|
localStorage.setItem(cons.secretKey.ACCESS_TOKEN, accessToken);
|
||||||
let baseUrl = null;
|
localStorage.setItem(cons.secretKey.DEVICE_ID, deviceId);
|
||||||
try {
|
localStorage.setItem(cons.secretKey.USER_ID, userId);
|
||||||
baseUrl = await getBaseUrl(homeserver);
|
localStorage.setItem(cons.secretKey.BASE_URL, baseUrl);
|
||||||
} catch (e) {
|
}
|
||||||
baseUrl = `https://${homeserver}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (typeof baseUrl === 'undefined') throw new Error('Homeserver not found');
|
|
||||||
|
|
||||||
|
function createTemporaryClient(baseUrl) {
|
||||||
return sdk.createClient({ baseUrl });
|
return sdk.createClient({ baseUrl });
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getLoginFlows(client) {
|
async function startSsoLogin(baseUrl, type, idpId) {
|
||||||
const flows = await client.loginFlows();
|
const client = createTemporaryClient(baseUrl);
|
||||||
if (flows !== undefined) {
|
|
||||||
return flows;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
async function startSsoLogin(homeserver, type, idpId) {
|
|
||||||
const client = await createTemporaryClient(homeserver);
|
|
||||||
localStorage.setItem(cons.secretKey.BASE_URL, client.baseUrl);
|
localStorage.setItem(cons.secretKey.BASE_URL, client.baseUrl);
|
||||||
window.location.href = client.getSsoLoginUrl(window.location.href, type, idpId);
|
window.location.href = client.getSsoLoginUrl(window.location.href, type, idpId);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function login(username, homeserver, password) {
|
async function login(baseUrl, username, email, password) {
|
||||||
const client = await createTemporaryClient(homeserver);
|
const identifier = {};
|
||||||
|
if (username) {
|
||||||
|
identifier.type = 'm.id.user';
|
||||||
|
identifier.user = username;
|
||||||
|
} else if (email) {
|
||||||
|
identifier.type = 'm.id.thirdparty';
|
||||||
|
identifier.medium = 'email';
|
||||||
|
identifier.address = email;
|
||||||
|
} else throw new Error('Bad Input');
|
||||||
|
|
||||||
const response = await client.login('m.login.password', {
|
const client = createTemporaryClient(baseUrl);
|
||||||
identifier: {
|
const res = await client.login('m.login.password', {
|
||||||
type: 'm.id.user',
|
identifier,
|
||||||
user: username,
|
|
||||||
},
|
|
||||||
password,
|
password,
|
||||||
initial_device_display_name: cons.DEVICE_DISPLAY_NAME,
|
initial_device_display_name: cons.DEVICE_DISPLAY_NAME,
|
||||||
});
|
});
|
||||||
|
|
||||||
localStorage.setItem(cons.secretKey.ACCESS_TOKEN, response.access_token);
|
const myBaseUrl = res?.well_known?.['m.homeserver']?.base_url || client.baseUrl;
|
||||||
localStorage.setItem(cons.secretKey.DEVICE_ID, response.device_id);
|
updateLocalStore(res.access_token, res.device_id, res.user_id, myBaseUrl);
|
||||||
localStorage.setItem(cons.secretKey.USER_ID, response.user_id);
|
|
||||||
localStorage.setItem(cons.secretKey.BASE_URL, response?.well_known?.['m.homeserver']?.base_url || client.baseUrl);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function loginWithToken(baseUrl, token) {
|
async function loginWithToken(baseUrl, token) {
|
||||||
const client = sdk.createClient(baseUrl);
|
const client = createTemporaryClient(baseUrl);
|
||||||
|
|
||||||
const response = await client.login('m.login.token', {
|
const res = await client.login('m.login.token', {
|
||||||
token,
|
token,
|
||||||
initial_device_display_name: cons.DEVICE_DISPLAY_NAME,
|
initial_device_display_name: cons.DEVICE_DISPLAY_NAME,
|
||||||
});
|
});
|
||||||
|
|
||||||
localStorage.setItem(cons.secretKey.ACCESS_TOKEN, response.access_token);
|
const myBaseUrl = res?.well_known?.['m.homeserver']?.base_url || client.baseUrl;
|
||||||
localStorage.setItem(cons.secretKey.DEVICE_ID, response.device_id);
|
updateLocalStore(res.access_token, res.device_id, res.user_id, myBaseUrl);
|
||||||
localStorage.setItem(cons.secretKey.USER_ID, response.user_id);
|
|
||||||
localStorage.setItem(cons.secretKey.BASE_URL, response?.well_known?.['m.homeserver']?.base_url || client.baseUrl);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getAdditionalInfo(baseUrl, content) {
|
// eslint-disable-next-line camelcase
|
||||||
try {
|
async function verifyEmail(baseUrl, email, client_secret, send_attempt, next_link) {
|
||||||
const res = await fetch(`${baseUrl}/_matrix/client/r0/register`, {
|
const res = await fetch(`${baseUrl}/_matrix/client/r0/register/email/requestToken`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: JSON.stringify(content),
|
body: JSON.stringify({
|
||||||
headers: {
|
email, client_secret, send_attempt, next_link,
|
||||||
'Content-Type': 'application/json; charset=utf-8',
|
}),
|
||||||
},
|
headers: {
|
||||||
credentials: 'same-origin',
|
'Content-Type': 'application/json; charset=utf-8',
|
||||||
});
|
},
|
||||||
const data = await res.json();
|
credentials: 'same-origin',
|
||||||
return data;
|
|
||||||
} catch (e) {
|
|
||||||
throw new Error(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async function verifyEmail(baseUrl, content) {
|
|
||||||
try {
|
|
||||||
const res = await fetch(`${baseUrl}/_matrix/client/r0/register/email/requestToken`, {
|
|
||||||
method: 'POST',
|
|
||||||
body: JSON.stringify(content),
|
|
||||||
headers: {
|
|
||||||
'Content-Type': 'application/json; charset=utf-8',
|
|
||||||
},
|
|
||||||
credentials: 'same-origin',
|
|
||||||
});
|
|
||||||
const data = await res.json();
|
|
||||||
return data;
|
|
||||||
} catch (e) {
|
|
||||||
throw new Error(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let session = null;
|
|
||||||
let clientSecret = null;
|
|
||||||
let sid = null;
|
|
||||||
async function register(username, homeserver, password, email, recaptchaValue, terms, verified) {
|
|
||||||
const baseUrl = await getBaseUrl(homeserver);
|
|
||||||
|
|
||||||
if (typeof baseUrl === 'undefined') throw new Error('Homeserver not found');
|
|
||||||
|
|
||||||
const client = sdk.createClient({ baseUrl });
|
|
||||||
|
|
||||||
const isAvailable = await client.isUsernameAvailable(username);
|
|
||||||
if (!isAvailable) throw new Error('Username not available');
|
|
||||||
|
|
||||||
if (typeof recaptchaValue === 'string') {
|
|
||||||
await getAdditionalInfo(baseUrl, {
|
|
||||||
auth: {
|
|
||||||
type: 'm.login.recaptcha',
|
|
||||||
session,
|
|
||||||
response: recaptchaValue,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
} else if (terms === true) {
|
|
||||||
await getAdditionalInfo(baseUrl, {
|
|
||||||
auth: {
|
|
||||||
type: 'm.login.terms',
|
|
||||||
session,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
} else if (verified !== true) {
|
|
||||||
session = null;
|
|
||||||
clientSecret = client.generateClientSecret();
|
|
||||||
const verifyData = await verifyEmail(baseUrl, {
|
|
||||||
email,
|
|
||||||
client_secret: clientSecret,
|
|
||||||
send_attempt: 1,
|
|
||||||
});
|
|
||||||
if (typeof verifyData.error === 'string') {
|
|
||||||
throw new Error(verifyData.error);
|
|
||||||
}
|
|
||||||
sid = verifyData.sid;
|
|
||||||
}
|
|
||||||
|
|
||||||
const additionalInfo = await getAdditionalInfo(baseUrl, {
|
|
||||||
auth: { session: (session !== null) ? session : undefined },
|
|
||||||
});
|
});
|
||||||
session = additionalInfo.session;
|
const data = await res.json();
|
||||||
if (typeof additionalInfo.completed === 'undefined' || additionalInfo.completed.length === 0) {
|
return data;
|
||||||
return ({
|
}
|
||||||
type: 'recaptcha',
|
|
||||||
public_key: additionalInfo.params['m.login.recaptcha'].public_key,
|
async function completeRegisterStage(
|
||||||
});
|
baseUrl, username, password, auth,
|
||||||
}
|
) {
|
||||||
if (additionalInfo.completed.find((process) => process === 'm.login.recaptcha') === 'm.login.recaptcha'
|
const tempClient = createTemporaryClient(baseUrl);
|
||||||
&& !additionalInfo.completed.find((process) => process === 'm.login.terms')) {
|
|
||||||
return ({
|
try {
|
||||||
type: 'terms',
|
const result = await tempClient.registerRequest({
|
||||||
en: additionalInfo.params['m.login.terms'].policies.privacy_policy.en,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
if (verified || additionalInfo.completed.find((process) => process === 'm.login.terms') === 'm.login.terms') {
|
|
||||||
const tpc = {
|
|
||||||
client_secret: clientSecret,
|
|
||||||
sid,
|
|
||||||
};
|
|
||||||
const verifyData = await getAdditionalInfo(baseUrl, {
|
|
||||||
auth: {
|
|
||||||
session,
|
|
||||||
type: 'm.login.email.identity',
|
|
||||||
threepidCreds: tpc,
|
|
||||||
threepid_creds: tpc,
|
|
||||||
},
|
|
||||||
username,
|
username,
|
||||||
password,
|
password,
|
||||||
|
auth,
|
||||||
|
initial_device_display_name: cons.DEVICE_DISPLAY_NAME,
|
||||||
});
|
});
|
||||||
if (verifyData.errcode === 'M_UNAUTHORIZED') {
|
const data = { completed: result.completed || [] };
|
||||||
return { type: 'email' };
|
if (result.access_token) {
|
||||||
|
data.done = true;
|
||||||
|
updateLocalStore(result.access_token, result.device_id, result.user_id, baseUrl);
|
||||||
}
|
}
|
||||||
|
return data;
|
||||||
localStorage.setItem(cons.secretKey.ACCESS_TOKEN, verifyData.access_token);
|
} catch (e) {
|
||||||
localStorage.setItem(cons.secretKey.DEVICE_ID, verifyData.device_id);
|
const result = e.data;
|
||||||
localStorage.setItem(cons.secretKey.USER_ID, verifyData.user_id);
|
const data = { completed: result.completed || [] };
|
||||||
localStorage.setItem(cons.secretKey.BASE_URL, baseUrl);
|
if (result.access_token) {
|
||||||
return { type: 'done' };
|
data.done = true;
|
||||||
|
updateLocalStore(result.access_token, result.device_id, result.user_id, baseUrl);
|
||||||
|
}
|
||||||
|
return data;
|
||||||
}
|
}
|
||||||
return {};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export {
|
export {
|
||||||
createTemporaryClient, getLoginFlows, login,
|
createTemporaryClient, login, verifyEmail,
|
||||||
loginWithToken, register, startSsoLogin,
|
loginWithToken, startSsoLogin,
|
||||||
|
completeRegisterStage,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import initMatrix from '../initMatrix';
|
|||||||
|
|
||||||
function logout() {
|
function logout() {
|
||||||
const mx = initMatrix.matrixClient;
|
const mx = initMatrix.matrixClient;
|
||||||
|
mx.stopClient();
|
||||||
mx.logout().then(() => {
|
mx.logout().then(() => {
|
||||||
mx.clearStores();
|
mx.clearStores();
|
||||||
window.localStorage.clear();
|
window.localStorage.clear();
|
||||||
|
|||||||
@@ -132,9 +132,11 @@ function leave(roomId) {
|
|||||||
* @param {boolean} [opts.isEncrypted=false] Makes room encrypted
|
* @param {boolean} [opts.isEncrypted=false] Makes room encrypted
|
||||||
* @param {boolean} [opts.isDirect=false] Makes room as direct message
|
* @param {boolean} [opts.isDirect=false] Makes room as direct message
|
||||||
* @param {string[]} [opts.invite=[]] An array of userId's to invite
|
* @param {string[]} [opts.invite=[]] An array of userId's to invite
|
||||||
|
* @param{number} [opts.powerLevel=100] My power level
|
||||||
*/
|
*/
|
||||||
async function create(opts) {
|
async function create(opts) {
|
||||||
const mx = initMatrix.matrixClient;
|
const mx = initMatrix.matrixClient;
|
||||||
|
const customPowerLevels = [101];
|
||||||
const options = {
|
const options = {
|
||||||
name: opts.name,
|
name: opts.name,
|
||||||
topic: opts.topic,
|
topic: opts.topic,
|
||||||
@@ -144,6 +146,9 @@ async function create(opts) {
|
|||||||
invite: opts.invite || [],
|
invite: opts.invite || [],
|
||||||
initial_state: [],
|
initial_state: [],
|
||||||
preset: opts.isDirect === true ? 'trusted_private_chat' : undefined,
|
preset: opts.isDirect === true ? 'trusted_private_chat' : undefined,
|
||||||
|
power_level_content_override: customPowerLevels.indexOf(opts.powerLevel) === -1 ? undefined : {
|
||||||
|
users: { [initMatrix.matrixClient.getUserId()]: opts.powerLevel },
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
if (opts.isPublic !== true && opts.isEncrypted === true) {
|
if (opts.isPublic !== true && opts.isEncrypted === true) {
|
||||||
@@ -183,12 +188,15 @@ async function create(opts) {
|
|||||||
async function invite(roomId, userId) {
|
async function invite(roomId, userId) {
|
||||||
const mx = initMatrix.matrixClient;
|
const mx = initMatrix.matrixClient;
|
||||||
|
|
||||||
try {
|
const result = await mx.invite(roomId, userId);
|
||||||
const result = await mx.invite(roomId, userId);
|
return result;
|
||||||
return result;
|
}
|
||||||
} catch (e) {
|
|
||||||
throw new Error(e);
|
async function kick(roomId, userId) {
|
||||||
}
|
const mx = initMatrix.matrixClient;
|
||||||
|
|
||||||
|
const result = await mx.kick(roomId, userId);
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
function createSpaceShortcut(roomId) {
|
function createSpaceShortcut(roomId) {
|
||||||
@@ -207,6 +215,6 @@ function deleteSpaceShortcut(roomId) {
|
|||||||
|
|
||||||
export {
|
export {
|
||||||
join, leave,
|
join, leave,
|
||||||
create, invite,
|
create, invite, kick,
|
||||||
createSpaceShortcut, deleteSpaceShortcut,
|
createSpaceShortcut, deleteSpaceShortcut,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ class InitMatrix extends EventEmitter {
|
|||||||
sessionStore: new sdk.WebStorageSessionStore(global.localStorage),
|
sessionStore: new sdk.WebStorageSessionStore(global.localStorage),
|
||||||
cryptoStore: new sdk.IndexedDBCryptoStore(global.indexedDB, 'crypto-store'),
|
cryptoStore: new sdk.IndexedDBCryptoStore(global.indexedDB, 'crypto-store'),
|
||||||
deviceId: secret.deviceId,
|
deviceId: secret.deviceId,
|
||||||
|
timelineSupport: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
await this.matrixClient.initCrypto();
|
await this.matrixClient.initCrypto();
|
||||||
|
|||||||
@@ -77,12 +77,28 @@ class Notifications extends EventEmitter {
|
|||||||
return this.roomIdToNoti.has(roomId);
|
return this.roomIdToNoti.has(roomId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_getAllParentIds(roomId) {
|
||||||
|
let allParentIds = this.roomList.roomIdToParents.get(roomId);
|
||||||
|
if (allParentIds === undefined) return new Set();
|
||||||
|
const parentIds = [...allParentIds];
|
||||||
|
|
||||||
|
parentIds.forEach((pId) => {
|
||||||
|
allParentIds = new Set(
|
||||||
|
[...allParentIds, ...this._getAllParentIds(pId)],
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
return allParentIds;
|
||||||
|
}
|
||||||
|
|
||||||
_setNoti(roomId, total, highlight, childId) {
|
_setNoti(roomId, total, highlight, childId) {
|
||||||
const prevTotal = this.roomIdToNoti.get(roomId)?.total ?? null;
|
const prevTotal = this.roomIdToNoti.get(roomId)?.total ?? null;
|
||||||
const noti = this.getNoti(roomId);
|
const noti = this.getNoti(roomId);
|
||||||
|
|
||||||
noti.total += total;
|
if (!childId || this._remainingParentIds?.has(roomId)) {
|
||||||
noti.highlight += highlight;
|
noti.total += total;
|
||||||
|
noti.highlight += highlight;
|
||||||
|
}
|
||||||
if (childId) {
|
if (childId) {
|
||||||
if (noti.from === null) noti.from = new Set();
|
if (noti.from === null) noti.from = new Set();
|
||||||
noti.from.add(childId);
|
noti.from.add(childId);
|
||||||
@@ -91,9 +107,16 @@ class Notifications extends EventEmitter {
|
|||||||
this.roomIdToNoti.set(roomId, noti);
|
this.roomIdToNoti.set(roomId, noti);
|
||||||
this.emit(cons.events.notifications.NOTI_CHANGED, roomId, noti.total, prevTotal);
|
this.emit(cons.events.notifications.NOTI_CHANGED, roomId, noti.total, prevTotal);
|
||||||
|
|
||||||
|
if (!childId) this._remainingParentIds = this._getAllParentIds(roomId);
|
||||||
|
else this._remainingParentIds.delete(roomId);
|
||||||
|
|
||||||
const parentIds = this.roomList.roomIdToParents.get(roomId);
|
const parentIds = this.roomList.roomIdToParents.get(roomId);
|
||||||
if (typeof parentIds === 'undefined') return;
|
if (typeof parentIds === 'undefined') {
|
||||||
|
if (!childId) this._remainingParentIds = undefined;
|
||||||
|
return;
|
||||||
|
}
|
||||||
[...parentIds].forEach((parentId) => this._setNoti(parentId, total, highlight, roomId));
|
[...parentIds].forEach((parentId) => this._setNoti(parentId, total, highlight, roomId));
|
||||||
|
if (!childId) this._remainingParentIds = undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
_deleteNoti(roomId, total, highlight, childId) {
|
_deleteNoti(roomId, total, highlight, childId) {
|
||||||
@@ -103,8 +126,12 @@ class Notifications extends EventEmitter {
|
|||||||
const prevTotal = noti.total;
|
const prevTotal = noti.total;
|
||||||
noti.total -= total;
|
noti.total -= total;
|
||||||
noti.highlight -= highlight;
|
noti.highlight -= highlight;
|
||||||
|
if (noti.total < 0) {
|
||||||
|
noti.total = 0;
|
||||||
|
noti.highlight = 0;
|
||||||
|
}
|
||||||
if (childId && noti.from !== null) {
|
if (childId && noti.from !== null) {
|
||||||
noti.from.delete(childId);
|
if (!this.hasNoti(childId)) noti.from.delete(childId);
|
||||||
}
|
}
|
||||||
if (noti.from === null || noti.from.size === 0) {
|
if (noti.from === null || noti.from.size === 0) {
|
||||||
this.roomIdToNoti.delete(roomId);
|
this.roomIdToNoti.delete(roomId);
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
const cons = {
|
const cons = {
|
||||||
|
version: '1.5.1',
|
||||||
secretKey: {
|
secretKey: {
|
||||||
ACCESS_TOKEN: 'cinny_access_token',
|
ACCESS_TOKEN: 'cinny_access_token',
|
||||||
DEVICE_ID: 'cinny_device_id',
|
DEVICE_ID: 'cinny_device_id',
|
||||||
|
|||||||
@@ -290,6 +290,17 @@ button {
|
|||||||
overflow: visible;
|
overflow: visible;
|
||||||
-webkit-appearance: button;
|
-webkit-appearance: button;
|
||||||
}
|
}
|
||||||
|
textarea,
|
||||||
|
input,
|
||||||
|
input[type],
|
||||||
|
input[type=text],
|
||||||
|
input[type=username],
|
||||||
|
input[type=password],
|
||||||
|
input[type=email] {
|
||||||
|
-webkit-appearance: none;
|
||||||
|
-moz-appearance: none;
|
||||||
|
appearance: none;
|
||||||
|
}
|
||||||
textarea {
|
textarea {
|
||||||
color: inherit;
|
color: inherit;
|
||||||
word-spacing: inherit;
|
word-spacing: inherit;
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
/* eslint-disable max-classes-per-file */
|
||||||
export function bytesToSize(bytes) {
|
export function bytesToSize(bytes) {
|
||||||
const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB'];
|
const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB'];
|
||||||
if (bytes === 0) return 'n/a';
|
if (bytes === 0) return 'n/a';
|
||||||
@@ -33,3 +34,53 @@ export function abbreviateNumber(number) {
|
|||||||
if (number > 99) return '99+';
|
if (number > 99) return '99+';
|
||||||
return number;
|
return number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export class Debounce {
|
||||||
|
constructor() {
|
||||||
|
this.timeoutId = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {function} func - callback function
|
||||||
|
* @param {number} wait - wait in milliseconds to call func
|
||||||
|
* @returns {func} debounceCallback - to pass arguments to func callback
|
||||||
|
*/
|
||||||
|
_(func, wait) {
|
||||||
|
const that = this;
|
||||||
|
return function debounceCallback(...args) {
|
||||||
|
clearTimeout(that.timeoutId);
|
||||||
|
that.timeoutId = setTimeout(() => {
|
||||||
|
func.apply(this, args);
|
||||||
|
that.timeoutId = null;
|
||||||
|
}, wait);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export class Throttle {
|
||||||
|
constructor() {
|
||||||
|
this.timeoutId = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {function} func - callback function
|
||||||
|
* @param {number} wait - wait in milliseconds to call func
|
||||||
|
* @returns {function} throttleCallback - to pass arguments to func callback
|
||||||
|
*/
|
||||||
|
_(func, wait) {
|
||||||
|
const that = this;
|
||||||
|
return function throttleCallback(...args) {
|
||||||
|
if (that.timeoutId !== null) return;
|
||||||
|
that.timeoutId = setTimeout(() => {
|
||||||
|
func.apply(this, args);
|
||||||
|
that.timeoutId = null;
|
||||||
|
}, wait);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getUrlPrams(paramName) {
|
||||||
|
const queryString = window.location.search;
|
||||||
|
const urlParams = new URLSearchParams(queryString);
|
||||||
|
return urlParams.get(paramName);
|
||||||
|
}
|
||||||
|
|||||||
@@ -2,15 +2,18 @@ import initMatrix from '../client/initMatrix';
|
|||||||
|
|
||||||
const WELL_KNOWN_URI = '/.well-known/matrix/client';
|
const WELL_KNOWN_URI = '/.well-known/matrix/client';
|
||||||
|
|
||||||
async function getBaseUrl(homeserver) {
|
async function getBaseUrl(servername) {
|
||||||
const serverDiscoveryUrl = `https://${homeserver}${WELL_KNOWN_URI}`;
|
let protocol = 'https://';
|
||||||
|
if (servername.match(/^https?:\/\//) !== null) protocol = '';
|
||||||
|
const serverDiscoveryUrl = `${protocol}${servername}${WELL_KNOWN_URI}`;
|
||||||
try {
|
try {
|
||||||
const result = await fetch(serverDiscoveryUrl, { method: 'GET' });
|
const result = await (await fetch(serverDiscoveryUrl, { method: 'GET' })).json();
|
||||||
const data = await result.json();
|
|
||||||
|
|
||||||
return data?.['m.homeserver']?.base_url;
|
const baseUrl = result?.['m.homeserver']?.base_url;
|
||||||
|
if (baseUrl === undefined) throw new Error();
|
||||||
|
return baseUrl;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
throw new Error('Homeserver not found');
|
throw new Error(`${protocol}${servername}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -45,30 +48,6 @@ async function isRoomAliasAvailable(alias) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function doesRoomHaveUnread(room) {
|
|
||||||
const userId = initMatrix.matrixClient.getUserId();
|
|
||||||
const readUpToId = room.getEventReadUpTo(userId);
|
|
||||||
const supportEvents = ['m.room.message', 'm.room.encrypted', 'm.sticker'];
|
|
||||||
|
|
||||||
if (room.timeline.length
|
|
||||||
&& room.timeline[room.timeline.length - 1].sender
|
|
||||||
&& room.timeline[room.timeline.length - 1].sender.userId === userId
|
|
||||||
&& room.timeline[room.timeline.length - 1].getType() !== 'm.room.member') {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (let i = room.timeline.length - 1; i >= 0; i -= 1) {
|
|
||||||
const event = room.timeline[i];
|
|
||||||
|
|
||||||
if (event.getId() === readUpToId) return false;
|
|
||||||
|
|
||||||
if (supportEvents.includes(event.getType())) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
function getPowerLabel(powerLevel) {
|
function getPowerLabel(powerLevel) {
|
||||||
if (powerLevel > 9000) return 'Goku';
|
if (powerLevel > 9000) return 'Goku';
|
||||||
if (powerLevel > 100) return 'Founder';
|
if (powerLevel > 100) return 'Founder';
|
||||||
@@ -79,5 +58,5 @@ function getPowerLabel(powerLevel) {
|
|||||||
|
|
||||||
export {
|
export {
|
||||||
getBaseUrl, getUsername, getUsernameOfRoomMember,
|
getBaseUrl, getUsername, getUsernameOfRoomMember,
|
||||||
isRoomAliasAvailable, doesRoomHaveUnread, getPowerLabel,
|
isRoomAliasAvailable, getPowerLabel,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
const HtmlWebpackPlugin = require('html-webpack-plugin');
|
const HtmlWebpackPlugin = require('html-webpack-plugin');
|
||||||
const FaviconsWebpackPlugin = require('favicons-webpack-plugin');
|
const FaviconsWebpackPlugin = require('favicons-webpack-plugin');
|
||||||
const webpack = require('webpack');
|
const CopyPlugin = require("copy-webpack-plugin");
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
entry: {
|
entry: {
|
||||||
@@ -38,15 +38,13 @@ module.exports = {
|
|||||||
use: ['html-loader'],
|
use: ['html-loader'],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
test: /\.(svg|png|jpe?g|gif|otf|ttf)$/,
|
test: /\.(png|jpe?g|gif|otf|ttf)$/,
|
||||||
use: {
|
type: 'asset/resource',
|
||||||
loader: 'file-loader',
|
|
||||||
options: {
|
|
||||||
name: '[name].[hash].[ext]',
|
|
||||||
outputPath: 'assets',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
test: /\.svg$/,
|
||||||
|
type: 'asset/inline',
|
||||||
|
}
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
plugins: [
|
plugins: [
|
||||||
@@ -67,8 +65,12 @@ module.exports = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
new webpack.DefinePlugin({
|
new CopyPlugin({
|
||||||
'process.env': JSON.stringify(process.env),
|
patterns: [
|
||||||
|
{ from: 'olm.wasm' },
|
||||||
|
{ from: '_redirects' },
|
||||||
|
{ from: 'config.json' },
|
||||||
|
],
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ const { merge } = require('webpack-merge');
|
|||||||
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
|
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
|
||||||
const CssMinimizerPlugin = require('css-minimizer-webpack-plugin');
|
const CssMinimizerPlugin = require('css-minimizer-webpack-plugin');
|
||||||
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
|
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
|
||||||
const CopyPlugin = require("copy-webpack-plugin");
|
|
||||||
|
|
||||||
module.exports = merge(common, {
|
module.exports = merge(common, {
|
||||||
mode: 'production',
|
mode: 'production',
|
||||||
@@ -36,11 +35,5 @@ module.exports = merge(common, {
|
|||||||
new MiniCssExtractPlugin({
|
new MiniCssExtractPlugin({
|
||||||
filename: '[name].[contenthash].bundle.css',
|
filename: '[name].[contenthash].bundle.css',
|
||||||
}),
|
}),
|
||||||
new CopyPlugin({
|
|
||||||
patterns: [
|
|
||||||
{ from: 'olm.wasm' },
|
|
||||||
{ from: '_redirects' },
|
|
||||||
],
|
|
||||||
}),
|
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user