Skip to content

Commit c08b7d4

Browse files
committed
Update action
1 parent 71f534d commit c08b7d4

16 files changed

+114
-221
lines changed

Mixin.xcodeproj/project.pbxproj

Lines changed: 4 additions & 13 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 47 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,7 @@ class ConversationViewController: UIViewController {
105105
private(set) lazy var imagePickerController = ImagePickerController(initialCameraPosition: .rear, cropImageAfterPicked: false, parent: self, delegate: self)
106106

107107
private lazy var userHandleViewController = R.storyboard.chat.user_handle()!
108-
private lazy var multipleSelectionActionView: MultipleSelectionActionView = {
109-
let view = R.nib.multipleSelectionActionView(owner: self)!
110-
view.delegate = self
111-
view.showCancelButton = false
112-
return view
113-
}()
108+
private lazy var multipleSelectionActionView = R.nib.multipleSelectionActionView(owner: self)!
114109
private lazy var announcementBadgeContentView = R.nib.announcementBadgeContentView(owner: self)!
115110

116111
private lazy var strangerHintView: StrangerHintView = {
@@ -521,6 +516,51 @@ class ConversationViewController: UIViewController {
521516
}
522517
}
523518

519+
@IBAction func multipleSelectionAction(_ sender: Any) {
520+
switch multipleSelectionActionView.intent {
521+
case .forward:
522+
let messages = dataSource.selectedViewModels.values
523+
.map({ $0.message })
524+
.sorted(by: { $0.createdAt < $1.createdAt })
525+
let containsTranscriptMessage = messages.contains {
526+
$0.category.hasSuffix("_TRANSCRIPT")
527+
}
528+
if messages.count == 1 || containsTranscriptMessage {
529+
let vc = MessageReceiverViewController.instance(content: .messages(messages))
530+
navigationController?.pushViewController(vc, animated: true)
531+
} else {
532+
let alert = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet)
533+
alert.addAction(UIAlertAction(title: R.string.localizable.chat_forward_one_by_one(), style: .default, handler: { (_) in
534+
let vc = MessageReceiverViewController.instance(content: .messages(messages))
535+
self.navigationController?.pushViewController(vc, animated: true)
536+
}))
537+
alert.addAction(UIAlertAction(title: R.string.localizable.chat_forward_combined(), style: .default, handler: { (_) in
538+
let vc = MessageReceiverViewController.instance(content: .transcript(messages))
539+
self.navigationController?.pushViewController(vc, animated: true)
540+
}))
541+
alert.addAction(UIAlertAction(title: R.string.localizable.dialog_button_cancel(), style: .cancel, handler: nil))
542+
present(alert, animated: true, completion: nil)
543+
}
544+
case .delete:
545+
let viewModels = dataSource.selectedViewModels.values.map({ $0 })
546+
let controller = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet)
547+
if !viewModels.contains(where: { $0.message.userId != myUserId || !$0.message.canRecall }) {
548+
controller.addAction(UIAlertAction(title: Localized.ACTION_DELETE_EVERYONE, style: .destructive, handler: { (_) in
549+
if AppGroupUserDefaults.User.hasShownRecallTips {
550+
self.deleteForEveryone(viewModels: viewModels)
551+
} else {
552+
self.showRecallTips(viewModels: viewModels)
553+
}
554+
}))
555+
}
556+
controller.addAction(UIAlertAction(title: Localized.ACTION_DELETE_ME, style: .destructive, handler: { (_) in
557+
self.deleteForMe(viewModels: viewModels)
558+
}))
559+
controller.addAction(UIAlertAction(title: Localized.DIALOG_BUTTON_CANCEL, style: .cancel, handler: nil))
560+
self.present(controller, animated: true, completion: nil)
561+
}
562+
}
563+
524564
@IBAction func dismissAnnouncementBadgeAction(_ sender: Any) {
525565
if dataSource.category == .group {
526566
AppGroupUserDefaults.User.hasUnreadAnnouncement.removeValue(forKey: conversationId)
@@ -1299,55 +1339,6 @@ class ConversationViewController: UIViewController {
12991339

13001340
}
13011341

1302-
extension ConversationViewController: MultipleSelectionActionViewDelegate {
1303-
1304-
func multipleSelectionActionViewDidTapAction(_ view: MultipleSelectionActionView) {
1305-
switch view.intent {
1306-
case .forward:
1307-
let messages = dataSource.selectedViewModels.values
1308-
.map({ $0.message })
1309-
.sorted(by: { $0.createdAt < $1.createdAt })
1310-
let containsTranscriptMessage = messages.contains {
1311-
$0.category.hasSuffix("_TRANSCRIPT")
1312-
}
1313-
if messages.count == 1 || containsTranscriptMessage {
1314-
let vc = MessageReceiverViewController.instance(content: .messages(messages))
1315-
navigationController?.pushViewController(vc, animated: true)
1316-
} else {
1317-
let alert = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet)
1318-
alert.addAction(UIAlertAction(title: R.string.localizable.chat_forward_one_by_one(), style: .default, handler: { (_) in
1319-
let vc = MessageReceiverViewController.instance(content: .messages(messages))
1320-
self.navigationController?.pushViewController(vc, animated: true)
1321-
}))
1322-
alert.addAction(UIAlertAction(title: R.string.localizable.chat_forward_combined(), style: .default, handler: { (_) in
1323-
let vc = MessageReceiverViewController.instance(content: .transcript(messages))
1324-
self.navigationController?.pushViewController(vc, animated: true)
1325-
}))
1326-
alert.addAction(UIAlertAction(title: R.string.localizable.dialog_button_cancel(), style: .cancel, handler: nil))
1327-
present(alert, animated: true, completion: nil)
1328-
}
1329-
case .delete:
1330-
let viewModels = dataSource.selectedViewModels.values.map({ $0 })
1331-
let controller = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet)
1332-
if !viewModels.contains(where: { $0.message.userId != myUserId || !$0.message.canRecall }) {
1333-
controller.addAction(UIAlertAction(title: Localized.ACTION_DELETE_EVERYONE, style: .destructive, handler: { (_) in
1334-
if AppGroupUserDefaults.User.hasShownRecallTips {
1335-
self.deleteForEveryone(viewModels: viewModels)
1336-
} else {
1337-
self.showRecallTips(viewModels: viewModels)
1338-
}
1339-
}))
1340-
}
1341-
controller.addAction(UIAlertAction(title: Localized.ACTION_DELETE_ME, style: .destructive, handler: { (_) in
1342-
self.deleteForMe(viewModels: self.dataSource.selectedViewModels.values.map({ $0 }))
1343-
}))
1344-
controller.addAction(UIAlertAction(title: Localized.DIALOG_BUTTON_CANCEL, style: .cancel, handler: nil))
1345-
self.present(controller, animated: true, completion: nil)
1346-
}
1347-
}
1348-
1349-
}
1350-
13511342
// MARK: - UIGestureRecognizerDelegate
13521343
extension ConversationViewController: UIGestureRecognizerDelegate {
13531344

@@ -1965,7 +1956,7 @@ extension ConversationViewController {
19651956
SendMessageService.shared.sendPinMessages(items: [message], conversationId: conversationId, action: .pin)
19661957
case .unpin:
19671958
dataSource.postponeMessagePinningUpdate(with: message.messageId)
1968-
SendMessageService.shared.sendPinMessages(items: [message], conversationId: conversationId, action: .pin)
1959+
SendMessageService.shared.sendPinMessages(items: [message], conversationId: conversationId, action: .unpin)
19691960
}
19701961
}
19711962

Mixin/UserInterface/Controllers/Chat/MediasPreviewViewController.swift

Lines changed: 10 additions & 8 deletions
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

Lines changed: 0 additions & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

0 commit comments

Comments
 (0)