Merge commit '36387e894ac0ad24530944867adf1f6ad88692d0'

This commit is contained in:
Ali
2021-10-16 02:20:57 +04:00
41 changed files with 1934 additions and 295 deletions

View File

@@ -64,6 +64,7 @@ public enum AdminLogEventAction {
case participantJoinedViaInvite(ExportedInvitation)
case changeHistoryTTL(previousValue: Int32?, updatedValue: Int32?)
case changeTheme(previous: String?, updated: String?)
case participantJoinByRequest(invitation: ExportedInvitation, approvedBy: PeerId)
}
public enum ChannelAdminLogEventError {
@@ -250,6 +251,8 @@ func channelAdminLogEvents(postbox: Postbox, network: Network, peerId: PeerId, m
action = .groupCallUpdateParticipantVolume(peerId: parsedParticipant.peerId, volume: parsedParticipant.volume ?? 10000)
case let .channelAdminLogEventActionChangeHistoryTTL(prevValue, newValue):
action = .changeHistoryTTL(previousValue: prevValue, updatedValue: newValue)
case let .channelAdminLogEventActionParticipantJoinByRequest(invite, approvedBy):
action = .participantJoinByRequest(invitation: ExportedInvitation(apiExportedInvite: invite), approvedBy: PeerId(namespace: Namespaces.Peer.CloudUser, id: PeerId.Id._internalFromInt64Value(approvedBy)))
}
let peerId = PeerId(namespace: Namespaces.Peer.CloudUser, id: PeerId.Id._internalFromInt64Value(userId))
if let action = action {

View File

@@ -81,7 +81,7 @@ func _internal_createPeerExportedInvitation(account: Account, peerId: PeerId, ex
if let _ = usageLimit {
flags |= (1 << 1)
}
if let _ = requestNeeded {
if let requestNeeded = requestNeeded, requestNeeded {
flags |= (1 << 3)
}
return account.network.request(Api.functions.messages.exportChatInvite(flags: flags, peer: inputPeer, expireDate: expireDate, usageLimit: usageLimit))

View File

@@ -4,6 +4,11 @@ import TelegramApi
import MtProtoKit
public enum JoinLinkInfoError {
case generic
case flood
}
public enum JoinLinkError {
case generic
case tooMuchJoined
@@ -49,7 +54,7 @@ func _internal_joinChatInteractively(with hash: String, account: Account) -> Sig
case "INVITE_REQUEST_SENT":
return .requestSent
default:
if error.description.hasPrefix("FLOOD_WAIT") {
if error.errorDescription.hasPrefix("FLOOD_WAIT") {
return .flood
} else {
return .generic
@@ -74,13 +79,17 @@ func _internal_joinChatInteractively(with hash: String, account: Account) -> Sig
}
}
func _internal_joinLinkInformation(_ hash: String, account: Account) -> Signal<ExternalJoiningChatState, NoError> {
return account.network.request(Api.functions.messages.checkChatInvite(hash: hash))
func _internal_joinLinkInformation(_ hash: String, account: Account) -> Signal<ExternalJoiningChatState, JoinLinkInfoError> {
return account.network.request(Api.functions.messages.checkChatInvite(hash: hash), automaticFloodWait: false)
|> map(Optional.init)
|> `catch` { _ -> Signal<Api.ChatInvite?, NoError> in
return .single(nil)
|> `catch` { error -> Signal<Api.ChatInvite?, JoinLinkInfoError> in
if error.errorDescription.hasPrefix("FLOOD_WAIT") {
return .fail(.flood)
} else {
return .single(nil)
}
}
|> mapToSignal { (result) -> Signal<ExternalJoiningChatState, NoError> in
|> mapToSignal { result -> Signal<ExternalJoiningChatState, JoinLinkInfoError> in
if let result = result {
switch result {
case let .chatInvite(flags, title, about, invitePhoto, participantsCount, participants):
@@ -96,6 +105,7 @@ func _internal_joinLinkInformation(_ hash: String, account: Account) -> Signal<E
return .alreadyJoined(peer.id)
})
|> castError(JoinLinkInfoError.self)
}
return .single(.invalidHash)
case let .chatInvitePeek(chat, expires):
@@ -107,6 +117,7 @@ func _internal_joinLinkInformation(_ hash: String, account: Account) -> Signal<E
return .peek(peer.id, expires)
})
|> castError(JoinLinkInfoError.self)
}
return .single(.invalidHash)
}

View File

@@ -486,7 +486,7 @@ public extension TelegramEngine {
return _internal_joinChatInteractively(with: hash, account: self.account)
}
public func joinLinkInformation(_ hash: String) -> Signal<ExternalJoiningChatState, NoError> {
public func joinLinkInformation(_ hash: String) -> Signal<ExternalJoiningChatState, JoinLinkInfoError> {
return _internal_joinLinkInformation(hash, account: self.account)
}