Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 2 additions & 2 deletions src/renderer/utils/api/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,8 @@ export async function searchDiscussions(
notification.subject.title,
),
firstDiscussions: 1,
lastComments: 1,
lastReplies: 1,
lastComments: 100,
lastReplies: 100,
Copy link

Copilot AI Aug 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Increasing from 1 to 100 comments significantly increases the API response size and processing time. Consider using a smaller number like 10-20 initially, or make this configurable based on the actual need.

Suggested change
lastReplies: 100,
lastComments: options?.lastComments ?? 20,
lastReplies: options?.lastReplies ?? 20,

Copilot uses AI. Check for mistakes.
Copy link

Copilot AI Aug 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Increasing from 1 to 100 replies significantly increases the API response size and processing time. Consider using a smaller number like 10-20 initially, or make this configurable based on the actual need.

Suggested change
lastReplies: 100,
lastReplies,

Copilot uses AI. Check for mistakes.
includeIsAnswered: isAnsweredDiscussionFeatureSupported(
notification.account,
),
Expand Down
12 changes: 7 additions & 5 deletions src/renderer/utils/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import type { PlatformType } from './auth/types';
import { Constants } from './constants';
import {
getCheckSuiteAttributes,
getLatestDiscussionComment,
getClosestDiscussionCommentOrReply,
getWorkflowRunAttributes,
} from './subject';

Expand Down Expand Up @@ -93,10 +93,12 @@ async function getDiscussionUrl(notification: Notification): Promise<Link> {
if (discussion) {
url.href = discussion.url;

const latestComment = getLatestDiscussionComment(discussion.comments.nodes);

if (latestComment) {
url.hash = `#discussioncomment-${latestComment.databaseId}`;
const closestComment = getClosestDiscussionCommentOrReply(
notification,
discussion.comments.nodes,
);
if (closestComment) {
url.hash = `#discussioncomment-${closestComment.databaseId}`;
}
}

Expand Down
32 changes: 24 additions & 8 deletions src/renderer/utils/subject.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { differenceInMilliseconds } from 'date-fns';

import { logError } from '../../shared/logger';
import type { Link } from '../types';
import type {
Expand Down Expand Up @@ -162,7 +164,8 @@ async function getGitifySubjectForDiscussion(
}
}

const latestDiscussionComment = getLatestDiscussionComment(
const latestDiscussionComment = getClosestDiscussionCommentOrReply(
notification,
discussion.comments.nodes,
);

Expand Down Expand Up @@ -190,20 +193,33 @@ async function getGitifySubjectForDiscussion(
};
}

export function getLatestDiscussionComment(
export function getClosestDiscussionCommentOrReply(
notification: Notification,
comments: DiscussionComment[],
): DiscussionComment | null {
if (!comments || comments.length === 0) {
return null;
}

// Return latest reply if available
if (comments[0].replies.nodes.length === 1) {
return comments[0].replies.nodes[0];
}
const targetTimestamp = notification.updated_at;

const allCommentsAndReplies = comments.flatMap((comment) => [
comment,
...comment.replies.nodes,
]);

// Find the closest match using the target timestamp
const closestComment = allCommentsAndReplies.reduce((prev, curr) => {
const prevDiff = Math.abs(
differenceInMilliseconds(prev.createdAt, targetTimestamp),
);
const currDiff = Math.abs(
differenceInMilliseconds(curr.createdAt, targetTimestamp),
Comment thread
setchy marked this conversation as resolved.
Comment thread
setchy marked this conversation as resolved.
);
return currDiff < prevDiff ? curr : prev;
});

// Return latest comment if no replies
return comments[0];
return closestComment;
}

async function getGitifySubjectForIssue(
Expand Down
Loading