|
| 1 | +import { CallDirection, CallState } from "../models"; |
| 2 | +import moment from "moment"; |
| 3 | + |
| 4 | +export function getCommentTitle( |
| 5 | + state: CallState, |
| 6 | + direction: CallDirection, |
| 7 | + locale: string, |
| 8 | + htmlOpen = "", |
| 9 | + htmlClose = "" |
| 10 | +) { |
| 11 | + const isGerman = locale.startsWith("de"); |
| 12 | + const isIncoming = direction == CallDirection.IN; |
| 13 | + const directionString = isGerman |
| 14 | + ? isIncoming |
| 15 | + ? "eingehender" |
| 16 | + : "ausgehender" |
| 17 | + : isIncoming |
| 18 | + ? "incoming" |
| 19 | + : "outgoing"; |
| 20 | + |
| 21 | + const titleEndGerman = `${directionString} Anruf (CLINQ)`; |
| 22 | + const titleEndEnglish = `${directionString} Call (CLINQ)`; |
| 23 | + |
| 24 | + switch (state) { |
| 25 | + case CallState.CONNECTED: |
| 26 | + return isGerman |
| 27 | + ? `${htmlOpen}Getätigter ${titleEndGerman}${htmlClose}` |
| 28 | + : `${htmlOpen}Connected ${titleEndEnglish}${htmlClose}`; |
| 29 | + case CallState.BUSY: |
| 30 | + return isGerman |
| 31 | + ? `${htmlOpen}Nicht angenommener ${titleEndGerman}${htmlClose}` |
| 32 | + : `${htmlOpen}Busy ${titleEndEnglish}${htmlClose}`; |
| 33 | + case CallState.MISSED: |
| 34 | + return isGerman |
| 35 | + ? `${htmlOpen}Verpasster ${titleEndGerman}${htmlClose}` |
| 36 | + : `${htmlOpen}Missed ${titleEndEnglish}${htmlClose}`; |
| 37 | + default: |
| 38 | + return isGerman |
| 39 | + ? `${htmlOpen}Getätigter ${titleEndGerman}${htmlClose}` |
| 40 | + : `${htmlOpen}Connected ${titleEndEnglish}${htmlClose}`; |
| 41 | + } |
| 42 | +} |
| 43 | + |
| 44 | +function createCallEventCommentHeader(locale: string) { |
| 45 | + const isGerman = locale.startsWith("de"); |
| 46 | + return `<h1>${isGerman ? "Notizen" : "Note"} (CLINQ):</h1>`; |
| 47 | +} |
| 48 | + |
| 49 | +export function getCommentContent(note: string, locale: string) { |
| 50 | + return `${createCallEventCommentHeader(locale)}${note}`; |
| 51 | +} |
| 52 | + |
| 53 | +export function getCallDuration( |
| 54 | + startTime: number, |
| 55 | + endTime: number, |
| 56 | + locale: string |
| 57 | +) { |
| 58 | + const start = moment(startTime); |
| 59 | + const end = moment(endTime); |
| 60 | + |
| 61 | + const diff = end.diff(start); |
| 62 | + |
| 63 | + return `${locale.startsWith("de") ? "Dauer" : "Duration"}: ${moment |
| 64 | + .utc(diff) |
| 65 | + .format("HH:mm:ss")}`; |
| 66 | +} |
0 commit comments