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
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,40 @@ function getSeenIds(): Set<string> {
} catch { return new Set(); }
}

function getStoredLocationCoordinates(): { latitude?: number; longitude?: number } {
try {
const rawLocation = localStorage.getItem("user_location");
if (!rawLocation) return {};

const location = JSON.parse(rawLocation);
const latitude = Number(location?.latitude);
const longitude = Number(location?.longitude);

return {
...(Number.isFinite(latitude) ? { latitude } : {}),
...(Number.isFinite(longitude) ? { longitude } : {})
};
} catch {
return {};
}
}

function buildNegativeFeedbackMetadata(
notification: ApiNotification,
reason: NotificationFeedbackReason,
message: string
) {
return {
notification_id: notification.notification_id,
notification_description: notification.content?.body,
message_type: notification.message_type ?? notification.metadata?.message_type,
category_type: notification.category_type,
...getStoredLocationCoordinates(),
reason,
feedback: message
};
}

export function NotificationsPopover() {
const notifications = useChatStore((s) => s.notifications);
const markNotificationRead = useChatStore((s) => s.markNotificationRead);
Expand Down Expand Up @@ -445,11 +479,7 @@ export function NotificationsPopover() {
apiService.trackUiTelemetryEvent({
event_name: "notification_feedback_dislike_submitted",
category: "notification_feedback",
metadata: {
notification_id: feedbackTarget.notification_id,
reason,
feedback: message
}
metadata: buildNegativeFeedbackMetadata(feedbackTarget, reason, message)
});
setFeedbackMap((previous) => ({ ...previous, [feedbackTarget.notification_id]: "disliked" }));
setFeedbackModalOpen(false);
Expand Down
11 changes: 7 additions & 4 deletions src/hooks/store/chat/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import { environment } from "@/lib/config/environment";
export type ApiNotification = {
notification_id: string;
type: string;
message_type?: string;
category_type?: string;
priority: "HIGH" | "MEDIUM" | "LOW";
valid_from: string;
valid_to: string;
Expand All @@ -31,10 +33,11 @@ export type ApiNotification = {
distance_km?: number;
} | null;
metadata: {
source: string;
template: string;
unique_id_iitm: string;
unique_id_pm_kisan: number;
source?: string;
template?: string;
unique_id_iitm?: string;
unique_id_pm_kisan?: number;
message_type?: string;
};
};

Expand Down
Loading