├── .env.local.example ├── .eslintignore ├── .eslintrc.json ├── .github ├── dependabot.yml ├── images │ ├── screenshot.png │ └── screenshot_old.png ├── package.json.patch └── workflows │ ├── deploy-preview.yml │ ├── deploy.yml │ ├── fossa.yml │ ├── scorecards-analysis.yml │ └── spell-check.yml ├── .gitignore ├── .vscode └── settings.json ├── LICENSE ├── README.md ├── SECURITY.md ├── _typos.toml ├── index.html ├── package-lock.json ├── package.json ├── postcss.config.cjs ├── public ├── .well-known │ └── security.txt ├── Logo.svg ├── Logo_colored.svg ├── fonts │ ├── Inter-Black.woff2 │ ├── Inter-Bold.woff2 │ ├── Inter-ExtraBold.woff2 │ ├── Inter-ExtraLight.woff2 │ ├── Inter-Light.woff2 │ ├── Inter-Medium.woff2 │ ├── Inter-Regular.woff2 │ ├── Inter-SemiBold.woff2 │ ├── Inter-Thin.woff2 │ └── Inter-VariableFont_slnt,wght.woff2 ├── locales │ ├── de │ │ └── translation.json │ └── en │ │ └── translation.json └── tick.svg ├── scripts └── setup.mjs ├── src ├── app.test.tsx ├── app.tsx ├── components │ ├── Logo_colored.svg │ ├── header.tsx │ └── post.tsx ├── context.ts ├── data │ ├── post.ts │ └── user.ts ├── env.d.ts ├── i18n.ts ├── index.css ├── main.tsx ├── matrix │ ├── client.ts │ ├── events │ │ └── ImageEvent.ts │ └── workers │ │ └── indexeddb.worker.ts ├── pages │ ├── Home.tsx │ ├── Join.tsx │ ├── Post.tsx │ └── Profile.tsx ├── test │ └── setup.ts ├── utils │ ├── asyncImages.tsx │ ├── resources.ts │ └── test-utils.tsx └── vite-env.d.ts ├── tailwind.config.cjs ├── tsconfig.json ├── tsconfig.node.json ├── tsconfig.worker.json └── vite.config.ts /.env.local.example: -------------------------------------------------------------------------------- 1 | VITE_MATRIX_SERVER_URL=https://matrix.something.com 2 | VITE_MATRIX_ROOT_FOLDER=$root:something.com 3 | VITE_MATRIX_INSTANCE_ADMIN=@admin:something.com 4 | 5 | VITE_SEARCH_URL=http://127.0.0.1:7700 6 | MEILI_MASTER_KEY=xxx 7 | VITE_MEILI_SEARCH_KEY=xxx -------------------------------------------------------------------------------- /.eslintignore: -------------------------------------------------------------------------------- 1 | node_modules -------------------------------------------------------------------------------- /.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "plugins": [ 3 | "tailwindcss", 4 | "@typescript-eslint" 5 | ], 6 | "parser": "@typescript-eslint/parser", 7 | "extends": [ 8 | "eslint:recommended", 9 | "plugin:@typescript-eslint/recommended", 10 | "plugin:unicorn/recommended", 11 | "plugin:tailwindcss/recommended" 12 | ], 13 | "rules": { 14 | "no-unused-vars": "off", 15 | "@typescript-eslint/no-unused-vars": [ 16 | "warn", 17 | { 18 | "argsIgnorePattern": "^_" 19 | } 20 | ], 21 | "@typescript-eslint/ban-ts-comment": "off", 22 | "tailwindcss/classnames-order": "off", 23 | "unicorn/prevent-abbreviations": "off", 24 | "unicorn/filename-case": "off", 25 | "unicorn/prefer-ternary": "off", 26 | "unicorn/no-lonely-if": "off", 27 | "unicorn/empty-brace-spaces": "off", 28 | "unicorn/prefer-node-protocol": "off", 29 | "unicorn/import-style": [ 30 | "error", 31 | { 32 | "checkDynamicImport": false 33 | } 34 | ] 35 | } 36 | } -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | # Enable version updates for npm 4 | - package-ecosystem: "npm" 5 | # Look for `package.json` and `lock` files in the `root` directory 6 | directory: "/" 7 | # Check the npm registry for updates every day (weekdays) 8 | schedule: 9 | interval: "daily" 10 | reviewers: 11 | - "MTRNord" 12 | assignees: 13 | - "MTRNord" 14 | open-pull-requests-limit: 1000 15 | 16 | # Enable version updates for Docker 17 | - package-ecosystem: "docker" 18 | # Look for a `Dockerfile` in the `root` directory 19 | directory: "/" 20 | # Check for updates once a week 21 | schedule: 22 | interval: "weekly" 23 | reviewers: 24 | - "MTRNord" 25 | assignees: 26 | - "MTRNord" 27 | open-pull-requests-limit: 10 28 | 29 | # Enable version updates for GitHub Actions 30 | - package-ecosystem: "github-actions" 31 | directory: "/" 32 | # Check for updates once a week 33 | schedule: 34 | interval: "weekly" 35 | reviewers: 36 | - "MTRNord" 37 | assignees: 38 | - "MTRNord" 39 | open-pull-requests-limit: 10 40 | -------------------------------------------------------------------------------- /.github/images/screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MTRNord/matrix-art/00629d204977b1263335932df073d46fdcdbdb71/.github/images/screenshot.png -------------------------------------------------------------------------------- /.github/images/screenshot_old.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MTRNord/matrix-art/00629d204977b1263335932df073d46fdcdbdb71/.github/images/screenshot_old.png -------------------------------------------------------------------------------- /.github/package.json.patch: -------------------------------------------------------------------------------- 1 | 36c36 2 | < "browser": "./lib/browser-index.ts", 3 | --- 4 | > "browser": "./lib/browser-index.js", 5 | -------------------------------------------------------------------------------- /.github/workflows/deploy-preview.yml: -------------------------------------------------------------------------------- 1 | name: Build and Deploy Preview 2 | permissions: 3 | actions: none 4 | checks: none 5 | contents: read 6 | deployments: none 7 | id-token: none 8 | issues: none 9 | discussions: none 10 | packages: none 11 | pages: none 12 | pull-requests: write 13 | repository-projects: none 14 | security-events: none 15 | statuses: none 16 | on: 17 | pull_request: 18 | jobs: 19 | build-and-deploy: 20 | concurrency: ci-${{ github.ref }} 21 | runs-on: self-hosted 22 | steps: 23 | - name: Edit PR Description 24 | if: ${{ github.ref != 'refs/heads/main' }} 25 | uses: Beakyn/gha-comment-pull-request@2167a7aee24f9e61ce76a23039f322e49a990409 26 | env: 27 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 28 | with: 29 | pull-request-number: ${{ steps.readctx.outputs.prnumber }} 30 | description-message: | 31 | ---- 32 | ⌛ Deploy Preview - Build in Progress 33 | - name: Checkout 🛎️ 34 | if: ${{ github.ref != 'refs/heads/main' }} 35 | uses: actions/checkout@v3 36 | - uses: actions/setup-node@v3 37 | name: Setup node 38 | if: ${{ github.ref != 'refs/heads/main' }} 39 | with: 40 | node-version: "18" 41 | - name: Create env file 42 | if: ${{ github.ref != 'refs/heads/main' }} 43 | run: | 44 | echo "VITE_MATRIX_SERVER_URL=https://matrix.art.midnightthoughts.space" > .env.local 45 | echo "VITE_MATRIX_INSTANCE_ADMIN=@administrator:art.midnightthoughts.space" >> .env.local 46 | echo "VITE_MATRIX_ROOT_FOLDER=#Matrix_Art:art.midnightthoughts.space" >> .env.local 47 | - name: Install and Build 🔧 48 | if: ${{ github.ref != 'refs/heads/main' }} 49 | run: | 50 | apt-get update && apt-get install -y patch 51 | npm ci 52 | mv .github/package.json.patch node_modules/matrix-js-sdk/package.json.patch 53 | pushd node_modules/matrix-js-sdk/ 54 | patch package.json < package.json.patch 55 | popd 56 | npx tsc && npx vite build --base /pr-${{ github.event.pull_request.number }}/ 57 | - name: Deploy to gh-pages 58 | if: ${{ github.ref != 'refs/heads/main' }} 59 | uses: peaceiris/actions-gh-pages@v3 60 | with: 61 | deploy_key: ${{ secrets.ACTIONS_DEPLOY_KEY }} 62 | publish_dir: ./dist 63 | destination_dir: ./pr-${{ github.event.pull_request.number }} 64 | cname: preview.art.midnightthoughts.space 65 | external_repository: MTRNord/matrix-art-preview 66 | - name: Edit PR Description 67 | if: ${{ github.ref != 'refs/heads/main' }} 68 | uses: Beakyn/gha-comment-pull-request@2167a7aee24f9e61ce76a23039f322e49a990409 69 | env: 70 | BUILD_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} 71 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 72 | with: 73 | description-message: | 74 | ---- 75 | 😎 Browse the preview: https://preview.art.midnightthoughts.space/pr-${{ github.event.pull_request.number }} ! 76 | 🔍 Inspect the deploy log: ${{ env.BUILD_URL }} 77 | ⚠️ Do you trust the author of this PR? Maybe this build will steal your keys or give you malware. Exercise caution. Use test accounts. 78 | -------------------------------------------------------------------------------- /.github/workflows/deploy.yml: -------------------------------------------------------------------------------- 1 | name: Build and Deploy 2 | permissions: 3 | actions: none 4 | checks: none 5 | contents: write 6 | deployments: none 7 | id-token: none 8 | issues: none 9 | discussions: none 10 | packages: none 11 | pages: none 12 | pull-requests: none 13 | repository-projects: none 14 | security-events: none 15 | statuses: none 16 | on: 17 | push: 18 | branches: [main] 19 | jobs: 20 | build-and-deploy: 21 | concurrency: ci-${{ github.ref }} 22 | runs-on: self-hosted 23 | steps: 24 | - name: Checkout 🛎️ 25 | uses: actions/checkout@755da8c3cf115ac066823e79a1e1788f8940201b # v3.2.0 26 | - uses: actions/setup-node@8c91899e586c5b171469028077307d293428b516 # v3.5.1 27 | name: Setup node 28 | with: 29 | node-version: "18" 30 | - name: Create env file 31 | run: | 32 | echo "VITE_MATRIX_SERVER_URL=https://matrix.art.midnightthoughts.space" > .env.local 33 | echo "VITE_MATRIX_INSTANCE_ADMIN=@administrator:art.midnightthoughts.space" >> .env.local 34 | echo "VITE_MATRIX_ROOT_FOLDER=#Matrix_Art:art.midnightthoughts.space" >> .env.local 35 | - name: Install and Build 🔧 36 | run: | 37 | apt-get update && apt-get install -y patch 38 | npm ci 39 | mv .github/package.json.patch node_modules/matrix-js-sdk/package.json.patch 40 | pushd node_modules/matrix-js-sdk/ 41 | patch package.json < package.json.patch 42 | popd 43 | npm run build 44 | - name: Deploy 🚀 45 | uses: JamesIves/github-pages-deploy-action@ba1486788b0490a235422264426c45848eac35c6 # v4.4.1 46 | env: 47 | BUILD_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} 48 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 49 | with: 50 | branch: gh-pages # The branch the action should deploy to. 51 | folder: dist # The folder the action should deploy. 52 | -------------------------------------------------------------------------------- /.github/workflows/fossa.yml: -------------------------------------------------------------------------------- 1 | name: Fossa Scan 2 | permissions: read-all 3 | on: 4 | push: 5 | branches: [main] 6 | jobs: 7 | fossa-scan: 8 | runs-on: self-hosted 9 | steps: 10 | # - name: Harden Runner 11 | # uses: step-security/harden-runner@bdb12b622a910dfdc99a31fdfe6f45a16bc287a4 # v1 12 | # with: 13 | # allowed-endpoints: " 14 | # app.fossa.com:443 15 | # github.com:443 16 | # objects.githubusercontent.com:443 17 | # raw.githubusercontent.com:443" 18 | # env: 19 | # USER: runner 20 | - uses: actions/checkout@629c2de402a417ea7690ca6ce3f33229e27606a5 # v2 21 | - uses: fossas/fossa-action@f61a4c0c263690f2ddb54b9822a719c25a7b608f # main 22 | with: 23 | api-key: ${{secrets.fossaApiKey}} 24 | -------------------------------------------------------------------------------- /.github/workflows/scorecards-analysis.yml: -------------------------------------------------------------------------------- 1 | name: Scorecards supply-chain security 2 | on: 3 | # Only the default branch is supported. 4 | branch_protection_rule: 5 | schedule: 6 | - cron: "15 7 * * 0" 7 | push: 8 | branches: [main] 9 | 10 | # Declare default permissions as read only. 11 | permissions: read-all 12 | 13 | jobs: 14 | analysis: 15 | name: Scorecards analysis 16 | runs-on: self-hosted 17 | permissions: 18 | # Needed to upload the results to code-scanning dashboard. 19 | security-events: write 20 | actions: read 21 | contents: read 22 | 23 | steps: 24 | - name: "Checkout code" 25 | uses: actions/checkout@ec3a7ce113134d7a93b817d10a8272cb61118579 # v2.4.0 26 | with: 27 | persist-credentials: false 28 | 29 | - name: "Run analysis" 30 | uses: ossf/scorecard-action@c1aec4ac820532bab364f02a81873c555a0ba3a1 # v1.0.1 31 | with: 32 | results_file: results.sarif 33 | results_format: sarif 34 | # Read-only PAT token. To create it, 35 | # follow the steps in https://github.com/ossf/scorecard-action#pat-token-creation. 36 | repo_token: ${{ secrets.SCORECARD_READ_TOKEN }} 37 | # Publish the results to enable scorecard badges. For more details, see 38 | # https://github.com/ossf/scorecard-action#publishing-results. 39 | # For private repositories, `publish_results` will automatically be set to `false`, 40 | # regardless of the value entered here. 41 | publish_results: true 42 | 43 | # Upload the results as artifacts (optional). 44 | - name: "Upload artifact" 45 | uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # v2.3.1 46 | with: 47 | name: SARIF file 48 | path: results.sarif 49 | retention-days: 5 50 | 51 | # Upload the results to GitHub's code scanning dashboard. 52 | - name: "Upload to code-scanning" 53 | uses: github/codeql-action/upload-sarif@a34ca99b4610d924e04c68db79e503e1f79f9f02 # v1.0.26 54 | with: 55 | sarif_file: results.sarif 56 | -------------------------------------------------------------------------------- /.github/workflows/spell-check.yml: -------------------------------------------------------------------------------- 1 | name: Spell Check 2 | on: 3 | push: 4 | branches: 5 | - "main" 6 | pull_request: 7 | 8 | # Declare default permissions as read only. 9 | permissions: read-all 10 | 11 | jobs: 12 | run: 13 | permissions: 14 | contents: read # for actions/checkout to fetch code 15 | name: Spell Check with Typos 16 | runs-on: self-hosted 17 | steps: 18 | # - name: Harden Runner 19 | # uses: step-security/harden-runner@bdb12b622a910dfdc99a31fdfe6f45a16bc287a4 # v1 20 | # with: 21 | # egress-policy: block 22 | # allowed-endpoints: github.com:443 23 | # env: 24 | # USER: runner 25 | - name: Checkout Actions Repository 26 | uses: actions/checkout@629c2de402a417ea7690ca6ce3f33229e27606a5 # v2 27 | 28 | - name: Check spelling 29 | uses: crate-ci/typos@927308c726b1fba730f7aaa8bde602148b82004d # master 30 | with: 31 | config: ${{github.workspace}}/_typos.toml 32 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | /.pnp 6 | .pnp.js 7 | 8 | # testing 9 | /coverage 10 | 11 | # next.js 12 | /.next/ 13 | /out/ 14 | 15 | # production 16 | /build 17 | 18 | # misc 19 | .DS_Store 20 | *.pem 21 | 22 | # debug 23 | npm-debug.log* 24 | yarn-debug.log* 25 | yarn-error.log* 26 | 27 | # local env files 28 | .env.local 29 | .env.development.local 30 | .env.test.local 31 | .env.production.local 32 | 33 | # Logs 34 | logs 35 | *.log 36 | npm-debug.log* 37 | yarn-debug.log* 38 | yarn-error.log* 39 | pnpm-debug.log* 40 | lerna-debug.log* 41 | 42 | node_modules 43 | dist 44 | dist-ssr 45 | *.local 46 | 47 | # Editor directories and files 48 | .vscode/* 49 | !.vscode/extensions.json 50 | .idea 51 | .DS_Store 52 | *.suo 53 | *.ntvs* 54 | *.njsproj 55 | *.sln 56 | *.sw? 57 | 58 | #pouchdb 59 | /matrix-art-db 60 | /localstorage 61 | #nextjs 62 | .env.*.local 63 | .env.local 64 | test-results/ 65 | playwright-report/ 66 | /meilifiles -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "yaml.schemas": { 3 | "https://json.schemastore.org/github-workflow.json": "file:///c%3A/Users/marce/WebstormProjects/matrix-art/.github/workflows/deploy.yml" 4 | } 5 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![Total alerts](https://img.shields.io/lgtm/alerts/g/MTRNord/matrix-art.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/MTRNord/matrix-art/alerts/) [![Language grade: JavaScript](https://img.shields.io/lgtm/grade/javascript/g/MTRNord/matrix-art.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/MTRNord/matrix-art/context:javascript) 2 | [![#matrix-art:nordgedanken.dev](https://img.shields.io/matrix/matrix-art:nordgedanken.dev?server_fqdn=matrix.nordgedanken.dev&label=%23matrix-art:nordgedanken.dev&logo=matrix)](https://matrix.to/#/#matrix-art:nordgedanken.dev) 3 | 4 | # Matrix-Art 5 | 6 | Matrix-Art is an image gallery for Matrix. 7 | 8 | ![Screenshot](.github/images/screenshot.png) 9 | 10 | ## Concept (roughly) 11 | 12 | https://scythe-pink-090.notion.site/Art-MX-Fediverse-Devianart-148d45b596e74582acff518baadd3026 13 | 14 | ## Demo Page 15 | 16 | https://art.midnightthoughts.space/ 17 | 18 | ## How to install 19 | 20 | ### Prerequisites 21 | 22 | - Nodejs 23 | - A Matrix Server with public registration 24 | - A Matrix Server with guests enabled 25 | - A Matrix Server with dynamic thumbnails 26 | - A Meillisearch server (See https://meilisearch.com for more information) 27 | 28 | ### Steps 29 | 30 | 1. Copy the `.env.local.example` to `.env.local` or set the `NEXT_PUBLIC_DEFAULT_SERVER_URL` variable. 31 | 2. Run `npm run dev` or build and run the Dockerimage 32 | 33 | ## Translations 34 | 35 | Translations can be contributed via https://trans.nordgedanken.dev/projects/matrix-art/matrix-art/ 36 | 37 | ![Übersetzungsstatus](https://trans.nordgedanken.dev/widgets/matrix-art/-/matrix-art/multi-auto.svg) -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | # Security Policy 2 | 3 | ## Supported Versions 4 | 5 | (Note this is currently alpha) 6 | 7 | 8 | 9 | 10 | | Version | Supported | 11 | | ------- | ------------------ | 12 | | main | :x: | 13 | 14 | ## Reporting a Vulnerability 15 | 16 | For people liking automation, there is https://art.midnightthoughts.space/.well-known/security.txt available. 17 | 18 | A security report should be written in English. 19 | German also is fine for me but should be avoided. 20 | Other languages will not be accepted, as I don't speak those. 21 | 22 | A report should contain the affected version, what is affected, how it is affected and if you know a solution please share it with me, so I can react quickly. 23 | 24 | Please also follow the responsible disclosure concept. I will try to react as fast as possible. However, please keep in mind this is a Hobby project, so I may not react within 48h. 25 | 26 | To contact me, please use **ONLY** one of these options: 27 | 28 | **Matrix:** matrix:u/mtrnord:nordgedanken.dev (Or https://matrix.to/#/@mtrnord:nordgedanken.dev ) 29 | 30 | **Email:** mailto:mtrnord[AT]nordgedanken.dev 31 | 32 | Please **DO NOT** under any circumstance do it via GitHub issues as this will leak the report to the public! 33 | 34 | For any further issues, please open an Issue or join https://matrix.to/#/#matrix-art:nordgedanken.dev 35 | -------------------------------------------------------------------------------- /_typos.toml: -------------------------------------------------------------------------------- 1 | [files] 2 | extend-exclude = [ 3 | "*.json", 4 | "*.svg", 5 | "localstorage/**", 6 | "node_modules/**", 7 | "matrix-art-db/**", 8 | ".next/**" 9 | ] 10 | 11 | [default] 12 | locale = "en" 13 | 14 | [default.extend-words] 15 | ND = "ND" -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Matrix Art 10 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "matrix-art", 3 | "private": true, 4 | "version": "0.0.0", 5 | "type": "module", 6 | "scripts": { 7 | "dev": "vite", 8 | "build": "tsc && vite build", 9 | "preview": "vite preview", 10 | "lint": "eslint src --ext .js,.jsx,.ts,.tsx", 11 | "coverage": "vitest run --coverage", 12 | "test": "vitest", 13 | "test:ui": "vitest --ui" 14 | }, 15 | "dependencies": { 16 | "@matrix-org/olm": "https://gitlab.matrix.org/api/v4/projects/27/packages/npm/@matrix-org/olm/-/@matrix-org/olm-3.2.14.tgz", 17 | "buffer": "^6.0.3", 18 | "events": "^3.3.0", 19 | "i18next": "^22.4.9", 20 | "i18next-browser-languagedetector": "^7.0.1", 21 | "i18next-http-backend": "^2.1.1", 22 | "inquirer": "^9.1.4", 23 | "matrix-events-sdk": "^0.0.1", 24 | "matrix-js-sdk": "^23.0.0", 25 | "react": "^18.2.0", 26 | "react-dom": "^18.2.0", 27 | "react-i18next": "^12.1.4", 28 | "react-plock": "github:MTRNord/react-plock#MTRNord/patch-react", 29 | "react-router-dom": "^6.7.0", 30 | "react-spinners": "^0.13.8" 31 | }, 32 | "devDependencies": { 33 | "@testing-library/jest-dom": "^5.16.5", 34 | "@testing-library/react": "^13.4.0", 35 | "@testing-library/user-event": "^14.4.3", 36 | "@types/events": "^3.0.0", 37 | "@types/react": "^18.0.27", 38 | "@types/react-dom": "^18.0.10", 39 | "@typescript-eslint/eslint-plugin": "^5.48.2", 40 | "@typescript-eslint/parser": "^5.48.2", 41 | "@vitejs/plugin-react-swc": "^3.0.1", 42 | "@vitest/ui": "^0.27.3", 43 | "autoprefixer": "^10.4.13", 44 | "eslint": "^8.32.0", 45 | "eslint-plugin-tailwindcss": "^3.8.0", 46 | "eslint-plugin-unicorn": "^45.0.2", 47 | "jsdom": "^21.1.0", 48 | "postcss": "^8.4.21", 49 | "tailwindcss": "^3.2.4", 50 | "typescript": "^4.9.4", 51 | "vite": "^4.0.5", 52 | "vite-plugin-ejs": "^1.6.4", 53 | "vitest": "^0.27.3" 54 | } 55 | } -------------------------------------------------------------------------------- /postcss.config.cjs: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | plugins: { 3 | tailwindcss: {}, 4 | autoprefixer: {}, 5 | }, 6 | } 7 | -------------------------------------------------------------------------------- /public/.well-known/security.txt: -------------------------------------------------------------------------------- 1 | Contact: mailto:mtrnord@nordgedanken.dev 2 | Contact: matrix:u/mtrnord:nordgedanken.dev 3 | Contact: https://matrix.to/#/@mtrnord:nordgedanken.dev 4 | Expires: 2176-02-14T11:04:00.000Z 5 | Preferred-Languages: en 6 | Canonical: https://art.midnightthoughts.space/.well-known/security.txt 7 | -------------------------------------------------------------------------------- /public/Logo.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /public/Logo_colored.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | 9 | 12 | 15 | 18 | 21 | 24 | 27 | 30 | 31 | 32 | 34 | 35 | 37 | 38 | 39 | 40 | 41 | 43 | 44 | 45 | 46 | 47 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | -------------------------------------------------------------------------------- /public/fonts/Inter-Black.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MTRNord/matrix-art/00629d204977b1263335932df073d46fdcdbdb71/public/fonts/Inter-Black.woff2 -------------------------------------------------------------------------------- /public/fonts/Inter-Bold.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MTRNord/matrix-art/00629d204977b1263335932df073d46fdcdbdb71/public/fonts/Inter-Bold.woff2 -------------------------------------------------------------------------------- /public/fonts/Inter-ExtraBold.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MTRNord/matrix-art/00629d204977b1263335932df073d46fdcdbdb71/public/fonts/Inter-ExtraBold.woff2 -------------------------------------------------------------------------------- /public/fonts/Inter-ExtraLight.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MTRNord/matrix-art/00629d204977b1263335932df073d46fdcdbdb71/public/fonts/Inter-ExtraLight.woff2 -------------------------------------------------------------------------------- /public/fonts/Inter-Light.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MTRNord/matrix-art/00629d204977b1263335932df073d46fdcdbdb71/public/fonts/Inter-Light.woff2 -------------------------------------------------------------------------------- /public/fonts/Inter-Medium.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MTRNord/matrix-art/00629d204977b1263335932df073d46fdcdbdb71/public/fonts/Inter-Medium.woff2 -------------------------------------------------------------------------------- /public/fonts/Inter-Regular.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MTRNord/matrix-art/00629d204977b1263335932df073d46fdcdbdb71/public/fonts/Inter-Regular.woff2 -------------------------------------------------------------------------------- /public/fonts/Inter-SemiBold.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MTRNord/matrix-art/00629d204977b1263335932df073d46fdcdbdb71/public/fonts/Inter-SemiBold.woff2 -------------------------------------------------------------------------------- /public/fonts/Inter-Thin.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MTRNord/matrix-art/00629d204977b1263335932df073d46fdcdbdb71/public/fonts/Inter-Thin.woff2 -------------------------------------------------------------------------------- /public/fonts/Inter-VariableFont_slnt,wght.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MTRNord/matrix-art/00629d204977b1263335932df073d46fdcdbdb71/public/fonts/Inter-VariableFont_slnt,wght.woff2 -------------------------------------------------------------------------------- /public/locales/de/translation.json: -------------------------------------------------------------------------------- 1 | { 2 | "Loading…": "Laden…", 3 | "Login": "Anmelden", 4 | "Register": "Registrieren", 5 | "Search": "Suchen", 6 | "Join": "Beitreten", 7 | "Post": "Veröffentlichen", 8 | "Homeserver": "Heimserver", 9 | "Username": "Benutzername", 10 | "Password": "Passwort", 11 | "Create account": "Benutzer anlegen", 12 | "Explore": "Entdecken" 13 | } 14 | -------------------------------------------------------------------------------- /public/locales/en/translation.json: -------------------------------------------------------------------------------- 1 | { 2 | "Loading…": "Loading…", 3 | "Login": "Login", 4 | "Register": "Register", 5 | "Search": "Search", 6 | "Join": "Join", 7 | "Post": "Post", 8 | "Homeserver": "Homeserver", 9 | "Username": "Username", 10 | "Password": "Password", 11 | "Create account": "Create account", 12 | "Explore": "Explore" 13 | } -------------------------------------------------------------------------------- /public/tick.svg: -------------------------------------------------------------------------------- 1 | 2 | 4 | -------------------------------------------------------------------------------- /scripts/setup.mjs: -------------------------------------------------------------------------------- 1 | import Olm from '@matrix-org/olm'; 2 | global.Olm = Olm; 3 | 4 | import inquirer from 'inquirer'; 5 | import { 6 | MemoryCryptoStore, 7 | MemoryStore, 8 | createClient, 9 | Preset, 10 | EventType, 11 | RoomCreateTypeField, 12 | RoomType, 13 | UNSTABLE_MSC3088_PURPOSE, 14 | UNSTABLE_MSC3089_TREE_SUBTYPE, 15 | UNSTABLE_MSC3088_ENABLED 16 | } from 'matrix-js-sdk'; 17 | import { MEGOLM_ALGORITHM } from 'matrix-js-sdk/lib/crypto/olmlib.js'; 18 | import { DEFAULT_TREE_POWER_LEVELS_TEMPLATE } from 'matrix-js-sdk/lib/models/MSC3089TreeSpace.js'; 19 | import { AutoDiscovery } from 'matrix-js-sdk/lib/autodiscovery.js'; 20 | import fs from 'fs'; 21 | 22 | console.info(`Welcome to setting up your Matrix Art instance. 23 | This will generate the required things for your instance. 24 | It will generate the room directory and the config file. 25 | You will need a user account that is the admin of your instance. We recommend to use a mjolnir. 26 | You will need to provide the following information:`); 27 | const replies = await inquirer.prompt([ 28 | { 29 | type: 'input', 30 | name: 'instance_name', 31 | message: 'What is the instance Name?', 32 | default: "Matrix Art", 33 | }, 34 | { 35 | type: 'input', 36 | name: 'homeserver', 37 | message: 'What is the instance Homeserver?', 38 | default: undefined, 39 | }, 40 | { 41 | type: 'input', 42 | name: 'admin_user', 43 | message: 'What is the admin user\'s full MXID?', 44 | default: undefined, 45 | }, 46 | { 47 | type: 'password', 48 | name: 'admin_password', 49 | message: 'What is the admin user\'s password? (not going to be stored)', 50 | default: undefined, 51 | }, 52 | ]); 53 | 54 | // Check inputs 55 | console.info("Checking inputs..."); 56 | if (replies.homeserver === undefined || replies.admin_user === undefined || replies.admin_password === undefined || replies.instance_name === undefined) { 57 | console.error('Please fill in all fields'); 58 | process.exit(1); 59 | } 60 | if (replies.homeserver.lastIndexOf('https://', 0) !== 0 && replies.homeserver.lastIndexOf('http://', 0) !== 0) { 61 | console.error('Please enter a valid homeserver url'); 62 | process.exit(1); 63 | } 64 | if (replies.admin_user.lastIndexOf('@', 0) !== 0) { 65 | console.error('Please enter a valid admin user'); 66 | process.exit(1); 67 | } 68 | 69 | await Olm.init(); 70 | 71 | // Matrix stuff 72 | console.info("Connecting to homeserver..."); 73 | const client = createClient({ 74 | useAuthorizationHeader: true, 75 | baseUrl: replies.homeserver, 76 | userId: replies.admin_user, 77 | deviceId: "MatrixArtSetup", 78 | sessionStore: new MemoryStore(), 79 | cryptoStore: new MemoryCryptoStore() 80 | }); 81 | 82 | await client.loginWithPassword(replies.admin_user, replies.admin_password); 83 | await client.initCrypto(); 84 | await client.startClient(); 85 | 86 | // Create room 87 | console.info("Creating root room..."); 88 | await client.createRoom({ 89 | name: replies.instance_name, 90 | preset: Preset.PublicChat, 91 | power_level_content_override: { 92 | ...DEFAULT_TREE_POWER_LEVELS_TEMPLATE, 93 | events: { 94 | [EventType.SpaceChild]: 0, 95 | }, 96 | users: { 97 | [client.getUserId()]: 100, 98 | }, 99 | }, 100 | creation_content: { 101 | [RoomCreateTypeField]: RoomType.Space, 102 | }, 103 | room_alias_name: replies.instance_name.replace(" ", "_"), 104 | initial_state: [ 105 | { 106 | type: UNSTABLE_MSC3088_PURPOSE.name, 107 | state_key: UNSTABLE_MSC3089_TREE_SUBTYPE.name, 108 | content: { 109 | [UNSTABLE_MSC3088_ENABLED.name]: true, 110 | }, 111 | }, 112 | { 113 | type: EventType.RoomEncryption, 114 | state_key: "", 115 | content: { 116 | algorithm: MEGOLM_ALGORITHM, 117 | }, 118 | }, 119 | { 120 | type: EventType.RoomGuestAccess, 121 | state_key: "", 122 | content: { 123 | guest_access: "can_join", 124 | }, 125 | }, 126 | { 127 | type: EventType.RoomHistoryVisibility, 128 | state_key: "", 129 | content: { 130 | history_visibility: "world_readable", 131 | }, 132 | } 133 | ], 134 | }); 135 | 136 | const wellKnown = await AutoDiscovery.getRawClientConfig(replies.homeserver); 137 | 138 | // Write config 139 | console.info("Writing config..."); 140 | fs.writeFileSync('./.env.local', `VITE_MATRIX_SERVER_URL="${replies.homeserver}" 141 | VITE_MATRIX_INSTANCE_ADMIN="${replies.admin_user}" 142 | VITE_MATRIX_ROOT_FOLDER="#${replies.instance_name.replace(" ", "_")}:${wellKnown['m.homeserver']}")}"`); 143 | 144 | console.info("Your instance is ready! Have fun!"); 145 | process.exit(0); 146 | 147 | //TODO: Allow upgrading the room with this script if the matrix art requirements change -------------------------------------------------------------------------------- /src/app.test.tsx: -------------------------------------------------------------------------------- 1 | import { App } from './app' 2 | import { render, screen } from './utils/test-utils' 3 | 4 | describe('First load tests', () => { 5 | it('The Explore page is default', () => { 6 | render() 7 | expect(screen.getByText(/Explore/i)).toBeInTheDocument() 8 | }) 9 | }) -------------------------------------------------------------------------------- /src/app.tsx: -------------------------------------------------------------------------------- 1 | import { lazy, useEffect, Suspense, useState } from 'react'; 2 | import { Home } from './pages/Home'; 3 | import { Client } from './context'; 4 | import { Header } from './components/header'; 5 | import { MatrixClient } from './matrix/client'; 6 | 7 | // eslint-disable-next-line @typescript-eslint/ban-ts-comment 8 | // @ts-ignore 9 | import olmWasmPath from "@matrix-org/olm/olm.wasm?url"; 10 | import OlmLegacy from '@matrix-org/olm/olm_legacy.js?url'; 11 | import Olm from '@matrix-org/olm'; 12 | import { Route, Routes } from 'react-router-dom'; 13 | import { useTranslation } from 'react-i18next'; 14 | 15 | const Join = lazy(() => import("./pages/Join")); 16 | const Post = lazy(() => import("./pages/Post")); 17 | const Profile = lazy(() => import("./pages/Profile")); 18 | 19 | 20 | const loadOlm = (): Promise => { 21 | /* Load Olm. We try the WebAssembly version first, and then the legacy */ 22 | return Olm.init({ 23 | locateFile: () => olmWasmPath, 24 | }).then(() => { 25 | console.log("Using WebAssembly Olm"); 26 | }).catch((error) => { 27 | console.log("Failed to load Olm: trying legacy version", error); 28 | return new Promise((resolve, reject) => { 29 | const s = document.createElement('script'); 30 | s.src = OlmLegacy; // XXX: This should be cache-busted too 31 | s.addEventListener('load', resolve); 32 | s.addEventListener('error', reject); 33 | document.body.append(s); 34 | }).then(() => { 35 | // Init window.Olm, ie. the one just loaded by the script tag, 36 | // not 'Olm' which is still the failed wasm version. 37 | return window.Olm.init(); 38 | }).then(() => { 39 | console.log("Using legacy Olm"); 40 | }).catch((error) => { 41 | console.log("Both WebAssembly and asm.js Olm failed!", error); 42 | }); 43 | }); 44 | }; 45 | 46 | 47 | export function App() { 48 | // eslint-disable-next-line unicorn/no-useless-undefined 49 | const [client, setClient] = useState(undefined); 50 | 51 | const loadMatrixClient = async () => { 52 | const client = await MatrixClient.new(); 53 | setClient(client); 54 | console.log("Client loaded"); 55 | await client?.start(); 56 | console.log("Client started"); 57 | } 58 | 59 | useEffect(() => { 60 | async function loadMatrix() { 61 | try { 62 | await loadOlm(); 63 | console.log("Olm loaded"); 64 | } catch { 65 | console.log("Olm not loaded"); 66 | } 67 | await loadMatrixClient(); 68 | } 69 | 70 | if (client == undefined) { 71 | loadMatrix(); 72 | } 73 | }, []); 74 | 75 | return ( 76 | 79 | 80 | } /> 81 | }> 83 | 84 | 85 | } /> 86 | }> 88 | 89 | 90 | } /> 91 | }> 93 | 94 | 95 | } /> 96 | 97 | 98 | ); 99 | } 100 | 101 | function LoadingPage() { 102 | const { t } = useTranslation(); 103 | 104 | return ( 105 |
106 |
107 |
108 |
109 |
110 |

