Don't display the only group in common if opened from the same group

This commit is contained in:
Ali 2020-03-01 23:39:32 +04:00
parent 171f4a76e9
commit 9fb963e3a6
5 changed files with 34 additions and 17 deletions

View File

@ -262,6 +262,7 @@ public enum PeerInfoControllerMode {
case generic
case calls(messages: [Message])
case nearbyPeer
case group(PeerId)
}
public enum ContactListActionItemInlineIconPosition {

View File

@ -7172,7 +7172,7 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G
} else {
if let peerId = peerId {
switch self.chatLocation {
case .peer:
case let .peer(selfPeerId):
switch navigation {
case .info:
let peerSignal: Signal<Peer?, NoError>
@ -7183,7 +7183,11 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G
}
self.navigationActionDisposable.set((peerSignal |> take(1) |> deliverOnMainQueue).start(next: { [weak self] peer in
if let strongSelf = self, let peer = peer {
if let infoController = strongSelf.context.sharedContext.makePeerInfoController(context: strongSelf.context, peer: peer, mode: .generic, avatarInitiallyExpanded: expandAvatar, fromChat: false) {
var mode: PeerInfoControllerMode = .generic
if let _ = fromMessage {
mode = .group(selfPeerId)
}
if let infoController = strongSelf.context.sharedContext.makePeerInfoController(context: strongSelf.context, peer: peer, mode: mode, avatarInitiallyExpanded: expandAvatar, fromChat: false) {
strongSelf.effectiveNavigationController?.pushViewController(infoController)
}
}

View File

@ -262,7 +262,7 @@ func keepPeerInfoScreenDataHot(context: AccountContext, peerId: PeerId) -> Signa
}
}
func peerInfoScreenData(context: AccountContext, peerId: PeerId, strings: PresentationStrings, dateTimeFormat: PresentationDateTimeFormat) -> Signal<PeerInfoScreenData, NoError> {
func peerInfoScreenData(context: AccountContext, peerId: PeerId, strings: PresentationStrings, dateTimeFormat: PresentationDateTimeFormat, ignoreGroupInCommon: PeerId?) -> Signal<PeerInfoScreenData, NoError> {
return peerInfoScreenInputData(context: context, peerId: peerId)
|> mapToSignal { inputData -> Signal<PeerInfoScreenData, NoError> in
switch inputData {
@ -401,9 +401,12 @@ func peerInfoScreenData(context: AccountContext, peerId: PeerId, strings: Presen
var availablePanes = availablePanes
if availablePanes != nil, groupsInCommon != nil, let cachedData = peerView.cachedData as? CachedUserData {
if cachedData.commonGroupCount != 0 {
if ignoreGroupInCommon != nil && cachedData.commonGroupCount == 1 {
} else {
availablePanes?.append(.groupsInCommon)
}
}
}
return PeerInfoScreenData(
peer: peerView.peers[userPeerId],

View File

@ -489,7 +489,7 @@ private final class PeerInfoInteraction {
let editingOpenStickerPackSetup: () -> Void
let openLocation: () -> Void
let editingOpenSetupLocation: () -> Void
let openPeerInfo: (Peer) -> Void
let openPeerInfo: (Peer, Bool) -> Void
let performMemberAction: (PeerInfoMember, PeerInfoMemberAction) -> Void
let openPeerInfoContextMenu: (PeerInfoContextSubject, ASDisplayNode) -> Void
let performBioLinkAction: (TextLinkItemActionType, TextLinkItem) -> Void
@ -519,7 +519,7 @@ private final class PeerInfoInteraction {
editingOpenStickerPackSetup: @escaping () -> Void,
openLocation: @escaping () -> Void,
editingOpenSetupLocation: @escaping () -> Void,
openPeerInfo: @escaping (Peer) -> Void,
openPeerInfo: @escaping (Peer, Bool) -> Void,
performMemberAction: @escaping (PeerInfoMember, PeerInfoMemberAction) -> Void,
openPeerInfoContextMenu: @escaping (PeerInfoContextSubject, ASDisplayNode) -> Void,
performBioLinkAction: @escaping (TextLinkItemActionType, TextLinkItem) -> Void,
@ -755,7 +755,7 @@ private func infoItems(data: PeerInfoScreenData?, context: AccountContext, prese
items[.peerMembers]!.append(PeerInfoScreenMemberItem(id: member.id, context: context, enclosingPeer: peer, member: member, action: isAccountPeer ? nil : { action in
switch action {
case .open:
interaction.openPeerInfo(member.peer)
interaction.openPeerInfo(member.peer, true)
case .promote:
interaction.performMemberAction(member, .promote)
case .restrict:
@ -1096,7 +1096,7 @@ private final class PeerInfoScreenNode: ViewControllerTracingNode, UIScrollViewD
}
private var didSetReady = false
init(controller: PeerInfoScreen, context: AccountContext, peerId: PeerId, avatarInitiallyExpanded: Bool, isOpenedFromChat: Bool, nearbyPeer: Bool, callMessages: [Message]) {
init(controller: PeerInfoScreen, context: AccountContext, peerId: PeerId, avatarInitiallyExpanded: Bool, isOpenedFromChat: Bool, nearbyPeer: Bool, callMessages: [Message], ignoreGroupInCommon: PeerId?) {
self.controller = controller
self.context = context
self.peerId = peerId
@ -1181,8 +1181,8 @@ private final class PeerInfoScreenNode: ViewControllerTracingNode, UIScrollViewD
editingOpenSetupLocation: { [weak self] in
self?.editingOpenSetupLocation()
},
openPeerInfo: { [weak self] peer in
self?.openPeerInfo(peer: peer)
openPeerInfo: { [weak self] peer, isMember in
self?.openPeerInfo(peer: peer, isMember: isMember)
},
performMemberAction: { [weak self] member, action in
self?.performMemberAction(member: member, action: action)
@ -1637,7 +1637,7 @@ private final class PeerInfoScreenNode: ViewControllerTracingNode, UIScrollViewD
}
switch action {
case .open:
strongSelf.openPeerInfo(peer: member.peer)
strongSelf.openPeerInfo(peer: member.peer, isMember: true)
case .promote:
strongSelf.performMemberAction(member: member, action: .promote)
case .restrict:
@ -1919,7 +1919,7 @@ private final class PeerInfoScreenNode: ViewControllerTracingNode, UIScrollViewD
}
}
self.dataDisposable = (peerInfoScreenData(context: context, peerId: peerId, strings: self.presentationData.strings, dateTimeFormat: self.presentationData.dateTimeFormat)
self.dataDisposable = (peerInfoScreenData(context: context, peerId: peerId, strings: self.presentationData.strings, dateTimeFormat: self.presentationData.dateTimeFormat, ignoreGroupInCommon: ignoreGroupInCommon)
|> deliverOnMainQueue).start(next: { [weak self] data in
guard let strongSelf = self else {
return
@ -2891,8 +2891,12 @@ private final class PeerInfoScreenNode: ViewControllerTracingNode, UIScrollViewD
self.controller?.push(locationController)
}
private func openPeerInfo(peer: Peer) {
if let infoController = self.context.sharedContext.makePeerInfoController(context: self.context, peer: peer, mode: .generic, avatarInitiallyExpanded: false, fromChat: false) {
private func openPeerInfo(peer: Peer, isMember: Bool) {
var mode: PeerInfoControllerMode = .generic
if isMember {
mode = .group(self.peerId)
}
if let infoController = self.context.sharedContext.makePeerInfoController(context: self.context, peer: peer, mode: mode, avatarInitiallyExpanded: false, fromChat: false) {
(self.controller?.navigationController as? NavigationController)?.pushViewController(infoController)
}
}
@ -4167,6 +4171,7 @@ public final class PeerInfoScreen: ViewController {
private let isOpenedFromChat: Bool
private let nearbyPeer: Bool
private let callMessages: [Message]
private let ignoreGroupInCommon: PeerId?
private var presentationData: PresentationData
private var presentationDataDisposable: Disposable?
@ -4182,13 +4187,14 @@ public final class PeerInfoScreen: ViewController {
private var validLayout: (layout: ContainerViewLayout, navigationHeight: CGFloat)?
public init(context: AccountContext, peerId: PeerId, avatarInitiallyExpanded: Bool, isOpenedFromChat: Bool, nearbyPeer: Bool, callMessages: [Message]) {
public init(context: AccountContext, peerId: PeerId, avatarInitiallyExpanded: Bool, isOpenedFromChat: Bool, nearbyPeer: Bool, callMessages: [Message], ignoreGroupInCommon: PeerId? = nil) {
self.context = context
self.peerId = peerId
self.avatarInitiallyExpanded = avatarInitiallyExpanded
self.isOpenedFromChat = isOpenedFromChat
self.nearbyPeer = nearbyPeer
self.callMessages = callMessages
self.ignoreGroupInCommon = ignoreGroupInCommon
self.presentationData = context.sharedContext.currentPresentationData.with { $0 }
@ -4259,7 +4265,7 @@ public final class PeerInfoScreen: ViewController {
}
override public func loadDisplayNode() {
self.displayNode = PeerInfoScreenNode(controller: self, context: self.context, peerId: self.peerId, avatarInitiallyExpanded: self.avatarInitiallyExpanded, isOpenedFromChat: self.isOpenedFromChat, nearbyPeer: self.nearbyPeer, callMessages: self.callMessages)
self.displayNode = PeerInfoScreenNode(controller: self, context: self.context, peerId: self.peerId, avatarInitiallyExpanded: self.avatarInitiallyExpanded, isOpenedFromChat: self.isOpenedFromChat, nearbyPeer: self.nearbyPeer, callMessages: self.callMessages, ignoreGroupInCommon: self.ignoreGroupInCommon)
self._ready.set(self.controllerNode.ready.get())

View File

@ -1259,6 +1259,7 @@ private func peerInfoControllerImpl(context: AccountContext, peer: Peer, mode: P
} else if peer is TelegramUser {
var nearbyPeer = false
var callMessages: [Message] = []
var ignoreGroupInCommon: PeerId?
switch mode {
case .nearbyPeer:
nearbyPeer = true
@ -1266,8 +1267,10 @@ private func peerInfoControllerImpl(context: AccountContext, peer: Peer, mode: P
callMessages = messages
case .generic:
break
case let .group(id):
ignoreGroupInCommon = id
}
return PeerInfoScreen(context: context, peerId: peer.id, avatarInitiallyExpanded: avatarInitiallyExpanded, isOpenedFromChat: isOpenedFromChat, nearbyPeer: nearbyPeer, callMessages: callMessages)
return PeerInfoScreen(context: context, peerId: peer.id, avatarInitiallyExpanded: avatarInitiallyExpanded, isOpenedFromChat: isOpenedFromChat, nearbyPeer: nearbyPeer, callMessages: callMessages, ignoreGroupInCommon: ignoreGroupInCommon)
} else if peer is TelegramSecretChat {
return PeerInfoScreen(context: context, peerId: peer.id, avatarInitiallyExpanded: avatarInitiallyExpanded, isOpenedFromChat: isOpenedFromChat, nearbyPeer: false, callMessages: [])
}