8000 Add option to view event source by ginnyTheCat · Pull Request #320 · cinnyapp/cinny · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Add option to view event source #320

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

Merged
merged 5 commits into from
Feb 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/app/molecules/message/Message.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import colorMXID from '../../../util/colorMXID';
import { getEventCords } from '../../../util/common';
import { redactEvent, sendReaction } from '../../../client/action/roomTimeline';
import {
openEmojiBoard, openProfileViewer, openReadReceipts, replyTo,
openEmojiBoard, openProfileViewer, openReadReceipts, openViewSource, replyTo,
} from '../../../client/action/navigation';
import { sanitizeCustomHtml } from '../../../util/sanitize';

Expand All @@ -33,6 +33,7 @@ import EmojiAddIC from '../../../../public/res/ic/outlined/emoji-add.svg';
import VerticalMenuIC from '../../../../public/res/ic/outlined/vertical-menu.svg';
import PencilIC from '../../../../public/res/ic/outlined/pencil.svg';
import TickMarkIC from '../../../../public/res/ic/outlined/tick-mark.svg';
import CmdIC from '../../../../public/res/ic/outlined/cmd.svg';
import BinIC from '../../../../public/res/ic/outlined/bin.svg';

function PlaceholderMessage() {
Expand Down Expand Up @@ -510,6 +511,12 @@ const MessageOptions = React.memo(({
>
Read receipts
</MenuItem>
<MenuItem
iconSrc={CmdIC}
=> openViewSource(mEvent)}
>
View source
</MenuItem>
{(canIRedact || senderId === mx.getUserId()) && (
<>
<MenuBorder />
Expand Down
5 changes: 4 additions & 1 deletion src/app/molecules/popup-window/PopupWindow.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ PWContentSelector.propTypes = {
function PopupWindow({
className, isOpen, title, contentTitle,
drawer, drawerOptions, contentOptions,
onRequestClose, children,
onAfterClose, onRequestClose, children,
}) {
const haveDrawer = drawer !== null;
const cTitle = contentTitle !== null ? contentTitle : title;
Expand All @@ -60,6 +60,7 @@ function PopupWindow({
<RawModal
className={`${className === null ? '' : `${className} `}pw-model`}
isOpen={isOpen}
>
>
size={haveDrawer ? 'large' : 'medium'}
>
Expand Down Expand Up @@ -116,6 +117,7 @@ PopupWindow.defaultProps = {
contentTitle: null,
drawerOptions: null,
contentOptions: null,
onAfterClose: null,
onRequestClose: null,
};

Expand All @@ -127,6 +129,7 @@ PopupWindow.propTypes = {
drawer: PropTypes.node,
drawerOptions: PropTypes.node,
contentOptions: PropTypes.node,
onAfterClose: PropTypes.func,
onRequestClose: PropTypes.func,
children: PropTypes.node.isRequired,
};
Expand Down
2 changes: 2 additions & 0 deletions src/app/organisms/pw/Dialogs.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ import ReadReceipts from '../read-receipts/ReadReceipts';
import ProfileViewer from '../profile-viewer/ProfileViewer';
import SpaceAddExisting from '../../molecules/space-add-existing/SpaceAddExisting';
import Search from '../search/Search';
import ViewSource from '../view-source/ViewSource';

function Dialogs() {
return (
<>
<ReadReceipts />
<ViewSource />
<ProfileViewer />
<SpaceAddExisting />
<Search />
Expand Down
73 changes: 73 additions & 0 deletions src/app/organisms/view-source/ViewSource.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import React, { useEffect, useState } from 'react';
import PropTypes from 'prop-types';
import './ViewSource.scss';

import cons from '../../../client/state/cons';
import navigation from '../../../client/state/navigation';

import IconButton from '../../atoms/button/IconButton';
import { MenuHeader } from '../../atoms/context-menu/ContextMenu';
import ScrollView from '../../atoms/scroll/ScrollView';
import PopupWindow from '../../molecules/popup-window/PopupWindow';

import CrossIC from '../../../../public/res/ic/outlined/cross.svg';

function ViewSourceBlock({ title, json }) {
return (
<div className="view-source__card">
<MenuHeader>{title}</MenuHeader>
<ScrollView horizontal vertical={false} autoHide>
<pre className="text text-b1">
<code className="language-json">
{JSON.stringify(json, null, 2)}
</code>
</pre>
</ScrollView>
</div>
);
}
ViewSourceBlock.propTypes = {
title: PropTypes.string.isRequired,
json: PropTypes.shape({}).isRequired,
};

function ViewSource() {
const [isOpen, setIsOpen] = useState(false);
const [event, setEvent] = useState(null);

useEffect(() => {
const loadViewSource = (e) => {
setEvent(e);
setIsOpen(true);
};
navigation.on(cons.events.navigation.VIEWSOURCE_OPENED, loadViewSource);
return () => {
navigation.removeListener(cons.events.navigation.VIEWSOURCE_OPENED, loadViewSource);
};
}, []);

const handleAfterClose = () => {
setEvent(null);
};

const renderViewSource = () => (
<div className="view-source">
{event.isEncrypted() && <ViewSourceBlock title="Decrypted source" json={event.getEffectiveEvent()} />}
<ViewSourceBlock title="Original source" json={event.event} />
</div>
);

return (
<PopupWindow
isOpen={isOpen}
title="View source"
>
=> setIsOpen(false)}
contentOptions={<IconButton src={CrossIC} => setIsOpen(false)} tooltip="Close" />}
>
{event && renderViewSource()}
</PopupWindow>
);
}

export default ViewSource;
17 changes: 17 additions & 0 deletions src/app/organisms/view-source/ViewSource.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
@use '../../partials/dir';

.view-source {
@include dir.side(margin, var(--sp-normal), var(--sp-extra-tight));

& pre {
padding: var(--sp-extra-tight);
}

&__card {
margin: var(--sp-normal) 0;
background-color: var(--bg-surface-hover);
border-radius: var(--bo-radius);
box-shadow: var(--bs-surface-border);
overflow: hidden;
}
}
7 changes: 7 additions & 0 deletions src/client/action/navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,13 @@ export function openReadReceipts(roomId, userIds) {
});
}

export function openViewSource(event) {
appDispatcher.dispatch({
type: cons.actions.navigation.OPEN_VIEWSOURCE,
event,
});
}

export function replyTo(userId, eventId, body) {
appDispatcher.dispatch({
type: cons.actions.navigation.CLICK_REPLY_TO,
Expand Down
2 changes: 2 additions & 0 deletions src/client/state/cons.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ const cons = {
OPEN_SETTINGS: 'OPEN_SETTINGS',
OPEN_EMOJIBOARD: 'OPEN_EMOJIBOARD',
OPEN_READRECEIPTS: 'OPEN_READRECEIPTS',
OPEN_VIEWSOURCE: 'OPEN_VIEWSOURCE',
CLICK_REPLY_TO: 'CLICK_REPLY_TO',
OPEN_SEARCH: 'OPEN_SEARCH',
OPEN_REUSABLE_CONTEXT_MENU: 'OPEN_REUSABLE_CONTEXT_MENU',
Expand Down Expand Up @@ -82,6 +83,7 @@ const cons = {
PROFILE_VIEWER_OPENED: 'PROFILE_VIEWER_OPENED',
EMOJIBOARD_OPENED: 'EMOJIBOARD_OPENED',
READRECEIPTS_OPENED: 'READRECEIPTS_OPENED',
VIEWSOURCE_OPENED: 'VIEWSOURCE_OPENED',
REPLY_TO_CLICKED: 'REPLY_TO_CLICKED',
SEARCH_OPENED: 'SEARCH_OPENED',
REUSABLE_CONTEXT_MENU_OPENED: 'REUSABLE_CONTEXT_MENU_OPENED',
Expand Down
6 changes: 6 additions & 0 deletions src/client/state/navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,12 @@ class Navigation extends EventEmitter {
action.userIds,
);
},
[cons.actions.navigation.OPEN_VIEWSOURCE]: () => {
this.emit(
cons.events.navigation.VIEWSOURCE_OPENED,
action.event,
);
},
[cons.actions.navigation.CLICK_REPLY_TO]: () => {
this.emit(
cons.events.navigation.REPLY_TO_CLICKED,
Expand Down
0