{t('Loading…')}

111 |
112 |
113 | ); 114 | } -------------------------------------------------------------------------------- /src/components/Logo_colored.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | 9 | 12 | 15 | 18 | 21 | 24 | 27 | 30 | 31 | 32 | 34 | 35 | 37 | 38 | 39 | 40 | 41 | 43 | 44 | 45 | 46 | 47 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | -------------------------------------------------------------------------------- /src/components/header.tsx: -------------------------------------------------------------------------------- 1 | import { Link } from "react-router-dom"; 2 | import { useContext } from "react"; 3 | import { Client } from "../context"; 4 | import logo_url from "./Logo_colored.svg"; 5 | import { useTranslation } from "react-i18next"; 6 | 7 | export function Header() { 8 | const client = useContext(Client); 9 | const { t } = useTranslation(); 10 | 11 | return ( 12 |
13 | Matrix Art 14 |
15 |
16 |
17 | 18 | 19 | 20 | 21 |
22 | 23 |
24 | { 25 | 26 | client?.isLoggedIn() ? {t('Post')} : 27 | {t('Join')} 28 | } 29 | 30 |
31 |
32 | ); 33 | } -------------------------------------------------------------------------------- /src/components/post.tsx: -------------------------------------------------------------------------------- 1 | import { Suspense } from "react"; 2 | import { PostData } from "../data/post"; 3 | import { UserData } from "../data/user"; 4 | import { SuspenseImage } from "../utils/asyncImages"; 5 | import { BounceLoader } from "react-spinners"; 6 | import { Link } from "react-router-dom"; 7 | 8 | type Props = { 9 | user: UserData; 10 | post: PostData; 11 | }; 12 | 13 | export function Post({ user, post }: Props) { 14 | 15 | return ( 16 | }> 17 |
18 | 19 | 20 | 21 |
22 | 23 | 24 |

{user.display_name}

25 | 26 | 46 |
47 |
48 |
49 | ); 50 | } -------------------------------------------------------------------------------- /src/context.ts: -------------------------------------------------------------------------------- 1 | import { MatrixClient } from "./matrix/client"; 2 | import { createContext } from "react"; 3 | 4 | export const Client = createContext(undefined); -------------------------------------------------------------------------------- /src/data/post.ts: -------------------------------------------------------------------------------- 1 | import { ImageEvent } from "../matrix/events/ImageEvent"; 2 | 3 | export class PostData { 4 | public readonly event_id: string; 5 | public readonly content: ImageEvent; 6 | constructor(event_id: string, content: ImageEvent) { 7 | this.event_id = event_id; 8 | this.content = content; 9 | } 10 | } -------------------------------------------------------------------------------- /src/data/user.ts: -------------------------------------------------------------------------------- 1 | export class UserData { 2 | public readonly mxid: string; 3 | public readonly display_name: string; 4 | public readonly avatar_url: string; 5 | 6 | constructor(mxid: string, display_name: string, avatar_url: string) { 7 | this.mxid = mxid; 8 | this.display_name = display_name; 9 | this.avatar_url = avatar_url; 10 | } 11 | } -------------------------------------------------------------------------------- /src/env.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | interface ImportMetaEnv { 4 | readonly VITE_MATRIX_SERVER_URL: string; 5 | readonly VITE_MATRIX_ROOT_FOLDER: string; 6 | readonly VITE_MATRIX_INSTANCE_ADMIN: string; 7 | } 8 | 9 | interface ImportMeta { 10 | readonly env: ImportMetaEnv; 11 | } 12 | -------------------------------------------------------------------------------- /src/i18n.ts: -------------------------------------------------------------------------------- 1 | import i18n from 'i18next'; 2 | import { initReactI18next } from 'react-i18next'; 3 | 4 | import Backend from 'i18next-http-backend'; 5 | import LanguageDetector from 'i18next-browser-languagedetector'; 6 | 7 | // don't want to use this? 8 | // have a look at the Quick start guide 9 | // for passing in lng and translations on init 10 | 11 | i18n 12 | // load translation using http -> see /public/locales (i.e. https://github.com/i18next/react-i18next/tree/master/example/react/public/locales) 13 | // learn more: https://github.com/i18next/i18next-http-backend 14 | // want your translations to be loaded from a professional CDN? => https://github.com/locize/react-tutorial#step-2---use-the-locize-cdn 15 | .use(Backend) 16 | // detect user language 17 | // learn more: https://github.com/i18next/i18next-browser-languageDetector 18 | .use(LanguageDetector) 19 | // pass the i18n instance to react-i18next. 20 | .use(initReactI18next) 21 | // init i18next 22 | // for all options read: https://www.i18next.com/overview/configuration-options 23 | .init({ 24 | fallbackLng: 'en', 25 | debug: true, 26 | 27 | interpolation: { 28 | escapeValue: false, // not needed for react as it escapes by default 29 | } 30 | }); 31 | 32 | export { default } from 'i18next'; -------------------------------------------------------------------------------- /src/index.css: -------------------------------------------------------------------------------- 1 | @tailwind base; 2 | @tailwind components; 3 | @tailwind utilities; 4 | 5 | @supports not (font-variation-settings: normal) { 6 | @font-face { 7 | font-family: "Inter"; 8 | font-style: normal; 9 | font-weight: 100; 10 | font-display: optional; 11 | src: url(/fonts/Inter-Thin.woff2) format("woff2") 12 | } 13 | 14 | @font-face { 15 | font-family: "Inter"; 16 | font-style: normal; 17 | font-weight: 200; 18 | font-display: optional; 19 | src: url(/fonts/Inter-ExtraLight.woff2) format("woff2") 20 | } 21 | 22 | @font-face { 23 | font-family: "Inter"; 24 | font-style: normal; 25 | font-weight: 300; 26 | font-display: optional; 27 | src: url(/fonts/Inter-Light.woff2) format("woff2") 28 | } 29 | 30 | @font-face { 31 | font-family: "Inter"; 32 | font-style: normal; 33 | font-weight: 400; 34 | font-display: optional; 35 | src: url(/fonts/Inter-Regular.woff2) format("woff2") 36 | } 37 | 38 | @font-face { 39 | font-family: "Inter"; 40 | font-style: normal; 41 | font-weight: 500; 42 | font-display: optional; 43 | src: url(/fonts/Inter-Medium.woff2) format("woff2") 44 | } 45 | 46 | @font-face { 47 | font-family: "Inter"; 48 | font-style: normal; 49 | font-weight: 600; 50 | font-display: optional; 51 | src: url(/fonts/Inter-SemiBold.woff2) format("woff2") 52 | } 53 | 54 | @font-face { 55 | font-family: "Inter"; 56 | font-style: normal; 57 | font-weight: 700; 58 | font-display: optional; 59 | src: url(/fonts/Inter-Bold.woff2) format("woff2") 60 | } 61 | 62 | @font-face { 63 | font-family: "Inter"; 64 | font-style: normal; 65 | font-weight: 800; 66 | font-display: optional; 67 | src: url(/fonts/Inter-ExtraBold.woff2) format("woff2") 68 | } 69 | 70 | @font-face { 71 | font-family: "Inter"; 72 | font-style: normal; 73 | font-weight: 900; 74 | font-display: optional; 75 | src: url(/fonts/Inter-Black.woff2) format("woff2") 76 | } 77 | } 78 | 79 | @supports (font-variation-settings: normal) { 80 | @font-face { 81 | font-family: "Inter"; 82 | font-style: normal; 83 | font-weight: 100 900; 84 | font-display: optional; 85 | src: url(/fonts/Inter-VariableFont_slnt,wght.woff2) format("woff2 supports variations"), 86 | url(/fonts/Inter-VariableFont_slnt,wght.woff2) format("woff2-variations"); 87 | } 88 | } 89 | 90 | 91 | html, body, #app { 92 | margin: 0; 93 | @apply h-full; 94 | } 95 | 96 | body { 97 | background-color:#424555; 98 | } 99 | 100 | /*Logo gradient*/ 101 | .logo-bg { 102 | background: linear-gradient(90deg, #751796 -58.41%, #FE7223 152.47%); 103 | } 104 | 105 | /*Search bg gradient*/ 106 | .search-bg { 107 | background: linear-gradient(90deg, rgba(196, 196, 196, 0.11) -33.43%, rgba(196, 196, 196, 0.07) 184.14%); 108 | } 109 | 110 | /*data text*/ 111 | .text-data { 112 | color: #AAB3CF; 113 | } 114 | .placeholder-data::placeholder { 115 | color: #AAB3CF; 116 | } -------------------------------------------------------------------------------- /src/main.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import ReactDOM from 'react-dom/client'; 3 | import { BrowserRouter } from 'react-router-dom'; 4 | import { App } from './app'; 5 | import './index.css'; 6 | import './i18n'; 7 | 8 | 9 | ReactDOM.createRoot(document.querySelector('#app') as HTMLElement).render( 10 | 11 | 12 | 13 | 14 | , 15 | ); -------------------------------------------------------------------------------- /src/matrix/client.ts: -------------------------------------------------------------------------------- 1 | import { 2 | createClient, 3 | EventTimeline, 4 | EventType, 5 | IndexedDBCryptoStore, 6 | IndexedDBStore, 7 | MatrixClient as MatrixClientSdk, 8 | MatrixEvent, MatrixEventEvent, 9 | Preset, 10 | RoomCreateTypeField, 11 | RoomType, 12 | UNSTABLE_MSC3088_ENABLED, 13 | UNSTABLE_MSC3088_PURPOSE, 14 | UNSTABLE_MSC3089_TREE_SUBTYPE 15 | } from 'matrix-js-sdk'; 16 | import { 17 | MEGOLM_ALGORITHM 18 | } from 'matrix-js-sdk/lib/crypto/olmlib'; 19 | import { 20 | DEFAULT_TREE_POWER_LEVELS_TEMPLATE, 21 | MSC3089TreeSpace 22 | } from 'matrix-js-sdk/lib/models/MSC3089TreeSpace'; 23 | import { 24 | M_IMAGE 25 | } from './events/ImageEvent'; 26 | // @ts-ignore - `.ts` is needed here to make TS happy 27 | import IndexedDBWorker from "./workers/indexeddb.worker.ts?worker"; 28 | 29 | export class MatrixClient { 30 | private events: MatrixEvent[] = []; 31 | private currentUserDirectory?: MSC3089TreeSpace; 32 | private rootDirectory?: MSC3089TreeSpace; 33 | private constructor(private client: MatrixClientSdk) { } 34 | 35 | public static async new(): Promise { 36 | // @ts-ignore Known to be a thing 37 | if (!global.Olm) { 38 | console.error( 39 | "global.Olm does not seem to be present." 40 | + " Did you forget to add olm in the out directory?" 41 | ); 42 | } 43 | 44 | let server; 45 | if (window.localStorage.getItem("server") === null) { 46 | server = import.meta.env.VITE_MATRIX_SERVER_URL; 47 | } else { 48 | server = window.localStorage.getItem("server"); 49 | } 50 | 51 | 52 | // TODO user id and token if logged in instead of new guest all the time 53 | if (!server) { 54 | throw new Error("No matrix server URL defined"); 55 | } 56 | 57 | let guest_client; 58 | if (window.localStorage.getItem("mxid_guest") !== null) { 59 | const mxid = window.localStorage.getItem("mxid_guest") ?? undefined; 60 | const token = window.localStorage.getItem("access_token_guest") ?? undefined; 61 | const device_id = window.localStorage.getItem("device_id_guest") ?? undefined; 62 | 63 | guest_client = createClient({ 64 | useAuthorizationHeader: true, 65 | baseUrl: server, 66 | userId: mxid, 67 | accessToken: token, 68 | deviceId: device_id, 69 | // @ts-ignore - The function currently comes with incorrect types 70 | store: new IndexedDBStore({ 71 | indexedDB: window.indexedDB, 72 | dbName: "matrix-art-sync:guest", 73 | localStorage: window.localStorage, 74 | workerFactory: () => new IndexedDBWorker(), 75 | }), 76 | cryptoStore: new IndexedDBCryptoStore( 77 | window.indexedDB, "matrix-art:crypto", 78 | ), 79 | }); 80 | guest_client.setGuest(true); 81 | } { 82 | 83 | const tmpClient = createClient({ baseUrl: import.meta.env.VITE_MATRIX_SERVER_URL }); 84 | // @ts-ignore - The function currently comes with incorrect types 85 | const { user_id, device_id, access_token } = await tmpClient.registerGuest(); 86 | 87 | guest_client = createClient({ 88 | useAuthorizationHeader: true, 89 | baseUrl: server, 90 | userId: user_id, 91 | accessToken: access_token, 92 | deviceId: device_id, 93 | // @ts-ignore - The function currently comes with incorrect types 94 | store: new IndexedDBStore({ 95 | indexedDB: window.indexedDB, 96 | dbName: "matrix-art-sync:guest", 97 | localStorage: window.localStorage, 98 | workerFactory: () => new IndexedDBWorker(), 99 | }), 100 | cryptoStore: new IndexedDBCryptoStore( 101 | window.indexedDB, "matrix-art:crypto", 102 | ), 103 | }); 104 | guest_client.setGuest(true); 105 | window.localStorage.setItem("mxid_guest", user_id); 106 | window.localStorage.setItem("access_token_guest", access_token); 107 | window.localStorage.setItem("device_id_guest", device_id); 108 | window.localStorage.setItem("server", server); 109 | } 110 | 111 | let client; 112 | if (window.localStorage.getItem("mxid") !== null) { 113 | const mxid = window.localStorage.getItem("mxid") ?? undefined; 114 | const token = window.localStorage.getItem("access_token") ?? undefined; 115 | const device_id = window.localStorage.getItem("device_id") ?? undefined; 116 | 117 | client = createClient({ 118 | useAuthorizationHeader: true, 119 | baseUrl: server, 120 | userId: mxid, 121 | accessToken: token, 122 | deviceId: device_id, 123 | // @ts-ignore - The function currently comes with incorrect types 124 | store: new IndexedDBStore({ 125 | indexedDB: window.indexedDB, 126 | dbName: "matrix-art-sync:guest", 127 | localStorage: window.localStorage, 128 | workerFactory: () => new IndexedDBWorker(), 129 | }), 130 | cryptoStore: new IndexedDBCryptoStore( 131 | window.indexedDB, "matrix-art:crypto", 132 | ), 133 | }); 134 | client.setGuest(false); 135 | } 136 | 137 | return new MatrixClient(client ?? guest_client); 138 | } 139 | 140 | public isLoggedIn(): boolean { 141 | return this.client.isLoggedIn() && !this.client.isGuest(); 142 | } 143 | 144 | public async start(): Promise { 145 | //TODO Setup handlers 146 | this.client.on(MatrixEventEvent.Decrypted, (event: MatrixEvent, _err?: Error) => { 147 | const ext_ev = event.unstableExtensibleEvent; 148 | if (ext_ev?.isEquivalentTo(M_IMAGE)) { 149 | this.events.push(event); 150 | } 151 | }); 152 | 153 | console.log("start"); 154 | await this.client.store.startup(); 155 | await this.client.initCrypto(); 156 | await this.client.startClient(); 157 | 158 | // Load the root 159 | const room = await this.client.joinRoom(import.meta.env.VITE_MATRIX_ROOT_FOLDER); 160 | // FIXME: This will break if the server is slower 161 | await delay(1000); 162 | this.rootDirectory = new MSC3089TreeSpace(this.client, room.roomId); 163 | console.log("started"); 164 | } 165 | 166 | public async register(homeserver: string = import.meta.env.VITE_MATRIX_SERVER_URL, username: string, password: string, createProfile = false) { 167 | this.client.stopClient(); 168 | this.client = createClient({ 169 | useAuthorizationHeader: true, 170 | baseUrl: homeserver, 171 | userId: username, 172 | deviceId: "Matrix Art", 173 | // @ts-ignore - The function currently comes with incorrect types 174 | store: new IndexedDBStore({ 175 | indexedDB: window.indexedDB, 176 | dbName: "matrix-art-sync:loggedin", 177 | localStorage: window.localStorage, 178 | workerFactory: () => new IndexedDBWorker(), 179 | }), 180 | cryptoStore: new IndexedDBCryptoStore( 181 | window.indexedDB, "matrix-art:crypto", 182 | ), 183 | }); 184 | 185 | await this.client.register(username, password, null, { type: "m.login.dummy" }); 186 | 187 | window.localStorage.setItem("server", homeserver); 188 | window.localStorage.setItem("mxid", username); 189 | window.localStorage.setItem("access_token", this.client.getAccessToken() ?? "unknown"); 190 | window.localStorage.setItem("device_id", "Matrix Art"); 191 | await this.start(); 192 | if (createProfile) { 193 | const subdirs = this.rootDirectory?.getDirectories(); 194 | const id = this.client.getUserId()?.replace(":", "_"); 195 | if (subdirs?.some((directory) => directory.room.name === id)) { 196 | this.rootDirectory = subdirs?.find((directory) => directory.room.name === id); 197 | } else { 198 | await this.createProfileFolder(); 199 | } 200 | } 201 | } 202 | 203 | // Login and create the profile if wanted 204 | public async login(homeserver: string, username: string, password: string, createProfile = false): Promise { 205 | this.client.stopClient(); 206 | this.client = createClient({ 207 | useAuthorizationHeader: true, 208 | baseUrl: homeserver, 209 | userId: username, 210 | deviceId: "Matrix Art", 211 | // @ts-ignore - The function currently comes with incorrect types 212 | store: new IndexedDBStore({ 213 | indexedDB: window.indexedDB, 214 | dbName: "matrix-art-sync:loggedin", 215 | localStorage: window.localStorage, 216 | workerFactory: () => new IndexedDBWorker(), 217 | }), 218 | cryptoStore: new IndexedDBCryptoStore( 219 | window.indexedDB, "matrix-art:crypto", 220 | ), 221 | }); 222 | await this.client.loginWithPassword(username, password); 223 | 224 | window.localStorage.setItem("server", homeserver); 225 | window.localStorage.setItem("mxid", username); 226 | window.localStorage.setItem("access_token", this.client.getAccessToken() ?? "unknown"); 227 | window.localStorage.setItem("device_id", "Matrix Art"); 228 | await this.start(); 229 | if (createProfile) { 230 | const subdirs = this.rootDirectory?.getDirectories(); 231 | console.log(subdirs); 232 | const id = this.client.getUserId()?.replace(":", "_"); 233 | if (subdirs?.some((directory) => directory.room.name === id)) { 234 | this.rootDirectory = subdirs?.find((directory) => directory.room.name === id); 235 | } else { 236 | await this.createProfileFolder(); 237 | } 238 | } 239 | } 240 | 241 | // creates the profile 242 | private async createProfileFolder() { 243 | if (this.client.isGuest()) { 244 | throw new Error("Cannot create a file tree space as a guest"); 245 | } 246 | // Load the root as client changed 247 | const room = await this.client.joinRoom(import.meta.env.VITE_MATRIX_ROOT_FOLDER); 248 | await delay(1000); 249 | this.rootDirectory = new MSC3089TreeSpace(this.client, room.roomId); 250 | // Create the user folder and add it to the top folder 251 | const id = this.client.getUserId()?.replace(":", "_"); 252 | this.currentUserDirectory = await this.createPublicSubDirectory(this.rootDirectory, id ?? "unknown"); 253 | // Create the public timeline for the user. We dont need it saved as we can get it again later using the users dir. 254 | await this.createPublicSubDirectory(this.currentUserDirectory, "Timeline"); 255 | } 256 | 257 | /** 258 | * Creates a new file tree space with the given name. The client will pick 259 | * defaults for how it expects to be able to support the remaining API offered 260 | * by the returned class. 261 | * 262 | * Note that this is UNSTABLE and may have breaking changes without notice. 263 | * @param {string} name The name of the tree space. 264 | * @returns {Promise} Resolves to the created space. 265 | * 266 | * This is taken from https://github.com/matrix-org/matrix-js-sdk/blob/d6f1c6cfdc5a4f3d7b4ec67fe9f4d89d7319d8f7/src/client.ts#L8776 267 | * License of the original file: Apache-2.0 268 | */ 269 | public async createPublicFileTree(name: string): Promise { 270 | if (this.client.isGuest()) { 271 | throw new Error("Cannot create a file tree space as a guest"); 272 | } 273 | const { room_id: roomId } = await this.client.createRoom({ 274 | name: name, 275 | preset: Preset.PublicChat, 276 | power_level_content_override: { 277 | ...DEFAULT_TREE_POWER_LEVELS_TEMPLATE, 278 | users: { 279 | // We want to be able to moderate this as the instance admin for legal reasons 280 | [import.meta.env.VITE_MATRIX_INSTANCE_ADMIN]: 100, 281 | // We initially need to use 100 to be able to create the room... 282 | [this.client.getUserId() ?? "broken"]: 100, 283 | }, 284 | }, 285 | invite: [ 286 | import.meta.env.VITE_MATRIX_INSTANCE_ADMIN, 287 | ], 288 | creation_content: { 289 | [RoomCreateTypeField]: RoomType.Space, 290 | }, 291 | initial_state: [ 292 | { 293 | type: UNSTABLE_MSC3088_PURPOSE.name, 294 | state_key: UNSTABLE_MSC3089_TREE_SUBTYPE.name, 295 | content: { 296 | [UNSTABLE_MSC3088_ENABLED.name]: true, 297 | }, 298 | }, 299 | { 300 | type: EventType.RoomEncryption, 301 | state_key: "", 302 | content: { 303 | algorithm: MEGOLM_ALGORITHM, 304 | }, 305 | }, 306 | { 307 | type: EventType.RoomGuestAccess, 308 | state_key: "", 309 | content: { 310 | guest_access: "can_join", 311 | }, 312 | }, 313 | { 314 | type: EventType.RoomHistoryVisibility, 315 | state_key: "", 316 | content: { 317 | history_visibility: "world_readable", 318 | }, 319 | } 320 | ], 321 | }); 322 | // Demote ourself 323 | const room = this.client.getRoom(roomId); 324 | const powerLevelEvent = room?.getLiveTimeline().getState(EventTimeline.FORWARDS)?.getStateEvents(EventType.RoomPowerLevels, ""); 325 | if (!powerLevelEvent) { 326 | throw new Error("Failed to find PL event"); 327 | } 328 | await this.client.setPowerLevel(roomId, this.client.getUserId() ?? "unknown", 50, powerLevelEvent); 329 | return new MSC3089TreeSpace(this.client, roomId); 330 | } 331 | 332 | /** 333 | * Creates a directory under this tree space, represented as another tree space. 334 | * @param {string} name The name for the directory. 335 | * @returns {Promise} Resolves to the created directory. 336 | * 337 | * This is taken from https://github.com/matrix-org/matrix-js-sdk/blob/feb83ba161c32c0519613b88027f573e22efa3aa/src/models/MSC3089TreeSpace.ts#L226 338 | * License of the original file: Apache-2.0 339 | */ 340 | public async createPublicSubDirectory(topdirectory: MSC3089TreeSpace, name: string): Promise { 341 | const directory = await this.createPublicFileTree(name); 342 | 343 | await this.client.sendStateEvent(topdirectory.roomId, EventType.SpaceChild, { 344 | via: [this.client.getDomain()], 345 | }, directory.roomId); 346 | 347 | await this.client.sendStateEvent(directory.roomId, EventType.SpaceParent, { 348 | via: [this.client.getDomain()], 349 | }, topdirectory.roomId); 350 | 351 | return directory; 352 | } 353 | } 354 | 355 | /* Technical folder layout (https://github.com/matrix-org/matrix-spec-proposals/blob/travis/msc/trees/proposals/3089-file-tree-structures.md) 356 | Idea by TravisR 357 | 358 | Note that every user can create a user folder or delete themself from it again. 359 | Every user owns their own user folder. 360 | 361 | If possible users shall never remove relations to other users folders. 362 | 363 | + 📂 Matrix Art User Dir (public, m.space) 364 | + 📂 User A (public, m.space) 365 | + 📂 Timeline (m.space) 366 | - 📄 Image A 367 | = Room A (invite protected, ) 368 | - 📄 Image B (counted as under the timeline) 369 | + 📂 User B (public, m.space) 370 | + 📂 Timeline (m.space) 371 | - 📄 Image C 372 | = Room B (invite protected, ) 373 | - 📄 Image D (counted as under the timeline) 374 | */ 375 | 376 | function delay(time: number): Promise { 377 | return new Promise(resolve => setTimeout(resolve, time)); 378 | } -------------------------------------------------------------------------------- /src/matrix/events/ImageEvent.ts: -------------------------------------------------------------------------------- 1 | import { 2 | ExtensibleEvents, 3 | IPartialEvent, 4 | Optional, 5 | UnstableValue, 6 | EventType, 7 | isEventTypeSame, 8 | isProvided, 9 | M_TEXT, 10 | InvalidEventError, 11 | isOptionalAString, 12 | NamespacedValue, 13 | M_MESSAGE_EVENT_CONTENT, 14 | EitherAnd, 15 | M_TEXT_EVENT, 16 | ExtensibleEvent 17 | } from "matrix-events-sdk"; 18 | 19 | export const M_IMAGE = new UnstableValue("m.image", "org.matrix.msc1767.image"); 20 | export const M_FILE = new UnstableValue("m.file", "org.matrix.msc1767.file"); 21 | export const M_THUMBNAIL = new UnstableValue("m.thumbnail", "org.matrix.msc1767.thumbnail"); 22 | export const M_BLURHASH = new UnstableValue("blurhash", "xyz.amorgan.blurhash"); 23 | export const MATRIX_ART_DESCRIPTION = new NamespacedValue("matrixart.description"); 24 | export const MATRIX_ART_TAGS = new NamespacedValue("matrixart.tags"); 25 | export const MATRIX_ART_NSFW = new NamespacedValue("matrixart.nsfw"); 26 | export const MATRIX_ART_LICENSE = new NamespacedValue("matrixart.license"); 27 | 28 | type ThumbnailFileEvent = ImageFields & { 29 | url: string; 30 | mimetype: string; 31 | size: number; 32 | }; 33 | 34 | type ImageFields = { 35 | width: number; 36 | height: number; 37 | }; 38 | 39 | type FileEvent = { 40 | url: string; 41 | name: string; 42 | mimetype: string; 43 | size: number; 44 | }; 45 | 46 | export type M_IMAGE_EVENT = EitherAnd<{ [M_IMAGE.name]: ImageFields; }, { [M_IMAGE.altName]: ImageFields; }>; 47 | export type M_FILE_EVENT = EitherAnd<{ [M_FILE.name]: FileEvent; }, { [M_FILE.altName]: FileEvent; }>; 48 | export type M_THUMBNAIL_EVENT = EitherAnd<{ [M_THUMBNAIL.name]: ThumbnailFileEvent[]; }, { [M_THUMBNAIL.altName]: ThumbnailFileEvent[]; }>; 49 | export type M_BLURHASH_EVENT = EitherAnd<{ [M_BLURHASH.name]: string; }, { [M_BLURHASH.altName]: string; }>; 50 | export type MATRIX_ART_TAGS_EVENT = { ["matrixart.tags"]: string[]; }; 51 | export type MATRIX_ART_DESCRIPTION_EVENT = { ["matrixart.description"]: string; }; 52 | export type MATRIX_ART_NSFW_EVENT = { ["matrixart.nsfw"]: boolean; }; 53 | export type MATRIX_ART_LICENSE_EVENT = { ["matrixart.license"]: string; }; 54 | export type M_IMAGE_EVENT_CONTENT = M_MESSAGE_EVENT_CONTENT 55 | & M_IMAGE_EVENT 56 | & M_FILE_EVENT 57 | & M_TEXT_EVENT 58 | | M_BLURHASH_EVENT 59 | | M_THUMBNAIL_EVENT 60 | | MATRIX_ART_TAGS_EVENT 61 | | MATRIX_ART_DESCRIPTION_EVENT 62 | | MATRIX_ART_NSFW_EVENT 63 | | MATRIX_ART_LICENSE_EVENT; 64 | 65 | export class ImageEvent extends ExtensibleEvent { 66 | public readonly image!: ImageFields; 67 | public readonly text!: string; 68 | public readonly thumbnails?: ThumbnailFileEvent[]; 69 | public readonly blurhash?: string; 70 | public readonly file!: FileEvent; 71 | public readonly description?: string; 72 | public readonly tags?: string[]; 73 | public readonly nsfw: boolean = false; 74 | public readonly license?: string; 75 | 76 | 77 | public isEquivalentTo(primaryEventType: EventType): boolean { 78 | return isEventTypeSame(primaryEventType, M_IMAGE); 79 | } 80 | public serialize(): IPartialEvent { 81 | const content: M_IMAGE_EVENT_CONTENT = { 82 | [M_TEXT.name]: this.text, 83 | [M_FILE.name]: this.file, 84 | [M_IMAGE.name]: this.image, 85 | [M_THUMBNAIL.name]: this.thumbnails, 86 | [M_BLURHASH.name]: this.blurhash, 87 | ["matrixart.description"]: this.description, 88 | ["matrixart.tags"]: this.tags, 89 | ["matrixart.nsfw"]: this.nsfw, 90 | ["matrixart.license"]: this.license, 91 | }; 92 | 93 | return { 94 | type: "m.image", 95 | content: content, 96 | }; 97 | } 98 | 99 | constructor(wireFormat: IPartialEvent) { 100 | super(wireFormat); 101 | 102 | const mimage = M_IMAGE.findIn(this.wireContent); 103 | // Probably wrong 104 | const mtext = M_TEXT.findIn(this.wireContent); 105 | const mfile = M_FILE.findIn(this.wireContent); 106 | const mthumbnail = M_THUMBNAIL.findIn(this.wireContent); 107 | const mblurhash = M_BLURHASH.findIn(this.wireContent); 108 | const matrixart_description = MATRIX_ART_DESCRIPTION.findIn(this.wireContent); 109 | const matrixart_tags = MATRIX_ART_TAGS.findIn(this.wireContent); 110 | const matrixart_nsfw = MATRIX_ART_NSFW.findIn(this.wireContent); 111 | const matrixart_license = MATRIX_ART_LICENSE.findIn(this.wireContent); 112 | 113 | // Required fields 114 | if (isProvided(mimage)) { 115 | if (!mimage) { 116 | throw new InvalidEventError("m.image is required to be present"); 117 | } 118 | this.image = mimage; 119 | } 120 | if (isProvided(mfile)) { 121 | if (!mfile) { 122 | throw new InvalidEventError("m.file is required to be present"); 123 | } 124 | this.file = mfile; 125 | } 126 | if (isOptionalAString(mtext)) { 127 | if (!mimage) { 128 | throw new InvalidEventError("m.text is required to be present"); 129 | } 130 | // Safe but ts is stupid here 131 | this.text = mtext as string; 132 | } 133 | 134 | // Optional fields 135 | if (isProvided(mthumbnail)) { 136 | if (!Array.isArray(mthumbnail)) { 137 | throw new InvalidEventError("m.thumbnail contents must be an array"); 138 | } 139 | this.thumbnails = mthumbnail; 140 | } 141 | if (isOptionalAString(mblurhash)) { 142 | this.blurhash = mblurhash as string; 143 | } 144 | if (isOptionalAString(matrixart_description)) { 145 | this.description = matrixart_description as string; 146 | } 147 | if (isProvided(matrixart_tags)) { 148 | if (!Array.isArray(matrixart_tags)) { 149 | throw new InvalidEventError("matrixart.tags contents must be an array"); 150 | } 151 | this.tags = matrixart_tags; 152 | } 153 | if (isProvided(matrixart_nsfw)) { 154 | if (typeof matrixart_nsfw !== "boolean") { 155 | throw new InvalidEventError("matrixart.tags contents must be an boolean"); 156 | } 157 | this.nsfw = matrixart_nsfw; 158 | } 159 | if (isOptionalAString(matrixart_license)) { 160 | this.license = matrixart_license as string; 161 | } 162 | } 163 | } 164 | 165 | function parseImageEvent(wireEvent: IPartialEvent): Optional { 166 | const event = wireEvent as IPartialEvent; 167 | return new ImageEvent(event); 168 | } 169 | 170 | ExtensibleEvents.registerInterpreter(M_IMAGE, parseImageEvent); 171 | ExtensibleEvents.unknownInterpretOrder.push(M_IMAGE); -------------------------------------------------------------------------------- /src/matrix/workers/indexeddb.worker.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2017 Vector Creations Ltd 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | http://www.apache.org/licenses/LICENSE-2.0 7 | Unless required by applicable law or agreed to in writing, software 8 | distributed under the License is distributed on an "AS IS" BASIS, 9 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | See the License for the specific language governing permissions and 11 | limitations under the License. 12 | */ 13 | import { IndexedDBStoreWorker } from "matrix-js-sdk/lib/indexeddb-worker"; 14 | 15 | // eslint-disable-next-line @typescript-eslint/no-explicit-any 16 | const ctx: Worker = self as any; 17 | 18 | const remoteWorker = new IndexedDBStoreWorker(ctx.postMessage); 19 | 20 | // eslint-disable-next-line unicorn/prefer-add-event-listener 21 | ctx.onmessage = remoteWorker.onMessage; -------------------------------------------------------------------------------- /src/pages/Home.tsx: -------------------------------------------------------------------------------- 1 | import { Header } from "../components/header"; 2 | import { Post } from "../components/post"; 3 | import { Plock } from "react-plock"; 4 | import { UserData } from "../data/user"; 5 | import { PostData } from "../data/post"; 6 | import { useTranslation } from "react-i18next"; 7 | 8 | 9 | const BREAKPOINTS = [ 10 | { size: 500, columns: 1 }, 11 | { size: 800, columns: 2 }, 12 | { size: 1400, columns: 3 }, 13 | { size: 1401, columns: 4 }, 14 | ]; 15 | 16 | export function Home() { 17 | const { t } = useTranslation(); 18 | 19 | return ( 20 |
21 |
22 |
23 |
24 |
25 |

