Refactoring

This commit is contained in:
Ali
2021-07-22 00:18:19 +02:00
parent 1a04fb4408
commit c9f009eae7
59 changed files with 614 additions and 399 deletions

View File

@@ -147,7 +147,7 @@ public struct TelegramChannelFlags: OptionSet {
public static let isGigagroup = TelegramChannelFlags(rawValue: 1 << 7)
}
public final class TelegramChannel: Peer {
public final class TelegramChannel: Peer, Equatable {
public let id: PeerId
public let accessHash: TelegramPeerAccessHash?
public let title: String
@@ -267,30 +267,34 @@ public final class TelegramChannel: Peer {
return false
}
if self.id != other.id || self.accessHash != other.accessHash || self.title != other.title || self.username != other.username || self.photo != other.photo {
return self == other
}
public static func ==(lhs: TelegramChannel, rhs: TelegramChannel) -> Bool {
if lhs.id != rhs.id || lhs.accessHash != rhs.accessHash || lhs.title != rhs.title || lhs.username != rhs.username || lhs.photo != rhs.photo {
return false
}
if self.creationDate != other.creationDate || self.version != other.version || self.participationStatus != other.participationStatus {
if lhs.creationDate != rhs.creationDate || lhs.version != rhs.version || lhs.participationStatus != rhs.participationStatus {
return false
}
if self.info != other.info || self.flags != other.flags || self.restrictionInfo != other.restrictionInfo {
if lhs.info != rhs.info || lhs.flags != rhs.flags || lhs.restrictionInfo != rhs.restrictionInfo {
return false
}
if self.adminRights != other.adminRights {
if lhs.adminRights != rhs.adminRights {
return false
}
if self.bannedRights != other.bannedRights {
if lhs.bannedRights != rhs.bannedRights {
return false
}
if self.defaultBannedRights != other.defaultBannedRights {
if lhs.defaultBannedRights != rhs.defaultBannedRights {
return false
}
return true
}

View File

@@ -74,7 +74,7 @@ public struct TelegramGroupToChannelMigrationReference: Equatable {
}
}
public final class TelegramGroup: Peer {
public final class TelegramGroup: Peer, Equatable {
public let id: PeerId
public let title: String
public let photo: [TelegramMediaImageRepresentation]
@@ -159,45 +159,49 @@ public final class TelegramGroup: Peer {
public func isEqual(_ other: Peer) -> Bool {
if let other = other as? TelegramGroup {
if self.id != other.id {
return false
}
if self.title != other.title {
return false
}
if self.photo != other.photo {
return false
}
if self.membership != other.membership {
return false
}
if self.version != other.version {
return false
}
if self.participantCount != other.participantCount {
return false
}
if self.role != other.role {
return false
}
if self.defaultBannedRights != other.defaultBannedRights {
return false
}
if self.migrationReference != other.migrationReference {
return false
}
if self.creationDate != other.creationDate {
return false
}
if self.flags != other.flags {
return false
}
return true
return self == other
} else {
return false
}
}
public static func ==(lhs: TelegramGroup, rhs: TelegramGroup) -> Bool {
if lhs.id != rhs.id {
return false
}
if lhs.title != rhs.title {
return false
}
if lhs.photo != rhs.photo {
return false
}
if lhs.membership != rhs.membership {
return false
}
if lhs.version != rhs.version {
return false
}
if lhs.participantCount != rhs.participantCount {
return false
}
if lhs.role != rhs.role {
return false
}
if lhs.defaultBannedRights != rhs.defaultBannedRights {
return false
}
if lhs.migrationReference != rhs.migrationReference {
return false
}
if lhs.creationDate != rhs.creationDate {
return false
}
if lhs.flags != rhs.flags {
return false
}
return true
}
public func updateFlags(flags: TelegramGroupFlags, version: Int) -> TelegramGroup {
return TelegramGroup(id: self.id, title: self.title, photo: self.photo, participantCount: self.participantCount, role: self.role, membership: self.membership, flags: flags, defaultBannedRights: self.defaultBannedRights, migrationReference: self.migrationReference, creationDate: self.creationDate, version: version)
}

View File

@@ -1,7 +1,7 @@
import Foundation
import Postbox
public final class TelegramSecretChat: Peer {
public final class TelegramSecretChat: Peer, Equatable {
public let id: PeerId
public let regularPeerId: PeerId
public let accessHash: Int64
@@ -57,11 +57,15 @@ public final class TelegramSecretChat: Peer {
public func isEqual(_ other: Peer) -> Bool {
if let other = other as? TelegramSecretChat {
return self.id == other.id && self.regularPeerId == other.regularPeerId && self.accessHash == other.accessHash && self.embeddedState == other.embeddedState && self.messageAutoremoveTimeout == other.messageAutoremoveTimeout && self.creationDate == other.creationDate && self.role == other.role
return self == other
} else {
return false
}
}
public static func ==(lhs: TelegramSecretChat, rhs: TelegramSecretChat) -> Bool {
return lhs.id == rhs.id && lhs.regularPeerId == rhs.regularPeerId && lhs.accessHash == rhs.accessHash && lhs.embeddedState == rhs.embeddedState && lhs.messageAutoremoveTimeout == rhs.messageAutoremoveTimeout && lhs.creationDate == rhs.creationDate && lhs.role == rhs.role
}
public func withUpdatedEmbeddedState(_ embeddedState: SecretChatEmbeddedPeerState) -> TelegramSecretChat {
return TelegramSecretChat(id: self.id, creationDate: self.creationDate, regularPeerId: self.regularPeerId, accessHash: self.accessHash, role: self.role, embeddedState: embeddedState, messageAutoremoveTimeout: self.messageAutoremoveTimeout)

View File

@@ -57,7 +57,7 @@ public struct BotUserInfo: PostboxCoding, Equatable {
}
}
public final class TelegramUser: Peer {
public final class TelegramUser: Peer, Equatable {
public let id: PeerId
public let accessHash: TelegramPeerAccessHash?
public let firstName: String?
@@ -198,45 +198,49 @@ public final class TelegramUser: Peer {
public func isEqual(_ other: Peer) -> Bool {
if let other = other as? TelegramUser {
if self.id != other.id {
return false
}
if self.accessHash != other.accessHash {
return false
}
if self.firstName != other.firstName {
return false
}
if self.lastName != other.lastName {
return false
}
if self.phone != other.phone {
return false
}
if self.photo.count != other.photo.count {
return false
}
for i in 0 ..< self.photo.count {
if self.photo[i] != other.photo[i] {
return false
}
}
if self.botInfo != other.botInfo {
return false
}
if self.restrictionInfo != other.restrictionInfo {
return false
}
if self.flags != other.flags {
return false
}
return true
return self == other
} else {
return false
}
}
public static func ==(lhs: TelegramUser, rhs: TelegramUser) -> Bool {
if lhs.id != rhs.id {
return false
}
if lhs.accessHash != rhs.accessHash {
return false
}
if lhs.firstName != rhs.firstName {
return false
}
if lhs.lastName != rhs.lastName {
return false
}
if lhs.phone != rhs.phone {
return false
}
if lhs.photo.count != rhs.photo.count {
return false
}
for i in 0 ..< lhs.photo.count {
if lhs.photo[i] != rhs.photo[i] {
return false
}
}
if lhs.botInfo != rhs.botInfo {
return false
}
if lhs.restrictionInfo != rhs.restrictionInfo {
return false
}
if lhs.flags != rhs.flags {
return false
}
return true
}
public func withUpdatedUsername(_ username:String?) -> TelegramUser {
return TelegramUser(id: self.id, accessHash: self.accessHash, firstName: self.firstName, lastName: self.lastName, username: username, phone: self.phone, photo: self.photo, botInfo: self.botInfo, restrictionInfo: self.restrictionInfo, flags: self.flags)