fix(chat): fix bot status not showing. Closes #3046

This commit is contained in:
Gabe Kangas 2023-05-31 13:28:06 -07:00
parent 1ed51859b0
commit 71703f2245
No known key found for this signature in database
GPG key ID: 4345B2060657F330
5 changed files with 19 additions and 15 deletions

View file

@ -28,9 +28,10 @@ const testMessages = `[
"timestamp": "2022-04-28T20:30:27.001762726Z", "timestamp": "2022-04-28T20:30:27.001762726Z",
"user": { "user": {
"id": "h_5GQ6E7R", "id": "h_5GQ6E7R",
"displayName": "UserDisplayName42", "displayName": "iAmABot",
"displayColor": 329, "displayColor": 329,
"createdAt": "2022-03-24T03:52:37.966584694Z", "createdAt": "2022-03-24T03:52:37.966584694Z",
"isBot": true,
"previousNames": [ "previousNames": [
"gifted-nobel", "gifted-nobel",
"EliteMooseTaskForce" "EliteMooseTaskForce"
@ -48,13 +49,14 @@ const testMessages = `[
"timestamp": "2022-04-28T20:30:28.806999545Z", "timestamp": "2022-04-28T20:30:28.806999545Z",
"user": { "user": {
"id": "h_5GQ6E7R", "id": "h_5GQ6E7R",
"displayName": "EliteMooseTaskForce", "displayName": "IAmABot",
"displayColor": 329, "displayColor": 329,
"createdAt": "2022-03-24T03:52:37.966584694Z", "createdAt": "2022-03-24T03:52:37.966584694Z",
"previousNames": [ "previousNames": [
"gifted-nobel", "gifted-nobel",
"EliteMooseTaskForce" "EliteMooseTaskForce"
], ],
"isBot": true,
"nameChangedAt": "2022-04-26T23:56:05.531287897Z", "nameChangedAt": "2022-04-26T23:56:05.531287897Z",
"scopes": [ "scopes": [
"" ""
@ -68,13 +70,14 @@ const testMessages = `[
"timestamp": "2022-04-28T20:30:34.500150601Z", "timestamp": "2022-04-28T20:30:34.500150601Z",
"user": { "user": {
"id": "h_5GQ6E7R", "id": "h_5GQ6E7R",
"displayName": "EliteMooseTaskForce", "displayName": "IAmABot",
"displayColor": 329, "displayColor": 329,
"createdAt": "2022-03-24T03:52:37.966584694Z", "createdAt": "2022-03-24T03:52:37.966584694Z",
"previousNames": [ "previousNames": [
"gifted-nobel", "gifted-nobel",
"EliteMooseTaskForce" "EliteMooseTaskForce"
], ],
"isBot": true,
"nameChangedAt": "2022-04-26T23:56:05.531287897Z", "nameChangedAt": "2022-04-26T23:56:05.531287897Z",
"scopes": [ "scopes": [
"" ""

View file

@ -83,7 +83,7 @@ function checkIsModerator(message: ChatMessage | ConnectedClientInfoEvent) {
const u = new User(user); const u = new User(user);
return u.isModerator(); return u.isModerator;
} }
export const ChatContainer: FC<ChatContainerProps> = ({ export const ChatContainer: FC<ChatContainerProps> = ({
@ -162,8 +162,8 @@ export const ChatContainer: FC<ChatContainerProps> = ({
highlightString={usernameToHighlight} // What to highlight in the message highlightString={usernameToHighlight} // What to highlight in the message
sentBySelf={message.user?.id === chatUserId} // The local user sent this message sentBySelf={message.user?.id === chatUserId} // The local user sent this message
sameUserAsLast={collapsed} sameUserAsLast={collapsed}
isAuthorModerator={message.user?.scopes?.includes('MODERATOR')} isAuthorModerator={message.user?.isModerator}
isAuthorBot={message.user?.scopes?.includes('BOT')} isAuthorBot={message.user?.isBot}
isAuthorAuthenticated={message.user?.authenticated} isAuthorAuthenticated={message.user?.authenticated}
key={message.id} key={message.id}
/> />

View file

@ -304,7 +304,7 @@ export const ClientConfigStore: FC = () => {
); );
if (message as ChatEvent) { if (message as ChatEvent) {
const m = new ChatEvent(message); const m = new ChatEvent(message);
if (!hasBeenModeratorNotified && m.user?.isModerator()) { if (!hasBeenModeratorNotified && m.user?.isModerator) {
setChatMessages(currentState => [...currentState, message as ChatEvent]); setChatMessages(currentState => [...currentState, message as ChatEvent]);
hasBeenModeratorNotified = true; hasBeenModeratorNotified = true;
} }

View file

@ -9,8 +9,8 @@ export const createUser = (name: string, color: number, createdAt: Date): User =
nameChangedAt: createdAt, nameChangedAt: createdAt,
previousNames: [], previousNames: [],
scopes: [], scopes: [],
isBot: false,
isModerator: () => false, isModerator: false,
}); });
export const spidermanUser = createUser('Spiderman', 1, new Date(2020, 1, 2)); export const spidermanUser = createUser('Spiderman', 1, new Date(2020, 1, 2));

View file

@ -9,6 +9,11 @@ export class User {
this.nameChangedAt = u.nameChangedAt; this.nameChangedAt = u.nameChangedAt;
this.scopes = u.scopes; this.scopes = u.scopes;
this.authenticated = u.authenticated; this.authenticated = u.authenticated;
this.isBot = u.isBot;
if (this.scopes && this.scopes.length > 0) {
this.isModerator = this.scopes.includes('MODERATOR');
}
} }
id: string; id: string;
@ -27,11 +32,7 @@ export class User {
authenticated: boolean; authenticated: boolean;
public isModerator = (): boolean => { isBot: boolean;
if (!this.scopes || this.scopes.length === 0) {
return false;
}
return this.scopes.includes('MODERATOR'); isModerator: boolean;
};
} }