@@ -64,6 +64,11 @@ class PostView: NSTableRowView {
64
64
$0. wantsLayer = true
65
65
$0. layer? . backgroundColor = Asset . barBoost. color. cgColor
66
66
}
67
+ let attachedMediaStackView = NSStackView ( views: [ ] ) ※ {
68
+ $0. orientation = . vertical
69
+ $0. spacing = 8
70
+ $0. setHuggingPriority ( . required, for: . vertical)
71
+ }
67
72
let guardTextField = NSTextField ( labelWithString: " \( L10n . Menu. post) → \( L10n . Menu. hidePrivatePosts) " )
68
73
69
74
init ( post: MastodonPost ) {
@@ -78,6 +83,7 @@ class PostView: NSTableRowView {
78
83
$0. setHuggingPriority ( . required, for: . vertical)
79
84
} ,
80
85
textView,
86
+ attachedMediaStackView,
81
87
] ) ※ {
82
88
$0. spacing = 4
83
89
$0. alignment = . leading
@@ -105,8 +111,9 @@ class PostView: NSTableRowView {
105
111
make. leading. equalTo ( iconView. snp. trailing) . offset ( 8 )
106
112
}
107
113
if post. originalPost. visibility != . public, post. originalPost. visibility != . unlisted {
108
- iconView. bind ( . hidden, to: NSUserDefaultsController . appGroup, withKeyPath: " values.hide_private_posts " , options: nil )
109
- stackView. bind ( . hidden, to: NSUserDefaultsController . appGroup, withKeyPath: " values.hide_private_posts " , options: nil )
114
+ for view in [ boostedPostIndicator, iconView, stackView] {
115
+ view. bind ( . hidden, to: NSUserDefaultsController . appGroup, withKeyPath: " values.hide_private_posts " , options: nil )
116
+ }
110
117
addSubview ( guardTextField)
111
118
guardTextField. snp. makeConstraints { make in
112
119
make. size. lessThanOrEqualToSuperview ( )
@@ -141,6 +148,18 @@ class PostView: NSTableRowView {
141
148
} else {
142
149
textView. textStorage? . setAttributedString ( NSAttributedString ( string: original. status, attributes: attributes) )
143
150
}
151
+ if original. attachments. count > 0 {
152
+ for media in original. attachments {
153
+ let imageView = AttachmentView ( attachment: media)
154
+ imageView. snp. makeConstraints { make in
155
+ make. height. equalTo ( 40 )
156
+ }
157
+ attachedMediaStackView. addArrangedSubview ( imageView)
158
+ }
159
+ attachedMediaStackView. isHidden = false
160
+ } else {
161
+ attachedMediaStackView. isHidden = true
162
+ }
144
163
}
145
164
146
165
override var isSelected : Bool {
@@ -166,3 +185,26 @@ class PostView: NSTableRowView {
166
185
}
167
186
}
168
187
}
188
+
189
+ class AttachmentView : LayeredImageView {
190
+ lazy var clickRecognizer = NSClickGestureRecognizer ( target: self , action: #selector( open) )
191
+ let attachment : MastodonAttachment
192
+
193
+ init ( attachment: MastodonAttachment ) {
194
+ self . attachment = attachment
195
+ super. init ( )
196
+ layer? . contentsGravity = . resizeAspectFill
197
+ loadImage ( url: URL ( string: attachment. previewUrl ?? " " ) )
198
+ addGestureRecognizer ( clickRecognizer)
199
+ }
200
+
201
+ required init ? ( coder: NSCoder ) {
202
+ fatalError ( " init(coder:) has not been implemented " )
203
+ }
204
+
205
+ @objc func open( ) {
206
+ if let url = URL ( string: attachment. url) {
207
+ NSWorkspace . shared. open ( url)
208
+ }
209
+ }
210
+ }
0 commit comments