mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-06-16 05:55:20 +00:00
Improvements
This commit is contained in:
parent
7ae4c0159a
commit
834089efa5
@ -1632,19 +1632,32 @@ final class ChatListSearchListPaneNode: ASDisplayNode, ChatListSearchPaneNode {
|
||||
return (peers: peers, unread: unread, recentlySearchedPeerIds: recentlySearchedPeerIds)
|
||||
}
|
||||
} else if let query = query, key == .channels {
|
||||
foundLocalPeers = context.engine.contacts.searchLocalPeers(query: query.lowercased(), scope: .channels)
|
||||
|> mapToSignal { local -> Signal<([EnginePeer.Id: Optional<EnginePeer.NotificationSettings>], [EnginePeer.Id: Int], [EngineRenderedPeer], EngineGlobalNotificationSettings), NoError> in
|
||||
var peerIds = Set<EnginePeer.Id>()
|
||||
var peers: [EngineRenderedPeer] = []
|
||||
foundLocalPeers = combineLatest(
|
||||
context.engine.contacts.searchLocalPeers(query: query.lowercased(), scope: .channels),
|
||||
context.engine.peers.recommendedChannelPeerIds(peerId: nil)
|
||||
)
|
||||
|> mapToSignal { local, recommended -> Signal<(peers: [EngineRenderedPeer], unread: [EnginePeer.Id: (Int32, Bool)], recentlySearchedPeerIds: Set<EnginePeer.Id>), NoError> in
|
||||
var peerIds: [EnginePeer.Id] = []
|
||||
|
||||
for peer in local {
|
||||
if !peerIds.contains(peer.peerId) {
|
||||
peerIds.insert(peer.peerId)
|
||||
peers.append(peer)
|
||||
peerIds.append(peer.peerId)
|
||||
}
|
||||
}
|
||||
if let recommended {
|
||||
for id in recommended {
|
||||
if !peerIds.contains(id) {
|
||||
peerIds.append(id)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return context.engine.data.subscribe(
|
||||
EngineDataMap(
|
||||
peerIds.map { peerId -> TelegramEngine.EngineData.Item.Peer.Peer in
|
||||
return TelegramEngine.EngineData.Item.Peer.Peer(id: peerId)
|
||||
}
|
||||
),
|
||||
EngineDataMap(
|
||||
peerIds.map { peerId -> TelegramEngine.EngineData.Item.Peer.NotificationSettings in
|
||||
return TelegramEngine.EngineData.Item.Peer.NotificationSettings(id: peerId)
|
||||
@ -1657,19 +1670,42 @@ final class ChatListSearchListPaneNode: ASDisplayNode, ChatListSearchPaneNode {
|
||||
),
|
||||
TelegramEngine.EngineData.Item.NotificationSettings.Global()
|
||||
)
|
||||
|> map { notificationSettings, unreadCounts, globalNotificationSettings in
|
||||
return (notificationSettings, unreadCounts, peers, globalNotificationSettings)
|
||||
}
|
||||
}
|
||||
|> map { notificationSettings, unreadCounts, peers, globalNotificationSettings -> (peers: [EngineRenderedPeer], unread: [EnginePeer.Id: (Int32, Bool)], recentlySearchedPeerIds: Set<EnginePeer.Id>) in
|
||||
var unread: [EnginePeer.Id: (Int32, Bool)] = [:]
|
||||
for peer in peers {
|
||||
var isMuted = false
|
||||
if let peerNotificationSettings = notificationSettings[peer.peerId], let peerNotificationSettings {
|
||||
if case let .muted(until) = peerNotificationSettings.muteState, until >= Int32(CFAbsoluteTimeGetCurrent() + NSTimeIntervalSince1970) {
|
||||
isMuted = true
|
||||
} else if case .default = peerNotificationSettings.muteState {
|
||||
if let peer = peer.peer {
|
||||
|> map { peers, notificationSettings, unreadCounts, globalNotificationSettings -> (peers: [EngineRenderedPeer], unread: [EnginePeer.Id: (Int32, Bool)], recentlySearchedPeerIds: Set<EnginePeer.Id>) in
|
||||
var resultPeers: [EngineRenderedPeer] = []
|
||||
var unread: [EnginePeer.Id: (Int32, Bool)] = [:]
|
||||
|
||||
var matchingIds: [EnginePeer.Id] = []
|
||||
for peer in local {
|
||||
if !matchingIds.contains(peer.peerId) {
|
||||
matchingIds.append(peer.peerId)
|
||||
}
|
||||
}
|
||||
|
||||
let queryTokens = stringIndexTokens(query.lowercased(), transliteration: .combined)
|
||||
if let recommended {
|
||||
for id in recommended {
|
||||
guard let maybePeer = peers[id], let peer = maybePeer else {
|
||||
continue
|
||||
}
|
||||
|
||||
if peer.indexName.matchesByTokens(queryTokens) {
|
||||
if !matchingIds.contains(id) {
|
||||
matchingIds.append(id)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for id in matchingIds {
|
||||
guard let maybePeer = peers[id], let peer = maybePeer else {
|
||||
continue
|
||||
}
|
||||
resultPeers.append(EngineRenderedPeer(peer: peer))
|
||||
var isMuted = false
|
||||
if let peerNotificationSettings = notificationSettings[peer.id] {
|
||||
if case let .muted(until) = peerNotificationSettings.muteState, until >= Int32(CFAbsoluteTimeGetCurrent() + NSTimeIntervalSince1970) {
|
||||
isMuted = true
|
||||
} else if case .default = peerNotificationSettings.muteState {
|
||||
if case .user = peer {
|
||||
isMuted = !globalNotificationSettings.privateChats.enabled
|
||||
} else if case .legacyGroup = peer {
|
||||
@ -1684,13 +1720,13 @@ final class ChatListSearchListPaneNode: ASDisplayNode, ChatListSearchPaneNode {
|
||||
}
|
||||
}
|
||||
}
|
||||
let unreadCount = unreadCounts[peer.id]
|
||||
if let unreadCount = unreadCount, unreadCount > 0 {
|
||||
unread[peer.id] = (Int32(unreadCount), isMuted)
|
||||
}
|
||||
}
|
||||
let unreadCount = unreadCounts[peer.peerId]
|
||||
if let unreadCount = unreadCount, unreadCount > 0 {
|
||||
unread[peer.peerId] = (Int32(unreadCount), isMuted)
|
||||
}
|
||||
return (peers: resultPeers, unread: unread, recentlySearchedPeerIds: Set())
|
||||
}
|
||||
return (peers: peers, unread: unread, recentlySearchedPeerIds: Set())
|
||||
}
|
||||
} else {
|
||||
foundLocalPeers = .single((peers: [], unread: [:], recentlySearchedPeerIds: Set()))
|
||||
@ -2807,6 +2843,10 @@ final class ChatListSearchListPaneNode: ASDisplayNode, ChatListSearchPaneNode {
|
||||
let toggleChannelsTabExpanded: () -> Void = {
|
||||
let _ = (isChannelsTabExpandedValue.get() |> take(1)).startStandalone(next: { value in
|
||||
isChannelsTabExpandedValue.set(!value)
|
||||
|
||||
Queue.mainQueue().async {
|
||||
interaction.dismissInput()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -70,6 +70,25 @@ extension PeerIndexNameRepresentation {
|
||||
return foundAtLeastOne
|
||||
}
|
||||
|
||||
public func matchesByTokens(_ other: [ValueBoxKey]) -> Bool {
|
||||
var foundAtLeastOne = false
|
||||
for searchToken in other {
|
||||
var found = false
|
||||
for token in self.indexTokens {
|
||||
if searchToken.isPrefix(to: token) {
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
return false
|
||||
}
|
||||
foundAtLeastOne = true
|
||||
break
|
||||
}
|
||||
return foundAtLeastOne
|
||||
}
|
||||
|
||||
public var indexTokens: [ValueBoxKey] {
|
||||
switch self {
|
||||
case let .title(title, addressNames):
|
||||
|
@ -750,6 +750,9 @@ fileprivate let parsers: [Int32 : (BufferReader) -> Any?] = {
|
||||
dict[455247544] = { return Api.Reaction.parse_reactionEmoji($0) }
|
||||
dict[2046153753] = { return Api.Reaction.parse_reactionEmpty($0) }
|
||||
dict[-1546531968] = { return Api.ReactionCount.parse_reactionCount($0) }
|
||||
dict[1268654752] = { return Api.ReactionNotificationsFrom.parse_reactionNotificationsFromAll($0) }
|
||||
dict[-1161583078] = { return Api.ReactionNotificationsFrom.parse_reactionNotificationsFromContacts($0) }
|
||||
dict[1457736048] = { return Api.ReactionsNotifySettings.parse_reactionsNotifySettings($0) }
|
||||
dict[1246753138] = { return Api.ReadParticipantDate.parse_readParticipantDate($0) }
|
||||
dict[-1551583367] = { return Api.ReceivedNotifyMessage.parse_receivedNotifyMessage($0) }
|
||||
dict[-1294306862] = { return Api.RecentMeUrl.parse_recentMeUrlChat($0) }
|
||||
@ -984,6 +987,7 @@ fileprivate let parsers: [Int32 : (BufferReader) -> Any?] = {
|
||||
dict[-180508905] = { return Api.Update.parse_updateNewQuickReply($0) }
|
||||
dict[967122427] = { return Api.Update.parse_updateNewScheduledMessage($0) }
|
||||
dict[1753886890] = { return Api.Update.parse_updateNewStickerSet($0) }
|
||||
dict[405070859] = { return Api.Update.parse_updateNewStoryReaction($0) }
|
||||
dict[-1094555409] = { return Api.Update.parse_updateNotifySettings($0) }
|
||||
dict[-337610926] = { return Api.Update.parse_updatePeerBlocked($0) }
|
||||
dict[-1147422299] = { return Api.Update.parse_updatePeerHistoryTTL($0) }
|
||||
@ -1352,7 +1356,7 @@ public extension Api {
|
||||
return parser(reader)
|
||||
}
|
||||
else {
|
||||
telegramApiLog("Type constructor \(String(signature, radix: 16, uppercase: false)) not found")
|
||||
telegramApiLog("Type constructor \(String(UInt32(bitPattern: signature), radix: 16, uppercase: false)) not found")
|
||||
return nil
|
||||
}
|
||||
}
|
||||
@ -1868,6 +1872,10 @@ public extension Api {
|
||||
_1.serialize(buffer, boxed)
|
||||
case let _1 as Api.ReactionCount:
|
||||
_1.serialize(buffer, boxed)
|
||||
case let _1 as Api.ReactionNotificationsFrom:
|
||||
_1.serialize(buffer, boxed)
|
||||
case let _1 as Api.ReactionsNotifySettings:
|
||||
_1.serialize(buffer, boxed)
|
||||
case let _1 as Api.ReadParticipantDate:
|
||||
_1.serialize(buffer, boxed)
|
||||
case let _1 as Api.ReceivedNotifyMessage:
|
||||
|
@ -422,6 +422,106 @@ public extension Api {
|
||||
|
||||
}
|
||||
}
|
||||
public extension Api {
|
||||
enum ReactionNotificationsFrom: TypeConstructorDescription {
|
||||
case reactionNotificationsFromAll
|
||||
case reactionNotificationsFromContacts
|
||||
|
||||
public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) {
|
||||
switch self {
|
||||
case .reactionNotificationsFromAll:
|
||||
if boxed {
|
||||
buffer.appendInt32(1268654752)
|
||||
}
|
||||
|
||||
break
|
||||
case .reactionNotificationsFromContacts:
|
||||
if boxed {
|
||||
buffer.appendInt32(-1161583078)
|
||||
}
|
||||
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
public func descriptionFields() -> (String, [(String, Any)]) {
|
||||
switch self {
|
||||
case .reactionNotificationsFromAll:
|
||||
return ("reactionNotificationsFromAll", [])
|
||||
case .reactionNotificationsFromContacts:
|
||||
return ("reactionNotificationsFromContacts", [])
|
||||
}
|
||||
}
|
||||
|
||||
public static func parse_reactionNotificationsFromAll(_ reader: BufferReader) -> ReactionNotificationsFrom? {
|
||||
return Api.ReactionNotificationsFrom.reactionNotificationsFromAll
|
||||
}
|
||||
public static func parse_reactionNotificationsFromContacts(_ reader: BufferReader) -> ReactionNotificationsFrom? {
|
||||
return Api.ReactionNotificationsFrom.reactionNotificationsFromContacts
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
public extension Api {
|
||||
enum ReactionsNotifySettings: TypeConstructorDescription {
|
||||
case reactionsNotifySettings(flags: Int32, messagesNotifyFrom: Api.ReactionNotificationsFrom?, storiesNotifyFrom: Api.ReactionNotificationsFrom?, sound: Api.NotificationSound, showPreviews: Api.Bool)
|
||||
|
||||
public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) {
|
||||
switch self {
|
||||
case .reactionsNotifySettings(let flags, let messagesNotifyFrom, let storiesNotifyFrom, let sound, let showPreviews):
|
||||
if boxed {
|
||||
buffer.appendInt32(1457736048)
|
||||
}
|
||||
serializeInt32(flags, buffer: buffer, boxed: false)
|
||||
if Int(flags) & Int(1 << 0) != 0 {messagesNotifyFrom!.serialize(buffer, true)}
|
||||
if Int(flags) & Int(1 << 1) != 0 {storiesNotifyFrom!.serialize(buffer, true)}
|
||||
sound.serialize(buffer, true)
|
||||
showPreviews.serialize(buffer, true)
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
public func descriptionFields() -> (String, [(String, Any)]) {
|
||||
switch self {
|
||||
case .reactionsNotifySettings(let flags, let messagesNotifyFrom, let storiesNotifyFrom, let sound, let showPreviews):
|
||||
return ("reactionsNotifySettings", [("flags", flags as Any), ("messagesNotifyFrom", messagesNotifyFrom as Any), ("storiesNotifyFrom", storiesNotifyFrom as Any), ("sound", sound as Any), ("showPreviews", showPreviews as Any)])
|
||||
}
|
||||
}
|
||||
|
||||
public static func parse_reactionsNotifySettings(_ reader: BufferReader) -> ReactionsNotifySettings? {
|
||||
var _1: Int32?
|
||||
_1 = reader.readInt32()
|
||||
var _2: Api.ReactionNotificationsFrom?
|
||||
if Int(_1!) & Int(1 << 0) != 0 {if let signature = reader.readInt32() {
|
||||
_2 = Api.parse(reader, signature: signature) as? Api.ReactionNotificationsFrom
|
||||
} }
|
||||
var _3: Api.ReactionNotificationsFrom?
|
||||
if Int(_1!) & Int(1 << 1) != 0 {if let signature = reader.readInt32() {
|
||||
_3 = Api.parse(reader, signature: signature) as? Api.ReactionNotificationsFrom
|
||||
} }
|
||||
var _4: Api.NotificationSound?
|
||||
if let signature = reader.readInt32() {
|
||||
_4 = Api.parse(reader, signature: signature) as? Api.NotificationSound
|
||||
}
|
||||
var _5: Api.Bool?
|
||||
if let signature = reader.readInt32() {
|
||||
_5 = Api.parse(reader, signature: signature) as? Api.Bool
|
||||
}
|
||||
let _c1 = _1 != nil
|
||||
let _c2 = (Int(_1!) & Int(1 << 0) == 0) || _2 != nil
|
||||
let _c3 = (Int(_1!) & Int(1 << 1) == 0) || _3 != nil
|
||||
let _c4 = _4 != nil
|
||||
let _c5 = _5 != nil
|
||||
if _c1 && _c2 && _c3 && _c4 && _c5 {
|
||||
return Api.ReactionsNotifySettings.reactionsNotifySettings(flags: _1!, messagesNotifyFrom: _2, storiesNotifyFrom: _3, sound: _4!, showPreviews: _5!)
|
||||
}
|
||||
else {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
public extension Api {
|
||||
enum ReadParticipantDate: TypeConstructorDescription {
|
||||
case readParticipantDate(userId: Int64, date: Int32)
|
||||
|
@ -134,6 +134,7 @@ public extension Api {
|
||||
case updateNewQuickReply(quickReply: Api.QuickReply)
|
||||
case updateNewScheduledMessage(message: Api.Message)
|
||||
case updateNewStickerSet(stickerset: Api.messages.StickerSet)
|
||||
case updateNewStoryReaction(storyId: Int32, peer: Api.Peer, reaction: Api.Reaction)
|
||||
case updateNotifySettings(peer: Api.NotifyPeer, notifySettings: Api.PeerNotifySettings)
|
||||
case updatePeerBlocked(flags: Int32, peerId: Api.Peer)
|
||||
case updatePeerHistoryTTL(flags: Int32, peer: Api.Peer, ttlPeriod: Int32?)
|
||||
@ -919,6 +920,14 @@ public extension Api {
|
||||
}
|
||||
stickerset.serialize(buffer, true)
|
||||
break
|
||||
case .updateNewStoryReaction(let storyId, let peer, let reaction):
|
||||
if boxed {
|
||||
buffer.appendInt32(405070859)
|
||||
}
|
||||
serializeInt32(storyId, buffer: buffer, boxed: false)
|
||||
peer.serialize(buffer, true)
|
||||
reaction.serialize(buffer, true)
|
||||
break
|
||||
case .updateNotifySettings(let peer, let notifySettings):
|
||||
if boxed {
|
||||
buffer.appendInt32(-1094555409)
|
||||
@ -1521,6 +1530,8 @@ public extension Api {
|
||||
return ("updateNewScheduledMessage", [("message", message as Any)])
|
||||
case .updateNewStickerSet(let stickerset):
|
||||
return ("updateNewStickerSet", [("stickerset", stickerset as Any)])
|
||||
case .updateNewStoryReaction(let storyId, let peer, let reaction):
|
||||
return ("updateNewStoryReaction", [("storyId", storyId as Any), ("peer", peer as Any), ("reaction", reaction as Any)])
|
||||
case .updateNotifySettings(let peer, let notifySettings):
|
||||
return ("updateNotifySettings", [("peer", peer as Any), ("notifySettings", notifySettings as Any)])
|
||||
case .updatePeerBlocked(let flags, let peerId):
|
||||
@ -3166,6 +3177,27 @@ public extension Api {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
public static func parse_updateNewStoryReaction(_ reader: BufferReader) -> Update? {
|
||||
var _1: Int32?
|
||||
_1 = reader.readInt32()
|
||||
var _2: Api.Peer?
|
||||
if let signature = reader.readInt32() {
|
||||
_2 = Api.parse(reader, signature: signature) as? Api.Peer
|
||||
}
|
||||
var _3: Api.Reaction?
|
||||
if let signature = reader.readInt32() {
|
||||
_3 = Api.parse(reader, signature: signature) as? Api.Reaction
|
||||
}
|
||||
let _c1 = _1 != nil
|
||||
let _c2 = _2 != nil
|
||||
let _c3 = _3 != nil
|
||||
if _c1 && _c2 && _c3 {
|
||||
return Api.Update.updateNewStoryReaction(storyId: _1!, peer: _2!, reaction: _3!)
|
||||
}
|
||||
else {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
public static func parse_updateNotifySettings(_ reader: BufferReader) -> Update? {
|
||||
var _1: Api.NotifyPeer?
|
||||
if let signature = reader.readInt32() {
|
||||
|
@ -679,6 +679,21 @@ public extension Api.functions.account {
|
||||
})
|
||||
}
|
||||
}
|
||||
public extension Api.functions.account {
|
||||
static func getReactionsNotifySettings() -> (FunctionDescription, Buffer, DeserializeFunctionResponse<Api.ReactionsNotifySettings>) {
|
||||
let buffer = Buffer()
|
||||
buffer.appendInt32(115172684)
|
||||
|
||||
return (FunctionDescription(name: "account.getReactionsNotifySettings", parameters: []), buffer, DeserializeFunctionResponse { (buffer: Buffer) -> Api.ReactionsNotifySettings? in
|
||||
let reader = BufferReader(buffer)
|
||||
var result: Api.ReactionsNotifySettings?
|
||||
if let signature = reader.readInt32() {
|
||||
result = Api.parse(reader, signature: signature) as? Api.ReactionsNotifySettings
|
||||
}
|
||||
return result
|
||||
})
|
||||
}
|
||||
}
|
||||
public extension Api.functions.account {
|
||||
static func getRecentEmojiStatuses(hash: Int64) -> (FunctionDescription, Buffer, DeserializeFunctionResponse<Api.account.EmojiStatuses>) {
|
||||
let buffer = Buffer()
|
||||
@ -1345,6 +1360,21 @@ public extension Api.functions.account {
|
||||
})
|
||||
}
|
||||
}
|
||||
public extension Api.functions.account {
|
||||
static func setReactionsNotifySettings(settings: Api.ReactionsNotifySettings) -> (FunctionDescription, Buffer, DeserializeFunctionResponse<Api.ReactionsNotifySettings>) {
|
||||
let buffer = Buffer()
|
||||
buffer.appendInt32(829220168)
|
||||
settings.serialize(buffer, true)
|
||||
return (FunctionDescription(name: "account.setReactionsNotifySettings", parameters: [("settings", String(describing: settings))]), buffer, DeserializeFunctionResponse { (buffer: Buffer) -> Api.ReactionsNotifySettings? in
|
||||
let reader = BufferReader(buffer)
|
||||
var result: Api.ReactionsNotifySettings?
|
||||
if let signature = reader.readInt32() {
|
||||
result = Api.parse(reader, signature: signature) as? Api.ReactionsNotifySettings
|
||||
}
|
||||
return result
|
||||
})
|
||||
}
|
||||
}
|
||||
public extension Api.functions.account {
|
||||
static func toggleConnectedBotPaused(peer: Api.InputPeer, paused: Api.Bool) -> (FunctionDescription, Buffer, DeserializeFunctionResponse<Api.Bool>) {
|
||||
let buffer = Buffer()
|
||||
@ -10265,15 +10295,16 @@ public extension Api.functions.stories {
|
||||
}
|
||||
}
|
||||
public extension Api.functions.stories {
|
||||
static func togglePinnedToTop(id: [Int32]) -> (FunctionDescription, Buffer, DeserializeFunctionResponse<Api.Bool>) {
|
||||
static func togglePinnedToTop(peer: Api.InputPeer, id: [Int32]) -> (FunctionDescription, Buffer, DeserializeFunctionResponse<Api.Bool>) {
|
||||
let buffer = Buffer()
|
||||
buffer.appendInt32(1634169010)
|
||||
buffer.appendInt32(187268763)
|
||||
peer.serialize(buffer, true)
|
||||
buffer.appendInt32(481674261)
|
||||
buffer.appendInt32(Int32(id.count))
|
||||
for item in id {
|
||||
serializeInt32(item, buffer: buffer, boxed: false)
|
||||
}
|
||||
return (FunctionDescription(name: "stories.togglePinnedToTop", parameters: [("id", String(describing: id))]), buffer, DeserializeFunctionResponse { (buffer: Buffer) -> Api.Bool? in
|
||||
return (FunctionDescription(name: "stories.togglePinnedToTop", parameters: [("peer", String(describing: peer)), ("id", String(describing: id))]), buffer, DeserializeFunctionResponse { (buffer: Buffer) -> Api.Bool? in
|
||||
let reader = BufferReader(buffer)
|
||||
var result: Api.Bool?
|
||||
if let signature = reader.readInt32() {
|
||||
|
@ -110,10 +110,11 @@ private func fetchedNotificationSettings(network: Network) -> Signal<GlobalNotif
|
||||
let users = network.request(Api.functions.account.getNotifySettings(peer: Api.InputNotifyPeer.inputNotifyUsers))
|
||||
let channels = network.request(Api.functions.account.getNotifySettings(peer: Api.InputNotifyPeer.inputNotifyBroadcasts))
|
||||
let contactsJoinedMuted = network.request(Api.functions.account.getContactSignUpNotification())
|
||||
let reactions = network.request(Api.functions.account.getReactionsNotifySettings())
|
||||
|
||||
return combineLatest(chats, users, channels, contactsJoinedMuted)
|
||||
return combineLatest(chats, users, channels, contactsJoinedMuted, reactions)
|
||||
|> retryRequest
|
||||
|> map { chats, users, channels, contactsJoinedMuted in
|
||||
|> map { chats, users, channels, contactsJoinedMuted, reactions in
|
||||
let chatsSettings: MessageNotificationSettings
|
||||
switch chats {
|
||||
case let .peerNotifySettings(_, showPreviews, _, muteUntil, iosSound, _, desktopSound, storiesMuted, storiesHideSender, storiesIosSound, _, storiesDesktopSound):
|
||||
@ -270,7 +271,40 @@ private func fetchedNotificationSettings(network: Network) -> Signal<GlobalNotif
|
||||
)
|
||||
}
|
||||
|
||||
let reactionSettings: PeerReactionNotificationSettings = .default
|
||||
let reactionSettings: PeerReactionNotificationSettings
|
||||
switch reactions {
|
||||
case let .reactionsNotifySettings(_, messagesNotifyFrom, storiesNotifyFrom, sound, showPreviews):
|
||||
let mappedMessages: PeerReactionNotificationSettings.Sources
|
||||
if let messagesNotifyFrom {
|
||||
switch messagesNotifyFrom {
|
||||
case .reactionNotificationsFromAll:
|
||||
mappedMessages = .everyone
|
||||
case .reactionNotificationsFromContacts:
|
||||
mappedMessages = .contacts
|
||||
}
|
||||
} else {
|
||||
mappedMessages = .nobody
|
||||
}
|
||||
|
||||
let mappedStories: PeerReactionNotificationSettings.Sources
|
||||
if let storiesNotifyFrom {
|
||||
switch storiesNotifyFrom {
|
||||
case .reactionNotificationsFromAll:
|
||||
mappedStories = .everyone
|
||||
case .reactionNotificationsFromContacts:
|
||||
mappedStories = .contacts
|
||||
}
|
||||
} else {
|
||||
mappedStories = .nobody
|
||||
}
|
||||
|
||||
reactionSettings = PeerReactionNotificationSettings(
|
||||
messages: mappedMessages,
|
||||
stories: mappedStories,
|
||||
hideSender: showPreviews == .boolFalse ? .hide : .show,
|
||||
sound: PeerMessageSound(apiSound: sound)
|
||||
)
|
||||
}
|
||||
|
||||
return GlobalNotificationSettingsSet(privateChats: userSettings, groupChats: chatsSettings, channels: channelSettings, reactionSettings: reactionSettings, contactsJoined: contactsJoinedMuted == .boolFalse)
|
||||
}
|
||||
@ -348,6 +382,47 @@ private func pushedNotificationSettings(network: Network, settings: GlobalNotifi
|
||||
return .single(.boolFalse)
|
||||
}
|
||||
|
||||
return combineLatest(pushedChats, pushedUsers, pushedChannels, pushedContactsJoined)
|
||||
var reactionFlags: Int32 = 0
|
||||
|
||||
var reactionsMessages: Api.ReactionNotificationsFrom?
|
||||
switch settings.reactionSettings.messages {
|
||||
case .nobody:
|
||||
break
|
||||
case .everyone:
|
||||
reactionsMessages = .reactionNotificationsFromAll
|
||||
case .contacts:
|
||||
reactionsMessages = .reactionNotificationsFromContacts
|
||||
}
|
||||
if reactionsMessages != nil {
|
||||
reactionFlags |= 1 << 0
|
||||
}
|
||||
|
||||
var reactionsStories: Api.ReactionNotificationsFrom?
|
||||
switch settings.reactionSettings.stories {
|
||||
case .nobody:
|
||||
break
|
||||
case .everyone:
|
||||
reactionsStories = .reactionNotificationsFromAll
|
||||
case .contacts:
|
||||
reactionsStories = .reactionNotificationsFromContacts
|
||||
}
|
||||
if reactionsStories != nil {
|
||||
reactionFlags |= 1 << 1
|
||||
}
|
||||
|
||||
let inputReactionSettings: Api.ReactionsNotifySettings = .reactionsNotifySettings(
|
||||
flags: reactionFlags,
|
||||
messagesNotifyFrom: reactionsMessages,
|
||||
storiesNotifyFrom: reactionsStories,
|
||||
sound: settings.reactionSettings.sound.apiSound,
|
||||
showPreviews: settings.reactionSettings.hideSender == .hide ? .boolFalse : .boolTrue
|
||||
)
|
||||
let pushedReactions = network.request(Api.functions.account.setReactionsNotifySettings(settings: inputReactionSettings))
|
||||
|> map(Optional.init)
|
||||
|> `catch` { _ -> Signal<Api.ReactionsNotifySettings?, NoError> in
|
||||
return .single(nil)
|
||||
}
|
||||
|
||||
return combineLatest(pushedChats, pushedUsers, pushedChannels, pushedContactsJoined, pushedReactions)
|
||||
|> mapToSignal { _ -> Signal<Void, NoError> in return .complete() }
|
||||
}
|
||||
|
@ -1693,8 +1693,11 @@ func _internal_updatePinnedToTopStories(account: Account, peerId: PeerId, ids: [
|
||||
|
||||
return inputPeer
|
||||
}
|
||||
|> mapToSignal { _ -> Signal<Never, NoError> in
|
||||
return account.network.request(Api.functions.stories.togglePinnedToTop(id: ids))
|
||||
|> mapToSignal { inputPeer -> Signal<Never, NoError> in
|
||||
guard let inputPeer else {
|
||||
return .complete()
|
||||
}
|
||||
return account.network.request(Api.functions.stories.togglePinnedToTop(peer: inputPeer, id: ids))
|
||||
|> `catch` { _ -> Signal<Api.Bool, NoError> in
|
||||
return .single(.boolFalse)
|
||||
}
|
||||
|
@ -145,6 +145,17 @@ public struct RecommendedChannels: Equatable {
|
||||
public let isHidden: Bool
|
||||
}
|
||||
|
||||
func _internal_recommendedChannelPeerIds(account: Account, peerId: EnginePeer.Id?) -> Signal<[EnginePeer.Id]?, NoError> {
|
||||
let key = PostboxViewKey.cachedItem(entryId(peerId: peerId))
|
||||
return account.postbox.combinedView(keys: [key])
|
||||
|> mapToSignal { views -> Signal<[EnginePeer.Id]?, NoError> in
|
||||
guard let cachedChannels = (views.views[key] as? CachedItemView)?.value?.get(CachedRecommendedChannels.self), !cachedChannels.peerIds.isEmpty else {
|
||||
return .single(nil)
|
||||
}
|
||||
return .single(cachedChannels.peerIds)
|
||||
}
|
||||
}
|
||||
|
||||
func _internal_recommendedChannels(account: Account, peerId: EnginePeer.Id?) -> Signal<RecommendedChannels?, NoError> {
|
||||
let key = PostboxViewKey.cachedItem(entryId(peerId: peerId))
|
||||
return account.postbox.combinedView(keys: [key])
|
||||
|
@ -435,6 +435,10 @@ public extension EnginePeer.IndexName {
|
||||
func matchesByTokens(_ other: String) -> Bool {
|
||||
return self._asIndexName().matchesByTokens(other)
|
||||
}
|
||||
|
||||
func matchesByTokens(_ other: [ValueBoxKey]) -> Bool {
|
||||
return self._asIndexName().matchesByTokens(other)
|
||||
}
|
||||
|
||||
func stringRepresentation(lastNameFirst: Bool) -> String {
|
||||
switch self {
|
||||
|
@ -1373,6 +1373,10 @@ public extension TelegramEngine {
|
||||
return _internal_recommendedChannels(account: self.account, peerId: peerId)
|
||||
}
|
||||
|
||||
public func recommendedChannelPeerIds(peerId: EnginePeer.Id?) -> Signal<[EnginePeer.Id]?, NoError> {
|
||||
return _internal_recommendedChannelPeerIds(account: self.account, peerId: peerId)
|
||||
}
|
||||
|
||||
public func toggleRecommendedChannelsHidden(peerId: EnginePeer.Id, hidden: Bool) -> Signal<Never, NoError> {
|
||||
return _internal_toggleRecommendedChannelsHidden(account: self.account, peerId: peerId, hidden: hidden)
|
||||
}
|
||||
|
@ -7091,12 +7091,24 @@ final class PeerInfoScreenNode: ViewControllerTracingNode, PeerInfoScreenNodePro
|
||||
if self.isMyProfile {
|
||||
//TODO:localize
|
||||
items.append(.action(ContextMenuActionItem(text: "Remove", textColor: .destructive, icon: { theme in generateTintedImage(image: UIImage(bundleImageName: "Chat/Context Menu/Delete"), color: theme.contextMenu.destructiveColor) }, action: { [weak self] c, _ in
|
||||
c.dismiss {
|
||||
guard let self else {
|
||||
return
|
||||
var subItems: [ContextMenuItem] = []
|
||||
let noAction: ((ContextMenuActionItem.Action) -> Void)? = nil
|
||||
subItems.append(.action(ContextMenuActionItem(
|
||||
text: "Are you sure you want to remove business hours?",
|
||||
textLayout: .multiline,
|
||||
textFont: .small,
|
||||
icon: { _ in nil },
|
||||
action: noAction
|
||||
)))
|
||||
subItems.append(.action(ContextMenuActionItem(text: "Remove", textColor: .destructive, icon: { _ in nil }, action: { [weak self] c, _ in
|
||||
c.dismiss {
|
||||
guard let self else {
|
||||
return
|
||||
}
|
||||
let _ = self.context.engine.accountData.updateAccountBusinessHours(businessHours: nil).startStandalone()
|
||||
}
|
||||
let _ = self.context.engine.accountData.updateAccountBusinessHours(businessHours: nil).startStandalone()
|
||||
}
|
||||
})))
|
||||
c.pushItems(items: .single(ContextController.Items(content: .list(subItems))))
|
||||
})))
|
||||
}
|
||||
|
||||
@ -7170,12 +7182,24 @@ final class PeerInfoScreenNode: ViewControllerTracingNode, PeerInfoScreenNodePro
|
||||
|
||||
//TODO:localize
|
||||
items.append(.action(ContextMenuActionItem(text: "Remove", textColor: .destructive, icon: { theme in generateTintedImage(image: UIImage(bundleImageName: "Chat/Context Menu/Delete"), color: theme.contextMenu.destructiveColor) }, action: { [weak self] c, _ in
|
||||
c.dismiss {
|
||||
guard let self else {
|
||||
return
|
||||
var subItems: [ContextMenuItem] = []
|
||||
let noAction: ((ContextMenuActionItem.Action) -> Void)? = nil
|
||||
subItems.append(.action(ContextMenuActionItem(
|
||||
text: "Are you sure you want to remove location?",
|
||||
textLayout: .multiline,
|
||||
textFont: .small,
|
||||
icon: { _ in nil },
|
||||
action: noAction
|
||||
)))
|
||||
subItems.append(.action(ContextMenuActionItem(text: "Remove", textColor: .destructive, icon: { _ in nil }, action: { [weak self] c, _ in
|
||||
c.dismiss {
|
||||
guard let self else {
|
||||
return
|
||||
}
|
||||
let _ = self.context.engine.accountData.updateAccountBusinessLocation(businessLocation: nil).startStandalone()
|
||||
}
|
||||
let _ = self.context.engine.accountData.updateAccountBusinessLocation(businessLocation: nil).startStandalone()
|
||||
}
|
||||
})))
|
||||
c.pushItems(items: .single(ContextController.Items(content: .list(subItems))))
|
||||
})))
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user