-
Notifications
You must be signed in to change notification settings - Fork 1
Initial support for Matrix #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
cfpwastaken
wants to merge
26
commits into
main
Choose a base branch
from
matrix
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
6b6335f
wip: matrix
cfpwastaken 896857c
wip: matrix
cfpwastaken acdc267
feat: css magic
j0code f2f4f3a
feat(matrix): more msgtypes for m.room.message
cfpwastaken e01b2b0
feat(matrix): m.room.name event
cfpwastaken 3fd76b8
feat(matrix): member list
cfpwastaken 1d7a2b8
feat(matrix): leaving and joining rooms
cfpwastaken a7de2f8
feat(matrix): register
cfpwastaken 6e05d19
feat(matrix): creating rooms
cfpwastaken db87c79
feat(matrix): inviting to rooms
cfpwastaken 84a909c
fix: name RoomNoticeMessage correctly
cfpwastaken db6f2f7
fix: name RoomAudioMessage correctly
cfpwastaken 0c6ed72
fix(avatar): reset element content before rerendering
cfpwastaken fe3b761
fix(RoomView): bad event .off handling
cfpwastaken f703a6c
fix(RoomEmoteMessage): body fallback handling
cfpwastaken fd7df05
feat(messages): correct formatting stuff
cfpwastaken ff38efc
fix(ChatInput): null room
cfpwastaken c058e57
fix(login): typed errors
cfpwastaken 6d57611
fix(client): init from App.ts
cfpwastaken e67ae78
fix(message): xss from innerHTML = body
cfpwastaken d5f32f7
fix(RoomFileMessage): add rel=noopener noreferrer
cfpwastaken add5f6b
fix(messages): cleanup file-based msgtypes
cfpwastaken ff90cb7
feat: use user profile cache
cfpwastaken 35590f8
fix(RoomNameEvent): call super.reset
cfpwastaken b5b682a
fix(html): more sanitization
cfpwastaken c818bfe
feat(messages): spoilers
cfpwastaken File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| import { matrix } from "../matrix"; | ||
| import Component from "./Component"; | ||
| import MXCImage from "./MXCImage"; | ||
|
|
||
| export default class Avatar extends Component { | ||
| public readonly mxid: string | ||
|
|
||
| constructor(mxid: string, className?: string) { | ||
| super("div", { classes: ["avatar", className].filter((v): v is string => !!v) }) | ||
| this.mxid = mxid | ||
| this.element.setAttribute("data-mxid", mxid) | ||
| this.reset() | ||
| } | ||
|
|
||
| async reset() { | ||
| const mxid = this.element.getAttribute("data-mxid") | ||
| if(!mxid) return | ||
|
|
||
| this.element.innerHTML = "" | ||
|
|
||
| const user = matrix.getUser(mxid) | ||
| let displayname = user?.displayName | ||
| let avatar_url = user?.avatarUrl | ||
| if(!user) { | ||
| const profile = await matrix.getProfileInfo(mxid) | ||
| displayname = profile?.displayname || mxid | ||
| avatar_url = profile?.avatar_url | ||
| } | ||
| if(avatar_url) { | ||
| let img = new MXCImage(avatar_url) | ||
| await img.reset() | ||
| this.element.appendChild(img.element) | ||
| } else { | ||
| this.element.style.backgroundColor = this.stringToColor(mxid) | ||
| this.element.style.color = this.contrastingColor(this.stringToColor(mxid)) | ||
| this.element.style.fontSize = "24px" | ||
| this.element.style.display = "flex" | ||
| this.element.style.alignItems = "center" | ||
| this.element.style.justifyContent = "center" | ||
| this.element.innerHTML = displayname?.[0].toUpperCase() || "?" | ||
| } | ||
| } | ||
|
|
||
| private stringToColor(str: string) { | ||
| let hash = 0 | ||
| for(let i = 0; i < str.length; i++) { | ||
| hash = str.charCodeAt(i) + ((hash << 5) - hash) | ||
| } | ||
| const color = (hash & 0x00FFFFFF).toString(16).toUpperCase() | ||
| return "#" + "00000".substring(0, 6 - color.length) + color | ||
| } | ||
|
|
||
| private contrastingColor(hex: string): "#000000" | "#FFFFFF" { | ||
| const r = parseInt(hex.substr(1, 2), 16) | ||
| const g = parseInt(hex.substr(3, 2), 16) | ||
| const b = parseInt(hex.substr(5, 2), 16) | ||
| const luminance = (0.299 * r + 0.587 * g + 0.114 * b) / 255 | ||
| return luminance > 0.5 ? "#000000" : "#FFFFFF" | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| import Component from "./Component"; | ||
|
|
||
| export default class ContextMenu extends Component { | ||
| public readonly content: HTMLElement | ||
| public readonly trigger: HTMLElement | ||
|
|
||
| constructor(tagName: keyof HTMLElementTagNameMap, { id, classes }: { id?: string, classes?: string[] }) { | ||
| super("div", { classes: ["context-menu"] }) | ||
|
|
||
| this.content = document.createElement(tagName) | ||
| if (id) this.content.id = id | ||
| this.content.classList.add("context-menu-content") | ||
| if (classes) this.content.classList.add(...classes) | ||
| this.content.style.position = "absolute" | ||
| this.content.style.display = "none" | ||
|
|
||
| this.element.appendChild(this.content) | ||
|
|
||
| this.trigger = document.createElement("div") | ||
| this.element.appendChild(this.trigger) | ||
|
|
||
| this.trigger.addEventListener("contextmenu", e => { | ||
| e.preventDefault() | ||
| this.content.style.left = `${e.clientX}px` | ||
| this.content.style.top = `${e.clientY}px` | ||
| this.content.style.display = "" | ||
| const hide = () => { | ||
| this.content.style.display = "none" | ||
| window.removeEventListener("click", hide) | ||
| } | ||
| window.addEventListener("click", hide) | ||
| }) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| import Component from "./Component" | ||
| import EmojiButton from "./EmojiButton" | ||
|
cfpwastaken marked this conversation as resolved.
|
||
|
|
||
| export default class FormCheckbox extends Component { | ||
|
|
||
| private readonly input: HTMLInputElement | ||
| private readonly label: HTMLSpanElement | ||
|
|
||
| constructor(id: string, label: string) { | ||
| super("div", { id, classes: ["form-input", "form-checkbox-input"] }) | ||
|
|
||
| this.input = document.createElement("input") | ||
| this.input.type = "checkbox" | ||
| this.element.append(this.input) | ||
|
|
||
| this.label = document.createElement("span") | ||
| this.label.textContent = label | ||
| this.element.append(this.label) | ||
| } | ||
|
|
||
| get value() { | ||
| return this.input.checked | ||
| } | ||
|
|
||
| clear() { | ||
| this.input.checked = false | ||
| } | ||
|
|
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,36 @@ | ||
| import { Room } from "matrix-js-sdk"; | ||
| import { matrix } from "../matrix"; | ||
| import { twemojiParse } from "../md"; | ||
| import Component from "./Component"; | ||
| import ContextMenu from "./ContextMenu"; | ||
| import { app, views } from "../main"; | ||
| import App from "./App"; | ||
|
|
||
| export default class ForumTab extends Component { | ||
|
|
||
| constructor(forum: any) { | ||
| readonly tab: HTMLElement | ||
|
|
||
| constructor(forum: Room) { | ||
| super("div", { classes: ["list-tab"] }) | ||
|
|
||
| this.element.innerHTML = twemojiParse(forum.name) | ||
| const ctxMenu = new ContextMenu("div", { classes: ["forum-tab-menu"] }) | ||
|
|
||
| const leaveButton = document.createElement("div") | ||
| leaveButton.textContent = "Leave" | ||
| leaveButton.addEventListener("click", async () => { | ||
| if(!confirm(`Are you sure you want to leave ${forum.name}?`)) return | ||
| await matrix.leave(forum.roomId) | ||
| let _app = app as App | ||
| _app.updateChannelList() | ||
| _app.renderView(undefined) | ||
| _app.updateMemberList(null) | ||
| }) | ||
| ctxMenu.content.appendChild(leaveButton) | ||
|
|
||
| this.tab = ctxMenu.trigger | ||
| ctxMenu.trigger.innerHTML = twemojiParse(forum.name) | ||
|
|
||
| this.element.appendChild(ctxMenu.element) | ||
| } | ||
|
|
||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.