Skip to content

Commit

Permalink
Update MTKruto
Browse files Browse the repository at this point in the history
  • Loading branch information
rojvv committed Apr 7, 2024
1 parent 12287ba commit 421a39d
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 28 deletions.
2 changes: 1 addition & 1 deletion deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"@twind/preset-tailwind": "https://esm.sh/@twind/[email protected]/",
"@twind/preset-autoprefix": "https://esm.sh/@twind/[email protected]/",
"$std/": "https://deno.land/[email protected]/",
"mtkruto/": "https://deno.land/x/[email protected].183/",
"mtkruto/": "https://deno.land/x/[email protected].301/",
"grammy/": "https://deno.land/x/[email protected]/",
"dexie": "https://esm.sh/[email protected]",
"dexie-react-hooks": "https://esm.sh/[email protected]?alias=react:preact/compat",
Expand Down
2 changes: 1 addition & 1 deletion islands/InlineMessageIdUnpacker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ComponentChildren } from "preact";
import { signal, useSignalEffect } from "@preact/signals";

import { base64DecodeUrlSafe } from "mtkruto/utilities/1_base64.ts";
import { TLReader } from "mtkruto/tl/3_tl_reader.ts";
import { TLReader } from "mtkruto/tl/4_tl_reader.ts";
import { id, types } from "mtkruto/2_tl.ts";

import { getHashSignal } from "../lib/hash.ts";
Expand Down
5 changes: 3 additions & 2 deletions islands/SessionStringGenerator.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { unreachable } from "$std/assert/unreachable.ts";

import { IS_BROWSER } from "$fresh/runtime.ts";
import { computed, Signal, signal } from "@preact/signals";

import { Client, StorageMemory, types } from "mtkruto/mod.ts";
import { UNREACHABLE } from "mtkruto/1_utilities.ts";
import { getDcIps } from "mtkruto/transport/2_transport_provider.ts";

import { isValidLibrary, ValidLibrary } from "../lib/misc.ts";
Expand Down Expand Up @@ -416,7 +417,7 @@ async function generateSessionString(library: ValidLibrary) { // TODO: report er
const dc = await client.storage.getDc();
const authKey = await client.storage.getAuthKey();
if (!dc || !authKey) {
UNREACHABLE();
unreachable();
}

const ip = getDcIps(dc, "ipv4")[0]; // TODO
Expand Down
16 changes: 8 additions & 8 deletions lib/file_id.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { UNREACHABLE } from "mtkruto/utilities/0_control.ts";
import { unreachable } from "$std/assert/unreachable.ts";
import { rleDecode, rleEncode } from "mtkruto/utilities/0_rle.ts";
import {
base64DecodeUrlSafe,
Expand Down Expand Up @@ -217,7 +217,7 @@ function serializePhotoSource(photoSource: PhotoSource, writer: TLWriter) {
writer.writeInt32(photoSource.version);
break;
default:
UNREACHABLE();
unreachable();
}
}
function getPhotoSourceCompareType(source: PhotoSource) {
Expand All @@ -227,7 +227,7 @@ function getPhotoSourceCompareType(source: PhotoSource) {
case PhotoSourceType.Thumbnail: {
const type = source.thumbnailType;
if (!(0 <= type && type <= 127)) {
UNREACHABLE();
unreachable();
}
if (type == "a".charCodeAt(0)) {
return 0;
Expand All @@ -253,7 +253,7 @@ function getPhotoSourceCompareType(source: PhotoSource) {
default:
break;
}
UNREACHABLE();
unreachable();
}
function writePhotoSourceUniqueId(photoSource: PhotoSource, writer: TLWriter) {
const compareType = getPhotoSourceCompareType(photoSource);
Expand All @@ -270,14 +270,14 @@ function writePhotoSourceUniqueId(photoSource: PhotoSource, writer: TLWriter) {
? photoSource.volumeId
: "stickerSetId" in photoSource
? photoSource.stickerSetId
: UNREACHABLE(),
: unreachable(),
);
writer.writeInt32(
"localId" in photoSource
? photoSource.localId
: "version" in photoSource
? photoSource.version
: UNREACHABLE(),
: unreachable(),
);
}

Expand Down Expand Up @@ -325,7 +325,7 @@ function getFileTypeClass(fileType: FileType) {
case FileType.None:
case FileType.Size:
default:
UNREACHABLE();
unreachable();
}
}

Expand Down Expand Up @@ -423,7 +423,7 @@ export function toUniqueFileId(fileId: FileId): string {
switch (fileId.location.source.type) {
case PhotoSourceType.Legacy:
case PhotoSourceType.StickerSetThumbnail:
UNREACHABLE();
unreachable();
/* falls through */
case PhotoSourceType.FullLegacy:
case PhotoSourceType.ChatPhotoSmallLegacy:
Expand Down
33 changes: 18 additions & 15 deletions static/connectivity-test/worker.js

Large diffs are not rendered by default.

10 changes: 9 additions & 1 deletion workers/connectivity_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,16 @@ async function handleMessage(
const writer = new TLWriter();
writer.writeString(initialDc);
writer.writeBytes(authKey);
writer.writeInt32(0);
writer.write(new Uint8Array([0]));
writer.writeInt64(0n);
authString = base64EncodeUrlSafe(rleEncode(writer.buffer));
}
postMessage(authKey);
client = new Client(new StorageMemory(authString));
await client.connect();
} catch (_err) {
} catch (err) {
console.error(err);
postMessage("failed");
postMessage("done");
return;
Expand All @@ -56,6 +60,10 @@ async function handleMessage(
) {
await handleMessage(data, true);
break;
} else {
console.error(err);
postMessage("failed");
break;
}
}
postMessage(Math.ceil(now() - then));
Expand Down

0 comments on commit 421a39d

Please sign in to comment.