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")
|
||||
let _ = (combineLatest(queue: queue,
|
||||
fetchMediaSignal
|
||||
|> timeout(10.0, queue: queue, alternate: .single(nil)),
|
||||
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 {
|
||||
completed()
|
||||
return
|
||||
@ -1527,6 +1536,15 @@ private final class NotificationServiceHandler {
|
||||
|
||||
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)
|
||||
|
||||
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)
|
||||
|
||||
return signal |> map { fullSizeData in
|
||||
|
@ -112,6 +112,7 @@ public struct Namespaces {
|
||||
public static let displayedStoryNotifications: Int8 = 28
|
||||
public static let storySendAsPeerIds: Int8 = 29
|
||||
public static let cachedChannelBoosts: Int8 = 31
|
||||
public static let displayedMessageNotifications: Int8 = 32
|
||||
}
|
||||
|
||||
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()))
|
||||
}
|
||||
|
||||
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? {
|
||||
if !isChannel {
|
||||
return views
|
||||
|
@ -67,7 +67,7 @@ public final class ChatMessageAttachedContentNode: ASDisplayNode {
|
||||
private var actionButtonSeparator: SimpleLayer?
|
||||
public let statusNode: ChatMessageDateAndStatusNode
|
||||
|
||||
private var inlineMediaValue: TelegramMediaImage?
|
||||
private var inlineMediaValue: Media?
|
||||
|
||||
//private var additionalImageBadgeNode: ChatMessageInteractiveMediaBadge?
|
||||
private var linkHighlightingNode: LinkHighlightingNode?
|
||||
@ -300,7 +300,7 @@ public final class ChatMessageAttachedContentNode: ASDisplayNode {
|
||||
var maxWidth: CGFloat = .greatestFiniteMagnitude
|
||||
|
||||
let contentMediaContinueLayout: ((CGSize, Bool, Bool, ImageCorners) -> (CGFloat, (CGFloat) -> (CGSize, (ListViewItemUpdateAnimation, Bool) -> ChatMessageInteractiveMediaNode)))?
|
||||
let inlineMediaAndSize: (TelegramMediaImage, CGSize)?
|
||||
let inlineMediaAndSize: (Media, CGSize)?
|
||||
|
||||
if let contentMediaValue {
|
||||
if contentMediaInline {
|
||||
@ -308,6 +308,8 @@ public final class ChatMessageAttachedContentNode: ASDisplayNode {
|
||||
|
||||
if let image = contentMediaValue as? TelegramMediaImage {
|
||||
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 {
|
||||
inlineMediaAndSize = nil
|
||||
}
|
||||
@ -892,17 +894,28 @@ public final class ChatMessageAttachedContentNode: ASDisplayNode {
|
||||
}
|
||||
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
|
||||
if let dimensions = inlineMediaValue.representations.last?.dimensions.cgSize {
|
||||
fittedImageSize = dimensions.aspectFilled(inlineMediaSize)
|
||||
if let image = inlineMediaValue as? TelegramMediaImage {
|
||||
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 {
|
||||
if let inlineMedia = self.inlineMedia {
|
||||
self.inlineMedia = nil
|
||||
@ -2133,7 +2146,11 @@ public final class ChatMessageAttachedContentNode: ASDisplayNode {
|
||||
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?) {
|
||||
@ -2184,7 +2201,7 @@ public final class ChatMessageAttachedContentNode: ASDisplayNode {
|
||||
var isHighlighted = false
|
||||
if rects == nil, let point {
|
||||
if let actionButton = self.actionButton, actionButton.frame.contains(point) {
|
||||
} else {
|
||||
} else if let backgroundView = self.backgroundView, backgroundView.frame.contains(point) {
|
||||
isHighlighted = true
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user