mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-06-16 05:55:20 +00:00
Various improvements
This commit is contained in:
parent
339089a3f8
commit
b43fa0ecb5
@ -1425,15 +1425,24 @@ private final class NotificationServiceHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let wasDisplayed = stateManager.postbox.transaction { transaction -> Bool in
|
||||||
|
if let messageId {
|
||||||
|
return _internal_getMessageNotificationWasDisplayed(transaction: transaction, id: messageId)
|
||||||
|
} else {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Logger.shared.log("NotificationService \(episode)", "Will fetch media")
|
Logger.shared.log("NotificationService \(episode)", "Will fetch media")
|
||||||
let _ = (combineLatest(queue: queue,
|
let _ = (combineLatest(queue: queue,
|
||||||
fetchMediaSignal
|
fetchMediaSignal
|
||||||
|> timeout(10.0, queue: queue, alternate: .single(nil)),
|
|> timeout(10.0, queue: queue, alternate: .single(nil)),
|
||||||
fetchNotificationSoundSignal
|
fetchNotificationSoundSignal
|
||||||
|> timeout(10.0, queue: queue, alternate: .single(nil))
|
|> timeout(10.0, queue: queue, alternate: .single(nil)),
|
||||||
|
wasDisplayed
|
||||||
)
|
)
|
||||||
|> deliverOn(queue)).start(next: { mediaData, notificationSoundData in
|
|> deliverOn(queue)).start(next: { mediaData, notificationSoundData, wasDisplayed in
|
||||||
guard let strongSelf = self, let stateManager = strongSelf.stateManager else {
|
guard let strongSelf = self, let stateManager = strongSelf.stateManager else {
|
||||||
completed()
|
completed()
|
||||||
return
|
return
|
||||||
@ -1527,6 +1536,15 @@ private final class NotificationServiceHandler {
|
|||||||
|
|
||||||
Logger.shared.log("NotificationService \(episode)", "Updating content to \(content)")
|
Logger.shared.log("NotificationService \(episode)", "Updating content to \(content)")
|
||||||
|
|
||||||
|
if wasDisplayed {
|
||||||
|
content = NotificationContent(isLockedMessage: nil)
|
||||||
|
Logger.shared.log("NotificationService \(episode)", "Was already displayed, skipping content")
|
||||||
|
} else if let messageId {
|
||||||
|
let _ = (stateManager.postbox.transaction { transaction -> Void in
|
||||||
|
_internal_setMessageNotificationWasDisplayed(transaction: transaction, id: messageId)
|
||||||
|
}).start()
|
||||||
|
}
|
||||||
|
|
||||||
updateCurrentContent(content)
|
updateCurrentContent(content)
|
||||||
|
|
||||||
completed()
|
completed()
|
||||||
|
@ -1915,7 +1915,7 @@ public func chatWebpageSnippetPhotoData(account: Account, userLocation: MediaRes
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public func chatWebpageSnippetFile(account: Account, userLocation: MediaResourceUserLocation, mediaReference: AnyMediaReference, representation: TelegramMediaImageRepresentation, automaticFetch: Bool = true) -> Signal<(TransformImageArguments) -> DrawingContext?, NoError> {
|
public func chatWebpageSnippetFile(account: Account, userLocation: MediaResourceUserLocation, mediaReference: AnyMediaReference, representation: TelegramMediaImageRepresentation, automaticFetch: Bool = true, placeholderColor: UIColor? = nil) -> Signal<(TransformImageArguments) -> DrawingContext?, NoError> {
|
||||||
let signal = chatWebpageSnippetFileData(account: account, userLocation: userLocation, mediaReference: mediaReference, resource: representation.resource, automaticFetch: automaticFetch)
|
let signal = chatWebpageSnippetFileData(account: account, userLocation: userLocation, mediaReference: mediaReference, resource: representation.resource, automaticFetch: automaticFetch)
|
||||||
|
|
||||||
return signal |> map { fullSizeData in
|
return signal |> map { fullSizeData in
|
||||||
|
@ -112,6 +112,7 @@ public struct Namespaces {
|
|||||||
public static let displayedStoryNotifications: Int8 = 28
|
public static let displayedStoryNotifications: Int8 = 28
|
||||||
public static let storySendAsPeerIds: Int8 = 29
|
public static let storySendAsPeerIds: Int8 = 29
|
||||||
public static let cachedChannelBoosts: Int8 = 31
|
public static let cachedChannelBoosts: Int8 = 31
|
||||||
|
public static let displayedMessageNotifications: Int8 = 32
|
||||||
}
|
}
|
||||||
|
|
||||||
public struct UnorderedItemList {
|
public struct UnorderedItemList {
|
||||||
|
@ -1993,6 +1993,20 @@ public func _internal_setStoryNotificationWasDisplayed(transaction: Transaction,
|
|||||||
transaction.putItemCacheEntry(id: ItemCacheEntryId(collectionId: Namespaces.CachedItemCollection.displayedStoryNotifications, key: key), entry: CodableEntry(data: Data()))
|
transaction.putItemCacheEntry(id: ItemCacheEntryId(collectionId: Namespaces.CachedItemCollection.displayedStoryNotifications, key: key), entry: CodableEntry(data: Data()))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public func _internal_getMessageNotificationWasDisplayed(transaction: Transaction, id: MessageId) -> Bool {
|
||||||
|
let key = ValueBoxKey(length: 8 + 4)
|
||||||
|
key.setInt64(0, value: id.peerId.toInt64())
|
||||||
|
key.setInt32(8, value: id.id)
|
||||||
|
return transaction.retrieveItemCacheEntry(id: ItemCacheEntryId(collectionId: Namespaces.CachedItemCollection.displayedMessageNotifications, key: key)) != nil
|
||||||
|
}
|
||||||
|
|
||||||
|
public func _internal_setMessageNotificationWasDisplayed(transaction: Transaction, id: MessageId) {
|
||||||
|
let key = ValueBoxKey(length: 8 + 4)
|
||||||
|
key.setInt64(0, value: id.peerId.toInt64())
|
||||||
|
key.setInt32(8, value: id.id)
|
||||||
|
transaction.putItemCacheEntry(id: ItemCacheEntryId(collectionId: Namespaces.CachedItemCollection.displayedMessageNotifications, key: key), entry: CodableEntry(data: Data()))
|
||||||
|
}
|
||||||
|
|
||||||
func _internal_updateStoryViewsForMyReaction(isChannel: Bool, views: Stories.Item.Views?, previousReaction: MessageReaction.Reaction?, reaction: MessageReaction.Reaction?) -> Stories.Item.Views? {
|
func _internal_updateStoryViewsForMyReaction(isChannel: Bool, views: Stories.Item.Views?, previousReaction: MessageReaction.Reaction?, reaction: MessageReaction.Reaction?) -> Stories.Item.Views? {
|
||||||
if !isChannel {
|
if !isChannel {
|
||||||
return views
|
return views
|
||||||
|
@ -67,7 +67,7 @@ public final class ChatMessageAttachedContentNode: ASDisplayNode {
|
|||||||
private var actionButtonSeparator: SimpleLayer?
|
private var actionButtonSeparator: SimpleLayer?
|
||||||
public let statusNode: ChatMessageDateAndStatusNode
|
public let statusNode: ChatMessageDateAndStatusNode
|
||||||
|
|
||||||
private var inlineMediaValue: TelegramMediaImage?
|
private var inlineMediaValue: Media?
|
||||||
|
|
||||||
//private var additionalImageBadgeNode: ChatMessageInteractiveMediaBadge?
|
//private var additionalImageBadgeNode: ChatMessageInteractiveMediaBadge?
|
||||||
private var linkHighlightingNode: LinkHighlightingNode?
|
private var linkHighlightingNode: LinkHighlightingNode?
|
||||||
@ -300,7 +300,7 @@ public final class ChatMessageAttachedContentNode: ASDisplayNode {
|
|||||||
var maxWidth: CGFloat = .greatestFiniteMagnitude
|
var maxWidth: CGFloat = .greatestFiniteMagnitude
|
||||||
|
|
||||||
let contentMediaContinueLayout: ((CGSize, Bool, Bool, ImageCorners) -> (CGFloat, (CGFloat) -> (CGSize, (ListViewItemUpdateAnimation, Bool) -> ChatMessageInteractiveMediaNode)))?
|
let contentMediaContinueLayout: ((CGSize, Bool, Bool, ImageCorners) -> (CGFloat, (CGFloat) -> (CGSize, (ListViewItemUpdateAnimation, Bool) -> ChatMessageInteractiveMediaNode)))?
|
||||||
let inlineMediaAndSize: (TelegramMediaImage, CGSize)?
|
let inlineMediaAndSize: (Media, CGSize)?
|
||||||
|
|
||||||
if let contentMediaValue {
|
if let contentMediaValue {
|
||||||
if contentMediaInline {
|
if contentMediaInline {
|
||||||
@ -308,6 +308,8 @@ public final class ChatMessageAttachedContentNode: ASDisplayNode {
|
|||||||
|
|
||||||
if let image = contentMediaValue as? TelegramMediaImage {
|
if let image = contentMediaValue as? TelegramMediaImage {
|
||||||
inlineMediaAndSize = (image, CGSize(width: 54.0, height: 54.0))
|
inlineMediaAndSize = (image, CGSize(width: 54.0, height: 54.0))
|
||||||
|
} else if let file = contentMediaValue as? TelegramMediaFile, !file.previewRepresentations.isEmpty {
|
||||||
|
inlineMediaAndSize = (file, CGSize(width: 54.0, height: 54.0))
|
||||||
} else {
|
} else {
|
||||||
inlineMediaAndSize = nil
|
inlineMediaAndSize = nil
|
||||||
}
|
}
|
||||||
@ -892,17 +894,28 @@ public final class ChatMessageAttachedContentNode: ASDisplayNode {
|
|||||||
}
|
}
|
||||||
self.inlineMediaValue = inlineMediaValue
|
self.inlineMediaValue = inlineMediaValue
|
||||||
|
|
||||||
if updateMedia {
|
|
||||||
let updateInlineImageSignal = chatWebpageSnippetPhoto(account: context.account, userLocation: .peer(message.id.peerId), photoReference: .message(message: MessageReference(message), media: inlineMediaValue), placeholderColor: mainColor.withMultipliedAlpha(0.1))
|
|
||||||
inlineMedia.setSignal(updateInlineImageSignal)
|
|
||||||
}
|
|
||||||
|
|
||||||
var fittedImageSize = inlineMediaSize
|
var fittedImageSize = inlineMediaSize
|
||||||
if let dimensions = inlineMediaValue.representations.last?.dimensions.cgSize {
|
if let image = inlineMediaValue as? TelegramMediaImage {
|
||||||
fittedImageSize = dimensions.aspectFilled(inlineMediaSize)
|
if let dimensions = image.representations.last?.dimensions.cgSize {
|
||||||
|
fittedImageSize = dimensions.aspectFilled(inlineMediaSize)
|
||||||
|
}
|
||||||
|
} else if let file = inlineMediaValue as? TelegramMediaFile {
|
||||||
|
if let dimensions = file.dimensions?.cgSize {
|
||||||
|
fittedImageSize = dimensions.aspectFilled(inlineMediaSize)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
inlineMedia.asyncLayout()(TransformImageArguments(corners: ImageCorners(radius: 4.0), imageSize: fittedImageSize, boundingSize: inlineMediaSize, intrinsicInsets: UIEdgeInsets()))()
|
|
||||||
|
|
||||||
|
if updateMedia {
|
||||||
|
if let image = inlineMediaValue as? TelegramMediaImage {
|
||||||
|
let updateInlineImageSignal = chatWebpageSnippetPhoto(account: context.account, userLocation: .peer(message.id.peerId), photoReference: .message(message: MessageReference(message), media: image), placeholderColor: mainColor.withMultipliedAlpha(0.1))
|
||||||
|
inlineMedia.setSignal(updateInlineImageSignal)
|
||||||
|
} else if let file = inlineMediaValue as? TelegramMediaFile, let representation = file.previewRepresentations.last {
|
||||||
|
let updateInlineImageSignal = chatWebpageSnippetFile(account: context.account, userLocation: .peer(message.id.peerId), mediaReference: .message(message: MessageReference(message), media: file), representation: representation)
|
||||||
|
inlineMedia.setSignal(updateInlineImageSignal)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
inlineMedia.asyncLayout()(TransformImageArguments(corners: ImageCorners(radius: 4.0), imageSize: fittedImageSize, boundingSize: inlineMediaSize, intrinsicInsets: UIEdgeInsets(), emptyColor: mainColor.withMultipliedAlpha(0.1)))()
|
||||||
} else {
|
} else {
|
||||||
if let inlineMedia = self.inlineMedia {
|
if let inlineMedia = self.inlineMedia {
|
||||||
self.inlineMedia = nil
|
self.inlineMedia = nil
|
||||||
@ -2133,7 +2146,11 @@ public final class ChatMessageAttachedContentNode: ASDisplayNode {
|
|||||||
return ChatMessageBubbleContentTapAction(content: .ignore)
|
return ChatMessageBubbleContentTapAction(content: .ignore)
|
||||||
}
|
}
|
||||||
|
|
||||||
return self.defaultContentAction()
|
if let backgroundView = self.backgroundView, backgroundView.frame.contains(point) {
|
||||||
|
return self.defaultContentAction()
|
||||||
|
} else {
|
||||||
|
return .init(content: .none)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public func updateTouchesAtPoint(_ point: CGPoint?) {
|
public func updateTouchesAtPoint(_ point: CGPoint?) {
|
||||||
@ -2184,7 +2201,7 @@ public final class ChatMessageAttachedContentNode: ASDisplayNode {
|
|||||||
var isHighlighted = false
|
var isHighlighted = false
|
||||||
if rects == nil, let point {
|
if rects == nil, let point {
|
||||||
if let actionButton = self.actionButton, actionButton.frame.contains(point) {
|
if let actionButton = self.actionButton, actionButton.frame.contains(point) {
|
||||||
} else {
|
} else if let backgroundView = self.backgroundView, backgroundView.frame.contains(point) {
|
||||||
isHighlighted = true
|
isHighlighted = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user