mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-08-02 00:17:02 +00:00
Added location-based group creation availability check
This commit is contained in:
parent
e2ff848937
commit
9e06580e83
@ -158,6 +158,22 @@ public func updateAddressName(account: Account, domain: AddressNameDomain, name:
|
||||
} |> mapError { _ -> UpdateAddressNameError in return .generic } |> switchToLatest
|
||||
}
|
||||
|
||||
public func checkPublicChannelCreationAvailability(account: Account, location: Bool = false) -> Signal<Bool, NoError> {
|
||||
var flags: Int32 = (1 << 1)
|
||||
if location {
|
||||
flags |= (1 << 0)
|
||||
}
|
||||
|
||||
return account.network.request(Api.functions.channels.getAdminedPublicChannels(flags: flags))
|
||||
|> retryRequest
|
||||
|> map { _ -> Bool in
|
||||
return true
|
||||
}
|
||||
|> `catch` { error -> Signal<Bool, NoError> in
|
||||
return .single(false)
|
||||
}
|
||||
}
|
||||
|
||||
public func adminedPublicChannels(account: Account, location: Bool = false) -> Signal<[Peer], NoError> {
|
||||
var flags: Int32 = 0
|
||||
if location {
|
||||
|
@ -136,7 +136,7 @@ final class ChatChannelSubscriberInputPanelNode: ChatInputPanelNode {
|
||||
} else {
|
||||
text = presentationInterfaceState.strings.Group_ErrorAccessDenied
|
||||
}
|
||||
strongSelf.interfaceInteraction?.presentController(standardTextAlertController(theme: AlertControllerTheme(presentationTheme: presentationInterfaceState.theme), title: nil, text: text, actions: [TextAlertAction(type: .defaultAction, title: presentationInterfaceState.strings.Common_OK, action: {})]), nil)
|
||||
strongSelf.interfaceInteraction?.presentController(textAlertController(context: context, title: nil, text: text, actions: [TextAlertAction(type: .defaultAction, title: presentationInterfaceState.strings.Common_OK, action: {})]), nil)
|
||||
}))
|
||||
case .kicked:
|
||||
break
|
||||
|
@ -772,7 +772,7 @@ final class ChatRecentActionsControllerNode: ViewControllerTracingNode {
|
||||
strongSelf.openPeer(peerId: peerId, peer: nil)
|
||||
}
|
||||
case .inaccessiblePeer:
|
||||
strongSelf.controllerInteraction.presentController(standardTextAlertController(theme: AlertControllerTheme(presentationTheme: strongSelf.presentationData.theme), title: nil, text: strongSelf.presentationData.strings.Conversation_ErrorInaccessibleMessage, actions: [TextAlertAction(type: .defaultAction, title: strongSelf.presentationData.strings.Common_OK, action: {})]), nil)
|
||||
strongSelf.controllerInteraction.presentController(textAlertController(context: strongSelf.context, title: nil, text: strongSelf.presentationData.strings.Conversation_ErrorInaccessibleMessage, actions: [TextAlertAction(type: .defaultAction, title: strongSelf.presentationData.strings.Common_OK, action: {})]), nil)
|
||||
case .botStart:
|
||||
break
|
||||
//strongSelf.openPeer(peerId: peerId, navigation: .withBotStartPayload(ChatControllerInitialBotStart(payload: payload, behavior: .interactive)), fromMessage: nil)
|
||||
|
@ -443,7 +443,7 @@ public func createGroupController(context: AccountContext, peerIds: [PeerId], in
|
||||
case .tooMuchLocationBasedGroups:
|
||||
text = presentationData.strings.CreateGroup_ErrorLocatedGroupsTooMuch
|
||||
}
|
||||
presentControllerImpl?(standardTextAlertController(theme: AlertControllerTheme(presentationTheme: presentationData.theme), title: nil, text: text, actions: [TextAlertAction(type: .defaultAction, title: presentationData.strings.Common_OK, action: {})]), nil)
|
||||
presentControllerImpl?(textAlertController(context: context, title: nil, text: text, actions: [TextAlertAction(type: .defaultAction, title: presentationData.strings.Common_OK, action: {})]), nil)
|
||||
}))
|
||||
}
|
||||
}, changeProfilePhoto: {
|
||||
|
@ -289,6 +289,8 @@ public func peersNearbyController(context: AccountContext) -> ViewController {
|
||||
var navigateToChatImpl: ((Peer) -> Void)?
|
||||
|
||||
let actionsDisposable = DisposableSet()
|
||||
let checkCreationAvailabilityDisposable = MetaDisposable()
|
||||
actionsDisposable.add(checkCreationAvailabilityDisposable)
|
||||
|
||||
let dataPromise = Promise<PeersNearbyData?>(nil)
|
||||
let addressPromise = Promise<String?>(nil)
|
||||
@ -297,12 +299,43 @@ public func peersNearbyController(context: AccountContext) -> ViewController {
|
||||
navigateToChatImpl?(peer)
|
||||
}, openCreateGroup: { latitude, longitude, address in
|
||||
let presentationData = context.sharedContext.currentPresentationData.with { $0 }
|
||||
let controller = PermissionController(context: context, splashScreen: true)
|
||||
controller.setState(.custom(icon: PermissionControllerCustomIcon(light: UIImage(bundleImageName: "Location/LocalGroupLightIcon"), dark: UIImage(bundleImageName: "Location/LocalGroupDarkIcon")), title: presentationData.strings.LocalGroup_Title, subtitle: address, text: presentationData.strings.LocalGroup_Text, buttonTitle: presentationData.strings.LocalGroup_ButtonTitle, footerText: presentationData.strings.LocalGroup_IrrelevantWarning), animated: false)
|
||||
controller.proceed = { result in
|
||||
replaceTopControllerImpl?(createGroupController(context: context, peerIds: [], mode: .locatedGroup(latitude: latitude, longitude: longitude, address: address)))
|
||||
|
||||
var cancelImpl: (() -> Void)?
|
||||
let progressSignal = Signal<Never, NoError> { subscriber in
|
||||
let controller = OverlayStatusController(theme: presentationData.theme, strings: presentationData.strings, type: .loading(cancelled: {
|
||||
cancelImpl?()
|
||||
}))
|
||||
presentControllerImpl?(controller, nil)
|
||||
return ActionDisposable { [weak controller] in
|
||||
Queue.mainQueue().async() {
|
||||
controller?.dismiss()
|
||||
}
|
||||
}
|
||||
}
|
||||
pushControllerImpl?(controller)
|
||||
|> runOn(Queue.mainQueue())
|
||||
|> delay(0.5, queue: Queue.mainQueue())
|
||||
let progressDisposable = progressSignal.start()
|
||||
cancelImpl = {
|
||||
checkCreationAvailabilityDisposable.set(nil)
|
||||
}
|
||||
checkCreationAvailabilityDisposable.set((checkPublicChannelCreationAvailability(account: context.account, location: true)
|
||||
|> afterDisposed {
|
||||
Queue.mainQueue().async {
|
||||
progressDisposable.dispose()
|
||||
}
|
||||
}
|
||||
|> deliverOnMainQueue).start(next: { available in
|
||||
if available {
|
||||
let controller = PermissionController(context: context, splashScreen: true)
|
||||
controller.setState(.custom(icon: PermissionControllerCustomIcon(light: UIImage(bundleImageName: "Location/LocalGroupLightIcon"), dark: UIImage(bundleImageName: "Location/LocalGroupDarkIcon")), title: presentationData.strings.LocalGroup_Title, subtitle: address, text: presentationData.strings.LocalGroup_Text, buttonTitle: presentationData.strings.LocalGroup_ButtonTitle, footerText: presentationData.strings.LocalGroup_IrrelevantWarning), animated: false)
|
||||
controller.proceed = { result in
|
||||
replaceTopControllerImpl?(createGroupController(context: context, peerIds: [], mode: .locatedGroup(latitude: latitude, longitude: longitude, address: address)))
|
||||
}
|
||||
pushControllerImpl?(controller)
|
||||
} else {
|
||||
presentControllerImpl?(textAlertController(context: context, title: nil, text: presentationData.strings.CreateGroup_ErrorLocatedGroupsTooMuch, actions: [TextAlertAction(type: .defaultAction, title: presentationData.strings.Common_OK, action: {})]), nil)
|
||||
}
|
||||
}))
|
||||
})
|
||||
|
||||
let dataSignal: Signal<PeersNearbyData?, NoError> = currentLocationManagerCoordinate(manager: context.sharedContext.locationManager!, timeout: 5.0)
|
||||
@ -359,7 +392,11 @@ public func peersNearbyController(context: AccountContext) -> ViewController {
|
||||
dataPromise.set(dataSignal)
|
||||
|
||||
let previousData = Atomic<PeersNearbyData?>(value: nil)
|
||||
let displayLoading: Signal<Bool, NoError> = .single(false) |> then(.single(true) |> delay(1.0, queue: Queue.mainQueue()))
|
||||
let displayLoading: Signal<Bool, NoError> = .single(false)
|
||||
|> then(
|
||||
.single(true)
|
||||
|> delay(1.0, queue: Queue.mainQueue())
|
||||
)
|
||||
|
||||
let signal = combineLatest(context.sharedContext.presentationData, dataPromise.get(), displayLoading)
|
||||
|> deliverOnMainQueue
|
||||
|
Loading…
x
Reference in New Issue
Block a user