Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 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 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 | 89x 89x 88x 88x 88x 88x 88x 88x 88x 88x | import { Dayjs } from "dayjs";
import { HostRequestStatus } from "proto/conversations_pb";
import {
CreateHostRequestReq,
GetHostRequestMessagesReq,
GetHostRequestReq,
GetResponseRateReq,
ListHostRequestsReq,
MarkLastSeenHostRequestReq,
RespondHostRequestReq,
SendHostRequestMessageReq,
} from "proto/requests_pb";
import client from "./client";
export async function listHostRequests({
lastRequestId = 0,
count = 10,
type = "all",
onlyActive = false,
}: {
lastRequestId?: number;
count?: number;
type?: "all" | "hosting" | "surfing";
onlyActive?: boolean;
}) {
const req = new ListHostRequestsReq();
req.setOnlyActive(onlyActive);
req.setOnlyReceived(type === "hosting");
req.setOnlySent(type === "surfing");
req.setLastRequestId(lastRequestId);
req.setNumber(count);
const response = await client.requests.listHostRequests(req);
return response.toObject();
}
export async function getHostRequest(id: number) {
const req = new GetHostRequestReq();
req.setHostRequestId(id);
const response = await client.requests.getHostRequest(req);
return response.toObject();
}
export async function sendHostRequestMessage(id: number, text: string) {
const req = new SendHostRequestMessageReq();
req.setHostRequestId(id);
req.setText(text);
const response = await client.requests.sendHostRequestMessage(req);
const messageId = response.getJsPbMessageId();
return messageId;
}
export async function respondHostRequest(
id: number,
status: HostRequestStatus,
text: string,
) {
const req = new RespondHostRequestReq();
req.setHostRequestId(id);
req.setStatus(status);
req.setText(text);
await client.requests.respondHostRequest(req);
}
export async function getHostRequestMessages(
id: number,
lastMessageId = 0,
count = 20,
) {
const req = new GetHostRequestMessagesReq();
req.setHostRequestId(id);
req.setLastMessageId(lastMessageId);
req.setNumber(count);
const response = await client.requests.getHostRequestMessages(req);
return response.toObject();
}
export type CreateHostRequestWrapper = Omit<
Required<CreateHostRequestReq.AsObject>,
"toDate" | "fromDate"
> & { toDate: Dayjs; fromDate: Dayjs; stayType: number };
export async function createHostRequest(data: CreateHostRequestWrapper) {
const req = new CreateHostRequestReq();
req.setHostUserId(data.hostUserId);
req.setFromDate(data.fromDate.format().split("T")[0]);
req.setToDate(data.toDate.format().split("T")[0]);
req.setText(data.text);
const response = await client.requests.createHostRequest(req);
return response.getHostRequestId();
}
export function markLastRequestSeen(hostRequestId: number, messageId: number) {
const req = new MarkLastSeenHostRequestReq();
req.setHostRequestId(hostRequestId);
req.setLastSeenMessageId(messageId);
return client.requests.markLastSeenHostRequest(req);
}
export async function getResponseRate(userId: number) {
const req = new GetResponseRateReq();
req.setUserId(userId);
return (await client.requests.getResponseRate(req)).toObject();
}
|