电报壁纸
Telegram 应用支持生成、分享和同步聊天背景。壁纸必须按照壁纸构造器中包含的说明进行渲染。
壁纸类型
壁纸主要分为四种类型:
- 图片壁纸
- 图案壁纸
- 填充壁纸
- 频道和超级乐队壁纸
填充和图案壁纸是使用三种填充类型之一生成的。
图片壁纸
wallPaper#a437c3ed id:long flags:# creator:flags.0?true default:flags.1?true pattern:flags.3?true dark:flags.4?true access_hash:long slug:string document:Document settings:flags.2?WallPaperSettings = WallPaper;wallPaperSettings#372efcd0 flags:# blur:flags.1?true motion:flags.2?true background_color:flags.0?int second_background_color:flags.4?int third_background_color:flags.5?int fourth_background_color:flags.6?int intensity:flags.3?int rotation:flags.4?int emoticon:flags.7?string = WallPaperSettings;
图片壁纸是由wallPaper构造函数描述的壁纸,该构造函数包含一个 JPEG 图像document字段。
该settings字段描述了如果设置了相应的标志,则应应用于图像的变换:
- settings.blur:图像应缩小到适合 450x450 正方形,然后进行半径为 12 的盒状模糊处理。
- settings.motion当设备倾斜时,图像需要稍微移动,以实现视差效果。
其他所有settings标志都应忽略。
图案壁纸
wallPaper#a437c3ed id:long flags:# creator:flags.0?true default:flags.1?true pattern:flags.3?true dark:flags.4?true access_hash:long slug:string document:Document settings:flags.2?WallPaperSettings = WallPaper;wallPaperSettings#372efcd0 flags:# blur:flags.1?true motion:flags.2?true background_color:flags.0?int second_background_color:flags.4?int third_background_color:flags.5?int fourth_background_color:flags.6?int intensity:flags.3?int rotation:flags.4?int emoticon:flags.7?string = WallPaperSettings;
图案壁纸是由设置了标志的wallPaper构造函数描述的壁纸pattern,它将字段中指定的颜色填充settings与字段中包含的 PNG 或 TGV(MIME 类型为“application/x-tgwallpattern”的 SVG 的 gzipped 子集)图案图像结合起来document。
图案图像应完全透明,只有图案本身应为黑色。
字段中的以下标志settings描述了图案应如何与颜色填充结合:
-
settings.intensity:一个介于 -100 到 100 之间的值。
- 0 到 100 之间的值表示图案应以指定的强度叠加在颜色填充之上(@ 100 时,黑色图案在背景填充上完全可见;@ 0 时,仅背景填充可见)。
- -1 到 -100 的值表示在以指定强度叠加到颜色填充上之前,应该反转图案(黑色背景,透明图案)(@ -100 时,填充图案在黑色背景上完全可见;@ -1 时,仅黑色可见)。
- settings.motion当设备倾斜时,图案需要在背景上稍微移动,以实现视差效果。
填充壁纸
wallPaperNoFile#e0804116 id:long flags:# default:flags.1?true dark:flags.4?true settings:flags.2?WallPaperSettings = WallPaper;
填充壁纸是由wallPaperNoFile构造函数描述的简单壁纸,仅包含字段指定的填充settings内容。
频道和超级乐队壁纸
wallPaperSettings#372efcd0 flags:# blur:flags.1?true motion:flags.2?true background_color:flags.0?int second_background_color:flags.4?int third_background_color:flags.5?int fourth_background_color:flags.6?int intensity:flags.3?int rotation:flags.4?int emoticon:flags.7?string = WallPaperSettings;
包含emoticon相关壁纸的填充壁纸settings表示频道/超级群组壁纸,可以安装在 »拥有足够提升的频道和超级群组中,请参阅此处 »了解更多信息。
可以使用account.getChatThemes获取频道/超级群组壁纸的完整列表。
频道/超级群组在达到更高的提升等级后,还可以设置任何自定义壁纸(不仅仅是account.getChatThemes返回的壁纸),详情请参见此处 » 。
填充类型
填充和图案壁纸是使用以下三种填充类型之一生成的:
- 固体填充
- 渐变填充
- 自由渐变填充
固体填充
wallPaperSettings#372efcd0 flags:# blur:flags.1?true motion:flags.2?true background_color:flags.0?int second_background_color:flags.4?int third_background_color:flags.5?int fourth_background_color:flags.6?int intensity:flags.3?int rotation:flags.4?int emoticon:flags.7?string = WallPaperSettings;
如果*_background_color只background_color设置了标志位,则填充仅由指定的 RGB-24 颜色构成。
渐变填充
wallPaperSettings#372efcd0 flags:# blur:flags.1?true motion:flags.2?true background_color:flags.0?int second_background_color:flags.4?int third_background_color:flags.5?int fourth_background_color:flags.6?int intensity:flags.3?int rotation:flags.4?int emoticon:flags.7?string = WallPaperSettings;
如果*_background_color仅设置了标志位background_color,second_background_color则填充将由指定的 RGB-24 颜色组成的自上而下(背景色-第二背景色)渐变构成。
如果设置了该标志位,rotation则表示渐变的顺时针旋转角度,单位为度;取值范围为 0-359。该值必须始终能被 45 整除,如果未设置,则默认为 0。
自由渐变填充
wallPaperSettings#372efcd0 flags:# blur:flags.1?true motion:flags.2?true background_color:flags.0?int second_background_color:flags.4?int third_background_color:flags.5?int fourth_background_color:flags.6?int intensity:flags.3?int rotation:flags.4?int emoticon:flags.7?string = WallPaperSettings;
如果设置了background_color、second_background_color和third_background_color可选的fourth_background_color标志,则填充将由指定的 3 或 4 种 RGB-24 颜色的自由渐变组成。
API 壁纸
上传壁纸
wallPaperSettings#372efcd0 flags:# blur:flags.1?true motion:flags.2?true background_color:flags.0?int second_background_color:flags.4?int third_background_color:flags.5?int fourth_background_color:flags.6?int intensity:flags.3?int rotation:flags.4?int emoticon:flags.7?string = WallPaperSettings;wallPaper#a437c3ed id:long flags:# creator:flags.0?true default:flags.1?true pattern:flags.3?true dark:flags.4?true access_hash:long slug:string document:Document settings:flags.2?WallPaperSettings = WallPaper;---functions---account.uploadWallPaper#e39a8f03 flags:# for_chat:flags.0?true file:InputFile mime_type:string settings:WallPaperSettings = WallPaper;
account.uploadWallPaper用于上传图片和图案壁纸。for_chat上传壁纸时必须设置标志,以便与messages.setChatWallPaper配合使用。
填充壁纸无需上传,因为它们没有关联的文件,可以直接在客户端生成wallPaperid=0构造函数并指定。
然后可以使用壁纸深度链接分享壁纸»,和/或按照此处指定的方式安装(仅限图像和图案壁纸)»。
安装壁纸
inputWallPaper#e630b979 id:long access_hash:long = InputWallPaper; inputWallPaperSlug#72091c80 slug:string = InputWallPaper;wallPaper#a437c3ed id:long flags:# creator:flags.0?true default:flags.1?true pattern:flags.3?true dark:flags.4?true access_hash:long slug:string document:Document settings:flags.2?WallPaperSettings = WallPaper;wallPaperSettings#372efcd0 flags:# blur:flags.1?true motion:flags.2?true background_color:flags.0?int second_background_color:flags.4?int third_background_color:flags.5?int fourth_background_color:flags.6?int intensity:flags.3?int rotation:flags.4?int emoticon:flags.7?string = WallPaperSettings;account.wallPapersNotModified#1c199183 = account.WallPapers; account.wallPapers#cdc3858c hash:long wallpapers:Vector<WallPaper> = account.WallPapers;---functions---account.getWallPaper#fc8ddbea wallpaper:InputWallPaper = WallPaper; account.getMultiWallPapers#65ad71dc wallpapers:Vector<InputWallPaper> = Vector<WallPaper>;account.saveWallPaper#6c5a5b37 wallpaper:InputWallPaper unsave:Bool settings:WallPaperSettings = Bool; account.installWallPaper#feed5769 wallpaper:InputWallPaper settings:WallPaperSettings = Bool; account.getWallPapers#7967d36 hash:long = account.WallPapers; account.resetWallPapers#bb3b9804 = Bool;
上传壁纸或收到壁纸深度链接后,即可按如下方式安装。
请注意,填充壁纸不能使用account.installWallPaper或account.saveWallPaper进行全局安装,客户端应该只在本地安装和跟踪它们,而不需要同步壁纸列表或发出安装信号。
API 会维护一个壁纸列表,用户可以将壁纸设置为聊天背景,其中包含一些预装壁纸。
要获取此列表,请使用`account.getWallPapers`。
要将壁纸保存到列表中,请使用`account.saveWallPaper`unsave=false。
要从列表中移除壁纸(包括预装壁纸),请使用`account.saveWallPaper`。要恢复默认列表,移除所有已安装的壁纸并重新安装之前移除的预装壁纸,请使用`account.resetWallPapers`。unsave=true
当客户端将壁纸设置为默认聊天背景时,调用account.installWallPaper 方法会将此安装通知服务器。
请注意,如果壁纸不在已保存的壁纸列表中,调用此方法还会自动保存该壁纸。
在所有需要InputWallPaper构造函数的情况下,传递:
- 使用壁纸深度链接时输入壁纸别名。
-
否则,使用完整壁纸的 ID 和访问哈希字段作为inputWallPaper。
如前所述,填充壁纸无法使用account.installWallPaper或account.saveWallPaper保存到服务器:填充壁纸可以使用inputWallPaperNoFile ,但只能在处理主题或使用messages.setChatWallPaper时使用,如下所示。
在特定聊天室或频道中安装壁纸
messageActionSetChatWallPaper#5060a3f4 flags:# same:flags.0?true for_both:flags.1?true wallpaper:WallPaper = MessageAction;updatePeerWallpaper#ae3f101d flags:# wallpaper_overridden:flags.1?true peer:Peer wallpaper:flags.0?WallPaper = Update;---functions---messages.setChatWallPaper#8ffacae1 flags:# for_both:flags.3?true revert:flags.4?true peer:InputPeer wallpaper:flags.0?InputWallPaper settings:flags.2?WallPaperSettings id:flags.1?int = Updates;
也可以在特定的私聊中安装壁纸,方法是使用messages.setChatWallPaper:这将发出messageActionSetChatWallPaper服务消息,在用户界面中显示壁纸,并邀请其他用户应用相同的壁纸。
要wallpaper,请传递:
- 使用壁纸深度链接时输入壁纸别名。
- inputWallPaperNoFile用于填充壁纸。
- 否则,使用完整壁纸的 ID 和访问哈希字段输入壁纸。
如果另一用户决定将相同的壁纸应用于聊天,则应调用messages.setChatWallPaper ,并将messageActionSetChatWallPapersettings服务消息中收到的壁纸(或者如果用户在应用壁纸之前自定义了某些设置,则传递一些不同的设置)以及messageActionSetChatWallPaper服务消息的,但不带: 这样,该操作将发出一个设置了标志的messageActionSetChatWallPaper,该消息应在 UI 中显示为简单的确认服务消息,不包含完整的壁纸,也不邀请另一用户应用壁纸(因为双方参与者刚刚都已经应用了壁纸)。idwallpaper same
但是,如果我们拥有高级订阅,就可以在未经对方明确确认的情况下更改对方的壁纸:为此,只需for_both在调用`messages.setChatWallPaper`时设置相应的标志即可。
这将更改聊天双方的壁纸,无需确认;同时,对方的 `userFull` 标志也会被设置;此外,该操作还会发出一个带有已设置标志的`messageActionSetChatWallPaper`消息。如果对方不喜欢我们为其选择的新壁纸,他们可以在自己的电脑上通过调用`messages.setChatWallPaper`并仅提供标志(以及相应的参数)来恢复之前的壁纸。wallpaper_overridden for_both
revertpeer
请注意,要将图像或图案壁纸传递给messages.setChatWallPaper,必须在使用 account.uploadWallPaper 上传它们for_chat时设置标志。
另请注意,与account.installWallPaper或account.saveWallPaper不同,messages.setChatWallPaper也接受填充壁纸。
壁纸更改也会发出updatePeerWallpaper更新。
当频道/群组达到配置参数/配置参数中指定的提升级别后,它们就可以设置account.getChatThemes 返回的频道壁纸之一(更多信息请参见 »)。channel_wallpaper_level_mingroup_wallpaper_level_min
当频道/超级组达到channel_custom_wallpaper_level_min配置group_custom_wallpaper_level_min参数中指定的至少提升级别后,它们将能够设置任何自定义壁纸,而不仅仅是填充频道壁纸。
设置频道壁纸时,不要设置for_both标志。