Compare commits
71 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
94ae2f2658 | ||
|
|
3453451df9 | ||
|
|
80d4a2b242 | ||
|
|
c9b1a062ce | ||
|
|
717ffe560f | ||
|
|
109e2fa82d | ||
|
|
d03fc2fcf1 | ||
|
|
d0111e7741 | ||
|
|
5e76d6d865 | ||
|
|
90e67b22b4 | ||
|
|
92ba6c9802 | ||
|
|
0286a51525 | ||
|
|
b552e2cda8 | ||
|
|
0feb56cb3e | ||
|
|
e1a0acdf4a | ||
|
|
6586f933ff | ||
|
|
4ec770da63 | ||
|
|
39b84a083d | ||
|
|
28857473b2 | ||
|
|
2bfc10dab4 | ||
|
|
1dce1157f4 | ||
|
|
08d53d52e7 | ||
|
|
2918d97fd0 | ||
|
|
701e170e19 | ||
|
|
71ee669fc5 | ||
|
|
661ac8c6f4 | ||
|
|
210f6b51df | ||
|
|
20611b6e4b | ||
|
|
689e4b8d23 | ||
|
|
d0378ea528 | ||
|
|
5454ed3458 | ||
|
|
0070d46a20 | ||
|
|
540c10aaff | ||
|
|
f5dfc3604a | ||
|
|
b2c5304efe | ||
|
|
fa512f16c6 | ||
|
|
cbfb25b390 | ||
|
|
b1e55201cf | ||
|
|
8beeb64127 | ||
|
|
2d2938c8ad | ||
|
|
e9005d57da | ||
|
|
69f7c8a500 | ||
|
|
98fd24ffdc | ||
|
|
21c3e90b58 | ||
|
|
49281e0d15 | ||
|
|
e597f81b45 | ||
|
|
9f6047aebd | ||
|
|
0745f964c1 | ||
|
|
18b1ad7b62 | ||
|
|
9448936e32 | ||
|
|
f1dc436a07 | ||
|
|
f163e24201 | ||
|
|
81f4f1c46f | ||
|
|
a82e74381f | ||
|
|
7459896bac | ||
|
|
dd2783b040 | ||
|
|
23ff2c3ab4 | ||
|
|
ad51191a77 | ||
|
|
8ef5ab6fe9 | ||
|
|
2218f9781b | ||
|
|
d08d727917 | ||
|
|
8cf030585f | ||
|
|
c29515db38 | ||
|
|
d9e27bfaf1 | ||
|
|
2e8830b9d3 | ||
|
|
4d3d6ea9a7 | ||
|
|
e69f344ab2 | ||
|
|
3bed452d34 | ||
|
|
5fb393d7ff | ||
|
|
313ff8e184 | ||
|
|
896738dc22 |
3
.github/FUNDING.yml
vendored
3
.github/FUNDING.yml
vendored
@@ -1 +1,2 @@
|
|||||||
liberapay: kfiven
|
patreon: ajbura
|
||||||
|
liberapay: ajbura
|
||||||
18
.github/ISSUE_TEMPLATE/bug_report.md
vendored
18
.github/ISSUE_TEMPLATE/bug_report.md
vendored
@@ -7,26 +7,26 @@ assignees: ''
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
**Describe the bug**
|
#### Describe the bug
|
||||||
A clear and concise description of what the bug is.
|
A clear and concise description of what the bug is.
|
||||||
|
|
||||||
**To Reproduce**
|
#### To Reproduce
|
||||||
Steps to reproduce the behavior:
|
Steps to reproduce the behavior:
|
||||||
1. Go to '...'
|
1. Go to '...'
|
||||||
2. Click on '....'
|
2. Click on '....'
|
||||||
3. Scroll down to '....'
|
3. Scroll down to '....'
|
||||||
4. See error
|
4. See error
|
||||||
|
|
||||||
**Expected behavior**
|
#### Expected behavior
|
||||||
A clear and concise description of what you expected to happen.
|
A clear and concise description of what you expected to happen.
|
||||||
|
|
||||||
**Screenshots**
|
#### Screenshots
|
||||||
If applicable, add screenshots to help explain your problem.
|
If applicable, add screenshots to help explain your problem.
|
||||||
|
|
||||||
**Desktop (please complete the following information):**
|
#### Desktop (please complete the following information):
|
||||||
- OS: [e.g. iOS]
|
- OS: [e.g. Windows, MacOS]
|
||||||
- Browser [e.g. chrome, safari]
|
- Browser: [e.g. chrome, firefox]
|
||||||
- Version [e.g. 22]
|
- Version: [e.g. 3.22]
|
||||||
|
|
||||||
**Additional context**
|
#### Additional context
|
||||||
Add any other context about the problem here.
|
Add any other context about the problem here.
|
||||||
8
.github/ISSUE_TEMPLATE/feature_request.md
vendored
8
.github/ISSUE_TEMPLATE/feature_request.md
vendored
@@ -7,14 +7,14 @@ assignees: ''
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
**Is your feature request related to a problem? Please describe.**
|
#### Is your feature request related to a problem? Please describe.
|
||||||
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
|
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
|
||||||
|
|
||||||
**Describe the solution you'd like**
|
#### Describe the solution you'd like
|
||||||
A clear and concise description of what you want to happen.
|
A clear and concise description of what you want to happen.
|
||||||
|
|
||||||
**Describe alternatives you've considered**
|
#### Describe alternatives you've considered
|
||||||
A clear and concise description of any alternative solutions or features you've considered.
|
A clear and concise description of any alternative solutions or features you've considered.
|
||||||
|
|
||||||
**Additional context**
|
#### Additional context
|
||||||
Add any other context or screenshots about the feature request here.
|
Add any other context or screenshots about the feature request here.
|
||||||
|
|||||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,5 +1,4 @@
|
|||||||
experiment
|
experiment
|
||||||
package-lock.json
|
|
||||||
dist
|
dist
|
||||||
node_modules
|
node_modules
|
||||||
devAssets
|
devAssets
|
||||||
20
Dockerfile
Normal file
20
Dockerfile
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
## Builder
|
||||||
|
FROM node:14-alpine as builder
|
||||||
|
|
||||||
|
WORKDIR /src
|
||||||
|
|
||||||
|
COPY . /src
|
||||||
|
RUN npm install \
|
||||||
|
&& npm run build
|
||||||
|
|
||||||
|
|
||||||
|
## App
|
||||||
|
FROM nginx:alpine
|
||||||
|
|
||||||
|
COPY --from=builder /src/dist /app
|
||||||
|
|
||||||
|
# Insert wasm type into Nginx mime.types file so they load correctly.
|
||||||
|
RUN sed -i '3i\ \ \ \ application/wasm wasm\;' /etc/nginx/mime.types
|
||||||
|
|
||||||
|
RUN rm -rf /usr/share/nginx/html \
|
||||||
|
&& ln -s /app /usr/share/nginx/html
|
||||||
36
README.md
36
README.md
@@ -8,4 +8,38 @@
|
|||||||
|
|
||||||
## About <a name = "about"></a>
|
## About <a name = "about"></a>
|
||||||
|
|
||||||
Cinny is a [matrix](https://matrix.org) client focusing primarily on simple, elegant and secure interface.
|
Cinny is a [Matrix](https://matrix.org) client focusing primarily on simple, elegant and secure interface.
|
||||||
|
|
||||||
|
## Building and Running
|
||||||
|
|
||||||
|
### Building from source
|
||||||
|
|
||||||
|
Execute the following commands to compile the app from its source code:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
npm install # Installs all dependencies
|
||||||
|
npm run build # Compiles the app into the dist/ directory
|
||||||
|
```
|
||||||
|
|
||||||
|
You can then copy the files to a webserver's webroot of your choice.
|
||||||
|
To serve a development version of the app locally for testing, you may also use the command `npm start`.
|
||||||
|
|
||||||
|
### Running with Docker
|
||||||
|
|
||||||
|
This repository includes a Dockerfile, which builds the application from source and serves it with Nginx on port 80. To
|
||||||
|
use this locally, you can build the container like so:
|
||||||
|
|
||||||
|
```
|
||||||
|
docker build -t cinny:latest .
|
||||||
|
```
|
||||||
|
|
||||||
|
You can then run the container you've built with a command similar to this:
|
||||||
|
|
||||||
|
```
|
||||||
|
docker run -p 8080:80 cinny:latest
|
||||||
|
```
|
||||||
|
|
||||||
|
This will forward your `localhost` port 8080 to the container's port 80. You can visit the app in your browser by
|
||||||
|
navigating to `http://localhost:8080`.
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
3
_redirects
Normal file
3
_redirects
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
# Redirects from what the browser requests to what we serve
|
||||||
|
/login /
|
||||||
|
/register /
|
||||||
12
contrib/nginx/README.md
Normal file
12
contrib/nginx/README.md
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
# nginx configuration
|
||||||
|
|
||||||
|
## Insert wasm type into nginx mime.types file so they load correctly.
|
||||||
|
|
||||||
|
`/etc/nginx/mime.types`:
|
||||||
|
```
|
||||||
|
types {
|
||||||
|
..
|
||||||
|
application/wasm wasm;
|
||||||
|
..
|
||||||
|
}
|
||||||
|
```
|
||||||
27
contrib/nginx/cinny.domain.tld.conf
Normal file
27
contrib/nginx/cinny.domain.tld.conf
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
server {
|
||||||
|
listen 80;
|
||||||
|
listen [::]:80;
|
||||||
|
server_name cinny.domain.tld;
|
||||||
|
|
||||||
|
location / {
|
||||||
|
return 301 https://$host$request_uri;
|
||||||
|
}
|
||||||
|
|
||||||
|
location /.well-known/acme-challenge/ {
|
||||||
|
alias /var/lib/letsencrypt/.well-known/acme-challenge/;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
server {
|
||||||
|
listen 443 ssl http2;
|
||||||
|
listen [::]:443 ssl;
|
||||||
|
server_name cinny.domain.tld;
|
||||||
|
|
||||||
|
location / {
|
||||||
|
root /opt/cinny/dist/;
|
||||||
|
index index.html;
|
||||||
|
}
|
||||||
|
location ~* ^\/(login|register) {
|
||||||
|
try_files $uri $uri/ /index.html;
|
||||||
|
}
|
||||||
|
}
|
||||||
13999
package-lock.json
generated
Normal file
13999
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
18
package.json
18
package.json
@@ -1,31 +1,32 @@
|
|||||||
{
|
{
|
||||||
"name": "cinny",
|
"name": "cinny",
|
||||||
"version": "1.0.0",
|
"version": "1.1.0",
|
||||||
"description": "Organized and powerful matrix client.",
|
"description": "Yet another matrix client",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"engines": {
|
"engines": {
|
||||||
"npm": "6.14.11",
|
"npm": ">=6.14.11",
|
||||||
"node": "14.6.0"
|
"node": ">=14.6.0"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "webpack serve --config ./webpack.dev.js --open",
|
"start": "webpack serve --config ./webpack.dev.js --open",
|
||||||
"build": "webpack --config ./webpack.prod.js"
|
"build": "webpack --config ./webpack.prod.js"
|
||||||
},
|
},
|
||||||
"keywords": [],
|
"keywords": [],
|
||||||
"author": "",
|
"author": "Ajay Bura",
|
||||||
"license": "ISC",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@matrix-org/olm": "https://gitlab.matrix.org/api/v4/projects/27/packages/npm/@matrix-org/olm/-/@matrix-org/olm-3.2.4.tgz",
|
||||||
"@tippyjs/react": "^4.2.5",
|
"@tippyjs/react": "^4.2.5",
|
||||||
"babel-polyfill": "^6.26.0",
|
"babel-polyfill": "^6.26.0",
|
||||||
"browser-encrypt-attachment": "^0.3.0",
|
"browser-encrypt-attachment": "^0.3.0",
|
||||||
|
"commonmark": "^0.30.0",
|
||||||
"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",
|
||||||
"fuse.js": "^6.4.6",
|
"fuse.js": "^6.4.6",
|
||||||
"html-react-parser": "^1.2.7",
|
"html-react-parser": "^1.2.7",
|
||||||
"linkifyjs": "^3.0.0-beta.3",
|
"linkifyjs": "^3.0.0-beta.3",
|
||||||
"matrix-js-sdk": "^11.2.0",
|
"matrix-js-sdk": "^12.2.0",
|
||||||
"olm": "https://packages.matrix.org/npm/olm/olm-3.2.1.tgz",
|
|
||||||
"prop-types": "^15.7.2",
|
"prop-types": "^15.7.2",
|
||||||
"react": "^17.0.2",
|
"react": "^17.0.2",
|
||||||
"react-autosize-textarea": "^7.1.0",
|
"react-autosize-textarea": "^7.1.0",
|
||||||
@@ -47,6 +48,7 @@
|
|||||||
"browserify-fs": "^1.0.0",
|
"browserify-fs": "^1.0.0",
|
||||||
"buffer": "^6.0.3",
|
"buffer": "^6.0.3",
|
||||||
"clean-webpack-plugin": "^3.0.0",
|
"clean-webpack-plugin": "^3.0.0",
|
||||||
|
"copy-webpack-plugin": "^9.0.1",
|
||||||
"crypto-browserify": "^3.12.0",
|
"crypto-browserify": "^3.12.0",
|
||||||
"css-loader": "^5.2.0",
|
"css-loader": "^5.2.0",
|
||||||
"css-minimizer-webpack-plugin": "^1.3.0",
|
"css-minimizer-webpack-plugin": "^1.3.0",
|
||||||
|
|||||||
@@ -7,13 +7,14 @@
|
|||||||
<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">
|
||||||
<meta name="description" content="Yet another matrix client. Where you can enjoy the conversation using simple, elegant and secure interface protected by e2ee with the power of open source.">
|
<meta name="author" content="Ajay Bura">
|
||||||
|
<meta name="description" content="A Matrix client where you can enjoy the conversation using simple, elegant and secure interface protected by e2ee with the power of open source.">
|
||||||
<meta name="keywords" content="cinny, cinnyapp, cinnychat, matrix, matrix client, matrix.org, element">
|
<meta name="keywords" content="cinny, cinnyapp, cinnychat, matrix, matrix client, matrix.org, element">
|
||||||
|
|
||||||
<meta property="og:title" content="Cinny">
|
<meta property="og:title" content="Cinny">
|
||||||
<meta property="og:url" content="https://cinny.in">
|
<meta property="og:url" content="https://cinny.in">
|
||||||
<meta property="og:image" content="https://cinny.in/assets/favicon-48x48.png">
|
<meta property="og:image" content="https://cinny.in/assets/favicon-48x48.png">
|
||||||
<meta property="og:description" content="Yet another matrix client. Where you can enjoy the conversation using simple, elegant and secure interface protected by e2ee with the power of open source.">
|
<meta property="og:description" content="A Matrix client where you can enjoy the conversation using simple, elegant and secure interface protected by e2ee with the power of open source.">
|
||||||
<meta name="theme-color" content="#000000">
|
<meta name="theme-color" content="#000000">
|
||||||
</head>
|
</head>
|
||||||
<body id="appBody">
|
<body id="appBody">
|
||||||
|
|||||||
18
public/res/ic/outlined/bin.svg
Normal file
18
public/res/ic/outlined/bin.svg
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
<?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">
|
||||||
|
<g>
|
||||||
|
<g>
|
||||||
|
<g>
|
||||||
|
<rect x="9" y="8" width="2" height="8"/>
|
||||||
|
</g>
|
||||||
|
<g>
|
||||||
|
<rect x="13" y="8" width="2" height="8"/>
|
||||||
|
</g>
|
||||||
|
</g>
|
||||||
|
<path d="M21,3h-5l-1.4-1.4C14.2,1.2,13.7,1,13.2,1h-2.3c-0.5,0-1,0.2-1.4,0.6L8,3H3v2h2v14c0,1.1,0.9,2,2,2h10c1.1,0,2-0.9,2-2V5h2
|
||||||
|
V3z M17,19H7V5h10V19z"/>
|
||||||
|
</g>
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 735 B |
11
public/res/ic/outlined/cmd.svg
Normal file
11
public/res/ic/outlined/cmd.svg
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
<?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">
|
||||||
|
<g>
|
||||||
|
<path d="M20,4H4C2.9,4,2,4.9,2,6v12c0,1.1,0.9,2,2,2h16c1.1,0,2-0.9,2-2V6C22,4.9,21.1,4,20,4z M20,18H4V6h16V18z"/>
|
||||||
|
<polygon points="7.5,16.5 12.1,12 7.5,7.5 6.5,8.5 9.9,12 6.5,15.5 "/>
|
||||||
|
<rect x="13" y="14.5" width="5" height="1.5"/>
|
||||||
|
</g>
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 688 B |
13
public/res/ic/outlined/emoji-add.svg
Normal file
13
public/res/ic/outlined/emoji-add.svg
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
<?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">
|
||||||
|
<g>
|
||||||
|
<path d="M12,20c-4.4,0-8-3.6-8-8s3.6-8,8-8V2C6.5,2,2,6.5,2,12s4.5,10,10,10s10-4.5,10-10h-2C20,16.4,16.4,20,12,20z"/>
|
||||||
|
<circle cx="9.5" cy="8.5" r="1.5"/>
|
||||||
|
<circle cx="14.5" cy="8.5" r="1.5"/>
|
||||||
|
<path d="M6,12c0,3.3,2.7,6,6,6s6-2.7,6-6h-2c0,2.2-1.8,4-4,4s-4-1.8-4-4H6z"/>
|
||||||
|
<polygon points="20.8,3.3 20.8,0 19.3,0 19.3,3.3 16,3.3 16,4.8 19.3,4.8 19.3,8 20.8,8 20.8,4.8 24,4.8 24,3.3 "/>
|
||||||
|
</g>
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 839 B |
14
public/res/ic/outlined/info.svg
Normal file
14
public/res/ic/outlined/info.svg
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
<?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">
|
||||||
|
<g>
|
||||||
|
<path d="M12,2C6.5,2,2,6.5,2,12s4.5,10,10,10s10-4.5,10-10S17.5,2,12,2z M12,20c-4.4,0-8-3.6-8-8s3.6-8,8-8s8,3.6,8,8
|
||||||
|
S16.4,20,12,20z"/>
|
||||||
|
<g>
|
||||||
|
<polygon points="12.8,15.5 12.8,10 12.2,10 11.3,10 10,10 10,11 11.3,11.5 11.3,15.5 10,16 10,17 14,17 14,16 "/>
|
||||||
|
<circle cx="12" cy="8" r="1"/>
|
||||||
|
</g>
|
||||||
|
</g>
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 749 B |
10
public/res/ic/outlined/markdown.svg
Normal file
10
public/res/ic/outlined/markdown.svg
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
<?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">
|
||||||
|
<g>
|
||||||
|
<polygon points="12,7 12,7 8,11 4,7 4,7 4,7 2,7 2,17 4,17 4,9.8 8,13.8 12,9.8 12,17 14,17 14,7 12,7 "/>
|
||||||
|
<path d="M20,14V7h-2v7h-2l3,3c0.1,0,0.5-0.4,1-0.9c0.9-0.9,2-2.1,2-2.1H20z"/>
|
||||||
|
</g>
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 637 B |
@@ -7,6 +7,7 @@
|
|||||||
.text {
|
.text {
|
||||||
color: var(--bg-surface-low);
|
color: var(--bg-surface-low);
|
||||||
text-align: center;
|
text-align: center;
|
||||||
|
font-weight: 700;
|
||||||
}
|
}
|
||||||
|
|
||||||
&--alert {
|
&--alert {
|
||||||
|
|||||||
@@ -2,8 +2,8 @@ import React from 'react';
|
|||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import './IconButton.scss';
|
import './IconButton.scss';
|
||||||
|
|
||||||
import Tippy from '@tippyjs/react';
|
|
||||||
import RawIcon from '../system-icons/RawIcon';
|
import RawIcon from '../system-icons/RawIcon';
|
||||||
|
import Tooltip from '../tooltip/Tooltip';
|
||||||
import { blurOnBubbling } from './script';
|
import { blurOnBubbling } from './script';
|
||||||
import Text from '../text/Text';
|
import Text from '../text/Text';
|
||||||
|
|
||||||
@@ -17,15 +17,9 @@ const IconButton = React.forwardRef(({
|
|||||||
variant, size, type,
|
variant, size, type,
|
||||||
tooltip, tooltipPlacement, src, onClick,
|
tooltip, tooltipPlacement, src, onClick,
|
||||||
}, ref) => (
|
}, ref) => (
|
||||||
<Tippy
|
<Tooltip
|
||||||
content={<Text variant="b2">{tooltip}</Text>}
|
|
||||||
className="ic-btn-tippy"
|
|
||||||
touch="hold"
|
|
||||||
arrow={false}
|
|
||||||
maxWidth={250}
|
|
||||||
placement={tooltipPlacement}
|
placement={tooltipPlacement}
|
||||||
delay={[0, 0]}
|
content={<Text variant="b2">{tooltip}</Text>}
|
||||||
duration={[100, 0]}
|
|
||||||
>
|
>
|
||||||
<button
|
<button
|
||||||
ref={ref}
|
ref={ref}
|
||||||
@@ -36,7 +30,7 @@ const IconButton = React.forwardRef(({
|
|||||||
>
|
>
|
||||||
<RawIcon size={size} src={src} />
|
<RawIcon size={size} src={src} />
|
||||||
</button>
|
</button>
|
||||||
</Tippy>
|
</Tooltip>
|
||||||
));
|
));
|
||||||
|
|
||||||
IconButton.defaultProps = {
|
IconButton.defaultProps = {
|
||||||
|
|||||||
@@ -31,15 +31,4 @@
|
|||||||
@include state.hover(var(--bg-surface-hover));
|
@include state.hover(var(--bg-surface-hover));
|
||||||
@include focus(var(--bg-surface-hover));
|
@include focus(var(--bg-surface-hover));
|
||||||
@include state.active(var(--bg-surface-active));
|
@include state.active(var(--bg-surface-active));
|
||||||
}
|
|
||||||
|
|
||||||
.ic-btn-tippy {
|
|
||||||
padding: var(--sp-extra-tight) var(--sp-normal);
|
|
||||||
background-color: var(--bg-tooltip);
|
|
||||||
border-radius: var(--bo-radius);
|
|
||||||
box-shadow: var(--bs-popup);
|
|
||||||
|
|
||||||
.text {
|
|
||||||
color: var(--tc-tooltip);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
37
src/app/atoms/tooltip/Tooltip.jsx
Normal file
37
src/app/atoms/tooltip/Tooltip.jsx
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import PropTypes from 'prop-types';
|
||||||
|
import './Tooltip.scss';
|
||||||
|
import Tippy from '@tippyjs/react';
|
||||||
|
|
||||||
|
function Tooltip({
|
||||||
|
className, placement, content, children,
|
||||||
|
}) {
|
||||||
|
return (
|
||||||
|
<Tippy
|
||||||
|
content={content}
|
||||||
|
className={`tooltip ${className}`}
|
||||||
|
touch="hold"
|
||||||
|
arrow={false}
|
||||||
|
maxWidth={250}
|
||||||
|
placement={placement}
|
||||||
|
delay={[0, 0]}
|
||||||
|
duration={[100, 0]}
|
||||||
|
>
|
||||||
|
{children}
|
||||||
|
</Tippy>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Tooltip.defaultProps = {
|
||||||
|
placement: 'top',
|
||||||
|
className: '',
|
||||||
|
};
|
||||||
|
|
||||||
|
Tooltip.propTypes = {
|
||||||
|
className: PropTypes.string,
|
||||||
|
placement: PropTypes.string,
|
||||||
|
content: PropTypes.node.isRequired,
|
||||||
|
children: PropTypes.node.isRequired,
|
||||||
|
};
|
||||||
|
|
||||||
|
export default Tooltip;
|
||||||
10
src/app/atoms/tooltip/Tooltip.scss
Normal file
10
src/app/atoms/tooltip/Tooltip.scss
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
.tooltip {
|
||||||
|
padding: var(--sp-extra-tight) var(--sp-normal);
|
||||||
|
background-color: var(--bg-tooltip);
|
||||||
|
border-radius: var(--bo-radius);
|
||||||
|
box-shadow: var(--bs-popup);
|
||||||
|
|
||||||
|
.text {
|
||||||
|
color: var(--tc-tooltip);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,11 +3,13 @@
|
|||||||
width: calc(100% - var(--sp-extra-tight));
|
width: calc(100% - var(--sp-extra-tight));
|
||||||
margin-left: auto;
|
margin-left: auto;
|
||||||
padding: var(--sp-extra-tight) var(--sp-extra-tight);
|
padding: var(--sp-extra-tight) var(--sp-extra-tight);
|
||||||
|
|
||||||
border: 1px solid transparent;
|
border: 1px solid transparent;
|
||||||
border-radius: var(--bo-radius);
|
border-radius: var(--bo-radius);
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
|
|
||||||
[dir=rtl] & {
|
[dir=rtl] & {
|
||||||
|
|
||||||
margin: {
|
margin: {
|
||||||
left: 0;
|
left: 0;
|
||||||
right: auto;
|
right: auto;
|
||||||
@@ -56,7 +58,7 @@
|
|||||||
margin: 0 var(--sp-ultra-tight);
|
margin: 0 var(--sp-ultra-tight);
|
||||||
height: 8px;
|
height: 8px;
|
||||||
width: 8px;
|
width: 8px;
|
||||||
background-color: var(--tc-surface-low);
|
background-color: var(--tc-surface-normal);
|
||||||
border-radius: 50%;
|
border-radius: 50%;
|
||||||
opacity: .4;
|
opacity: .4;
|
||||||
}
|
}
|
||||||
|
|||||||
108
src/app/molecules/import-e2e-room-keys/ImportE2ERoomKeys.jsx
Normal file
108
src/app/molecules/import-e2e-room-keys/ImportE2ERoomKeys.jsx
Normal file
@@ -0,0 +1,108 @@
|
|||||||
|
import React, { useState, useEffect, useRef } from 'react';
|
||||||
|
import './ImportE2ERoomKeys.scss';
|
||||||
|
import EventEmitter from 'events';
|
||||||
|
|
||||||
|
import initMatrix from '../../../client/initMatrix';
|
||||||
|
import decryptMegolmKeyFile from '../../../util/decryptE2ERoomKeys';
|
||||||
|
|
||||||
|
import Text from '../../atoms/text/Text';
|
||||||
|
import IconButton from '../../atoms/button/IconButton';
|
||||||
|
import Button from '../../atoms/button/Button';
|
||||||
|
import Input from '../../atoms/input/Input';
|
||||||
|
import Spinner from '../../atoms/spinner/Spinner';
|
||||||
|
|
||||||
|
import CirclePlusIC from '../../../../public/res/ic/outlined/circle-plus.svg';
|
||||||
|
|
||||||
|
const viewEvent = new EventEmitter();
|
||||||
|
|
||||||
|
async function tryDecrypt(file, password) {
|
||||||
|
try {
|
||||||
|
const arrayBuffer = await file.arrayBuffer();
|
||||||
|
viewEvent.emit('importing', true);
|
||||||
|
viewEvent.emit('status', 'Decrypting file...');
|
||||||
|
const keys = await decryptMegolmKeyFile(arrayBuffer, password);
|
||||||
|
|
||||||
|
viewEvent.emit('status', 'Decrypting messages...');
|
||||||
|
await initMatrix.matrixClient.importRoomKeys(JSON.parse(keys));
|
||||||
|
|
||||||
|
viewEvent.emit('status', null);
|
||||||
|
viewEvent.emit('importing', false);
|
||||||
|
} catch (e) {
|
||||||
|
viewEvent.emit('status', e.friendlyText || 'Something went wrong!');
|
||||||
|
viewEvent.emit('importing', false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function ImportE2ERoomKeys() {
|
||||||
|
const [keyFile, setKeyFile] = useState(null);
|
||||||
|
const [status, setStatus] = useState(null);
|
||||||
|
const [isImporting, setIsImporting] = useState(false);
|
||||||
|
const inputRef = useRef(null);
|
||||||
|
const passwordRef = useRef(null);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const handleIsImporting = (isImp) => setIsImporting(isImp);
|
||||||
|
const handleStatus = (msg) => setStatus(msg);
|
||||||
|
viewEvent.on('importing', handleIsImporting);
|
||||||
|
viewEvent.on('status', handleStatus);
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
viewEvent.removeListener('importing', handleIsImporting);
|
||||||
|
viewEvent.removeListener('status', handleStatus);
|
||||||
|
};
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
function importE2ERoomKeys() {
|
||||||
|
const password = passwordRef.current.value;
|
||||||
|
if (password === '' || keyFile === null) return;
|
||||||
|
if (isImporting) return;
|
||||||
|
|
||||||
|
tryDecrypt(keyFile, password);
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleFileChange(e) {
|
||||||
|
const file = e.target.files.item(0);
|
||||||
|
passwordRef.current.value = '';
|
||||||
|
setKeyFile(file);
|
||||||
|
setStatus(null);
|
||||||
|
}
|
||||||
|
function removeImportKeysFile() {
|
||||||
|
inputRef.current.value = null;
|
||||||
|
passwordRef.current.value = null;
|
||||||
|
setKeyFile(null);
|
||||||
|
setStatus(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!isImporting && status === null) {
|
||||||
|
removeImportKeysFile();
|
||||||
|
}
|
||||||
|
}, [isImporting, status]);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="import-e2e-room-keys">
|
||||||
|
<input ref={inputRef} onChange={handleFileChange} style={{ display: 'none' }} type="file" />
|
||||||
|
|
||||||
|
<form className="import-e2e-room-keys__form" onSubmit={(e) => { e.preventDefault(); importE2ERoomKeys(); }}>
|
||||||
|
{ keyFile !== null && (
|
||||||
|
<div className="import-e2e-room-keys__file">
|
||||||
|
<IconButton onClick={removeImportKeysFile} src={CirclePlusIC} tooltip="Remove file" />
|
||||||
|
<Text>{keyFile.name}</Text>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
{keyFile === null && <Button onClick={() => inputRef.current.click()}>Import keys</Button>}
|
||||||
|
<Input forwardRef={passwordRef} type="password" placeholder="Password" required />
|
||||||
|
<Button disabled={isImporting} variant="primary" type="submit">Decrypt</Button>
|
||||||
|
</form>
|
||||||
|
{ isImporting && status !== null && (
|
||||||
|
<div className="import-e2e-room-keys__process">
|
||||||
|
<Spinner size="small" />
|
||||||
|
<Text variant="b2">{status}</Text>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
{!isImporting && status !== null && <Text className="import-e2e-room-keys__error" variant="b2">{status}</Text>}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default ImportE2ERoomKeys;
|
||||||
@@ -0,0 +1,63 @@
|
|||||||
|
|
||||||
|
.import-e2e-room-keys {
|
||||||
|
&__file {
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
background: var(--bg-surface-low);
|
||||||
|
border-radius: var(--bo-radius);
|
||||||
|
box-shadow: var(--bs-surface-border);
|
||||||
|
|
||||||
|
& button {
|
||||||
|
--parent-height: 46px;
|
||||||
|
width: var(--parent-height);
|
||||||
|
height: 100%;
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
& .ic-raw {
|
||||||
|
background-color: var(--bg-caution);
|
||||||
|
transform: rotate(45deg);
|
||||||
|
}
|
||||||
|
|
||||||
|
& .text {
|
||||||
|
margin-left: var(--sp-tight);
|
||||||
|
margin-right: var(--sp-loose);
|
||||||
|
max-width: 86px;
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
white-space: nowrap;
|
||||||
|
|
||||||
|
[dir=rtl] {
|
||||||
|
margin-right: var(--sp-tight);
|
||||||
|
margin-left: var(--sp-loose);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
&__form {
|
||||||
|
display: flex;
|
||||||
|
margin-top: var(--sp-extra-tight);
|
||||||
|
|
||||||
|
|
||||||
|
& .input-container {
|
||||||
|
flex: 1;
|
||||||
|
margin: 0 var(--sp-tight);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
&__process {
|
||||||
|
margin-top: var(--sp-tight);
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
& .text {
|
||||||
|
margin: 0 var(--sp-tight);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
&__error {
|
||||||
|
margin-top: var(--sp-tight);
|
||||||
|
color: var(--bg-danger);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -7,10 +7,14 @@ 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';
|
||||||
import { coy } from 'react-syntax-highlighter/dist/esm/styles/prism';
|
import { coy } from 'react-syntax-highlighter/dist/esm/styles/prism';
|
||||||
|
import parse from 'html-react-parser';
|
||||||
|
import twemoji from 'twemoji';
|
||||||
|
import { getUsername } from '../../../util/matrixUtil';
|
||||||
|
|
||||||
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';
|
||||||
import Avatar from '../../atoms/avatar/Avatar';
|
import Avatar from '../../atoms/avatar/Avatar';
|
||||||
|
import Tooltip from '../../atoms/tooltip/Tooltip';
|
||||||
|
|
||||||
import ReplyArrowIC from '../../../../public/res/ic/outlined/reply-arrow.svg';
|
import ReplyArrowIC from '../../../../public/res/ic/outlined/reply-arrow.svg';
|
||||||
|
|
||||||
@@ -61,89 +65,178 @@ function PlaceholderMessage() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function Message({
|
function MessageHeader({
|
||||||
color, avatarSrc, name, content,
|
userId, name, color, time,
|
||||||
time, markdown, contentOnly, reply,
|
|
||||||
edited, reactions,
|
|
||||||
}) {
|
}) {
|
||||||
const msgClass = contentOnly ? 'message--content-only' : 'message--full';
|
|
||||||
return (
|
return (
|
||||||
<div className={`message ${msgClass}`}>
|
<div className="message__header">
|
||||||
<div className="message__avatar-container">
|
<div style={{ color }} className="message__profile">
|
||||||
{!contentOnly && <Avatar imageSrc={avatarSrc} text={name.slice(0, 1)} bgColor={color} size="small" />}
|
<Text variant="b1">{name}</Text>
|
||||||
|
<Text variant="b1">{userId}</Text>
|
||||||
</div>
|
</div>
|
||||||
<div className="message__main-container">
|
<div className="message__time">
|
||||||
{ !contentOnly && (
|
<Text variant="b3">{time}</Text>
|
||||||
<div className="message__header">
|
|
||||||
<div style={{ color }} className="message__profile">
|
|
||||||
<Text variant="b1">{name}</Text>
|
|
||||||
</div>
|
|
||||||
<div className="message__time">
|
|
||||||
<Text variant="b3">{time}</Text>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
<div className="message__content">
|
|
||||||
{ reply !== null && (
|
|
||||||
<div className="message__reply-content">
|
|
||||||
<Text variant="b2">
|
|
||||||
<RawIcon color={reply.color} size="extra-small" src={ReplyArrowIC} />
|
|
||||||
<span style={{ color: reply.color }}>{reply.to}</span>
|
|
||||||
<>{` ${reply.content}`}</>
|
|
||||||
</Text>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
<div className="text text-b1">
|
|
||||||
{ markdown ? genMarkdown(content) : linkifyContent(content) }
|
|
||||||
</div>
|
|
||||||
{ edited && <Text className="message__edited" variant="b3">(edited)</Text>}
|
|
||||||
{ reactions && (
|
|
||||||
<div className="message__reactions text text-b3 noselect">
|
|
||||||
{
|
|
||||||
reactions.map((reaction) => (
|
|
||||||
<button key={reaction.id} onClick={() => alert('Sending reactions is yet to be implemented.')} type="button" className={`msg__reaction${reaction.active ? ' msg__reaction--active' : ''}`}>
|
|
||||||
{`${reaction.key} ${reaction.count}`}
|
|
||||||
</button>
|
|
||||||
))
|
|
||||||
}
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
MessageHeader.propTypes = {
|
||||||
Message.defaultProps = {
|
userId: PropTypes.string.isRequired,
|
||||||
color: 'var(--tc-surface-high)',
|
|
||||||
avatarSrc: null,
|
|
||||||
markdown: false,
|
|
||||||
contentOnly: false,
|
|
||||||
reply: null,
|
|
||||||
edited: false,
|
|
||||||
reactions: null,
|
|
||||||
};
|
|
||||||
|
|
||||||
Message.propTypes = {
|
|
||||||
color: PropTypes.string,
|
|
||||||
avatarSrc: PropTypes.string,
|
|
||||||
name: PropTypes.string.isRequired,
|
name: PropTypes.string.isRequired,
|
||||||
content: PropTypes.node.isRequired,
|
color: PropTypes.string.isRequired,
|
||||||
time: PropTypes.string.isRequired,
|
time: PropTypes.string.isRequired,
|
||||||
markdown: PropTypes.bool,
|
|
||||||
contentOnly: PropTypes.bool,
|
|
||||||
reply: PropTypes.shape({
|
|
||||||
color: PropTypes.string.isRequired,
|
|
||||||
to: PropTypes.string.isRequired,
|
|
||||||
content: PropTypes.string.isRequired,
|
|
||||||
}),
|
|
||||||
edited: PropTypes.bool,
|
|
||||||
reactions: PropTypes.arrayOf(PropTypes.exact({
|
|
||||||
id: PropTypes.string,
|
|
||||||
key: PropTypes.string,
|
|
||||||
count: PropTypes.number,
|
|
||||||
active: PropTypes.bool,
|
|
||||||
})),
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export { Message as default, PlaceholderMessage };
|
function MessageReply({
|
||||||
|
userId, name, color, content,
|
||||||
|
}) {
|
||||||
|
return (
|
||||||
|
<div className="message__reply">
|
||||||
|
<Text variant="b2">
|
||||||
|
<RawIcon color={color} size="extra-small" src={ReplyArrowIC} />
|
||||||
|
<span style={{ color }}>{name}</span>
|
||||||
|
<>{` ${content}`}</>
|
||||||
|
</Text>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
MessageReply.propTypes = {
|
||||||
|
userId: PropTypes.string.isRequired,
|
||||||
|
name: PropTypes.string.isRequired,
|
||||||
|
color: PropTypes.string.isRequired,
|
||||||
|
content: PropTypes.string.isRequired,
|
||||||
|
};
|
||||||
|
|
||||||
|
function MessageContent({ content, isMarkdown, isEdited }) {
|
||||||
|
return (
|
||||||
|
<div className="message__content">
|
||||||
|
<div className="text text-b1">
|
||||||
|
{ isMarkdown ? genMarkdown(content) : linkifyContent(content) }
|
||||||
|
</div>
|
||||||
|
{ isEdited && <Text className="message__content-edited" variant="b3">(edited)</Text>}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
MessageContent.defaultProps = {
|
||||||
|
isMarkdown: false,
|
||||||
|
isEdited: false,
|
||||||
|
};
|
||||||
|
MessageContent.propTypes = {
|
||||||
|
content: PropTypes.node.isRequired,
|
||||||
|
isMarkdown: PropTypes.bool,
|
||||||
|
isEdited: PropTypes.bool,
|
||||||
|
};
|
||||||
|
|
||||||
|
function MessageReactionGroup({ children }) {
|
||||||
|
return (
|
||||||
|
<div className="message__reactions text text-b3 noselect">
|
||||||
|
{ children }
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
MessageReactionGroup.propTypes = {
|
||||||
|
children: PropTypes.node.isRequired,
|
||||||
|
};
|
||||||
|
|
||||||
|
function genReactionMsg(userIds, reaction) {
|
||||||
|
const genLessContText = (text) => <span style={{ opacity: '.6' }}>{text}</span>;
|
||||||
|
let msg = <></>;
|
||||||
|
userIds.forEach((userId, index) => {
|
||||||
|
if (index === 0) msg = <>{getUsername(userId)}</>;
|
||||||
|
// eslint-disable-next-line react/jsx-one-expression-per-line
|
||||||
|
else if (index === userIds.length - 1) msg = <>{msg}{genLessContText(' and ')}{getUsername(userId)}</>;
|
||||||
|
// eslint-disable-next-line react/jsx-one-expression-per-line
|
||||||
|
else msg = <>{msg}{genLessContText(', ')}{getUsername(userId)}</>;
|
||||||
|
});
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
{msg}
|
||||||
|
{genLessContText(' reacted with')}
|
||||||
|
{parse(twemoji.parse(reaction))}
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function MessageReaction({
|
||||||
|
reaction, users, isActive, onClick,
|
||||||
|
}) {
|
||||||
|
return (
|
||||||
|
<Tooltip
|
||||||
|
className="msg__reaction-tooltip"
|
||||||
|
content={<Text variant="b2">{genReactionMsg(users, reaction)}</Text>}
|
||||||
|
>
|
||||||
|
<button
|
||||||
|
onClick={onClick}
|
||||||
|
type="button"
|
||||||
|
className={`msg__reaction${isActive ? ' msg__reaction--active' : ''}`}
|
||||||
|
>
|
||||||
|
{ parse(twemoji.parse(reaction)) }
|
||||||
|
<Text variant="b3" className="msg__reaction-count">{users.length}</Text>
|
||||||
|
</button>
|
||||||
|
</Tooltip>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
MessageReaction.propTypes = {
|
||||||
|
reaction: PropTypes.node.isRequired,
|
||||||
|
users: PropTypes.arrayOf(PropTypes.string).isRequired,
|
||||||
|
isActive: PropTypes.bool.isRequired,
|
||||||
|
onClick: PropTypes.func.isRequired,
|
||||||
|
};
|
||||||
|
|
||||||
|
function MessageOptions({ children }) {
|
||||||
|
return (
|
||||||
|
<div className="message__options">
|
||||||
|
{children}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
MessageOptions.propTypes = {
|
||||||
|
children: PropTypes.node.isRequired,
|
||||||
|
};
|
||||||
|
|
||||||
|
function Message({
|
||||||
|
avatar, header, reply, content, reactions, options,
|
||||||
|
}) {
|
||||||
|
const msgClass = header === null ? ' message--content-only' : ' message--full';
|
||||||
|
return (
|
||||||
|
<div className={`message${msgClass}`}>
|
||||||
|
<div className="message__avatar-container">
|
||||||
|
{avatar !== null && avatar}
|
||||||
|
</div>
|
||||||
|
<div className="message__main-container">
|
||||||
|
{header !== null && header}
|
||||||
|
{reply !== null && reply}
|
||||||
|
{content}
|
||||||
|
{reactions !== null && reactions}
|
||||||
|
{options !== null && options}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
Message.defaultProps = {
|
||||||
|
avatar: null,
|
||||||
|
header: null,
|
||||||
|
reply: null,
|
||||||
|
reactions: null,
|
||||||
|
options: null,
|
||||||
|
};
|
||||||
|
Message.propTypes = {
|
||||||
|
avatar: PropTypes.node,
|
||||||
|
header: PropTypes.node,
|
||||||
|
reply: PropTypes.node,
|
||||||
|
content: PropTypes.node.isRequired,
|
||||||
|
reactions: PropTypes.node,
|
||||||
|
options: PropTypes.node,
|
||||||
|
};
|
||||||
|
|
||||||
|
export {
|
||||||
|
Message,
|
||||||
|
MessageHeader,
|
||||||
|
MessageReply,
|
||||||
|
MessageContent,
|
||||||
|
MessageReactionGroup,
|
||||||
|
MessageReaction,
|
||||||
|
MessageOptions,
|
||||||
|
PlaceholderMessage,
|
||||||
|
};
|
||||||
|
|||||||
@@ -8,6 +8,9 @@
|
|||||||
|
|
||||||
&:hover {
|
&:hover {
|
||||||
background-color: var(--bg-surface-hover);
|
background-color: var(--bg-surface-hover);
|
||||||
|
& .message__options {
|
||||||
|
display: flex;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[dir=rtl] & {
|
[dir=rtl] & {
|
||||||
@@ -21,8 +24,7 @@
|
|||||||
padding-top: 6px;
|
padding-top: 6px;
|
||||||
}
|
}
|
||||||
|
|
||||||
&__avatar-container,
|
&__avatar-container{
|
||||||
&__profile {
|
|
||||||
margin-right: var(--sp-tight);
|
margin-right: var(--sp-tight);
|
||||||
|
|
||||||
[dir=rtl] & {
|
[dir=rtl] & {
|
||||||
@@ -36,6 +38,8 @@
|
|||||||
&__main-container {
|
&__main-container {
|
||||||
flex: 1;
|
flex: 1;
|
||||||
min-width: 0;
|
min-width: 0;
|
||||||
|
|
||||||
|
position: relative;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -49,24 +53,6 @@
|
|||||||
&__avatar-container {
|
&__avatar-container {
|
||||||
width: var(--av-small);
|
width: var(--av-small);
|
||||||
}
|
}
|
||||||
&__reply-content {
|
|
||||||
.text {
|
|
||||||
color: var(--tc-surface-low);
|
|
||||||
white-space: nowrap;
|
|
||||||
overflow: hidden;
|
|
||||||
text-overflow: ellipsis;
|
|
||||||
}
|
|
||||||
.ic-raw {
|
|
||||||
width: 16px;
|
|
||||||
height: 14px;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
&__edited {
|
|
||||||
color: var(--tc-surface-low);
|
|
||||||
}
|
|
||||||
&__reactions {
|
|
||||||
margin-top: var(--sp-ultra-tight);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.ph-msg {
|
.ph-msg {
|
||||||
@@ -106,14 +92,26 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.message__reply,
|
||||||
|
.message__content,
|
||||||
|
.message__reactions {
|
||||||
|
max-width: 640px;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
.message__header {
|
.message__header {
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: baseline;
|
align-items: baseline;
|
||||||
|
|
||||||
& .message__profile {
|
& .message__profile {
|
||||||
flex: 1;
|
|
||||||
min-width: 0;
|
min-width: 0;
|
||||||
color: var(--tc-surface-high);
|
color: var(--tc-surface-high);
|
||||||
|
margin-right: var(--sp-tight);
|
||||||
|
|
||||||
|
[dir=rtl] & {
|
||||||
|
margin-left: var(--sp-tight);
|
||||||
|
margin-right: 0;
|
||||||
|
}
|
||||||
|
|
||||||
& > .text {
|
& > .text {
|
||||||
color: inherit;
|
color: inherit;
|
||||||
@@ -122,16 +120,36 @@
|
|||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
text-overflow: ellipsis;
|
text-overflow: ellipsis;
|
||||||
}
|
}
|
||||||
|
& > .text:last-child { display: none; }
|
||||||
|
&:hover {
|
||||||
|
& > .text:first-child { display: none; }
|
||||||
|
& > .text:last-child { display: block; }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
& .message__time {
|
& .message__time {
|
||||||
|
flex: 1;
|
||||||
|
display: flex;
|
||||||
|
justify-content: flex-end;
|
||||||
& > .text {
|
& > .text {
|
||||||
|
white-space: nowrap;
|
||||||
color: var(--tc-surface-low);
|
color: var(--tc-surface-low);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
.message__reply {
|
||||||
|
.text {
|
||||||
|
color: var(--tc-surface-low);
|
||||||
|
white-space: nowrap;
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
}
|
||||||
|
.ic-raw {
|
||||||
|
width: 16px;
|
||||||
|
height: 14px;
|
||||||
|
}
|
||||||
|
}
|
||||||
.message__content {
|
.message__content {
|
||||||
max-width: 640px;
|
|
||||||
word-break: break-word;
|
word-break: break-word;
|
||||||
|
|
||||||
& > .text > * {
|
& > .text > * {
|
||||||
@@ -141,21 +159,40 @@
|
|||||||
& a {
|
& a {
|
||||||
word-break: break-all;
|
word-break: break-all;
|
||||||
}
|
}
|
||||||
|
&-edited {
|
||||||
|
color: var(--tc-surface-low);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.message__reactions {
|
||||||
|
display: flex;
|
||||||
}
|
}
|
||||||
.msg__reaction {
|
.msg__reaction {
|
||||||
--reaction-height: 24px;
|
margin: var(--sp-extra-tight) var(--sp-extra-tight) 0 0;
|
||||||
--reaction-padding: 6px;
|
padding: 0 var(--sp-ultra-tight);
|
||||||
--reaction-radius: calc(var(--bo-radius) / 2);
|
min-height: 26px;
|
||||||
display: inline-flex;
|
display: inline-flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
color: var(--tc-surface-normal);
|
color: var(--tc-surface-normal);
|
||||||
|
background-color: var(--bg-surface-low);
|
||||||
border: 1px solid var(--bg-surface-border);
|
border: 1px solid var(--bg-surface-border);
|
||||||
padding: 0 var(--reaction-padding);
|
border-radius: 4px;
|
||||||
border-radius: var(--reaction-radius);
|
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
height: var(--reaction-height);
|
|
||||||
|
|
||||||
margin-right: var(--sp-extra-tight);
|
& .emoji {
|
||||||
|
width: 14px;
|
||||||
|
height: 14px;
|
||||||
|
margin: 2px;
|
||||||
|
}
|
||||||
|
&-count {
|
||||||
|
margin: 0 var(--sp-ultra-tight);
|
||||||
|
color: var(--tc-surface-normal)
|
||||||
|
}
|
||||||
|
&-tooltip .emoji {
|
||||||
|
width: 14px;
|
||||||
|
height: 14px;
|
||||||
|
margin: 0 var(--sp-ultra-tight);
|
||||||
|
margin-bottom: -2px;
|
||||||
|
}
|
||||||
|
|
||||||
[dir=rtl] & {
|
[dir=rtl] & {
|
||||||
margin: {
|
margin: {
|
||||||
@@ -186,9 +223,25 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
.message__options {
|
||||||
|
position: absolute;
|
||||||
|
top: 0;
|
||||||
|
right: 60px;
|
||||||
|
transform: translateY(-50%);
|
||||||
|
|
||||||
|
border-radius: var(--bo-radius);
|
||||||
|
box-shadow: var(--bs-surface-border);
|
||||||
|
background-color: var(--bg-surface-low);
|
||||||
|
display: none;
|
||||||
|
|
||||||
|
[dir=rtl] & {
|
||||||
|
left: 60px;
|
||||||
|
right: unset;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// markdown formating
|
// markdown formating
|
||||||
.message {
|
.message__content {
|
||||||
& h1,
|
& h1,
|
||||||
& h2 {
|
& h2 {
|
||||||
color: var(--tc-surface-high);
|
color: var(--tc-surface-high);
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.pw {
|
.pw {
|
||||||
--popup-window-drawer-width: 312px;
|
--popup-window-drawer-width: 280px;
|
||||||
|
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
@@ -51,26 +51,21 @@
|
|||||||
|
|
||||||
.pw__drawer {
|
.pw__drawer {
|
||||||
& .header {
|
& .header {
|
||||||
padding-left: var(--sp-extra-tight);
|
padding-left: var(--sp-tight);
|
||||||
|
& .header__title-wrapper {
|
||||||
& .ic-btn-surface:first-child {
|
margin: 0 var(--sp-extra-tight);
|
||||||
margin-right: var(--sp-ultra-tight);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[dir=rtl] & {
|
[dir=rtl] & {
|
||||||
padding-right: var(--sp-extra-tight);
|
padding-right: var(--sp-tight);
|
||||||
& .ic-btn-surface:first-child {
|
|
||||||
margin-right: 0;
|
|
||||||
margin-left: var(--sp-ultra-tight);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.pw-content-selector {
|
.pw-content-selector {
|
||||||
|
margin: 0 var(--sp-extra-tight);
|
||||||
|
border-radius: var(--bo-radius);
|
||||||
&--selected {
|
&--selected {
|
||||||
border: 1px solid var(--bg-surface-border);
|
box-shadow: var(--bs-surface-border);
|
||||||
border-width: 1px 0;
|
|
||||||
background-color: var(--bg-surface);
|
background-color: var(--bg-surface);
|
||||||
|
|
||||||
& .context-menu__item > button {
|
& .context-menu__item > button {
|
||||||
@@ -81,17 +76,13 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
& .context-menu__item > button {
|
& .context-menu__item > button {
|
||||||
|
border-radius: var(--bo-radius);
|
||||||
& .text {
|
& .text {
|
||||||
color: var(--tc-surface-normal);
|
color: var(--tc-surface-normal);
|
||||||
}
|
}
|
||||||
padding-left: var(--sp-normal);
|
|
||||||
& .ic-raw {
|
& .ic-raw {
|
||||||
margin-right: var(--sp-tight);
|
margin-right: var(--sp-tight);
|
||||||
}
|
[dir=rtl] & {
|
||||||
|
|
||||||
[dir=rtl] & {
|
|
||||||
padding-right: var(--sp-normal);
|
|
||||||
& .ic-raw {
|
|
||||||
margin-right: 0;
|
margin-right: 0;
|
||||||
margin-left: var(--sp-tight);
|
margin-left: var(--sp-tight);
|
||||||
}
|
}
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -21,103 +21,6 @@
|
|||||||
@extend .channel-view-flexItem;
|
@extend .channel-view-flexItem;
|
||||||
position: relative;
|
position: relative;
|
||||||
}
|
}
|
||||||
|
|
||||||
&__content {
|
|
||||||
min-height: 100%;
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
justify-content: flex-end;
|
|
||||||
|
|
||||||
& .timeline__wrapper {
|
|
||||||
--typing-noti-height: 28px;
|
|
||||||
min-height: 0;
|
|
||||||
min-width: 0;
|
|
||||||
padding-bottom: var(--typing-noti-height);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
&__typing {
|
|
||||||
display: flex;
|
|
||||||
padding: var(--sp-ultra-tight) var(--sp-normal);
|
|
||||||
background: var(--bg-surface);
|
|
||||||
transition: transform 200ms ease-in-out;
|
|
||||||
|
|
||||||
& b {
|
|
||||||
color: var(--tc-surface-high);
|
|
||||||
}
|
|
||||||
|
|
||||||
&--open {
|
|
||||||
transform: translateY(-99%);
|
|
||||||
}
|
|
||||||
|
|
||||||
& .text {
|
|
||||||
flex: 1;
|
|
||||||
min-width: 0;
|
|
||||||
|
|
||||||
overflow: hidden;
|
|
||||||
white-space: nowrap;
|
|
||||||
text-overflow: ellipsis;
|
|
||||||
margin: 0 var(--sp-tight);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.bouncingLoader {
|
|
||||||
transform: translateY(2px);
|
|
||||||
margin: 0 calc(var(--sp-ultra-tight) / 2);
|
|
||||||
}
|
|
||||||
.bouncingLoader > div,
|
|
||||||
.bouncingLoader:before,
|
|
||||||
.bouncingLoader:after {
|
|
||||||
display: inline-block;
|
|
||||||
width: 8px;
|
|
||||||
height: 8px;
|
|
||||||
background: var(--tc-surface-high);
|
|
||||||
border-radius: 50%;
|
|
||||||
animation: bouncing-loader 0.6s infinite alternate;
|
|
||||||
}
|
|
||||||
|
|
||||||
.bouncingLoader:before,
|
|
||||||
.bouncingLoader:after {
|
|
||||||
content: "";
|
|
||||||
}
|
|
||||||
|
|
||||||
.bouncingLoader > div {
|
|
||||||
margin: 0 4px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.bouncingLoader > div {
|
|
||||||
animation-delay: 0.2s;
|
|
||||||
}
|
|
||||||
|
|
||||||
.bouncingLoader:after {
|
|
||||||
animation-delay: 0.4s;
|
|
||||||
}
|
|
||||||
|
|
||||||
@keyframes bouncing-loader {
|
|
||||||
to {
|
|
||||||
opacity: 0.1;
|
|
||||||
transform: translate3d(0, -4px, 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
&__STB {
|
|
||||||
position: absolute;
|
|
||||||
right: var(--sp-normal);
|
|
||||||
bottom: 0;
|
|
||||||
border-radius: var(--bo-radius);
|
|
||||||
box-shadow: var(--bs-surface-border);
|
|
||||||
background-color: var(--bg-surface-low);
|
|
||||||
transition: transform 200ms ease-in-out;
|
|
||||||
transform: translateY(100%) scale(0);
|
|
||||||
[dir=rtl] & {
|
|
||||||
right: unset;
|
|
||||||
left: var(--sp-normal);
|
|
||||||
}
|
|
||||||
|
|
||||||
&--open {
|
|
||||||
transform: translateY(-28px) scale(1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
&__sticky {
|
&__sticky {
|
||||||
min-height: 85px;
|
min-height: 85px;
|
||||||
@@ -125,124 +28,4 @@
|
|||||||
background: var(--bg-surface);
|
background: var(--bg-surface);
|
||||||
border-top: 1px solid var(--bg-surface-border);
|
border-top: 1px solid var(--bg-surface-border);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
.channel-input {
|
|
||||||
padding: var(--sp-extra-tight) calc(var(--sp-normal) - 2px);
|
|
||||||
display: flex;
|
|
||||||
min-height: 48px;
|
|
||||||
|
|
||||||
&__space {
|
|
||||||
min-width: 0;
|
|
||||||
align-self: center;
|
|
||||||
margin: auto;
|
|
||||||
padding: 0 var(--sp-tight);
|
|
||||||
}
|
|
||||||
|
|
||||||
&__input-container {
|
|
||||||
flex: 1;
|
|
||||||
min-width: 0;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
|
|
||||||
margin: 0 calc(var(--sp-tight) - 2px);
|
|
||||||
background-color: var(--bg-surface-low);
|
|
||||||
box-shadow: var(--bs-surface-border);
|
|
||||||
border-radius: var(--bo-radius);
|
|
||||||
|
|
||||||
& > .ic-raw {
|
|
||||||
transform: scale(0.8);
|
|
||||||
margin-left: var(--sp-extra-tight);
|
|
||||||
[dir=rtl] & {
|
|
||||||
margin-left: 0;
|
|
||||||
margin-right: var(--sp-extra-tight);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
& .scrollbar {
|
|
||||||
max-height: 50vh;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
&__textarea-wrapper {
|
|
||||||
min-height: 40px;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
|
|
||||||
& textarea {
|
|
||||||
resize: none;
|
|
||||||
width: 100%;
|
|
||||||
min-width: 0;
|
|
||||||
min-height: 100%;
|
|
||||||
padding: var(--sp-ultra-tight) calc(var(--sp-tight) - 2px);
|
|
||||||
|
|
||||||
&::placeholder {
|
|
||||||
color: var(--tc-surface-low);
|
|
||||||
}
|
|
||||||
&:focus {
|
|
||||||
outline: none;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.channel-cmd-bar {
|
|
||||||
--cmd-bar-height: 28px;
|
|
||||||
min-height: var(--cmd-bar-height);
|
|
||||||
|
|
||||||
& .timeline-change {
|
|
||||||
justify-content: flex-end;
|
|
||||||
padding: var(--sp-ultra-tight) var(--sp-normal);
|
|
||||||
|
|
||||||
&__content {
|
|
||||||
margin: 0;
|
|
||||||
flex: unset;
|
|
||||||
& > .text {
|
|
||||||
overflow: hidden;
|
|
||||||
white-space: nowrap;
|
|
||||||
text-overflow: ellipsis;
|
|
||||||
& b {
|
|
||||||
color: var(--tc-surface-normal);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.channel-attachment {
|
|
||||||
--side-spacing: calc(var(--sp-normal) + var(--av-small) + var(--sp-tight));
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
margin-left: var(--side-spacing);
|
|
||||||
margin-top: var(--sp-extra-tight);
|
|
||||||
line-height: 0;
|
|
||||||
[dir=rtl] & {
|
|
||||||
margin-left: 0;
|
|
||||||
margin-right: var(--side-spacing);
|
|
||||||
}
|
|
||||||
|
|
||||||
&__preview > img {
|
|
||||||
max-height: 40px;
|
|
||||||
border-radius: var(--bo-radius);
|
|
||||||
}
|
|
||||||
&__icon {
|
|
||||||
padding: var(--sp-extra-tight);
|
|
||||||
background-color: var(--bg-surface-low);
|
|
||||||
box-shadow: var(--bs-surface-border);
|
|
||||||
border-radius: var(--bo-radius);
|
|
||||||
}
|
|
||||||
&__info {
|
|
||||||
flex: 1;
|
|
||||||
min-width: 0;
|
|
||||||
margin: 0 var(--sp-tight);
|
|
||||||
}
|
|
||||||
|
|
||||||
&__option button {
|
|
||||||
transition: transform 200ms ease-in-out;
|
|
||||||
transform: translateY(-48px);
|
|
||||||
& .ic-raw {
|
|
||||||
transition: transform 200ms ease-in-out;
|
|
||||||
transform: rotate(45deg);
|
|
||||||
background-color: var(--bg-caution);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
438
src/app/organisms/channel/ChannelViewCmdBar.jsx
Normal file
438
src/app/organisms/channel/ChannelViewCmdBar.jsx
Normal file
@@ -0,0 +1,438 @@
|
|||||||
|
/* eslint-disable react/prop-types */
|
||||||
|
import React, { useState, useEffect } from 'react';
|
||||||
|
import PropTypes from 'prop-types';
|
||||||
|
import './ChannelViewCmdBar.scss';
|
||||||
|
import Fuse from 'fuse.js';
|
||||||
|
import parse from 'html-react-parser';
|
||||||
|
import twemoji from 'twemoji';
|
||||||
|
|
||||||
|
import initMatrix from '../../../client/initMatrix';
|
||||||
|
import cons from '../../../client/state/cons';
|
||||||
|
import { toggleMarkdown } from '../../../client/action/settings';
|
||||||
|
import * as roomActions from '../../../client/action/room';
|
||||||
|
import {
|
||||||
|
selectRoom,
|
||||||
|
openCreateChannel,
|
||||||
|
openPublicChannels,
|
||||||
|
openInviteUser,
|
||||||
|
} from '../../../client/action/navigation';
|
||||||
|
import { searchEmoji } from '../emoji-board/emoji';
|
||||||
|
|
||||||
|
import Text from '../../atoms/text/Text';
|
||||||
|
import Button from '../../atoms/button/Button';
|
||||||
|
import IconButton from '../../atoms/button/IconButton';
|
||||||
|
import ContextMenu, { MenuHeader } from '../../atoms/context-menu/ContextMenu';
|
||||||
|
import ScrollView from '../../atoms/scroll/ScrollView';
|
||||||
|
import SettingTile from '../../molecules/setting-tile/SettingTile';
|
||||||
|
import TimelineChange from '../../molecules/message/TimelineChange';
|
||||||
|
|
||||||
|
import CmdIC from '../../../../public/res/ic/outlined/cmd.svg';
|
||||||
|
|
||||||
|
import { getUsersActionJsx } from './common';
|
||||||
|
|
||||||
|
const commands = [{
|
||||||
|
name: 'markdown',
|
||||||
|
description: 'Toggle markdown for messages.',
|
||||||
|
exe: () => toggleMarkdown(),
|
||||||
|
}, {
|
||||||
|
name: 'startDM',
|
||||||
|
isOptions: true,
|
||||||
|
description: 'Start direct message with user. Example: /startDM/@johndoe.matrix.org',
|
||||||
|
exe: (roomId, searchTerm) => openInviteUser(undefined, searchTerm),
|
||||||
|
}, {
|
||||||
|
name: 'createChannel',
|
||||||
|
description: 'Create new channel',
|
||||||
|
exe: () => openCreateChannel(),
|
||||||
|
}, {
|
||||||
|
name: 'join',
|
||||||
|
isOptions: true,
|
||||||
|
description: 'Join channel with alias. Example: /join/#cinny:matrix.org',
|
||||||
|
exe: (roomId, searchTerm) => openPublicChannels(searchTerm),
|
||||||
|
}, {
|
||||||
|
name: 'leave',
|
||||||
|
description: 'Leave current channel',
|
||||||
|
exe: (roomId) => roomActions.leave(roomId),
|
||||||
|
}, {
|
||||||
|
name: 'invite',
|
||||||
|
isOptions: true,
|
||||||
|
description: 'Invite user to room. Example: /invite/@johndoe:matrix.org',
|
||||||
|
exe: (roomId, searchTerm) => openInviteUser(roomId, searchTerm),
|
||||||
|
}];
|
||||||
|
|
||||||
|
function CmdHelp() {
|
||||||
|
return (
|
||||||
|
<ContextMenu
|
||||||
|
placement="top"
|
||||||
|
content={(
|
||||||
|
<>
|
||||||
|
<MenuHeader>General command</MenuHeader>
|
||||||
|
<Text variant="b2">/command_name</Text>
|
||||||
|
<MenuHeader>Go-to commands</MenuHeader>
|
||||||
|
<Text variant="b2">{'>*space_name'}</Text>
|
||||||
|
<Text variant="b2">{'>#channel_name'}</Text>
|
||||||
|
<Text variant="b2">{'>@people_name'}</Text>
|
||||||
|
<MenuHeader>Autofill command</MenuHeader>
|
||||||
|
<Text variant="b2">:emoji_name:</Text>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
render={(toggleMenu) => (
|
||||||
|
<IconButton
|
||||||
|
src={CmdIC}
|
||||||
|
size="extra-small"
|
||||||
|
onClick={toggleMenu}
|
||||||
|
tooltip="Commands"
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function ViewCmd() {
|
||||||
|
function renderAllCmds() {
|
||||||
|
return commands.map((command) => (
|
||||||
|
<SettingTile
|
||||||
|
key={command.name}
|
||||||
|
title={command.name}
|
||||||
|
content={(<Text variant="b3">{command.description}</Text>)}
|
||||||
|
/>
|
||||||
|
));
|
||||||
|
}
|
||||||
|
return (
|
||||||
|
<ContextMenu
|
||||||
|
maxWidth={250}
|
||||||
|
placement="top"
|
||||||
|
content={(
|
||||||
|
<>
|
||||||
|
<MenuHeader>General commands</MenuHeader>
|
||||||
|
{renderAllCmds()}
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
render={(toggleMenu) => (
|
||||||
|
<span>
|
||||||
|
<Button onClick={toggleMenu}><span className="text text-b3">View all</span></Button>
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function FollowingMembers({ roomId, roomTimeline, viewEvent }) {
|
||||||
|
const [followingMembers, setFollowingMembers] = useState([]);
|
||||||
|
const mx = initMatrix.matrixClient;
|
||||||
|
|
||||||
|
function handleOnMessageSent() {
|
||||||
|
setFollowingMembers([]);
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateFollowingMembers() {
|
||||||
|
const room = mx.getRoom(roomId);
|
||||||
|
const { timeline } = room;
|
||||||
|
const userIds = room.getUsersReadUpTo(timeline[timeline.length - 1]);
|
||||||
|
const myUserId = mx.getUserId();
|
||||||
|
setFollowingMembers(userIds.filter((userId) => userId !== myUserId));
|
||||||
|
}
|
||||||
|
|
||||||
|
useEffect(() => updateFollowingMembers(), [roomId]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
roomTimeline.on(cons.events.roomTimeline.READ_RECEIPT, updateFollowingMembers);
|
||||||
|
viewEvent.on('message_sent', handleOnMessageSent);
|
||||||
|
return () => {
|
||||||
|
roomTimeline.removeListener(cons.events.roomTimeline.READ_RECEIPT, updateFollowingMembers);
|
||||||
|
viewEvent.removeListener('message_sent', handleOnMessageSent);
|
||||||
|
};
|
||||||
|
}, [roomTimeline]);
|
||||||
|
|
||||||
|
return followingMembers.length !== 0 && (
|
||||||
|
<TimelineChange
|
||||||
|
variant="follow"
|
||||||
|
content={getUsersActionJsx(followingMembers, 'following the conversation.')}
|
||||||
|
time=""
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
FollowingMembers.propTypes = {
|
||||||
|
roomId: PropTypes.string.isRequired,
|
||||||
|
roomTimeline: PropTypes.shape({}).isRequired,
|
||||||
|
viewEvent: PropTypes.shape({}).isRequired,
|
||||||
|
};
|
||||||
|
|
||||||
|
function getCmdActivationMessage(prefix) {
|
||||||
|
function genMessage(prime, secondary) {
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<span>{prime}</span>
|
||||||
|
<span>{secondary}</span>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
const cmd = {
|
||||||
|
'/': () => genMessage('General command mode activated. ', 'Type command name for suggestions.'),
|
||||||
|
'>*': () => genMessage('Go-to command mode activated. ', 'Type space name for suggestions.'),
|
||||||
|
'>#': () => genMessage('Go-to command mode activated. ', 'Type channel name for suggestions.'),
|
||||||
|
'>@': () => genMessage('Go-to command mode activated. ', 'Type people name for suggestions.'),
|
||||||
|
':': () => genMessage('Emoji autofill command mode activated. ', 'Type emoji shortcut for suggestions.'),
|
||||||
|
};
|
||||||
|
return cmd[prefix]?.();
|
||||||
|
}
|
||||||
|
|
||||||
|
function CmdItem({ onClick, children }) {
|
||||||
|
return (
|
||||||
|
<button className="cmd-item" onClick={onClick} type="button">
|
||||||
|
{children}
|
||||||
|
</button>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
CmdItem.propTypes = {
|
||||||
|
onClick: PropTypes.func.isRequired,
|
||||||
|
children: PropTypes.node.isRequired,
|
||||||
|
};
|
||||||
|
|
||||||
|
function searchInRoomIds(roomIds, term) {
|
||||||
|
const rooms = roomIds.map((rId) => {
|
||||||
|
const room = initMatrix.matrixClient.getRoom(rId);
|
||||||
|
return {
|
||||||
|
name: room.name,
|
||||||
|
roomId: room.roomId,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
const fuse = new Fuse(rooms, {
|
||||||
|
includeScore: true,
|
||||||
|
keys: ['name'],
|
||||||
|
threshold: '0.3',
|
||||||
|
});
|
||||||
|
return fuse.search(term);
|
||||||
|
}
|
||||||
|
|
||||||
|
function searchCommands(term) {
|
||||||
|
const fuse = new Fuse(commands, {
|
||||||
|
includeScore: true,
|
||||||
|
keys: ['name'],
|
||||||
|
threshold: '0.3',
|
||||||
|
});
|
||||||
|
return fuse.search(term);
|
||||||
|
}
|
||||||
|
|
||||||
|
let perfectMatchCmd = null;
|
||||||
|
function getCmdSuggestions({ prefix, slug }, fireCmd, viewEvent) {
|
||||||
|
function getRoomsSuggestion(cmdPrefix, rooms, roomSlug) {
|
||||||
|
const result = searchInRoomIds(rooms, roomSlug);
|
||||||
|
if (result.length === 0) viewEvent.emit('cmd_error');
|
||||||
|
perfectMatchCmd = {
|
||||||
|
prefix: cmdPrefix,
|
||||||
|
slug: roomSlug,
|
||||||
|
result: result[0]?.item || null,
|
||||||
|
};
|
||||||
|
return result.map((finding) => (
|
||||||
|
<CmdItem
|
||||||
|
key={finding.item.roomId}
|
||||||
|
onClick={() => {
|
||||||
|
fireCmd({
|
||||||
|
prefix: cmdPrefix,
|
||||||
|
slug: roomSlug,
|
||||||
|
result: finding.item,
|
||||||
|
});
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Text variant="b2">{finding.item.name}</Text>
|
||||||
|
</CmdItem>
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
function getGenCmdSuggestions(cmdPrefix, cmdSlug) {
|
||||||
|
const cmdSlugParts = cmdSlug.split('/');
|
||||||
|
const cmdSlugOption = cmdSlugParts[1];
|
||||||
|
const result = searchCommands(cmdSlugParts[0]);
|
||||||
|
if (result.length === 0) viewEvent.emit('cmd_error');
|
||||||
|
perfectMatchCmd = {
|
||||||
|
prefix: cmdPrefix,
|
||||||
|
slug: cmdSlug,
|
||||||
|
option: cmdSlugOption,
|
||||||
|
result: result[0]?.item || null,
|
||||||
|
};
|
||||||
|
return result.map((finding) => {
|
||||||
|
let option = '';
|
||||||
|
if (finding.item.isOptions) {
|
||||||
|
if (typeof cmdSlugOption === 'string') option = `/${cmdSlugOption}`;
|
||||||
|
else option = '/?';
|
||||||
|
}
|
||||||
|
return (
|
||||||
|
<CmdItem
|
||||||
|
key={finding.item.name}
|
||||||
|
onClick={() => {
|
||||||
|
fireCmd({
|
||||||
|
prefix: cmdPrefix,
|
||||||
|
slug: cmdSlug,
|
||||||
|
option: cmdSlugOption,
|
||||||
|
result: finding.item,
|
||||||
|
});
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Text variant="b2">{`${finding.item.name}${option}`}</Text>
|
||||||
|
</CmdItem>
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function getEmojiSuggestion(emPrefix, shortcutSlug) {
|
||||||
|
let searchTerm = shortcutSlug;
|
||||||
|
if (searchTerm.length <= 3) {
|
||||||
|
if (searchTerm.match(/^[-]?(\))/)) searchTerm = 'smile';
|
||||||
|
else if (searchTerm.match(/^[-]?(s|S)/)) searchTerm = 'confused';
|
||||||
|
else if (searchTerm.match(/^[-]?(o|O|0)/)) searchTerm = 'astonished';
|
||||||
|
else if (searchTerm.match(/^[-]?(\|)/)) searchTerm = 'neutral_face';
|
||||||
|
else if (searchTerm.match(/^[-]?(d|D)/)) searchTerm = 'grin';
|
||||||
|
else if (searchTerm.match(/^[-]?(\/)/)) searchTerm = 'frown';
|
||||||
|
else if (searchTerm.match(/^[-]?(p|P)/)) searchTerm = 'stick_out_tongue';
|
||||||
|
else if (searchTerm.match(/^'[-]?(\()/)) searchTerm = 'cry';
|
||||||
|
else if (searchTerm.match(/^[-]?(x|X)/)) searchTerm = 'dizzy_face';
|
||||||
|
else if (searchTerm.match(/^[-]?(\()/)) searchTerm = 'pleading_face';
|
||||||
|
else if (searchTerm.match(/^[-]?(\$)/)) searchTerm = 'money';
|
||||||
|
else if (searchTerm.match(/^(<3)/)) searchTerm = 'heart';
|
||||||
|
}
|
||||||
|
const result = searchEmoji(searchTerm);
|
||||||
|
if (result.length === 0) viewEvent.emit('cmd_error');
|
||||||
|
perfectMatchCmd = {
|
||||||
|
prefix: emPrefix,
|
||||||
|
slug: shortcutSlug,
|
||||||
|
result: result[0]?.item || null,
|
||||||
|
};
|
||||||
|
return result.map((finding) => (
|
||||||
|
<CmdItem
|
||||||
|
key={finding.item.hexcode}
|
||||||
|
onClick={() => fireCmd({
|
||||||
|
prefix: emPrefix,
|
||||||
|
slug: shortcutSlug,
|
||||||
|
result: finding.item,
|
||||||
|
})}
|
||||||
|
>
|
||||||
|
{
|
||||||
|
parse(twemoji.parse(
|
||||||
|
finding.item.unicode,
|
||||||
|
{
|
||||||
|
attributes: () => ({
|
||||||
|
unicode: finding.item.unicode,
|
||||||
|
shortcodes: finding.item.shortcodes?.toString(),
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
))
|
||||||
|
}
|
||||||
|
</CmdItem>
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
const { roomList } = initMatrix;
|
||||||
|
const cmd = {
|
||||||
|
'/': (command) => getGenCmdSuggestions(prefix, command),
|
||||||
|
'>*': (space) => getRoomsSuggestion(prefix, [...roomList.spaces], space),
|
||||||
|
'>#': (channel) => getRoomsSuggestion(prefix, [...roomList.rooms], channel),
|
||||||
|
'>@': (people) => getRoomsSuggestion(prefix, [...roomList.directs], people),
|
||||||
|
':': (emojiShortcut) => getEmojiSuggestion(prefix, emojiShortcut),
|
||||||
|
};
|
||||||
|
return cmd[prefix]?.(slug);
|
||||||
|
}
|
||||||
|
|
||||||
|
function ChannelViewCmdBar({ roomId, roomTimeline, viewEvent }) {
|
||||||
|
const [cmd, setCmd] = useState(null);
|
||||||
|
|
||||||
|
function processCmd(prefix, slug) {
|
||||||
|
setCmd({ prefix, slug });
|
||||||
|
}
|
||||||
|
function activateCmd(prefix) {
|
||||||
|
setCmd({ prefix });
|
||||||
|
perfectMatchCmd = null;
|
||||||
|
}
|
||||||
|
function deactivateCmd() {
|
||||||
|
setCmd(null);
|
||||||
|
perfectMatchCmd = null;
|
||||||
|
}
|
||||||
|
function fireCmd(myCmd) {
|
||||||
|
if (myCmd.prefix.match(/^>[*#@]$/)) {
|
||||||
|
selectRoom(myCmd.result.roomId);
|
||||||
|
viewEvent.emit('cmd_fired');
|
||||||
|
}
|
||||||
|
if (myCmd.prefix === '/') {
|
||||||
|
myCmd.result.exe(roomId, myCmd.option);
|
||||||
|
viewEvent.emit('cmd_fired');
|
||||||
|
}
|
||||||
|
if (myCmd.prefix === ':') {
|
||||||
|
viewEvent.emit('cmd_fired', {
|
||||||
|
replace: myCmd.result.unicode,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
deactivateCmd();
|
||||||
|
}
|
||||||
|
function executeCmd() {
|
||||||
|
if (perfectMatchCmd === null) return;
|
||||||
|
if (perfectMatchCmd.result === null) return;
|
||||||
|
fireCmd(perfectMatchCmd);
|
||||||
|
}
|
||||||
|
function errorCmd() {
|
||||||
|
setCmd({ error: 'No suggestion found.' });
|
||||||
|
}
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
viewEvent.on('cmd_activate', activateCmd);
|
||||||
|
viewEvent.on('cmd_process', processCmd);
|
||||||
|
viewEvent.on('cmd_deactivate', deactivateCmd);
|
||||||
|
viewEvent.on('cmd_exe', executeCmd);
|
||||||
|
viewEvent.on('cmd_error', errorCmd);
|
||||||
|
return () => {
|
||||||
|
deactivateCmd();
|
||||||
|
viewEvent.removeListener('cmd_activate', activateCmd);
|
||||||
|
viewEvent.removeListener('cmd_process', processCmd);
|
||||||
|
viewEvent.removeListener('cmd_deactivate', deactivateCmd);
|
||||||
|
viewEvent.removeListener('cmd_exe', executeCmd);
|
||||||
|
viewEvent.removeListener('cmd_error', errorCmd);
|
||||||
|
};
|
||||||
|
}, [roomId]);
|
||||||
|
|
||||||
|
if (cmd !== null && typeof cmd.error !== 'undefined') {
|
||||||
|
return (
|
||||||
|
<div className="cmd-bar">
|
||||||
|
<div className="cmd-bar__info">
|
||||||
|
<div className="cmd-bar__info-indicator--error" />
|
||||||
|
</div>
|
||||||
|
<div className="cmd-bar__content">
|
||||||
|
<Text className="cmd-bar__content-error" variant="b2">{cmd.error}</Text>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="cmd-bar">
|
||||||
|
<div className="cmd-bar__info">
|
||||||
|
{cmd === null && <CmdHelp />}
|
||||||
|
{cmd !== null && typeof cmd.slug === 'undefined' && <div className="cmd-bar__info-indicator" /> }
|
||||||
|
{cmd !== null && typeof cmd.slug === 'string' && <Text variant="b3">TAB</Text>}
|
||||||
|
</div>
|
||||||
|
<div className="cmd-bar__content">
|
||||||
|
{cmd === null && (
|
||||||
|
<FollowingMembers
|
||||||
|
roomId={roomId}
|
||||||
|
roomTimeline={roomTimeline}
|
||||||
|
viewEvent={viewEvent}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
{cmd !== null && typeof cmd.slug === 'undefined' && <Text className="cmd-bar__content-help" variant="b2">{getCmdActivationMessage(cmd.prefix)}</Text>}
|
||||||
|
{cmd !== null && typeof cmd.slug === 'string' && (
|
||||||
|
<ScrollView horizontal vertical={false} invisible>
|
||||||
|
<div className="cmd-bar__content__suggestions">{getCmdSuggestions(cmd, fireCmd, viewEvent)}</div>
|
||||||
|
</ScrollView>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<div className="cmd-bar__more">
|
||||||
|
{cmd !== null && cmd.prefix === '/' && <ViewCmd />}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
ChannelViewCmdBar.propTypes = {
|
||||||
|
roomId: PropTypes.string.isRequired,
|
||||||
|
roomTimeline: PropTypes.shape({}).isRequired,
|
||||||
|
viewEvent: PropTypes.shape({}).isRequired,
|
||||||
|
};
|
||||||
|
|
||||||
|
export default ChannelViewCmdBar;
|
||||||
139
src/app/organisms/channel/ChannelViewCmdBar.scss
Normal file
139
src/app/organisms/channel/ChannelViewCmdBar.scss
Normal file
@@ -0,0 +1,139 @@
|
|||||||
|
.overflow-ellipsis {
|
||||||
|
overflow: hidden;
|
||||||
|
white-space: nowrap;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
}
|
||||||
|
|
||||||
|
.cmd-bar {
|
||||||
|
--cmd-bar-height: 28px;
|
||||||
|
min-height: var(--cmd-bar-height);
|
||||||
|
display: flex;
|
||||||
|
|
||||||
|
&__info {
|
||||||
|
display: flex;
|
||||||
|
width: calc(2 * var(--sp-extra-loose));
|
||||||
|
padding-left: var(--sp-ultra-tight);
|
||||||
|
[dir=rtl] & {
|
||||||
|
padding-left: 0;
|
||||||
|
padding-right: var(--sp-ultra-tight);
|
||||||
|
}
|
||||||
|
|
||||||
|
& > * {
|
||||||
|
margin: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
& .ic-btn-surface {
|
||||||
|
padding: 0;
|
||||||
|
& .ic-raw {
|
||||||
|
background-color: var(--tc-surface-low);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
& .context-menu .text-b2 {
|
||||||
|
margin: var(--sp-extra-tight) var(--sp-tight);
|
||||||
|
}
|
||||||
|
|
||||||
|
&-indicator,
|
||||||
|
&-indicator--error {
|
||||||
|
width: 8px;
|
||||||
|
height: 8px;
|
||||||
|
border-radius: 50%;
|
||||||
|
background-color: var(--bg-positive);
|
||||||
|
}
|
||||||
|
&-indicator--error {
|
||||||
|
background-color: var(--bg-danger);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
&__content {
|
||||||
|
min-width: 0;
|
||||||
|
flex: 1;
|
||||||
|
display: flex;
|
||||||
|
|
||||||
|
&-help,
|
||||||
|
&-error {
|
||||||
|
@extend .overflow-ellipsis;
|
||||||
|
align-self: center;
|
||||||
|
span {
|
||||||
|
color: var(--tc-surface-low);
|
||||||
|
&:first-child {
|
||||||
|
color: var(--tc-surface-normal)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
&-error {
|
||||||
|
color: var(--bg-danger);
|
||||||
|
}
|
||||||
|
&__suggestions {
|
||||||
|
display: flex;
|
||||||
|
height: 100%;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
&__more {
|
||||||
|
display: flex;
|
||||||
|
& button {
|
||||||
|
min-width: 0;
|
||||||
|
height: 100%;
|
||||||
|
margin: 0 var(--sp-normal);
|
||||||
|
padding: 0 var(--sp-extra-tight);
|
||||||
|
box-shadow: none;
|
||||||
|
border-radius: var(--bo-radius) var(--bo-radius) 0 0;
|
||||||
|
& .text {
|
||||||
|
color: var(--tc-surface-normal);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
& .setting-tile {
|
||||||
|
margin: var(--sp-tight);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
& .timeline-change {
|
||||||
|
width: 100%;
|
||||||
|
justify-content: flex-end;
|
||||||
|
padding: var(--sp-ultra-tight) var(--sp-normal);
|
||||||
|
border-radius: var(--bo-radius) var(--bo-radius) 0 0;
|
||||||
|
|
||||||
|
&__content {
|
||||||
|
margin: 0;
|
||||||
|
flex: unset;
|
||||||
|
& > .text {
|
||||||
|
@extend .overflow-ellipsis;
|
||||||
|
& b {
|
||||||
|
color: var(--tc-surface-normal);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.cmd-item {
|
||||||
|
--cmd-item-bar: inset 0 -2px 0 0 var(--bg-caution);
|
||||||
|
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
margin-right: var(--sp-extra-tight);
|
||||||
|
padding: 0 var(--sp-extra-tight);
|
||||||
|
height: 100%;
|
||||||
|
border-radius: var(--bo-radius) var(--bo-radius) 0 0;
|
||||||
|
cursor: pointer;
|
||||||
|
|
||||||
|
[dir=rtl] & {
|
||||||
|
margin-right: 0;
|
||||||
|
margin-left: var(--sp-extra-tight);
|
||||||
|
}
|
||||||
|
|
||||||
|
& .emoji {
|
||||||
|
width: 20px;
|
||||||
|
height: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
background-color: var(--bg-caution-hover);
|
||||||
|
}
|
||||||
|
&:focus {
|
||||||
|
background-color: var(--bg-caution-active);
|
||||||
|
box-shadow: var(--cmd-item-bar);
|
||||||
|
border-bottom: 2px solid transparent;
|
||||||
|
outline: none;
|
||||||
|
}
|
||||||
|
}
|
||||||
446
src/app/organisms/channel/ChannelViewContent.jsx
Normal file
446
src/app/organisms/channel/ChannelViewContent.jsx
Normal file
@@ -0,0 +1,446 @@
|
|||||||
|
/* eslint-disable react/prop-types */
|
||||||
|
import React, { useState, useEffect, useLayoutEffect } from 'react';
|
||||||
|
import PropTypes from 'prop-types';
|
||||||
|
import './ChannelViewContent.scss';
|
||||||
|
|
||||||
|
import dateFormat from 'dateformat';
|
||||||
|
|
||||||
|
import initMatrix from '../../../client/initMatrix';
|
||||||
|
import cons from '../../../client/state/cons';
|
||||||
|
import { redact } from '../../../client/action/room';
|
||||||
|
import { getUsername, doesRoomHaveUnread } from '../../../util/matrixUtil';
|
||||||
|
import colorMXID from '../../../util/colorMXID';
|
||||||
|
import { diffMinutes, isNotInSameDay } from '../../../util/common';
|
||||||
|
|
||||||
|
import Divider from '../../atoms/divider/Divider';
|
||||||
|
import Avatar from '../../atoms/avatar/Avatar';
|
||||||
|
import IconButton from '../../atoms/button/IconButton';
|
||||||
|
import {
|
||||||
|
Message,
|
||||||
|
MessageHeader,
|
||||||
|
MessageReply,
|
||||||
|
MessageContent,
|
||||||
|
MessageReactionGroup,
|
||||||
|
MessageReaction,
|
||||||
|
MessageOptions,
|
||||||
|
PlaceholderMessage,
|
||||||
|
} from '../../molecules/message/Message';
|
||||||
|
import * as Media from '../../molecules/media/Media';
|
||||||
|
import ChannelIntro from '../../molecules/channel-intro/ChannelIntro';
|
||||||
|
import TimelineChange from '../../molecules/message/TimelineChange';
|
||||||
|
|
||||||
|
import ReplyArrowIC from '../../../../public/res/ic/outlined/reply-arrow.svg';
|
||||||
|
import BinIC from '../../../../public/res/ic/outlined/bin.svg';
|
||||||
|
|
||||||
|
import { parseReply, parseTimelineChange } from './common';
|
||||||
|
|
||||||
|
const MAX_MSG_DIFF_MINUTES = 5;
|
||||||
|
|
||||||
|
let wasAtBottom = true;
|
||||||
|
function ChannelViewContent({
|
||||||
|
roomId, roomTimeline, timelineScroll, viewEvent,
|
||||||
|
}) {
|
||||||
|
const [isReachedTimelineEnd, setIsReachedTimelineEnd] = useState(false);
|
||||||
|
const [onStateUpdate, updateState] = useState(null);
|
||||||
|
const [onPagination, setOnPagination] = useState(null);
|
||||||
|
const mx = initMatrix.matrixClient;
|
||||||
|
|
||||||
|
function autoLoadTimeline() {
|
||||||
|
if (timelineScroll.isScrollable() === true) return;
|
||||||
|
roomTimeline.paginateBack();
|
||||||
|
}
|
||||||
|
function trySendingReadReceipt() {
|
||||||
|
const { room, timeline } = roomTimeline;
|
||||||
|
if (doesRoomHaveUnread(room) && timeline.length !== 0) {
|
||||||
|
mx.sendReadReceipt(timeline[timeline.length - 1]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function onReachedTop() {
|
||||||
|
if (roomTimeline.isOngoingPagination || isReachedTimelineEnd) return;
|
||||||
|
roomTimeline.paginateBack();
|
||||||
|
}
|
||||||
|
function toggleOnReachedBottom(isBottom) {
|
||||||
|
wasAtBottom = isBottom;
|
||||||
|
if (!isBottom) return;
|
||||||
|
trySendingReadReceipt();
|
||||||
|
}
|
||||||
|
|
||||||
|
const updatePAG = (canPagMore) => {
|
||||||
|
if (!canPagMore) {
|
||||||
|
setIsReachedTimelineEnd(true);
|
||||||
|
} else {
|
||||||
|
setOnPagination({});
|
||||||
|
autoLoadTimeline();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
// force update RoomTimeline on cons.events.roomTimeline.EVENT
|
||||||
|
const updateRT = () => {
|
||||||
|
if (wasAtBottom) {
|
||||||
|
trySendingReadReceipt();
|
||||||
|
}
|
||||||
|
updateState({});
|
||||||
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
setIsReachedTimelineEnd(false);
|
||||||
|
wasAtBottom = true;
|
||||||
|
}, [roomId]);
|
||||||
|
useEffect(() => trySendingReadReceipt(), [roomTimeline]);
|
||||||
|
|
||||||
|
// init room setup completed.
|
||||||
|
// listen for future. setup stateUpdate listener.
|
||||||
|
useEffect(() => {
|
||||||
|
roomTimeline.on(cons.events.roomTimeline.EVENT, updateRT);
|
||||||
|
roomTimeline.on(cons.events.roomTimeline.PAGINATED, updatePAG);
|
||||||
|
viewEvent.on('reached-top', onReachedTop);
|
||||||
|
viewEvent.on('toggle-reached-bottom', toggleOnReachedBottom);
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
roomTimeline.removeListener(cons.events.roomTimeline.EVENT, updateRT);
|
||||||
|
roomTimeline.removeListener(cons.events.roomTimeline.PAGINATED, updatePAG);
|
||||||
|
viewEvent.removeListener('reached-top', onReachedTop);
|
||||||
|
viewEvent.removeListener('toggle-reached-bottom', toggleOnReachedBottom);
|
||||||
|
};
|
||||||
|
}, [roomTimeline, isReachedTimelineEnd, onPagination]);
|
||||||
|
|
||||||
|
useLayoutEffect(() => {
|
||||||
|
timelineScroll.reachBottom();
|
||||||
|
autoLoadTimeline();
|
||||||
|
}, [roomTimeline]);
|
||||||
|
|
||||||
|
useLayoutEffect(() => {
|
||||||
|
if (onPagination === null) return;
|
||||||
|
timelineScroll.tryRestoringScroll();
|
||||||
|
}, [onPagination]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (onStateUpdate === null) return;
|
||||||
|
if (wasAtBottom) timelineScroll.reachBottom();
|
||||||
|
}, [onStateUpdate]);
|
||||||
|
|
||||||
|
let prevMEvent = null;
|
||||||
|
function renderMessage(mEvent) {
|
||||||
|
function isMedia(mE) {
|
||||||
|
return (
|
||||||
|
mE.getContent()?.msgtype === 'm.file'
|
||||||
|
|| mE.getContent()?.msgtype === 'm.image'
|
||||||
|
|| mE.getContent()?.msgtype === 'm.audio'
|
||||||
|
|| mE.getContent()?.msgtype === 'm.video'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
function genMediaContent(mE) {
|
||||||
|
const mContent = mE.getContent();
|
||||||
|
let mediaMXC = mContent.url;
|
||||||
|
let thumbnailMXC = mContent?.info?.thumbnail_url;
|
||||||
|
const isEncryptedFile = typeof mediaMXC === 'undefined';
|
||||||
|
if (isEncryptedFile) mediaMXC = mContent.file.url;
|
||||||
|
|
||||||
|
switch (mE.getContent()?.msgtype) {
|
||||||
|
case 'm.file':
|
||||||
|
return (
|
||||||
|
<Media.File
|
||||||
|
name={mContent.body}
|
||||||
|
link={mx.mxcUrlToHttp(mediaMXC)}
|
||||||
|
file={mContent.file}
|
||||||
|
type={mContent.info.mimetype}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
case 'm.image':
|
||||||
|
return (
|
||||||
|
<Media.Image
|
||||||
|
name={mContent.body}
|
||||||
|
width={mContent.info.w || null}
|
||||||
|
height={mContent.info.h || null}
|
||||||
|
link={mx.mxcUrlToHttp(mediaMXC)}
|
||||||
|
file={isEncryptedFile ? mContent.file : null}
|
||||||
|
type={mContent.info.mimetype}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
case 'm.audio':
|
||||||
|
return (
|
||||||
|
<Media.Audio
|
||||||
|
name={mContent.body}
|
||||||
|
link={mx.mxcUrlToHttp(mediaMXC)}
|
||||||
|
type={mContent.info.mimetype}
|
||||||
|
file={mContent.file}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
case 'm.video':
|
||||||
|
if (typeof thumbnailMXC === 'undefined') {
|
||||||
|
thumbnailMXC = mContent.info?.thumbnail_file?.url || null;
|
||||||
|
}
|
||||||
|
return (
|
||||||
|
<Media.Video
|
||||||
|
name={mContent.body}
|
||||||
|
link={mx.mxcUrlToHttp(mediaMXC)}
|
||||||
|
thumbnail={thumbnailMXC === null ? null : mx.mxcUrlToHttp(thumbnailMXC)}
|
||||||
|
thumbnailFile={isEncryptedFile ? mContent.info.thumbnail_file : null}
|
||||||
|
thumbnailType={mContent.info.thumbnail_info?.mimetype || null}
|
||||||
|
width={mContent.info.w || null}
|
||||||
|
height={mContent.info.h || null}
|
||||||
|
file={isEncryptedFile ? mContent.file : null}
|
||||||
|
type={mContent.info.mimetype}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
default:
|
||||||
|
return 'Unable to attach media file!';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mEvent.getType() === 'm.room.create') {
|
||||||
|
const roomTopic = roomTimeline.room.currentState.getStateEvents('m.room.topic')[0]?.getContent().topic;
|
||||||
|
return (
|
||||||
|
<ChannelIntro
|
||||||
|
key={mEvent.getId()}
|
||||||
|
avatarSrc={roomTimeline.room.getAvatarUrl(initMatrix.matrixClient.baseUrl, 80, 80, 'crop')}
|
||||||
|
name={roomTimeline.room.name}
|
||||||
|
heading={`Welcome to ${roomTimeline.room.name}`}
|
||||||
|
desc={`This is the beginning of ${roomTimeline.room.name} channel.${typeof roomTopic !== 'undefined' ? (` Topic: ${roomTopic}`) : ''}`}
|
||||||
|
time={`Created at ${dateFormat(mEvent.getDate(), 'dd mmmm yyyy, hh:MM TT')}`}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (
|
||||||
|
mEvent.getType() !== 'm.room.message'
|
||||||
|
&& mEvent.getType() !== 'm.room.encrypted'
|
||||||
|
&& mEvent.getType() !== 'm.room.member'
|
||||||
|
) return false;
|
||||||
|
if (mEvent.getRelation()?.rel_type === 'm.replace') return false;
|
||||||
|
|
||||||
|
// ignore if message is deleted
|
||||||
|
if (mEvent.isRedacted()) return false;
|
||||||
|
|
||||||
|
let divider = null;
|
||||||
|
if (prevMEvent !== null && isNotInSameDay(mEvent.getDate(), prevMEvent.getDate())) {
|
||||||
|
divider = <Divider key={`divider-${mEvent.getId()}`} text={`${dateFormat(mEvent.getDate(), 'mmmm dd, yyyy')}`} />;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mEvent.getType() !== 'm.room.member') {
|
||||||
|
const isContentOnly = (
|
||||||
|
prevMEvent !== null
|
||||||
|
&& prevMEvent.getType() !== 'm.room.member'
|
||||||
|
&& diffMinutes(mEvent.getDate(), prevMEvent.getDate()) <= MAX_MSG_DIFF_MINUTES
|
||||||
|
&& prevMEvent.getSender() === mEvent.getSender()
|
||||||
|
);
|
||||||
|
|
||||||
|
const myPowerlevel = roomTimeline.room.getMember(mx.getUserId()).powerLevel;
|
||||||
|
const canIRedact = roomTimeline.room.currentState.hasSufficientPowerLevelFor('redact', myPowerlevel);
|
||||||
|
|
||||||
|
let content = mEvent.getContent().body;
|
||||||
|
if (typeof content === 'undefined') return null;
|
||||||
|
let reply = null;
|
||||||
|
let reactions = null;
|
||||||
|
let isMarkdown = mEvent.getContent().format === 'org.matrix.custom.html';
|
||||||
|
const isReply = typeof mEvent.getWireContent()['m.relates_to']?.['m.in_reply_to'] !== 'undefined';
|
||||||
|
const isEdited = roomTimeline.editedTimeline.has(mEvent.getId());
|
||||||
|
const haveReactions = roomTimeline.reactionTimeline.has(mEvent.getId());
|
||||||
|
|
||||||
|
if (isReply) {
|
||||||
|
const parsedContent = parseReply(content);
|
||||||
|
|
||||||
|
if (parsedContent !== null) {
|
||||||
|
const username = getUsername(parsedContent.userId);
|
||||||
|
reply = {
|
||||||
|
userId: parsedContent.userId,
|
||||||
|
color: colorMXID(parsedContent.userId),
|
||||||
|
to: username,
|
||||||
|
content: parsedContent.replyContent,
|
||||||
|
};
|
||||||
|
content = parsedContent.content;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isEdited) {
|
||||||
|
const editedList = roomTimeline.editedTimeline.get(mEvent.getId());
|
||||||
|
const latestEdited = editedList[editedList.length - 1];
|
||||||
|
if (typeof latestEdited.getContent()['m.new_content'] === 'undefined') return null;
|
||||||
|
const latestEditBody = latestEdited.getContent()['m.new_content'].body;
|
||||||
|
const parsedEditedContent = parseReply(latestEditBody);
|
||||||
|
isMarkdown = latestEdited.getContent()['m.new_content'].format === 'org.matrix.custom.html';
|
||||||
|
if (parsedEditedContent === null) {
|
||||||
|
content = latestEditBody;
|
||||||
|
} else {
|
||||||
|
content = parsedEditedContent.content;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (haveReactions) {
|
||||||
|
reactions = [];
|
||||||
|
roomTimeline.reactionTimeline.get(mEvent.getId()).forEach((rEvent) => {
|
||||||
|
if (rEvent.getRelation() === null) return;
|
||||||
|
function alreadyHaveThisReaction(rE) {
|
||||||
|
for (let i = 0; i < reactions.length; i += 1) {
|
||||||
|
if (reactions[i].key === rE.getRelation().key) return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (alreadyHaveThisReaction(rEvent)) {
|
||||||
|
for (let i = 0; i < reactions.length; i += 1) {
|
||||||
|
if (reactions[i].key === rEvent.getRelation().key) {
|
||||||
|
reactions[i].users.push(rEvent.getSender());
|
||||||
|
if (reactions[i].isActive !== true) {
|
||||||
|
const myUserId = initMatrix.matrixClient.getUserId();
|
||||||
|
reactions[i].isActive = rEvent.getSender() === myUserId;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
reactions.push({
|
||||||
|
id: rEvent.getId(),
|
||||||
|
key: rEvent.getRelation().key,
|
||||||
|
users: [rEvent.getSender()],
|
||||||
|
isActive: (rEvent.getSender() === initMatrix.matrixClient.getUserId()),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const senderMXIDColor = colorMXID(mEvent.sender.userId);
|
||||||
|
const userAvatar = isContentOnly ? null : (
|
||||||
|
<Avatar
|
||||||
|
imageSrc={mEvent.sender.getAvatarUrl(initMatrix.matrixClient.baseUrl, 36, 36, 'crop')}
|
||||||
|
text={getUsername(mEvent.sender.userId).slice(0, 1)}
|
||||||
|
bgColor={senderMXIDColor}
|
||||||
|
size="small"
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
const userHeader = isContentOnly ? null : (
|
||||||
|
<MessageHeader
|
||||||
|
userId={mEvent.sender.userId}
|
||||||
|
name={getUsername(mEvent.sender.userId)}
|
||||||
|
color={senderMXIDColor}
|
||||||
|
time={`${dateFormat(mEvent.getDate(), 'hh:MM TT')}`}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
const userReply = reply === null ? null : (
|
||||||
|
<MessageReply
|
||||||
|
userId={reply.userId}
|
||||||
|
name={reply.to}
|
||||||
|
color={reply.color}
|
||||||
|
content={reply.content}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
const userContent = (
|
||||||
|
<MessageContent
|
||||||
|
isMarkdown={isMarkdown}
|
||||||
|
content={isMedia(mEvent) ? genMediaContent(mEvent) : content}
|
||||||
|
isEdited={isEdited}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
const userReactions = reactions === null ? null : (
|
||||||
|
<MessageReactionGroup>
|
||||||
|
{
|
||||||
|
reactions.map((reaction) => (
|
||||||
|
<MessageReaction
|
||||||
|
key={reaction.id}
|
||||||
|
reaction={reaction.key}
|
||||||
|
users={reaction.users}
|
||||||
|
isActive={reaction.isActive}
|
||||||
|
onClick={() => alert('Sending reactions is yet to be implemented.')}
|
||||||
|
/>
|
||||||
|
))
|
||||||
|
}
|
||||||
|
</MessageReactionGroup>
|
||||||
|
);
|
||||||
|
const userOptions = (
|
||||||
|
<MessageOptions>
|
||||||
|
<IconButton
|
||||||
|
onClick={() => {
|
||||||
|
viewEvent.emit('reply_to', mEvent.getSender(), mEvent.getId(), isMedia(mEvent) ? mEvent.getContent().body : content);
|
||||||
|
}}
|
||||||
|
src={ReplyArrowIC}
|
||||||
|
size="extra-small"
|
||||||
|
tooltip="Reply"
|
||||||
|
/>
|
||||||
|
{(canIRedact || mEvent.getSender() === mx.getUserId()) && (
|
||||||
|
<IconButton
|
||||||
|
onClick={() => {
|
||||||
|
if (window.confirm('Are you sure you want to delete this event')) {
|
||||||
|
redact(roomId, mEvent.getId());
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
src={BinIC}
|
||||||
|
size="extra-small"
|
||||||
|
tooltip="Delete"
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</MessageOptions>
|
||||||
|
);
|
||||||
|
|
||||||
|
const myMessageEl = (
|
||||||
|
<Message
|
||||||
|
key={mEvent.getId()}
|
||||||
|
avatar={userAvatar}
|
||||||
|
header={userHeader}
|
||||||
|
reply={userReply}
|
||||||
|
content={userContent}
|
||||||
|
reactions={userReactions}
|
||||||
|
options={userOptions}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
|
||||||
|
prevMEvent = mEvent;
|
||||||
|
return myMessageEl;
|
||||||
|
}
|
||||||
|
prevMEvent = mEvent;
|
||||||
|
const timelineChange = parseTimelineChange(mEvent);
|
||||||
|
if (timelineChange === null) return null;
|
||||||
|
return (
|
||||||
|
<React.Fragment key={`box-${mEvent.getId()}`}>
|
||||||
|
{divider}
|
||||||
|
<TimelineChange
|
||||||
|
key={mEvent.getId()}
|
||||||
|
variant={timelineChange.variant}
|
||||||
|
content={timelineChange.content}
|
||||||
|
time={`${dateFormat(mEvent.getDate(), 'hh:MM TT')}`}
|
||||||
|
/>
|
||||||
|
</React.Fragment>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const roomTopic = roomTimeline.room.currentState.getStateEvents('m.room.topic')[0]?.getContent().topic;
|
||||||
|
return (
|
||||||
|
<div className="channel-view__content">
|
||||||
|
<div className="timeline__wrapper">
|
||||||
|
{
|
||||||
|
roomTimeline.timeline[0].getType() !== 'm.room.create' && !isReachedTimelineEnd && (
|
||||||
|
<>
|
||||||
|
<PlaceholderMessage key={Math.random().toString(20).substr(2, 6)} />
|
||||||
|
<PlaceholderMessage key={Math.random().toString(20).substr(2, 6)} />
|
||||||
|
<PlaceholderMessage key={Math.random().toString(20).substr(2, 6)} />
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
{
|
||||||
|
roomTimeline.timeline[0].getType() !== 'm.room.create' && isReachedTimelineEnd && (
|
||||||
|
<ChannelIntro
|
||||||
|
key={Math.random().toString(20).substr(2, 6)}
|
||||||
|
avatarSrc={roomTimeline.room.getAvatarUrl(initMatrix.matrixClient.baseUrl, 80, 80, 'crop')}
|
||||||
|
name={roomTimeline.room.name}
|
||||||
|
heading={`Welcome to ${roomTimeline.room.name}`}
|
||||||
|
desc={`This is the beginning of ${roomTimeline.room.name} channel.${typeof roomTopic !== 'undefined' ? (` Topic: ${roomTopic}`) : ''}`}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
{ roomTimeline.timeline.map(renderMessage) }
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
ChannelViewContent.propTypes = {
|
||||||
|
roomId: PropTypes.string.isRequired,
|
||||||
|
roomTimeline: PropTypes.shape({}).isRequired,
|
||||||
|
timelineScroll: PropTypes.shape({
|
||||||
|
reachBottom: PropTypes.func,
|
||||||
|
autoReachBottom: PropTypes.func,
|
||||||
|
tryRestoringScroll: PropTypes.func,
|
||||||
|
enableSmoothScroll: PropTypes.func,
|
||||||
|
disableSmoothScroll: PropTypes.func,
|
||||||
|
isScrollable: PropTypes.func,
|
||||||
|
}).isRequired,
|
||||||
|
viewEvent: PropTypes.shape({}).isRequired,
|
||||||
|
};
|
||||||
|
|
||||||
|
export default ChannelViewContent;
|
||||||
13
src/app/organisms/channel/ChannelViewContent.scss
Normal file
13
src/app/organisms/channel/ChannelViewContent.scss
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
.channel-view__content {
|
||||||
|
min-height: 100%;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
justify-content: flex-end;
|
||||||
|
|
||||||
|
& .timeline__wrapper {
|
||||||
|
--typing-noti-height: 28px;
|
||||||
|
min-height: 0;
|
||||||
|
min-width: 0;
|
||||||
|
padding-bottom: var(--typing-noti-height);
|
||||||
|
}
|
||||||
|
}
|
||||||
83
src/app/organisms/channel/ChannelViewFloating.jsx
Normal file
83
src/app/organisms/channel/ChannelViewFloating.jsx
Normal file
@@ -0,0 +1,83 @@
|
|||||||
|
/* eslint-disable react/prop-types */
|
||||||
|
import React, { useState, useEffect } from 'react';
|
||||||
|
import PropTypes from 'prop-types';
|
||||||
|
import './ChannelViewFloating.scss';
|
||||||
|
|
||||||
|
import initMatrix from '../../../client/initMatrix';
|
||||||
|
import cons from '../../../client/state/cons';
|
||||||
|
|
||||||
|
import Text from '../../atoms/text/Text';
|
||||||
|
import IconButton from '../../atoms/button/IconButton';
|
||||||
|
|
||||||
|
import ChevronBottomIC from '../../../../public/res/ic/outlined/chevron-bottom.svg';
|
||||||
|
|
||||||
|
import { getUsersActionJsx } from './common';
|
||||||
|
|
||||||
|
function ChannelViewFloating({
|
||||||
|
roomId, roomTimeline, timelineScroll, viewEvent,
|
||||||
|
}) {
|
||||||
|
const [reachedBottom, setReachedBottom] = useState(true);
|
||||||
|
const [typingMembers, setTypingMembers] = useState(new Set());
|
||||||
|
const mx = initMatrix.matrixClient;
|
||||||
|
|
||||||
|
function isSomeoneTyping(members) {
|
||||||
|
const m = members;
|
||||||
|
m.delete(mx.getUserId());
|
||||||
|
if (m.size === 0) return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getTypingMessage(members) {
|
||||||
|
const userIds = members;
|
||||||
|
userIds.delete(mx.getUserId());
|
||||||
|
return getUsersActionJsx([...userIds], 'typing...');
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateTyping(members) {
|
||||||
|
setTypingMembers(members);
|
||||||
|
}
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
setReachedBottom(true);
|
||||||
|
setTypingMembers(new Set());
|
||||||
|
viewEvent.on('toggle-reached-bottom', setReachedBottom);
|
||||||
|
return () => viewEvent.removeListener('toggle-reached-bottom', setReachedBottom);
|
||||||
|
}, [roomId]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
roomTimeline.on(cons.events.roomTimeline.TYPING_MEMBERS_UPDATED, updateTyping);
|
||||||
|
return () => {
|
||||||
|
roomTimeline?.removeListener(cons.events.roomTimeline.TYPING_MEMBERS_UPDATED, updateTyping);
|
||||||
|
};
|
||||||
|
}, [roomTimeline]);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<div className={`channel-view__typing${isSomeoneTyping(typingMembers) ? ' channel-view__typing--open' : ''}`}>
|
||||||
|
<div className="bouncingLoader"><div /></div>
|
||||||
|
<Text variant="b2">{getTypingMessage(typingMembers)}</Text>
|
||||||
|
</div>
|
||||||
|
<div className={`channel-view__STB${reachedBottom ? '' : ' channel-view__STB--open'}`}>
|
||||||
|
<IconButton
|
||||||
|
onClick={() => {
|
||||||
|
timelineScroll.enableSmoothScroll();
|
||||||
|
timelineScroll.reachBottom();
|
||||||
|
timelineScroll.disableSmoothScroll();
|
||||||
|
}}
|
||||||
|
src={ChevronBottomIC}
|
||||||
|
tooltip="Scroll to Bottom"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
ChannelViewFloating.propTypes = {
|
||||||
|
roomId: PropTypes.string.isRequired,
|
||||||
|
roomTimeline: PropTypes.shape({}).isRequired,
|
||||||
|
timelineScroll: PropTypes.shape({
|
||||||
|
reachBottom: PropTypes.func,
|
||||||
|
}).isRequired,
|
||||||
|
viewEvent: PropTypes.shape({}).isRequired,
|
||||||
|
};
|
||||||
|
|
||||||
|
export default ChannelViewFloating;
|
||||||
84
src/app/organisms/channel/ChannelViewFloating.scss
Normal file
84
src/app/organisms/channel/ChannelViewFloating.scss
Normal file
@@ -0,0 +1,84 @@
|
|||||||
|
.channel-view {
|
||||||
|
&__typing {
|
||||||
|
display: flex;
|
||||||
|
padding: var(--sp-ultra-tight) var(--sp-normal);
|
||||||
|
background: var(--bg-surface);
|
||||||
|
transition: transform 200ms ease-in-out;
|
||||||
|
|
||||||
|
& b {
|
||||||
|
color: var(--tc-surface-high);
|
||||||
|
}
|
||||||
|
|
||||||
|
&--open {
|
||||||
|
transform: translateY(-99%);
|
||||||
|
}
|
||||||
|
|
||||||
|
& .text {
|
||||||
|
flex: 1;
|
||||||
|
min-width: 0;
|
||||||
|
|
||||||
|
overflow: hidden;
|
||||||
|
white-space: nowrap;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
margin: 0 var(--sp-tight);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.bouncingLoader {
|
||||||
|
transform: translateY(2px);
|
||||||
|
margin: 0 calc(var(--sp-ultra-tight) / 2);
|
||||||
|
}
|
||||||
|
.bouncingLoader > div,
|
||||||
|
.bouncingLoader:before,
|
||||||
|
.bouncingLoader:after {
|
||||||
|
display: inline-block;
|
||||||
|
width: 8px;
|
||||||
|
height: 8px;
|
||||||
|
background: var(--tc-surface-high);
|
||||||
|
border-radius: 50%;
|
||||||
|
animation: bouncing-loader 0.6s infinite alternate;
|
||||||
|
}
|
||||||
|
|
||||||
|
.bouncingLoader:before,
|
||||||
|
.bouncingLoader:after {
|
||||||
|
content: "";
|
||||||
|
}
|
||||||
|
|
||||||
|
.bouncingLoader > div {
|
||||||
|
margin: 0 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.bouncingLoader > div {
|
||||||
|
animation-delay: 0.2s;
|
||||||
|
}
|
||||||
|
|
||||||
|
.bouncingLoader:after {
|
||||||
|
animation-delay: 0.4s;
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes bouncing-loader {
|
||||||
|
to {
|
||||||
|
opacity: 0.1;
|
||||||
|
transform: translate3d(0, -4px, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
&__STB {
|
||||||
|
position: absolute;
|
||||||
|
right: var(--sp-normal);
|
||||||
|
bottom: 0;
|
||||||
|
border-radius: var(--bo-radius);
|
||||||
|
box-shadow: var(--bs-surface-border);
|
||||||
|
background-color: var(--bg-surface-low);
|
||||||
|
transition: transform 200ms ease-in-out;
|
||||||
|
transform: translateY(100%) scale(0);
|
||||||
|
[dir=rtl] & {
|
||||||
|
right: unset;
|
||||||
|
left: var(--sp-normal);
|
||||||
|
}
|
||||||
|
|
||||||
|
&--open {
|
||||||
|
transform: translateY(-28px) scale(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
60
src/app/organisms/channel/ChannelViewHeader.jsx
Normal file
60
src/app/organisms/channel/ChannelViewHeader.jsx
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import PropTypes from 'prop-types';
|
||||||
|
|
||||||
|
import initMatrix from '../../../client/initMatrix';
|
||||||
|
import { togglePeopleDrawer, openInviteUser } from '../../../client/action/navigation';
|
||||||
|
import * as roomActions from '../../../client/action/room';
|
||||||
|
import colorMXID from '../../../util/colorMXID';
|
||||||
|
|
||||||
|
import Text from '../../atoms/text/Text';
|
||||||
|
import IconButton from '../../atoms/button/IconButton';
|
||||||
|
import Header, { TitleWrapper } from '../../atoms/header/Header';
|
||||||
|
import Avatar from '../../atoms/avatar/Avatar';
|
||||||
|
import ContextMenu, { MenuItem, MenuHeader } from '../../atoms/context-menu/ContextMenu';
|
||||||
|
|
||||||
|
import UserIC from '../../../../public/res/ic/outlined/user.svg';
|
||||||
|
import VerticalMenuIC from '../../../../public/res/ic/outlined/vertical-menu.svg';
|
||||||
|
import LeaveArrowIC from '../../../../public/res/ic/outlined/leave-arrow.svg';
|
||||||
|
import AddUserIC from '../../../../public/res/ic/outlined/add-user.svg';
|
||||||
|
|
||||||
|
function ChannelViewHeader({ roomId }) {
|
||||||
|
const mx = initMatrix.matrixClient;
|
||||||
|
const avatarSrc = mx.getRoom(roomId).getAvatarUrl(mx.baseUrl, 36, 36, 'crop');
|
||||||
|
const roomName = mx.getRoom(roomId).name;
|
||||||
|
const roomTopic = mx.getRoom(roomId).currentState.getStateEvents('m.room.topic')[0]?.getContent().topic;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Header>
|
||||||
|
<Avatar imageSrc={avatarSrc} text={roomName.slice(0, 1)} bgColor={colorMXID(roomName)} size="small" />
|
||||||
|
<TitleWrapper>
|
||||||
|
<Text variant="h2">{roomName}</Text>
|
||||||
|
{ typeof roomTopic !== 'undefined' && <p title={roomTopic} className="text text-b3">{roomTopic}</p>}
|
||||||
|
</TitleWrapper>
|
||||||
|
<IconButton onClick={togglePeopleDrawer} tooltip="People" src={UserIC} />
|
||||||
|
<ContextMenu
|
||||||
|
placement="bottom"
|
||||||
|
content={(toogleMenu) => (
|
||||||
|
<>
|
||||||
|
<MenuHeader>Options</MenuHeader>
|
||||||
|
{/* <MenuBorder /> */}
|
||||||
|
<MenuItem
|
||||||
|
iconSrc={AddUserIC}
|
||||||
|
onClick={() => {
|
||||||
|
openInviteUser(roomId); toogleMenu();
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Invite
|
||||||
|
</MenuItem>
|
||||||
|
<MenuItem iconSrc={LeaveArrowIC} variant="danger" onClick={() => roomActions.leave(roomId)}>Leave</MenuItem>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
render={(toggleMenu) => <IconButton onClick={toggleMenu} tooltip="Options" src={VerticalMenuIC} />}
|
||||||
|
/>
|
||||||
|
</Header>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
ChannelViewHeader.propTypes = {
|
||||||
|
roomId: PropTypes.string.isRequired,
|
||||||
|
};
|
||||||
|
|
||||||
|
export default ChannelViewHeader;
|
||||||
382
src/app/organisms/channel/ChannelViewInput.jsx
Normal file
382
src/app/organisms/channel/ChannelViewInput.jsx
Normal file
@@ -0,0 +1,382 @@
|
|||||||
|
/* eslint-disable react/prop-types */
|
||||||
|
import React, { useState, useEffect, useRef } from 'react';
|
||||||
|
import PropTypes from 'prop-types';
|
||||||
|
import './ChannelViewInput.scss';
|
||||||
|
|
||||||
|
import TextareaAutosize from 'react-autosize-textarea';
|
||||||
|
|
||||||
|
import initMatrix from '../../../client/initMatrix';
|
||||||
|
import cons from '../../../client/state/cons';
|
||||||
|
import settings from '../../../client/state/settings';
|
||||||
|
import { bytesToSize } from '../../../util/common';
|
||||||
|
import { getUsername } from '../../../util/matrixUtil';
|
||||||
|
import colorMXID from '../../../util/colorMXID';
|
||||||
|
|
||||||
|
import Text from '../../atoms/text/Text';
|
||||||
|
import RawIcon from '../../atoms/system-icons/RawIcon';
|
||||||
|
import IconButton from '../../atoms/button/IconButton';
|
||||||
|
import ContextMenu from '../../atoms/context-menu/ContextMenu';
|
||||||
|
import ScrollView from '../../atoms/scroll/ScrollView';
|
||||||
|
import { MessageReply } from '../../molecules/message/Message';
|
||||||
|
import EmojiBoard from '../emoji-board/EmojiBoard';
|
||||||
|
|
||||||
|
import CirclePlusIC from '../../../../public/res/ic/outlined/circle-plus.svg';
|
||||||
|
import EmojiIC from '../../../../public/res/ic/outlined/emoji.svg';
|
||||||
|
import SendIC from '../../../../public/res/ic/outlined/send.svg';
|
||||||
|
import ShieldIC from '../../../../public/res/ic/outlined/shield.svg';
|
||||||
|
import VLCIC from '../../../../public/res/ic/outlined/vlc.svg';
|
||||||
|
import VolumeFullIC from '../../../../public/res/ic/outlined/volume-full.svg';
|
||||||
|
import MarkdownIC from '../../../../public/res/ic/outlined/markdown.svg';
|
||||||
|
import FileIC from '../../../../public/res/ic/outlined/file.svg';
|
||||||
|
import CrossIC from '../../../../public/res/ic/outlined/cross.svg';
|
||||||
|
|
||||||
|
const CMD_REGEX = /(\/|>[#*@]|:)(\S*)$/;
|
||||||
|
let isTyping = false;
|
||||||
|
let isCmdActivated = false;
|
||||||
|
let cmdCursorPos = null;
|
||||||
|
function ChannelViewInput({
|
||||||
|
roomId, roomTimeline, timelineScroll, viewEvent,
|
||||||
|
}) {
|
||||||
|
const [attachment, setAttachment] = useState(null);
|
||||||
|
const [isMarkdown, setIsMarkdown] = useState(settings.isMarkdown);
|
||||||
|
const [replyTo, setReplyTo] = useState(null);
|
||||||
|
|
||||||
|
const textAreaRef = useRef(null);
|
||||||
|
const inputBaseRef = useRef(null);
|
||||||
|
const uploadInputRef = useRef(null);
|
||||||
|
const uploadProgressRef = useRef(null);
|
||||||
|
const rightOptionsRef = useRef(null);
|
||||||
|
|
||||||
|
const TYPING_TIMEOUT = 5000;
|
||||||
|
const mx = initMatrix.matrixClient;
|
||||||
|
const { roomsInput } = initMatrix;
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
settings.on(cons.events.settings.MARKDOWN_TOGGLED, setIsMarkdown);
|
||||||
|
return () => {
|
||||||
|
settings.removeListener(cons.events.settings.MARKDOWN_TOGGLED, setIsMarkdown);
|
||||||
|
};
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const sendIsTyping = (isT) => {
|
||||||
|
mx.sendTyping(roomId, isT, isT ? TYPING_TIMEOUT : undefined);
|
||||||
|
isTyping = isT;
|
||||||
|
|
||||||
|
if (isT === true) {
|
||||||
|
setTimeout(() => {
|
||||||
|
if (isTyping) sendIsTyping(false);
|
||||||
|
}, TYPING_TIMEOUT);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
function uploadingProgress(myRoomId, { loaded, total }) {
|
||||||
|
if (myRoomId !== roomId) return;
|
||||||
|
const progressPer = Math.round((loaded * 100) / total);
|
||||||
|
uploadProgressRef.current.textContent = `Uploading: ${bytesToSize(loaded)}/${bytesToSize(total)} (${progressPer}%)`;
|
||||||
|
inputBaseRef.current.style.backgroundImage = `linear-gradient(90deg, var(--bg-surface-hover) ${progressPer}%, var(--bg-surface-low) ${progressPer}%)`;
|
||||||
|
}
|
||||||
|
function clearAttachment(myRoomId) {
|
||||||
|
if (roomId !== myRoomId) return;
|
||||||
|
setAttachment(null);
|
||||||
|
inputBaseRef.current.style.backgroundImage = 'unset';
|
||||||
|
uploadInputRef.current.value = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
function rightOptionsA11Y(A11Y) {
|
||||||
|
const rightOptions = rightOptionsRef.current.children;
|
||||||
|
for (let index = 0; index < rightOptions.length; index += 1) {
|
||||||
|
rightOptions[index].disabled = !A11Y;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function activateCmd(prefix) {
|
||||||
|
isCmdActivated = true;
|
||||||
|
inputBaseRef.current.style.boxShadow = '0 0 0 1px var(--bg-positive)';
|
||||||
|
rightOptionsA11Y(false);
|
||||||
|
viewEvent.emit('cmd_activate', prefix);
|
||||||
|
}
|
||||||
|
function deactivateCmd() {
|
||||||
|
if (inputBaseRef.current !== null) {
|
||||||
|
inputBaseRef.current.style.boxShadow = 'var(--bs-surface-border)';
|
||||||
|
rightOptionsA11Y(true);
|
||||||
|
}
|
||||||
|
isCmdActivated = false;
|
||||||
|
cmdCursorPos = null;
|
||||||
|
}
|
||||||
|
function errorCmd() {
|
||||||
|
inputBaseRef.current.style.boxShadow = '0 0 0 1px var(--bg-danger)';
|
||||||
|
}
|
||||||
|
function setCursorPosition(pos) {
|
||||||
|
setTimeout(() => {
|
||||||
|
textAreaRef.current.focus();
|
||||||
|
textAreaRef.current.setSelectionRange(pos, pos);
|
||||||
|
}, 0);
|
||||||
|
}
|
||||||
|
function replaceCmdWith(msg, cursor, replacement) {
|
||||||
|
if (msg === null) return null;
|
||||||
|
const targetInput = msg.slice(0, cursor);
|
||||||
|
const cmdParts = targetInput.match(CMD_REGEX);
|
||||||
|
const leadingInput = msg.slice(0, cmdParts.index);
|
||||||
|
if (replacement.length > 0) setCursorPosition(leadingInput.length + replacement.length);
|
||||||
|
return leadingInput + replacement + msg.slice(cursor);
|
||||||
|
}
|
||||||
|
function firedCmd(cmdData) {
|
||||||
|
const msg = textAreaRef.current.value;
|
||||||
|
textAreaRef.current.value = replaceCmdWith(
|
||||||
|
msg, cmdCursorPos, typeof cmdData?.replace !== 'undefined' ? cmdData.replace : '',
|
||||||
|
);
|
||||||
|
deactivateCmd();
|
||||||
|
}
|
||||||
|
|
||||||
|
function setUpReply(userId, eventId, content) {
|
||||||
|
setReplyTo({ userId, eventId, content });
|
||||||
|
roomsInput.setReplyTo(roomId, { userId, eventId, content });
|
||||||
|
}
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
roomsInput.on(cons.events.roomsInput.UPLOAD_PROGRESS_CHANGES, uploadingProgress);
|
||||||
|
roomsInput.on(cons.events.roomsInput.ATTACHMENT_CANCELED, clearAttachment);
|
||||||
|
roomsInput.on(cons.events.roomsInput.FILE_UPLOADED, clearAttachment);
|
||||||
|
viewEvent.on('cmd_error', errorCmd);
|
||||||
|
viewEvent.on('cmd_fired', firedCmd);
|
||||||
|
viewEvent.on('reply_to', setUpReply);
|
||||||
|
if (textAreaRef?.current !== null) {
|
||||||
|
isTyping = false;
|
||||||
|
textAreaRef.current.focus();
|
||||||
|
textAreaRef.current.value = roomsInput.getMessage(roomId);
|
||||||
|
setAttachment(roomsInput.getAttachment(roomId));
|
||||||
|
setReplyTo(roomsInput.getReplyTo(roomId));
|
||||||
|
}
|
||||||
|
return () => {
|
||||||
|
roomsInput.removeListener(cons.events.roomsInput.UPLOAD_PROGRESS_CHANGES, uploadingProgress);
|
||||||
|
roomsInput.removeListener(cons.events.roomsInput.ATTACHMENT_CANCELED, clearAttachment);
|
||||||
|
roomsInput.removeListener(cons.events.roomsInput.FILE_UPLOADED, clearAttachment);
|
||||||
|
viewEvent.removeListener('cmd_error', errorCmd);
|
||||||
|
viewEvent.removeListener('cmd_fired', firedCmd);
|
||||||
|
viewEvent.removeListener('reply_to', setUpReply);
|
||||||
|
if (isCmdActivated) deactivateCmd();
|
||||||
|
if (textAreaRef?.current === null) return;
|
||||||
|
|
||||||
|
const msg = textAreaRef.current.value;
|
||||||
|
inputBaseRef.current.style.backgroundImage = 'unset';
|
||||||
|
if (msg.trim() === '') {
|
||||||
|
roomsInput.setMessage(roomId, '');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
roomsInput.setMessage(roomId, msg);
|
||||||
|
};
|
||||||
|
}, [roomId]);
|
||||||
|
|
||||||
|
async function sendMessage() {
|
||||||
|
if (isCmdActivated) {
|
||||||
|
viewEvent.emit('cmd_exe');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const msgBody = textAreaRef.current.value;
|
||||||
|
if (roomsInput.isSending(roomId)) return;
|
||||||
|
if (msgBody.trim() === '' && attachment === null) return;
|
||||||
|
sendIsTyping(false);
|
||||||
|
|
||||||
|
roomsInput.setMessage(roomId, msgBody);
|
||||||
|
if (attachment !== null) {
|
||||||
|
roomsInput.setAttachment(roomId, attachment);
|
||||||
|
}
|
||||||
|
textAreaRef.current.disabled = true;
|
||||||
|
textAreaRef.current.style.cursor = 'not-allowed';
|
||||||
|
await roomsInput.sendInput(roomId);
|
||||||
|
textAreaRef.current.disabled = false;
|
||||||
|
textAreaRef.current.style.cursor = 'unset';
|
||||||
|
textAreaRef.current.focus();
|
||||||
|
|
||||||
|
textAreaRef.current.value = roomsInput.getMessage(roomId);
|
||||||
|
timelineScroll.reachBottom();
|
||||||
|
viewEvent.emit('message_sent');
|
||||||
|
textAreaRef.current.style.height = 'unset';
|
||||||
|
if (replyTo !== null) setReplyTo(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
function processTyping(msg) {
|
||||||
|
const isEmptyMsg = msg === '';
|
||||||
|
|
||||||
|
if (isEmptyMsg && isTyping) {
|
||||||
|
sendIsTyping(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!isEmptyMsg && !isTyping) {
|
||||||
|
sendIsTyping(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function getCursorPosition() {
|
||||||
|
return textAreaRef.current.selectionStart;
|
||||||
|
}
|
||||||
|
|
||||||
|
function recognizeCmd(rawInput) {
|
||||||
|
const cursor = getCursorPosition();
|
||||||
|
const targetInput = rawInput.slice(0, cursor);
|
||||||
|
|
||||||
|
const cmdParts = targetInput.match(CMD_REGEX);
|
||||||
|
if (cmdParts === null) {
|
||||||
|
if (isCmdActivated) {
|
||||||
|
deactivateCmd();
|
||||||
|
viewEvent.emit('cmd_deactivate');
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const cmdPrefix = cmdParts[1];
|
||||||
|
const cmdSlug = cmdParts[2];
|
||||||
|
|
||||||
|
if (cmdPrefix === ':') {
|
||||||
|
// skip emoji autofill command if link is suspected.
|
||||||
|
const checkForLink = targetInput.slice(0, cmdParts.index);
|
||||||
|
if (checkForLink.match(/(http|https|mailto|matrix|ircs|irc)$/)) {
|
||||||
|
deactivateCmd();
|
||||||
|
viewEvent.emit('cmd_deactivate');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
cmdCursorPos = cursor;
|
||||||
|
if (cmdSlug === '') {
|
||||||
|
activateCmd(cmdPrefix);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!isCmdActivated) activateCmd(cmdPrefix);
|
||||||
|
inputBaseRef.current.style.boxShadow = '0 0 0 1px var(--bg-caution)';
|
||||||
|
viewEvent.emit('cmd_process', cmdPrefix, cmdSlug);
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleMsgTyping(e) {
|
||||||
|
const msg = e.target.value;
|
||||||
|
recognizeCmd(e.target.value);
|
||||||
|
if (!isCmdActivated) processTyping(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleKeyDown(e) {
|
||||||
|
if (e.keyCode === 13 && e.shiftKey === false) {
|
||||||
|
e.preventDefault();
|
||||||
|
sendMessage();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function addEmoji(emoji) {
|
||||||
|
textAreaRef.current.value += emoji.unicode;
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleUploadClick() {
|
||||||
|
if (attachment === null) uploadInputRef.current.click();
|
||||||
|
else {
|
||||||
|
roomsInput.cancelAttachment(roomId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function uploadFileChange(e) {
|
||||||
|
const file = e.target.files.item(0);
|
||||||
|
setAttachment(file);
|
||||||
|
if (file !== null) roomsInput.setAttachment(roomId, file);
|
||||||
|
}
|
||||||
|
|
||||||
|
function renderInputs() {
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<div className={`channel-input__option-container${attachment === null ? '' : ' channel-attachment__option'}`}>
|
||||||
|
<input onChange={uploadFileChange} style={{ display: 'none' }} ref={uploadInputRef} type="file" />
|
||||||
|
<IconButton onClick={handleUploadClick} tooltip={attachment === null ? 'Upload' : 'Cancel'} src={CirclePlusIC} />
|
||||||
|
</div>
|
||||||
|
<div ref={inputBaseRef} className="channel-input__input-container">
|
||||||
|
{roomTimeline.isEncryptedRoom() && <RawIcon size="extra-small" src={ShieldIC} />}
|
||||||
|
<ScrollView autoHide>
|
||||||
|
<Text className="channel-input__textarea-wrapper">
|
||||||
|
<TextareaAutosize
|
||||||
|
ref={textAreaRef}
|
||||||
|
onChange={handleMsgTyping}
|
||||||
|
onResize={() => timelineScroll.autoReachBottom()}
|
||||||
|
onKeyDown={handleKeyDown}
|
||||||
|
placeholder="Send a message..."
|
||||||
|
/>
|
||||||
|
</Text>
|
||||||
|
</ScrollView>
|
||||||
|
{isMarkdown && <RawIcon size="extra-small" src={MarkdownIC} />}
|
||||||
|
</div>
|
||||||
|
<div ref={rightOptionsRef} className="channel-input__option-container">
|
||||||
|
<ContextMenu
|
||||||
|
placement="top"
|
||||||
|
content={(
|
||||||
|
<EmojiBoard onSelect={addEmoji} />
|
||||||
|
)}
|
||||||
|
render={(toggleMenu) => <IconButton onClick={toggleMenu} tooltip="Emoji" src={EmojiIC} />}
|
||||||
|
/>
|
||||||
|
<IconButton onClick={sendMessage} tooltip="Send" src={SendIC} />
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function attachFile() {
|
||||||
|
const fileType = attachment.type.slice(0, attachment.type.indexOf('/'));
|
||||||
|
return (
|
||||||
|
<div className="channel-attachment">
|
||||||
|
<div className={`channel-attachment__preview${fileType !== 'image' ? ' channel-attachment__icon' : ''}`}>
|
||||||
|
{fileType === 'image' && <img alt={attachment.name} src={URL.createObjectURL(attachment)} />}
|
||||||
|
{fileType === 'video' && <RawIcon src={VLCIC} />}
|
||||||
|
{fileType === 'audio' && <RawIcon src={VolumeFullIC} />}
|
||||||
|
{fileType !== 'image' && fileType !== 'video' && fileType !== 'audio' && <RawIcon src={FileIC} />}
|
||||||
|
</div>
|
||||||
|
<div className="channel-attachment__info">
|
||||||
|
<Text variant="b1">{attachment.name}</Text>
|
||||||
|
<Text variant="b3"><span ref={uploadProgressRef}>{`size: ${bytesToSize(attachment.size)}`}</span></Text>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function attachReply() {
|
||||||
|
return (
|
||||||
|
<div className="channel-reply">
|
||||||
|
<IconButton
|
||||||
|
onClick={() => {
|
||||||
|
roomsInput.cancelReplyTo(roomId);
|
||||||
|
setReplyTo(null);
|
||||||
|
}}
|
||||||
|
src={CrossIC}
|
||||||
|
tooltip="Cancel reply"
|
||||||
|
size="extra-small"
|
||||||
|
/>
|
||||||
|
<MessageReply
|
||||||
|
userId={replyTo.userId}
|
||||||
|
name={getUsername(replyTo.userId)}
|
||||||
|
color={colorMXID(replyTo.userId)}
|
||||||
|
content={replyTo.content}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
{ replyTo !== null && attachReply()}
|
||||||
|
{ attachment !== null && attachFile() }
|
||||||
|
<form className="channel-input" onSubmit={(e) => { e.preventDefault(); }}>
|
||||||
|
{
|
||||||
|
roomTimeline.room.isSpaceRoom()
|
||||||
|
? <Text className="channel-input__space" variant="b1">Spaces are yet to be implemented</Text>
|
||||||
|
: renderInputs()
|
||||||
|
}
|
||||||
|
</form>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
ChannelViewInput.propTypes = {
|
||||||
|
roomId: PropTypes.string.isRequired,
|
||||||
|
roomTimeline: PropTypes.shape({}).isRequired,
|
||||||
|
timelineScroll: PropTypes.shape({
|
||||||
|
reachBottom: PropTypes.func,
|
||||||
|
autoReachBottom: PropTypes.func,
|
||||||
|
tryRestoringScroll: PropTypes.func,
|
||||||
|
enableSmoothScroll: PropTypes.func,
|
||||||
|
disableSmoothScroll: PropTypes.func,
|
||||||
|
}).isRequired,
|
||||||
|
viewEvent: PropTypes.shape({}).isRequired,
|
||||||
|
};
|
||||||
|
|
||||||
|
export default ChannelViewInput;
|
||||||
116
src/app/organisms/channel/ChannelViewInput.scss
Normal file
116
src/app/organisms/channel/ChannelViewInput.scss
Normal file
@@ -0,0 +1,116 @@
|
|||||||
|
.channel-input {
|
||||||
|
padding: var(--sp-extra-tight) calc(var(--sp-normal) - 2px);
|
||||||
|
display: flex;
|
||||||
|
min-height: 48px;
|
||||||
|
|
||||||
|
&__space {
|
||||||
|
min-width: 0;
|
||||||
|
align-self: center;
|
||||||
|
margin: auto;
|
||||||
|
padding: 0 var(--sp-tight);
|
||||||
|
}
|
||||||
|
|
||||||
|
&__input-container {
|
||||||
|
flex: 1;
|
||||||
|
min-width: 0;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
|
||||||
|
margin: 0 calc(var(--sp-tight) - 2px);
|
||||||
|
background-color: var(--bg-surface-low);
|
||||||
|
box-shadow: var(--bs-surface-border);
|
||||||
|
border-radius: var(--bo-radius);
|
||||||
|
|
||||||
|
& > .ic-raw {
|
||||||
|
transform: scale(0.8);
|
||||||
|
margin: 0 var(--sp-extra-tight);
|
||||||
|
}
|
||||||
|
& .scrollbar {
|
||||||
|
max-height: 50vh;
|
||||||
|
flex: 1;
|
||||||
|
|
||||||
|
&:first-child {
|
||||||
|
margin-left: var(--sp-tight);
|
||||||
|
[dir=rtl] & {
|
||||||
|
margin-left: 0;
|
||||||
|
margin-right: var(--sp-tight);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
&__textarea-wrapper {
|
||||||
|
min-height: 40px;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
|
||||||
|
& textarea {
|
||||||
|
resize: none;
|
||||||
|
width: 100%;
|
||||||
|
min-width: 0;
|
||||||
|
min-height: 100%;
|
||||||
|
padding: var(--sp-ultra-tight) 0;
|
||||||
|
|
||||||
|
&::placeholder {
|
||||||
|
color: var(--tc-surface-low);
|
||||||
|
}
|
||||||
|
&:focus {
|
||||||
|
outline: none;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.channel-attachment {
|
||||||
|
--side-spacing: calc(var(--sp-normal) + var(--av-small) + var(--sp-tight));
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
margin-left: var(--side-spacing);
|
||||||
|
margin-top: var(--sp-extra-tight);
|
||||||
|
line-height: 0;
|
||||||
|
[dir=rtl] & {
|
||||||
|
margin-left: 0;
|
||||||
|
margin-right: var(--side-spacing);
|
||||||
|
}
|
||||||
|
|
||||||
|
&__preview > img {
|
||||||
|
max-height: 40px;
|
||||||
|
border-radius: var(--bo-radius);
|
||||||
|
}
|
||||||
|
&__icon {
|
||||||
|
padding: var(--sp-extra-tight);
|
||||||
|
background-color: var(--bg-surface-low);
|
||||||
|
box-shadow: var(--bs-surface-border);
|
||||||
|
border-radius: var(--bo-radius);
|
||||||
|
}
|
||||||
|
&__info {
|
||||||
|
flex: 1;
|
||||||
|
min-width: 0;
|
||||||
|
margin: 0 var(--sp-tight);
|
||||||
|
}
|
||||||
|
|
||||||
|
&__option button {
|
||||||
|
transition: transform 200ms ease-in-out;
|
||||||
|
transform: translateY(-48px);
|
||||||
|
& .ic-raw {
|
||||||
|
transition: transform 200ms ease-in-out;
|
||||||
|
transform: rotate(45deg);
|
||||||
|
background-color: var(--bg-caution);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.channel-reply {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
background-color: var(--bg-surface-low);
|
||||||
|
border-bottom: 1px solid var(--bg-surface-border);
|
||||||
|
|
||||||
|
& .ic-btn-surface {
|
||||||
|
margin: 0 13px 0 17px;
|
||||||
|
border-radius: 0;
|
||||||
|
[dir=rtl] & {
|
||||||
|
margin: 0 17px 0 13px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
261
src/app/organisms/channel/common.jsx
Normal file
261
src/app/organisms/channel/common.jsx
Normal file
@@ -0,0 +1,261 @@
|
|||||||
|
import React from 'react';
|
||||||
|
|
||||||
|
import { getUsername } from '../../../util/matrixUtil';
|
||||||
|
|
||||||
|
function getTimelineJSXMessages() {
|
||||||
|
return {
|
||||||
|
join(user) {
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<b>{user}</b>
|
||||||
|
{' joined the channel'}
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
leave(user) {
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<b>{user}</b>
|
||||||
|
{' left the channel'}
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
invite(inviter, user) {
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<b>{inviter}</b>
|
||||||
|
{' invited '}
|
||||||
|
<b>{user}</b>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
cancelInvite(inviter, user) {
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<b>{inviter}</b>
|
||||||
|
{' canceled '}
|
||||||
|
<b>{user}</b>
|
||||||
|
{'\'s invite'}
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
rejectInvite(user) {
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<b>{user}</b>
|
||||||
|
{' rejected the invitation'}
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
kick(actor, user, reason) {
|
||||||
|
const reasonMsg = (typeof reason === 'string') ? ` for ${reason}` : '';
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<b>{actor}</b>
|
||||||
|
{' kicked '}
|
||||||
|
<b>{user}</b>
|
||||||
|
{reasonMsg}
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
ban(actor, user, reason) {
|
||||||
|
const reasonMsg = (typeof reason === 'string') ? ` for ${reason}` : '';
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<b>{actor}</b>
|
||||||
|
{' banned '}
|
||||||
|
<b>{user}</b>
|
||||||
|
{reasonMsg}
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
unban(actor, user) {
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<b>{actor}</b>
|
||||||
|
{' unbanned '}
|
||||||
|
<b>{user}</b>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
avatarSets(user) {
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<b>{user}</b>
|
||||||
|
{' set the avatar'}
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
avatarChanged(user) {
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<b>{user}</b>
|
||||||
|
{' changed the avatar'}
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
avatarRemoved(user) {
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<b>{user}</b>
|
||||||
|
{' removed the avatar'}
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
nameSets(user, newName) {
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<b>{user}</b>
|
||||||
|
{' set the display name to '}
|
||||||
|
<b>{newName}</b>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
nameChanged(user, newName) {
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<b>{user}</b>
|
||||||
|
{' changed the display name to '}
|
||||||
|
<b>{newName}</b>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
nameRemoved(user, lastName) {
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<b>{user}</b>
|
||||||
|
{' removed the display name '}
|
||||||
|
<b>{lastName}</b>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function getUsersActionJsx(userIds, actionStr) {
|
||||||
|
const getUserJSX = (username) => <b>{getUsername(username)}</b>;
|
||||||
|
if (!Array.isArray(userIds)) return 'Idle';
|
||||||
|
if (userIds.length === 0) return 'Idle';
|
||||||
|
const MAX_VISIBLE_COUNT = 3;
|
||||||
|
|
||||||
|
const u1Jsx = getUserJSX(userIds[0]);
|
||||||
|
// eslint-disable-next-line react/jsx-one-expression-per-line
|
||||||
|
if (userIds.length === 1) return <>{u1Jsx} is {actionStr}</>;
|
||||||
|
|
||||||
|
const u2Jsx = getUserJSX(userIds[1]);
|
||||||
|
// eslint-disable-next-line react/jsx-one-expression-per-line
|
||||||
|
if (userIds.length === 2) return <>{u1Jsx} and {u2Jsx} are {actionStr}</>;
|
||||||
|
|
||||||
|
const u3Jsx = getUserJSX(userIds[2]);
|
||||||
|
if (userIds.length === 3) {
|
||||||
|
// eslint-disable-next-line react/jsx-one-expression-per-line
|
||||||
|
return <>{u1Jsx}, {u2Jsx} and {u3Jsx} are {actionStr}</>;
|
||||||
|
}
|
||||||
|
|
||||||
|
const othersCount = userIds.length - MAX_VISIBLE_COUNT;
|
||||||
|
// eslint-disable-next-line react/jsx-one-expression-per-line
|
||||||
|
return <>{u1Jsx}, {u2Jsx}, {u3Jsx} and {othersCount} other are {actionStr}</>;
|
||||||
|
}
|
||||||
|
|
||||||
|
function parseReply(rawContent) {
|
||||||
|
if (rawContent.indexOf('>') !== 0) return null;
|
||||||
|
let content = rawContent.slice(rawContent.indexOf('@'));
|
||||||
|
const userId = content.slice(0, content.indexOf('>'));
|
||||||
|
|
||||||
|
content = content.slice(content.indexOf('>') + 2);
|
||||||
|
const replyContent = content.slice(0, content.indexOf('\n\n'));
|
||||||
|
content = content.slice(content.indexOf('\n\n') + 2);
|
||||||
|
|
||||||
|
if (userId === '') return null;
|
||||||
|
|
||||||
|
return {
|
||||||
|
userId,
|
||||||
|
replyContent,
|
||||||
|
content,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function parseTimelineChange(mEvent) {
|
||||||
|
const tJSXMsgs = getTimelineJSXMessages();
|
||||||
|
const makeReturnObj = (variant, content) => ({
|
||||||
|
variant,
|
||||||
|
content,
|
||||||
|
});
|
||||||
|
const content = mEvent.getContent();
|
||||||
|
const prevContent = mEvent.getPrevContent();
|
||||||
|
const sender = mEvent.getSender();
|
||||||
|
const senderName = getUsername(sender);
|
||||||
|
const userName = getUsername(mEvent.getStateKey());
|
||||||
|
|
||||||
|
switch (content.membership) {
|
||||||
|
case 'invite': return makeReturnObj('invite', tJSXMsgs.invite(senderName, userName));
|
||||||
|
case 'ban': return makeReturnObj('leave', tJSXMsgs.ban(senderName, userName, content.reason));
|
||||||
|
case 'join':
|
||||||
|
if (prevContent.membership === 'join') {
|
||||||
|
if (content.displayname !== prevContent.displayname) {
|
||||||
|
if (typeof content.displayname === 'undefined') return makeReturnObj('avatar', tJSXMsgs.nameRemoved(sender, prevContent.displayname));
|
||||||
|
if (typeof prevContent.displayname === 'undefined') return makeReturnObj('avatar', tJSXMsgs.nameSets(sender, content.displayname));
|
||||||
|
return makeReturnObj('avatar', tJSXMsgs.nameChanged(prevContent.displayname, content.displayname));
|
||||||
|
}
|
||||||
|
if (content.avatar_url !== prevContent.avatar_url) {
|
||||||
|
if (typeof content.avatar_url === 'undefined') return makeReturnObj('avatar', tJSXMsgs.avatarRemoved(content.displayname));
|
||||||
|
if (typeof prevContent.avatar_url === 'undefined') return makeReturnObj('avatar', tJSXMsgs.avatarSets(content.displayname));
|
||||||
|
return makeReturnObj('avatar', tJSXMsgs.avatarChanged(content.displayname));
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return makeReturnObj('join', tJSXMsgs.join(senderName));
|
||||||
|
case 'leave':
|
||||||
|
if (sender === mEvent.getStateKey()) {
|
||||||
|
switch (prevContent.membership) {
|
||||||
|
case 'invite': return makeReturnObj('invite-cancel', tJSXMsgs.rejectInvite(senderName));
|
||||||
|
default: return makeReturnObj('leave', tJSXMsgs.leave(senderName));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
switch (prevContent.membership) {
|
||||||
|
case 'invite': return makeReturnObj('invite-cancel', tJSXMsgs.cancelInvite(senderName, userName));
|
||||||
|
case 'ban': return makeReturnObj('other', tJSXMsgs.unban(senderName, userName));
|
||||||
|
// sender is not target and made the target leave,
|
||||||
|
// if not from invite/ban then this is a kick
|
||||||
|
default: return makeReturnObj('leave', tJSXMsgs.kick(senderName, userName, content.reason));
|
||||||
|
}
|
||||||
|
default: return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function scrollToBottom(ref) {
|
||||||
|
const maxScrollTop = ref.current.scrollHeight - ref.current.offsetHeight;
|
||||||
|
// eslint-disable-next-line no-param-reassign
|
||||||
|
ref.current.scrollTop = maxScrollTop;
|
||||||
|
}
|
||||||
|
|
||||||
|
function isAtBottom(ref) {
|
||||||
|
const { scrollHeight, scrollTop, offsetHeight } = ref.current;
|
||||||
|
const scrollUptoBottom = scrollTop + offsetHeight;
|
||||||
|
|
||||||
|
// scroll view have to div inside div which contains messages
|
||||||
|
const lastMessage = ref.current.lastElementChild.lastElementChild.lastElementChild;
|
||||||
|
const lastChildHeight = lastMessage.offsetHeight;
|
||||||
|
|
||||||
|
// auto scroll to bottom even if user has EXTRA_SPACE left to scroll
|
||||||
|
const EXTRA_SPACE = 48;
|
||||||
|
|
||||||
|
if (scrollHeight - scrollUptoBottom <= lastChildHeight + EXTRA_SPACE) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
function autoScrollToBottom(ref) {
|
||||||
|
if (isAtBottom(ref)) scrollToBottom(ref);
|
||||||
|
}
|
||||||
|
|
||||||
|
export {
|
||||||
|
getTimelineJSXMessages,
|
||||||
|
getUsersActionJsx,
|
||||||
|
parseReply,
|
||||||
|
parseTimelineChange,
|
||||||
|
scrollToBottom,
|
||||||
|
isAtBottom,
|
||||||
|
autoScrollToBottom,
|
||||||
|
};
|
||||||
@@ -88,7 +88,7 @@ function SearchedEmoji() {
|
|||||||
setSearchedEmojis([]);
|
setSearchedEmojis([]);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
setSearchedEmojis(searchEmoji(term));
|
setSearchedEmojis(searchEmoji(term).map((finding) => finding.item));
|
||||||
}
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ function searchEmoji(term) {
|
|||||||
|
|
||||||
let result = fuse.search(term);
|
let result = fuse.search(term);
|
||||||
if (result.length > 20) result = result.slice(0, 20);
|
if (result.length > 20) result = result.slice(0, 20);
|
||||||
return result.map((finding) => finding.item);
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
export {
|
export {
|
||||||
|
|||||||
@@ -18,7 +18,9 @@ import ChannelTile from '../../molecules/channel-tile/ChannelTile';
|
|||||||
import CrossIC from '../../../../public/res/ic/outlined/cross.svg';
|
import CrossIC from '../../../../public/res/ic/outlined/cross.svg';
|
||||||
import UserIC from '../../../../public/res/ic/outlined/user.svg';
|
import UserIC from '../../../../public/res/ic/outlined/user.svg';
|
||||||
|
|
||||||
function InviteUser({ isOpen, roomId, onRequestClose }) {
|
function InviteUser({
|
||||||
|
isOpen, roomId, searchTerm, onRequestClose,
|
||||||
|
}) {
|
||||||
const [isSearching, updateIsSearching] = useState(false);
|
const [isSearching, updateIsSearching] = useState(false);
|
||||||
const [searchQuery, updateSearchQuery] = useState({});
|
const [searchQuery, updateSearchQuery] = useState({});
|
||||||
const [users, updateUsers] = useState([]);
|
const [users, updateUsers] = useState([]);
|
||||||
@@ -63,26 +65,8 @@ function InviteUser({ isOpen, roomId, onRequestClose }) {
|
|||||||
updateRoomIdToUserId(getMapCopy(roomIdToUserId));
|
updateRoomIdToUserId(getMapCopy(roomIdToUserId));
|
||||||
}
|
}
|
||||||
|
|
||||||
useEffect(() => () => {
|
async function searchUser(username) {
|
||||||
updateIsSearching(false);
|
const inputUsername = username.trim();
|
||||||
updateSearchQuery({});
|
|
||||||
updateUsers([]);
|
|
||||||
updateProcUsers(new Set());
|
|
||||||
updateUserProcError(new Map());
|
|
||||||
updateCreatedDM(new Map());
|
|
||||||
updateRoomIdToUserId(new Map());
|
|
||||||
updateInvitedUserIds(new Set());
|
|
||||||
}, [isOpen]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
initMatrix.roomList.on(cons.events.roomList.ROOM_CREATED, onDMCreated);
|
|
||||||
return () => {
|
|
||||||
initMatrix.roomList.removeListener(cons.events.roomList.ROOM_CREATED, onDMCreated);
|
|
||||||
};
|
|
||||||
}, [isOpen, procUsers, createdDM, roomIdToUserId]);
|
|
||||||
|
|
||||||
async function searchUser() {
|
|
||||||
const inputUsername = usernameRef.current.value.trim();
|
|
||||||
if (isSearching || inputUsername === '' || inputUsername === searchQuery.username) return;
|
if (isSearching || inputUsername === '' || inputUsername === searchQuery.username) return;
|
||||||
const isInputUserId = inputUsername[0] === '@' && inputUsername.indexOf(':') > 1;
|
const isInputUserId = inputUsername[0] === '@' && inputUsername.indexOf(':') > 1;
|
||||||
updateIsSearching(true);
|
updateIsSearching(true);
|
||||||
@@ -216,6 +200,27 @@ function InviteUser({ isOpen, roomId, onRequestClose }) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (isOpen && typeof searchTerm === 'string') searchUser(searchTerm);
|
||||||
|
return () => {
|
||||||
|
updateIsSearching(false);
|
||||||
|
updateSearchQuery({});
|
||||||
|
updateUsers([]);
|
||||||
|
updateProcUsers(new Set());
|
||||||
|
updateUserProcError(new Map());
|
||||||
|
updateCreatedDM(new Map());
|
||||||
|
updateRoomIdToUserId(new Map());
|
||||||
|
updateInvitedUserIds(new Set());
|
||||||
|
};
|
||||||
|
}, [isOpen, searchTerm]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
initMatrix.roomList.on(cons.events.roomList.ROOM_CREATED, onDMCreated);
|
||||||
|
return () => {
|
||||||
|
initMatrix.roomList.removeListener(cons.events.roomList.ROOM_CREATED, onDMCreated);
|
||||||
|
};
|
||||||
|
}, [isOpen, procUsers, createdDM, roomIdToUserId]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<PopupWindow
|
<PopupWindow
|
||||||
isOpen={isOpen}
|
isOpen={isOpen}
|
||||||
@@ -224,8 +229,8 @@ function InviteUser({ isOpen, roomId, onRequestClose }) {
|
|||||||
onRequestClose={onRequestClose}
|
onRequestClose={onRequestClose}
|
||||||
>
|
>
|
||||||
<div className="invite-user">
|
<div className="invite-user">
|
||||||
<form className="invite-user__form" onSubmit={(e) => { e.preventDefault(); searchUser(); }}>
|
<form className="invite-user__form" onSubmit={(e) => { e.preventDefault(); searchUser(usernameRef.current.value); }}>
|
||||||
<Input forwardRef={usernameRef} label="Username or userId" />
|
<Input value={searchTerm} forwardRef={usernameRef} label="Username or userId" />
|
||||||
<Button disabled={isSearching} iconSrc={UserIC} variant="primary" type="submit">Search</Button>
|
<Button disabled={isSearching} iconSrc={UserIC} variant="primary" type="submit">Search</Button>
|
||||||
</form>
|
</form>
|
||||||
<div className="invite-user__search-status">
|
<div className="invite-user__search-status">
|
||||||
@@ -258,11 +263,13 @@ function InviteUser({ isOpen, roomId, onRequestClose }) {
|
|||||||
|
|
||||||
InviteUser.defaultProps = {
|
InviteUser.defaultProps = {
|
||||||
roomId: undefined,
|
roomId: undefined,
|
||||||
|
searchTerm: undefined,
|
||||||
};
|
};
|
||||||
|
|
||||||
InviteUser.propTypes = {
|
InviteUser.propTypes = {
|
||||||
isOpen: PropTypes.bool.isRequired,
|
isOpen: PropTypes.bool.isRequired,
|
||||||
roomId: PropTypes.string,
|
roomId: PropTypes.string,
|
||||||
|
searchTerm: PropTypes.string,
|
||||||
onRequestClose: PropTypes.func.isRequired,
|
onRequestClose: PropTypes.func.isRequired,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -20,7 +20,71 @@ import HashSearchIC from '../../../../public/res/ic/outlined/hash-search.svg';
|
|||||||
|
|
||||||
const SEARCH_LIMIT = 20;
|
const SEARCH_LIMIT = 20;
|
||||||
|
|
||||||
function PublicChannels({ isOpen, onRequestClose }) {
|
function TryJoinWithAlias({ alias, onRequestClose }) {
|
||||||
|
const [status, setStatus] = useState({
|
||||||
|
isJoining: false,
|
||||||
|
error: null,
|
||||||
|
roomId: null,
|
||||||
|
tempRoomId: null,
|
||||||
|
});
|
||||||
|
function handleOnRoomAdded(roomId) {
|
||||||
|
if (status.tempRoomId !== null && status.tempRoomId !== roomId) return;
|
||||||
|
setStatus({
|
||||||
|
isJoining: false, error: null, roomId, tempRoomId: null,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
initMatrix.roomList.on(cons.events.roomList.ROOM_JOINED, handleOnRoomAdded);
|
||||||
|
return () => {
|
||||||
|
initMatrix.roomList.removeListener(cons.events.roomList.ROOM_JOINED, handleOnRoomAdded);
|
||||||
|
};
|
||||||
|
}, [status]);
|
||||||
|
|
||||||
|
async function joinWithAlias() {
|
||||||
|
setStatus({
|
||||||
|
isJoining: true, error: null, roomId: null, tempRoomId: null,
|
||||||
|
});
|
||||||
|
try {
|
||||||
|
const roomId = await roomActions.join(alias, false);
|
||||||
|
setStatus({
|
||||||
|
isJoining: true, error: null, roomId: null, tempRoomId: roomId,
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
setStatus({
|
||||||
|
isJoining: false,
|
||||||
|
error: `Unable to join ${alias}. Either channel is private or doesn't exist.`,
|
||||||
|
roomId: null,
|
||||||
|
tempRoomId: null,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="try-join-with-alias">
|
||||||
|
{status.roomId === null && !status.isJoining && status.error === null && (
|
||||||
|
<Button onClick={() => joinWithAlias()}>{`Try joining ${alias}`}</Button>
|
||||||
|
)}
|
||||||
|
{status.isJoining && (
|
||||||
|
<>
|
||||||
|
<Spinner size="small" />
|
||||||
|
<Text>{`Joining ${alias}...`}</Text>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
{status.roomId !== null && (
|
||||||
|
<Button onClick={() => { onRequestClose(); selectRoom(status.roomId); }}>Open</Button>
|
||||||
|
)}
|
||||||
|
{status.error !== null && <Text variant="b2"><span style={{ color: 'var(--bg-danger)' }}>{status.error}</span></Text>}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
TryJoinWithAlias.propTypes = {
|
||||||
|
alias: PropTypes.string.isRequired,
|
||||||
|
onRequestClose: PropTypes.func.isRequired,
|
||||||
|
};
|
||||||
|
|
||||||
|
function PublicChannels({ isOpen, searchTerm, onRequestClose }) {
|
||||||
const [isSearching, updateIsSearching] = useState(false);
|
const [isSearching, updateIsSearching] = useState(false);
|
||||||
const [isViewMore, updateIsViewMore] = useState(false);
|
const [isViewMore, updateIsViewMore] = useState(false);
|
||||||
const [publicChannels, updatePublicChannels] = useState([]);
|
const [publicChannels, updatePublicChannels] = useState([]);
|
||||||
@@ -33,8 +97,13 @@ function PublicChannels({ isOpen, onRequestClose }) {
|
|||||||
const userId = initMatrix.matrixClient.getUserId();
|
const userId = initMatrix.matrixClient.getUserId();
|
||||||
|
|
||||||
async function searchChannels(viewMore) {
|
async function searchChannels(viewMore) {
|
||||||
let inputHs = hsRef?.current?.value;
|
let inputChannelName = channelNameRef?.current?.value || searchTerm;
|
||||||
let inputChannelName = channelNameRef?.current?.value;
|
let isInputAlias = false;
|
||||||
|
if (typeof inputChannelName === 'string') {
|
||||||
|
isInputAlias = inputChannelName[0] === '#' && inputChannelName.indexOf(':') > 1;
|
||||||
|
}
|
||||||
|
const hsFromAlias = (isInputAlias) ? inputChannelName.slice(inputChannelName.indexOf(':') + 1) : null;
|
||||||
|
let inputHs = hsFromAlias || hsRef?.current?.value;
|
||||||
|
|
||||||
if (typeof inputHs !== 'string') inputHs = userId.slice(userId.indexOf(':') + 1);
|
if (typeof inputHs !== 'string') inputHs = userId.slice(userId.indexOf(':') + 1);
|
||||||
if (typeof inputChannelName !== 'string') inputChannelName = '';
|
if (typeof inputChannelName !== 'string') inputChannelName = '';
|
||||||
@@ -68,9 +137,18 @@ function PublicChannels({ isOpen, onRequestClose }) {
|
|||||||
updateNextBatch(result.next_batch);
|
updateNextBatch(result.next_batch);
|
||||||
updateIsSearching(false);
|
updateIsSearching(false);
|
||||||
updateIsViewMore(false);
|
updateIsViewMore(false);
|
||||||
|
if (totalChannels.length === 0) {
|
||||||
|
updateSearchQuery({
|
||||||
|
error: `No result found for "${inputChannelName}" on ${inputHs}`,
|
||||||
|
alias: isInputAlias ? inputChannelName : null,
|
||||||
|
});
|
||||||
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
updatePublicChannels([]);
|
updatePublicChannels([]);
|
||||||
updateSearchQuery({ error: 'Something went wrong!' });
|
updateSearchQuery({
|
||||||
|
error: 'Something went wrong!',
|
||||||
|
alias: isInputAlias ? inputChannelName : null,
|
||||||
|
});
|
||||||
updateIsSearching(false);
|
updateIsSearching(false);
|
||||||
updateNextBatch(undefined);
|
updateNextBatch(undefined);
|
||||||
updateIsViewMore(false);
|
updateIsViewMore(false);
|
||||||
@@ -139,7 +217,7 @@ function PublicChannels({ isOpen, onRequestClose }) {
|
|||||||
<div className="public-channels">
|
<div className="public-channels">
|
||||||
<form className="public-channels__form" onSubmit={(e) => { e.preventDefault(); searchChannels(); }}>
|
<form className="public-channels__form" onSubmit={(e) => { e.preventDefault(); searchChannels(); }}>
|
||||||
<div className="public-channels__input-wrapper">
|
<div className="public-channels__input-wrapper">
|
||||||
<Input forwardRef={channelNameRef} label="Channel name" />
|
<Input value={searchTerm} forwardRef={channelNameRef} label="Channel name or alias" />
|
||||||
<Input forwardRef={hsRef} value={userId.slice(userId.indexOf(':') + 1)} label="Homeserver" required />
|
<Input forwardRef={hsRef} value={userId.slice(userId.indexOf(':') + 1)} label="Homeserver" required />
|
||||||
</div>
|
</div>
|
||||||
<Button disabled={isSearching} iconSrc={HashSearchIC} variant="primary" type="submit">Search</Button>
|
<Button disabled={isSearching} iconSrc={HashSearchIC} variant="primary" type="submit">Search</Button>
|
||||||
@@ -169,9 +247,14 @@ function PublicChannels({ isOpen, onRequestClose }) {
|
|||||||
: <Text variant="b2">{`Search result for "${searchQuery.name}" on ${searchQuery.homeserver}.`}</Text>
|
: <Text variant="b2">{`Search result for "${searchQuery.name}" on ${searchQuery.homeserver}.`}</Text>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
{
|
{ searchQuery.error && (
|
||||||
searchQuery.error && <Text className="public-channels__search-error" variant="b2">{searchQuery.error}</Text>
|
<>
|
||||||
}
|
<Text className="public-channels__search-error" variant="b2">{searchQuery.error}</Text>
|
||||||
|
{typeof searchQuery.alias === 'string' && (
|
||||||
|
<TryJoinWithAlias onRequestClose={onRequestClose} alias={searchQuery.alias} />
|
||||||
|
)}
|
||||||
|
</>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
{ publicChannels.length !== 0 && (
|
{ publicChannels.length !== 0 && (
|
||||||
<div className="public-channels__content">
|
<div className="public-channels__content">
|
||||||
@@ -191,8 +274,13 @@ function PublicChannels({ isOpen, onRequestClose }) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PublicChannels.defaultProps = {
|
||||||
|
searchTerm: undefined,
|
||||||
|
};
|
||||||
|
|
||||||
PublicChannels.propTypes = {
|
PublicChannels.propTypes = {
|
||||||
isOpen: PropTypes.bool.isRequired,
|
isOpen: PropTypes.bool.isRequired,
|
||||||
|
searchTerm: PropTypes.string,
|
||||||
onRequestClose: PropTypes.func.isRequired,
|
onRequestClose: PropTypes.func.isRequired,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -55,6 +55,10 @@
|
|||||||
& .donut-spinner {
|
& .donut-spinner {
|
||||||
margin: 0 var(--sp-tight);
|
margin: 0 var(--sp-tight);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.try-join-with-alias {
|
||||||
|
margin-top: var(--sp-normal);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
&__search-error {
|
&__search-error {
|
||||||
color: var(--bg-danger);
|
color: var(--bg-danger);
|
||||||
@@ -84,4 +88,13 @@
|
|||||||
right: var(--sp-normal);
|
right: var(--sp-normal);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.try-join-with-alias {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
|
||||||
|
& >.text:nth-child(2) {
|
||||||
|
margin: 0 var(--sp-normal);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -11,24 +11,32 @@ import Settings from '../settings/Settings';
|
|||||||
|
|
||||||
function Windows() {
|
function Windows() {
|
||||||
const [isInviteList, changeInviteList] = useState(false);
|
const [isInviteList, changeInviteList] = useState(false);
|
||||||
const [isPubilcChannels, changePubilcChannels] = useState(false);
|
const [publicChannels, changePublicChannels] = useState({
|
||||||
|
isOpen: false, searchTerm: undefined,
|
||||||
|
});
|
||||||
const [isCreateChannel, changeCreateChannel] = useState(false);
|
const [isCreateChannel, changeCreateChannel] = useState(false);
|
||||||
const [inviteUser, changeInviteUser] = useState({ isOpen: false, roomId: undefined });
|
const [inviteUser, changeInviteUser] = useState({
|
||||||
|
isOpen: false, roomId: undefined, term: undefined,
|
||||||
|
});
|
||||||
const [settings, changeSettings] = useState(false);
|
const [settings, changeSettings] = useState(false);
|
||||||
|
|
||||||
function openInviteList() {
|
function openInviteList() {
|
||||||
changeInviteList(true);
|
changeInviteList(true);
|
||||||
}
|
}
|
||||||
function openPublicChannels() {
|
function openPublicChannels(searchTerm) {
|
||||||
changePubilcChannels(true);
|
changePublicChannels({
|
||||||
|
isOpen: true,
|
||||||
|
searchTerm,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
function openCreateChannel() {
|
function openCreateChannel() {
|
||||||
changeCreateChannel(true);
|
changeCreateChannel(true);
|
||||||
}
|
}
|
||||||
function openInviteUser(roomId) {
|
function openInviteUser(roomId, searchTerm) {
|
||||||
changeInviteUser({
|
changeInviteUser({
|
||||||
isOpen: true,
|
isOpen: true,
|
||||||
roomId,
|
roomId,
|
||||||
|
searchTerm,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
function openSettings() {
|
function openSettings() {
|
||||||
@@ -57,8 +65,9 @@ function Windows() {
|
|||||||
onRequestClose={() => changeInviteList(false)}
|
onRequestClose={() => changeInviteList(false)}
|
||||||
/>
|
/>
|
||||||
<PublicChannels
|
<PublicChannels
|
||||||
isOpen={isPubilcChannels}
|
isOpen={publicChannels.isOpen}
|
||||||
onRequestClose={() => changePubilcChannels(false)}
|
searchTerm={publicChannels.searchTerm}
|
||||||
|
onRequestClose={() => changePublicChannels({ isOpen: false, searchTerm: undefined })}
|
||||||
/>
|
/>
|
||||||
<CreateChannel
|
<CreateChannel
|
||||||
isOpen={isCreateChannel}
|
isOpen={isCreateChannel}
|
||||||
@@ -67,6 +76,7 @@ function Windows() {
|
|||||||
<InviteUser
|
<InviteUser
|
||||||
isOpen={inviteUser.isOpen}
|
isOpen={inviteUser.isOpen}
|
||||||
roomId={inviteUser.roomId}
|
roomId={inviteUser.roomId}
|
||||||
|
searchTerm={inviteUser.searchTerm}
|
||||||
onRequestClose={() => changeInviteUser({ isOpen: false, roomId: undefined })}
|
onRequestClose={() => changeInviteUser({ isOpen: false, roomId: undefined })}
|
||||||
/>
|
/>
|
||||||
<Settings
|
<Settings
|
||||||
|
|||||||
@@ -1,49 +1,148 @@
|
|||||||
import React from 'react';
|
import React, { useState } from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import './Settings.scss';
|
import './Settings.scss';
|
||||||
|
|
||||||
|
import initMatrix from '../../../client/initMatrix';
|
||||||
import settings from '../../../client/state/settings';
|
import settings from '../../../client/state/settings';
|
||||||
|
import { toggleMarkdown } from '../../../client/action/settings';
|
||||||
|
|
||||||
import Text from '../../atoms/text/Text';
|
import Text from '../../atoms/text/Text';
|
||||||
import IconButton from '../../atoms/button/IconButton';
|
import IconButton from '../../atoms/button/IconButton';
|
||||||
|
import Button from '../../atoms/button/Button';
|
||||||
|
import Toggle from '../../atoms/button/Toggle';
|
||||||
import SegmentedControls from '../../atoms/segmented-controls/SegmentedControls';
|
import SegmentedControls from '../../atoms/segmented-controls/SegmentedControls';
|
||||||
|
|
||||||
import PopupWindow from '../../molecules/popup-window/PopupWindow';
|
import PopupWindow, { PWContentSelector } from '../../molecules/popup-window/PopupWindow';
|
||||||
import SettingTile from '../../molecules/setting-tile/SettingTile';
|
import SettingTile from '../../molecules/setting-tile/SettingTile';
|
||||||
|
import ImportE2ERoomKeys from '../../molecules/import-e2e-room-keys/ImportE2ERoomKeys';
|
||||||
|
|
||||||
|
import SunIC from '../../../../public/res/ic/outlined/sun.svg';
|
||||||
|
import LockIC from '../../../../public/res/ic/outlined/lock.svg';
|
||||||
|
import InfoIC from '../../../../public/res/ic/outlined/info.svg';
|
||||||
import CrossIC from '../../../../public/res/ic/outlined/cross.svg';
|
import CrossIC from '../../../../public/res/ic/outlined/cross.svg';
|
||||||
|
|
||||||
|
import CinnySVG from '../../../../public/res/svg/cinny.svg';
|
||||||
|
|
||||||
|
function AppearanceSection() {
|
||||||
|
const [, updateState] = useState({});
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="settings-content">
|
||||||
|
<SettingTile
|
||||||
|
title="Theme"
|
||||||
|
content={(
|
||||||
|
<SegmentedControls
|
||||||
|
selected={settings.getThemeIndex()}
|
||||||
|
segments={[
|
||||||
|
{ text: 'Light' },
|
||||||
|
{ text: 'Silver' },
|
||||||
|
{ text: 'Dark' },
|
||||||
|
{ text: 'Butter' },
|
||||||
|
]}
|
||||||
|
onSelect={(index) => settings.setTheme(index)}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
<SettingTile
|
||||||
|
title="Markdown formatting"
|
||||||
|
options={(
|
||||||
|
<Toggle
|
||||||
|
isActive={settings.isMarkdown}
|
||||||
|
onToggle={(isMarkdown) => { toggleMarkdown(isMarkdown); updateState({}); }}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
content={<Text variant="b3">Format messages with markdown syntax before sending.</Text>}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function SecuritySection() {
|
||||||
|
return (
|
||||||
|
<div className="set-security settings-content">
|
||||||
|
<SettingTile
|
||||||
|
title={`Device ID: ${initMatrix.matrixClient.getDeviceId()}`}
|
||||||
|
content={<Text variant="b3">Use this device ID to verify or manage this session from Element client.</Text>}
|
||||||
|
/>
|
||||||
|
<SettingTile
|
||||||
|
title="Import E2E room keys"
|
||||||
|
content={(
|
||||||
|
<>
|
||||||
|
<Text variant="b3">{'To decrypt older messages, Export E2EE room keys from Element (Settings > Security & Privacy > Encryption > Cryptography) and import them here. Imported keys are encrypted so you\'ll have to enter the password you set in order to decrypt it.'}</Text>
|
||||||
|
<ImportE2ERoomKeys />
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function AboutSection() {
|
||||||
|
return (
|
||||||
|
<div className="settings-content settings__about">
|
||||||
|
<div className="set-about__branding">
|
||||||
|
<img width="60" height="60" src={CinnySVG} alt="Cinny logo" />
|
||||||
|
<div>
|
||||||
|
<Text variant="h2">
|
||||||
|
Cinny
|
||||||
|
<span className="text text-b3" style={{ margin: '0 var(--sp-extra-tight)' }}>v1.1.0</span>
|
||||||
|
</Text>
|
||||||
|
<Text>Yet another matrix client</Text>
|
||||||
|
|
||||||
|
<div className="set-about__btns">
|
||||||
|
<Button onClick={() => window.open('https://github.com/ajbura/cinny')}>Source code</Button>
|
||||||
|
<Button onClick={() => window.open('https://liberapay.com/ajbura/donate')}>Support</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
function Settings({ isOpen, onRequestClose }) {
|
function Settings({ isOpen, onRequestClose }) {
|
||||||
|
const settingSections = [{
|
||||||
|
name: 'Appearance',
|
||||||
|
iconSrc: SunIC,
|
||||||
|
render() {
|
||||||
|
return <AppearanceSection />;
|
||||||
|
},
|
||||||
|
}, {
|
||||||
|
name: 'Security & Privacy',
|
||||||
|
iconSrc: LockIC,
|
||||||
|
render() {
|
||||||
|
return <SecuritySection />;
|
||||||
|
},
|
||||||
|
}, {
|
||||||
|
name: 'Help & About',
|
||||||
|
iconSrc: InfoIC,
|
||||||
|
render() {
|
||||||
|
return <AboutSection />;
|
||||||
|
},
|
||||||
|
}];
|
||||||
|
const [selectedSection, setSelectedSection] = useState(settingSections[0]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<PopupWindow
|
<PopupWindow
|
||||||
className="settings-window"
|
className="settings-window"
|
||||||
isOpen={isOpen}
|
isOpen={isOpen}
|
||||||
onRequestClose={onRequestClose}
|
onRequestClose={onRequestClose}
|
||||||
title="Settings"
|
title="Settings"
|
||||||
|
contentTitle={selectedSection.name}
|
||||||
|
drawer={
|
||||||
|
settingSections.map((section) => (
|
||||||
|
<PWContentSelector
|
||||||
|
key={section.name}
|
||||||
|
selected={selectedSection.name === section.name}
|
||||||
|
onClick={() => setSelectedSection(section)}
|
||||||
|
iconSrc={section.iconSrc}
|
||||||
|
>
|
||||||
|
{section.name}
|
||||||
|
</PWContentSelector>
|
||||||
|
))
|
||||||
|
}
|
||||||
contentOptions={<IconButton src={CrossIC} onClick={onRequestClose} tooltip="Close" />}
|
contentOptions={<IconButton src={CrossIC} onClick={onRequestClose} tooltip="Close" />}
|
||||||
>
|
>
|
||||||
<div className="settings-content">
|
{selectedSection.render()}
|
||||||
<SettingTile
|
|
||||||
title="Theme"
|
|
||||||
content={(
|
|
||||||
<SegmentedControls
|
|
||||||
selected={settings.getThemeIndex()}
|
|
||||||
segments={[
|
|
||||||
{ text: 'Light' },
|
|
||||||
{ text: 'Silver' },
|
|
||||||
{ text: 'Dark' },
|
|
||||||
{ text: 'Butter' },
|
|
||||||
]}
|
|
||||||
onSelect={(index) => settings.setTheme(index)}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
<div style={{ flex: '1' }} />
|
|
||||||
<Text className="settings__about" variant="b1">
|
|
||||||
<a href="https://cinny.in/#about" target="_blank" rel="noreferrer">About</a>
|
|
||||||
</Text>
|
|
||||||
<Text className="settings__about">Version: 1.0.0</Text>
|
|
||||||
</div>
|
|
||||||
</PopupWindow>
|
</PopupWindow>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
.settings-window {
|
.settings-window {
|
||||||
& .pw__content-container {
|
& .pw__content-container {
|
||||||
height: 100%;
|
min-height: 100%;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -12,11 +12,32 @@
|
|||||||
margin-right: var(--sp-normal);
|
margin-right: var(--sp-normal);
|
||||||
}
|
}
|
||||||
|
|
||||||
display: flex;
|
& .setting-tile {
|
||||||
flex-direction: column;
|
margin-top: var(--sp-normal);
|
||||||
height: 100%;
|
border-bottom: 1px solid var(--bg-surface-border);
|
||||||
|
padding-bottom: 16px;
|
||||||
|
&__title__wrapper {
|
||||||
|
margin-bottom: var(--sp-ultra-tight);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.settings__about {
|
.set-about {
|
||||||
text-align: center;
|
&__branding {
|
||||||
|
margin-top: var(--sp-extra-tight);
|
||||||
|
margin-bottom: var(--sp-normal);
|
||||||
|
display: flex;
|
||||||
|
|
||||||
|
& > div {
|
||||||
|
margin: 0 calc(var(--sp-loose) + var(--sp-ultra-tight));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
&__btns {
|
||||||
|
margin: 0;
|
||||||
|
margin-top: var(--sp-normal);
|
||||||
|
& button:last-child {
|
||||||
|
margin: 0 var(--sp-tight)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -13,13 +13,17 @@ import Spinner from '../../atoms/spinner/Spinner';
|
|||||||
|
|
||||||
import CinnySvg from '../../../../public/res/svg/cinny.svg';
|
import CinnySvg from '../../../../public/res/svg/cinny.svg';
|
||||||
|
|
||||||
const USERNAME_REGEX = /^[a-z0-9_-]+$/;
|
// This regex validates historical usernames, which don't satisy today's username requirements.
|
||||||
const BAD_USERNAME_ERROR = 'Username must contain only lowercase letters, numbers, dashes and underscores.';
|
// See https://matrix.org/docs/spec/appendices#id13 for more info.
|
||||||
|
const LOCALPART_LOGIN_REGEX = /^[!-9|;-~]+$/;
|
||||||
|
const LOCALPART_SIGNUP_REGEX = /^[a-z0-9_\-.=/]+$/;
|
||||||
|
const BAD_LOCALPART_ERROR = 'Username must contain only a-z, 0-9, ., _, =, -, and /.';
|
||||||
|
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_REGEX = /.+/;
|
||||||
const PASSWORD_STRENGHT_REGEX = /^(?=.*\d)(?=.*[A-Z])(?=.*[a-z])(?=.*[^\w\d\s:])([^\s]){8,16}$/;
|
const PASSWORD_STRENGHT_REGEX = /^(?=.*\d)(?=.*[A-Z])(?=.*[a-z])(?=.*[^\w\d\s:])([^\s]){8,127}$/;
|
||||||
const BAD_PASSWORD_ERROR = 'Password must contain 1 number, 1 uppercase letters, 1 lowercase letters, 1 non-alpha numeric number, 8-16 characters with no space.';
|
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 CONFIRM_PASSWORD_ERROR = 'Password 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-z0-9]+)@([a-z0-9-]+(?:.[a-z0-9-]+).[a-z]{2,4})/;
|
||||||
const BAD_EMAIL_ERROR = 'Invalid email address';
|
const BAD_EMAIL_ERROR = 'Invalid email address';
|
||||||
@@ -52,6 +56,18 @@ function validateOnChange(e, regex, error) {
|
|||||||
document.getElementById('auth_submit-btn').disabled = false;
|
document.getElementById('auth_submit-btn').disabled = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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) {
|
||||||
|
const noLeadingAt = rawUsername.indexOf('@') === 0 ? rawUsername.substr(1) : rawUsername;
|
||||||
|
return noLeadingAt.trim();
|
||||||
|
}
|
||||||
|
|
||||||
function Auth({ type }) {
|
function Auth({ type }) {
|
||||||
const [process, changeProcess] = useState(null);
|
const [process, changeProcess] = useState(null);
|
||||||
const usernameRef = useRef(null);
|
const usernameRef = useRef(null);
|
||||||
@@ -99,12 +115,17 @@ function Auth({ type }) {
|
|||||||
document.getElementById('auth_submit-btn').disabled = true;
|
document.getElementById('auth_submit-btn').disabled = true;
|
||||||
document.getElementById('auth_error').style.display = 'none';
|
document.getElementById('auth_error').style.display = 'none';
|
||||||
|
|
||||||
if (!isValidInput(usernameRef.current.value, USERNAME_REGEX)) {
|
/** @type {string} */
|
||||||
showBadInputError(usernameRef.current, BAD_USERNAME_ERROR);
|
const rawUsername = usernameRef.current.value;
|
||||||
|
/** @type {string} */
|
||||||
|
const normalizedUsername = normalizeUsername(rawUsername);
|
||||||
|
|
||||||
|
if (!isValidInput(normalizedUsername, LOCALPART_LOGIN_REGEX)) {
|
||||||
|
showBadInputError(usernameRef.current, BAD_LOCALPART_ERROR);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
auth.login(usernameRef.current.value, homeserverRef.current.value, passwordRef.current.value)
|
auth.login(normalizedUsername, homeserverRef.current.value, passwordRef.current.value)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
document.getElementById('auth_submit-btn').disabled = false;
|
document.getElementById('auth_submit-btn').disabled = false;
|
||||||
window.location.replace('/');
|
window.location.replace('/');
|
||||||
@@ -122,8 +143,8 @@ function Auth({ type }) {
|
|||||||
document.getElementById('auth_submit-btn').disabled = true;
|
document.getElementById('auth_submit-btn').disabled = true;
|
||||||
document.getElementById('auth_error').style.display = 'none';
|
document.getElementById('auth_error').style.display = 'none';
|
||||||
|
|
||||||
if (!isValidInput(usernameRef.current.value, USERNAME_REGEX)) {
|
if (!isValidInput(usernameRef.current.value, LOCALPART_SIGNUP_REGEX)) {
|
||||||
showBadInputError(usernameRef.current, BAD_USERNAME_ERROR);
|
showBadInputError(usernameRef.current, BAD_LOCALPART_ERROR);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!isValidInput(passwordRef.current.value, PASSWORD_STRENGHT_REGEX)) {
|
if (!isValidInput(passwordRef.current.value, PASSWORD_STRENGHT_REGEX)) {
|
||||||
@@ -138,6 +159,10 @@ function Auth({ type }) {
|
|||||||
showBadInputError(emailRef.current, BAD_EMAIL_ERROR);
|
showBadInputError(emailRef.current, BAD_EMAIL_ERROR);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (`@${usernameRef.current.value}:${homeserverRef.current.value}`.length > 255) {
|
||||||
|
showBadInputError(usernameRef.current, USER_ID_TOO_LONG_ERROR);
|
||||||
|
return;
|
||||||
|
}
|
||||||
register();
|
register();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -171,7 +196,9 @@ function Auth({ type }) {
|
|||||||
<div className="username__wrapper">
|
<div className="username__wrapper">
|
||||||
<Input
|
<Input
|
||||||
forwardRef={usernameRef}
|
forwardRef={usernameRef}
|
||||||
onChange={(e) => validateOnChange(e, USERNAME_REGEX, BAD_USERNAME_ERROR)}
|
onChange={(e) => (type === 'login'
|
||||||
|
? validateOnChange(e, LOCALPART_LOGIN_REGEX, BAD_LOCALPART_ERROR)
|
||||||
|
: validateOnChange(e, LOCALPART_SIGNUP_REGEX, BAD_LOCALPART_ERROR))}
|
||||||
id="auth_username"
|
id="auth_username"
|
||||||
label="Username"
|
label="Username"
|
||||||
required
|
required
|
||||||
@@ -251,7 +278,7 @@ function StaticWrapper({ children }) {
|
|||||||
<img className="app-ident__logo noselect" src={CinnySvg} alt="Cinny logo" />
|
<img className="app-ident__logo noselect" src={CinnySvg} alt="Cinny logo" />
|
||||||
<div className="app-ident__text flex-v--center">
|
<div className="app-ident__text flex-v--center">
|
||||||
<Text variant="h2">Cinny</Text>
|
<Text variant="h2">Cinny</Text>
|
||||||
<Text variant="b2">Yet another matrix client.</Text>
|
<Text variant="b2">Yet another matrix client</Text>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{ children }
|
{ children }
|
||||||
@@ -302,7 +329,7 @@ function Terms({ url, 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)' }} />
|
||||||
<Text variant="b1">In order to complete registration, you need to agree with terms and conditions.</Text>
|
<Text variant="b1">In order to complete registration, you need to agree to the terms and conditions.</Text>
|
||||||
<div style={{ display: 'flex', alignItems: 'center', margin: 'var(--sp-normal) 0' }}>
|
<div style={{ display: 'flex', alignItems: 'center', margin: 'var(--sp-normal) 0' }}>
|
||||||
<input id="termsCheckbox" type="checkbox" required />
|
<input id="termsCheckbox" type="checkbox" required />
|
||||||
<Text variant="b1">
|
<Text variant="b1">
|
||||||
|
|||||||
@@ -3,14 +3,22 @@ import cons from '../state/cons';
|
|||||||
import { getBaseUrl } from '../../util/matrixUtil';
|
import { getBaseUrl } from '../../util/matrixUtil';
|
||||||
|
|
||||||
async function login(username, homeserver, password) {
|
async function login(username, homeserver, password) {
|
||||||
const baseUrl = await getBaseUrl(homeserver);
|
let baseUrl = null;
|
||||||
|
try {
|
||||||
|
baseUrl = await getBaseUrl(homeserver);
|
||||||
|
} catch (e) {
|
||||||
|
baseUrl = `https://${homeserver}`;
|
||||||
|
}
|
||||||
|
|
||||||
if (typeof baseUrl === 'undefined') throw new Error('Homeserver not found');
|
if (typeof baseUrl === 'undefined') throw new Error('Homeserver not found');
|
||||||
|
|
||||||
const client = sdk.createClient({ baseUrl });
|
const client = sdk.createClient({ baseUrl });
|
||||||
|
|
||||||
const response = await client.login('m.login.password', {
|
const response = await client.login('m.login.password', {
|
||||||
user: `@${username}:${homeserver}`,
|
identifier: {
|
||||||
|
type: 'm.id.user',
|
||||||
|
user: username,
|
||||||
|
},
|
||||||
password,
|
password,
|
||||||
initial_device_display_name: cons.DEVICE_DISPLAY_NAME,
|
initial_device_display_name: cons.DEVICE_DISPLAY_NAME,
|
||||||
});
|
});
|
||||||
@@ -18,7 +26,7 @@ async function login(username, homeserver, password) {
|
|||||||
localStorage.setItem(cons.secretKey.ACCESS_TOKEN, response.access_token);
|
localStorage.setItem(cons.secretKey.ACCESS_TOKEN, response.access_token);
|
||||||
localStorage.setItem(cons.secretKey.DEVICE_ID, response.device_id);
|
localStorage.setItem(cons.secretKey.DEVICE_ID, response.device_id);
|
||||||
localStorage.setItem(cons.secretKey.USER_ID, response.user_id);
|
localStorage.setItem(cons.secretKey.USER_ID, response.user_id);
|
||||||
localStorage.setItem(cons.secretKey.BASE_URL, response.well_known['m.homeserver'].base_url);
|
localStorage.setItem(cons.secretKey.BASE_URL, response?.well_known?.['m.homeserver']?.base_url || baseUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getAdditionalInfo(baseUrl, content) {
|
async function getAdditionalInfo(baseUrl, content) {
|
||||||
@@ -39,7 +47,7 @@ async function getAdditionalInfo(baseUrl, content) {
|
|||||||
}
|
}
|
||||||
async function verifyEmail(baseUrl, content) {
|
async function verifyEmail(baseUrl, content) {
|
||||||
try {
|
try {
|
||||||
const res = await fetch(`${baseUrl}/_matrix/client/r0/register/email/requestToken `, {
|
const res = await fetch(`${baseUrl}/_matrix/client/r0/register/email/requestToken`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: JSON.stringify(content),
|
body: JSON.stringify(content),
|
||||||
headers: {
|
headers: {
|
||||||
@@ -85,7 +93,6 @@ async function register(username, homeserver, password, email, recaptchaValue, t
|
|||||||
} else if (verified !== true) {
|
} else if (verified !== true) {
|
||||||
session = null;
|
session = null;
|
||||||
clientSecret = client.generateClientSecret();
|
clientSecret = client.generateClientSecret();
|
||||||
console.log(clientSecret);
|
|
||||||
const verifyData = await verifyEmail(baseUrl, {
|
const verifyData = await verifyEmail(baseUrl, {
|
||||||
email,
|
email,
|
||||||
client_secret: clientSecret,
|
client_secret: clientSecret,
|
||||||
|
|||||||
@@ -27,9 +27,10 @@ function openInviteList() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function openPublicChannels() {
|
function openPublicChannels(searchTerm) {
|
||||||
appDispatcher.dispatch({
|
appDispatcher.dispatch({
|
||||||
type: cons.actions.navigation.OPEN_PUBLIC_CHANNELS,
|
type: cons.actions.navigation.OPEN_PUBLIC_CHANNELS,
|
||||||
|
searchTerm,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -39,10 +40,11 @@ function openCreateChannel() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function openInviteUser(roomId) {
|
function openInviteUser(roomId, searchTerm) {
|
||||||
appDispatcher.dispatch({
|
appDispatcher.dispatch({
|
||||||
type: cons.actions.navigation.OPEN_INVITE_USER,
|
type: cons.actions.navigation.OPEN_INVITE_USER,
|
||||||
roomId,
|
roomId,
|
||||||
|
searchTerm,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -83,20 +83,24 @@ function guessDMRoomTargetId(room, myUserId) {
|
|||||||
* @param {string} roomId
|
* @param {string} roomId
|
||||||
* @param {boolean} isDM
|
* @param {boolean} isDM
|
||||||
*/
|
*/
|
||||||
function join(roomId, isDM) {
|
async function join(roomIdOrAlias, isDM) {
|
||||||
const mx = initMatrix.matrixClient;
|
const mx = initMatrix.matrixClient;
|
||||||
mx.joinRoom(roomId)
|
try {
|
||||||
.then(async () => {
|
const resultRoom = await mx.joinRoom(roomIdOrAlias);
|
||||||
if (isDM) {
|
|
||||||
const targetUserId = guessDMRoomTargetId(mx.getRoom(roomId), mx.getUserId());
|
if (isDM) {
|
||||||
await addRoomToMDirect(roomId, targetUserId);
|
const targetUserId = guessDMRoomTargetId(mx.getRoom(resultRoom.roomId), mx.getUserId());
|
||||||
}
|
await addRoomToMDirect(resultRoom.roomId, targetUserId);
|
||||||
appDispatcher.dispatch({
|
}
|
||||||
type: cons.actions.room.JOIN,
|
appDispatcher.dispatch({
|
||||||
roomId,
|
type: cons.actions.room.JOIN,
|
||||||
isDM,
|
roomId: resultRoom.roomId,
|
||||||
});
|
isDM,
|
||||||
}).catch();
|
});
|
||||||
|
return resultRoom.roomId;
|
||||||
|
} catch (e) {
|
||||||
|
throw new Error(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -104,8 +108,9 @@ function join(roomId, isDM) {
|
|||||||
* @param {string} roomId
|
* @param {string} roomId
|
||||||
* @param {boolean} isDM
|
* @param {boolean} isDM
|
||||||
*/
|
*/
|
||||||
function leave(roomId, isDM) {
|
function leave(roomId) {
|
||||||
const mx = initMatrix.matrixClient;
|
const mx = initMatrix.matrixClient;
|
||||||
|
const isDM = initMatrix.roomList.directs.has(roomId);
|
||||||
mx.leave(roomId)
|
mx.leave(roomId)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
appDispatcher.dispatch({
|
appDispatcher.dispatch({
|
||||||
@@ -184,6 +189,19 @@ async function invite(roomId, userId) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function redact(roomId, eventId, reason) {
|
||||||
|
const mx = initMatrix.matrixClient;
|
||||||
|
|
||||||
|
try {
|
||||||
|
await mx.redactEvent(roomId, eventId, undefined, typeof reason === 'undefined' ? undefined : { reason });
|
||||||
|
return true;
|
||||||
|
} catch (e) {
|
||||||
|
throw new Error(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export {
|
export {
|
||||||
join, leave, create, invite,
|
join, leave,
|
||||||
|
create, invite,
|
||||||
|
redact,
|
||||||
};
|
};
|
||||||
|
|||||||
12
src/client/action/settings.js
Normal file
12
src/client/action/settings.js
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
import appDispatcher from '../dispatcher';
|
||||||
|
import cons from '../state/cons';
|
||||||
|
|
||||||
|
function toggleMarkdown() {
|
||||||
|
appDispatcher.dispatch({
|
||||||
|
type: cons.actions.settings.TOGGLE_MARKDOWN,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export {
|
||||||
|
toggleMarkdown,
|
||||||
|
};
|
||||||
@@ -5,7 +5,7 @@ import { secret } from './state/auth';
|
|||||||
import RoomList from './state/RoomList';
|
import RoomList from './state/RoomList';
|
||||||
import RoomsInput from './state/RoomsInput';
|
import RoomsInput from './state/RoomsInput';
|
||||||
|
|
||||||
global.Olm = require('olm');
|
global.Olm = require('@matrix-org/olm');
|
||||||
|
|
||||||
class InitMatrix extends EventEmitter {
|
class InitMatrix extends EventEmitter {
|
||||||
async init() {
|
async init() {
|
||||||
@@ -77,6 +77,7 @@ class InitMatrix extends EventEmitter {
|
|||||||
|
|
||||||
listenEvents() {
|
listenEvents() {
|
||||||
this.matrixClient.on('Session.logged_out', () => {
|
this.matrixClient.on('Session.logged_out', () => {
|
||||||
|
this.matrixClient.stopClient();
|
||||||
this.matrixClient.clearStores();
|
this.matrixClient.clearStores();
|
||||||
window.localStorage.clear();
|
window.localStorage.clear();
|
||||||
window.location.reload();
|
window.location.reload();
|
||||||
|
|||||||
@@ -35,6 +35,11 @@ class RoomTimeline extends EventEmitter {
|
|||||||
this.emit(cons.events.roomTimeline.EVENT);
|
this.emit(cons.events.roomTimeline.EVENT);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
this._listenRedaction = (event, room) => {
|
||||||
|
if (room.roomId !== this.roomId) return;
|
||||||
|
this.emit(cons.events.roomTimeline.EVENT);
|
||||||
|
};
|
||||||
|
|
||||||
this._listenDecryptEvent = (event) => {
|
this._listenDecryptEvent = (event) => {
|
||||||
if (event.getRoomId() !== this.roomId) return;
|
if (event.getRoomId() !== this.roomId) return;
|
||||||
|
|
||||||
@@ -67,6 +72,7 @@ class RoomTimeline extends EventEmitter {
|
|||||||
};
|
};
|
||||||
|
|
||||||
this.matrixClient.on('Room.timeline', this._listenRoomTimeline);
|
this.matrixClient.on('Room.timeline', this._listenRoomTimeline);
|
||||||
|
this.matrixClient.on('Room.redaction', this._listenRedaction);
|
||||||
this.matrixClient.on('Event.decrypted', this._listenDecryptEvent);
|
this.matrixClient.on('Event.decrypted', this._listenDecryptEvent);
|
||||||
this.matrixClient.on('RoomMember.typing', this._listenTypingEvent);
|
this.matrixClient.on('RoomMember.typing', this._listenTypingEvent);
|
||||||
this.matrixClient.on('Room.receipt', this._listenReciptEvent);
|
this.matrixClient.on('Room.receipt', this._listenReciptEvent);
|
||||||
@@ -152,6 +158,7 @@ class RoomTimeline extends EventEmitter {
|
|||||||
|
|
||||||
removeInternalListeners() {
|
removeInternalListeners() {
|
||||||
this.matrixClient.removeListener('Room.timeline', this._listenRoomTimeline);
|
this.matrixClient.removeListener('Room.timeline', this._listenRoomTimeline);
|
||||||
|
this.matrixClient.removeListener('Room.redaction', this._listenRedaction);
|
||||||
this.matrixClient.removeListener('Event.decrypted', this._listenDecryptEvent);
|
this.matrixClient.removeListener('Event.decrypted', this._listenDecryptEvent);
|
||||||
this.matrixClient.removeListener('RoomMember.typing', this._listenTypingEvent);
|
this.matrixClient.removeListener('RoomMember.typing', this._listenTypingEvent);
|
||||||
this.matrixClient.removeListener('Room.receipt', this._listenReciptEvent);
|
this.matrixClient.removeListener('Room.receipt', this._listenReciptEvent);
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
import EventEmitter from 'events';
|
import EventEmitter from 'events';
|
||||||
|
import { Parser, HtmlRenderer } from 'commonmark';
|
||||||
import encrypt from 'browser-encrypt-attachment';
|
import encrypt from 'browser-encrypt-attachment';
|
||||||
import cons from './cons';
|
import cons from './cons';
|
||||||
|
import settings from './settings';
|
||||||
|
|
||||||
function getImageDimension(file) {
|
function getImageDimension(file) {
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
@@ -78,6 +80,32 @@ function getVideoThumbnail(video, width, height, mimeType) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getFormattedBody(markdown) {
|
||||||
|
const reader = new Parser();
|
||||||
|
const writer = new HtmlRenderer();
|
||||||
|
const parsed = reader.parse(markdown);
|
||||||
|
return writer.render(parsed);
|
||||||
|
}
|
||||||
|
|
||||||
|
function getReplyFormattedBody(roomId, reply) {
|
||||||
|
const replyToLink = `<a href="https://matrix.to/#/${roomId}/${reply.eventId}">In reply to</a>`;
|
||||||
|
const userLink = `<a href="https://matrix.to/#/${reply.userId}">${reply.userId}</a>`;
|
||||||
|
return `<mx-reply><blockquote>${replyToLink}${userLink}<br />${reply.content}</blockquote></mx-reply>`;
|
||||||
|
}
|
||||||
|
|
||||||
|
function bindReplyToContent(roomId, reply, content) {
|
||||||
|
const newContent = { ...content };
|
||||||
|
newContent.body = `> <${reply.userId}> ${reply.content}`;
|
||||||
|
newContent.body += `\n\n${content.body}`;
|
||||||
|
newContent.format = 'org.matrix.custom.html';
|
||||||
|
newContent['m.relates_to'] = content['m.relates_to'] || {};
|
||||||
|
newContent['m.relates_to']['m.in_reply_to'] = { event_id: reply.eventId };
|
||||||
|
|
||||||
|
const formattedReply = getReplyFormattedBody(roomId, reply);
|
||||||
|
newContent.formatted_body = formattedReply + (content.formatted_body || content.body);
|
||||||
|
return newContent;
|
||||||
|
}
|
||||||
|
|
||||||
class RoomsInput extends EventEmitter {
|
class RoomsInput extends EventEmitter {
|
||||||
constructor(mx) {
|
constructor(mx) {
|
||||||
super();
|
super();
|
||||||
@@ -89,6 +117,7 @@ class RoomsInput extends EventEmitter {
|
|||||||
cleanEmptyEntry(roomId) {
|
cleanEmptyEntry(roomId) {
|
||||||
const input = this.getInput(roomId);
|
const input = this.getInput(roomId);
|
||||||
const isEmpty = typeof input.attachment === 'undefined'
|
const isEmpty = typeof input.attachment === 'undefined'
|
||||||
|
&& typeof input.replyTo === 'undefined'
|
||||||
&& (typeof input.message === 'undefined' || input.message === '');
|
&& (typeof input.message === 'undefined' || input.message === '');
|
||||||
if (isEmpty) {
|
if (isEmpty) {
|
||||||
this.roomIdToInput.delete(roomId);
|
this.roomIdToInput.delete(roomId);
|
||||||
@@ -112,6 +141,25 @@ class RoomsInput extends EventEmitter {
|
|||||||
return input.message;
|
return input.message;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setReplyTo(roomId, replyTo) {
|
||||||
|
const input = this.getInput(roomId);
|
||||||
|
input.replyTo = replyTo;
|
||||||
|
this.roomIdToInput.set(roomId, input);
|
||||||
|
}
|
||||||
|
|
||||||
|
getReplyTo(roomId) {
|
||||||
|
const input = this.getInput(roomId);
|
||||||
|
if (typeof input.replyTo === 'undefined') return null;
|
||||||
|
return input.replyTo;
|
||||||
|
}
|
||||||
|
|
||||||
|
cancelReplyTo(roomId) {
|
||||||
|
const input = this.getInput(roomId);
|
||||||
|
if (typeof input.replyTo === 'undefined') return;
|
||||||
|
delete input.replyTo;
|
||||||
|
this.roomIdToInput.set(roomId, input);
|
||||||
|
}
|
||||||
|
|
||||||
setAttachment(roomId, file) {
|
setAttachment(roomId, file) {
|
||||||
const input = this.getInput(roomId);
|
const input = this.getInput(roomId);
|
||||||
input.attachment = {
|
input.attachment = {
|
||||||
@@ -136,13 +184,9 @@ class RoomsInput extends EventEmitter {
|
|||||||
this.matrixClient.cancelUpload(uploadingPromise);
|
this.matrixClient.cancelUpload(uploadingPromise);
|
||||||
delete input.attachment.uploadingPromise;
|
delete input.attachment.uploadingPromise;
|
||||||
}
|
}
|
||||||
if (input.message) {
|
delete input.attachment;
|
||||||
delete input.attachment;
|
delete input.isSending;
|
||||||
delete input.isSending;
|
this.roomIdToInput.set(roomId, input);
|
||||||
this.roomIdToInput.set(roomId, input);
|
|
||||||
} else {
|
|
||||||
this.roomIdToInput.delete(roomId);
|
|
||||||
}
|
|
||||||
this.emit(cons.events.roomsInput.ATTACHMENT_CANCELED, roomId);
|
this.emit(cons.events.roomsInput.ATTACHMENT_CANCELED, roomId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -159,10 +203,17 @@ class RoomsInput extends EventEmitter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (this.getMessage(roomId).trim() !== '') {
|
if (this.getMessage(roomId).trim() !== '') {
|
||||||
const content = {
|
let content = {
|
||||||
body: input.message,
|
body: input.message,
|
||||||
msgtype: 'm.text',
|
msgtype: 'm.text',
|
||||||
};
|
};
|
||||||
|
if (settings.isMarkdown) {
|
||||||
|
content.format = 'org.matrix.custom.html';
|
||||||
|
content.formatted_body = getFormattedBody(input.message);
|
||||||
|
}
|
||||||
|
if (typeof input.replyTo !== 'undefined') {
|
||||||
|
content = bindReplyToContent(roomId, input.replyTo, content);
|
||||||
|
}
|
||||||
this.matrixClient.sendMessage(roomId, content);
|
this.matrixClient.sendMessage(roomId, content);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -22,9 +22,12 @@ const cons = {
|
|||||||
LEAVE: 'LEAVE',
|
LEAVE: 'LEAVE',
|
||||||
CREATE: 'CREATE',
|
CREATE: 'CREATE',
|
||||||
error: {
|
error: {
|
||||||
CREATE: 'CREATE',
|
CREATE: 'ERROR_CREATE',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
settings: {
|
||||||
|
TOGGLE_MARKDOWN: 'TOGGLE_MARKDOWN',
|
||||||
|
},
|
||||||
},
|
},
|
||||||
events: {
|
events: {
|
||||||
navigation: {
|
navigation: {
|
||||||
@@ -57,6 +60,9 @@ const cons = {
|
|||||||
FILE_UPLOAD_CANCELED: 'FILE_UPLOAD_CANCELED',
|
FILE_UPLOAD_CANCELED: 'FILE_UPLOAD_CANCELED',
|
||||||
ATTACHMENT_CANCELED: 'ATTACHMENT_CANCELED',
|
ATTACHMENT_CANCELED: 'ATTACHMENT_CANCELED',
|
||||||
},
|
},
|
||||||
|
settings: {
|
||||||
|
MARKDOWN_TOGGLED: 'MARKDOWN_TOGGLED',
|
||||||
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -37,13 +37,13 @@ class Navigation extends EventEmitter {
|
|||||||
this.emit(cons.events.navigation.INVITE_LIST_OPENED);
|
this.emit(cons.events.navigation.INVITE_LIST_OPENED);
|
||||||
},
|
},
|
||||||
[cons.actions.navigation.OPEN_PUBLIC_CHANNELS]: () => {
|
[cons.actions.navigation.OPEN_PUBLIC_CHANNELS]: () => {
|
||||||
this.emit(cons.events.navigation.PUBLIC_CHANNELS_OPENED);
|
this.emit(cons.events.navigation.PUBLIC_CHANNELS_OPENED, action.searchTerm);
|
||||||
},
|
},
|
||||||
[cons.actions.navigation.OPEN_CREATE_CHANNEL]: () => {
|
[cons.actions.navigation.OPEN_CREATE_CHANNEL]: () => {
|
||||||
this.emit(cons.events.navigation.CREATE_CHANNEL_OPENED);
|
this.emit(cons.events.navigation.CREATE_CHANNEL_OPENED);
|
||||||
},
|
},
|
||||||
[cons.actions.navigation.OPEN_INVITE_USER]: () => {
|
[cons.actions.navigation.OPEN_INVITE_USER]: () => {
|
||||||
this.emit(cons.events.navigation.INVITE_USER_OPENED, action.roomId);
|
this.emit(cons.events.navigation.INVITE_USER_OPENED, action.roomId, action.searchTerm);
|
||||||
},
|
},
|
||||||
[cons.actions.navigation.OPEN_SETTINGS]: () => {
|
[cons.actions.navigation.OPEN_SETTINGS]: () => {
|
||||||
this.emit(cons.events.navigation.SETTINGS_OPENED);
|
this.emit(cons.events.navigation.SETTINGS_OPENED);
|
||||||
|
|||||||
@@ -1,15 +1,36 @@
|
|||||||
class Settings {
|
import EventEmitter from 'events';
|
||||||
|
import appDispatcher from '../dispatcher';
|
||||||
|
|
||||||
|
import cons from './cons';
|
||||||
|
|
||||||
|
function getSettings() {
|
||||||
|
const settings = localStorage.getItem('settings');
|
||||||
|
if (settings === null) return null;
|
||||||
|
return JSON.parse(settings);
|
||||||
|
}
|
||||||
|
|
||||||
|
function setSettings(key, value) {
|
||||||
|
let settings = getSettings();
|
||||||
|
if (settings === null) settings = {};
|
||||||
|
settings[key] = value;
|
||||||
|
localStorage.setItem('settings', JSON.stringify(settings));
|
||||||
|
}
|
||||||
|
|
||||||
|
class Settings extends EventEmitter {
|
||||||
constructor() {
|
constructor() {
|
||||||
|
super();
|
||||||
|
|
||||||
this.themes = ['', 'silver-theme', 'dark-theme', 'butter-theme'];
|
this.themes = ['', 'silver-theme', 'dark-theme', 'butter-theme'];
|
||||||
this.themeIndex = this.getThemeIndex();
|
this.themeIndex = this.getThemeIndex();
|
||||||
|
|
||||||
|
this.isMarkdown = this.getIsMarkdown();
|
||||||
}
|
}
|
||||||
|
|
||||||
getThemeIndex() {
|
getThemeIndex() {
|
||||||
if (typeof this.themeIndex === 'number') return this.themeIndex;
|
if (typeof this.themeIndex === 'number') return this.themeIndex;
|
||||||
|
|
||||||
let settings = localStorage.getItem('settings');
|
const settings = getSettings();
|
||||||
if (settings === null) return 0;
|
if (settings === null) return 0;
|
||||||
settings = JSON.parse(settings);
|
|
||||||
if (typeof settings.themeIndex === 'undefined') return 0;
|
if (typeof settings.themeIndex === 'undefined') return 0;
|
||||||
// eslint-disable-next-line radix
|
// eslint-disable-next-line radix
|
||||||
return parseInt(settings.themeIndex);
|
return parseInt(settings.themeIndex);
|
||||||
@@ -26,11 +47,33 @@ class Settings {
|
|||||||
appBody.classList.remove(themeName);
|
appBody.classList.remove(themeName);
|
||||||
});
|
});
|
||||||
if (this.themes[themeIndex] !== '') appBody.classList.add(this.themes[themeIndex]);
|
if (this.themes[themeIndex] !== '') appBody.classList.add(this.themes[themeIndex]);
|
||||||
localStorage.setItem('settings', JSON.stringify({ themeIndex }));
|
setSettings('themeIndex', themeIndex);
|
||||||
this.themeIndex = themeIndex;
|
this.themeIndex = themeIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getIsMarkdown() {
|
||||||
|
if (typeof this.isMarkdown === 'boolean') return this.isMarkdown;
|
||||||
|
|
||||||
|
const settings = getSettings();
|
||||||
|
if (settings === null) return false;
|
||||||
|
if (typeof settings.isMarkdown === 'undefined') return false;
|
||||||
|
return settings.isMarkdown;
|
||||||
|
}
|
||||||
|
|
||||||
|
setter(action) {
|
||||||
|
const actions = {
|
||||||
|
[cons.actions.settings.TOGGLE_MARKDOWN]: () => {
|
||||||
|
this.isMarkdown = !this.isMarkdown;
|
||||||
|
setSettings('isMarkdown', this.isMarkdown);
|
||||||
|
this.emit(cons.events.settings.MARKDOWN_TOGGLED, this.isMarkdown);
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
actions[action.type]?.();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const settings = new Settings();
|
const settings = new Settings();
|
||||||
|
appDispatcher.register(settings.setter.bind(settings));
|
||||||
|
|
||||||
export default settings;
|
export default settings;
|
||||||
|
|||||||
@@ -14,7 +14,10 @@
|
|||||||
--bg-primary-active: rgba(83, 110, 234, 70%);
|
--bg-primary-active: rgba(83, 110, 234, 70%);
|
||||||
--bg-primary-border: rgba(83, 110, 234, 38%);
|
--bg-primary-border: rgba(83, 110, 234, 38%);
|
||||||
|
|
||||||
--bg-positive: #45B83B;
|
--bg-positive: rgb(69, 184, 59);
|
||||||
|
--bg-positive-hover: rgba(69, 184, 59, 8%);
|
||||||
|
--bg-positive-active: rgba(69, 184, 59, 15%);
|
||||||
|
--bg-positive-border: rgba(69, 184, 59, 40%);
|
||||||
|
|
||||||
--bg-caution: rgb(255, 179, 0);
|
--bg-caution: rgb(255, 179, 0);
|
||||||
--bg-caution-hover: rgba(255, 179, 0, 8%);
|
--bg-caution-hover: rgba(255, 179, 0, 8%);
|
||||||
@@ -37,6 +40,10 @@
|
|||||||
--tc-primary-normal: rgba(255, 255, 255, 68%);
|
--tc-primary-normal: rgba(255, 255, 255, 68%);
|
||||||
--tc-primary-low: rgba(255, 255, 255, 40%);
|
--tc-primary-low: rgba(255, 255, 255, 40%);
|
||||||
|
|
||||||
|
--tc-positive-high: var(--bg-positive);
|
||||||
|
--tc-positive-normal: rgb(69, 184, 59, 80%);
|
||||||
|
--tc-positive-low: rgb(69, 184, 59, 60%);
|
||||||
|
|
||||||
--tc-caution-high: var(--bg-caution);
|
--tc-caution-high: var(--bg-caution);
|
||||||
--tc-caution-normal: rgb(255, 179, 0, 80%);
|
--tc-caution-normal: rgb(255, 179, 0, 80%);
|
||||||
--tc-caution-low: rgb(255, 179, 0, 60%);
|
--tc-caution-low: rgb(255, 179, 0, 60%);
|
||||||
@@ -53,6 +60,7 @@
|
|||||||
/* system icons | --ic-[background type]-[priority]: value */
|
/* system icons | --ic-[background type]-[priority]: value */
|
||||||
--ic-surface-normal: #626262;
|
--ic-surface-normal: #626262;
|
||||||
--ic-primary-normal: #ffffff;
|
--ic-primary-normal: #ffffff;
|
||||||
|
--ic-positive-normal: rgba(69, 184, 59, 80%);
|
||||||
--ic-caution-normal: rgba(255, 179, 0, 80%);
|
--ic-caution-normal: rgba(255, 179, 0, 80%);
|
||||||
--ic-danger-normal: rgba(240, 71, 71, 0.7);
|
--ic-danger-normal: rgba(240, 71, 71, 0.7);
|
||||||
|
|
||||||
@@ -81,6 +89,9 @@
|
|||||||
--bs-primary-border: inset 0 0 0 1px var(--bg-primary-border);
|
--bs-primary-border: inset 0 0 0 1px var(--bg-primary-border);
|
||||||
--bs-primary-outline: 0 0 0 2px var(--bg-primary-border);
|
--bs-primary-outline: 0 0 0 2px var(--bg-primary-border);
|
||||||
|
|
||||||
|
--bs-positive-border: inset 0 0 0 1px var(--bg-positive-border);
|
||||||
|
--bs-positive-outline: 0 0 0 2px var(--bg-positive-border);
|
||||||
|
|
||||||
--bs-caution-border: inset 0 0 0 1px var(--bg-caution-border);
|
--bs-caution-border: inset 0 0 0 1px var(--bg-caution-border);
|
||||||
--bs-caution-outline: 0 0 0 2px var(--bg-caution-border);
|
--bs-caution-outline: 0 0 0 2px var(--bg-caution-border);
|
||||||
|
|
||||||
@@ -210,6 +221,7 @@
|
|||||||
|
|
||||||
html {
|
html {
|
||||||
height: 100%;
|
height: 100%;
|
||||||
|
overflow: hidden;
|
||||||
}
|
}
|
||||||
|
|
||||||
body {
|
body {
|
||||||
|
|||||||
225
src/util/decryptE2ERoomKeys.js
Normal file
225
src/util/decryptE2ERoomKeys.js
Normal file
@@ -0,0 +1,225 @@
|
|||||||
|
// https://github.com/matrix-org/matrix-react-sdk/blob/e78a1adb6f1af2ea425b0bae9034fb7344a4b2e8/src/utils/MegolmExportEncryption.js
|
||||||
|
|
||||||
|
const subtleCrypto = window.crypto.subtle || window.crypto.webkitSubtle;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Make an Error object which has a friendlyText property which is already
|
||||||
|
* translated and suitable for showing to the user.
|
||||||
|
*
|
||||||
|
* @param {string} msg message for the exception
|
||||||
|
* @param {string} friendlyText
|
||||||
|
* @returns {Error}
|
||||||
|
*/
|
||||||
|
function friendlyError(msg, friendlyText) {
|
||||||
|
const e = new Error(msg);
|
||||||
|
e.friendlyText = friendlyText;
|
||||||
|
return e;
|
||||||
|
}
|
||||||
|
|
||||||
|
function cryptoFailMsg() {
|
||||||
|
return 'Your browser does not support the required cryptography extensions';
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Derive the AES and HMAC-SHA-256 keys for the file
|
||||||
|
*
|
||||||
|
* @param {Unit8Array} salt salt for pbkdf
|
||||||
|
* @param {Number} iterations number of pbkdf iterations
|
||||||
|
* @param {String} password password
|
||||||
|
* @return {Promise<[CryptoKey, CryptoKey]>} promise for [aes key, hmac key]
|
||||||
|
*/
|
||||||
|
async function deriveKeys(salt, iterations, password) {
|
||||||
|
const start = new Date();
|
||||||
|
|
||||||
|
let key;
|
||||||
|
try {
|
||||||
|
key = await subtleCrypto.importKey(
|
||||||
|
'raw',
|
||||||
|
new TextEncoder().encode(password),
|
||||||
|
{ name: 'PBKDF2' },
|
||||||
|
false,
|
||||||
|
['deriveBits'],
|
||||||
|
);
|
||||||
|
} catch (e) {
|
||||||
|
throw friendlyError(`subtleCrypto.importKey failed: ${e}`, cryptoFailMsg());
|
||||||
|
}
|
||||||
|
|
||||||
|
let keybits;
|
||||||
|
try {
|
||||||
|
keybits = await subtleCrypto.deriveBits(
|
||||||
|
{
|
||||||
|
name: 'PBKDF2',
|
||||||
|
salt,
|
||||||
|
iterations,
|
||||||
|
hash: 'SHA-512',
|
||||||
|
},
|
||||||
|
key,
|
||||||
|
512,
|
||||||
|
);
|
||||||
|
} catch (e) {
|
||||||
|
throw friendlyError(`subtleCrypto.deriveBits failed: ${e}`, cryptoFailMsg());
|
||||||
|
}
|
||||||
|
|
||||||
|
const now = new Date();
|
||||||
|
console.log(`E2e import/export: deriveKeys took ${(now - start)}ms`);
|
||||||
|
|
||||||
|
const aesKey = keybits.slice(0, 32);
|
||||||
|
const hmacKey = keybits.slice(32);
|
||||||
|
|
||||||
|
const aesProm = subtleCrypto.importKey(
|
||||||
|
'raw',
|
||||||
|
aesKey,
|
||||||
|
{ name: 'AES-CTR' },
|
||||||
|
false,
|
||||||
|
['encrypt', 'decrypt'],
|
||||||
|
).catch((e) => {
|
||||||
|
throw friendlyError(`subtleCrypto.importKey failed for AES key: ${e}`, cryptoFailMsg());
|
||||||
|
});
|
||||||
|
|
||||||
|
const hmacProm = subtleCrypto.importKey(
|
||||||
|
'raw',
|
||||||
|
hmacKey,
|
||||||
|
{
|
||||||
|
name: 'HMAC',
|
||||||
|
hash: { name: 'SHA-256' },
|
||||||
|
},
|
||||||
|
false,
|
||||||
|
['sign', 'verify'],
|
||||||
|
).catch((e) => {
|
||||||
|
throw friendlyError(`subtleCrypto.importKey failed for HMAC key: ${e}`, cryptoFailMsg());
|
||||||
|
});
|
||||||
|
|
||||||
|
// eslint-disable-next-line no-return-await
|
||||||
|
return await Promise.all([aesProm, hmacProm]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Decode a base64 string to a typed array of uint8.
|
||||||
|
* @param {string} base64 The base64 to decode.
|
||||||
|
* @return {Uint8Array} The decoded data.
|
||||||
|
*/
|
||||||
|
function decodeBase64(base64) {
|
||||||
|
// window.atob returns a unicode string with codepoints in the range 0-255.
|
||||||
|
const latin1String = window.atob(base64);
|
||||||
|
// Encode the string as a Uint8Array
|
||||||
|
const uint8Array = new Uint8Array(latin1String.length);
|
||||||
|
for (let i = 0; i < latin1String.length; i += 1) {
|
||||||
|
uint8Array[i] = latin1String.charCodeAt(i);
|
||||||
|
}
|
||||||
|
return uint8Array;
|
||||||
|
}
|
||||||
|
|
||||||
|
const HEADER_LINE = '-----BEGIN MEGOLM SESSION DATA-----';
|
||||||
|
const TRAILER_LINE = '-----END MEGOLM SESSION DATA-----';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Unbase64 an ascii-armoured megolm key file
|
||||||
|
*
|
||||||
|
* Strips the header and trailer lines, and unbase64s the content
|
||||||
|
*
|
||||||
|
* @param {ArrayBuffer} data input file
|
||||||
|
* @return {Uint8Array} unbase64ed content
|
||||||
|
*/
|
||||||
|
function unpackMegolmKeyFile(data) {
|
||||||
|
// parse the file as a great big String. This should be safe, because there
|
||||||
|
// should be no non-ASCII characters, and it means that we can do string
|
||||||
|
// comparisons to find the header and footer, and feed it into window.atob.
|
||||||
|
const fileStr = new TextDecoder().decode(new Uint8Array(data));
|
||||||
|
|
||||||
|
// look for the start line
|
||||||
|
let lineStart = 0;
|
||||||
|
while (1) {
|
||||||
|
const lineEnd = fileStr.indexOf('\n', lineStart);
|
||||||
|
if (lineEnd < 0) {
|
||||||
|
throw new Error('Header line not found');
|
||||||
|
}
|
||||||
|
const line = fileStr.slice(lineStart, lineEnd).trim();
|
||||||
|
|
||||||
|
// start the next line after the newline
|
||||||
|
lineStart = lineEnd + 1;
|
||||||
|
|
||||||
|
if (line === HEADER_LINE) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const dataStart = lineStart;
|
||||||
|
|
||||||
|
// look for the end line
|
||||||
|
while (1) {
|
||||||
|
const lineEnd = fileStr.indexOf('\n', lineStart);
|
||||||
|
const line = fileStr.slice(lineStart, lineEnd < 0 ? undefined : lineEnd).trim();
|
||||||
|
if (line === TRAILER_LINE) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (lineEnd < 0) {
|
||||||
|
throw new Error('Trailer line not found');
|
||||||
|
}
|
||||||
|
|
||||||
|
// start the next line after the newline
|
||||||
|
lineStart = lineEnd + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
const dataEnd = lineStart;
|
||||||
|
return decodeBase64(fileStr.slice(dataStart, dataEnd));
|
||||||
|
}
|
||||||
|
|
||||||
|
export default async function decryptMegolmKeyFile(data, password) {
|
||||||
|
const body = unpackMegolmKeyFile(data);
|
||||||
|
|
||||||
|
// check we have a version byte
|
||||||
|
if (body.length < 1) {
|
||||||
|
throw friendlyError('Invalid file: too short', 'Not a valid keyfile');
|
||||||
|
}
|
||||||
|
|
||||||
|
const version = body[0];
|
||||||
|
if (version !== 1) {
|
||||||
|
throw friendlyError('Unsupported version', 'Not a valid keyfile');
|
||||||
|
}
|
||||||
|
|
||||||
|
const ciphertextLength = body.length - (1 + 16 + 16 + 4 + 32);
|
||||||
|
if (ciphertextLength < 0) {
|
||||||
|
throw friendlyError('Invalid file: too short', 'Not a valid keyfile');
|
||||||
|
}
|
||||||
|
|
||||||
|
const salt = body.subarray(1, 1 + 16);
|
||||||
|
const iv = body.subarray(17, 17 + 16);
|
||||||
|
const iterations = body[33] << 24 | body[34] << 16 | body[35] << 8 | body[36];
|
||||||
|
const ciphertext = body.subarray(37, 37 + ciphertextLength);
|
||||||
|
const hmac = body.subarray(-32);
|
||||||
|
|
||||||
|
const [aesKey, hmacKey] = await deriveKeys(salt, iterations, password);
|
||||||
|
const toVerify = body.subarray(0, -32);
|
||||||
|
|
||||||
|
let isValid;
|
||||||
|
try {
|
||||||
|
isValid = await subtleCrypto.verify(
|
||||||
|
{ name: 'HMAC' },
|
||||||
|
hmacKey,
|
||||||
|
hmac,
|
||||||
|
toVerify,
|
||||||
|
);
|
||||||
|
} catch (e) {
|
||||||
|
throw friendlyError(`subtleCrypto.verify failed: ${e}`, cryptoFailMsg());
|
||||||
|
}
|
||||||
|
if (!isValid) {
|
||||||
|
throw friendlyError('hmac mismatch', 'Authentication check failed: Incorrect password?');
|
||||||
|
}
|
||||||
|
|
||||||
|
let plaintext;
|
||||||
|
try {
|
||||||
|
plaintext = await subtleCrypto.decrypt(
|
||||||
|
{
|
||||||
|
name: 'AES-CTR',
|
||||||
|
counter: iv,
|
||||||
|
length: 64,
|
||||||
|
},
|
||||||
|
aesKey,
|
||||||
|
ciphertext,
|
||||||
|
);
|
||||||
|
} catch (e) {
|
||||||
|
throw friendlyError(`subtleCrypto.decrypt failed: ${e}`, cryptoFailMsg());
|
||||||
|
}
|
||||||
|
|
||||||
|
return new TextDecoder().decode(new Uint8Array(plaintext));
|
||||||
|
}
|
||||||
@@ -55,9 +55,9 @@ module.exports = {
|
|||||||
devMode: 'light',
|
devMode: 'light',
|
||||||
favicons: {
|
favicons: {
|
||||||
appName: 'Cinny',
|
appName: 'Cinny',
|
||||||
appDescription: 'A matrix client',
|
appDescription: 'Yet another matrix client',
|
||||||
developerName: 'ajbura, 1997kB',
|
developerName: 'Ajay Bura',
|
||||||
developerURL: null,
|
developerURL: 'https://github.com/ajbura',
|
||||||
icons: {
|
icons: {
|
||||||
coast: false,
|
coast: false,
|
||||||
yandex: false,
|
yandex: false,
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ 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',
|
||||||
@@ -35,5 +36,11 @@ 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