Skip to content

Commit e513fbe

Browse files
committed
refactor: transform utils
Signed-off-by: Adam Setch <adam.setch@outlook.com>
1 parent 3955b87 commit e513fbe

2 files changed

Lines changed: 29 additions & 10 deletions

File tree

src/renderer/utils/api/transform.ts

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,36 @@ import type { RawGitHubNotification } from './types';
1414

1515
import { getReasonDetails } from '../reason';
1616

17+
/**
18+
* Transform all raw notifications from Atlassian types to Atlassify types.
19+
*
20+
* @param rawNotifications - The Atlassian notifications.
21+
* @param account - The account.
22+
* @returns Transformed Atlassify notifications.
23+
*/
24+
export function transformNotifications(
25+
rawNotifications: RawGitHubNotification[],
26+
account: Account,
27+
): GitifyNotification[] {
28+
return rawNotifications.map((raw) => {
29+
return transformNotification(raw, account);
30+
});
31+
}
32+
1733
/**
1834
* Transform a raw GitHub notification to GitifyNotification.
1935
* Called immediately after REST API response is received.
2036
*
2137
* This is the ONLY place where raw GitHub types should be converted
2238
* to Gitify's internal notification type.
39+
*
40+
* @param raw - The GitHub notification.
41+
* @param account - The account.
42+
* @returns A transformed Gitify notification.
2343
*/
24-
export function transformNotification(
44+
function transformNotification(
2545
raw: RawGitHubNotification,
2646
account: Account,
27-
order = 0,
2847
): GitifyNotification {
2948
return {
3049
id: raw.id,
@@ -33,10 +52,9 @@ export function transformNotification(
3352
reason: transformReason(raw.reason),
3453
subject: transformSubject(raw.subject),
3554
repository: transformRepository(raw.repository),
36-
account,
37-
order,
38-
// Display fields start as undefined, populated by formatNotification post-enrichment
39-
display: undefined,
55+
account: account,
56+
order: 0, // Will be set later in stabilizeNotificationsOrder
57+
display: undefined, // Display fields start as undefined, populated by formatNotification post-enrichment
4058
};
4159
}
4260

src/renderer/utils/notifications/notifications.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414
} from '../api/client';
1515
import { determineFailureType } from '../api/errors';
1616
import type { FetchMergedDetailsTemplateQuery } from '../api/graphql/generated/graphql';
17-
import { transformNotification } from '../api/transform';
17+
import { transformNotifications } from '../api/transform';
1818
import { rendererLogError, rendererLogWarn } from '../logger';
1919
import {
2020
filterBaseNotifications,
@@ -92,9 +92,10 @@ export async function getAllNotifications(
9292
try {
9393
const rawNotifications = await accountNotifications.notifications;
9494

95-
let notifications = rawNotifications.map((raw) => {
96-
return transformNotification(raw, accountNotifications.account);
97-
});
95+
let notifications = transformNotifications(
96+
rawNotifications,
97+
accountNotifications.account,
98+
);
9899

99100
notifications = filterBaseNotifications(
100101
notifications,

0 commit comments

Comments
 (0)