Reworked the BrowserIPC module
parent
1774b52504
commit
34e371ce64
|
@ -23,11 +23,14 @@ export function createErrorResult<T>(result: MessageCommandErrorResult) : Action
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function createResult<T>(result: T) : ActionResult<T> {
|
export function createResult() : ActionResult<void>;
|
||||||
|
export function createResult<T>(result: T) : ActionResult<T>;
|
||||||
|
|
||||||
|
export function createResult(result?) : ActionResult<any> {
|
||||||
return {
|
return {
|
||||||
status: "success",
|
status: "success",
|
||||||
result: result,
|
result: result,
|
||||||
unwrap(): T {
|
unwrap() {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +1,13 @@
|
||||||
import {ClientServices} from "./ClientService";
|
import {ClientServices} from "./ClientService";
|
||||||
import {ActionResult, createErrorResult, createResult} from "./Action";
|
import {ActionResult, createErrorResult, createResult} from "./Action";
|
||||||
|
import {InviteAction} from "./Messages";
|
||||||
|
|
||||||
export type InviteLinkInfo = {
|
export type InviteLinkInfo = {
|
||||||
linkId: string,
|
linkId: string,
|
||||||
|
|
||||||
timestampCreated: number,
|
timestampCreated: number,
|
||||||
timestampDeleted: number,
|
timestampDeleted: number,
|
||||||
|
timestampExpired: number,
|
||||||
|
|
||||||
amountViewed: number,
|
amountViewed: number,
|
||||||
amountClicked: number,
|
amountClicked: number,
|
||||||
|
@ -14,6 +15,7 @@ export type InviteLinkInfo = {
|
||||||
propertiesConnect: {[key: string]: string},
|
propertiesConnect: {[key: string]: string},
|
||||||
propertiesInfo: {[key: string]: string},
|
propertiesInfo: {[key: string]: string},
|
||||||
};
|
};
|
||||||
|
|
||||||
export class ClientServiceInvite {
|
export class ClientServiceInvite {
|
||||||
private readonly handle: ClientServices;
|
private readonly handle: ClientServices;
|
||||||
|
|
||||||
|
@ -73,9 +75,29 @@ export class ClientServiceInvite {
|
||||||
|
|
||||||
timestampCreated: notifyResult.value.timestamp_created,
|
timestampCreated: notifyResult.value.timestamp_created,
|
||||||
timestampDeleted: notifyResult.value.timestamp_deleted,
|
timestampDeleted: notifyResult.value.timestamp_deleted,
|
||||||
|
timestampExpired: notifyResult.value.timestamp_expired,
|
||||||
|
|
||||||
propertiesConnect: notifyResult.value.properties_connect,
|
propertiesConnect: notifyResult.value.properties_connect,
|
||||||
propertiesInfo: notifyResult.value.properties_info,
|
propertiesInfo: notifyResult.value.properties_info,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
async logAction<A extends Exclude<InviteAction, InviteAction & { payload }>["type"]>(linkId: string, action: A) : Promise<ActionResult<void>>;
|
||||||
|
async logAction<A extends Extract<InviteAction, InviteAction & { payload }>["type"]>(linkId: string, action: A, value: Extract<InviteAction, { payload, type: A }>["payload"]) : Promise<ActionResult<void>>;
|
||||||
|
|
||||||
|
async logAction(linkId: string, action, payload?) : Promise<ActionResult<void>> {
|
||||||
|
/* 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();
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -43,6 +43,14 @@ export type MessageNotify =
|
||||||
| { type: "NotifyInviteInfo"; payload: NotifyInviteInfo };
|
| { type: "NotifyInviteInfo"; payload: NotifyInviteInfo };
|
||||||
|
|
||||||
/* Some command data payload */
|
/* 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 {
|
export enum ClientSessionType {
|
||||||
WebClient = 0,
|
WebClient = 0,
|
||||||
TeaClient = 1,
|
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 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 };
|
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 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 } };
|
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 } };
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue