From 34e371ce6478dc64414e9498201bab1237cebeca Mon Sep 17 00:00:00 2001 From: WolverinDEV Date: Sat, 20 Feb 2021 17:46:16 +0100 Subject: [PATCH] Reworked the BrowserIPC module --- src/Action.ts | 7 +++++-- src/ClientServiceInvite.ts | 24 +++++++++++++++++++++++- src/Messages.ts | 11 +++++++++-- 3 files changed, 37 insertions(+), 5 deletions(-) diff --git a/src/Action.ts b/src/Action.ts index 6374a90..9c2b0b2 100644 --- a/src/Action.ts +++ b/src/Action.ts @@ -23,11 +23,14 @@ export function createErrorResult(result: MessageCommandErrorResult) : Action } } -export function createResult(result: T) : ActionResult { +export function createResult() : ActionResult; +export function createResult(result: T) : ActionResult; + +export function createResult(result?) : ActionResult { return { status: "success", result: result, - unwrap(): T { + unwrap() { return result; } } diff --git a/src/ClientServiceInvite.ts b/src/ClientServiceInvite.ts index 7557a1c..9d8cd21 100644 --- a/src/ClientServiceInvite.ts +++ b/src/ClientServiceInvite.ts @@ -1,12 +1,13 @@ import {ClientServices} from "./ClientService"; import {ActionResult, createErrorResult, createResult} from "./Action"; +import {InviteAction} from "./Messages"; export type InviteLinkInfo = { linkId: string, timestampCreated: number, timestampDeleted: number, - + timestampExpired: number, amountViewed: number, amountClicked: number, @@ -14,6 +15,7 @@ export type InviteLinkInfo = { propertiesConnect: {[key: string]: string}, propertiesInfo: {[key: string]: string}, }; + export class ClientServiceInvite { private readonly handle: ClientServices; @@ -73,9 +75,29 @@ export class ClientServiceInvite { timestampCreated: notifyResult.value.timestamp_created, timestampDeleted: notifyResult.value.timestamp_deleted, + timestampExpired: notifyResult.value.timestamp_expired, propertiesConnect: notifyResult.value.properties_connect, propertiesInfo: notifyResult.value.properties_info, }); } + + + async logAction["type"]>(linkId: string, action: A) : Promise>; + async logAction["type"]>(linkId: string, action: A, value: Extract["payload"]) : Promise>; + + async logAction(linkId: string, action, payload?) : Promise> { + /* TODO: If the session isn't available post the updates later on */ + const connection = this.handle.getConnection(); + const result = await connection.executeCommand("InviteLogAction", { + link_id: linkId, + action: (arguments.length >= 3 ? { type: action, payload: payload } : { type: action }) as any + }); + + if(result.type !== "Success") { + return createErrorResult(result); + } + + return createResult(); + } } \ No newline at end of file diff --git a/src/Messages.ts b/src/Messages.ts index ab9579d..7360730 100644 --- a/src/Messages.ts +++ b/src/Messages.ts @@ -43,6 +43,14 @@ export type MessageNotify = | { type: "NotifyInviteInfo"; payload: NotifyInviteInfo }; /* Some command data payload */ +export type InviteAction = + | { type: "OpenTeaClientProtocol" } + | { type: "RedirectWebClient" } + | { type: "ConnectAttempt" } + | { type: "ConnectSuccess" } + | { type: "ConnectFailure"; payload: { reason: string } } + | { type: "ConnectNoAction"; payload: { reason: string } }; + export enum ClientSessionType { WebClient = 0, TeaClient = 1, @@ -58,7 +66,7 @@ export type CommandSessionUpdateLocale = { ip_country: string | null; select export type CommandInviteQueryInfo = { link_id: string; register_view: boolean }; -export type CommandInviteLogAction = { click_type: number }; +export type CommandInviteLogAction = { link_id: string; action: InviteAction }; export type CommandInviteCreate = { new_link: boolean; properties_connect: { [key: string]: string }; properties_info: { [key: string]: string }; timestamp_expired: number }; @@ -68,4 +76,3 @@ export type NotifyClientsOnline = { users_online: { [key: number]: number }; export type NotifyInviteCreated = { link_id: string; admin_token: string | null }; export type NotifyInviteInfo = { link_id: string; timestamp_created: number; timestamp_deleted: number; timestamp_expired: number; amount_viewed: number; amount_clicked: number; properties_connect: { [key: string]: string }; properties_info: { [key: string]: string } }; -