Skip to content

Commit

Permalink
feat: add display name/discriminator support
Browse files Browse the repository at this point in the history
  • Loading branch information
Rexogamer committed Oct 31, 2023
1 parent c7f200f commit 5ee2176
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 53 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
"react-native-vector-icons": "^10.0.0",
"readable-stream": "^4.4.2",
"revkit": "^1.1.14",
"revolt.js": "npm:@rexovolt/revolt.js",
"revolt.js": "npm:@rexovolt/revolt.js@^6.2.0",
"stream-browserify": "^3.0.0",
"timers-browserify": "^2.0.12",
"tty-browserify": "^0.0.1",
Expand Down
23 changes: 18 additions & 5 deletions src/components/common/atoms/Username.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {app, client} from '../../../Generic';
import {currentTheme, styles} from '../../../Theme';
import {Text} from './Text';
import {USER_IDS} from '../../../lib/consts';
import {getColour, getHighestRole} from '../../../lib/utils';
import {getColour} from '../../../lib/utils';

type UsernameProps = {
server?: Server;
Expand All @@ -17,26 +17,37 @@ type UsernameProps = {
size?: number;
masquerade?: string | null;
color?: string;
skipDisplayName?: boolean;
};

export const Username = observer(
({server, user, noBadge, size, masquerade, color}: UsernameProps) => {
({
server,
user,
noBadge,
size,
masquerade,
color,
skipDisplayName,
}: UsernameProps) => {
if (typeof user !== 'object') {
return (
<Text style={size ? {fontSize: size} : {}}>{'<Unknown User>'}</Text>
);
}
let memberObject = server
const memberObject = server
? client.members.getKey({
server: server?._id,
user: user?._id,
})
: undefined;
let roleColor = color ? getColour(color) : styles.textDefault.color;
let name =
const name =
server && memberObject?.nickname
? memberObject?.nickname
: user?.username;
: !skipDisplayName
? user.display_name ?? user.username
: user.username;
if (server && memberObject?.roles && memberObject?.roles?.length > 0) {
let srv = client.servers.get(memberObject._id.server);
if (srv?.roles) {
Expand Down Expand Up @@ -67,7 +78,9 @@ export const Username = observer(
fontWeight: 'bold',
fontSize: size || app.settings.get('ui.messaging.fontSize'),
}}>
{skipDisplayName ? '@' : null}
{masquerade ?? name}
{skipDisplayName ? `#${user.discriminator}` : null}
</Text>
{!noBadge ? (
<>
Expand Down
57 changes: 38 additions & 19 deletions src/components/sheets/ProfileSheet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
import {BottomSheet} from '../common/BottomSheet';
import {MarkdownView} from '../common/MarkdownView';
import {UserList} from '../navigation/UserList';
import {GapView} from '../layout';

// const Image = FastImage;

Expand Down Expand Up @@ -175,26 +176,44 @@ export const ProfileSheet = observer(() => {
style={{flexDirection: 'row', width: '80%', marginBottom: 12}}>
<View>
<Username user={user} server={server ?? undefined} size={24} />
<View key={1} style={{flexDirection: 'row'}}>
{server ? (
<>
{client.members.getKey({
server: server?._id,
user: user._id,
})?.avatar?._id !== user.avatar?._id ? (
<>
<Avatar size={24} user={user} />
<Text type={'header'} style={{marginLeft: 4}}>
@
</Text>
</>
) : (
<Text type={'header'}>@</Text>
)}
{!server ? (
<Username
user={user}
server={server ?? undefined}
size={16}
color={currentTheme.foregroundSecondary}
skipDisplayName
/>
) : null}
{server ? (
<View
style={{
flexDirection: 'row',
}}>
{client.members.getKey({
server: server?._id,
user: user._id,
})?.avatar?._id !== user.avatar?._id &&
client.members.getKey({
server: server?._id,
user: user._id,
})?.avatar?._id !== undefined ? (
<View style={{alignSelf: 'center', marginEnd: 4}}>
<Avatar size={24} user={user} />
</View>
) : null}
<View style={{flexDirection: 'column'}}>
<Username user={user} size={16} noBadge />
</>
) : null}
</View>
<Username
user={user}
size={16}
color={currentTheme.foregroundSecondary}
noBadge
skipDisplayName
/>
</View>
</View>
) : null}
{user.status?.text ? <Text>{user.status?.text}</Text> : <></>}
</View>
</View>
Expand Down
43 changes: 15 additions & 28 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3645,13 +3645,6 @@ available-typed-arrays@^1.0.5:
resolved "https://registry.yarnpkg.com/available-typed-arrays/-/available-typed-arrays-1.0.5.tgz#92f95616501069d07d10edb2fc37d3e1c65123b7"
integrity sha512-DMD0KiN46eipeziST1LPP/STfDU0sufISXmjSgvVsoU2tqxctQeASejWcfNtxYKqETM1UxQ8sp2OrSBWpHY6sw==

axios@^0.21.4:
version "0.21.4"
resolved "https://registry.yarnpkg.com/axios/-/axios-0.21.4.tgz#c67b90dc0568e5c1cf2b0b858c43ba28e2eda575"
integrity sha512-ut5vewkiu8jjGBdqpM44XxjuCjq9LAKeHVmoVfHVzy8eHgxxq8SbAVQNovDA8mVi05kP0Ea/n/UzcSHcTJQfNg==
dependencies:
follow-redirects "^1.14.0"

axios@^0.26.1:
version "0.26.1"
resolved "https://registry.yarnpkg.com/axios/-/axios-0.26.1.tgz#1ede41c51fcf51bbbd6fd43669caaa4f0495aaa9"
Expand Down Expand Up @@ -5366,7 +5359,7 @@ eventemitter3@^4.0.7:
resolved "https://registry.yarnpkg.com/eventemitter3/-/eventemitter3-4.0.7.tgz#2de9b68f6528d5644ef5c59526a1b4a07306169f"
integrity sha512-8guHBZCwKnFhYdHr2ysuRWErTwhoN2X8XELRlrRwpmfeY2jjuUN4taQMsULKUVo1K4DvZl+0pgfyoysHxvmvEw==

eventemitter3@^5.0.0:
eventemitter3@^5.0.0, eventemitter3@^5.0.1:
version "5.0.1"
resolved "https://registry.yarnpkg.com/eventemitter3/-/eventemitter3-5.0.1.tgz#53f5ffd0a492ac800721bb42c66b841de96423c4"
integrity sha512-GWkBvjiSZK87ELrYOSESUYeVIc9mvLLf/nXalMOS5dYrgZq9o5OVkbZAVM06CVxYsCwH9BDZFPlQTlPA1j4ahA==
Expand Down Expand Up @@ -5659,7 +5652,7 @@ flow-parser@^0.206.0:
resolved "https://registry.yarnpkg.com/flow-parser/-/flow-parser-0.206.0.tgz#f4f794f8026535278393308e01ea72f31000bfef"
integrity sha512-HVzoK3r6Vsg+lKvlIZzaWNBVai+FXTX1wdYhz/wVlH13tb/gOdLXmlTqy6odmTBhT5UoWUbq0k8263Qhr9d88w==

follow-redirects@^1.14.0, follow-redirects@^1.14.8, follow-redirects@^1.15.0:
follow-redirects@^1.14.8, follow-redirects@^1.15.0:
version "1.15.2"
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.15.2.tgz#b460864144ba63f2681096f274c4e57026da2c13"
integrity sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA==
Expand Down Expand Up @@ -7513,12 +7506,7 @@ logkitty@^0.7.1:
dayjs "^1.8.15"
yargs "^15.1.0"

long@^5.2.0:
version "5.2.1"
resolved "https://registry.yarnpkg.com/long/-/long-5.2.1.tgz#e27595d0083d103d2fa2c20c7699f8e0c92b897f"
integrity sha512-GKSNGeNAtw8IryjjkhZxuKB3JzlcLTwjtiQCHKvqQet81I93kXslhDQruGI/QsddO83mcDToBVy7GqGS/zYf/A==

long@^5.2.1:
long@^5.2.1, long@^5.2.3:
version "5.2.3"
resolved "https://registry.yarnpkg.com/long/-/long-5.2.3.tgz#a3ba97f3877cf1d778eccbcb048525ebb77499e1"
integrity sha512-lcHwpNoggQTObv5apGNCTdJrO69eHOZMi4BNC+rTLER8iHAqGrUVeLh/irVIM7zTw2bOXA8T6uNPeujwOLg/2Q==
Expand Down Expand Up @@ -9954,7 +9942,7 @@ revkit@^1.1.14:
revolt-api "^0.6.7"
ulid "^2.3.0"

[email protected], revolt-api@^0.6.7, revolt-api@^0.6.8:
[email protected], revolt-api@^0.6.7:
version "0.6.8"
resolved "https://registry.yarnpkg.com/revolt-api/-/revolt-api-0.6.8.tgz#8703e2ea28489f6ed69a0e861a44a8747b4a46c0"
integrity sha512-ktqs/3M9iiB1aBFmyF1pw7Mt8/k44VGXF5TGed7+3eIFtJIEGPSt+zcvrK/EfL3dYmbtUcZL+apFDEjot6yr3Q==
Expand All @@ -9963,23 +9951,22 @@ [email protected], revolt-api@^0.6.7, revolt-api@^0.6.8:
axios "^0.26.1"
lodash.defaultsdeep "^4.6.1"

"revolt.js@npm:@rexovolt/revolt.js":
version "6.1.0"
resolved "https://registry.yarnpkg.com/@rexovolt/revolt.js/-/revolt.js-6.1.0.tgz#11c9e28e6ec1e768614a016f2419a91d338591c9"
integrity sha512-THmIxFr/fvyi8VVrIRdwEpYtK+ITRQq3RflzejoCNPjBxzeJd1NSKrA5d1djnXLchin+saxprtmuSU7q4LyPFQ==
"revolt.js@npm:@rexovolt/revolt.js@^6.2.0":
version "6.2.0"
resolved "https://registry.yarnpkg.com/@rexovolt/revolt.js/-/revolt.js-6.2.0.tgz#fcb53a93c709a24df49b73a4a9fbc40201790cc4"
integrity sha512-aViNMHE8hx+foenk3eI0f/LuD2z5S4qjedxCzSwQZrjnIlwdQMhTy0SU7bHsSE87Rjs89Xrmi78siLw5CykzlQ==
dependencies:
"@insertish/exponential-backoff" "3.1.0-patch.2"
"@insertish/isomorphic-ws" "^4.0.1"
axios "^0.21.4"
eventemitter3 "^4.0.7"
eventemitter3 "^5.0.1"
lodash.defaultsdeep "^4.6.1"
lodash.flatten "^4.4.0"
lodash.isequal "^4.5.0"
long "^5.2.0"
long "^5.2.3"
mobx "^6.3.2"
revolt-api "0.6.8"
ulid "^2.3.0"
ws "^8.2.2"
ws "^8.14.2"

rimraf@^2.2.8, rimraf@^2.6.3:
version "2.7.1"
Expand Down Expand Up @@ -11209,10 +11196,10 @@ ws@^7, ws@^7.5.1:
resolved "https://registry.yarnpkg.com/ws/-/ws-7.5.9.tgz#54fa7db29f4c7cec68b1ddd3a89de099942bb591"
integrity sha512-F+P9Jil7UiSKSkppIiD94dN07AwvFixvLIj1Og1Rl9GGMuNipJnV9JzjD6XuqmAeiswGvUmNLjr5cFuXwNS77Q==

ws@^8.2.2:
version "8.13.0"
resolved "https://registry.yarnpkg.com/ws/-/ws-8.13.0.tgz#9a9fb92f93cf41512a0735c8f4dd09b8a1211cd0"
integrity sha512-x9vcZYTrFPC7aSIbj7sRCYo7L/Xb8Iy+pW0ng0wt2vCJv7M9HOMy0UoN3rr+IFC7hb7vXoqS+P9ktyLLLhO+LA==
ws@^8.14.2:
version "8.14.2"
resolved "https://registry.yarnpkg.com/ws/-/ws-8.14.2.tgz#6c249a806eb2db7a20d26d51e7709eab7b2e6c7f"
integrity sha512-wEBG1ftX4jcglPxgFCMJmZ2PLtSbJ2Peg6TmpJFTbe9GZYOQCDPdMYu/Tm0/bGZkw8paZnJY45J4K2PZrLYq8g==

xdg-basedir@^3.0.0:
version "3.0.0"
Expand Down

0 comments on commit 5ee2176

Please sign in to comment.