feat!: updated to layer 167

breaking:
 - `User#color`: type changed `number -> ChatColors`
 - `User#replyBackgroundEmojiId` removed (moved to `color.backgroundEmojiId`)
 - same for `Chat`
This commit is contained in:
alina 🌸 2023-12-01 17:29:36 +03:00
parent e22aed56af
commit 4d27ca56d1
Signed by: teidesu
SSH key fingerprint: SHA256:uNeCpw6aTSU4aIObXLvHfLkDa82HWH9EiOj9AXOIRpI
8 changed files with 72 additions and 43 deletions

View file

@ -17,7 +17,7 @@
"test:browser:dev": "vitest --config .config/vite.browser.mts watch", "test:browser:dev": "vitest --config .config/vite.browser.mts watch",
"lint": "eslint .", "lint": "eslint .",
"lint:ci": "NODE_OPTIONS=\\\"--max_old_space_size=8192\\\" eslint --config .config/eslint.ci.js .", "lint:ci": "NODE_OPTIONS=\\\"--max_old_space_size=8192\\\" eslint --config .config/eslint.ci.js .",
"lint:tsc": "pnpm -r --workspace-concurrency=4 exec tsc --build", "lint:tsc": "rimraf packages/**/dist && pnpm -r --workspace-concurrency=4 exec tsc --build",
"lint:tsc:ci": "pnpm -r exec tsc --build", "lint:tsc:ci": "pnpm -r exec tsc --build",
"lint:dpdm": "dpdm -T --no-warning --no-tree --exit-code circular:1 packages/*", "lint:dpdm": "dpdm -T --no-warning --no-tree --exit-code circular:1 packages/*",
"lint:fix": "eslint --fix .", "lint:fix": "eslint --fix .",

View file

@ -0,0 +1,37 @@
import { tl } from '@mtcute/core'
import { makeInspectable } from '../../utils/inspectable.js'
/**
* Information about colors of a chat
*/
export class ChatColors {
constructor(
private readonly _peerId: number,
readonly raw?: tl.RawPeerColor,
) {}
/**
* Color ID
*
* Note that this value is **not** an RGB color representation. Instead, it is
* a number which should be used to pick a color from a predefined
* list of colors:
* - `0-6` are the default colors used by Telegram clients:
* `red, orange, purple, green, sea, blue, pink`
* - `>= 7` are returned by `help.getAppConfig`.
*/
get color(): number {
return this.raw?.color ?? this._peerId % 7
}
/**
* ID of the emoji that should be used as a background pattern
* when rendering the color
*/
get backgroundEmojiId(): tl.Long | null {
return this.raw?.backgroundEmojiId ?? null
}
}
makeInspectable(ChatColors)

View file

