forked from BasedHardware/omi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgoogleMap.ts
More file actions
58 lines (52 loc) · 1.58 KB
/
Copy pathgoogleMap.ts
File metadata and controls
58 lines (52 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// Pure mappers: Google REST JSON → app item shapes. No IO; unit-testable.
import type { GmailItem, CalendarItem } from '../../shared/types'
type GmailHeader = { name: string; value: string }
export type GmailMessageJson = {
id?: string
snippet?: string
internalDate?: string
payload?: { headers?: GmailHeader[] }
}
function header(headers: GmailHeader[] | undefined, name: string): string {
const h = headers?.find((x) => x.name.toLowerCase() === name.toLowerCase())
return h?.value ?? ''
}
export function mapGmailMessage(m: GmailMessageJson): GmailItem | null {
if (!m.id) return null
const headers = m.payload?.headers
return {
id: m.id,
subject: header(headers, 'Subject'),
from: header(headers, 'From'),
snippet: m.snippet ?? '',
internalDateMs: m.internalDate ? Number(m.internalDate) || 0 : 0
}
}
type CalDateTime = { dateTime?: string; date?: string }
export type CalEventJson = {
id?: string
summary?: string
location?: string
description?: string
updated?: string
start?: CalDateTime
end?: CalDateTime
}
function eventMs(d: CalDateTime | undefined): number {
const v = d?.dateTime ?? d?.date
if (!v) return 0
const t = Date.parse(v)
return Number.isNaN(t) ? 0 : t
}
export function mapCalendarEvent(e: CalEventJson): CalendarItem | null {
if (!e.id) return null
return {
id: e.id,
title: e.summary ?? '(no title)',
startMs: eventMs(e.start),
endMs: eventMs(e.end),
location: e.location || undefined,
description: e.description || undefined,
updatedMs: e.updated ? Date.parse(e.updated) || 0 : 0
}
}