{t('Explore')}

26 | 48 |
49 |
50 | ); 51 | } -------------------------------------------------------------------------------- /src/pages/Join.tsx: -------------------------------------------------------------------------------- 1 | import React, { useState, useContext } from "react"; 2 | import { Client } from "../context"; 3 | import { Header } from "../components/header"; 4 | import { useNavigate } from "react-router-dom"; 5 | import { useTranslation } from "react-i18next"; 6 | 7 | const ACTIVE_TAB_CSS = "inline-block p-4 w-full text-gray-900 bg-gray-100 hover:ring-blue-300 hover:ring-1 focus:ring-transparent focus:outline-none dark:bg-gray-700 dark:text-white"; 8 | const TAB_CSS = "inline-block p-4 w-full bg-white hover:text-gray-700 hover:bg-gray-50 hover:ring-blue-300 hover:ring-1 focus:ring-transparent focus:outline-none dark:hover:text-white dark:bg-gray-800 dark:hover:bg-gray-700"; 9 | 10 | export default function Join() { 11 | const navigate = useNavigate(); 12 | const client = useContext(Client); 13 | const [homeserver, setHomeserver] = useState(import.meta.env.VITE_MATRIX_SERVER_URL); 14 | const [username, setUsername] = useState(""); 15 | const [password, setPassword] = useState(""); 16 | const [createProfile, setCreateProfile] = useState(true); 17 | const [currentTab, setCurrentTab] = useState("login"); 18 | const { t } = useTranslation(); 19 | 20 | const onSubmit = async (_e: React.FormEvent) => { 21 | if (!client) { 22 | return; 23 | } 24 | if (homeserver === "" || username === "" || password === "") { 25 | return; 26 | } 27 | if (currentTab === "login" && !client?.isLoggedIn()) { 28 | await client.login(homeserver, username, password, createProfile); 29 | } else if (currentTab === "register" && !client.isLoggedIn()) { 30 | await client.register(homeserver, username, password, createProfile); 31 | } 32 | navigate('/', { replace: true }); 33 | } 34 | 35 | const onInput = (e: React.FormEvent) => { 36 | const target = (e.target as HTMLInputElement); 37 | const value = target.type === 'checkbox' ? target.checked : target.value; 38 | const name = target.name; 39 | switch (name) { 40 | case "homeserver": { 41 | setHomeserver(value as string); 42 | break; 43 | } 44 | case "username": { 45 | setUsername(value as string); 46 | break; 47 | } 48 | case "password": { 49 | setPassword(value as string); 50 | break; 51 | } 52 | case "createProfile": { 53 | setCreateProfile(value as boolean); 54 | break; 55 | } 56 | } 57 | } 58 | 59 | return ( 60 |
61 |
62 |
63 |
64 | 65 |
66 |

{t('Join')}

67 |
68 | 76 |
77 | 78 | 79 | 80 | 84 | 85 | 86 |
87 |
88 |
89 |
90 | ); 91 | } -------------------------------------------------------------------------------- /src/pages/Post.tsx: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import { useParams } from "react-router-dom"; 3 | import { Header } from "../components/header"; 4 | 5 | export default function Post() { 6 | const { postId } = useParams(); 7 | return ( 8 |
9 |
10 |
11 |
12 | 13 |
14 | 15 |
16 |
17 | ); 18 | } -------------------------------------------------------------------------------- /src/pages/Profile.tsx: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import { useParams } from "react-router-dom"; 3 | import { Header } from "../components/header"; 4 | 5 | export default function Profile() { 6 | const { userId } = useParams(); 7 | return ( 8 |
9 |
10 |
11 |
12 | 13 |
14 | 15 |
16 |
17 | ); 18 | } -------------------------------------------------------------------------------- /src/test/setup.ts: -------------------------------------------------------------------------------- 1 | import '@testing-library/jest-dom' -------------------------------------------------------------------------------- /src/utils/asyncImages.tsx: -------------------------------------------------------------------------------- 1 | // First we need a type of cache to avoid creating resources for images 2 | import { ImgHTMLAttributes } from "react"; 3 | import { createResource, Resource } from "./resources"; 4 | 5 | // we have already fetched in the past 6 | export const cache = new Map>(); 7 | 8 | // then we create our loadImage function, this function receives the source 9 | // of the image and returns a resource 10 | export function loadImage(source: string): Resource { 11 | // here we start getting the resource from the cache 12 | let resource = cache.get(source); 13 | // and if it's there we return it immediately 14 | if (resource) return resource; 15 | // but if it's not we create a new resource 16 | resource = createResource( 17 | () => 18 | // in our async function we create a promise 19 | new Promise((resolve, reject) => { 20 | // then create a new image element 21 | const img = new window.Image(); 22 | // set the src to our source 23 | img.src = source; 24 | // and start listening for the load event to resolve the promise 25 | img.addEventListener("load", () => resolve(source)); 26 | // and also the error event to reject the promise 27 | img.addEventListener("error", () => 28 | reject(new Error(`Failed to load image ${source}`)) 29 | ); 30 | }) 31 | ); 32 | // before finishing we save the new resource in the cache 33 | cache.set(source, resource); 34 | // and return return it 35 | return resource; 36 | } 37 | 38 | export function SuspenseImage( 39 | props: ImgHTMLAttributes 40 | ): JSX.Element { 41 | loadImage(props.src ?? "undefined").read(); 42 | return ; 43 | } -------------------------------------------------------------------------------- /src/utils/resources.ts: -------------------------------------------------------------------------------- 1 | // A Resource is an object with a read method returning the payload 2 | export interface Resource { 3 | read: () => Payload; 4 | } 5 | 6 | export type status = "pending" | "success" | "error"; 7 | 8 | // this function let us get a new function using the asyncFn we pass 9 | // this function also receives a payload and return us a resource with 10 | // that payload assigned as type 11 | export function createResource( 12 | asyncFn: () => Promise 13 | ): Resource { 14 | // we start defining our resource is on a pending status 15 | let status: status = "pending"; 16 | // and we create a variable to store the result 17 | let result: Payload | Error; 18 | // then we immediately start running the `asyncFn` function 19 | // and we store the resulting promise 20 | const promise = asyncFn().then( 21 | (r: Payload) => { 22 | // once it's fulfilled we change the status to success 23 | // and we save the returned value as result 24 | status = "success"; 25 | result = r; 26 | }, 27 | (error: Error) => { 28 | // once it's rejected we change the status to error 29 | // and we save the returned error as result 30 | status = "error"; 31 | result = error; 32 | } 33 | ); 34 | // lately we return an error object with the read method 35 | return { 36 | read(): Payload { 37 | // here we will check the status value 38 | switch (status) { 39 | case "pending": { 40 | // if it's still pending we throw the promise 41 | // throwing a promise is how Suspense know our component is not ready 42 | throw promise; 43 | } 44 | case "error": { 45 | // if it's error we throw the error 46 | throw result as Error; 47 | } 48 | case "success": { 49 | // if it's success we return the result 50 | return result as Payload; 51 | } 52 | } 53 | }, 54 | }; 55 | } -------------------------------------------------------------------------------- /src/utils/test-utils.tsx: -------------------------------------------------------------------------------- 1 | /* eslint-disable import/export */ 2 | import { cleanup, render } from '@testing-library/react' 3 | import { afterEach } from 'vitest' 4 | 5 | afterEach(() => { 6 | cleanup() 7 | }) 8 | 9 | const customRender = (ui: React.ReactElement, options = {}) => 10 | render(ui, { 11 | // wrap provider(s) here if needed 12 | wrapper: ({ children }) => children, 13 | ...options, 14 | }) 15 | 16 | export * from '@testing-library/react' 17 | export { default as userEvent } from '@testing-library/user-event' 18 | // override render export 19 | export { customRender as render } -------------------------------------------------------------------------------- /src/vite-env.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | -------------------------------------------------------------------------------- /tailwind.config.cjs: -------------------------------------------------------------------------------- 1 | const defaultTheme = require('tailwindcss/defaultTheme') 2 | 3 | module.exports = { 4 | content: [ 5 | "./index.html", 6 | "./src/**/*.{js,ts,jsx,tsx}", 7 | ], 8 | theme: { 9 | extend: { 10 | fontFamily: { 11 | sans: ['Inter', ...defaultTheme.fontFamily.sans], 12 | }, 13 | }, 14 | }, 15 | plugins: [], 16 | } 17 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "ESNext", 4 | "useDefineForClassFields": true, 5 | "lib": [ 6 | "DOM", 7 | "DOM.Iterable", 8 | "ESNext" 9 | ], 10 | "allowJs": false, 11 | "skipLibCheck": true, 12 | "esModuleInterop": false, 13 | "allowSyntheticDefaultImports": true, 14 | "strict": true, 15 | "forceConsistentCasingInFileNames": true, 16 | "module": "ESNext", 17 | "moduleResolution": "Node", 18 | "resolveJsonModule": true, 19 | "isolatedModules": true, 20 | "noEmit": true, 21 | "jsx": "react-jsx" 22 | }, 23 | "include": [ 24 | "src" 25 | ], 26 | "references": [ 27 | { 28 | "path": "./tsconfig.node.json" 29 | } 30 | ] 31 | } -------------------------------------------------------------------------------- /tsconfig.node.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "composite": true, 4 | "module": "ESNext", 5 | "moduleResolution": "Node" 6 | }, 7 | "include": [ 8 | "vite.config.ts", 9 | "scripts/**/*" 10 | ], 11 | } -------------------------------------------------------------------------------- /tsconfig.worker.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "composite": true, 4 | "rootDir": "./src", 5 | "target": "ES5", 6 | "useDefineForClassFields": true, 7 | "lib": [ 8 | "DOM", 9 | "DOM.Iterable", 10 | "ESNext" 11 | ], 12 | "allowJs": false, 13 | "skipLibCheck": true, 14 | "esModuleInterop": true, 15 | "allowSyntheticDefaultImports": true, 16 | "strict": true, 17 | "forceConsistentCasingInFileNames": true, 18 | "module": "CommonJS", 19 | "moduleResolution": "Node", 20 | "resolveJsonModule": true, 21 | "isolatedModules": false, 22 | "jsx": "preserve", 23 | "jsxFactory": "h", 24 | "jsxFragmentFactory": "Fragment" 25 | }, 26 | "include": [ 27 | "./src/matrix/workers/**/*.ts" 28 | ] 29 | } -------------------------------------------------------------------------------- /vite.config.ts: -------------------------------------------------------------------------------- 1 | import { defineConfig, splitVendorChunkPlugin } from 'vite'; 2 | import react from "@vitejs/plugin-react-swc"; 3 | import { ViteEjsPlugin } from "vite-plugin-ejs"; 4 | 5 | // https://vitejs.dev/config/ 6 | export default defineConfig({ 7 | build: { 8 | sourcemap: true, 9 | }, 10 | plugins: [ 11 | react(), 12 | splitVendorChunkPlugin(), 13 | ViteEjsPlugin((viteConfig) => ({ 14 | // viteConfig is the current Vite resolved config 15 | env: viteConfig.env, 16 | })), 17 | ], 18 | resolve: { 19 | dedupe: [ 20 | "react", 21 | "react-dom", 22 | "matrix-js-sdk", 23 | ] 24 | }, 25 | worker: { 26 | format: 'iife', 27 | }, 28 | test: { 29 | globals: true, 30 | environment: 'jsdom', 31 | setupFiles: './src/test/setup.ts', 32 | // you might want to disable it, if you don't have tests that rely on CSS 33 | // since parsing CSS is slow 34 | css: true, 35 | } 36 | }); 37 | --------------------------------------------------------------------------------