Skip to content

Commit 27ae295

Browse files
committed
Merge branch 'master' of gitlab.com:peter-iakovlev/telegram-ios
2 parents 07436e4 + ef652c0 commit 27ae295

File tree

9 files changed

+177
-127
lines changed

9 files changed

+177
-127
lines changed

submodules/TelegramApi/Sources/Api0.swift

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -903,7 +903,7 @@ fileprivate let parsers: [Int32 : (BufferReader) -> Any?] = {
903903
dict[1301522832] = { return Api.SponsoredMessage.parse_sponsoredMessage($0) }
904904
dict[1124938064] = { return Api.SponsoredMessageReportOption.parse_sponsoredMessageReportOption($0) }
905905
dict[1237678029] = { return Api.StarGift.parse_starGift($0) }
906-
dict[708628759] = { return Api.StarRefProgram.parse_starRefProgram($0) }
906+
dict[-586389774] = { return Api.StarRefProgram.parse_starRefProgram($0) }
907907
dict[-1145654109] = { return Api.StarsAmount.parse_starsAmount($0) }
908908
dict[1577421297] = { return Api.StarsGiftOption.parse_starsGiftOption($0) }
909909
dict[-1798404822] = { return Api.StarsGiveawayOption.parse_starsGiveawayOption($0) }
@@ -950,7 +950,6 @@ fileprivate let parsers: [Int32 : (BufferReader) -> Any?] = {
950950
dict[-1870436597] = { return Api.StoryView.parse_storyViewPublicForward($0) }
951951
dict[-1116418231] = { return Api.StoryView.parse_storyViewPublicRepost($0) }
952952
dict[-1923523370] = { return Api.StoryViews.parse_storyViews($0) }
953-
dict[642695037] = { return Api.SuggestedBotStarRef.parse_suggestedBotStarRef($0) }
954953
dict[1964978502] = { return Api.TextWithEntities.parse_textWithEntities($0) }
955954
dict[-1609668650] = { return Api.Theme.parse_theme($0) }
956955
dict[-94849324] = { return Api.ThemeSettings.parse_themeSettings($0) }
@@ -1371,7 +1370,7 @@ fileprivate let parsers: [Int32 : (BufferReader) -> Any?] = {
13711370
dict[-919881925] = { return Api.payments.StarsRevenueStats.parse_starsRevenueStats($0) }
13721371
dict[497778871] = { return Api.payments.StarsRevenueWithdrawalUrl.parse_starsRevenueWithdrawalUrl($0) }
13731372
dict[1822222573] = { return Api.payments.StarsStatus.parse_starsStatus($0) }
1374-
dict[-937776981] = { return Api.payments.SuggestedStarRefBots.parse_suggestedStarRefBots($0) }
1373+
dict[-1261053863] = { return Api.payments.SuggestedStarRefBots.parse_suggestedStarRefBots($0) }
13751374
dict[1801827607] = { return Api.payments.UserStarGifts.parse_userStarGifts($0) }
13761375
dict[-784000893] = { return Api.payments.ValidatedRequestedInfo.parse_validatedRequestedInfo($0) }
13771376
dict[541839704] = { return Api.phone.ExportedGroupCallInvite.parse_exportedGroupCallInvite($0) }
@@ -2111,8 +2110,6 @@ public extension Api {
21112110
_1.serialize(buffer, boxed)
21122111
case let _1 as Api.StoryViews:
21132112
_1.serialize(buffer, boxed)
2114-
case let _1 as Api.SuggestedBotStarRef:
2115-
_1.serialize(buffer, boxed)
21162113
case let _1 as Api.TextWithEntities:
21172114
_1.serialize(buffer, boxed)
21182115
case let _1 as Api.Theme:

submodules/TelegramApi/Sources/Api24.swift

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -644,44 +644,54 @@ public extension Api {
644644
}
645645
public extension Api {
646646
enum StarRefProgram: TypeConstructorDescription {
647-
case starRefProgram(flags: Int32, commissionPermille: Int32, durationMonths: Int32?, endDate: Int32?)
647+
case starRefProgram(flags: Int32, botId: Int64, commissionPermille: Int32, durationMonths: Int32?, endDate: Int32?, dailyRevenuePerUser: Api.StarsAmount?)
648648

649649
public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) {
650650
switch self {
651-
case .starRefProgram(let flags, let commissionPermille, let durationMonths, let endDate):
651+
case .starRefProgram(let flags, let botId, let commissionPermille, let durationMonths, let endDate, let dailyRevenuePerUser):
652652
if boxed {
653-
buffer.appendInt32(708628759)
653+
buffer.appendInt32(-586389774)
654654
}
655655
serializeInt32(flags, buffer: buffer, boxed: false)
656+
serializeInt64(botId, buffer: buffer, boxed: false)
656657
serializeInt32(commissionPermille, buffer: buffer, boxed: false)
657658
if Int(flags) & Int(1 << 0) != 0 {serializeInt32(durationMonths!, buffer: buffer, boxed: false)}
658659
if Int(flags) & Int(1 << 1) != 0 {serializeInt32(endDate!, buffer: buffer, boxed: false)}
660+
if Int(flags) & Int(1 << 2) != 0 {dailyRevenuePerUser!.serialize(buffer, true)}
659661
break
660662
}
661663
}
662664

663665
public func descriptionFields() -> (String, [(String, Any)]) {
664666
switch self {
665-
case .starRefProgram(let flags, let commissionPermille, let durationMonths, let endDate):
666-
return ("starRefProgram", [("flags", flags as Any), ("commissionPermille", commissionPermille as Any), ("durationMonths", durationMonths as Any), ("endDate", endDate as Any)])
667+
case .starRefProgram(let flags, let botId, let commissionPermille, let durationMonths, let endDate, let dailyRevenuePerUser):
668+
return ("starRefProgram", [("flags", flags as Any), ("botId", botId as Any), ("commissionPermille", commissionPermille as Any), ("durationMonths", durationMonths as Any), ("endDate", endDate as Any), ("dailyRevenuePerUser", dailyRevenuePerUser as Any)])
667669
}
668670
}
669671

670672
public static func parse_starRefProgram(_ reader: BufferReader) -> StarRefProgram? {
671673
var _1: Int32?
672674
_1 = reader.readInt32()
673-
var _2: Int32?
674-
_2 = reader.readInt32()
675+
var _2: Int64?
676+
_2 = reader.readInt64()
675677
var _3: Int32?
676-
if Int(_1!) & Int(1 << 0) != 0 {_3 = reader.readInt32() }
678+
_3 = reader.readInt32()
677679
var _4: Int32?
678-
if Int(_1!) & Int(1 << 1) != 0 {_4 = reader.readInt32() }
680+
if Int(_1!) & Int(1 << 0) != 0 {_4 = reader.readInt32() }
681+
var _5: Int32?
682+
if Int(_1!) & Int(1 << 1) != 0 {_5 = reader.readInt32() }
683+
var _6: Api.StarsAmount?
684+
if Int(_1!) & Int(1 << 2) != 0 {if let signature = reader.readInt32() {
685+
_6 = Api.parse(reader, signature: signature) as? Api.StarsAmount
686+
} }
679687
let _c1 = _1 != nil
680688
let _c2 = _2 != nil
681-
let _c3 = (Int(_1!) & Int(1 << 0) == 0) || _3 != nil
682-
let _c4 = (Int(_1!) & Int(1 << 1) == 0) || _4 != nil
683-
if _c1 && _c2 && _c3 && _c4 {
684-
return Api.StarRefProgram.starRefProgram(flags: _1!, commissionPermille: _2!, durationMonths: _3, endDate: _4)
689+
let _c3 = _3 != nil
690+
let _c4 = (Int(_1!) & Int(1 << 0) == 0) || _4 != nil
691+
let _c5 = (Int(_1!) & Int(1 << 1) == 0) || _5 != nil
692+
let _c6 = (Int(_1!) & Int(1 << 2) == 0) || _6 != nil
693+
if _c1 && _c2 && _c3 && _c4 && _c5 && _c6 {
694+
return Api.StarRefProgram.starRefProgram(flags: _1!, botId: _2!, commissionPermille: _3!, durationMonths: _4, endDate: _5, dailyRevenuePerUser: _6)
685695
}
686696
else {
687697
return nil

submodules/TelegramApi/Sources/Api26.swift

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -272,54 +272,6 @@ public extension Api {
272272

273273
}
274274
}
275-
public extension Api {
276-
enum SuggestedBotStarRef: TypeConstructorDescription {
277-
case suggestedBotStarRef(flags: Int32, botId: Int64, commissionPermille: Int32, durationMonths: Int32?)
278-
279-
public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) {
280-
switch self {
281-
case .suggestedBotStarRef(let flags, let botId, let commissionPermille, let durationMonths):
282-
if boxed {
283-
buffer.appendInt32(642695037)
284-
}
285-
serializeInt32(flags, buffer: buffer, boxed: false)
286-
serializeInt64(botId, buffer: buffer, boxed: false)
287-
serializeInt32(commissionPermille, buffer: buffer, boxed: false)
288-
if Int(flags) & Int(1 << 0) != 0 {serializeInt32(durationMonths!, buffer: buffer, boxed: false)}
289-
break
290-
}
291-
}
292-
293-
public func descriptionFields() -> (String, [(String, Any)]) {
294-
switch self {
295-
case .suggestedBotStarRef(let flags, let botId, let commissionPermille, let durationMonths):
296-
return ("suggestedBotStarRef", [("flags", flags as Any), ("botId", botId as Any), ("commissionPermille", commissionPermille as Any), ("durationMonths", durationMonths as Any)])
297-
}
298-
}
299-
300-
public static func parse_suggestedBotStarRef(_ reader: BufferReader) -> SuggestedBotStarRef? {
301-
var _1: Int32?
302-
_1 = reader.readInt32()
303-
var _2: Int64?
304-
_2 = reader.readInt64()
305-
var _3: Int32?
306-
_3 = reader.readInt32()
307-
var _4: Int32?
308-
if Int(_1!) & Int(1 << 0) != 0 {_4 = reader.readInt32() }
309-
let _c1 = _1 != nil
310-
let _c2 = _2 != nil
311-
let _c3 = _3 != nil
312-
let _c4 = (Int(_1!) & Int(1 << 0) == 0) || _4 != nil
313-
if _c1 && _c2 && _c3 && _c4 {
314-
return Api.SuggestedBotStarRef.suggestedBotStarRef(flags: _1!, botId: _2!, commissionPermille: _3!, durationMonths: _4)
315-
}
316-
else {
317-
return nil
318-
}
319-
}
320-
321-
}
322-
}
323275
public extension Api {
324276
enum TextWithEntities: TypeConstructorDescription {
325277
case textWithEntities(text: String, entities: [Api.MessageEntity])

submodules/TelegramApi/Sources/Api35.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -214,13 +214,13 @@ public extension Api.payments {
214214
}
215215
public extension Api.payments {
216216
enum SuggestedStarRefBots: TypeConstructorDescription {
217-
case suggestedStarRefBots(flags: Int32, count: Int32, suggestedBots: [Api.SuggestedBotStarRef], users: [Api.User], nextOffset: String?)
217+
case suggestedStarRefBots(flags: Int32, count: Int32, suggestedBots: [Api.StarRefProgram], users: [Api.User], nextOffset: String?)
218218

219219
public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) {
220220
switch self {
221221
case .suggestedStarRefBots(let flags, let count, let suggestedBots, let users, let nextOffset):
222222
if boxed {
223-
buffer.appendInt32(-937776981)
223+
buffer.appendInt32(-1261053863)
224224
}
225225
serializeInt32(flags, buffer: buffer, boxed: false)
226226
serializeInt32(count, buffer: buffer, boxed: false)
@@ -251,9 +251,9 @@ public extension Api.payments {
251251
_1 = reader.readInt32()
252252
var _2: Int32?
253253
_2 = reader.readInt32()
254-
var _3: [Api.SuggestedBotStarRef]?
254+
var _3: [Api.StarRefProgram]?
255255
if let _ = reader.readInt32() {
256-
_3 = Api.parseVector(reader, elementSignature: 0, elementType: Api.SuggestedBotStarRef.self)
256+
_3 = Api.parseVector(reader, elementSignature: 0, elementType: Api.StarRefProgram.self)
257257
}
258258
var _4: [Api.User]?
259259
if let _ = reader.readInt32() {

submodules/TelegramCore/Sources/SyncCore/SyncCore_CachedUserData.swift

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -627,17 +627,24 @@ extension TelegramBusinessChatLinks {
627627
}
628628

629629
public final class TelegramStarRefProgram: Codable, Equatable {
630+
public let botId: PeerId
630631
public let commissionPermille: Int32
631632
public let durationMonths: Int32?
632633
public let endDate: Int32?
634+
public let dailyRevenuePerUser: StarsAmount?
633635

634-
public init(commissionPermille: Int32, durationMonths: Int32?, endDate: Int32?) {
636+
public init(botId: PeerId, commissionPermille: Int32, durationMonths: Int32?, endDate: Int32?, dailyRevenuePerUser: StarsAmount?) {
637+
self.botId = botId
635638
self.commissionPermille = commissionPermille
636639
self.durationMonths = durationMonths
637640
self.endDate = endDate
641+
self.dailyRevenuePerUser = dailyRevenuePerUser
638642
}
639643

640644
public static func ==(lhs: TelegramStarRefProgram, rhs: TelegramStarRefProgram) -> Bool {
645+
if lhs.botId != rhs.botId {
646+
return false
647+
}
641648
if lhs.commissionPermille != rhs.commissionPermille {
642649
return false
643650
}
@@ -647,15 +654,18 @@ public final class TelegramStarRefProgram: Codable, Equatable {
647654
if lhs.endDate != rhs.endDate {
648655
return false
649656
}
657+
if lhs.dailyRevenuePerUser != rhs.dailyRevenuePerUser {
658+
return false
659+
}
650660
return true
651661
}
652662
}
653663

654664
extension TelegramStarRefProgram {
655665
convenience init(apiStarRefProgram: Api.StarRefProgram) {
656666
switch apiStarRefProgram {
657-
case let .starRefProgram(_, commissionPermille, durationMonths, endDate):
658-
self.init(commissionPermille: commissionPermille, durationMonths: durationMonths, endDate: endDate)
667+
case let .starRefProgram(_, botId, commissionPermille, durationMonths, endDate, dailyRevenuePerUser):
668+
self.init(botId: PeerId(namespace: Namespaces.Peer.CloudUser, id: PeerId.Id._internalFromInt64Value(botId)), commissionPermille: commissionPermille, durationMonths: durationMonths, endDate: endDate, dailyRevenuePerUser: dailyRevenuePerUser.flatMap(StarsAmount.init(apiAmount:)))
659669
}
660670
}
661671
}

submodules/TelegramCore/Sources/TelegramEngine/Messages/BotWebView.swift

Lines changed: 67 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -752,28 +752,24 @@ func _internal_requestConnectedStarRefBots(account: Account, id: EnginePeer.Id,
752752
public final class TelegramSuggestedStarRefBotList: Equatable {
753753
public enum SortMode {
754754
case date
755-
case commission
755+
case profitability
756+
case revenue
756757
}
757758

758759
public final class Item: Equatable {
759760
public let peer: EnginePeer
760-
public let commissionPermille: Int32
761-
public let durationMonths: Int32?
761+
public let program: TelegramStarRefProgram
762762

763-
public init(peer: EnginePeer, commissionPermille: Int32, durationMonths: Int32?) {
763+
public init(peer: EnginePeer, program: TelegramStarRefProgram) {
764764
self.peer = peer
765-
self.commissionPermille = commissionPermille
766-
self.durationMonths = durationMonths
765+
self.program = program
767766
}
768767

769768
public static func ==(lhs: Item, rhs: Item) -> Bool {
770769
if lhs.peer != rhs.peer {
771770
return false
772771
}
773-
if lhs.commissionPermille != rhs.commissionPermille {
774-
return false
775-
}
776-
if lhs.durationMonths != rhs.durationMonths {
772+
if lhs.program != rhs.program {
777773
return false
778774
}
779775
return true
@@ -795,7 +791,7 @@ public final class TelegramSuggestedStarRefBotList: Equatable {
795791
}
796792
}
797793

798-
func _internal_requestSuggestedStarRefBots(account: Account, id: EnginePeer.Id, orderByCommission: Bool, offset: String?, limit: Int) -> Signal<TelegramSuggestedStarRefBotList?, NoError> {
794+
func _internal_requestSuggestedStarRefBots(account: Account, id: EnginePeer.Id, sortMode: TelegramSuggestedStarRefBotList.SortMode, offset: String?, limit: Int) -> Signal<TelegramSuggestedStarRefBotList?, NoError> {
799795
return account.postbox.transaction { transaction -> Api.InputPeer? in
800796
return transaction.getPeer(id).flatMap(apiInputPeer)
801797
}
@@ -804,8 +800,13 @@ func _internal_requestSuggestedStarRefBots(account: Account, id: EnginePeer.Id,
804800
return .single(nil)
805801
}
806802
var flags: Int32 = 0
807-
if orderByCommission {
808-
flags |= 1 << 2
803+
switch sortMode {
804+
case .revenue:
805+
flags |= 1 << 0
806+
case .date:
807+
flags |= 1 << 1
808+
case .profitability:
809+
break
809810
}
810811
return account.network.request(Api.functions.payments.getSuggestedStarRefBots(
811812
flags: flags,
@@ -827,18 +828,15 @@ func _internal_requestSuggestedStarRefBots(account: Account, id: EnginePeer.Id,
827828
updatePeers(transaction: transaction, accountPeerId: account.peerId, peers: AccumulatedPeers(users: users))
828829

829830
var items: [TelegramSuggestedStarRefBotList.Item] = []
830-
for suggestedBot in suggestedBots {
831-
switch suggestedBot {
832-
case let .suggestedBotStarRef(_, botId, commissionPermille, durationMonths):
833-
guard let botPeer = transaction.getPeer(PeerId(namespace: Namespaces.Peer.CloudUser, id: PeerId.Id._internalFromInt64Value(botId))) else {
834-
continue
835-
}
836-
items.append(TelegramSuggestedStarRefBotList.Item(
837-
peer: EnginePeer(botPeer),
838-
commissionPermille: commissionPermille,
839-
durationMonths: durationMonths
840-
))
831+
for starRefProgram in suggestedBots {
832+
let parsedProgram = TelegramStarRefProgram(apiStarRefProgram: starRefProgram)
833+
guard let botPeer = transaction.getPeer(parsedProgram.botId) else {
834+
continue
841835
}
836+
items.append(TelegramSuggestedStarRefBotList.Item(
837+
peer: EnginePeer(botPeer),
838+
program: parsedProgram
839+
))
842840
}
843841

844842
return TelegramSuggestedStarRefBotList(items: items, totalCount: Int(count), nextOffset: nextOffset)
@@ -1010,3 +1008,48 @@ func _internal_getStarRefBotConnection(account: Account, id: EnginePeer.Id, targ
10101008
}
10111009
}
10121010
}
1011+
1012+
func _internal_getPossibleStarRefBotTargets(account: Account) -> Signal<[EnginePeer], NoError> {
1013+
return combineLatest(
1014+
account.network.request(Api.functions.bots.getAdminedBots())
1015+
|> `catch` { _ -> Signal<[Api.User], NoError> in
1016+
return .single([])
1017+
},
1018+
account.network.request(Api.functions.channels.getAdminedPublicChannels(flags: 0))
1019+
|> map(Optional.init)
1020+
|> `catch` { _ -> Signal<Api.messages.Chats?, NoError> in
1021+
return .single(nil)
1022+
}
1023+
)
1024+
|> mapToSignal { apiBots, apiChannels -> Signal<[EnginePeer], NoError> in
1025+
return account.postbox.transaction { transaction -> [EnginePeer] in
1026+
var result: [EnginePeer] = []
1027+
1028+
if let peer = transaction.getPeer(account.peerId) {
1029+
result.append(EnginePeer(peer))
1030+
}
1031+
1032+
updatePeers(transaction: transaction, accountPeerId: account.peerId, peers: AccumulatedPeers(users: apiBots))
1033+
for bot in apiBots {
1034+
if let peer = transaction.getPeer(bot.peerId) {
1035+
result.append(EnginePeer(peer))
1036+
}
1037+
}
1038+
1039+
if let apiChannels {
1040+
switch apiChannels {
1041+
case let .chats(chats), let .chatsSlice(_, chats):
1042+
updatePeers(transaction: transaction, accountPeerId: account.peerId, peers: AccumulatedPeers(chats: chats, users: []))
1043+
1044+
for chat in chats {
1045+
if let peer = transaction.getPeer(chat.peerId) {
1046+
result.append(EnginePeer(peer))
1047+
}
1048+
}
1049+
}
1050+
}
1051+
1052+
return result
1053+
}
1054+
}
1055+
}

0 commit comments

Comments
 (0)