Merge branch 'requests' of gitlab.com:peter-iakovlev/telegram-ios into requests

This commit is contained in:
Ilya Laktyushin 2021-10-05 17:55:37 +04:00
commit da5e87c515
3 changed files with 16 additions and 8 deletions

View File

@ -32,7 +32,7 @@ public struct ExportedInvitation: Codable, Equatable {
self.link = try container.decode(String.self, forKey: "l")
self.isPermanent = try container.decode(Bool.self, forKey: "permanent")
self.requestApproval = (try? container.decode(Bool.self, forKey: "requestApproval")) ?? false
self.requestApproval = try container.decodeIfPresent(Bool.self, forKey: "requestApproval") ?? false
self.isRevoked = try container.decode(Bool.self, forKey: "revoked")
self.adminId = PeerId(try container.decode(Int64.self, forKey: "adminId"))
self.date = try container.decode(Int32.self, forKey: "date")

View File

@ -81,6 +81,9 @@ func _internal_createPeerExportedInvitation(account: Account, peerId: PeerId, ex
if let _ = usageLimit {
flags |= (1 << 1)
}
if let _ = requestNeeded {
flags |= (1 << 3)
}
return account.network.request(Api.functions.messages.exportChatInvite(flags: flags, peer: inputPeer, expireDate: expireDate, usageLimit: usageLimit))
|> mapError { _ in return CreatePeerExportedInvitationError.generic }
|> map { result -> ExportedInvitation? in

View File

@ -22,8 +22,16 @@ func apiUpdatesGroups(_ updates: Api.Updates) -> [Api.Chat] {
}
public enum ExternalJoiningChatState {
case invite(title: String, photoRepresentation: TelegramMediaImageRepresentation?, participantsCount: Int32, participants: [Peer]?)
case request(title: String, about: String?, photoRepresentation: TelegramMediaImageRepresentation?, participantsCount: Int32, isGroup: Bool)
public struct InviteFlags {
public let isChannel: Bool
public let isBroadcast: Bool
public let isPublic: Bool
public let isMegagroup: Bool
public let requestNeeded: Bool
}
case invite(flags: InviteFlags, title: String, about: String?, photoRepresentation: TelegramMediaImageRepresentation?, participantsCount: Int32, participants: [Peer]?)
case alreadyJoined(PeerId)
case invalidHash
case peek(PeerId, Int32)
@ -70,11 +78,8 @@ func _internal_joinLinkInformation(_ hash: String, account: Account) -> Signal<E
switch result {
case let .chatInvite(flags, title, about, invitePhoto, participantsCount, participants):
let photo = telegramMediaImageFromApiPhoto(invitePhoto).flatMap({ smallestImageRepresentation($0.representations) })
if (flags & (1 << 6)) != 0 {
return .single(.request(title: title, about: about, photoRepresentation: photo, participantsCount: participantsCount, isGroup: (flags & (1 << 1)) == 0))
} else {
return .single(.invite(title: title, photoRepresentation: photo, participantsCount: participantsCount, participants: participants?.map({TelegramUser(user: $0)})))
}
let flags:ExternalJoiningChatState.InviteFlags = .init(isChannel: (flags & (1 << 0)) != 0, isBroadcast: (flags & (1 << 1)) != 0, isPublic: (flags & (1 << 2)) != 0, isMegagroup: (flags & (1 << 3)) != 0, requestNeeded: (flags & (1 << 6)) != 0)
return .single(.invite(flags: flags, title: title, about: about, photoRepresentation: photo, participantsCount: participantsCount, participants: participants?.map({TelegramUser(user: $0)})))
case let .chatInviteAlready(chat):
if let peer = parseTelegramGroupOrChannel(chat: chat) {
return account.postbox.transaction({ (transaction) -> ExternalJoiningChatState in