Skip to content

Commit 84fc1eb

Browse files
committed
Update action
1 parent 71f534d commit 84fc1eb

14 files changed

+54
-93
lines changed

Mixin.xcodeproj/project.pbxproj

+4-13
Original file line numberDiff line numberDiff line change
@@ -625,7 +625,7 @@
625625
7CF9503F277D8839000AECC7 /* MediasPreviewViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7CF9503E277D8839000AECC7 /* MediasPreviewViewController.swift */; };
626626
7CF95041277D8904000AECC7 /* SelectedMediaCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7CF95040277D8904000AECC7 /* SelectedMediaCell.swift */; };
627627
7CFF1387277D5C3400FA745D /* MediasPreviewWindow.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7CFF1386277D5C3400FA745D /* MediasPreviewWindow.swift */; };
628-
7CFF1389277D5C6600FA745D /* MediaPreviewWindow.xib in Resources */ = {isa = PBXBuildFile; fileRef = 7CFF1388277D5C6600FA745D /* MediaPreviewWindow.xib */; };
628+
7CFF1389277D5C6600FA745D /* MediasPreviewWindow.xib in Resources */ = {isa = PBXBuildFile; fileRef = 7CFF1388277D5C6600FA745D /* MediasPreviewWindow.xib */; };
629629
811C8154F03C8CBB72DBA1F4 /* Pods_MixinShare.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 67A8E0E9B65F16ADB27E6F25 /* Pods_MixinShare.framework */; };
630630
842347EE2695BA6400009A39 /* InitializeBotJob.swift in Sources */ = {isa = PBXBuildFile; fileRef = 842347ED2695BA6400009A39 /* InitializeBotJob.swift */; };
631631
94046B91272DC265007C1D4A /* GroupCallMembersDataSource.swift in Sources */ = {isa = PBXBuildFile; fileRef = 94046B90272DC265007C1D4A /* GroupCallMembersDataSource.swift */; };
@@ -1619,7 +1619,7 @@
16191619
7CF9503E277D8839000AECC7 /* MediasPreviewViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MediasPreviewViewController.swift; sourceTree = "<group>"; };
16201620
7CF95040277D8904000AECC7 /* SelectedMediaCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SelectedMediaCell.swift; sourceTree = "<group>"; };
16211621
7CFF1386277D5C3400FA745D /* MediasPreviewWindow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MediasPreviewWindow.swift; sourceTree = "<group>"; };
1622-
7CFF1388277D5C6600FA745D /* MediaPreviewWindow.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = MediaPreviewWindow.xib; sourceTree = "<group>"; };
1622+
7CFF1388277D5C6600FA745D /* MediasPreviewWindow.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = MediasPreviewWindow.xib; sourceTree = "<group>"; };
16231623
842347ED2695BA6400009A39 /* InitializeBotJob.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InitializeBotJob.swift; sourceTree = "<group>"; };
16241624
8C43D9D96FCB101481DFD90F /* Pods-Mixin.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Mixin.release.xcconfig"; path = "Pods/Target Support Files/Pods-Mixin/Pods-Mixin.release.xcconfig"; sourceTree = "<group>"; };
16251625
94046B90272DC265007C1D4A /* GroupCallMembersDataSource.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GroupCallMembersDataSource.swift; sourceTree = "<group>"; };
@@ -2177,7 +2177,6 @@
21772177
94D63DD52646C29100FD7EE8 /* MessageViewModelFactory.swift */,
21782178
7CC7304F2745F95D002780F5 /* StickerStore.swift */,
21792179
7CF7416D27DAD93000DA0004 /* SnapCenterFlowLayout.swift */,
2180-
7C247AA6277AEDD100112A30 /* StackedPhotoLayout.swift */,
21812180
);
21822181
path = Model;
21832182
sourceTree = "<group>";
@@ -2568,13 +2567,6 @@
25682567
path = ReCaptcha;
25692568
sourceTree = "<group>";
25702569
};
2571-
7C0E1D0B2786E9F400762FBE /* Model */ = {
2572-
isa = PBXGroup;
2573-
children = (
2574-
);
2575-
path = Model;
2576-
sourceTree = "<group>";
2577-
};
25782570
7C35D1CF2689C04F002B5BBC /* Cells */ = {
25792571
isa = PBXGroup;
25802572
children = (
@@ -2933,7 +2925,6 @@
29332925
DF016B2C2098B35F00B8FFDE /* Windows */ = {
29342926
isa = PBXGroup;
29352927
children = (
2936-
7C0E1D0B2786E9F400762FBE /* Model */,
29372928
DF53BB6D202362A9002BF028 /* Cells */,
29382929
DF53BB6620233647002BF028 /* Views */,
29392930
DF43304422648B32006D971D /* AssetInfoWindow.swift */,
@@ -2973,7 +2964,7 @@
29732964
7C6132B527953B15002777EE /* DeleteAccountAbortWindow.swift */,
29742965
7C6132B727953B4F002777EE /* DeleteAccountAbortWindow.xib */,
29752966
7CFF1386277D5C3400FA745D /* MediasPreviewWindow.swift */,
2976-
7CFF1388277D5C6600FA745D /* MediaPreviewWindow.xib */,
2967+
7CFF1388277D5C6600FA745D /* MediasPreviewWindow.xib */,
29772968
);
29782969
path = Windows;
29792970
sourceTree = "<group>";
@@ -3933,7 +3924,7 @@
39333924
DF44B0CE20C6897D00A099B6 /* EmptyView.xib in Resources */,
39343925
277FF70C1F909A1200DBB2EB /* Assets.xcassets in Resources */,
39353926
7BF19C20241D40FA00B192D5 /* LocationSearchView.xib in Resources */,
3936-
7CFF1389277D5C6600FA745D /* MediaPreviewWindow.xib in Resources */,
3927+
7CFF1389277D5C6600FA745D /* MediasPreviewWindow.xib in Resources */,
39373928
7B8BB590234F36C000991ACB /* Colors.xcassets in Resources */,
39383929
94B8D18A266E41D300F43CBB /* DatabaseDiagnosticView.xib in Resources */,
39393930
7BFCB7762419FC5B00E7BC43 /* LocationCell.xib in Resources */,

Mixin/UserInterface/Controllers/Chat/Cells/PhotoInputGridCell.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class PhotoInputGridCell: UICollectionViewCell {
3535
overlayView.isHidden = true
3636
}
3737

38-
func updateSelectedIndex(_ index: Int?) {
38+
func updateBadge(with index: Int?) {
3939
if let index = index {
4040
badge.text = "\(index + 1)"
4141
badge.borderWidth = 0

Mixin/UserInterface/Controllers/Chat/Cells/SelectedMediaCell.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class SelectedMediaCell: UICollectionViewCell {
99
@IBOutlet weak var imageView: SDAnimatedImageView!
1010
@IBOutlet weak var mediaTypeView: MediaTypeOverlayView!
1111

12-
var onRemove: (() -> Void)?
12+
var deselectAsset: (() -> Void)?
1313

1414
private lazy var imageRequestOptions: PHImageRequestOptions = {
1515
let options = PHImageRequestOptions()
@@ -43,7 +43,7 @@ class SelectedMediaCell: UICollectionViewCell {
4343
}
4444

4545
@IBAction func closeAction(_ sender: Any) {
46-
onRemove?()
46+
deselectAsset?()
4747
}
4848

4949
}

Mixin/UserInterface/Controllers/Chat/ConversationViewController.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -1965,7 +1965,7 @@ extension ConversationViewController {
19651965
SendMessageService.shared.sendPinMessages(items: [message], conversationId: conversationId, action: .pin)
19661966
case .unpin:
19671967
dataSource.postponeMessagePinningUpdate(with: message.messageId)
1968-
SendMessageService.shared.sendPinMessages(items: [message], conversationId: conversationId, action: .pin)
1968+
SendMessageService.shared.sendPinMessages(items: [message], conversationId: conversationId, action: .unpin)
19691969
}
19701970
}
19711971

Mixin/UserInterface/Controllers/Chat/MediasPreviewViewController.swift

+10-8
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,13 @@ final class MediasPreviewViewController: UIViewController {
3737
extension MediasPreviewViewController {
3838

3939
func add(_ asset: PHAsset) {
40+
guard !assets.contains(asset) else {
41+
return
42+
}
4043
assets.append(asset)
41-
collectionView.insertItems(at: [IndexPath(item: assets.count - 1, section: 0)])
42-
collectionView.scrollToItem(at: IndexPath(item: assets.count - 1, section: 0),
43-
at: .centeredHorizontally,
44-
animated: true)
44+
let index = IndexPath(item: assets.count - 1, section: 0)
45+
collectionView.insertItems(at: [index])
46+
collectionView.scrollToItem(at: index, at: .centeredHorizontally, animated: true)
4547
}
4648

4749
func remove(_ asset: PHAsset) {
@@ -78,7 +80,7 @@ extension MediasPreviewViewController: UICollectionViewDataSource {
7880
if indexPath.item < assets.count {
7981
let asset = assets[indexPath.item]
8082
cell.load(asset: asset, size: cellSizeForItemAt(indexPath.item))
81-
cell.onRemove = { [weak self] in
83+
cell.deselectAsset = { [weak self] in
8284
guard let self = self else {
8385
return
8486
}
@@ -117,13 +119,13 @@ extension MediasPreviewViewController {
117119
let width: CGFloat
118120
let ratio = CGFloat(asset.pixelWidth) / CGFloat(asset.pixelHeight)
119121
if ratio > 1 {
120-
width = height / 3 * 4
122+
width = ceil(height / 3 * 4)
121123
} else if ratio < 1 {
122-
width = height / 4 * 3
124+
width = ceil(height / 4 * 3)
123125
} else {
124126
width = height
125127
}
126-
let size = CGSize(width: ceil(width), height: ceil(height))
128+
let size = CGSize(width: width, height: height)
127129
cellSizeCache[asset.localIdentifier] = size
128130
return size
129131
}

Mixin/UserInterface/Controllers/Chat/Model/ConversationDataSource.swift

-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ class ConversationDataSource {
4747
private var messageProcessingIsCancelled = false
4848
private var didInitializedData = false
4949
private var pendingPinningUpdateMessageId: String?
50-
private var stackedPhotoMessages = [MessageItem]()
5150

5251
var layoutSize: CGSize {
5352
Queue.main.autoSync {

Mixin/UserInterface/Controllers/Chat/PhotoInputGridViewController.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ extension PhotoInputGridViewController: UICollectionViewDataSource {
139139
cell.imageView.contentMode = .scaleAspectFill
140140
cell.imageView.backgroundColor = .background
141141
cell.badge.isHidden = false
142-
cell.updateSelectedIndex(selectedAssets.firstIndex(of: asset))
142+
cell.updateBadge(with: selectedAssets.firstIndex(of: asset))
143143
imageManager.requestImage(for: asset, targetSize: thumbnailSize, contentMode: .aspectFill, options: imageRequestOptions) { [weak cell] (image, _) in
144144
guard let cell = cell, cell.identifier == asset.localIdentifier else {
145145
return

Mixin/UserInterface/Controllers/Chat/PhotoInputViewController.swift

+13-13
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class PhotoInputViewController: UIViewController, ConversationInputAccessible {
2222
}
2323

2424
private weak var mediasPreviewControllerIfLoaded: MediasPreviewViewController?
25-
private lazy var mediasPreviewViewController: MediasPreviewViewController = {
25+
private lazy var mediasPreviewController: MediasPreviewViewController = {
2626
let controller = R.storyboard.chat.selected_medias()!
2727
controller.delegate = self
2828
mediasPreviewControllerIfLoaded = controller
@@ -235,14 +235,14 @@ extension PhotoInputViewController: PhotoInputGridViewControllerDelegate {
235235
if !controller.selectedAssets.isEmpty {
236236
presentMediasPreviewControllerAnimated()
237237
}
238-
mediasPreviewViewController.add(asset)
238+
mediasPreviewController.add(asset)
239239
}
240240

241241
func photoInputGridViewController(_ controller: PhotoInputGridViewController, didDeselect asset: PHAsset) {
242242
if controller.selectedAssets.isEmpty {
243243
dismissMediasPreviewControllerAnimated()
244244
} else {
245-
mediasPreviewViewController.remove(asset)
245+
mediasPreviewController.remove(asset)
246246
}
247247
}
248248

@@ -282,21 +282,21 @@ extension PhotoInputViewController: MediasPreviewViewControllerDelegate {
282282

283283
extension PhotoInputViewController: MediasPreviewWindowDelegate {
284284

285-
func mediasPreviewWindow(_ window: MediasPreviewWindow, willDismiss assets: [PHAsset]) {
285+
func mediasPreviewWindow(_ window: MediasPreviewWindow, willDismissWindow assets: [PHAsset]) {
286286
if assets.isEmpty {
287287
gridViewController.deselectAll()
288288
dismissMediasPreviewControllerAnimated()
289289
} else {
290290
gridViewController.updateSelectdAssets(assets)
291-
mediasPreviewViewController.updateAssets(assets)
291+
mediasPreviewController.updateAssets(assets)
292292
}
293293
}
294294

295-
func mediasPreviewWindow(_ window: MediasPreviewWindow, didSendItems assets: [PHAsset]) {
295+
func mediasPreviewWindow(_ window: MediasPreviewWindow, didTapSendItems assets: [PHAsset]) {
296296
sendItems(assets: assets)
297297
}
298298

299-
func mediasPreviewWindow(_ window: MediasPreviewWindow, didSendFiles assets: [PHAsset]) {
299+
func mediasPreviewWindow(_ window: MediasPreviewWindow, didTapSendFiles assets: [PHAsset]) {
300300
sendAsFiles(assets: assets)
301301
}
302302

@@ -345,16 +345,16 @@ extension PhotoInputViewController {
345345

346346
private func presentMediasPreviewControllerAnimated() {
347347
guard
348-
mediasPreviewViewController.parent == nil,
348+
mediasPreviewController.parent == nil,
349349
let conversationInputViewController = conversationInputViewController,
350350
let inputBarView = conversationInputViewController.inputBarView,
351351
let conversationViewController = conversationInputViewController.parent
352352
else {
353353
return
354354
}
355355
gridViewController.view.isUserInteractionEnabled = false
356-
let previewController = mediasPreviewViewController
357-
let previewViewHeight = mediasPreviewViewController.viewHeight
356+
let previewController = mediasPreviewController
357+
let previewViewHeight = mediasPreviewController.viewHeight
358358
addChild(previewController)
359359
view.insertSubview(previewController.view, at: 0)
360360
previewController.view.snp.makeConstraints({ (make) in
@@ -380,15 +380,15 @@ extension PhotoInputViewController {
380380

381381
private func dismissMediasPreviewControllerAnimated() {
382382
guard
383-
mediasPreviewViewController.parent != nil,
383+
mediasPreviewController.parent != nil,
384384
let conversationInputViewController = conversationInputViewController,
385385
let inputBarView = conversationInputViewController.inputBarView
386386
else {
387387
return
388388
}
389389
gridViewController.view.isUserInteractionEnabled = false
390-
let previewController = mediasPreviewViewController
391-
let previewViewHeight = mediasPreviewViewController.viewHeight
390+
let previewController = mediasPreviewController
391+
let previewViewHeight = mediasPreviewController.viewHeight
392392
addChild(previewController)
393393
view.insertSubview(previewController.view, at: 0)
394394
previewController.view.snp.remakeConstraints({ (make) in

Mixin/UserInterface/Controllers/Chat/PinMessagesPreviewViewController.swift

+6
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ final class PinMessagesPreviewViewController: StaticMessagesViewController {
1919
private var ignoresPinMessageChangeNotification = false
2020
private var canUnpinMessages = false
2121

22+
private var layoutWidth: CGFloat {
23+
Queue.main.autoSync {
24+
AppDelegate.current.mainWindow.bounds.width
25+
}
26+
}
27+
2228
private weak var bottomBarViewIfAdded: UIView?
2329

2430
init(conversationId: String, isGroup: Bool) {

Mixin/UserInterface/Controllers/Chat/StaticMessagesViewController.swift

+3-36
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,6 @@ class StaticMessagesViewController: UIViewController {
1717

1818
var dates: [String] = []
1919
var viewModels: [String: [MessageViewModel]] = [:]
20-
var layoutWidth: CGFloat {
21-
Queue.main.autoSync {
22-
AppDelegate.current.mainWindow.bounds.width
23-
}
24-
}
2520

2621
private let conversationId: String
2722
private let audioManager: StaticAudioMessagePlayingManager
@@ -184,41 +179,12 @@ class StaticMessagesViewController: UIViewController {
184179
}
185180
}
186181

187-
func removeViewModel(at indexPath: IndexPath) -> (didRemoveRow: Bool, didRemoveSection: Bool) {
188-
var didRemoveRow = false
189-
var didRemoveSection = false
190-
let date = dates[indexPath.section]
191-
if let _ = viewModels[date]?.remove(at: indexPath.row) {
192-
didRemoveRow = true
193-
}
194-
if let viewModels = viewModels[date], viewModels.isEmpty {
195-
if let index = dates.firstIndex(of: date) {
196-
didRemoveSection = true
197-
dates.remove(at: index)
198-
}
199-
self.viewModels[date] = nil
200-
}
201-
if let viewModels = self.viewModels[date] {
202-
let indexBeforeDeletedMessage = indexPath.row - 1
203-
let indexAfterDeletedMessage = indexPath.row
204-
if indexBeforeDeletedMessage >= 0 {
205-
let style = factory.style(forIndex: indexBeforeDeletedMessage, viewModels: viewModels)
206-
self.viewModels[date]?[indexBeforeDeletedMessage].style = style
207-
}
208-
if indexAfterDeletedMessage < viewModels.count {
209-
let style = factory.style(forIndex: indexAfterDeletedMessage, viewModels: viewModels)
210-
self.viewModels[date]?[indexAfterDeletedMessage].style = style
211-
}
212-
}
213-
return (didRemoveRow, didRemoveSection)
214-
}
215-
216182
}
217183

218184
// MARK: - Actions
219185
extension StaticMessagesViewController {
220186

221-
@objc func tapAction(_ recognizer: UIGestureRecognizer) {
187+
@objc private func tapAction(_ recognizer: UIGestureRecognizer) {
222188
let tappedIndexPath = tableView.indexPathForRow(at: recognizer.location(in: tableView))
223189
let tappedViewModel: MessageViewModel? = {
224190
if let indexPath = tappedIndexPath {
@@ -588,9 +554,10 @@ extension StaticMessagesViewController {
588554
return
589555
}
590556
DispatchQueue.main.sync {
557+
let layoutWidth = AppDelegate.current.mainWindow.bounds.width
591558
let date = DateFormatter.yyyymmdd.string(from: message.createdAt.toUTCDate())
592559
if let style = self.viewModels[date]?[indexPath.row].style {
593-
let viewModel = self.factory.viewModel(withMessage: message, style: style, fits: self.layoutWidth)
560+
let viewModel = self.factory.viewModel(withMessage: message, style: style, fits: layoutWidth)
594561
self.viewModels[date]?[indexPath.row] = viewModel
595562
self.tableView.reloadData()
596563
}

Mixin/UserInterface/Controllers/Chat/TranscriptPreviewViewController.swift

+2-1
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ extension TranscriptPreviewViewController {
143143
}
144144

145145
private func reloadData() {
146+
let layoutWidth = AppDelegate.current.mainWindow.bounds.width
146147
queue.async { [weak self] in
147148
guard let self = self else {
148149
return
@@ -152,7 +153,7 @@ extension TranscriptPreviewViewController {
152153
let children = items.compactMap { item in
153154
TranscriptMessage(transcriptId: transcriptId, mediaUrl: item.mediaUrl, thumbImage: item.thumbImage, messageItem: item)
154155
}
155-
let (dates, viewModels) = self.categorizedViewModels(with: items, fits: self.layoutWidth)
156+
let (dates, viewModels) = self.categorizedViewModels(with: items, fits: layoutWidth)
156157
DispatchQueue.main.async {
157158
self.childMessages = children
158159
self.dates = dates

Mixin/UserInterface/Windows/Cells/MediaPreviewCell.xib

+2-7
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="19529" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="20037" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
33
<device id="retina6_1" orientation="portrait" appearance="light"/>
44
<dependencies>
55
<deployment identifier="iOS"/>
6-
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="19519"/>
6+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="20020"/>
77
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
88
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
99
</dependencies>
@@ -23,11 +23,6 @@
2323
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="MqO-Z8-zEn" customClass="MediaTypeOverlayView" customModule="Mixin" customModuleProvider="target">
2424
<rect key="frame" x="0.0" y="0.0" width="312" height="312"/>
2525
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
26-
<userDefinedRuntimeAttributes>
27-
<userDefinedRuntimeAttribute type="number" keyPath="typeViewBottomSpace">
28-
<real key="value" value="1"/>
29-
</userDefinedRuntimeAttribute>
30-
</userDefinedRuntimeAttributes>
3126
</view>
3227
<imageView clipsSubviews="YES" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="ic_photo_checkmark" translatesAutoresizingMaskIntoConstraints="NO" id="qiu-YU-Oii">
3328
<rect key="frame" x="278" y="278" width="28" height="28"/>

0 commit comments

Comments
 (0)