Slowmode fixes

This commit is contained in:
Peter 2019-07-25 19:42:01 +01:00
parent 89da2e7a3d
commit e1728a62b5
15 changed files with 2570 additions and 2569 deletions

View File

@ -4484,6 +4484,7 @@ Any member of this group will be able to see messages in the channel.";
"Chat.AttachmentLimitExceeded" = "Slowmode is enabled. You can't select more items."; "Chat.AttachmentLimitExceeded" = "Slowmode is enabled. You can't select more items.";
"Chat.AttachmentMultipleFilesDisabled" = "Slowmode is enabled. You can't send multiple files at once."; "Chat.AttachmentMultipleFilesDisabled" = "Slowmode is enabled. You can't send multiple files at once.";
"Chat.AttachmentMultipleForwardDisabled" = "Slowmode is enabled. You can't forward multiple messages at once."; "Chat.AttachmentMultipleForwardDisabled" = "Slowmode is enabled. You can't forward multiple messages at once.";
"Chat.MultipleTextMessagesDisabled" = "Slowmode is enabled. You can't send multiple messages at once.";
"StickerPacksSettings.AnimatedStickersInfo" = "Animated stickers in a chat will play continuously."; "StickerPacksSettings.AnimatedStickersInfo" = "Animated stickers in a chat will play continuously.";
"Appearance.ThemePreview.ChatList.1.Name" = "Eva Summer"; "Appearance.ThemePreview.ChatList.1.Name" = "Eva Summer";

View File

