mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-22 14:20:20 +00:00
Merge branch 'master' of gitlab.com:peter-iakovlev/telegram-ios
This commit is contained in:
@@ -198,7 +198,9 @@ public final class Logger {
|
||||
var fileEvents: [(Double, String)] = []
|
||||
if let data = try? Data(contentsOf: URL(fileURLWithPath: filePath), options: .mappedRead) {
|
||||
let dataLength = data.count
|
||||
data.withUnsafeBytes { (bytes: UnsafePointer<Int8>) -> Void in
|
||||
data.withUnsafeBytes { rawBytes -> Void in
|
||||
let bytes = rawBytes.baseAddress!.assumingMemoryBound(to: Int8.self)
|
||||
|
||||
var offset = 0
|
||||
while offset < dataLength {
|
||||
let remainingLength = dataLength - offset
|
||||
@@ -341,7 +343,9 @@ public final class Logger {
|
||||
|
||||
if let currentFile = currentFile {
|
||||
if let data = content.data(using: .utf8) {
|
||||
data.withUnsafeBytes { (bytes: UnsafePointer<UInt8>) -> Void in
|
||||
data.withUnsafeBytes { rawBytes -> Void in
|
||||
let bytes = rawBytes.baseAddress!.assumingMemoryBound(to: UInt8.self)
|
||||
|
||||
let _ = currentFile.write(bytes, count: data.count)
|
||||
}
|
||||
var newline: UInt8 = 0x0a
|
||||
@@ -448,7 +452,9 @@ public final class Logger {
|
||||
|
||||
if let currentFile = currentFile {
|
||||
let contentDataCount = contentData.count
|
||||
contentData.withUnsafeBytes { (bytes: UnsafePointer<UInt8>) -> Void in
|
||||
contentData.withUnsafeBytes { rawBytes -> Void in
|
||||
let bytes = rawBytes.baseAddress!.assumingMemoryBound(to: UInt8.self)
|
||||
|
||||
let _ = currentFile.write(bytes, count: contentDataCount)
|
||||
}
|
||||
if let shortFile = self.shortFile {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import Foundation
|
||||
import Postbox
|
||||
|
||||
import TelegramApi
|
||||
|
||||
public extension MessageFlags {
|
||||
var isSending: Bool {
|
||||
@@ -302,3 +302,15 @@ public extension Message {
|
||||
}
|
||||
}
|
||||
|
||||
public func _internal_parseMediaAttachment(data: Data) -> Media? {
|
||||
guard let object = Api.parse(Buffer(buffer: MemoryBuffer(data: data))) else {
|
||||
return nil
|
||||
}
|
||||
if let photo = object as? Api.Photo {
|
||||
return telegramMediaImageFromApiPhoto(photo)
|
||||
} else if let file = object as? Api.Document {
|
||||
return telegramMediaFileFromApiDocument(file)
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,23 +57,34 @@ public extension Peer {
|
||||
switch self {
|
||||
case let user as TelegramUser:
|
||||
if let firstName = user.firstName, let lastName = user.lastName, !firstName.isEmpty && !lastName.isEmpty {
|
||||
return [firstName.substring(to: firstName.index(after: firstName.startIndex)).uppercased(), lastName.substring(to: lastName.index(after: lastName.startIndex)).uppercased()]
|
||||
return [
|
||||
String(firstName[..<firstName.index(after: firstName.startIndex)].uppercased()),
|
||||
String(lastName[..<lastName.index(after: lastName.startIndex)].uppercased()),
|
||||
]
|
||||
} else if let firstName = user.firstName, !firstName.isEmpty {
|
||||
return [firstName.substring(to: firstName.index(after: firstName.startIndex)).uppercased()]
|
||||
return [
|
||||
String(firstName[..<firstName.index(after: firstName.startIndex)].uppercased())
|
||||
]
|
||||
} else if let lastName = user.lastName, !lastName.isEmpty {
|
||||
return [lastName.substring(to: lastName.index(after: lastName.startIndex)).uppercased()]
|
||||
return [
|
||||
String(lastName[..<lastName.index(after: lastName.startIndex)].uppercased()),
|
||||
]
|
||||
}
|
||||
|
||||
return []
|
||||
case let group as TelegramGroup:
|
||||
if group.title.startIndex != group.title.endIndex {
|
||||
return [group.title.substring(to: group.title.index(after: group.title.startIndex)).uppercased()]
|
||||
return [
|
||||
String(group.title[..<group.title.index(after: group.title.startIndex)].uppercased()),
|
||||
]
|
||||
} else {
|
||||
return []
|
||||
}
|
||||
case let channel as TelegramChannel:
|
||||
if channel.title.startIndex != channel.title.endIndex {
|
||||
return [channel.title.substring(to: channel.title.index(after: channel.title.startIndex)).uppercased()]
|
||||
return [
|
||||
String(channel.title[..<channel.title.index(after: channel.title.startIndex)].uppercased()),
|
||||
]
|
||||
} else {
|
||||
return []
|
||||
}
|
||||
@@ -183,12 +194,12 @@ public func peerDebugDisplayTitles(_ peers: [Peer]) -> String {
|
||||
}
|
||||
}
|
||||
|
||||
public func messageMainPeer(_ message: Message) -> Peer? {
|
||||
public func messageMainPeer(_ message: EngineMessage) -> EnginePeer? {
|
||||
if let peer = message.peers[message.id.peerId] {
|
||||
if let peer = peer as? TelegramSecretChat {
|
||||
return message.peers[peer.regularPeerId]
|
||||
return message.peers[peer.regularPeerId].flatMap(EnginePeer.init)
|
||||
} else {
|
||||
return peer
|
||||
return EnginePeer(peer)
|
||||
}
|
||||
} else {
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user