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.
|
||||||
4
.gitignore
vendored
4
.gitignore
vendored
@@ -1,4 +1,6 @@
|
|||||||
experiment
|
experiment
|
||||||
dist
|
dist
|
||||||
node_modules
|
node_modules
|
||||||
devAssets
|
devAssets
|
||||||
|
|
||||||
|
.DS_Store
|
||||||
|
|||||||
@@ -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.3.2",
|
"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">
|
||||||
|
|||||||
7
public/res/ic/outlined/shield-empty.svg
Normal file
7
public/res/ic/outlined/shield-empty.svg
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!-- Generator: Adobe Illustrator 18.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
|
||||||
|
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
|
||||||
|
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
|
||||||
|
viewBox="0 0 24 24" enable-background="new 0 0 24 24" xml:space="preserve">
|
||||||
|
<path d="M12,2L3,6v7c0,5,4,9,9,9c5,0,9-4,9-9V6L12,2z M19,13c0,3.9-3.1,7-7,7s-7-3.1-7-7V7.3l7-3.1l7,3.1V13z"/>
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 554 B |
@@ -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>
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -24,7 +24,6 @@
|
|||||||
height: var(--av-extra-small);
|
height: var(--av-extra-small);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
img {
|
img {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
|
|||||||
@@ -6,18 +6,20 @@ 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}`)}
|
||||||
onClick={onClick}
|
onClick={onClick}
|
||||||
type={type === 'button' ? 'button' : 'submit'}
|
// eslint-disable-next-line react/button-has-type
|
||||||
|
type={type}
|
||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
>
|
>
|
||||||
{iconSrc !== null && <RawIcon size="small" src={iconSrc} />}
|
{iconSrc !== null && <RawIcon size="small" src={iconSrc} />}
|
||||||
@@ -25,7 +27,7 @@ function Button({
|
|||||||
{typeof children !== 'string' && children }
|
{typeof children !== 'string' && children }
|
||||||
</button>
|
</button>
|
||||||
);
|
);
|
||||||
}
|
});
|
||||||
|
|
||||||
Button.defaultProps = {
|
Button.defaultProps = {
|
||||||
id: '',
|
id: '',
|
||||||
@@ -42,7 +44,7 @@ Button.propTypes = {
|
|||||||
className: PropTypes.string,
|
className: PropTypes.string,
|
||||||
variant: PropTypes.oneOf(['surface', 'primary', 'positive', 'caution', 'danger']),
|
variant: PropTypes.oneOf(['surface', 'primary', 'positive', 'caution', 'danger']),
|
||||||
iconSrc: PropTypes.string,
|
iconSrc: PropTypes.string,
|
||||||
type: PropTypes.oneOf(['button', 'submit']),
|
type: PropTypes.oneOf(['button', 'submit', 'reset']),
|
||||||
onClick: PropTypes.func,
|
onClick: PropTypes.func,
|
||||||
children: PropTypes.node.isRequired,
|
children: PropTypes.node.isRequired,
|
||||||
disabled: PropTypes.bool,
|
disabled: PropTypes.bool,
|
||||||
|
|||||||
@@ -17,7 +17,8 @@ const IconButton = React.forwardRef(({
|
|||||||
className={`ic-btn ic-btn-${variant}`}
|
className={`ic-btn ic-btn-${variant}`}
|
||||||
onMouseUp={(e) => blurOnBubbling(e, `.ic-btn-${variant}`)}
|
onMouseUp={(e) => blurOnBubbling(e, `.ic-btn-${variant}`)}
|
||||||
onClick={onClick}
|
onClick={onClick}
|
||||||
type={type === 'button' ? 'button' : 'submit'}
|
// eslint-disable-next-line react/button-has-type
|
||||||
|
type={type}
|
||||||
>
|
>
|
||||||
<RawIcon size={size} src={src} />
|
<RawIcon size={size} src={src} />
|
||||||
</button>
|
</button>
|
||||||
@@ -45,7 +46,7 @@ IconButton.defaultProps = {
|
|||||||
IconButton.propTypes = {
|
IconButton.propTypes = {
|
||||||
variant: PropTypes.oneOf(['surface', 'positive', 'caution', 'danger']),
|
variant: PropTypes.oneOf(['surface', 'positive', 'caution', 'danger']),
|
||||||
size: PropTypes.oneOf(['normal', 'small', 'extra-small']),
|
size: PropTypes.oneOf(['normal', 'small', 'extra-small']),
|
||||||
type: PropTypes.oneOf(['button', 'submit']),
|
type: PropTypes.oneOf(['button', 'submit', 'reset']),
|
||||||
tooltip: PropTypes.string,
|
tooltip: PropTypes.string,
|
||||||
tooltipPlacement: PropTypes.oneOf(['top', 'right', 'bottom', 'left']),
|
tooltipPlacement: PropTypes.oneOf(['top', 'right', 'bottom', 'left']),
|
||||||
src: PropTypes.string.isRequired,
|
src: PropTypes.string.isRequired,
|
||||||
|
|||||||
@@ -7,13 +7,14 @@ import RawIcon from '../system-icons/RawIcon';
|
|||||||
|
|
||||||
function Chip({
|
function Chip({
|
||||||
iconSrc, iconColor, text, children,
|
iconSrc, iconColor, text, children,
|
||||||
|
onClick,
|
||||||
}) {
|
}) {
|
||||||
return (
|
return (
|
||||||
<div className="chip">
|
<button className="chip" type="button" onClick={onClick}>
|
||||||
{iconSrc != null && <RawIcon src={iconSrc} color={iconColor} size="small" />}
|
{iconSrc != null && <RawIcon src={iconSrc} color={iconColor} size="extra-small" />}
|
||||||
{(text != null && text !== '') && <Text variant="b2">{text}</Text>}
|
{(text != null && text !== '') && <Text variant="b3">{text}</Text>}
|
||||||
{children}
|
{children}
|
||||||
</div>
|
</button>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -22,6 +23,7 @@ Chip.propTypes = {
|
|||||||
iconColor: PropTypes.string,
|
iconColor: PropTypes.string,
|
||||||
text: PropTypes.string,
|
text: PropTypes.string,
|
||||||
children: PropTypes.element,
|
children: PropTypes.element,
|
||||||
|
onClick: PropTypes.func,
|
||||||
};
|
};
|
||||||
|
|
||||||
Chip.defaultProps = {
|
Chip.defaultProps = {
|
||||||
@@ -29,6 +31,7 @@ Chip.defaultProps = {
|
|||||||
iconColor: null,
|
iconColor: null,
|
||||||
text: null,
|
text: null,
|
||||||
children: null,
|
children: null,
|
||||||
|
onClick: null,
|
||||||
};
|
};
|
||||||
|
|
||||||
export default Chip;
|
export default Chip;
|
||||||
|
|||||||
@@ -7,13 +7,27 @@
|
|||||||
|
|
||||||
background: var(--bg-surface-low);
|
background: var(--bg-surface-low);
|
||||||
border-radius: var(--bo-radius);
|
border-radius: var(--bo-radius);
|
||||||
border: 1px solid var(--bg-surface-border);
|
box-shadow: var(--bs-surface-border);
|
||||||
|
cursor: pointer;
|
||||||
|
|
||||||
|
@media (hover: hover) {
|
||||||
|
&:hover {
|
||||||
|
background-color: var(--bg-surface-hover);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
& > .text {
|
||||||
|
flex: 1;
|
||||||
|
color: var(--tc-surface-high);
|
||||||
|
}
|
||||||
|
|
||||||
& > .ic-raw {
|
& > .ic-raw {
|
||||||
margin-right: var(--sp-extra-tight);
|
width: 16px;
|
||||||
|
height: 16px;
|
||||||
|
margin-right: var(--sp-ultra-tight);
|
||||||
[dir=rtl] & {
|
[dir=rtl] & {
|
||||||
margin-right: 0;
|
margin-right: 0;
|
||||||
margin-left: var(--sp-extra-tight);
|
margin-left: var(--sp-ultra-tight);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -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;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import React, { useState } from 'react';
|
import React, { useState, useEffect } from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import './SegmentedControls.scss';
|
import './SegmentedControls.scss';
|
||||||
|
|
||||||
@@ -17,6 +17,10 @@ function SegmentedControls({
|
|||||||
onSelect(segmentIndex);
|
onSelect(segmentIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
setSelect(selected);
|
||||||
|
}, [selected]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="segmented-controls">
|
<div className="segmented-controls">
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -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 {
|
||||||
|
|||||||
@@ -22,11 +22,12 @@
|
|||||||
|
|
||||||
&__avatar-container {
|
&__avatar-container {
|
||||||
padding-top: 6px;
|
padding-top: 6px;
|
||||||
}
|
|
||||||
|
|
||||||
&__avatar-container{
|
|
||||||
margin-right: var(--sp-tight);
|
margin-right: var(--sp-tight);
|
||||||
|
|
||||||
|
& button {
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
[dir=rtl] & {
|
[dir=rtl] & {
|
||||||
margin: {
|
margin: {
|
||||||
left: var(--sp-tight);
|
left: var(--sp-tight);
|
||||||
@@ -159,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);
|
||||||
@@ -261,6 +262,16 @@
|
|||||||
right: unset;
|
right: unset;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@media (min-width: 1620px) {
|
||||||
|
.message__options {
|
||||||
|
right: unset;
|
||||||
|
left: 770px;
|
||||||
|
[dir=rtl] {
|
||||||
|
left: unset;
|
||||||
|
right: 770px
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// markdown formating
|
// markdown formating
|
||||||
.message__content {
|
.message__content {
|
||||||
@@ -398,4 +409,15 @@
|
|||||||
border-bottom-width: 0px !important;
|
border-bottom-width: 0px !important;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.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>
|
||||||
@@ -28,7 +28,7 @@ function RoomIntro({
|
|||||||
}
|
}
|
||||||
|
|
||||||
RoomIntro.defaultProps = {
|
RoomIntro.defaultProps = {
|
||||||
avatarSrc: false,
|
avatarSrc: null,
|
||||||
time: null,
|
time: null,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -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">
|
||||||
|
|||||||
41
src/app/molecules/sso-buttons/SSOButtons.jsx
Normal file
41
src/app/molecules/sso-buttons/SSOButtons.jsx
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import PropTypes from 'prop-types';
|
||||||
|
import './SSOButtons.scss';
|
||||||
|
|
||||||
|
import { createTemporaryClient, startSsoLogin } from '../../../client/action/auth';
|
||||||
|
|
||||||
|
import Button from '../../atoms/button/Button';
|
||||||
|
|
||||||
|
function SSOButtons({ type, identityProviders, baseUrl }) {
|
||||||
|
const tempClient = createTemporaryClient(baseUrl);
|
||||||
|
function handleClick(id) {
|
||||||
|
startSsoLogin(baseUrl, type, id);
|
||||||
|
}
|
||||||
|
return (
|
||||||
|
<div className="sso-buttons">
|
||||||
|
{identityProviders
|
||||||
|
.sort((idp, idp2) => {
|
||||||
|
if (typeof idp.icon !== 'string') return -1;
|
||||||
|
return idp.name.toLowerCase() > idp2.name.toLowerCase() ? 1 : -1;
|
||||||
|
})
|
||||||
|
.map((idp) => (
|
||||||
|
idp.icon
|
||||||
|
? (
|
||||||
|
<button key={idp.id} type="button" className="sso-btn" onClick={() => handleClick(idp.id)}>
|
||||||
|
<img className="sso-btn__img" src={tempClient.mxcUrlToHttp(idp.icon)} alt={idp.name} />
|
||||||
|
</button>
|
||||||
|
) : <Button key={idp.id} className="sso-btn__text-only" onClick={() => handleClick(idp.id)}>{`Login with ${idp.name}`}</Button>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
SSOButtons.propTypes = {
|
||||||
|
identityProviders: PropTypes.arrayOf(
|
||||||
|
PropTypes.shape({}),
|
||||||
|
).isRequired,
|
||||||
|
baseUrl: PropTypes.string.isRequired,
|
||||||
|
type: PropTypes.oneOf(['sso', 'cas']).isRequired,
|
||||||
|
};
|
||||||
|
|
||||||
|
export default SSOButtons;
|
||||||
25
src/app/molecules/sso-buttons/SSOButtons.scss
Normal file
25
src/app/molecules/sso-buttons/SSOButtons.scss
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
.sso-buttons {
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sso-btn {
|
||||||
|
margin: var(--sp-tight);
|
||||||
|
display: inline-flex;
|
||||||
|
justify-content: center;
|
||||||
|
|
||||||
|
cursor: pointer;
|
||||||
|
|
||||||
|
&__img {
|
||||||
|
height: var(--av-small);
|
||||||
|
width: var(--av-small);
|
||||||
|
}
|
||||||
|
&__text-only {
|
||||||
|
margin-top: var(--sp-normal);
|
||||||
|
flex-basis: 100%;
|
||||||
|
& .text {
|
||||||
|
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 {
|
||||||
|
|||||||
@@ -80,17 +80,17 @@ EmojiGroup.propTypes = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const asyncSearch = new AsyncSearch();
|
const asyncSearch = new AsyncSearch();
|
||||||
asyncSearch.setup(emojis, { keys: ['shortcode'], limit: 30 });
|
asyncSearch.setup(emojis, { keys: ['shortcode'], isContain: true, limit: 40 });
|
||||||
function SearchedEmoji() {
|
function SearchedEmoji() {
|
||||||
const [searchedEmojis, setSearchedEmojis] = useState(null);
|
const [searchedEmojis, setSearchedEmojis] = useState(null);
|
||||||
|
|
||||||
function handleSearchEmoji(resultEmojis, term) {
|
function handleSearchEmoji(resultEmojis, term) {
|
||||||
if (term === '' || resultEmojis.length === 0) {
|
if (term === '' || resultEmojis.length === 0) {
|
||||||
if (term === '') setSearchedEmojis(null);
|
if (term === '') setSearchedEmojis(null);
|
||||||
else setSearchedEmojis([]);
|
else setSearchedEmojis({ emojis: [] });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
setSearchedEmojis(resultEmojis);
|
setSearchedEmojis({ emojis: resultEmojis });
|
||||||
}
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -102,7 +102,7 @@ function SearchedEmoji() {
|
|||||||
|
|
||||||
if (searchedEmojis === null) return false;
|
if (searchedEmojis === null) return false;
|
||||||
|
|
||||||
return <EmojiGroup key="-1" name={searchedEmojis.length === 0 ? 'No search result found' : 'Search results'} groupEmojis={searchedEmojis} />;
|
return <EmojiGroup key="-1" name={searchedEmojis.emojis.length === 0 ? 'No search result found' : 'Search results'} groupEmojis={searchedEmojis.emojis} />;
|
||||||
}
|
}
|
||||||
|
|
||||||
function EmojiBoard({ onSelect }) {
|
function EmojiBoard({ onSelect }) {
|
||||||
|
|||||||
@@ -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();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -24,6 +24,28 @@ import PowerIC from '../../../../public/res/ic/outlined/power.svg';
|
|||||||
|
|
||||||
function ProfileAvatarMenu() {
|
function ProfileAvatarMenu() {
|
||||||
const mx = initMatrix.matrixClient;
|
const mx = initMatrix.matrixClient;
|
||||||
|
const [profile, setProfile] = useState({
|
||||||
|
avatarUrl: null,
|
||||||
|
displayName: mx.getUser(mx.getUserId()).displayName,
|
||||||
|
});
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const user = mx.getUser(mx.getUserId());
|
||||||
|
const setNewProfile = (avatarUrl, displayName) => setProfile({
|
||||||
|
avatarUrl: avatarUrl || null,
|
||||||
|
displayName: displayName || profile.displayName,
|
||||||
|
});
|
||||||
|
const onAvatarChange = (event, myUser) => {
|
||||||
|
setNewProfile(myUser.avatarUrl, myUser.displayName);
|
||||||
|
};
|
||||||
|
mx.getProfileInfo(mx.getUserId()).then((info) => {
|
||||||
|
setNewProfile(info.avatar_url, info.displayname);
|
||||||
|
});
|
||||||
|
user.on('User.avatarUrl', onAvatarChange);
|
||||||
|
return () => {
|
||||||
|
user.removeListener('User.avatarUrl', onAvatarChange);
|
||||||
|
};
|
||||||
|
}, []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ContextMenu
|
<ContextMenu
|
||||||
@@ -45,10 +67,10 @@ function ProfileAvatarMenu() {
|
|||||||
render={(toggleMenu) => (
|
render={(toggleMenu) => (
|
||||||
<SidebarAvatar
|
<SidebarAvatar
|
||||||
onClick={toggleMenu}
|
onClick={toggleMenu}
|
||||||
tooltip={mx.getUser(mx.getUserId()).displayName}
|
tooltip={profile.displayName}
|
||||||
imageSrc={mx.getUser(mx.getUserId()).avatarUrl !== null ? mx.mxcUrlToHttp(mx.getUser(mx.getUserId()).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={mx.getUser(mx.getUserId()).displayName.slice(0, 1)}
|
text={profile.displayName}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
@@ -99,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);
|
||||||
@@ -167,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}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import React, { useState, useRef } from 'react';
|
import React, { useState, useEffect, useRef } from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
|
|
||||||
import initMatrix from '../../../client/initMatrix';
|
import initMatrix from '../../../client/initMatrix';
|
||||||
@@ -17,11 +17,17 @@ function ProfileEditor({
|
|||||||
const mx = initMatrix.matrixClient;
|
const mx = initMatrix.matrixClient;
|
||||||
const displayNameRef = useRef(null);
|
const displayNameRef = useRef(null);
|
||||||
const bgColor = colorMXID(userId);
|
const bgColor = colorMXID(userId);
|
||||||
const [avatarSrc, setAvatarSrc] = useState(mx.mxcUrlToHttp(mx.getUser(mx.getUserId()).avatarUrl, 80, 80, 'crop') || null);
|
const [avatarSrc, setAvatarSrc] = useState(null);
|
||||||
const [disabled, setDisabled] = useState(true);
|
const [disabled, setDisabled] = useState(true);
|
||||||
|
|
||||||
let username = mx.getUser(mx.getUserId()).displayName;
|
let username = mx.getUser(mx.getUserId()).displayName;
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
mx.getProfileInfo(mx.getUserId()).then((info) => {
|
||||||
|
setAvatarSrc(info.avatar_url ? mx.mxcUrlToHttp(info.avatar_url, 80, 80, 'crop') : null);
|
||||||
|
});
|
||||||
|
}, [userId]);
|
||||||
|
|
||||||
// Sets avatar URL and updates the avatar component in profile editor to reflect new upload
|
// Sets avatar URL and updates the avatar component in profile editor to reflect new upload
|
||||||
function handleAvatarUpload(url) {
|
function handleAvatarUpload(url) {
|
||||||
if (url === null) {
|
if (url === null) {
|
||||||
|
|||||||
298
src/app/organisms/profile-viewer/ProfileViewer.jsx
Normal file
298
src/app/organisms/profile-viewer/ProfileViewer.jsx
Normal file
@@ -0,0 +1,298 @@
|
|||||||
|
import React, { useState, useEffect, useRef } from 'react';
|
||||||
|
import PropTypes from 'prop-types';
|
||||||
|
import './ProfileViewer.scss';
|
||||||
|
|
||||||
|
import initMatrix from '../../../client/initMatrix';
|
||||||
|
import cons from '../../../client/state/cons';
|
||||||
|
import navigation from '../../../client/state/navigation';
|
||||||
|
import { selectRoom } from '../../../client/action/navigation';
|
||||||
|
import * as roomActions from '../../../client/action/room';
|
||||||
|
|
||||||
|
import { getUsername, getUsernameOfRoomMember, getPowerLabel } from '../../../util/matrixUtil';
|
||||||
|
import colorMXID from '../../../util/colorMXID';
|
||||||
|
|
||||||
|
import Text from '../../atoms/text/Text';
|
||||||
|
import Chip from '../../atoms/chip/Chip';
|
||||||
|
import IconButton from '../../atoms/button/IconButton';
|
||||||
|
import Avatar from '../../atoms/avatar/Avatar';
|
||||||
|
import Button from '../../atoms/button/Button';
|
||||||
|
import Dialog from '../../molecules/dialog/Dialog';
|
||||||
|
import SettingTile from '../../molecules/setting-tile/SettingTile';
|
||||||
|
|
||||||
|
import ShieldEmptyIC from '../../../../public/res/ic/outlined/shield-empty.svg';
|
||||||
|
import ChevronBottomIC from '../../../../public/res/ic/outlined/chevron-bottom.svg';
|
||||||
|
import CrossIC from '../../../../public/res/ic/outlined/cross.svg';
|
||||||
|
|
||||||
|
function SessionInfo({ userId }) {
|
||||||
|
const [devices, setDevices] = useState(null);
|
||||||
|
const mx = initMatrix.matrixClient;
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
let isUnmounted = false;
|
||||||
|
|
||||||
|
async function loadDevices() {
|
||||||
|
try {
|
||||||
|
await mx.downloadKeys([userId], true);
|
||||||
|
const myDevices = mx.getStoredDevicesForUser(userId);
|
||||||
|
|
||||||
|
if (isUnmounted) return;
|
||||||
|
setDevices(myDevices);
|
||||||
|
} catch {
|
||||||
|
setDevices([]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
loadDevices();
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
isUnmounted = true;
|
||||||
|
};
|
||||||
|
}, [userId]);
|
||||||
|
|
||||||
|
function renderSessionChips() {
|
||||||
|
return (
|
||||||
|
<div className="session-info__chips">
|
||||||
|
{devices === null && <Text variant="b3">Loading sessions...</Text>}
|
||||||
|
{devices?.length === 0 && <Text variant="b3">No session found.</Text>}
|
||||||
|
{devices !== null && (devices.map((device) => (
|
||||||
|
<Chip
|
||||||
|
key={device.deviceId}
|
||||||
|
iconSrc={ShieldEmptyIC}
|
||||||
|
text={device.getDisplayName() || device.deviceId}
|
||||||
|
/>
|
||||||
|
)))}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="session-info">
|
||||||
|
<SettingTile
|
||||||
|
title="Sessions"
|
||||||
|
content={renderSessionChips()}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
SessionInfo.propTypes = {
|
||||||
|
userId: PropTypes.string.isRequired,
|
||||||
|
};
|
||||||
|
|
||||||
|
function ProfileFooter({ roomId, userId, onRequestClose }) {
|
||||||
|
const [isCreatingDM, setIsCreatingDM] = useState(false);
|
||||||
|
const [isIgnoring, setIsIgnoring] = useState(false);
|
||||||
|
const [isUserIgnored, setIsUserIgnored] = useState(initMatrix.matrixClient.isUserIgnored(userId));
|
||||||
|
|
||||||
|
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(() => () => {
|
||||||
|
isMountedRef.current = false;
|
||||||
|
}, []);
|
||||||
|
useEffect(() => {
|
||||||
|
setIsUserIgnored(initMatrix.matrixClient.isUserIgnored(userId));
|
||||||
|
setIsIgnoring(false);
|
||||||
|
setIsInviting(false);
|
||||||
|
}, [userId]);
|
||||||
|
|
||||||
|
async function openDM() {
|
||||||
|
const directIds = [...initMatrix.roomList.directs];
|
||||||
|
|
||||||
|
// Check and open if user already have a DM with userId.
|
||||||
|
for (let i = 0; i < directIds.length; i += 1) {
|
||||||
|
const dRoom = mx.getRoom(directIds[i]);
|
||||||
|
const roomMembers = dRoom.getMembers();
|
||||||
|
if (roomMembers.length <= 2 && dRoom.currentState.members[userId]) {
|
||||||
|
selectRoom(directIds[i]);
|
||||||
|
onRequestClose();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create new DM
|
||||||
|
try {
|
||||||
|
setIsCreatingDM(true);
|
||||||
|
const result = await roomActions.create({
|
||||||
|
isEncrypted: true,
|
||||||
|
isDirect: true,
|
||||||
|
invite: [userId],
|
||||||
|
});
|
||||||
|
|
||||||
|
if (isMountedRef.current === false) return;
|
||||||
|
setIsCreatingDM(false);
|
||||||
|
selectRoom(result.room_id);
|
||||||
|
onRequestClose();
|
||||||
|
} catch {
|
||||||
|
setIsCreatingDM(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function toggleIgnore() {
|
||||||
|
const ignoredUsers = mx.getIgnoredUsers();
|
||||||
|
const uIndex = ignoredUsers.indexOf(userId);
|
||||||
|
if (uIndex >= 0) {
|
||||||
|
if (uIndex === -1) return;
|
||||||
|
ignoredUsers.splice(uIndex, 1);
|
||||||
|
} else ignoredUsers.push(userId);
|
||||||
|
|
||||||
|
try {
|
||||||
|
setIsIgnoring(true);
|
||||||
|
await mx.setIgnoredUsers(ignoredUsers);
|
||||||
|
|
||||||
|
if (isMountedRef.current === false) return;
|
||||||
|
setIsUserIgnored(uIndex < 0);
|
||||||
|
setIsIgnoring(false);
|
||||||
|
} catch {
|
||||||
|
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 (
|
||||||
|
<div className="profile-viewer__buttons">
|
||||||
|
<Button
|
||||||
|
variant="primary"
|
||||||
|
onClick={openDM}
|
||||||
|
disabled={isCreatingDM}
|
||||||
|
>
|
||||||
|
{isCreatingDM ? 'Creating room...' : 'Message'}
|
||||||
|
</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
|
||||||
|
variant={isUserIgnored ? 'positive' : 'danger'}
|
||||||
|
onClick={toggleIgnore}
|
||||||
|
disabled={isIgnoring}
|
||||||
|
>
|
||||||
|
{
|
||||||
|
isUserIgnored
|
||||||
|
? `${isIgnoring ? 'Unignoring...' : 'Unignore'}`
|
||||||
|
: `${isIgnoring ? 'Ignoring...' : 'Ignore'}`
|
||||||
|
}
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
ProfileFooter.propTypes = {
|
||||||
|
roomId: PropTypes.string.isRequired,
|
||||||
|
userId: PropTypes.string.isRequired,
|
||||||
|
onRequestClose: PropTypes.func.isRequired,
|
||||||
|
};
|
||||||
|
|
||||||
|
function ProfileViewer() {
|
||||||
|
const [isOpen, setIsOpen] = useState(false);
|
||||||
|
const [roomId, setRoomId] = useState(null);
|
||||||
|
const [userId, setUserId] = useState(null);
|
||||||
|
|
||||||
|
const mx = initMatrix.matrixClient;
|
||||||
|
const room = roomId ? mx.getRoom(roomId) : null;
|
||||||
|
let username = '';
|
||||||
|
if (room !== null) {
|
||||||
|
const roomMember = room.getMember(userId);
|
||||||
|
if (roomMember) username = getUsernameOfRoomMember(roomMember);
|
||||||
|
else username = getUsername(userId);
|
||||||
|
}
|
||||||
|
|
||||||
|
function loadProfile(uId, rId) {
|
||||||
|
setIsOpen(true);
|
||||||
|
setUserId(uId);
|
||||||
|
setRoomId(rId);
|
||||||
|
}
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
navigation.on(cons.events.navigation.PROFILE_VIEWER_OPENED, loadProfile);
|
||||||
|
return () => {
|
||||||
|
navigation.removeListener(cons.events.navigation.PROFILE_VIEWER_OPENED, loadProfile);
|
||||||
|
};
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (isOpen) return;
|
||||||
|
setUserId(null);
|
||||||
|
setRoomId(null);
|
||||||
|
}, [isOpen]);
|
||||||
|
|
||||||
|
function renderProfile() {
|
||||||
|
const member = room.getMember(userId) || mx.getUser(userId) || {};
|
||||||
|
const avatarMxc = member.getMxcAvatarUrl?.() || member.avatarUrl;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="profile-viewer">
|
||||||
|
<div className="profile-viewer__user">
|
||||||
|
<Avatar
|
||||||
|
imageSrc={!avatarMxc ? null : mx.mxcUrlToHttp(avatarMxc, 80, 80, 'crop')}
|
||||||
|
text={username}
|
||||||
|
bgColor={colorMXID(userId)}
|
||||||
|
size="large"
|
||||||
|
/>
|
||||||
|
<div className="profile-viewer__user__info">
|
||||||
|
<Text variant="s1">{username}</Text>
|
||||||
|
<Text variant="b2">{userId}</Text>
|
||||||
|
</div>
|
||||||
|
<div className="profile-viewer__user__role">
|
||||||
|
<Text variant="b3">Role</Text>
|
||||||
|
<Button iconSrc={ChevronBottomIC}>{getPowerLabel(member.powerLevel) || 'Member'}</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<SessionInfo userId={userId} />
|
||||||
|
{ userId !== mx.getUserId() && (
|
||||||
|
<ProfileFooter
|
||||||
|
roomId={roomId}
|
||||||
|
userId={userId}
|
||||||
|
onRequestClose={() => setIsOpen(false)}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Dialog
|
||||||
|
className="profile-viewer__dialog"
|
||||||
|
isOpen={isOpen}
|
||||||
|
title={`${username} in ${room?.name ?? ''}`}
|
||||||
|
onRequestClose={() => setIsOpen(false)}
|
||||||
|
contentOptions={<IconButton src={CrossIC} onClick={() => setIsOpen(false)} tooltip="Close" />}
|
||||||
|
>
|
||||||
|
{isOpen && renderProfile()}
|
||||||
|
</Dialog>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default ProfileViewer;
|
||||||
89
src/app/organisms/profile-viewer/ProfileViewer.scss
Normal file
89
src/app/organisms/profile-viewer/ProfileViewer.scss
Normal file
@@ -0,0 +1,89 @@
|
|||||||
|
.profile-viewer__dialog {
|
||||||
|
& .dialog__content__wrapper {
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
& .dialog__content-container {
|
||||||
|
padding: var(--sp-normal);
|
||||||
|
padding-bottom: 89px;
|
||||||
|
padding-right: var(--sp-extra-tight);
|
||||||
|
[dir=rtl] & {
|
||||||
|
padding-right: var(--sp-normal);
|
||||||
|
padding-left: var(--sp-extra-tight);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.profile-viewer {
|
||||||
|
&__user {
|
||||||
|
display: flex;
|
||||||
|
padding-bottom: var(--sp-normal);
|
||||||
|
border-bottom: 1px solid var(--bg-surface-border);
|
||||||
|
|
||||||
|
&__info {
|
||||||
|
align-self: end;
|
||||||
|
flex: 1;
|
||||||
|
min-width: 0;
|
||||||
|
|
||||||
|
margin: 0 var(--sp-normal);
|
||||||
|
|
||||||
|
& .text-s1 {
|
||||||
|
font-weight: 500;
|
||||||
|
}
|
||||||
|
& .text {
|
||||||
|
white-space: pre-wrap;
|
||||||
|
word-break: break-word;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
&__role {
|
||||||
|
align-self: end;
|
||||||
|
& > .text {
|
||||||
|
margin-bottom: var(--sp-ultra-tight);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
& .session-info {
|
||||||
|
margin-top: var(--sp-normal);
|
||||||
|
}
|
||||||
|
|
||||||
|
&__buttons {
|
||||||
|
position: absolute;
|
||||||
|
left: 0;
|
||||||
|
bottom: 0;
|
||||||
|
|
||||||
|
width: 100%;
|
||||||
|
padding: var(--sp-normal);
|
||||||
|
background-color: var(--bg-surface);
|
||||||
|
border-top: 1px solid var(--bg-surface-border);
|
||||||
|
display: flex;
|
||||||
|
|
||||||
|
& > *:nth-child(2n) {
|
||||||
|
margin: 0 var(--sp-normal)
|
||||||
|
}
|
||||||
|
& > *:last-child {
|
||||||
|
margin-left: auto;
|
||||||
|
[dir=rtl] & {
|
||||||
|
margin-left: 0;
|
||||||
|
margin-right: auto;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.session-info {
|
||||||
|
& .setting-tile__title .text {
|
||||||
|
color: var(--tc-surface-high);
|
||||||
|
}
|
||||||
|
&__chips {
|
||||||
|
padding-top: var(--sp-ultra-tight);
|
||||||
|
& .chip {
|
||||||
|
margin: {
|
||||||
|
top: var(--sp-extra-tight);
|
||||||
|
right: var(--sp-extra-tight);
|
||||||
|
}
|
||||||
|
[dir=rtl] & {
|
||||||
|
margin: 0 0 var(--sp-extra-tight) var(--sp-extra-tight);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,11 +1,13 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
|
||||||
import ReadReceipts from '../read-receipts/ReadReceipts';
|
import ReadReceipts from '../read-receipts/ReadReceipts';
|
||||||
|
import ProfileViewer from '../profile-viewer/ProfileViewer';
|
||||||
|
|
||||||
function Dialogs() {
|
function Dialogs() {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<ReadReceipts />
|
<ReadReceipts />
|
||||||
|
<ProfileViewer />
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import PeopleSelector from '../../molecules/people-selector/PeopleSelector';
|
|||||||
import Dialog from '../../molecules/dialog/Dialog';
|
import Dialog from '../../molecules/dialog/Dialog';
|
||||||
|
|
||||||
import CrossIC from '../../../../public/res/ic/outlined/cross.svg';
|
import CrossIC from '../../../../public/res/ic/outlined/cross.svg';
|
||||||
|
import { openProfileViewer } from '../../../client/action/navigation';
|
||||||
|
|
||||||
function ReadReceipts() {
|
function ReadReceipts() {
|
||||||
const [isOpen, setIsOpen] = useState(false);
|
const [isOpen, setIsOpen] = useState(false);
|
||||||
@@ -58,7 +59,10 @@ function ReadReceipts() {
|
|||||||
return (
|
return (
|
||||||
<PeopleSelector
|
<PeopleSelector
|
||||||
key={receipt.userId}
|
key={receipt.userId}
|
||||||
onClick={() => alert('Viewing profile is yet to be implemented')}
|
onClick={() => {
|
||||||
|
setIsOpen(false);
|
||||||
|
openProfileViewer(receipt.userId, roomId);
|
||||||
|
}}
|
||||||
avatarSrc={member?.getAvatarUrl(initMatrix.matrixClient.baseUrl, 24, 24, 'crop')}
|
avatarSrc={member?.getAvatarUrl(initMatrix.matrixClient.baseUrl, 24, 24, 'crop')}
|
||||||
name={getUserDisplayName(receipt.userId)}
|
name={getUserDisplayName(receipt.userId)}
|
||||||
color={colorMXID(receipt.userId)}
|
color={colorMXID(receipt.userId)}
|
||||||
|
|||||||
@@ -1,29 +1,29 @@
|
|||||||
import React, { useState, useEffect } from 'react';
|
import React, {
|
||||||
|
useState, useEffect, useCallback, useRef,
|
||||||
|
} from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import './PeopleDrawer.scss';
|
import './PeopleDrawer.scss';
|
||||||
|
|
||||||
import initMatrix from '../../../client/initMatrix';
|
import initMatrix from '../../../client/initMatrix';
|
||||||
import { getUsernameOfRoomMember } from '../../../util/matrixUtil';
|
import { getPowerLabel, getUsernameOfRoomMember } from '../../../util/matrixUtil';
|
||||||
import colorMXID from '../../../util/colorMXID';
|
import colorMXID from '../../../util/colorMXID';
|
||||||
import { openInviteUser } from '../../../client/action/navigation';
|
import { openInviteUser, openProfileViewer } from '../../../client/action/navigation';
|
||||||
|
import AsyncSearch from '../../../util/AsyncSearch';
|
||||||
|
|
||||||
import Text from '../../atoms/text/Text';
|
import Text from '../../atoms/text/Text';
|
||||||
import Header, { TitleWrapper } from '../../atoms/header/Header';
|
import Header, { TitleWrapper } from '../../atoms/header/Header';
|
||||||
|
import RawIcon from '../../atoms/system-icons/RawIcon';
|
||||||
import IconButton from '../../atoms/button/IconButton';
|
import IconButton from '../../atoms/button/IconButton';
|
||||||
import Button from '../../atoms/button/Button';
|
import Button from '../../atoms/button/Button';
|
||||||
import ScrollView from '../../atoms/scroll/ScrollView';
|
import ScrollView from '../../atoms/scroll/ScrollView';
|
||||||
import Input from '../../atoms/input/Input';
|
import Input from '../../atoms/input/Input';
|
||||||
|
import SegmentedControl from '../../atoms/segmented-controls/SegmentedControls';
|
||||||
import PeopleSelector from '../../molecules/people-selector/PeopleSelector';
|
import PeopleSelector from '../../molecules/people-selector/PeopleSelector';
|
||||||
|
|
||||||
import AddUserIC from '../../../../public/res/ic/outlined/add-user.svg';
|
import AddUserIC from '../../../../public/res/ic/outlined/add-user.svg';
|
||||||
|
import SearchIC from '../../../../public/res/ic/outlined/search.svg';
|
||||||
|
import CrossIC from '../../../../public/res/ic/outlined/cross.svg';
|
||||||
|
|
||||||
function getPowerLabel(powerLevel) {
|
|
||||||
if (powerLevel > 9000) return 'Goku';
|
|
||||||
if (powerLevel > 100) return 'Founder';
|
|
||||||
if (powerLevel === 100) return 'Admin';
|
|
||||||
if (powerLevel >= 50) return 'Mod';
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
function AtoZ(m1, m2) {
|
function AtoZ(m1, m2) {
|
||||||
const aName = m1.name;
|
const aName = m1.name;
|
||||||
const bName = m2.name;
|
const bName = m2.name;
|
||||||
@@ -44,31 +44,102 @@ function sortByPowerLevel(m1, m2) {
|
|||||||
if (pl1 < pl2) return 1;
|
if (pl1 < pl2) return 1;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
function simplyfiMembers(members) {
|
||||||
|
const mx = initMatrix.matrixClient;
|
||||||
|
return members.map((member) => ({
|
||||||
|
userId: member.userId,
|
||||||
|
name: getUsernameOfRoomMember(member),
|
||||||
|
username: member.userId.slice(1, member.userId.indexOf(':')),
|
||||||
|
avatarSrc: member.getAvatarUrl(mx.baseUrl, 24, 24, 'crop'),
|
||||||
|
peopleRole: getPowerLabel(member.powerLevel),
|
||||||
|
powerLevel: members.powerLevel,
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
const asyncSearch = new AsyncSearch();
|
||||||
function PeopleDrawer({ roomId }) {
|
function PeopleDrawer({ roomId }) {
|
||||||
const PER_PAGE_MEMBER = 50;
|
const PER_PAGE_MEMBER = 50;
|
||||||
const room = initMatrix.matrixClient.getRoom(roomId);
|
const mx = initMatrix.matrixClient;
|
||||||
const totalMemberList = room.getJoinedMembers().sort(AtoZ).sort(sortByPowerLevel);
|
const room = mx.getRoom(roomId);
|
||||||
const [memberList, updateMemberList] = useState([]);
|
|
||||||
let isRoomChanged = false;
|
let isRoomChanged = false;
|
||||||
|
|
||||||
|
const [itemCount, setItemCount] = useState(PER_PAGE_MEMBER);
|
||||||
|
const [membership, setMembership] = useState('join');
|
||||||
|
const [memberList, setMemberList] = useState([]);
|
||||||
|
const [searchedMembers, setSearchedMembers] = useState(null);
|
||||||
|
const searchRef = useRef(null);
|
||||||
|
|
||||||
|
const getMembersWithMembership = useCallback(
|
||||||
|
(mship) => room.getMembersWithMembership(mship),
|
||||||
|
[roomId, membership],
|
||||||
|
);
|
||||||
|
|
||||||
function loadMorePeople() {
|
function loadMorePeople() {
|
||||||
updateMemberList(totalMemberList.slice(0, memberList.length + PER_PAGE_MEMBER));
|
setItemCount(itemCount + PER_PAGE_MEMBER);
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleSearchData(data) {
|
||||||
|
// NOTICE: data is passed as object property
|
||||||
|
// because react sucks at handling state update with array.
|
||||||
|
setSearchedMembers({ data });
|
||||||
|
setItemCount(PER_PAGE_MEMBER);
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleSearch(e) {
|
||||||
|
const term = e.target.value;
|
||||||
|
if (term === '' || term === undefined) {
|
||||||
|
searchRef.current.value = '';
|
||||||
|
searchRef.current.focus();
|
||||||
|
setSearchedMembers(null);
|
||||||
|
setItemCount(PER_PAGE_MEMBER);
|
||||||
|
} else asyncSearch.search(term);
|
||||||
}
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
updateMemberList(totalMemberList.slice(0, PER_PAGE_MEMBER));
|
asyncSearch.setup(memberList, {
|
||||||
|
keys: ['name', 'username', 'userId'],
|
||||||
|
limit: PER_PAGE_MEMBER,
|
||||||
|
});
|
||||||
|
}, [memberList]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
let isGettingMembers = true;
|
||||||
|
const updateMemberList = (event) => {
|
||||||
|
if (isGettingMembers) return;
|
||||||
|
console.log(event?.event?.room_id);
|
||||||
|
if (event && event?.event?.room_id !== roomId) return;
|
||||||
|
setMemberList(
|
||||||
|
simplyfiMembers(
|
||||||
|
getMembersWithMembership(membership)
|
||||||
|
.sort(AtoZ).sort(sortByPowerLevel),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
};
|
||||||
|
searchRef.current.value = '';
|
||||||
|
updateMemberList();
|
||||||
room.loadMembersIfNeeded().then(() => {
|
room.loadMembersIfNeeded().then(() => {
|
||||||
|
isGettingMembers = false;
|
||||||
if (isRoomChanged) return;
|
if (isRoomChanged) return;
|
||||||
const newTotalMemberList = room.getJoinedMembers().sort(AtoZ).sort(sortByPowerLevel);
|
updateMemberList();
|
||||||
updateMemberList(newTotalMemberList.slice(0, PER_PAGE_MEMBER));
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
asyncSearch.on(asyncSearch.RESULT_SENT, handleSearchData);
|
||||||
|
mx.on('RoomMember.membership', updateMemberList);
|
||||||
return () => {
|
return () => {
|
||||||
isRoomChanged = true;
|
isRoomChanged = true;
|
||||||
|
setMemberList([]);
|
||||||
|
setSearchedMembers(null);
|
||||||
|
setItemCount(PER_PAGE_MEMBER);
|
||||||
|
asyncSearch.removeListener(asyncSearch.RESULT_SENT, handleSearchData);
|
||||||
|
mx.removeListener('RoomMember.membership', updateMemberList);
|
||||||
};
|
};
|
||||||
|
}, [roomId, membership]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
setMembership('join');
|
||||||
}, [roomId]);
|
}, [roomId]);
|
||||||
|
|
||||||
|
const mList = searchedMembers !== null ? searchedMembers.data : memberList.slice(0, itemCount);
|
||||||
return (
|
return (
|
||||||
<div className="people-drawer">
|
<div className="people-drawer">
|
||||||
<Header>
|
<Header>
|
||||||
@@ -84,21 +155,53 @@ function PeopleDrawer({ roomId }) {
|
|||||||
<div className="people-drawer__scrollable">
|
<div className="people-drawer__scrollable">
|
||||||
<ScrollView autoHide>
|
<ScrollView autoHide>
|
||||||
<div className="people-drawer__content">
|
<div className="people-drawer__content">
|
||||||
|
<SegmentedControl
|
||||||
|
selected={
|
||||||
|
(() => {
|
||||||
|
const getSegmentIndex = {
|
||||||
|
join: 0,
|
||||||
|
invite: 1,
|
||||||
|
ban: 2,
|
||||||
|
};
|
||||||
|
return getSegmentIndex[membership];
|
||||||
|
})()
|
||||||
|
}
|
||||||
|
segments={[{ text: 'Joined' }, { text: 'Invited' }, { text: 'Banned' }]}
|
||||||
|
onSelect={(index) => {
|
||||||
|
const selectSegment = [
|
||||||
|
() => setMembership('join'),
|
||||||
|
() => setMembership('invite'),
|
||||||
|
() => setMembership('ban'),
|
||||||
|
];
|
||||||
|
selectSegment[index]?.();
|
||||||
|
}}
|
||||||
|
/>
|
||||||
{
|
{
|
||||||
memberList.map((member) => (
|
mList.map((member) => (
|
||||||
<PeopleSelector
|
<PeopleSelector
|
||||||
key={member.userId}
|
key={member.userId}
|
||||||
onClick={() => alert('Viewing profile is yet to be implemented')}
|
onClick={() => openProfileViewer(member.userId, roomId)}
|
||||||
avatarSrc={member.getAvatarUrl(initMatrix.matrixClient.baseUrl, 24, 24, 'crop')}
|
avatarSrc={member.avatarSrc}
|
||||||
name={getUsernameOfRoomMember(member)}
|
name={member.name}
|
||||||
color={colorMXID(member.userId)}
|
color={colorMXID(member.userId)}
|
||||||
peopleRole={getPowerLabel(member.powerLevel)}
|
peopleRole={member.peopleRole}
|
||||||
/>
|
/>
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
{
|
||||||
|
(searchedMembers?.data.length === 0 || memberList.length === 0)
|
||||||
|
&& (
|
||||||
|
<div className="people-drawer__noresult">
|
||||||
|
<Text variant="b2">No result found!</Text>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
<div className="people-drawer__load-more">
|
<div className="people-drawer__load-more">
|
||||||
{
|
{
|
||||||
memberList.length !== totalMemberList.length && (
|
mList.length !== 0
|
||||||
|
&& memberList.length > itemCount
|
||||||
|
&& searchedMembers === null
|
||||||
|
&& (
|
||||||
<Button onClick={loadMorePeople}>View more</Button>
|
<Button onClick={loadMorePeople}>View more</Button>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -108,7 +211,12 @@ function PeopleDrawer({ roomId }) {
|
|||||||
</div>
|
</div>
|
||||||
<div className="people-drawer__sticky">
|
<div className="people-drawer__sticky">
|
||||||
<form onSubmit={(e) => e.preventDefault()} className="people-search">
|
<form onSubmit={(e) => e.preventDefault()} className="people-search">
|
||||||
<Input type="text" placeholder="Search" required />
|
<RawIcon size="small" src={SearchIC} />
|
||||||
|
<Input forwardRef={searchRef} type="text" onChange={handleSearch} placeholder="Search" required />
|
||||||
|
{
|
||||||
|
searchedMembers !== null
|
||||||
|
&& <IconButton onClick={handleSearch} size="small" src={CrossIC} />
|
||||||
|
}
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -35,19 +35,48 @@
|
|||||||
@extend .people-drawer-flexItem;
|
@extend .people-drawer-flexItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
&__sticky {
|
&__noresult {
|
||||||
display: none;
|
padding: var(--sp-extra-tight) var(--sp-normal);
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
&__sticky {
|
||||||
& .people-search {
|
& .people-search {
|
||||||
min-height: 48px;
|
--search-input-height: 40px;
|
||||||
|
min-height: var(--search-input-height);
|
||||||
|
|
||||||
margin: 0 var(--sp-normal);
|
margin: 0 var(--sp-normal);
|
||||||
|
|
||||||
position: relative;
|
position: relative;
|
||||||
bottom: var(--sp-normal);
|
bottom: var(--sp-normal);
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
|
||||||
|
& > .ic-raw,
|
||||||
|
& > .ic-btn {
|
||||||
|
position: absolute;
|
||||||
|
z-index: 99;
|
||||||
|
}
|
||||||
|
& > .ic-raw {
|
||||||
|
left: var(--sp-tight);
|
||||||
|
[dir=rtl] & {
|
||||||
|
right: var(--sp-tight);
|
||||||
|
left: unset;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
& > .ic-btn {
|
||||||
|
right: 2px;
|
||||||
|
[dir=rtl] & {
|
||||||
|
left: 2px;
|
||||||
|
right: unset;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
& .input-container {
|
||||||
|
flex: 1;
|
||||||
|
}
|
||||||
& .input {
|
& .input {
|
||||||
height: 48px;
|
padding: 0 calc(var(--sp-loose) + var(--sp-normal));
|
||||||
|
height: var(--search-input-height);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -55,7 +84,21 @@
|
|||||||
|
|
||||||
.people-drawer__content {
|
.people-drawer__content {
|
||||||
padding-top: var(--sp-extra-tight);
|
padding-top: var(--sp-extra-tight);
|
||||||
padding-bottom: calc( var(--sp-extra-tight) + var(--sp-normal));
|
padding-bottom: calc(2 * var(--sp-normal));
|
||||||
|
|
||||||
|
& .segmented-controls {
|
||||||
|
display: flex;
|
||||||
|
margin-bottom: var(--sp-extra-tight);
|
||||||
|
margin-left: var(--sp-extra-tight);
|
||||||
|
[dir=rtl] & {
|
||||||
|
margin-left: unset;
|
||||||
|
margin-right: var(--sp-extra-tight);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
& .segment-btn {
|
||||||
|
flex: 1;
|
||||||
|
padding: var(--sp-ultra-tight) 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
.people-drawer__load-more {
|
.people-drawer__load-more {
|
||||||
padding: var(--sp-normal);
|
padding: var(--sp-normal);
|
||||||
|
|||||||
@@ -319,6 +319,7 @@ function RoomViewCmdBar({ roomId, roomTimeline, viewEvent }) {
|
|||||||
else if (searchTerm.match(/^[-]?(\()$/)) searchTerm = 'pleading_face';
|
else if (searchTerm.match(/^[-]?(\()$/)) searchTerm = 'pleading_face';
|
||||||
else if (searchTerm.match(/^[-]?(\$)$/)) searchTerm = 'money';
|
else if (searchTerm.match(/^[-]?(\$)$/)) searchTerm = 'money';
|
||||||
else if (searchTerm.match(/^(<3)$/)) searchTerm = 'heart';
|
else if (searchTerm.match(/^(<3)$/)) searchTerm = 'heart';
|
||||||
|
else if (searchTerm.match(/^(c|ca|cat)$/)) searchTerm = '_cat';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -343,7 +344,7 @@ function RoomViewCmdBar({ roomId, roomTimeline, viewEvent }) {
|
|||||||
'>*': () => asyncSearch.setup(getRooms([...roomList.spaces]), { keys: ['name'], limit: 20 }),
|
'>*': () => asyncSearch.setup(getRooms([...roomList.spaces]), { keys: ['name'], limit: 20 }),
|
||||||
'>#': () => asyncSearch.setup(getRooms([...roomList.rooms]), { keys: ['name'], limit: 20 }),
|
'>#': () => asyncSearch.setup(getRooms([...roomList.rooms]), { keys: ['name'], limit: 20 }),
|
||||||
'>@': () => asyncSearch.setup(getRooms([...roomList.directs]), { keys: ['name'], limit: 20 }),
|
'>@': () => asyncSearch.setup(getRooms([...roomList.directs]), { keys: ['name'], limit: 20 }),
|
||||||
':': () => asyncSearch.setup(emojis, { keys: ['shortcode'], limit: 20 }),
|
':': () => asyncSearch.setup(emojis, { keys: ['shortcode'], isContain: true, limit: 20 }),
|
||||||
'@': () => asyncSearch.setup(matrixClient.getRoom(roomId).getJoinedMembers().map((member) => ({
|
'@': () => asyncSearch.setup(matrixClient.getRoom(roomId).getJoinedMembers().map((member) => ({
|
||||||
name: member.name,
|
name: member.name,
|
||||||
userId: member.userId.slice(1),
|
userId: member.userId.slice(1),
|
||||||
|
|||||||
@@ -8,10 +8,10 @@ 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, openReadReceipts } from '../../../client/action/navigation';
|
import { openEmojiBoard, openProfileViewer, openReadReceipts } from '../../../client/action/navigation';
|
||||||
|
|
||||||
import Divider from '../../atoms/divider/Divider';
|
import Divider from '../../atoms/divider/Divider';
|
||||||
import Avatar from '../../atoms/avatar/Avatar';
|
import Avatar from '../../atoms/avatar/Avatar';
|
||||||
@@ -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';
|
||||||
@@ -353,12 +355,14 @@ function RoomViewContent({
|
|||||||
|
|
||||||
const senderMXIDColor = colorMXID(mEvent.sender.userId);
|
const senderMXIDColor = colorMXID(mEvent.sender.userId);
|
||||||
const userAvatar = isContentOnly ? null : (
|
const userAvatar = isContentOnly ? null : (
|
||||||
<Avatar
|
<button type="button" onClick={() => openProfileViewer(mEvent.sender.userId, roomId)}>
|
||||||
imageSrc={mEvent.sender.getAvatarUrl(initMatrix.matrixClient.baseUrl, 36, 36, 'crop')}
|
<Avatar
|
||||||
text={getUsernameOfRoomMember(mEvent.sender).slice(0, 1)}
|
imageSrc={mEvent.sender.getAvatarUrl(initMatrix.matrixClient.baseUrl, 36, 36, 'crop')}
|
||||||
bgColor={senderMXIDColor}
|
text={getUsernameOfRoomMember(mEvent.sender)}
|
||||||
size="small"
|
bgColor={senderMXIDColor}
|
||||||
/>
|
size="small"
|
||||||
|
/>
|
||||||
|
</button>
|
||||||
);
|
);
|
||||||
const userHeader = isContentOnly ? null : (
|
const userHeader = isContentOnly ? null : (
|
||||||
<MessageHeader
|
<MessageHeader
|
||||||
@@ -377,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}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
@@ -494,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;
|
||||||
@@ -313,6 +313,7 @@ function RoomViewInput({
|
|||||||
|
|
||||||
function addEmoji(emoji) {
|
function addEmoji(emoji) {
|
||||||
textAreaRef.current.value += emoji.unicode;
|
textAreaRef.current.value += emoji.unicode;
|
||||||
|
textAreaRef.current.focus();
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleUploadClick() {
|
function handleUploadClick() {
|
||||||
@@ -327,8 +328,7 @@ function RoomViewInput({
|
|||||||
if (file !== null) roomsInput.setAttachment(roomId, file);
|
if (file !== null) roomsInput.setAttachment(roomId, file);
|
||||||
}
|
}
|
||||||
|
|
||||||
const myPowerlevel = roomTimeline.room.getMember(mx.getUserId()).powerLevel;
|
const canISend = roomTimeline.room.currentState.maySendMessage(mx.getUserId());
|
||||||
const canISend = roomTimeline.room.currentState.hasSufficientPowerLevelFor('events_default', myPowerlevel);
|
|
||||||
|
|
||||||
function renderInputs() {
|
function renderInputs() {
|
||||||
if (!canISend) {
|
if (!canISend) {
|
||||||
|
|||||||
@@ -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,13 +105,13 @@ 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.3.2</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>
|
||||||
|
|
||||||
<div className="set-about__btns">
|
<div className="set-about__btns">
|
||||||
<Button onClick={() => window.open('https://github.com/ajbura/cinny')}>Source code</Button>
|
<Button onClick={() => window.open('https://github.com/ajbura/cinny')}>Source code</Button>
|
||||||
<Button onClick={() => window.open('https://liberapay.com/ajbura/donate')}>Support</Button>
|
<Button onClick={() => window.open('https://cinny.in/#sponsor')}>Support</Button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import {
|
import {
|
||||||
BrowserRouter, Switch, Route, Redirect,
|
BrowserRouter,
|
||||||
} from 'react-router-dom';
|
} from 'react-router-dom';
|
||||||
|
|
||||||
import { isAuthenticated } from '../../client/state/auth';
|
import { isAuthenticated } from '../../client/state/auth';
|
||||||
@@ -11,17 +11,7 @@ import Client from '../templates/client/Client';
|
|||||||
function App() {
|
function App() {
|
||||||
return (
|
return (
|
||||||
<BrowserRouter>
|
<BrowserRouter>
|
||||||
<Switch>
|
{ isAuthenticated() ? <Client /> : <Auth />}
|
||||||
<Route exact path="/">
|
|
||||||
{ isAuthenticated() ? <Client /> : <Redirect to="/login" />}
|
|
||||||
</Route>
|
|
||||||
<Route path="/login">
|
|
||||||
{ isAuthenticated() ? <Redirect to="/" /> : <Auth type="login" />}
|
|
||||||
</Route>
|
|
||||||
<Route path="/register">
|
|
||||||
{ isAuthenticated() ? <Redirect to="/" /> : <Auth type="register" />}
|
|
||||||
</Route>
|
|
||||||
</Switch>
|
|
||||||
</BrowserRouter>
|
</BrowserRouter>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +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 { Link } 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 { 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';
|
||||||
@@ -12,320 +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';
|
||||||
|
|
||||||
// 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({ type }) {
|
let searchingHs = null;
|
||||||
const [process, changeProcess] = useState(null);
|
function Homeserver({ onChange }) {
|
||||||
const usernameRef = useRef(null);
|
const [hs, setHs] = useState(null);
|
||||||
const homeserverRef = useRef(null);
|
const [debounce] = useState(new Debounce());
|
||||||
const passwordRef = useRef(null);
|
const [process, setProcess] = useState({ isLoading: true, message: 'Loading homeserver list...' });
|
||||||
const confirmPasswordRef = useRef(null);
|
const hsRef = useRef();
|
||||||
const emailRef = useRef(null);
|
|
||||||
|
|
||||||
function register(recaptchaValue, terms, verified) {
|
const setupHsConfig = async (servername) => {
|
||||||
auth.register(
|
setProcess({ isLoading: true, message: 'Looking for homeserver...' });
|
||||||
usernameRef.current.value,
|
let baseUrl = null;
|
||||||
homeserverRef.current.value,
|
try {
|
||||||
passwordRef.current.value,
|
baseUrl = await getBaseUrl(servername);
|
||||||
emailRef.current.value,
|
} catch (e) {
|
||||||
recaptchaValue,
|
baseUrl = e.message;
|
||||||
terms,
|
}
|
||||||
verified,
|
if (searchingHs !== servername) return;
|
||||||
).then((res) => {
|
setProcess({ isLoading: true, message: `Connecting to ${baseUrl}...` });
|
||||||
document.getElementById('auth_submit-btn').disabled = false;
|
const tempClient = auth.createTemporaryClient(baseUrl);
|
||||||
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) {
|
Promise.allSettled([tempClient.loginFlows(), tempClient.register()])
|
||||||
e.preventDefault();
|
.then((values) => {
|
||||||
document.getElementById('auth_submit-btn').disabled = true;
|
const loginFlow = values[0].status === 'fulfilled' ? values[0]?.value : undefined;
|
||||||
document.getElementById('auth_error').style.display = 'none';
|
const registerFlow = values[1].status === 'rejected' ? values[1]?.reason?.data : undefined;
|
||||||
|
if (loginFlow === undefined || registerFlow === undefined) throw new Error();
|
||||||
|
|
||||||
/** @type {string} */
|
if (searchingHs !== servername) return;
|
||||||
const rawUsername = usernameRef.current.value;
|
onChange({ baseUrl, login: loginFlow, register: registerFlow });
|
||||||
/** @type {string} */
|
setProcess({ isLoading: false });
|
||||||
const normalizedUsername = normalizeUsername(rawUsername);
|
}).catch(() => {
|
||||||
|
if (searchingHs !== servername) return;
|
||||||
auth.login(normalizedUsername, homeserverRef.current.value, passwordRef.current.value)
|
onChange(null);
|
||||||
.then(() => {
|
setProcess({ isLoading: false, error: 'Unable to connect. Please check your input.' });
|
||||||
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}
|
|
||||||
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>
|
|
||||||
</form>
|
|
||||||
</div>
|
</div>
|
||||||
|
)}
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
Homeserver.propTypes = {
|
||||||
|
onChange: PropTypes.func.isRequired,
|
||||||
|
};
|
||||||
|
|
||||||
<div 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'];
|
||||||
<Link to={type === 'login' ? '/register' : '/login'}>
|
const isPassword = loginFlow?.filter((flow) => flow.type === 'm.login.password')[0];
|
||||||
{ type === 'login' ? ' Register' : ' Login' }
|
const ssoProviders = loginFlow?.filter((flow) => flow.type === 'm.login.sso')[0];
|
||||||
</Link>
|
|
||||||
</Text>
|
const initialValues = {
|
||||||
</div>
|
username: '', password: '', email: '', other: '',
|
||||||
</StaticWrapper>
|
};
|
||||||
|
|
||||||
|
const validator = (values) => {
|
||||||
|
const errors = {};
|
||||||
|
if (typeIndex === 0 && values.username.length > 0 && values.username.indexOf(':') > -1) {
|
||||||
|
errors.username = 'Username must contain local-part only';
|
||||||
|
}
|
||||||
|
if (typeIndex === 1 && values.email.length > 0 && !isValidInput(values.email, EMAIL_REGEX)) {
|
||||||
|
errors.email = BAD_EMAIL_ERROR;
|
||||||
|
}
|
||||||
|
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>
|
||||||
|
)}
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Auth.propTypes = {
|
function Auth() {
|
||||||
type: PropTypes.string.isRequired,
|
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);
|
||||||
|
}
|
||||||
|
}, []);
|
||||||
|
|
||||||
function StaticWrapper({ children }) {
|
|
||||||
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>
|
||||||
@@ -359,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)' }} />
|
||||||
@@ -382,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;
|
||||||
&__interactive{
|
}
|
||||||
flex: 1;
|
.auth-footer {
|
||||||
min-width: 0;
|
padding: var(--sp-normal) 0;
|
||||||
}
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
|
||||||
&__interactive {
|
& > *:nth-child(2n) {
|
||||||
padding: calc(var(--sp-normal) + var(--sp-extra-loose));
|
margin: 0 var(--sp-loose);
|
||||||
padding-bottom: var(--sp-extra-loose);
|
}
|
||||||
background-color: var(--bg-surface);
|
& a {
|
||||||
}
|
color: var(--tc-surface-normal);
|
||||||
|
&:hover { text-decoration: underline; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.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);
|
||||||
|
}
|
||||||
|
|
||||||
|
&__heading {
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
margin-top: calc(var(--sp-extra-loose) + var(--sp-tight));
|
||||||
}
|
}
|
||||||
|
|
||||||
.submit-btn__wrapper {
|
&__btns {
|
||||||
margin-top: var(--sp-extra-loose);
|
padding-top: var(--sp-loose);
|
||||||
margin-bottom: var(--sp-loose);
|
margin-bottom: var(--sp-extra-loose);
|
||||||
align-items: flex-start;
|
display: flex;
|
||||||
|
justify-content: flex-end;
|
||||||
& > .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 {
|
&__error {
|
||||||
height: 100%;
|
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,152 +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';
|
|
||||||
|
|
||||||
async function login(username, homeserver, password) {
|
function updateLocalStore(accessToken, deviceId, userId, baseUrl) {
|
||||||
let baseUrl = null;
|
localStorage.setItem(cons.secretKey.ACCESS_TOKEN, accessToken);
|
||||||
try {
|
localStorage.setItem(cons.secretKey.DEVICE_ID, deviceId);
|
||||||
baseUrl = await getBaseUrl(homeserver);
|
localStorage.setItem(cons.secretKey.USER_ID, userId);
|
||||||
} catch (e) {
|
localStorage.setItem(cons.secretKey.BASE_URL, baseUrl);
|
||||||
baseUrl = `https://${homeserver}`;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (typeof baseUrl === 'undefined') throw new Error('Homeserver not found');
|
function createTemporaryClient(baseUrl) {
|
||||||
|
return sdk.createClient({ baseUrl });
|
||||||
|
}
|
||||||
|
|
||||||
const client = sdk.createClient({ baseUrl });
|
async function startSsoLogin(baseUrl, type, idpId) {
|
||||||
|
const client = createTemporaryClient(baseUrl);
|
||||||
|
localStorage.setItem(cons.secretKey.BASE_URL, client.baseUrl);
|
||||||
|
window.location.href = client.getSsoLoginUrl(window.location.href, type, idpId);
|
||||||
|
}
|
||||||
|
|
||||||
const response = await client.login('m.login.password', {
|
async function login(baseUrl, username, email, password) {
|
||||||
identifier: {
|
const identifier = {};
|
||||||
type: 'm.id.user',
|
if (username) {
|
||||||
user: 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 client = createTemporaryClient(baseUrl);
|
||||||
|
const res = await client.login('m.login.password', {
|
||||||
|
identifier,
|
||||||
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 || baseUrl);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getAdditionalInfo(baseUrl, content) {
|
async function loginWithToken(baseUrl, token) {
|
||||||
try {
|
const client = createTemporaryClient(baseUrl);
|
||||||
const res = await fetch(`${baseUrl}/_matrix/client/r0/register`, {
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
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;
|
const res = await client.login('m.login.token', {
|
||||||
let clientSecret = null;
|
token,
|
||||||
let sid = null;
|
initial_device_display_name: cons.DEVICE_DISPLAY_NAME,
|
||||||
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;
|
|
||||||
if (typeof additionalInfo.completed === 'undefined' || additionalInfo.completed.length === 0) {
|
const myBaseUrl = res?.well_known?.['m.homeserver']?.base_url || client.baseUrl;
|
||||||
return ({
|
updateLocalStore(res.access_token, res.device_id, res.user_id, myBaseUrl);
|
||||||
type: 'recaptcha',
|
}
|
||||||
public_key: additionalInfo.params['m.login.recaptcha'].public_key,
|
|
||||||
});
|
// eslint-disable-next-line camelcase
|
||||||
}
|
async function verifyEmail(baseUrl, email, client_secret, send_attempt, next_link) {
|
||||||
if (additionalInfo.completed.find((process) => process === 'm.login.recaptcha') === 'm.login.recaptcha'
|
const res = await fetch(`${baseUrl}/_matrix/client/r0/register/email/requestToken`, {
|
||||||
&& !additionalInfo.completed.find((process) => process === 'm.login.terms')) {
|
method: 'POST',
|
||||||
return ({
|
body: JSON.stringify({
|
||||||
type: 'terms',
|
email, client_secret, send_attempt, next_link,
|
||||||
en: additionalInfo.params['m.login.terms'].policies.privacy_policy.en,
|
}),
|
||||||
});
|
headers: {
|
||||||
}
|
'Content-Type': 'application/json; charset=utf-8',
|
||||||
if (verified || additionalInfo.completed.find((process) => process === 'm.login.terms') === 'm.login.terms') {
|
},
|
||||||
const tpc = {
|
credentials: 'same-origin',
|
||||||
client_secret: clientSecret,
|
});
|
||||||
sid,
|
const data = await res.json();
|
||||||
};
|
return data;
|
||||||
const verifyData = await getAdditionalInfo(baseUrl, {
|
}
|
||||||
auth: {
|
|
||||||
session,
|
async function completeRegisterStage(
|
||||||
type: 'm.login.email.identity',
|
baseUrl, username, password, auth,
|
||||||
threepidCreds: tpc,
|
) {
|
||||||
threepid_creds: tpc,
|
const tempClient = createTemporaryClient(baseUrl);
|
||||||
},
|
|
||||||
|
try {
|
||||||
|
const result = await tempClient.registerRequest({
|
||||||
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 { login, register };
|
export {
|
||||||
|
createTemporaryClient, login, verifyEmail,
|
||||||
|
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();
|
||||||
|
|||||||
@@ -55,6 +55,14 @@ function openInviteUser(roomId, searchTerm) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function openProfileViewer(userId, roomId) {
|
||||||
|
appDispatcher.dispatch({
|
||||||
|
type: cons.actions.navigation.OPEN_PROFILE_VIEWER,
|
||||||
|
userId,
|
||||||
|
roomId,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function openSettings() {
|
function openSettings() {
|
||||||
appDispatcher.dispatch({
|
appDispatcher.dispatch({
|
||||||
type: cons.actions.navigation.OPEN_SETTINGS,
|
type: cons.actions.navigation.OPEN_SETTINGS,
|
||||||
@@ -94,6 +102,7 @@ export {
|
|||||||
openPublicRooms,
|
openPublicRooms,
|
||||||
openCreateRoom,
|
openCreateRoom,
|
||||||
openInviteUser,
|
openInviteUser,
|
||||||
|
openProfileViewer,
|
||||||
openSettings,
|
openSettings,
|
||||||
openEmojiBoard,
|
openEmojiBoard,
|
||||||
openReadReceipts,
|
openReadReceipts,
|
||||||
|
|||||||
@@ -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,
|
||||||
@@ -143,6 +145,10 @@ async function create(opts) {
|
|||||||
is_direct: opts.isDirect === true,
|
is_direct: opts.isDirect === true,
|
||||||
invite: opts.invite || [],
|
invite: opts.invite || [],
|
||||||
initial_state: [],
|
initial_state: [],
|
||||||
|
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) {
|
||||||
@@ -182,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) {
|
||||||
@@ -206,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',
|
||||||
@@ -27,6 +28,7 @@ const cons = {
|
|||||||
OPEN_PUBLIC_ROOMS: 'OPEN_PUBLIC_ROOMS',
|
OPEN_PUBLIC_ROOMS: 'OPEN_PUBLIC_ROOMS',
|
||||||
OPEN_CREATE_ROOM: 'OPEN_CREATE_ROOM',
|
OPEN_CREATE_ROOM: 'OPEN_CREATE_ROOM',
|
||||||
OPEN_INVITE_USER: 'OPEN_INVITE_USER',
|
OPEN_INVITE_USER: 'OPEN_INVITE_USER',
|
||||||
|
OPEN_PROFILE_VIEWER: 'OPEN_PROFILE_VIEWER',
|
||||||
OPEN_SETTINGS: 'OPEN_SETTINGS',
|
OPEN_SETTINGS: 'OPEN_SETTINGS',
|
||||||
OPEN_EMOJIBOARD: 'OPEN_EMOJIBOARD',
|
OPEN_EMOJIBOARD: 'OPEN_EMOJIBOARD',
|
||||||
OPEN_READRECEIPTS: 'OPEN_READRECEIPTS',
|
OPEN_READRECEIPTS: 'OPEN_READRECEIPTS',
|
||||||
@@ -57,6 +59,7 @@ const cons = {
|
|||||||
CREATE_ROOM_OPENED: 'CREATE_ROOM_OPENED',
|
CREATE_ROOM_OPENED: 'CREATE_ROOM_OPENED',
|
||||||
INVITE_USER_OPENED: 'INVITE_USER_OPENED',
|
INVITE_USER_OPENED: 'INVITE_USER_OPENED',
|
||||||
SETTINGS_OPENED: 'SETTINGS_OPENED',
|
SETTINGS_OPENED: 'SETTINGS_OPENED',
|
||||||
|
PROFILE_VIEWER_OPENED: 'PROFILE_VIEWER_OPENED',
|
||||||
EMOJIBOARD_OPENED: 'EMOJIBOARD_OPENED',
|
EMOJIBOARD_OPENED: 'EMOJIBOARD_OPENED',
|
||||||
READRECEIPTS_OPENED: 'READRECEIPTS_OPENED',
|
READRECEIPTS_OPENED: 'READRECEIPTS_OPENED',
|
||||||
ROOMOPTIONS_OPENED: 'ROOMOPTIONS_OPENED',
|
ROOMOPTIONS_OPENED: 'ROOMOPTIONS_OPENED',
|
||||||
|
|||||||
@@ -69,6 +69,9 @@ class Navigation extends EventEmitter {
|
|||||||
[cons.actions.navigation.OPEN_INVITE_USER]: () => {
|
[cons.actions.navigation.OPEN_INVITE_USER]: () => {
|
||||||
this.emit(cons.events.navigation.INVITE_USER_OPENED, action.roomId, action.searchTerm);
|
this.emit(cons.events.navigation.INVITE_USER_OPENED, action.roomId, action.searchTerm);
|
||||||
},
|
},
|
||||||
|
[cons.actions.navigation.OPEN_PROFILE_VIEWER]: () => {
|
||||||
|
this.emit(cons.events.navigation.PROFILE_VIEWER_OPENED, action.userId, action.roomId);
|
||||||
|
},
|
||||||
[cons.actions.navigation.OPEN_SETTINGS]: () => {
|
[cons.actions.navigation.OPEN_SETTINGS]: () => {
|
||||||
this.emit(cons.events.navigation.SETTINGS_OPENED);
|
this.emit(cons.events.navigation.SETTINGS_OPENED);
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -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,31 +48,15 @@ async function isRoomAliasAvailable(alias) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function doesRoomHaveUnread(room) {
|
function getPowerLabel(powerLevel) {
|
||||||
const userId = initMatrix.matrixClient.getUserId();
|
if (powerLevel > 9000) return 'Goku';
|
||||||
const readUpToId = room.getEventReadUpTo(userId);
|
if (powerLevel > 100) return 'Founder';
|
||||||
const supportEvents = ['m.room.message', 'm.room.encrypted', 'm.sticker'];
|
if (powerLevel === 100) return 'Admin';
|
||||||
|
if (powerLevel >= 50) return 'Mod';
|
||||||
if (room.timeline.length
|
return null;
|
||||||
&& 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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export {
|
export {
|
||||||
getBaseUrl, getUsername, getUsernameOfRoomMember,
|
getBaseUrl, getUsername, getUsernameOfRoomMember,
|
||||||
isRoomAliasAvailable, doesRoomHaveUnread,
|
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