Skip to content

Commit b2bcc7f

Browse files
author
Mike Renoir
committed
bugfixes
1 parent 6bb8977 commit b2bcc7f

11 files changed

+158
-74
lines changed

‎Telegram-Mac/AccountInfoItem.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ class AccountInfoItem: GeneralRowItem {
8282

8383
let hasControl = PremiumStatusControl.hasControl(peer)
8484

85-
self.titleLayout.measure(width: width - 140 - (hasControl ? 35 : 0))
86-
self.titleActiveLayout.measure(width: width - 140 - (hasControl ? 35 : 0))
85+
self.titleLayout.measure(width: width - 140 - (hasControl ? 45 : 0))
86+
self.titleActiveLayout.measure(width: width - 140 - (hasControl ? 45 : 0))
8787
return success
8888
}
8989

@@ -345,7 +345,7 @@ private class AccountInfoView : GeneralContainableRowView {
345345

346346
let h: CGFloat = statusControl != nil ? 6 : 0
347347

348-
container.setFrameSize(NSMakeSize(max(titleView.frame.width, textView.frame.width + (statusControl != nil ? 35 : 0)), titleView.frame.height + textView.frame.height + 2 + h))
348+
container.setFrameSize(NSMakeSize(max(titleView.frame.width, textView.frame.width + (statusControl != nil ? 40 : 0)), titleView.frame.height + textView.frame.height + 2 + h))
349349

350350
titleView.setFrameOrigin(0, h)
351351
textView.setFrameOrigin(0, titleView.frame.maxY + 2)

‎Telegram-Mac/AddReactionManager.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ final class ContextAddReactionsListView : View, StickerFramesCollector {
9494
let rect = CGRect(origin: .zero, size: size)
9595

9696
self.player = LottiePlayerView(frame: rect)
97-
self.imageView = InlineStickerView(account: context.account, inlinePacksContext: context.inlinePacksContext, emoji: .init(fileId: reaction.fileId, file: reaction.file, emoji: ""), size: size)
97+
self.imageView = InlineStickerView(account: context.account, inlinePacksContext: context.inlinePacksContext, emoji: .init(fileId: reaction.fileId, file: reaction.file, emoji: ""), size: size, shimmerColor: .init(circle: true))
9898
self.reaction = reaction
9999
self.context = context
100100

‎Telegram-Mac/ChatReactionsView.swift

+34-18
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,33 @@ extension MessageReaction.Reaction {
3434
}
3535
}
3636

37+
extension MessageReaction {
38+
static func <(lhs: MessageReaction, rhs: MessageReaction) -> Bool {
39+
var lhsCount = lhs.count
40+
if lhs.chosenOrder != nil {
41+
lhsCount -= 1
42+
}
43+
var rhsCount = rhs.count
44+
if rhs.chosenOrder != nil {
45+
rhsCount -= 1
46+
}
47+
if lhsCount != rhsCount {
48+
return lhsCount > rhsCount
49+
}
50+
51+
if (lhs.chosenOrder != nil) != (rhs.chosenOrder != nil) {
52+
if lhs.chosenOrder != nil {
53+
return true
54+
} else {
55+
return false
56+
}
57+
} else if let lhsIndex = lhs.chosenOrder, let rhsIndex = rhs.chosenOrder {
58+
return lhsIndex < rhsIndex
59+
}
60+
return false
61+
}
62+
}
63+
3764
final class ChatReactionsLayout {
3865

3966
struct Theme : Equatable {
@@ -160,14 +187,14 @@ final class ChatReactionsLayout {
160187
func getInlineLayer(_ mode: ChatReactionsLayout.Mode) -> InlineStickerItemLayer {
161188
switch source {
162189
case let .builtin(reaction):
163-
return .init(account: context.account, file: reaction.staticIcon, size: presentation.reactionSize)
190+
return .init(account: context.account, file: reaction.staticIcon, size: presentation.reactionSize, shimmerColor: .init(color: presentation.bgColor.darker(), circle: true))
164191
case let .custom(fileId, file, _):
165192
var reactionSize: NSSize = presentation.reactionSize
166193
if mode == .full {
167194
reactionSize.width += 3
168195
reactionSize.height += 3
169196
}
170-
return .init(account: context.account, inlinePacksContext: context.inlinePacksContext, emoji: .init(fileId: fileId, file: file, emoji: ""), size: reactionSize)
197+
return .init(account: context.account, inlinePacksContext: context.inlinePacksContext, emoji: .init(fileId: fileId, file: file, emoji: ""), size: reactionSize, shimmerColor: .init(color: presentation.bgColor.darker(), circle: true))
171198
}
172199
}
173200

@@ -431,21 +458,7 @@ final class ChatReactionsLayout {
431458
}
432459
}
433460

434-
let sorted = reactions.reactions.sorted(by: { lhs, rhs in
435-
if lhs.isSelected != rhs.isSelected {
436-
if lhs.isSelected {
437-
return true
438-
} else {
439-
return false
440-
}
441-
} else {
442-
if let lhsIndex = lhs.chosenOrder, let rhsIndex = rhs.chosenOrder {
443-
return lhsIndex < rhsIndex
444-
} else {
445-
return lhs.count > rhs.count
446-
}
447-
}
448-
})
461+
let sorted = reactions.reactions.sorted(by: <)
449462

450463

451464
self.reactions = sorted.compactMap { reaction in
@@ -474,6 +487,9 @@ final class ChatReactionsLayout {
474487
if let peer = message.peers[message.id.peerId], peer.isChannel {
475488
recentPeers = []
476489
}
490+
if reactions.reactions.reduce(0, { $0 + $1.count }) > 3 {
491+
recentPeers = []
492+
}
477493

478494
if message.id.peerId.namespace == Namespaces.Peer.CloudUser {
479495
if mode == .full {
@@ -627,7 +643,7 @@ class AnimationLayerContainer : View {
627643
override func layout() {
628644
super.layout()
629645
if let imageLayer = self.imageLayer {
630-
imageLayer.frame = focus(imageLayer.frame.size)
646+
imageLayer.frame = self.bounds
631647
}
632648
}
633649

‎Telegram-Mac/ChatRowItem.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -2733,7 +2733,7 @@ class ChatRowItem: TableRowItem {
27332733
var accessToAll: Bool
27342734

27352735
let isSelected:(MessageReaction.Reaction)->Bool = { reaction in
2736-
return message.effectiveReactions?.contains(where: { $0.value == reaction }) ?? false
2736+
return message.effectiveReactions?.contains(where: { $0.value == reaction && $0.isSelected }) ?? false
27372737
}
27382738

27392739

‎Telegram-Mac/CoreExtension.swift

+1-15
Original file line numberDiff line numberDiff line change
@@ -614,21 +614,7 @@ public extension Message {
614614
var updated:[UpdateMessageReaction] = []
615615
if let reactions = self.effectiveReactions {
616616

617-
let sorted = reactions.sorted(by: { lhs, rhs in
618-
if lhs.isSelected != rhs.isSelected {
619-
if lhs.isSelected {
620-
return true
621-
} else {
622-
return false
623-
}
624-
} else {
625-
if let lhsIndex = lhs.chosenOrder, let rhsIndex = rhs.chosenOrder {
626-
return lhsIndex < rhsIndex
627-
} else {
628-
return lhs.count > rhs.count
629-
}
630-
}
631-
})
617+
let sorted = reactions.sorted(by: <)
632618

633619
updated = sorted.compactMap { value in
634620
if value.isSelected {

‎Telegram-Mac/EmojiesController.swift

+26-4
Original file line numberDiff line numberDiff line change
@@ -557,19 +557,41 @@ private func entries(_ state: State, arguments: Arguments) -> [InputDataEntry] {
557557
}
558558
popular = Array(top.prefix(perline * 2))
559559
recent = state.recentReactionsItems
560+
561+
560562
for item in state.topReactionsItems {
561563
let recentContains = recent.contains(where: { $0.id.id == item.id.id })
562564
let popularContains = popular.contains(where: { $0.id.id == item.id.id })
563565

564566
if !recentContains && !popularContains {
565-
switch item.content {
566-
case .builtin:
567+
if state.recentReactionsItems.isEmpty {
568+
switch item.content {
569+
case .builtin:
570+
recent.append(item)
571+
default:
572+
break
573+
}
574+
} else {
567575
recent.append(item)
568-
default:
569-
break
570576
}
571577
}
572578
}
579+
580+
if let reactions = state.reactions?.reactions {
581+
for reaction in reactions {
582+
let recentContains = recent.contains(where: { $0.content.reaction == reaction.value })
583+
let popularContains = popular.contains(where: { $0.content.reaction == reaction.value })
584+
if !recentContains && !popularContains {
585+
switch reaction.value {
586+
case let .builtin(emoji):
587+
recent.append(.init(.builtin(emoji)))
588+
default:
589+
break
590+
}
591+
}
592+
}
593+
}
594+
573595
recent = Array(recent.prefix(perline * 10))
574596
// } else {
575597
// popular = Array(state.topReactionsItems.prefix(perline * 2))

‎Telegram-Mac/Info.plist

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
</dict>
3636
</array>
3737
<key>CFBundleVersion</key>
38-
<string>236327</string>
38+
<string>236378</string>
3939
<key>LSApplicationCategoryType</key>
4040
<string>public.app-category.social-networking</string>
4141
<key>LSFileQuarantineEnabled</key>

‎Telegram-Mac/InlineStickerItemLayer.swift

+53-19
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import TelegramCore
1212
import Postbox
1313
import TGUIKit
1414
import Accelerate
15+
import AppKit
1516

1617
class InlineStickerLockLayer : SimpleLayer {
1718
private let lockedView: SimpleLayer = SimpleLayer()
@@ -250,14 +251,14 @@ private final class MultiTargetContextCache {
250251
}
251252

252253
final class InlineStickerView: View {
253-
init(account: Account, inlinePacksContext: InlineStickersContext?, emoji: ChatTextCustomEmojiAttribute, size: NSSize, getColors:((TelegramMediaFile)->[LottieColor])? = nil) {
254-
let layer = InlineStickerItemLayer(account: account, inlinePacksContext: inlinePacksContext, emoji: emoji, size: size, getColors: getColors)
254+
init(account: Account, inlinePacksContext: InlineStickersContext?, emoji: ChatTextCustomEmojiAttribute, size: NSSize, getColors:((TelegramMediaFile)->[LottieColor])? = nil, shimmerColor: InlineStickerItemLayer.Shimmer = .init(circle: false)) {
255+
let layer = InlineStickerItemLayer(account: account, inlinePacksContext: inlinePacksContext, emoji: emoji, size: size, getColors: getColors, shimmerColor: shimmerColor)
255256
super.init(frame: size.bounds)
256257
self.layer = layer
257258
layer.superview = self
258259
}
259-
init(account: Account, file: TelegramMediaFile, size: NSSize, getColors:((TelegramMediaFile)->[LottieColor])? = nil) {
260-
let layer = InlineStickerItemLayer(account: account, file: file, size: size, getColors: getColors)
260+
init(account: Account, file: TelegramMediaFile, size: NSSize, getColors:((TelegramMediaFile)->[LottieColor])? = nil, shimmerColor: InlineStickerItemLayer.Shimmer = .init(circle: false)) {
261+
let layer = InlineStickerItemLayer(account: account, file: file, size: size, getColors: getColors, shimmerColor: shimmerColor)
261262
super.init(frame: size.bounds)
262263
self.layer = layer
263264
layer.superview = self
@@ -359,11 +360,23 @@ final class InlineStickerItemLayer : SimpleLayer {
359360

360361
private let getColors:((TelegramMediaFile)->[LottieColor])?
361362

362-
init(account: Account, inlinePacksContext: InlineStickersContext?, emoji: ChatTextCustomEmojiAttribute, size: NSSize, playPolicy: LottiePlayPolicy = .loop, checkStatus: Bool = false, aspectFilled: Bool = false, getColors:((TelegramMediaFile)->[LottieColor])? = nil) {
363+
struct Shimmer {
364+
let color: NSColor
365+
let circle: Bool
366+
init(color:NSColor = NSColor(0x748391), circle: Bool) {
367+
self.color = color
368+
self.circle = circle
369+
}
370+
}
371+
private let shimmerColor: Shimmer
372+
373+
374+
init(account: Account, inlinePacksContext: InlineStickersContext?, emoji: ChatTextCustomEmojiAttribute, size: NSSize, playPolicy: LottiePlayPolicy = .loop, checkStatus: Bool = false, aspectFilled: Bool = false, getColors:((TelegramMediaFile)->[LottieColor])? = nil, shimmerColor: Shimmer = Shimmer(circle: false)) {
363375
self.aspectFilled = aspectFilled
364376
self.account = account
365377
self.playPolicy = playPolicy
366378
self.getColors = getColors
379+
self.shimmerColor = shimmerColor
367380
super.init()
368381
self.frame = size.bounds
369382
self.initialize()
@@ -386,11 +399,12 @@ final class InlineStickerItemLayer : SimpleLayer {
386399
})
387400
}
388401

389-
init(account: Account, file: TelegramMediaFile, size: NSSize, playPolicy: LottiePlayPolicy = .loop, aspectFilled: Bool = false, getColors:((TelegramMediaFile)->[LottieColor])? = nil) {
402+
init(account: Account, file: TelegramMediaFile, size: NSSize, playPolicy: LottiePlayPolicy = .loop, aspectFilled: Bool = false, getColors:((TelegramMediaFile)->[LottieColor])? = nil, shimmerColor: Shimmer = Shimmer(circle: false)) {
390403
self.aspectFilled = aspectFilled
391404
self.account = account
392405
self.playPolicy = playPolicy
393406
self.getColors = getColors
407+
self.shimmerColor = shimmerColor
394408
super.init()
395409
self.initialize()
396410
self.file = file
@@ -449,20 +463,26 @@ final class InlineStickerItemLayer : SimpleLayer {
449463
}
450464
}
451465
}
466+
private var isPreviousPreview: Bool = false
467+
452468
private var contextToken: (Int, MultiTargetContextCache.Key)?
453469
private func set(_ animation: LottieAnimation?, force: Bool = false) {
454470
self.animation = animation
455471
if let animation = animation, let isPlayable = self.isPlayable, isPlayable, !stopped {
456-
weak var layer: CALayer? = self
472+
weak var layer: InlineStickerItemLayer? = self
457473
let key: MultiTargetContextCache.Key = .init(key: animation.key, unique: unique)
458474
delayDisposable.set(delaySignal(MultiTargetContextCache.exists(key) || force ? 0 : 0.1).start(completed: { [weak self] in
459-
475+
460476
self?.contextToken = (MultiTargetContextCache.create(animation, key: key, displayFrame: { image in
461477
DispatchQueue.main.async {
462478
layer?.contents = image
479+
if layer?.isPreviousPreview == true {
480+
layer?.animateContents()
481+
layer?.isPreviousPreview = false
482+
}
463483
}
464484
}, release: {
465-
485+
466486
}, updateState: { [weak self] state in
467487
self?.updateState(state)
468488
}), key)
@@ -590,7 +610,7 @@ final class InlineStickerItemLayer : SimpleLayer {
590610
}
591611

592612
fetchDisposable.set(fetchedMediaResource(mediaBox: account.postbox.mediaBox, reference: mediaResource).start())
593-
613+
let shimmerColor = self.shimmerColor
594614
let fillColor: NSColor? = getColors?(file).first?.color
595615
let emptyColor: TransformImageEmptyColor?
596616
if let fillColor = fillColor {
@@ -612,28 +632,29 @@ final class InlineStickerItemLayer : SimpleLayer {
612632

613633

614634
let signal: Signal<ImageDataTransformation, NoError>
615-
635+
616636
switch file.mimeType {
617637
case "image/webp":
618638
signal = chatMessageSticker(postbox: account.postbox, file: reference, small: aspectSize.width <= 5, scale: System.backingScale, fetched: true)
619639
default:
620640
signal = chatMessageAnimatedSticker(postbox: account.postbox, file: reference, small: aspectSize.width <= 5, scale: System.backingScale, size: aspectSize, fetched: true, thumbAtFrame: 0, isVideo: file.fileName == "webm-preview" || file.isVideoSticker)
621641
}
622-
642+
623643
var result: TransformImageResult?
624644
_ = cachedMedia(media: file, arguments: arguments, scale: System.backingScale).start(next: { value in
625645
result = value
626646
})
627647
if self.playerState != .playing {
628648
self.contents = result?.image
629-
649+
630650
if let image = result?.image {
631651
self.preview = image
652+
self.isPreviousPreview = true
632653
}
633654
}
634655

635656

636-
if self.preview == nil, let data = file.immediateThumbnailData, self.playerState != .playing {
657+
if self.preview == nil, self.playerState != .playing {
637658

638659
let dataSignal = account.postbox.mediaBox.resourceData(mediaResource.resource)
639660
|> map { $0.complete }
@@ -649,10 +670,19 @@ final class InlineStickerItemLayer : SimpleLayer {
649670
current = ShimmerLayer()
650671
self?.addSublayer(current)
651672
self?.shimmer = current
652-
current.frame = size.bounds.focus(aspectSize)
653673
}
654-
current.update(backgroundColor: nil, foregroundColor: NSColor(rgb: 0x748391, alpha: 0.2), shimmeringColor: NSColor(rgb: 0x748391, alpha: 0.35), data: data, size: aspectSize)
655-
current.updateAbsoluteRect(size.bounds, within: aspectSize)
674+
675+
let data = shimmerColor.circle ? nil : file.immediateThumbnailData
676+
677+
let shimmerSize = aspectSize
678+
679+
current.update(backgroundColor: nil, foregroundColor: shimmerColor.color.withAlphaComponent(0.2), shimmeringColor: shimmerColor.color.withAlphaComponent(0.35), data: data, size: shimmerSize)
680+
current.updateAbsoluteRect(size.bounds, within: shimmerSize)
681+
682+
current.frame = size.bounds.focus(aspectSize)
683+
684+
self?.isPreviousPreview = true
685+
656686
} else {
657687
if let shimmer = self?.shimmer {
658688
shimmer.animateAlpha(from: 1, to: 0, duration: 0.2, removeOnCompletion: false, completion: { [weak shimmer] _ in
@@ -683,11 +713,15 @@ final class InlineStickerItemLayer : SimpleLayer {
683713
let fontImage = fontContext?.generateImage()
684714
return (TransformImageResult(image, context?.isHighQuality ?? false), TransformImageResult(fontImage, fontContext?.isHighQuality ?? false))
685715
} |> deliverOnMainQueue
686-
716+
687717
previewDisposable = result.start(next: { [weak self] result, fontResult in
688718
if self?.playerState != .playing {
689719
self?.contents = result.image
690720
}
721+
if self?.isPreviousPreview == true {
722+
self?.animateContents()
723+
self?.isPreviousPreview = false
724+
}
691725
if let image = result.image {
692726
self?.preview = image
693727
if let shimmer = self?.shimmer {
@@ -697,7 +731,7 @@ final class InlineStickerItemLayer : SimpleLayer {
697731
self?.shimmer = nil
698732
}
699733
}
700-
734+
701735
cacheMedia(fontResult, media: file, arguments: fontArguments, scale: System.backingScale)
702736
cacheMedia(result, media: file, arguments: arguments, scale: System.backingScale)
703737
})

0 commit comments

Comments
 (0)