@ -3,6 +3,7 @@ import { getMarkedPeerId, MtArgumentError, MtTypeAssertionError, tl } from '@mtc
import { makeInspectable } from '../../utils/index.js' import { makeInspectable } from '../../utils/index.js'
import { memoizeGetters } from '../../utils/memoize.js' import { memoizeGetters } from '../../utils/memoize.js'
import { MessageEntity } from '../messages/message-entity.js' import { MessageEntity } from '../messages/message-entity.js'
import { ChatColors } from './chat-colors.js'
import { ChatLocation } from './chat-location.js' import { ChatLocation } from './chat-location.js'
import { ChatPermissions } from './chat-permissions.js' import { ChatPermissions } from './chat-permissions.js'
import { ChatPhoto } from './chat-photo.js' import { ChatPhoto } from './chat-photo.js'
@ -531,30 +532,14 @@ export class Chat {
} }
/** /**
* Name color of this chat, which should also be used when * Color that should be used when rendering replies to
* rendering replies to their messages and web previews sent by them. * the messages and web previews sent by this chat,
* * as well as to render the chat title
* Note that this value is **not** an RGB color representation. Instead, it is
* a number which should be used to pick a color from a predefined
* list of colors:
* - `0-6` are the default colors used by Telegram clients:
* `red, orange, purple, green, sea, blue, pink`
* - `>= 7` are returned by `help.getAppConfig`.
*/ */
get color(): number { get color(): ChatColors {
if (this.peer._ !== 'channel' && this.peer._ !== 'user') return this.peer.id % 7 const color = this.peer._ === 'user' || this.peer._ === 'channel' ? this.peer.color : undefined
return this.peer.color ?? this.peer.id % 7 return new ChatColors(this.peer.id, color)
}
/**
* ID of the emoji that should be used as a background pattern
* when rendering replies to this user's messages.
*/
get replyBackgroundEmojiId(): tl.Long | null {
if (this.peer._ !== 'channel' && this.peer._ !== 'user') return null
return this.peer.backgroundEmojiId ?? null
} }
/** /**
@ -671,5 +656,6 @@ memoizeGetters(Chat, [
'defaultPermissions', 'defaultPermissions',
'location', 'location',
'user', 'user',
'color',
]) ])
makeInspectable(Chat, [], ['user']) makeInspectable(Chat, [], ['user'])

View file

@ -5,6 +5,7 @@ import { makeInspectable } from '../../utils/index.js'
import { memoizeGetters } from '../../utils/memoize.js' import { memoizeGetters } from '../../utils/memoize.js'
import { MessageEntity } from '../messages/message-entity.js' import { MessageEntity } from '../messages/message-entity.js'
import { EmojiStatus } from '../reactions/emoji-status.js' import { EmojiStatus } from '../reactions/emoji-status.js'
import { ChatColors } from './chat-colors.js'
import { ChatPhoto } from './chat-photo.js' import { ChatPhoto } from './chat-photo.js'
/** /**
@ -375,26 +376,22 @@ export class User {
} }
/** /**
* Name color of this user, which should also be used when * Color that should be used when rendering replies to
* rendering replies to their messages and web previews sent by them. * their messages and web previews sent by them,
* * as well as to render the chat title
* Note that this value is **not** an RGB color representation. Instead, it is
* a number which should be used to pick a color from a predefined
* list of colors:
* - `0-6` are the default colors used by Telegram clients:
* `red, orange, purple, green, sea, blue, pink`
* - `>= 7` are returned by `help.getAppConfig`.
*/ */
get color(): number { get color(): ChatColors {
return this.raw.color ?? this.raw.id % 7 return new ChatColors(this.raw.id, this.raw.color)
} }
/** /**
* ID of the emoji that should be used as a background pattern * Color that should be used when rendering the header of
* when rendering replies to this user's messages. * the user's profile
*
* If `null`, a generic header should be used instead
*/ */
get replyBackgroundEmojiId(): tl.Long | null { get profileColors(): ChatColors | null {
return this.raw.backgroundEmojiId ?? null return this.raw.profileColor ? new ChatColors(this.raw.id, this.raw.profileColor) : null
} }
/** /**
@ -490,5 +487,13 @@ export class User {
} }
} }
memoizeGetters(User, ['_parsedStatus' as keyof User, 'usernames', 'inputPeer', 'photo', 'emojiStatus']) memoizeGetters(User, [
'_parsedStatus' as keyof User,
'usernames',
'inputPeer',
'photo',
'emojiStatus',
'color',
'profileColors',
])
makeInspectable(User, undefined, ['_parsedStatus' as keyof User]) makeInspectable(User, undefined, ['_parsedStatus' as keyof User])

View file

@ -2,7 +2,7 @@
TL schema and related utils used for mtcute. TL schema and related utils used for mtcute.
Generated from TL layer **166** (last updated on 25.11.2023). Generated from TL layer **167** (last updated on 01.12.2023).
## About ## About

File diff suppressed because one or more lines are too long

View file

@ -114,6 +114,7 @@
"updateChannelReadMessagesContents": ["channel_id"], "updateChannelReadMessagesContents": ["channel_id"],
"updateChannelTooLong": ["channel_id"], "updateChannelTooLong": ["channel_id"],
"updateChannelUserTyping": ["channel_id"], "updateChannelUserTyping": ["channel_id"],
"updateChannelViewForumAsMessages": ["channel_id"],
"updateChannelWebPage": ["channel_id"], "updateChannelWebPage": ["channel_id"],
"updateChat": ["chat_id"], "updateChat": ["chat_id"],
"updateChatParticipant": ["chat_id", "actor_id", "user_id"], "updateChatParticipant": ["chat_id", "actor_id", "user_id"],
@ -123,7 +124,7 @@
"updateChatUserTyping": ["chat_id"], "updateChatUserTyping": ["chat_id"],
"updateDeleteChannelMessages": ["channel_id"], "updateDeleteChannelMessages": ["channel_id"],
"updateGroupCall": ["chat_id"], "updateGroupCall": ["chat_id"],
"updateGroupInvitePrivacyForbidden": ["chat_id"], "updateGroupInvitePrivacyForbidden": ["user_id"],
"updateInlineBotCallbackQuery": ["user_id"], "updateInlineBotCallbackQuery": ["user_id"],
"updatePinnedChannelMessages": ["channel_id"], "updatePinnedChannelMessages": ["channel_id"],
"updateReadChannelDiscussionInbox": ["channel_id", "broadcast_id"], "updateReadChannelDiscussionInbox": ["channel_id", "broadcast_id"],

View file

@ -1,6 +1,6 @@
{ {
"name": "@mtcute/tl", "name": "@mtcute/tl",
"version": "166.2.0", "version": "167.0.0",
"description": "TL schema used for mtcute", "description": "TL schema used for mtcute",
"main": "index.js", "main": "index.js",
"author": "Alina Sireneva <alina@tei.su>", "author": "Alina Sireneva <alina@tei.su>",