mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-24 07:05:35 +00:00
Merge branch 'master' of gitlab.com:peter-iakovlev/telegram-ios
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import Foundation
|
||||
import Postbox
|
||||
import SwiftSignalKit
|
||||
import TelegramApi
|
||||
|
||||
public final class NewSessionReview: Codable, Equatable {
|
||||
struct Id {
|
||||
@@ -19,11 +20,13 @@ public final class NewSessionReview: Codable, Equatable {
|
||||
public let id: Int64
|
||||
public let device: String
|
||||
public let location: String
|
||||
public let timestamp: Int32
|
||||
|
||||
public init(id: Int64, device: String, location: String) {
|
||||
public init(id: Int64, device: String, location: String, timestamp: Int32) {
|
||||
self.id = id
|
||||
self.device = device
|
||||
self.location = location
|
||||
self.timestamp = timestamp
|
||||
}
|
||||
|
||||
public init(from decoder: Decoder) throws {
|
||||
@@ -32,6 +35,7 @@ public final class NewSessionReview: Codable, Equatable {
|
||||
self.id = try container.decode(Int64.self, forKey: "id")
|
||||
self.device = try container.decode(String.self, forKey: "device")
|
||||
self.location = try container.decode(String.self, forKey: "location")
|
||||
self.timestamp = try container.decode(Int32.self, forKey: "timestamp")
|
||||
}
|
||||
|
||||
public func encode(to encoder: Encoder) throws {
|
||||
@@ -40,6 +44,7 @@ public final class NewSessionReview: Codable, Equatable {
|
||||
try container.encode(self.id, forKey: "id")
|
||||
try container.encode(self.device, forKey: "device")
|
||||
try container.encode(self.location, forKey: "location")
|
||||
try container.encode(self.timestamp, forKey: "timestamp")
|
||||
}
|
||||
|
||||
public static func ==(lhs: NewSessionReview, rhs: NewSessionReview) -> Bool {
|
||||
@@ -52,10 +57,42 @@ public final class NewSessionReview: Codable, Equatable {
|
||||
if lhs.location != rhs.location {
|
||||
return false
|
||||
}
|
||||
if lhs.timestamp != rhs.timestamp {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
func _internal_cleanupSessionReviews(account: Account) -> Signal<Never, NoError> {
|
||||
return account.postbox.transaction { transaction -> Void in
|
||||
var autoconfirmTimeout: Int32 = 7 * 24 * 60 * 60
|
||||
let appConfig = currentAppConfiguration(transaction: transaction)
|
||||
if let data = appConfig.data {
|
||||
if let value = data["authorization_autoconfirm_period"] as? Double {
|
||||
autoconfirmTimeout = Int32(round(value))
|
||||
}
|
||||
}
|
||||
|
||||
let timestamp = Int32(Date().timeIntervalSince1970)
|
||||
var removeIds: [MemoryBuffer] = []
|
||||
for entry in transaction.getOrderedListItems(collectionId: Namespaces.OrderedItemList.NewSessionReviews) {
|
||||
guard let item = entry.contents.get(NewSessionReview.self) else {
|
||||
removeIds.append(entry.id)
|
||||
continue
|
||||
}
|
||||
if item.timestamp <= timestamp - autoconfirmTimeout {
|
||||
removeIds.append(entry.id)
|
||||
}
|
||||
}
|
||||
|
||||
for removeId in removeIds {
|
||||
transaction.removeOrderedItemListItem(collectionId: Namespaces.OrderedItemList.NewSessionReviews, itemId: removeId)
|
||||
}
|
||||
}
|
||||
|> ignoreValues
|
||||
}
|
||||
|
||||
public func newSessionReviews(postbox: Postbox) -> Signal<[NewSessionReview], NoError> {
|
||||
let viewKey: PostboxViewKey = .orderedItemList(id: Namespaces.OrderedItemList.NewSessionReviews)
|
||||
return postbox.combinedView(keys: [viewKey])
|
||||
@@ -102,3 +139,11 @@ public func removeNewSessionReviews(postbox: Postbox, ids: [Int64]) -> Signal<Ne
|
||||
}
|
||||
|> ignoreValues
|
||||
}
|
||||
|
||||
func _internal_confirmNewSessionReview(account: Account, id: Int64) -> Signal<Never, NoError> {
|
||||
return account.network.request(Api.functions.account.changeAuthorizationSettings(flags: 1 << 3, hash: id, encryptedRequestsDisabled: nil, callRequestsDisabled: nil))
|
||||
|> `catch` { _ -> Signal<Api.Bool, NoError> in
|
||||
return .single(.boolFalse)
|
||||
}
|
||||
|> ignoreValues
|
||||
}
|
||||
|
||||
@@ -22,13 +22,17 @@ public struct TelegramChatAdminRightsFlags: OptionSet, Hashable {
|
||||
public static let canBeAnonymous = TelegramChatAdminRightsFlags(rawValue: 1 << 10)
|
||||
public static let canManageCalls = TelegramChatAdminRightsFlags(rawValue: 1 << 11)
|
||||
public static let canManageTopics = TelegramChatAdminRightsFlags(rawValue: 1 << 13)
|
||||
public static let canPostStories = TelegramChatAdminRightsFlags(rawValue: 1 << 14)
|
||||
public static let canEditStories = TelegramChatAdminRightsFlags(rawValue: 1 << 15)
|
||||
public static let canDeleteStories = TelegramChatAdminRightsFlags(rawValue: 1 << 16)
|
||||
|
||||
|
||||
public static var all: TelegramChatAdminRightsFlags {
|
||||
return [.canChangeInfo, .canPostMessages, .canEditMessages, .canDeleteMessages, .canBanUsers, .canInviteUsers, .canPinMessages, .canAddAdmins, .canBeAnonymous, .canManageCalls, .canManageTopics]
|
||||
return [.canChangeInfo, .canPostMessages, .canEditMessages, .canDeleteMessages, .canBanUsers, .canInviteUsers, .canPinMessages, .canAddAdmins, .canBeAnonymous, .canManageCalls, .canManageTopics, .canPostStories, .canEditStories, .canDeleteStories]
|
||||
}
|
||||
|
||||
public static var allChannel: TelegramChatAdminRightsFlags {
|
||||
return [.canChangeInfo, .canPostMessages, .canEditMessages, .canDeleteMessages, .canBanUsers, .canInviteUsers, .canPinMessages, .canAddAdmins, .canManageCalls, .canManageTopics]
|
||||
return [.canChangeInfo, .canPostMessages, .canEditMessages, .canDeleteMessages, .canBanUsers, .canInviteUsers, .canPinMessages, .canAddAdmins, .canManageCalls, .canManageTopics, .canPostStories, .canEditStories, .canDeleteStories]
|
||||
}
|
||||
|
||||
public static let internal_groupSpecific: TelegramChatAdminRightsFlags = [
|
||||
@@ -49,7 +53,10 @@ public struct TelegramChatAdminRightsFlags: OptionSet, Hashable {
|
||||
.canDeleteMessages,
|
||||
.canManageCalls,
|
||||
.canInviteUsers,
|
||||
.canAddAdmins
|
||||
.canAddAdmins,
|
||||
.canPostStories,
|
||||
.canEditStories,
|
||||
.canDeleteStories
|
||||
]
|
||||
|
||||
public static func peerSpecific(peer: EnginePeer) -> TelegramChatAdminRightsFlags {
|
||||
|
||||
Reference in New Issue
Block a user