@ -153,7 +153,7 @@ const NSUInteger TGAttachmentDisplayedAssetLimit = 500;
} }
}; };
if (allowGrouping) if (allowGrouping)
_selectionContext.grouping = ![[[NSUserDefaults standardUserDefaults] objectForKey:@"TG_mediaGroupingDisabled_v0"] boolValue]; _selectionContext.grouping = true;
[_selectionContext setItemSourceUpdatedSignal:[_assetsLibrary libraryChanged]]; [_selectionContext setItemSourceUpdatedSignal:[_assetsLibrary libraryChanged]];
_selectionContext.updatedItemsSignal = ^SSignal *(NSArray *items) _selectionContext.updatedItemsSignal = ^SSignal *(NSArray *items)
{ {

View File

@ -1175,7 +1175,7 @@ static CGPoint TGCameraControllerClampPointToScreenSize(__unused id self, __unus
{ {
selectionContext = [[TGMediaSelectionContext alloc] initWithGroupingAllowed:self.allowGrouping selectionLimit:30]; selectionContext = [[TGMediaSelectionContext alloc] initWithGroupingAllowed:self.allowGrouping selectionLimit:30];
if (self.allowGrouping) if (self.allowGrouping)
selectionContext.grouping = ![[[NSUserDefaults standardUserDefaults] objectForKey:@"TG_mediaGroupingDisabled_v0"] boolValue]; selectionContext.grouping = true;
_selectionContext = selectionContext; _selectionContext = selectionContext;
} }

View File

@ -243,7 +243,7 @@
__weak TGMediaAssetsController *weakSelf = self; __weak TGMediaAssetsController *weakSelf = self;
_selectionContext = [[TGMediaSelectionContext alloc] initWithGroupingAllowed:allowGrouping selectionLimit:selectionLimit]; _selectionContext = [[TGMediaSelectionContext alloc] initWithGroupingAllowed:allowGrouping selectionLimit:selectionLimit];
if (allowGrouping) if (allowGrouping)
_selectionContext.grouping = ![[[NSUserDefaults standardUserDefaults] objectForKey:@"TG_mediaGroupingDisabled_v0"] boolValue]; _selectionContext.grouping = true;
_selectionContext.selectionLimitExceeded = ^{ _selectionContext.selectionLimitExceeded = ^{
__strong TGMediaAssetsController *strongSelf = weakSelf; __strong TGMediaAssetsController *strongSelf = weakSelf;
if (strongSelf == nil) if (strongSelf == nil)

View File

@ -229,7 +229,7 @@
if (_selectionContext.allowGrouping) if (_selectionContext.allowGrouping)
{ {
_groupButton = [[TGMediaPickerGroupButton alloc] initWithFrame:CGRectMake(0, 0, 38.0f, 38.0f)]; /*_groupButton = [[TGMediaPickerGroupButton alloc] initWithFrame:CGRectMake(0, 0, 38.0f, 38.0f)];
[_groupButton setHidden:true animated:false]; [_groupButton setHidden:true animated:false];
_groupButton.selected = _selectionContext.grouping; _groupButton.selected = _selectionContext.grouping;
[_groupButton addTarget:self action:@selector(toggleGrouping) forControlEvents:UIControlEventTouchUpInside]; [_groupButton addTarget:self action:@selector(toggleGrouping) forControlEvents:UIControlEventTouchUpInside];
@ -240,7 +240,7 @@
__strong TGMediaPickerGalleryInterfaceView *strongSelf = weakSelf; __strong TGMediaPickerGalleryInterfaceView *strongSelf = weakSelf;
if (strongSelf != nil) if (strongSelf != nil)
[strongSelf->_groupButton setSelected:next.boolValue]; [strongSelf->_groupButton setSelected:next.boolValue];
}]; }];*/
if (_editingContext != nil) if (_editingContext != nil)
{ {

View File

@ -21,6 +21,8 @@
@property (nonatomic, readonly) bool knobStartedDragging; @property (nonatomic, readonly) bool knobStartedDragging;
@property (nonatomic) bool limitValueChangedToLatestState;
@property (nonatomic, assign) CGFloat knobPadding; @property (nonatomic, assign) CGFloat knobPadding;
@property (nonatomic, assign) CGFloat lineSize; @property (nonatomic, assign) CGFloat lineSize;
@property (nonatomic, strong) UIColor *backColor; @property (nonatomic, strong) UIColor *backColor;

View File

@ -602,7 +602,9 @@ const CGFloat TGPhotoEditorSliderViewInternalMargin = 7.0f;
} }
[self setNeedsLayout]; [self setNeedsLayout];
[self sendActionsForControlEvents:UIControlEventValueChanged]; if (!_limitValueChangedToLatestState) {
[self sendActionsForControlEvents:UIControlEventValueChanged];
}
return true; return true;
} }

View File

@ -450,7 +450,6 @@ public func channelPermissionsController(context: AccountContext, peerId: PeerId
var presentControllerImpl: ((ViewController, Any?) -> Void)? var presentControllerImpl: ((ViewController, Any?) -> Void)?
var pushControllerImpl: ((ViewController) -> Void)? var pushControllerImpl: ((ViewController) -> Void)?
var cancelSlowmodeDraggingImpl: (() -> Void)?
let actionsDisposable = DisposableSet() let actionsDisposable = DisposableSet()
@ -648,8 +647,6 @@ public func channelPermissionsController(context: AccountContext, peerId: PeerId
updateDefaultRightsDisposable.set(updateChannelSlowModeInteractively(postbox: context.account.postbox, network: context.account.network, accountStateManager: context.account.stateManager, peerId: peerId, timeout: modifiedSlowmodeTimeout == 0 ? nil : value).start()) updateDefaultRightsDisposable.set(updateChannelSlowModeInteractively(postbox: context.account.postbox, network: context.account.network, accountStateManager: context.account.stateManager, peerId: peerId, timeout: modifiedSlowmodeTimeout == 0 ? nil : value).start())
} }
} else if let _ = view.peers[peerId] as? TelegramGroup, let _ = view.cachedData as? CachedGroupData { } else if let _ = view.peers[peerId] as? TelegramGroup, let _ = view.cachedData as? CachedGroupData {
cancelSlowmodeDraggingImpl?()
updateState { state in updateState { state in
var state = state var state = state
state.modifiedSlowmodeTimeout = value state.modifiedSlowmodeTimeout = value
@ -767,16 +764,6 @@ public func channelPermissionsController(context: AccountContext, peerId: PeerId
(controller.navigationController as? NavigationController)?.pushViewController(c) (controller.navigationController as? NavigationController)?.pushViewController(c)
} }
} }
cancelSlowmodeDraggingImpl = { [weak controller] in
guard let controller = controller else {
return
}
controller.forEachItemNode { itemNode in
if let itemNode = itemNode as? ChatSlowmodeItemNode {
itemNode.cancelDragging()
}
}
}
upgradedToSupergroupImpl = { [weak controller] upgradedPeerId, f in upgradedToSupergroupImpl = { [weak controller] upgradedPeerId, f in
guard let controller = controller, let navigationController = controller.navigationController as? NavigationController else { guard let controller = controller, let navigationController = controller.navigationController as? NavigationController else {
return return

View File

@ -2391,20 +2391,30 @@ public final class ChatController: TelegramController, GalleryHiddenMediaTarget,
} }
} }
self.chatDisplayNode.sendMessages = { [weak self] messages in self.chatDisplayNode.sendMessages = { [weak self] messages, isAnyMessageTextPartitioned in
if let strongSelf = self, case let .peer(peerId) = strongSelf.chatLocation { if let strongSelf = self, case let .peer(peerId) = strongSelf.chatLocation {
strongSelf.commitPurposefulAction() strongSelf.commitPurposefulAction()
let forwardCount = messages.reduce(0, { count, message -> Int in if let channel = strongSelf.presentationInterfaceState.renderedPeer?.peer as? TelegramChannel, channel.isRestrictedBySlowmode {
if case .forward = message { let forwardCount = messages.reduce(0, { count, message -> Int in
return count + 1 if case .forward = message {
} else { return count + 1
return count } else {
return count
}
})
var errorText: String?
if forwardCount > 1 {
errorText = strongSelf.presentationData.strings.Chat_AttachmentMultipleForwardDisabled
} else if isAnyMessageTextPartitioned {
errorText = strongSelf.presentationData.strings.Chat_MultipleTextMessagesDisabled
}
if let errorText = errorText {
strongSelf.present(standardTextAlertController(theme: AlertControllerTheme(presentationTheme: strongSelf.presentationData.theme), title: nil, text: errorText, actions: [TextAlertAction(type: .defaultAction, title: strongSelf.presentationData.strings.Common_OK, action: {})]), in: .window(.root))
return
} }
})
if let channel = strongSelf.presentationInterfaceState.renderedPeer?.peer as? TelegramChannel, channel.isRestrictedBySlowmode, forwardCount > 1 {
strongSelf.present(standardTextAlertController(theme: AlertControllerTheme(presentationTheme: strongSelf.presentationData.theme), title: nil, text: strongSelf.presentationData.strings.Chat_AttachmentMultipleForwardDisabled, actions: [TextAlertAction(type: .defaultAction, title: strongSelf.presentationData.strings.Common_OK, action: {})]), in: .window(.root))
return
} }
let _ = (enqueueMessages(account: strongSelf.context.account, peerId: peerId, messages: strongSelf.transformEnqueueMessages(messages)) let _ = (enqueueMessages(account: strongSelf.context.account, peerId: peerId, messages: strongSelf.transformEnqueueMessages(messages))
@ -2430,7 +2440,7 @@ public final class ChatController: TelegramController, GalleryHiddenMediaTarget,
guard let strongSelf = self else { guard let strongSelf = self else {
return return
} }
if let _ = strongSelf.presentationInterfaceState.slowmodeState { if strongSelf.presentationInterfaceState.interfaceState.editMessage == nil, let _ = strongSelf.presentationInterfaceState.slowmodeState {
if let rect = strongSelf.chatDisplayNode.frameForAttachmentButton() { if let rect = strongSelf.chatDisplayNode.frameForAttachmentButton() {
strongSelf.interfaceInteraction?.displaySlowmodeTooltip(strongSelf.chatDisplayNode, rect) strongSelf.interfaceInteraction?.displaySlowmodeTooltip(strongSelf.chatDisplayNode, rect)
} }

View File

@ -127,7 +127,7 @@ class ChatControllerNode: ASDisplayNode, UIScrollViewDelegate {
var requestUpdateChatInterfaceState: (Bool, Bool, (ChatInterfaceState) -> ChatInterfaceState) -> Void = { _, _, _ in } var requestUpdateChatInterfaceState: (Bool, Bool, (ChatInterfaceState) -> ChatInterfaceState) -> Void = { _, _, _ in }
var requestUpdateInterfaceState: (ContainedViewLayoutTransition, Bool, (ChatPresentationInterfaceState) -> ChatPresentationInterfaceState) -> Void = { _, _, _ in } var requestUpdateInterfaceState: (ContainedViewLayoutTransition, Bool, (ChatPresentationInterfaceState) -> ChatPresentationInterfaceState) -> Void = { _, _, _ in }
var sendMessages: ([EnqueueMessage]) -> Void = { _ in } var sendMessages: ([EnqueueMessage], Bool) -> Void = { _, _ in }
var displayAttachmentMenu: () -> Void = { } var displayAttachmentMenu: () -> Void = { }
var paste: (ChatTextInputPanelPasteData) -> Void = { _ in } var paste: (ChatTextInputPanelPasteData) -> Void = { _ in }
var updateTypingActivity: (Bool) -> Void = { _ in } var updateTypingActivity: (Bool) -> Void = { _ in }
@ -345,7 +345,7 @@ class ChatControllerNode: ASDisplayNode, UIScrollViewDelegate {
} }
if case .peer = strongSelf.chatLocation { if case .peer = strongSelf.chatLocation {
strongSelf.sendMessages(messages) strongSelf.sendMessages(messages, messages.count > 1)
} }
} }
} }

View File

@ -128,6 +128,7 @@ class ChatSlowmodeItemNode: ListViewItemNode {
self.view.disablesInteractiveTransitionGestureRecognizer = true self.view.disablesInteractiveTransitionGestureRecognizer = true
let sliderView = TGPhotoEditorSliderView() let sliderView = TGPhotoEditorSliderView()
sliderView.limitValueChangedToLatestState = true
sliderView.enablePanHandling = true sliderView.enablePanHandling = true
sliderView.trackCornerRadius = 1.0 sliderView.trackCornerRadius = 1.0
sliderView.lineSize = 2.0 sliderView.lineSize = 2.0
@ -299,9 +300,4 @@ class ChatSlowmodeItemNode: ListViewItemNode {
item.updated(value) item.updated(value)
} }
} }
func cancelDragging() {
self.sliderView?.cancelTracking(with: nil)
}
} }

View File

@ -608,11 +608,13 @@ class ChatTextInputPanelNode: ChatInputPanelNode, ASEditableTextNodeDelegate {
var isSlowmodeActive = false var isSlowmodeActive = false
if interfaceState.slowmodeState != nil { if interfaceState.slowmodeState != nil {
isSlowmodeActive = true isSlowmodeActive = true
isMediaEnabled = false if !isEditingMedia {
isMediaEnabled = false
}
} }
transition.updateAlpha(layer: self.attachmentButton.layer, alpha: isMediaEnabled ? 1.0 : 0.4) transition.updateAlpha(layer: self.attachmentButton.layer, alpha: isMediaEnabled ? 1.0 : 0.4)
self.attachmentButton.isEnabled = isMediaEnabled self.attachmentButton.isEnabled = isMediaEnabled
self.attachmentButtonDisabledNode.isHidden = !isSlowmodeActive self.attachmentButtonDisabledNode.isHidden = !isSlowmodeActive || isMediaEnabled
if self.presentationInterfaceState != interfaceState { if self.presentationInterfaceState != interfaceState {
let previousState = self.presentationInterfaceState let previousState = self.presentationInterfaceState

View File

@ -200,9 +200,9 @@ final class StickerPackPreviewControllerNode: ViewControllerTracingNode, UIScrol
var menuItems: [PeekControllerMenuItem] = [] var menuItems: [PeekControllerMenuItem] = []
if let stickerPack = strongSelf.stickerPack, case let .result(info, _, _) = stickerPack, info.id.namespace == Namespaces.ItemCollection.CloudStickerPacks { if let stickerPack = strongSelf.stickerPack, case let .result(info, _, _) = stickerPack, info.id.namespace == Namespaces.ItemCollection.CloudStickerPacks {
if strongSelf.sendSticker != nil { if strongSelf.sendSticker != nil {
menuItems.append(PeekControllerMenuItem(title: strongSelf.presentationData.strings.ShareMenu_Send, color: .accent, font: .bold, action: { _, _ in menuItems.append(PeekControllerMenuItem(title: strongSelf.presentationData.strings.ShareMenu_Send, color: .accent, font: .bold, action: { node, rect in
if let strongSelf = self { if let strongSelf = self {
return strongSelf.sendSticker?(.standalone(media: item.file), itemNode, itemNode.bounds) ?? false return strongSelf.sendSticker?(.standalone(media: item.file), node, rect) ?? false
} else { } else {
return false return false
} }