Various improvements

This commit is contained in:
Ilya Laktyushin 2024-07-22 20:43:52 +04:00
parent 4e46697a66
commit 31ba87fb0f
16 changed files with 252 additions and 139 deletions

View File

@ -12582,3 +12582,5 @@ Sorry for the inconvenience.";
"WebBrowser.Exceptions.Create.Placeholder" = "Enter URL";
"WebBrowser.Done" = "Done";
"AccessDenied.LocationWeather" = "Telegram needs access to your location so that you can add the weather widget to your stories.\n\nPlease go to Settings > Privacy > Location Services and set Telegram to ON.";

View File

@ -36,6 +36,7 @@ public enum DeviceAccessLocationSubject {
case send
case live
case tracking
case weather
}
public enum DeviceAccessSubject {
@ -474,7 +475,7 @@ public final class DeviceAccess {
}
case .authorizedWhenInUse:
switch locationSubject {
case .send, .tracking:
case .send, .tracking, .weather:
completion(true)
case .live:
completion(false)
@ -495,6 +496,8 @@ public final class DeviceAccess {
text = presentationData.strings.AccessDenied_LocationDenied
case .tracking:
text = presentationData.strings.AccessDenied_LocationTracking
case .weather:
text = presentationData.strings.AccessDenied_LocationWeather
}
} else {
text = presentationData.strings.AccessDenied_LocationDisabled
@ -505,7 +508,7 @@ public final class DeviceAccess {
}
case .notDetermined:
switch locationSubject {
case .send, .tracking:
case .send, .tracking, .weather:
locationManager?.requestWhenInUseAuthorization(completion: { status in
completion(status == .authorizedWhenInUse || status == .authorizedAlways)
})

View File

@ -159,6 +159,14 @@ public final class DrawingWeatherEntityView: DrawingEntityView, UITextViewDelega
case .white:
updatedStyle = .black
case .black:
updatedStyle = .transparent
case .transparent:
if self.weatherEntity.hasCustomColor {
updatedStyle = .custom
} else {
updatedStyle = .white
}
case .custom:
updatedStyle = .white
}
self.weatherEntity.style = updatedStyle
@ -201,8 +209,15 @@ public final class DrawingWeatherEntityView: DrawingEntityView, UITextViewDelega
switch self.weatherEntity.style {
case .white:
textColor = .black
case .black:
case .black, .transparent:
textColor = .white
case .custom:
let color = self.weatherEntity.color.toUIColor()
if color.lightness > 0.705 {
textColor = .black
} else {
textColor = .white
}
}
text.addAttribute(.foregroundColor, value: textColor, range: range)
@ -226,6 +241,21 @@ public final class DrawingWeatherEntityView: DrawingEntityView, UITextViewDelega
self.textView.textColor = .white
self.backgroundView.backgroundColor = .black
self.backgroundView.isHidden = false
case .transparent:
self.textView.textColor = .white
self.backgroundView.backgroundColor = UIColor(rgb: 0x000000, alpha: 0.2)
self.backgroundView.isHidden = false
case .custom:
let color = self.weatherEntity.color.toUIColor()
let textColor: UIColor
if color.lightness > 0.705 {
textColor = .black
} else {
textColor = .white
}
self.textView.textColor = textColor
self.backgroundView.backgroundColor = color
self.backgroundView.isHidden = false
}
self.textView.textAlignment = .left

View File

@ -520,7 +520,7 @@ fileprivate let parsers: [Int32 : (BufferReader) -> Any?] = {
dict[340088945] = { return Api.MediaArea.parse_mediaAreaSuggestedReaction($0) }
dict[926421125] = { return Api.MediaArea.parse_mediaAreaUrl($0) }
dict[-1098720356] = { return Api.MediaArea.parse_mediaAreaVenue($0) }
dict[1132918857] = { return Api.MediaArea.parse_mediaAreaWeather($0) }
dict[1235637404] = { return Api.MediaArea.parse_mediaAreaWeather($0) }
dict[-808853502] = { return Api.MediaAreaCoordinates.parse_mediaAreaCoordinates($0) }
dict[-1808510398] = { return Api.Message.parse_message($0) }
dict[-1868117372] = { return Api.Message.parse_messageEmpty($0) }
@ -1170,6 +1170,7 @@ fileprivate let parsers: [Int32 : (BufferReader) -> Any?] = {
dict[-1542017919] = { return Api.auth.SentCodeType.parse_sentCodeTypeSmsWord($0) }
dict[-391678544] = { return Api.bots.BotInfo.parse_botInfo($0) }
dict[428978491] = { return Api.bots.PopularAppBots.parse_popularAppBots($0) }
dict[1357069389] = { return Api.bots.PreviewInfo.parse_previewInfo($0) }
dict[-309659827] = { return Api.channels.AdminLogResults.parse_adminLogResults($0) }
dict[-541588713] = { return Api.channels.ChannelParticipant.parse_channelParticipant($0) }
dict[-1699676497] = { return Api.channels.ChannelParticipants.parse_channelParticipants($0) }
@ -1399,7 +1400,7 @@ public extension Api {
return parser(reader)
}
else {
telegramApiLog("Type constructor \(String(UInt32(bitPattern: signature), radix: 16, uppercase: false)) not found")
telegramApiLog("Type constructor \(String(signature, radix: 16, uppercase: false)) not found")
return nil
}
}
@ -2151,6 +2152,8 @@ public extension Api {
_1.serialize(buffer, boxed)
case let _1 as Api.bots.PopularAppBots:
_1.serialize(buffer, boxed)
case let _1 as Api.bots.PreviewInfo:
_1.serialize(buffer, boxed)
case let _1 as Api.channels.AdminLogResults:
_1.serialize(buffer, boxed)
case let _1 as Api.channels.ChannelParticipant:

View File

@ -231,7 +231,7 @@ public extension Api {
case mediaAreaSuggestedReaction(flags: Int32, coordinates: Api.MediaAreaCoordinates, reaction: Api.Reaction)
case mediaAreaUrl(coordinates: Api.MediaAreaCoordinates, url: String)
case mediaAreaVenue(coordinates: Api.MediaAreaCoordinates, geo: Api.GeoPoint, title: String, address: String, provider: String, venueId: String, venueType: String)
case mediaAreaWeather(flags: Int32, coordinates: Api.MediaAreaCoordinates, emoji: String, temperatureC: Double)
case mediaAreaWeather(coordinates: Api.MediaAreaCoordinates, emoji: String, temperatureC: Double, color: Int32)
public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) {
switch self {
@ -295,14 +295,14 @@ public extension Api {
serializeString(venueId, buffer: buffer, boxed: false)
serializeString(venueType, buffer: buffer, boxed: false)
break
case .mediaAreaWeather(let flags, let coordinates, let emoji, let temperatureC):
case .mediaAreaWeather(let coordinates, let emoji, let temperatureC, let color):
if boxed {
buffer.appendInt32(1132918857)
buffer.appendInt32(1235637404)
}
serializeInt32(flags, buffer: buffer, boxed: false)
coordinates.serialize(buffer, true)
serializeString(emoji, buffer: buffer, boxed: false)
serializeDouble(temperatureC, buffer: buffer, boxed: false)
serializeInt32(color, buffer: buffer, boxed: false)
break
}
}
@ -323,8 +323,8 @@ public extension Api {
return ("mediaAreaUrl", [("coordinates", coordinates as Any), ("url", url as Any)])
case .mediaAreaVenue(let coordinates, let geo, let title, let address, let provider, let venueId, let venueType):
return ("mediaAreaVenue", [("coordinates", coordinates as Any), ("geo", geo as Any), ("title", title as Any), ("address", address as Any), ("provider", provider as Any), ("venueId", venueId as Any), ("venueType", venueType as Any)])
case .mediaAreaWeather(let flags, let coordinates, let emoji, let temperatureC):
return ("mediaAreaWeather", [("flags", flags as Any), ("coordinates", coordinates as Any), ("emoji", emoji as Any), ("temperatureC", temperatureC as Any)])
case .mediaAreaWeather(let coordinates, let emoji, let temperatureC, let color):
return ("mediaAreaWeather", [("coordinates", coordinates as Any), ("emoji", emoji as Any), ("temperatureC", temperatureC as Any), ("color", color as Any)])
}
}
@ -484,22 +484,22 @@ public extension Api {
}
}
public static func parse_mediaAreaWeather(_ reader: BufferReader) -> MediaArea? {
var _1: Int32?
_1 = reader.readInt32()
var _2: Api.MediaAreaCoordinates?
var _1: Api.MediaAreaCoordinates?
if let signature = reader.readInt32() {
_2 = Api.parse(reader, signature: signature) as? Api.MediaAreaCoordinates
_1 = Api.parse(reader, signature: signature) as? Api.MediaAreaCoordinates
}
var _3: String?
_3 = parseString(reader)
var _4: Double?
_4 = reader.readDouble()
var _2: String?
_2 = parseString(reader)
var _3: Double?
_3 = reader.readDouble()
var _4: Int32?
_4 = reader.readInt32()
let _c1 = _1 != nil
let _c2 = _2 != nil
let _c3 = _3 != nil
let _c4 = _4 != nil
if _c1 && _c2 && _c3 && _c4 {
return Api.MediaArea.mediaAreaWeather(flags: _1!, coordinates: _2!, emoji: _3!, temperatureC: _4!)
return Api.MediaArea.mediaAreaWeather(coordinates: _1!, emoji: _2!, temperatureC: _3!, color: _4!)
}
else {
return nil

View File

@ -1,3 +1,55 @@
public extension Api.bots {
enum PreviewInfo: TypeConstructorDescription {
case previewInfo(media: [Api.MessageMedia], langCodes: [String])
public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) {
switch self {
case .previewInfo(let media, let langCodes):
if boxed {
buffer.appendInt32(1357069389)
}
buffer.appendInt32(481674261)
buffer.appendInt32(Int32(media.count))
for item in media {
item.serialize(buffer, true)
}
buffer.appendInt32(481674261)
buffer.appendInt32(Int32(langCodes.count))
for item in langCodes {
serializeString(item, buffer: buffer, boxed: false)
}
break
}
}
public func descriptionFields() -> (String, [(String, Any)]) {
switch self {
case .previewInfo(let media, let langCodes):
return ("previewInfo", [("media", media as Any), ("langCodes", langCodes as Any)])
}
}
public static func parse_previewInfo(_ reader: BufferReader) -> PreviewInfo? {
var _1: [Api.MessageMedia]?
if let _ = reader.readInt32() {
_1 = Api.parseVector(reader, elementSignature: 0, elementType: Api.MessageMedia.self)
}
var _2: [String]?
if let _ = reader.readInt32() {
_2 = Api.parseVector(reader, elementSignature: -1255641564, elementType: String.self)
}
let _c1 = _1 != nil
let _c2 = _2 != nil
if _c1 && _c2 {
return Api.bots.PreviewInfo.previewInfo(media: _1!, langCodes: _2!)
}
else {
return nil
}
}
}
}
public extension Api.channels {
enum AdminLogResults: TypeConstructorDescription {
case adminLogResults(events: [Api.ChannelAdminLogEvent], chats: [Api.Chat], users: [Api.User])
@ -1404,61 +1456,3 @@ public extension Api.help {
}
}
public extension Api.help {
enum Country: TypeConstructorDescription {
case country(flags: Int32, iso2: String, defaultName: String, name: String?, countryCodes: [Api.help.CountryCode])
public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) {
switch self {
case .country(let flags, let iso2, let defaultName, let name, let countryCodes):
if boxed {
buffer.appendInt32(-1014526429)
}
serializeInt32(flags, buffer: buffer, boxed: false)
serializeString(iso2, buffer: buffer, boxed: false)
serializeString(defaultName, buffer: buffer, boxed: false)
if Int(flags) & Int(1 << 1) != 0 {serializeString(name!, buffer: buffer, boxed: false)}
buffer.appendInt32(481674261)
buffer.appendInt32(Int32(countryCodes.count))
for item in countryCodes {
item.serialize(buffer, true)
}
break
}
}
public func descriptionFields() -> (String, [(String, Any)]) {
switch self {
case .country(let flags, let iso2, let defaultName, let name, let countryCodes):
return ("country", [("flags", flags as Any), ("iso2", iso2 as Any), ("defaultName", defaultName as Any), ("name", name as Any), ("countryCodes", countryCodes as Any)])
}
}
public static func parse_country(_ reader: BufferReader) -> Country? {
var _1: Int32?
_1 = reader.readInt32()
var _2: String?
_2 = parseString(reader)
var _3: String?
_3 = parseString(reader)
var _4: String?
if Int(_1!) & Int(1 << 1) != 0 {_4 = parseString(reader) }
var _5: [Api.help.CountryCode]?
if let _ = reader.readInt32() {
_5 = Api.parseVector(reader, elementSignature: 0, elementType: Api.help.CountryCode.self)
}
let _c1 = _1 != nil
let _c2 = _2 != nil
let _c3 = _3 != nil
let _c4 = (Int(_1!) & Int(1 << 1) == 0) || _4 != nil
let _c5 = _5 != nil
if _c1 && _c2 && _c3 && _c4 && _c5 {
return Api.help.Country.country(flags: _1!, iso2: _2!, defaultName: _3!, name: _4, countryCodes: _5!)
}
else {
return nil
}
}
}
}

View File

@ -1,3 +1,61 @@
public extension Api.help {
enum Country: TypeConstructorDescription {
case country(flags: Int32, iso2: String, defaultName: String, name: String?, countryCodes: [Api.help.CountryCode])
public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) {
switch self {
case .country(let flags, let iso2, let defaultName, let name, let countryCodes):
if boxed {
buffer.appendInt32(-1014526429)
}
serializeInt32(flags, buffer: buffer, boxed: false)
serializeString(iso2, buffer: buffer, boxed: false)
serializeString(defaultName, buffer: buffer, boxed: false)
if Int(flags) & Int(1 << 1) != 0 {serializeString(name!, buffer: buffer, boxed: false)}
buffer.appendInt32(481674261)
buffer.appendInt32(Int32(countryCodes.count))
for item in countryCodes {
item.serialize(buffer, true)
}
break
}
}
public func descriptionFields() -> (String, [(String, Any)]) {
switch self {
case .country(let flags, let iso2, let defaultName, let name, let countryCodes):
return ("country", [("flags", flags as Any), ("iso2", iso2 as Any), ("defaultName", defaultName as Any), ("name", name as Any), ("countryCodes", countryCodes as Any)])
}
}
public static func parse_country(_ reader: BufferReader) -> Country? {
var _1: Int32?
_1 = reader.readInt32()
var _2: String?
_2 = parseString(reader)
var _3: String?
_3 = parseString(reader)
var _4: String?
if Int(_1!) & Int(1 << 1) != 0 {_4 = parseString(reader) }
var _5: [Api.help.CountryCode]?
if let _ = reader.readInt32() {
_5 = Api.parseVector(reader, elementSignature: 0, elementType: Api.help.CountryCode.self)
}
let _c1 = _1 != nil
let _c2 = _2 != nil
let _c3 = _3 != nil
let _c4 = (Int(_1!) & Int(1 << 1) == 0) || _4 != nil
let _c5 = _5 != nil
if _c1 && _c2 && _c3 && _c4 && _c5 {
return Api.help.Country.country(flags: _1!, iso2: _2!, defaultName: _3!, name: _4, countryCodes: _5!)
}
else {
return nil
}
}
}
}
public extension Api.help {
enum CountryCode: TypeConstructorDescription {
case countryCode(flags: Int32, countryCode: String, prefixes: [String]?, patterns: [String]?)

View File

@ -2201,12 +2201,13 @@ public extension Api.functions.auth {
}
}
public extension Api.functions.bots {
static func addPreviewMedia(bot: Api.InputUser, media: Api.InputMedia) -> (FunctionDescription, Buffer, DeserializeFunctionResponse<Api.MessageMedia>) {
static func addPreviewMedia(bot: Api.InputUser, langCode: String, media: Api.InputMedia) -> (FunctionDescription, Buffer, DeserializeFunctionResponse<Api.MessageMedia>) {
let buffer = Buffer()
buffer.appendInt32(1633332331)
buffer.appendInt32(911238190)
bot.serialize(buffer, true)
serializeString(langCode, buffer: buffer, boxed: false)
media.serialize(buffer, true)
return (FunctionDescription(name: "bots.addPreviewMedia", parameters: [("bot", String(describing: bot)), ("media", String(describing: media))]), buffer, DeserializeFunctionResponse { (buffer: Buffer) -> Api.MessageMedia? in
return (FunctionDescription(name: "bots.addPreviewMedia", parameters: [("bot", String(describing: bot)), ("langCode", String(describing: langCode)), ("media", String(describing: media))]), buffer, DeserializeFunctionResponse { (buffer: Buffer) -> Api.MessageMedia? in
let reader = BufferReader(buffer)
var result: Api.MessageMedia?
if let signature = reader.readInt32() {
@ -2263,16 +2264,17 @@ public extension Api.functions.bots {
}
}
public extension Api.functions.bots {
static func deletePreviewMedia(bot: Api.InputUser, media: [Api.InputMedia]) -> (FunctionDescription, Buffer, DeserializeFunctionResponse<Api.Bool>) {
static func deletePreviewMedia(bot: Api.InputUser, langCode: String, media: [Api.InputMedia]) -> (FunctionDescription, Buffer, DeserializeFunctionResponse<Api.Bool>) {
let buffer = Buffer()
buffer.appendInt32(481471475)
buffer.appendInt32(755054003)
bot.serialize(buffer, true)
serializeString(langCode, buffer: buffer, boxed: false)
buffer.appendInt32(481674261)
buffer.appendInt32(Int32(media.count))
for item in media {
item.serialize(buffer, true)
}
return (FunctionDescription(name: "bots.deletePreviewMedia", parameters: [("bot", String(describing: bot)), ("media", String(describing: media))]), buffer, DeserializeFunctionResponse { (buffer: Buffer) -> Api.Bool? in
return (FunctionDescription(name: "bots.deletePreviewMedia", parameters: [("bot", String(describing: bot)), ("langCode", String(describing: langCode)), ("media", String(describing: media))]), buffer, DeserializeFunctionResponse { (buffer: Buffer) -> Api.Bool? in
let reader = BufferReader(buffer)
var result: Api.Bool?
if let signature = reader.readInt32() {
@ -2283,13 +2285,14 @@ public extension Api.functions.bots {
}
}
public extension Api.functions.bots {
static func editPreviewMedia(bot: Api.InputUser, media: Api.InputMedia, newMedia: Api.InputMedia) -> (FunctionDescription, Buffer, DeserializeFunctionResponse<Api.MessageMedia>) {
static func editPreviewMedia(bot: Api.InputUser, langCode: String, media: Api.InputMedia, newMedia: Api.InputMedia) -> (FunctionDescription, Buffer, DeserializeFunctionResponse<Api.MessageMedia>) {
let buffer = Buffer()
buffer.appendInt32(-1436441263)
buffer.appendInt32(1892426154)
bot.serialize(buffer, true)
serializeString(langCode, buffer: buffer, boxed: false)
media.serialize(buffer, true)
newMedia.serialize(buffer, true)
return (FunctionDescription(name: "bots.editPreviewMedia", parameters: [("bot", String(describing: bot)), ("media", String(describing: media)), ("newMedia", String(describing: newMedia))]), buffer, DeserializeFunctionResponse { (buffer: Buffer) -> Api.MessageMedia? in
return (FunctionDescription(name: "bots.editPreviewMedia", parameters: [("bot", String(describing: bot)), ("langCode", String(describing: langCode)), ("media", String(describing: media)), ("newMedia", String(describing: newMedia))]), buffer, DeserializeFunctionResponse { (buffer: Buffer) -> Api.MessageMedia? in
let reader = BufferReader(buffer)
var result: Api.MessageMedia?
if let signature = reader.readInt32() {
@ -2363,6 +2366,22 @@ public extension Api.functions.bots {
})
}
}
public extension Api.functions.bots {
static func getPreviewInfo(bot: Api.InputUser, langCode: String) -> (FunctionDescription, Buffer, DeserializeFunctionResponse<Api.bots.PreviewInfo>) {
let buffer = Buffer()
buffer.appendInt32(1111143341)
bot.serialize(buffer, true)
serializeString(langCode, buffer: buffer, boxed: false)
return (FunctionDescription(name: "bots.getPreviewInfo", parameters: [("bot", String(describing: bot)), ("langCode", String(describing: langCode))]), buffer, DeserializeFunctionResponse { (buffer: Buffer) -> Api.bots.PreviewInfo? in
let reader = BufferReader(buffer)
var result: Api.bots.PreviewInfo?
if let signature = reader.readInt32() {
result = Api.parse(reader, signature: signature) as? Api.bots.PreviewInfo
}
return result
})
}
}
public extension Api.functions.bots {
static func getPreviewMedias(bot: Api.InputUser) -> (FunctionDescription, Buffer, DeserializeFunctionResponse<[Api.MessageMedia]>) {
let buffer = Buffer()
@ -2396,16 +2415,17 @@ public extension Api.functions.bots {
}
}
public extension Api.functions.bots {
static func reorderPreviewMedias(bot: Api.InputUser, order: [Api.InputMedia]) -> (FunctionDescription, Buffer, DeserializeFunctionResponse<Api.Bool>) {
static func reorderPreviewMedias(bot: Api.InputUser, langCode: String, order: [Api.InputMedia]) -> (FunctionDescription, Buffer, DeserializeFunctionResponse<Api.Bool>) {
let buffer = Buffer()
buffer.appendInt32(-1472444656)
buffer.appendInt32(-1238895702)
bot.serialize(buffer, true)
serializeString(langCode, buffer: buffer, boxed: false)
buffer.appendInt32(481674261)
buffer.appendInt32(Int32(order.count))
for item in order {
item.serialize(buffer, true)
}
return (FunctionDescription(name: "bots.reorderPreviewMedias", parameters: [("bot", String(describing: bot)), ("order", String(describing: order))]), buffer, DeserializeFunctionResponse { (buffer: Buffer) -> Api.Bool? in
return (FunctionDescription(name: "bots.reorderPreviewMedias", parameters: [("bot", String(describing: bot)), ("langCode", String(describing: langCode)), ("order", String(describing: order))]), buffer, DeserializeFunctionResponse { (buffer: Buffer) -> Api.Bool? in
let reader = BufferReader(buffer)
var result: Api.Bool?
if let signature = reader.readInt32() {

View File

@ -522,12 +522,8 @@ func mediaAreaFromApiMediaArea(_ mediaArea: Api.MediaArea) -> MediaArea? {
return .link(coordinates: coodinatesFromApiMediaAreaCoordinates(coordinates), url: url)
case let .mediaAreaChannelPost(coordinates, channelId, messageId):
return .channelMessage(coordinates: coodinatesFromApiMediaAreaCoordinates(coordinates), messageId: EngineMessage.Id(peerId: PeerId(namespace: Namespaces.Peer.CloudChannel, id: PeerId.Id._internalFromInt64Value(channelId)), namespace: Namespaces.Message.Cloud, id: messageId))
case let .mediaAreaWeather(flags, coordinates, emoji, temperatureC):
var parsedFlags = MediaArea.WeatherFlags()
if (flags & (1 << 0)) != 0 {
parsedFlags.insert(.isDark)
}
return .weather(coordinates: coodinatesFromApiMediaAreaCoordinates(coordinates), emoji: emoji, temperature: temperatureC, flags: parsedFlags)
case let .mediaAreaWeather(coordinates, emoji, temperatureC, color):
return .weather(coordinates: coodinatesFromApiMediaAreaCoordinates(coordinates), emoji: emoji, temperature: temperatureC, color: color)
}
}
@ -580,12 +576,8 @@ func apiMediaAreasFromMediaAreas(_ mediaAreas: [MediaArea], transaction: Transac
}
case let .link(_, url):
apiMediaAreas.append(.mediaAreaUrl(coordinates: inputCoordinates, url: url))
case let .weather(_, emoji, temperature, flags):
var apiFlags: Int32 = 0
if flags.contains(.isDark) {
apiFlags |= (1 << 0)
}
apiMediaAreas.append(.mediaAreaWeather(flags: apiFlags, coordinates: inputCoordinates, emoji: emoji, temperatureC: temperature))
case let .weather(_, emoji, temperature, color):
apiMediaAreas.append(.mediaAreaWeather(coordinates: inputCoordinates, emoji: emoji, temperatureC: temperature, color: color))
}
}
return apiMediaAreas

View File

@ -8,6 +8,7 @@ public enum MediaArea: Codable, Equatable {
case value
case flags
case temperature
case color
}
public struct Coordinates: Codable, Equatable {
@ -150,7 +151,7 @@ public enum MediaArea: Codable, Equatable {
case reaction(coordinates: Coordinates, reaction: MessageReaction.Reaction, flags: ReactionFlags)
case channelMessage(coordinates: Coordinates, messageId: EngineMessage.Id)
case link(coordinates: Coordinates, url: String)
case weather(coordinates: Coordinates, emoji: String, temperature: Double, flags: WeatherFlags)
case weather(coordinates: Coordinates, emoji: String, temperature: Double, color: Int32)
public struct ReactionFlags: OptionSet {
public var rawValue: Int32
@ -167,21 +168,6 @@ public enum MediaArea: Codable, Equatable {
public static let isFlipped = ReactionFlags(rawValue: 1 << 1)
}
public struct WeatherFlags: OptionSet {
public var rawValue: Int32
public init(rawValue: Int32) {
self.rawValue = rawValue
}
public init() {
self.rawValue = 0
}
public static let isDark = WeatherFlags(rawValue: 1 << 0)
}
private enum MediaAreaType: Int32 {
case venue
case reaction
@ -222,8 +208,8 @@ public enum MediaArea: Codable, Equatable {
let coordinates = try container.decode(MediaArea.Coordinates.self, forKey: .coordinates)
let emoji = try container.decode(String.self, forKey: .value)
let temperature = try container.decode(Double.self, forKey: .temperature)
let flags = WeatherFlags(rawValue: try container.decodeIfPresent(Int32.self, forKey: .flags) ?? 0)
self = .weather(coordinates: coordinates, emoji: emoji, temperature: temperature, flags: flags)
let color = try container.decodeIfPresent(Int32.self, forKey: .color) ?? 0
self = .weather(coordinates: coordinates, emoji: emoji, temperature: temperature, color: color)
}
}
@ -248,12 +234,12 @@ public enum MediaArea: Codable, Equatable {
try container.encode(MediaAreaType.link.rawValue, forKey: .type)
try container.encode(coordinates, forKey: .coordinates)
try container.encode(url, forKey: .value)
case let .weather(coordinates, emoji, temperature, flags):
case let .weather(coordinates, emoji, temperature, color):
try container.encode(MediaAreaType.weather.rawValue, forKey: .type)
try container.encode(coordinates, forKey: .coordinates)
try container.encode(emoji, forKey: .value)
try container.encode(temperature, forKey: .temperature)
try container.encode(flags.rawValue, forKey: .flags)
try container.encode(color, forKey: .color)
}
}
}

View File

@ -1300,7 +1300,7 @@ func _internal_uploadBotPreviewImpl(
return postbox.transaction { transaction -> Signal<StoryUploadResult, NoError> in
switch content.content {
case let .media(inputMedia, _):
return network.request(Api.functions.bots.addPreviewMedia(bot: inputUser, media: inputMedia))
return network.request(Api.functions.bots.addPreviewMedia(bot: inputUser, langCode: "", media: inputMedia))
|> map(Optional.init)
|> `catch` { _ -> Signal<Api.MessageMedia?, NoError> in
return .single(nil)
@ -1402,7 +1402,7 @@ func _internal_deleteBotPreviews(account: Account, peerId: PeerId, ids: [MediaId
return .complete()
}
return account.network.request(Api.functions.bots.deletePreviewMedia(bot: inputPeer, media: inputMedia))
return account.network.request(Api.functions.bots.deletePreviewMedia(bot: inputPeer, langCode: "", media: inputMedia))
|> `catch` { _ -> Signal<Api.Bool, NoError> in
return .single(.boolFalse)
}

View File

@ -2307,7 +2307,7 @@ public final class BotPreviewStoryListContext: StoryListContext {
guard let self, let inputUser else {
return
}
let signal = self.account.network.request(Api.functions.bots.reorderPreviewMedias(bot: inputUser, order: inputMedia))
let signal = self.account.network.request(Api.functions.bots.reorderPreviewMedias(bot: inputUser, langCode: "", order: inputMedia))
self.reorderDisposable.set(signal.startStrict())
})
}

View File

@ -192,15 +192,12 @@ public enum CodableDrawingEntity: Equatable {
url: url
)
case let .weather(entity):
var flags: MediaArea.WeatherFlags = []
if entity.style == .black {
flags.insert(.isDark)
}
let color: UInt32 = 0xffffffff
return .weather(
coordinates: coordinates,
emoji: entity.emoji,
temperature: entity.temperature,
flags: flags
color: Int32(bitPattern: color)
)
default:
return nil

View File

@ -11,6 +11,7 @@ public final class DrawingWeatherEntity: DrawingEntity, Codable {
case uuid
case style
case color
case hasCustomColor
case emoji
case temperature
case icon
@ -25,6 +26,8 @@ public final class DrawingWeatherEntity: DrawingEntity, Codable {
public enum Style: Codable, Equatable {
case white
case black
case transparent
case custom
}
public var uuid: UUID
@ -38,7 +41,18 @@ public final class DrawingWeatherEntity: DrawingEntity, Codable {
public var emoji: String
public var temperature: Double
public var color: DrawingColor = DrawingColor.clear
public var color: DrawingColor = DrawingColor(color: .white) {
didSet {
if self.color.toUIColor().argb == UIColor.white.argb {
self.style = .white
self.hasCustomColor = false
} else {
self.style = .custom
self.hasCustomColor = true
}
}
}
public var hasCustomColor = false
public var lineWidth: CGFloat = 0.0
public var referenceDrawingSize: CGSize
@ -83,6 +97,8 @@ public final class DrawingWeatherEntity: DrawingEntity, Codable {
self.emoji = try container.decode(String.self, forKey: .emoji)
self.temperature = try container.decode(Double.self, forKey: .temperature)
self.style = try container.decode(Style.self, forKey: .style)
self.color = try container.decodeIfPresent(DrawingColor.self, forKey: .color) ?? DrawingColor(color: .white)
self.hasCustomColor = try container.decodeIfPresent(Bool.self, forKey: .hasCustomColor) ?? false
if let iconData = try container.decodeIfPresent(Data.self, forKey: .icon) {
self.icon = PostboxDecoder(buffer: MemoryBuffer(data: iconData)).decodeRootObject() as? TelegramMediaFile
@ -104,6 +120,8 @@ public final class DrawingWeatherEntity: DrawingEntity, Codable {
try container.encode(self.emoji, forKey: .emoji)
try container.encode(self.temperature, forKey: .temperature)
try container.encode(self.style, forKey: .style)
try container.encode(self.color, forKey: .color)
try container.encode(self.hasCustomColor, forKey: .hasCustomColor)
var encoder = PostboxEncoder()
if let icon = self.icon {
@ -152,6 +170,9 @@ public final class DrawingWeatherEntity: DrawingEntity, Codable {
if self.style != other.style {
return false
}
if self.color != other.color {
return false
}
if self.referenceDrawingSize != other.referenceDrawingSize {
return false
}

View File

@ -48,7 +48,6 @@ import StickerPackEditTitleController
import StickerPickerScreen
import UIKitRuntimeUtils
import ImageObjectSeparation
import DeviceAccess
private let playbackButtonTag = GenericComponentViewTag()
private let muteButtonTag = GenericComponentViewTag()
@ -4592,7 +4591,7 @@ public final class MediaEditorScreen: ViewController, UIDropInteractionDelegate
}
func presentLocationAccessAlert() {
DeviceAccess.authorizeAccess(to: .location(.send), locationManager: self.locationManager, presentationData: self.presentationData, present: { [weak self] c, a in
DeviceAccess.authorizeAccess(to: .location(.weather), locationManager: self.locationManager, presentationData: self.presentationData, present: { [weak self] c, a in
self?.controller?.present(c, in: .window(.root), with: a)
}, openSettings: { [weak self] in
self?.context.sharedContext.applicationBindings.openSettings()

View File

@ -562,7 +562,7 @@ final class StoryItemOverlaysView: UIView {
emoji: String,
emojiFile: TelegramMediaFile?,
temperature: Double,
flags: MediaArea.WeatherFlags,
color: Int32,
synchronous: Bool,
size: CGSize,
cornerRadius: CGFloat,
@ -570,13 +570,21 @@ final class StoryItemOverlaysView: UIView {
) -> CGSize {
let itemSize = CGSize(width: floor(size.height * 0.71), height: floor(size.height * 0.71))
let backgroundColor = UIColor(argb: UInt32(bitPattern: color))
let textColor: UIColor
if backgroundColor.lightness > 0.705 {
textColor = .black
} else {
textColor = .white
}
let placeholderColor = textColor.withAlphaComponent(0.1)
if self.file?.fileId != emojiFile?.fileId, let file = emojiFile {
self.file = file
self.customEmojiLoadDisposable?.dispose()
self.customEmojiLoadDisposable = fetchedMediaResource(mediaBox: context.account.postbox.mediaBox, userLocation: .other, userContentType: .sticker, reference: .standalone(resource: file.resource)).start()
let placeholderColor = flags.contains(.isDark) ? UIColor(white: 1.0, alpha: 0.1) : UIColor(white: 0.0, alpha: 0.1)
let _ = self.directStickerView.update(
transition: .immediate,
component: AnyComponent(LottieComponent(
@ -601,7 +609,7 @@ final class StoryItemOverlaysView: UIView {
let string = NSMutableAttributedString(
string: stringForTemperature(temperature),
font: textFont,
textColor: flags.contains(.isDark) ? UIColor(rgb: 0xffffff) : UIColor(rgb: 0x000000)
textColor: textColor
)
string.addAttribute(.kern, value: -(size.height / 38.0) as NSNumber, range: NSMakeRange(0, string.length))
@ -644,7 +652,7 @@ final class StoryItemOverlaysView: UIView {
let contentSize = CGSize(width: contentWidth, height: size.height)
self.backgroundView.backgroundColor = flags.contains(.isDark) ? UIColor(rgb: 0x000000) : UIColor(rgb: 0xffffff)
self.backgroundView.backgroundColor = backgroundColor
self.backgroundView.frame = CGRect(origin: .zero, size: contentSize)
self.backgroundView.layer.cornerRadius = cornerRadius
@ -752,7 +760,7 @@ final class StoryItemOverlaysView: UIView {
)
nextId += 1
case let .weather(coordinates, emoji, temperature, flags):
case let .weather(coordinates, emoji, temperature, color):
guard let (itemFrame, itemRotation, cornerRadius) = getFrameAndRotation(coordinates: coordinates) else {
continue
}
@ -773,7 +781,7 @@ final class StoryItemOverlaysView: UIView {
emoji: emoji,
emojiFile: context.animatedEmojiStickersValue[emoji]?.first?.file,
temperature: temperature,
flags: flags,
color: color,
synchronous: attemptSynchronous,
size: itemFrame.size,
cornerRadius: cornerRadius,