Merge commit '47896caf0551044f790882c1daafc2ff855f9c04'

This commit is contained in:
Ali
2020-01-17 22:04:52 +04:00
3 changed files with 134 additions and 96 deletions

View File

@@ -1156,6 +1156,8 @@ final class SharedApplicationContext {
self.registerForNotifications(context: context.context, authorize: authorizeNotifications)
self.resetIntentsIfNeeded(context: context.context)
let _ = storeCurrentCallListTabDefaultValue(accountManager: context.context.sharedContext.accountManager).start()
}))
} else {
self.mainWindow.viewController = nil

View File

@@ -81,14 +81,6 @@ class ChatMessageInstantVideoItemNode: ChatMessageItemView {
}
return .waitForSingleTap
}
recognizer.longTap = { [weak self] point, recognizer in
guard let strongSelf = self else {
return
}
if strongSelf.gestureRecognized(gesture: .longTap, location: point, recognizer: recognizer) {
recognizer.cancel()
}
}
self.view.addGestureRecognizer(recognizer)
let replyRecognizer = ChatSwipeToReplyRecognizer(target: self, action: #selector(self.swipeToReplyGesture(_:)))
@@ -588,93 +580,87 @@ class ChatMessageInstantVideoItemNode: ChatMessageItemView {
switch recognizer.state {
case .ended:
if let (gesture, location) = recognizer.lastRecognizedGestureAndLocation {
let _ = self.gestureRecognized(gesture: gesture, location: location, recognizer: nil)
switch gesture {
case .tap:
if let avatarNode = self.accessoryItemNode as? ChatMessageAvatarAccessoryItemNode, avatarNode.frame.contains(location) {
if let item = self.item, let author = item.content.firstMessage.author {
var openPeerId = item.effectiveAuthorId ?? author.id
var navigate: ChatControllerInteractionNavigateToPeer
if item.content.firstMessage.id.peerId == item.context.account.peerId {
navigate = .chat(textInputState: nil, subject: nil)
} else {
navigate = .info
}
for attribute in item.content.firstMessage.attributes {
if let attribute = attribute as? SourceReferenceMessageAttribute {
openPeerId = attribute.messageId.peerId
navigate = .chat(textInputState: nil, subject: .message(attribute.messageId))
}
}
if item.effectiveAuthorId?.namespace == Namespaces.Peer.Empty {
item.controllerInteraction.displayMessageTooltip(item.content.firstMessage.id, item.presentationData.strings.Conversation_ForwardAuthorHiddenTooltip, self, avatarNode.frame)
} else {
if let channel = item.content.firstMessage.forwardInfo?.author as? TelegramChannel, channel.username == nil {
if case .member = channel.participationStatus {
} else {
item.controllerInteraction.displayMessageTooltip(item.message.id, item.presentationData.strings.Conversation_PrivateChannelTooltip, self, avatarNode.frame)
return
}
}
item.controllerInteraction.openPeer(openPeerId, navigate, item.message)
}
}
return
}
if let replyInfoNode = self.replyInfoNode, replyInfoNode.frame.contains(location) {
if let item = self.item {
for attribute in item.message.attributes {
if let attribute = attribute as? ReplyMessageAttribute {
item.controllerInteraction.navigateToMessage(item.message.id, attribute.messageId)
return
}
}
}
}
if let forwardInfoNode = self.forwardInfoNode, forwardInfoNode.frame.contains(location) {
if let item = self.item, let forwardInfo = item.message.forwardInfo {
if let sourceMessageId = forwardInfo.sourceMessageId {
if let channel = forwardInfo.author as? TelegramChannel, channel.username == nil {
if case .member = channel.participationStatus {
} else {
item.controllerInteraction.displayMessageTooltip(item.message.id, item.presentationData.strings.Conversation_PrivateChannelTooltip, forwardInfoNode, nil)
return
}
}
item.controllerInteraction.navigateToMessage(item.message.id, sourceMessageId)
} else if let id = forwardInfo.source?.id ?? forwardInfo.author?.id {
item.controllerInteraction.openPeer(id, .chat(textInputState: nil, subject: nil), nil)
} else if let _ = forwardInfo.authorSignature {
item.controllerInteraction.displayMessageTooltip(item.message.id, item.presentationData.strings.Conversation_ForwardAuthorHiddenTooltip, forwardInfoNode, nil)
}
return
}
}
self.item?.controllerInteraction.clickThroughMessage()
case .longTap, .doubleTap:
if let item = self.item, let videoContentNode = self.interactiveVideoNode.videoContentNode(at: self.view.convert(location, to: self.interactiveVideoNode.view)) {
item.controllerInteraction.openMessageContextMenu(item.message, false, videoContentNode, videoContentNode.bounds, nil)
}
case .hold:
break
}
}
default:
break
}
}
private func gestureRecognized(gesture: TapLongTapOrDoubleTapGesture, location: CGPoint, recognizer: TapLongTapOrDoubleTapGestureRecognizer?) -> Bool {
switch gesture {
case .tap:
if let avatarNode = self.accessoryItemNode as? ChatMessageAvatarAccessoryItemNode, avatarNode.frame.contains(location) {
if let item = self.item, let author = item.content.firstMessage.author {
var openPeerId = item.effectiveAuthorId ?? author.id
var navigate: ChatControllerInteractionNavigateToPeer
if item.content.firstMessage.id.peerId == item.context.account.peerId {
navigate = .chat(textInputState: nil, subject: nil)
} else {
navigate = .info
}
for attribute in item.content.firstMessage.attributes {
if let attribute = attribute as? SourceReferenceMessageAttribute {
openPeerId = attribute.messageId.peerId
navigate = .chat(textInputState: nil, subject: .message(attribute.messageId))
}
}
if item.effectiveAuthorId?.namespace == Namespaces.Peer.Empty {
item.controllerInteraction.displayMessageTooltip(item.content.firstMessage.id, item.presentationData.strings.Conversation_ForwardAuthorHiddenTooltip, self, avatarNode.frame)
} else {
if let channel = item.content.firstMessage.forwardInfo?.author as? TelegramChannel, channel.username == nil {
if case .member = channel.participationStatus {
} else {
item.controllerInteraction.displayMessageTooltip(item.message.id, item.presentationData.strings.Conversation_PrivateChannelTooltip, self, avatarNode.frame)
return true
}
}
item.controllerInteraction.openPeer(openPeerId, navigate, item.message)
}
}
return true
}
if let replyInfoNode = self.replyInfoNode, replyInfoNode.frame.contains(location) {
if let item = self.item {
for attribute in item.message.attributes {
if let attribute = attribute as? ReplyMessageAttribute {
item.controllerInteraction.navigateToMessage(item.message.id, attribute.messageId)
return true
}
}
}
}
if let forwardInfoNode = self.forwardInfoNode, forwardInfoNode.frame.contains(location) {
if let item = self.item, let forwardInfo = item.message.forwardInfo {
if let sourceMessageId = forwardInfo.sourceMessageId {
if let channel = forwardInfo.author as? TelegramChannel, channel.username == nil {
if case .member = channel.participationStatus {
} else {
item.controllerInteraction.displayMessageTooltip(item.message.id, item.presentationData.strings.Conversation_PrivateChannelTooltip, forwardInfoNode, nil)
return true
}
}
item.controllerInteraction.navigateToMessage(item.message.id, sourceMessageId)
} else if let id = forwardInfo.source?.id ?? forwardInfo.author?.id {
item.controllerInteraction.openPeer(id, .chat(textInputState: nil, subject: nil), nil)
} else if let _ = forwardInfo.authorSignature {
item.controllerInteraction.displayMessageTooltip(item.message.id, item.presentationData.strings.Conversation_ForwardAuthorHiddenTooltip, forwardInfoNode, nil)
}
return true
}
}
self.item?.controllerInteraction.clickThroughMessage()
case .longTap, .doubleTap:
if let item = self.item, let videoContentNode = self.interactiveVideoNode.videoContentNode(at: self.view.convert(location, to: self.interactiveVideoNode.view)) {
item.controllerInteraction.openMessageContextMenu(item.message, false, videoContentNode, videoContentNode.bounds, recognizer)
return false
}
case .hold:
break
}
return true
}
@objc func shareButtonPressed() {
if let item = self.item {
if item.content.firstMessage.id.peerId == item.context.account.peerId {

View File

@@ -3,22 +3,58 @@ import Postbox
import SwiftSignalKit
public struct CallListSettings: PreferencesEntry, Equatable {
public var showTab: Bool
public var _showTab: Bool?
public var defaultShowTab: Bool?
public static var defaultSettings: CallListSettings {
return CallListSettings(showTab: false)
return CallListSettings(showTab: true)
}
public var showTab: Bool {
get {
if let value = self._showTab {
return value
} else if let defaultValue = self.defaultShowTab {
return defaultValue
} else {
return CallListSettings.defaultSettings.showTab
}
} set {
self._showTab = newValue
}
}
public init(showTab: Bool) {
self.showTab = showTab
self._showTab = showTab
}
public init(showTab: Bool?, defaultShowTab: Bool?) {
self._showTab = showTab
self.defaultShowTab = defaultShowTab
}
public init(decoder: PostboxDecoder) {
self.showTab = decoder.decodeInt32ForKey("showTab", orElse: 0) != 0
var defaultValue = CallListSettings.defaultSettings.showTab
if let alternativeDefaultValue = decoder.decodeOptionalInt32ForKey("defaultShowTab") {
defaultValue = alternativeDefaultValue != 0
self.defaultShowTab = alternativeDefaultValue != 0
}
if let value = decoder.decodeOptionalInt32ForKey("showTab") {
self._showTab = value != 0
}
}
public func encode(_ encoder: PostboxEncoder) {
encoder.encodeInt32(self.showTab ? 1 : 0, forKey: "showTab")
if let defaultShowTab = self.defaultShowTab {
encoder.encodeInt32(defaultShowTab ? 1 : 0, forKey: "defaultShowTab")
} else {
encoder.encodeNil(forKey: "defaultShowTab")
}
if let showTab = self._showTab {
encoder.encodeInt32(showTab ? 1 : 0, forKey: "showTab")
} else {
encoder.encodeNil(forKey: "showTab")
}
}
public func isEqual(to: PreferencesEntry) -> Bool {
@@ -30,11 +66,11 @@ public struct CallListSettings: PreferencesEntry, Equatable {
}
public static func ==(lhs: CallListSettings, rhs: CallListSettings) -> Bool {
return lhs.showTab == rhs.showTab
return lhs._showTab == rhs._showTab && lhs.defaultShowTab == rhs.defaultShowTab
}
public func withUpdatedShowTab(_ showTab: Bool) -> CallListSettings {
return CallListSettings(showTab: showTab)
return CallListSettings(showTab: showTab, defaultShowTab: self.defaultShowTab)
}
}
@@ -51,3 +87,17 @@ public func updateCallListSettingsInteractively(accountManager: AccountManager,
})
}
}
public func storeCurrentCallListTabDefaultValue(accountManager: AccountManager) -> Signal<Void, NoError> {
return accountManager.transaction { transaction -> Void in
transaction.updateSharedData(ApplicationSpecificSharedDataKeys.callListSettings, { entry in
let currentSettings: CallListSettings
if let entry = entry as? CallListSettings {
currentSettings = entry
} else {
currentSettings = CallListSettings(showTab: nil, defaultShowTab: CallListSettings.defaultSettings.showTab)
}
return currentSettings
})
}
}