Skip to content
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
10 changes: 4 additions & 6 deletions src/renderer/components/notifications/NotificationFooter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { RelativeTime, Stack, Text } from '@primer/react';
import { type GitifyNotification, Opacity, Size } from '../../types';
import { cn } from '../../utils/cn';
import { openUserProfile } from '../../utils/links';
import { createNotificationHandler } from '../../utils/notifications/handlers';
import { AvatarWithFallback } from '../avatars/AvatarWithFallback';
import { MetricGroup } from '../metrics/MetricGroup';

Expand All @@ -15,6 +16,8 @@ interface NotificationFooterProps {
export const NotificationFooter: FC<NotificationFooterProps> = ({
notification,
}: NotificationFooterProps) => {
const handler = createNotificationHandler(notification);

return (
<Stack
align="center"
Expand Down Expand Up @@ -44,12 +47,7 @@ export const NotificationFooter: FC<NotificationFooterProps> = ({
) : (
<AvatarWithFallback
size={Size.SMALL}
userType={
notification.subject.type === 'RepositoryDependabotAlertsThread' ||
notification.subject.type === 'RepositoryVulnerabilityAlert'
? 'Bot'
: 'User'
}
userType={handler.defaultUserType()}
/>
)}

Expand Down
5 changes: 5 additions & 0 deletions src/renderer/utils/notifications/handlers/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
type Link,
type SettingsState,
type SubjectType,
type UserType,
} from '../../../types';
import type { NotificationTypeHandler } from './types';
import { formatForDisplay } from './utils';
Expand Down Expand Up @@ -61,6 +62,10 @@ export class DefaultHandler implements NotificationTypeHandler {
defaultUrl(notification: GitifyNotification): Link {
return notification.repository.htmlUrl;
}

defaultUserType(): UserType {
return 'User';
}
}

export const defaultHandler = new DefaultHandler();
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { FC } from 'react';
import type { OcticonProps } from '@primer/octicons-react';
import { AlertIcon } from '@primer/octicons-react';

import type { GitifyNotification, Link } from '../../../types';
import type { GitifyNotification, Link, UserType } from '../../../types';
import { DefaultHandler, defaultHandler } from './default';

class RepositoryDependabotAlertsThreadHandler extends DefaultHandler {
Expand All @@ -18,6 +18,10 @@ class RepositoryDependabotAlertsThreadHandler extends DefaultHandler {
url.pathname += '/security/dependabot';
return url.href as Link;
}

defaultUserType(): UserType {
return 'Bot';
}
}

export const repositoryDependabotAlertsThreadHandler =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { FC } from 'react';

import { AlertIcon, type OcticonProps } from '@primer/octicons-react';

import type { GitifyNotification } from '../../../types';
import type { GitifyNotification, UserType } from '../../../types';
import { DefaultHandler } from './default';

class RepositoryVulnerabilityAlertHandler extends DefaultHandler {
Expand All @@ -11,6 +11,10 @@ class RepositoryVulnerabilityAlertHandler extends DefaultHandler {
iconType(_notification: GitifyNotification): FC<OcticonProps> {
return AlertIcon;
}

defaultUserType(): UserType {
return 'Bot';
}
}

export const repositoryVulnerabilityAlertHandler =
Expand Down
6 changes: 6 additions & 0 deletions src/renderer/utils/notifications/handlers/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import type {
Link,
SettingsState,
SubjectType,
UserType,
} from '../../../types';

export interface NotificationTypeHandler {
Expand Down Expand Up @@ -60,4 +61,9 @@ export interface NotificationTypeHandler {
* Default url for notification type.
*/
defaultUrl(notification: GitifyNotification): Link;

/**
* Default user type for notification type.
*/
defaultUserType(): UserType;
}