Skip to content

Commit

Permalink
fix: clean up circular imports
Browse files Browse the repository at this point in the history
  • Loading branch information
Rexogamer committed May 9, 2024
1 parent 2dd52a0 commit 72f3828
Show file tree
Hide file tree
Showing 38 changed files with 285 additions and 275 deletions.
2 changes: 1 addition & 1 deletion i18n/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import 'intl-pluralrules';

import {resources} from '@rvmob-i18n/languages';
import {languageDetectorPlugin} from '@rvmob-i18n/getLanguage';
import {Text} from '@rvmob/components/common/atoms';
import {Text} from '@rvmob/components/common/atoms/Text';

i18n
.use(initReactI18next) // passes i18n down to react-i18next
Expand Down
74 changes: 1 addition & 73 deletions src/Generic.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,11 @@
import {Linking, View} from 'react-native';

import AsyncStorage from '@react-native-async-storage/async-storage';

import {API, Channel, Client, Message, Server} from 'revolt.js';

import {setLanguage} from '@rvmob-i18n/i18n';
import {languages} from '@rvmob-i18n/languages';
import {Image} from '@rvmob/crossplat/Image';
import {setTheme, themes} from '@rvmob/Theme';
import {
DEFAULT_API_URL,
DEFAULT_MAX_SIDE,
DISCOVER_URL,
LOADING_SCREEN_REMARKS,
RE_INVITE,
RE_BOT_INVITE,
WIKI_URL,
} from '@rvmob/lib/consts';
import {DEFAULT_API_URL, LOADING_SCREEN_REMARKS} from '@rvmob/lib/consts';
import {
CreateChannelModalProps,
DeletableObject,
Expand Down Expand Up @@ -418,67 +407,6 @@ getAPIURL().then(url => {
});
});

export const openUrl = (url: string) => {
console.log(`[FUNCTIONS] Handling URL: ${url}`);
if (url.startsWith('/@')) {
console.log(`[FUNCTIONS] Opening user profile from URL: ${url}`);
let id = url.slice(2);
let user = client.users.get(id);
if (user) {
app.openProfile(user);
}
return;
}
let match = url.match(RE_INVITE);
let isDiscover = url.match(DISCOVER_URL);
let isWiki = url.match(WIKI_URL);
if (match && !isWiki && !isDiscover) {
console.log(`[FUNCTIONS] Opening server invite from URL: ${url}`);
app.openInvite(match[0].split('/').pop());
return;
}
let botmatch = url.match(RE_BOT_INVITE);
if (botmatch) {
console.log(`[FUNCTIONS] Opening bot invite from URL: ${url}`);
app.openBotInvite(botmatch[0].split('/').pop());
return;
}
if (url.startsWith('/bot/')) {
console.log(`[FUNCTIONS] Opening bot invite from URL: ${url}`);
const id = url.split('/');
app.openBotInvite(id[2]);
return;
}

Linking.openURL(url);
};

export const GeneralAvatar = ({
attachment,
size,
directory,
}: {
attachment: any;
size: number;
directory?: string;
}) => {
const uri = directory
? client.configuration?.features.autumn.url + directory + attachment
: client.generateFileURL(attachment) + '?max_side=' + DEFAULT_MAX_SIDE;
return (
<View>
{
<Image
source={{
uri: uri,
}}
style={{width: size || 35, height: size || 35, borderRadius: 10000}}
/>
}
</View>
);
};

