Skip to content

Commit

Permalink
refactor(client/getMe) return type based on args (#661)
Browse files Browse the repository at this point in the history
  • Loading branch information
SunsetTechuila committed Apr 12, 2024
1 parent f8710df commit 4690d50
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
2 changes: 2 additions & 0 deletions gramjs/client/TelegramClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1226,6 +1226,8 @@ export class TelegramClient extends TelegramBaseClient {
* console.log("My username is",me.username);
* ```
*/
getMe(inputPeer: true): Promise<Api.InputPeerUser>;
getMe(inputPeer?: false): Promise<Api.User>;
getMe(inputPeer = false) {
return userMethods.getMe(this, inputPeer);
}
Expand Down
12 changes: 6 additions & 6 deletions gramjs/client/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,12 @@ export async function invoke<R extends Api.AnyRequest>(
}

/** @hidden */
export async function getMe(
client: TelegramClient,
inputPeer = false
): Promise<Api.InputPeerUser | Api.User> {
export async function getMe<
T extends boolean,
R = T extends true ? Api.InputPeerUser : Api.User
>(client: TelegramClient, inputPeer: T): Promise<R> {
if (inputPeer && client._selfInputPeer) {
return client._selfInputPeer;
return client._selfInputPeer as R;
}
const me = (
await client.invoke(
Expand All @@ -142,7 +142,7 @@ export async function getMe(
false
) as Api.InputPeerUser;
}
return inputPeer ? client._selfInputPeer : me;
return inputPeer ? (client._selfInputPeer as R) : (me as R);
}

/** @hidden */
Expand Down
2 changes: 1 addition & 1 deletion gramjs/tl/custom/messageButton.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ export class MessageButton {
);
}
if (sharePhone == true || typeof sharePhone == "string") {
const me = (await this._client.getMe()) as Api.User;
const me = await this._client.getMe();
sharePhone = new Api.InputMediaContact({
phoneNumber:
(sharePhone == true ? me.phone : sharePhone) || "",
Expand Down

0 comments on commit 4690d50

Please sign in to comment.