mirror of
https://github.com/khoaliber/khoj.git
synced 2026-03-05 21:29:11 +00:00
Default to using system clock to infer user timezone on js clients
Using system clock to infer user timezone on clients makes Khoj more robust to provide location aware responses. Previously only ip based location was used to infer timezone via API. This didn't provide any decent fallback when calls to ipapi failed or Khoj was being run in offline mode
This commit is contained in:
@@ -33,10 +33,10 @@ interface ChatMessageState {
|
||||
}
|
||||
|
||||
interface Location {
|
||||
region: string;
|
||||
city: string;
|
||||
countryName: string;
|
||||
countryCode: string;
|
||||
region?: string;
|
||||
city?: string;
|
||||
countryName?: string;
|
||||
countryCode?: string;
|
||||
timezone: string;
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ export class KhojChatView extends KhojPaneView {
|
||||
result: string;
|
||||
setting: KhojSetting;
|
||||
waitingForLocation: boolean;
|
||||
location: Location;
|
||||
location: Location = { timezone: Intl.DateTimeFormat().resolvedOptions().timeZone };
|
||||
keyPressTimeout: NodeJS.Timeout | null = null;
|
||||
userMessages: string[] = []; // Store user sent messages for input history cycling
|
||||
currentMessageIndex: number = -1; // Track current message index in userMessages array
|
||||
@@ -1058,13 +1058,11 @@ export class KhojChatView extends KhojPaneView {
|
||||
n: this.setting.resultsCount,
|
||||
stream: true,
|
||||
...(!!conversationId && { conversation_id: conversationId }),
|
||||
...(!!this.location && {
|
||||
city: this.location.city,
|
||||
region: this.location.region,
|
||||
country: this.location.countryName,
|
||||
country_code: this.location.countryCode,
|
||||
timezone: this.location.timezone,
|
||||
}),
|
||||
...(!!this.location && this.location.city && { city: this.location.city }),
|
||||
...(!!this.location && this.location.region && { region: this.location.region }),
|
||||
...(!!this.location && this.location.countryName && { country: this.location.countryName }),
|
||||
...(!!this.location && this.location.countryCode && { country_code: this.location.countryCode }),
|
||||
...(!!this.location && this.location.timezone && { timezone: this.location.timezone }),
|
||||
};
|
||||
|
||||
let newResponseEl = this.createKhojResponseDiv();
|
||||
|
||||
Reference in New Issue
Block a user