export var selectedRemark =
LOADING_SCREEN_REMARKS[
Math.floor(Math.random() * LOADING_SCREEN_REMARKS.length)
Expand Down
3 changes: 1 addition & 2 deletions src/MessageBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@ import {ulid} from 'ulid';

import {DocumentPicker} from './crossplat/DocumentPicker';
import {app, client, setFunction} from './Generic';
import {Avatar} from './Profile';
import {styles, currentTheme} from './Theme';
import {Text, Username} from './components/common/atoms';
import {Avatar, Text, Username} from './components/common/atoms';
import {USER_IDS} from './lib/consts';
import {ReplyingMessage} from './lib/types';
import {getReadableFileSize, showToast} from './lib/utils';
Expand Down
3 changes: 2 additions & 1 deletion src/Modals.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ import MaterialCommunityIcon from 'react-native-vector-icons/MaterialCommunityIc

import {API, Channel, Server, User} from 'revolt.js';

import {app, client, openUrl, setFunction} from './Generic';
import {app, client, setFunction} from './Generic';
import {
CreateChannelModalProps,
DeletableObject,
TextEditingModalProps,
} from './lib/types';
import {openUrl} from '@rvmob/lib/utils';
import {currentTheme} from './Theme';
import {GapView} from './components/layout';
import {
Expand Down
132 changes: 5 additions & 127 deletions src/Profile.tsx
Original file line number Diff line number Diff line change
@@ -1,135 +1,13 @@
import {observer} from 'mobx-react-lite';
import {client, app} from './Generic';
import {client} from './Generic';
import {currentTheme} from './Theme';
import {Pressable, View} from 'react-native';
import {View} from 'react-native';
import {Server, User, Channel} from 'revolt.js';
import {Text, Username} from './components/common/atoms';
import {Image} from '@rvmob/crossplat/Image';
import {DEFAULT_MAX_SIDE} from './lib/consts';
import {Avatar} from '@rvmob/components/common/atoms/Avatar';
import {Text} from '@rvmob/components/common/atoms/Text';
import {Username} from '@rvmob/components/common/atoms/Username';
import {getColour} from './lib/utils';

type AvatarProps = {
channel?: Channel;
user?: User | null;
server?: Server;
status?: boolean;
size?: number;
backgroundColor?: string;
masquerade?: string;
pressable?: boolean;
};

export const Avatar = observer(
({
channel,
user,
server,
status,
size,
backgroundColor,
masquerade,
pressable,
}: AvatarProps) => {
let memberObject =
server && user
? client.members.getKey({
server: server?._id,
user: user?._id,
})
: null;
let statusColor;
let statusScale = 2.7;
if (status) {
const s = user?.online ? user.status?.presence || 'Online' : 'Offline';
statusColor = currentTheme[`status${s}`];
}
let Container = pressable
? ({children}) => (
<Pressable
onPress={() => app.openImage(memberObject?.avatar || user?.avatar)}>
{children}
</Pressable>
)
: View;
if (user) {
return (
<Container>
<Image
source={{
uri:
(masquerade
? masquerade
: server &&
memberObject?.generateAvatarURL &&
memberObject?.generateAvatarURL()
? memberObject?.generateAvatarURL()
: user?.generateAvatarURL()) +
'?max_side=' +
DEFAULT_MAX_SIDE,
}}
style={{width: size || 35, height: size || 35, borderRadius: 10000}}
/>
{status ? (
<View
style={{
width: Math.round(size / statusScale),
height: Math.round(size / statusScale),
backgroundColor: statusColor,
borderRadius: 10000,
marginTop: -Math.round(size / statusScale),
left: size - Math.round(size / statusScale),
borderWidth: Math.round(size / 20),
borderColor: backgroundColor || currentTheme.backgroundPrimary,
}}
/>
) : null}
{masquerade && app.settings.get('ui.messaging.showMasqAvatar') ? (
<Image
style={{
width: Math.round(size / statusScale),
height: Math.round(size / statusScale),
marginBottom: -Math.round(size / statusScale),
bottom: size,
borderRadius: 10000,
borderWidth: Math.round(size / 30),
borderColor: backgroundColor || currentTheme.backgroundPrimary,
}}
source={{
uri:
server &&
memberObject?.generateAvatarURL &&
memberObject?.generateAvatarURL()
? memberObject?.generateAvatarURL()
: user?.generateAvatarURL(),
}}
/>
) : null}
</Container>
);
}
if (channel) {
return (
<View>
{channel?.generateIconURL() ? (
<Image
source={{
uri:
channel?.generateIconURL() + '?max_side=' + DEFAULT_MAX_SIDE,
}}
style={{
width: size || 35,
height: size || 35,
borderRadius: 10000,
}}
/>
) : null}
</View>
);
}
return <></>;
},
);

type MiniProfileProps = {
user?: User;
scale?: number;
Expand Down
3 changes: 1 addition & 2 deletions src/SideMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ import MaterialIcon from 'react-native-vector-icons/MaterialIcons';
import {Server} from 'revolt.js';

import {app, setFunction, client} from './Generic';
import {Avatar} from './Profile';
import {styles, currentTheme} from './Theme';
import {Button} from './components/common/atoms';
import {Avatar, Button} from './components/common/atoms';
import {ChannelList} from './components/navigation/ChannelList';
import {ServerList} from './components/navigation/ServerList';
import {DEFAULT_API_URL} from './lib/consts';
Expand Down
3 changes: 1 addition & 2 deletions src/components/Notification.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ import MaterialCommunityIcon from 'react-native-vector-icons/MaterialCommunityIc

import {Message} from 'revolt.js';

import {Avatar} from '../Profile';
import {currentTheme, styles} from '../Theme';
import {Text, Username} from './common/atoms';
import {Avatar, Text, Username} from './common/atoms';
import {MarkdownView} from './common/MarkdownView';
import {parseRevoltNodes} from '../lib/utils';

Expand Down
13 changes: 7 additions & 6 deletions src/components/common/MarkdownView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ import {createContext, useState} from 'react';
import spoilerPlugin from '@traptitech/markdown-it-spoiler';
import Markdown, {hasParents, MarkdownIt} from 'react-native-markdown-display';

import {app, openUrl} from '../../Generic';
import {currentTheme} from '../../Theme';
import {app} from '@rvmob/Generic';
import {currentTheme} from '@rvmob/Theme';
import {Text} from './atoms';
import {renderEmojis} from './messaging/Emoji';
import {renderEmoji} from './messaging/Emoji';
import {openUrl} from '@rvmob/lib/utils';

const defaultMarkdownIt = MarkdownIt({typographer: true, linkify: true})
.disable(['image'])
Expand Down Expand Up @@ -51,8 +52,8 @@ const spoilerRule = {
: spoilerStyle.hiddenSpoiler),
}}>
{
/* FIXME: Rendering emojis reveals spoiler markdown
renderEmojis(node.content)*/
/* FIXME: Rendering emoji reveals spoiler markdown
renderEmoji(node.content)*/
node.content
}
</Text>
Expand All @@ -63,7 +64,7 @@ const spoilerRule = {

return (
<Text key={node.key} style={{...inheritedStyles, ...styles.text}}>
{renderEmojis(node.content)}
{renderEmoji(node.content)}
</Text>
);
},
Expand Down
Loading

0 comments on commit 72f3828

Please sign in to comment.