Skip to content

Commit

Permalink
Merge branch 'glitch-soc:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
NoaHimesaka1873 committed Apr 29, 2023
2 parents f1439c8 + 1565af1 commit 00b8d9d
Show file tree
Hide file tree
Showing 16 changed files with 105 additions and 92 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export const PICTURE_IN_PICTURE_REMOVE = 'PICTURE_IN_PICTURE_REMOVE';
* @return {object}
*/
export const deployPictureInPicture = (statusId, accountId, playerType, props) => {
// @ts-expect-error
return (dispatch, getState) => {
// Do not open a player for a toot that does not exist
if (getState().hasIn(['statuses', statusId])) {
Expand Down
12 changes: 12 additions & 0 deletions app/javascript/flavours/glitch/actions/streaming.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export const connectTimelineStream = (timelineId, channelName, params = {}, opti
connectStream(channelName, params, (dispatch, getState) => {
const locale = getState().getIn(['meta', 'locale']);

// @ts-expect-error
let pollingId;

/**
Expand All @@ -61,6 +62,7 @@ export const connectTimelineStream = (timelineId, channelName, params = {}, opti
onConnect() {
dispatch(connectTimeline(timelineId));

// @ts-expect-error
if (pollingId) {
clearTimeout(pollingId);
pollingId = null;
Expand All @@ -75,31 +77,38 @@ export const connectTimelineStream = (timelineId, channelName, params = {}, opti
dispatch(disconnectTimeline(timelineId));

if (options.fallback) {
// @ts-expect-error
pollingId = setTimeout(() => useFallback(options.fallback), randomUpTo(40000));
}
},

onReceive (data) {
switch(data.event) {
case 'update':
// @ts-expect-error
dispatch(updateTimeline(timelineId, JSON.parse(data.payload), options.accept));
break;
case 'status.update':
// @ts-expect-error
dispatch(updateStatus(JSON.parse(data.payload)));
break;
case 'delete':
dispatch(deleteFromTimelines(data.payload));
break;
case 'notification':
// @ts-expect-error
dispatch(updateNotifications(JSON.parse(data.payload), messages, locale));
break;
case 'conversation':
// @ts-expect-error
dispatch(updateConversations(JSON.parse(data.payload)));
break;
case 'announcement':
// @ts-expect-error
dispatch(updateAnnouncements(JSON.parse(data.payload)));
break;
case 'announcement.reaction':
// @ts-expect-error
dispatch(updateAnnouncementsReaction(JSON.parse(data.payload)));
break;
case 'announcement.delete':
Expand All @@ -115,7 +124,9 @@ export const connectTimelineStream = (timelineId, channelName, params = {}, opti
* @param {function(): void} done
*/
const refreshHomeTimelineAndNotification = (dispatch, done) => {
// @ts-expect-error
dispatch(expandHomeTimeline({}, () =>
// @ts-expect-error
dispatch(expandNotifications({}, () =>
dispatch(fetchAnnouncements(done))))));
};
Expand All @@ -124,6 +135,7 @@ const refreshHomeTimelineAndNotification = (dispatch, done) => {
* @return {function(): void}
*/
export const connectUserStream = () =>
// @ts-expect-error
connectTimelineStream('home', 'user', {}, { fallback: refreshHomeTimelineAndNotification, fillGaps: fillHomeTimelineGaps });

/**
Expand Down
4 changes: 2 additions & 2 deletions app/javascript/flavours/glitch/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const setCSRFHeader = () => {
ready(setCSRFHeader);

/**
* @param {() => import('immutable').Map} getState
* @param {() => import('immutable').Map<string,any>} getState
* @returns {import('axios').RawAxiosRequestHeaders}
*/
const authorizationHeaderFromState = getState => {
Expand All @@ -52,7 +52,7 @@ const authorizationHeaderFromState = getState => {
};

/**
* @param {() => import('immutable').Map} getState
* @param {() => import('immutable').Map<string,any>} getState
* @returns {import('axios').AxiosInstance}
*/
export default function api(getState) {
Expand Down
79 changes: 0 additions & 79 deletions app/javascript/flavours/glitch/components/avatar.jsx

This file was deleted.

48 changes: 48 additions & 0 deletions app/javascript/flavours/glitch/components/avatar.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import * as React from 'react';
import classNames from 'classnames';
import { autoPlayGif } from 'flavours/glitch/initial_state';
import { useHovering } from 'hooks/useHovering';
import type { Account } from 'types/resources';

type Props = {
account: Account | undefined;
className?: string;
size: number;
style?: React.CSSProperties;
inline?: boolean;
}

export const Avatar: React.FC<Props> = ({
account,
className,
size = 20,
inline = false,
style: styleFromParent,
}) => {
const { hovering, handleMouseEnter, handleMouseLeave } = useHovering(autoPlayGif);

const style = {
...styleFromParent,
width: `${size}px`,
height: `${size}px`,
backgroundSize: `${size}px ${size}px`,
};

if (account) {
style.backgroundImage = `url(${account.get(hovering ? 'avatar' : 'avatar_static')})`;
}

return (
<div
className={classNames('account__avatar', { 'account__avatar-inline': inline }, className)}
onMouseEnter={handleMouseEnter}
onMouseLeave={handleMouseLeave}
style={style}
data-avatar-of={account && `@${account.get('acct')}`}
role='img'
aria-label={account?.get('acct')}
/>
);
};

export default Avatar;
1 change: 1 addition & 0 deletions app/javascript/flavours/glitch/components/blurhash.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ function Blurhash({
const ctx = canvas.getContext('2d');
const imageData = new ImageData(pixels, width, height);

// @ts-expect-error
ctx.putImageData(imageData, 0, 0);
} catch (err) {
console.error('Blurhash decoding failure', { err, hash });
Expand Down
3 changes: 3 additions & 0 deletions app/javascript/flavours/glitch/components/hashtag.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,14 @@ export const accountsCountRenderer = (displayNumber, pluralReady) => (
/>
);

// @ts-expect-error
export const ImmutableHashtag = ({ hashtag }) => (
<Hashtag
name={hashtag.get('name')}
href={hashtag.get('url')}
to={`/tags/${hashtag.get('name')}`}
people={hashtag.getIn(['history', 0, 'accounts']) * 1 + hashtag.getIn(['history', 1, 'accounts']) * 1}
// @ts-expect-error
history={hashtag.get('history').reverse().map((day) => day.get('uses')).toArray()}
/>
);
Expand All @@ -64,6 +66,7 @@ ImmutableHashtag.propTypes = {
hashtag: ImmutablePropTypes.map.isRequired,
};

// @ts-expect-error
const Hashtag = ({ name, href, to, people, uses, history, className, description, withGraph }) => (
<div className={classNames('trends__item', className)}>
<div className='trends__item__name'>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const emojis = {};
// decompress
Object.keys(shortCodesToEmojiData).forEach((shortCode) => {
let [
filenameData, // eslint-disable-line no-unused-vars
filenameData, // eslint-disable-line @typescript-eslint/no-unused-vars
searchData,
] = shortCodesToEmojiData[shortCode];
let [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

const [
shortCodesToEmojiData,
skins, // eslint-disable-line no-unused-vars
categories, // eslint-disable-line no-unused-vars
short_names, // eslint-disable-line no-unused-vars
skins, // eslint-disable-line @typescript-eslint/no-unused-vars
categories, // eslint-disable-line @typescript-eslint/no-unused-vars
short_names, // eslint-disable-line @typescript-eslint/no-unused-vars
emojisWithoutShortCodes,
] = require('./emoji_compressed');
const { unicodeToFilename } = require('./unicode_to_filename');
Expand Down
9 changes: 8 additions & 1 deletion app/javascript/flavours/glitch/initial_state.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
* @property {boolean} activity_api_enabled
* @property {string} admin
* @property {boolean=} boost_modal
* @property {boolean=} favourite_modal
* @property {boolean} crop_images
* @property {boolean=} delete_modal
* @property {boolean=} disable_swiping
Expand Down Expand Up @@ -81,14 +82,19 @@
* @property {boolean=} use_pending_items
* @property {string} version
* @property {boolean} translation_enabled
* @property {object} local_settings
* @property {string} status_page_url
* @property {boolean} system_emoji_font
* @property {string} default_content_type
*/

/**
* @typedef InitialState
* @property {Record<string, Account>} accounts
* @property {InitialStateLanguage[]} languages
* @property {InitialStateMeta} meta
* @property {object} local_settings
* @property {number} max_toot_chars
* @property {number} poll_limits
*/

const element = document.getElementById('initial-state');
Expand All @@ -98,6 +104,7 @@ const initialState = element?.textContent && JSON.parse(element.textContent);
// Glitch-YRYR-specific “local settings”
if (initialState) {
try {
// @ts-expect-error
initialState.local_settings = JSON.parse(localStorage.getItem('mastodon-settings'));
} catch (e) {
initialState.local_settings = {};
Expand Down
3 changes: 2 additions & 1 deletion app/javascript/flavours/glitch/is_mobile.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export const layoutFromWindow = (layout_local_setting) => {
}
};

// @ts-expect-error
const iOS = /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream;

const listenerOptions = supportsPassiveEvents ? { passive: true } : false;
Expand All @@ -45,7 +46,7 @@ let userTouching = false;
const touchListener = () => {
userTouching = true;

window.removeEventListener('touchstart', touchListener, listenerOptions);
window.removeEventListener('touchstart', touchListener);
};

window.addEventListener('touchstart', touchListener, listenerOptions);
Expand Down
10 changes: 10 additions & 0 deletions app/javascript/flavours/glitch/stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ const subscribe = ({ channelName, params, onConnect }) => {
subscriptionCounters[key] = subscriptionCounters[key] || 0;

if (subscriptionCounters[key] === 0) {
// @ts-expect-error
sharedConnection.send(JSON.stringify({ type: 'subscribe', stream: channelName, ...params }));
}

Expand All @@ -74,7 +75,9 @@ const unsubscribe = ({ channelName, params, onDisconnect }) => {

subscriptionCounters[key] = subscriptionCounters[key] || 1;

// @ts-expect-error
if (subscriptionCounters[key] === 1 && sharedConnection.readyState === WebSocketClient.OPEN) {
// @ts-expect-error
sharedConnection.send(JSON.stringify({ type: 'unsubscribe', stream: channelName, ...params }));
}

Expand All @@ -87,6 +90,7 @@ const sharedCallbacks = {
subscriptions.forEach(subscription => subscribe(subscription));
},

// @ts-expect-error
received (data) {
const { stream } = data;

Expand Down Expand Up @@ -138,6 +142,7 @@ const channelNameWithInlineParams = (channelName, params) => {
* @param {function(Function, Function): { onConnect: (function(): void), onReceive: (function(StreamEvent): void), onDisconnect: (function(): void) }} callbacks
* @return {function(): void}
*/
// @ts-expect-error
export const connectStream = (channelName, params, callbacks) => (dispatch, getState) => {
const streamingAPIBaseURL = getState().getIn(['meta', 'streaming_api_base_url']);
const accessToken = getState().getIn(['meta', 'access_token']);
Expand Down Expand Up @@ -227,14 +232,19 @@ const handleEventSourceMessage = (e, received) => {
const createConnection = (streamingAPIBaseURL, accessToken, channelName, { connected, received, disconnected, reconnected }) => {
const params = channelName.split('&');

// @ts-expect-error
channelName = params.shift();

if (streamingAPIBaseURL.startsWith('ws')) {
// @ts-expect-error
const ws = new WebSocketClient(`${streamingAPIBaseURL}/api/v1/streaming/?${params.join('&')}`, accessToken);

// @ts-expect-error
ws.onopen = connected;
ws.onmessage = e => received(JSON.parse(e.data));
// @ts-expect-error
ws.onclose = disconnected;
// @ts-expect-error
ws.onreconnect = reconnected;

return ws;
Expand Down
3 changes: 0 additions & 3 deletions app/javascript/flavours/glitch/uuid.js

This file was deleted.

3 changes: 3 additions & 0 deletions app/javascript/flavours/glitch/uuid.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function uuid(a?: string): string {
return a ? ((a as any as number) ^ Math.random() * 16 >> (a as any as number) / 4).toString(16) : ('' + 1e7 + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, uuid);
}
Loading

0 comments on commit 00b8d9d

Please sign in to comment.