From db106d206bf983e6921432be00bd0c4bf5cda64b Mon Sep 17 00:00:00 2001 From: overtake Date: Mon, 9 Oct 2017 13:59:35 +0300 Subject: [PATCH] no message --- TelegramCore/ChannelBlacklist.swift | 1 + TelegramCore/EnqueueMessage.swift | 11 +++++- .../ManagedLocalInputActivities.swift | 4 ++ TelegramCore/PeerInputActivity.swift | 28 +++++++++++--- TelegramCore/PendingMessageManager.swift | 4 ++ TelegramCore/RemovePeerMember.swift | 38 +++---------------- .../UpdateCachedChannelParticipants.swift | 4 +- 7 files changed, 49 insertions(+), 41 deletions(-) diff --git a/TelegramCore/ChannelBlacklist.swift b/TelegramCore/ChannelBlacklist.swift index 2f23562e23..60a53aec57 100644 --- a/TelegramCore/ChannelBlacklist.swift +++ b/TelegramCore/ChannelBlacklist.swift @@ -160,6 +160,7 @@ public func updateChannelMemberBannedRights(account: Account, peerId: PeerId, me } } + var isKicked = false var isBanned = false if rights.flags.contains(.banReadMessages) { diff --git a/TelegramCore/EnqueueMessage.swift b/TelegramCore/EnqueueMessage.swift index 4a4357f60f..44241385b0 100644 --- a/TelegramCore/EnqueueMessage.swift +++ b/TelegramCore/EnqueueMessage.swift @@ -38,6 +38,8 @@ private func filterMessageAttributesForOutgoingMessage(_ attributes: [MessageAtt return true case _ as AutoremoveTimeoutMessageAttribute: return true + case _ as NotificationInfoMessageAttribute: + return true default: return false } @@ -276,6 +278,13 @@ func enqueueMessages(modifier: Modifier, account: Account, peerId: PeerId, messa } + let authorId:PeerId? + if let peer = peer as? TelegramChannel, case let .broadcast(info) = peer.info, !info.flags.contains(.messagesShouldHaveSignatures) { + authorId = peer.id + } else { + authorId = account.peerId + } + var entitiesAttribute: TextEntitiesMessageAttribute? for attribute in attributes { if let attribute = attribute as? TextEntitiesMessageAttribute { @@ -286,7 +295,7 @@ func enqueueMessages(modifier: Modifier, account: Account, peerId: PeerId, messa let (tags, globalTags) = tagsForStoreMessage(incoming: false, attributes: attributes, media: sourceMessage.media, textEntities: entitiesAttribute?.entities) - storeMessages.append(StoreMessage(peerId: peerId, namespace: Namespaces.Message.Local, globallyUniqueId: randomId, timestamp: timestamp, flags: flags, tags: tags, globalTags: globalTags, forwardInfo: forwardInfo, authorId: account.peerId, text: sourceMessage.text, attributes: attributes, media: sourceMessage.media)) + storeMessages.append(StoreMessage(peerId: peerId, namespace: Namespaces.Message.Local, globallyUniqueId: randomId, timestamp: timestamp, flags: flags, tags: tags, globalTags: globalTags, forwardInfo: forwardInfo, authorId: authorId, text: sourceMessage.text, attributes: attributes, media: sourceMessage.media)) } } } diff --git a/TelegramCore/ManagedLocalInputActivities.swift b/TelegramCore/ManagedLocalInputActivities.swift index 7f5edd4fea..be1fe510c1 100644 --- a/TelegramCore/ManagedLocalInputActivities.swift +++ b/TelegramCore/ManagedLocalInputActivities.swift @@ -95,6 +95,10 @@ private func actionFromActivity(_ activity: PeerInputActivity?) -> Api.SendMessa return .sendMessageGamePlayAction case let .uploadingFile(progress): return .sendMessageUploadDocumentAction(progress: progress) + case let .uploadingPhoto(progress): + return .sendMessageUploadPhotoAction(progress: progress) + case let .uploadingVideo(progress): + return .sendMessageUploadVideoAction(progress: progress) case .recordingInstantVideo: return .sendMessageRecordRoundAction case .uploadingInstantVideo: diff --git a/TelegramCore/PeerInputActivity.swift b/TelegramCore/PeerInputActivity.swift index 520ad23767..6bd8f5d563 100644 --- a/TelegramCore/PeerInputActivity.swift +++ b/TelegramCore/PeerInputActivity.swift @@ -4,6 +4,8 @@ public enum PeerInputActivity: Comparable { case typingText case uploadingFile(progress: Int32) case recordingVoice + case uploadingPhoto(progress: Int32) + case uploadingVideo(progress: Int32) case playingGame case recordingInstantVideo case uploadingInstantVideo @@ -34,6 +36,18 @@ public enum PeerInputActivity: Comparable { } else { return false } + case .uploadingPhoto(let progress): + if case .uploadingPhoto(progress) = rhs { + return true + } else { + return false + } + case .uploadingVideo(let progress): + if case .uploadingVideo(progress) = rhs { + return true + } else { + return false + } case .recordingInstantVideo: if case .recordingInstantVideo = rhs { return true @@ -57,12 +71,16 @@ public enum PeerInputActivity: Comparable { return 1 case .recordingVoice: return 2 - case .recordingInstantVideo: + case .uploadingPhoto: return 3 - case .uploadingInstantVideo: + case .uploadingVideo: return 4 - case .playingGame: + case .recordingInstantVideo: return 5 + case .uploadingInstantVideo: + return 6 + case .playingGame: + return 7 } } @@ -85,9 +103,9 @@ extension PeerInputActivity { case let .sendMessageUploadDocumentAction(progress): self = .uploadingFile(progress: progress) case let .sendMessageUploadPhotoAction(progress): - self = .uploadingFile(progress: progress) + self = .uploadingPhoto(progress: progress) case let .sendMessageUploadVideoAction(progress): - self = .uploadingFile(progress: progress) + self = .uploadingVideo(progress: progress) case .sendMessageRecordRoundAction: self = .recordingInstantVideo case .sendMessageUploadRoundAction: diff --git a/TelegramCore/PendingMessageManager.swift b/TelegramCore/PendingMessageManager.swift index 9e8bd6b1d4..7d76864a78 100644 --- a/TelegramCore/PendingMessageManager.swift +++ b/TelegramCore/PendingMessageManager.swift @@ -458,6 +458,10 @@ public final class PendingMessageManager { if attribute.flags.contains(.disableLinkPreviews) { flags |= Int32(1 << 1) } + } else if let attribute = attribute as? NotificationInfoMessageAttribute { + if attribute.flags.contains(.muted) { + flags |= Int32(1 << 5) + } } } diff --git a/TelegramCore/RemovePeerMember.swift b/TelegramCore/RemovePeerMember.swift index 4310b3ba18..02d5a3cdc8 100644 --- a/TelegramCore/RemovePeerMember.swift +++ b/TelegramCore/RemovePeerMember.swift @@ -10,6 +10,11 @@ import Foundation #endif public func removePeerMember(account: Account, peerId: PeerId, memberId: PeerId) -> Signal { + + if peerId.namespace == Namespaces.Peer.CloudChannel { + return updateChannelMemberBannedRights(account: account, peerId: peerId, memberId: memberId, rights: TelegramChannelBannedRights(flags: [.banReadMessages], untilDate: 0)) + } + return account.postbox.modify { modifier -> Signal in if let peer = modifier.getPeer(peerId), let memberPeer = modifier.getPeer(memberId), let inputUser = apiInputUser(memberPeer) { if let group = peer as? TelegramGroup { @@ -41,39 +46,6 @@ public func removePeerMember(account: Account, peerId: PeerId, memberId: PeerId) }) } } - } else if let channel = peer as? TelegramChannel, let inputChannel = apiInputChannel(channel) { - return account.network.request(Api.functions.channels.kickFromChannel(channel: inputChannel, userId: inputUser, kicked: .boolTrue)) - |> mapError { error -> Void in - return Void() - } - |> `catch` { _ -> Signal in - return .complete() - } - |> mapToSignal { result -> Signal in - account.stateManager.addUpdates(result) - - return account.postbox.modify { modifier -> Void in - modifier.updatePeerCachedData(peerIds: Set([peerId]), update: { _, cachedData -> CachedPeerData? in - if let cachedData = cachedData as? CachedChannelData, let participants = cachedData.topParticipants { - var updatedParticipants = participants.participants - for i in 0 ..< participants.participants.count { - if participants.participants[i].peerId == memberId { - updatedParticipants.remove(at: i) - break - } - } - let updatedData = cachedData.withUpdatedTopParticipants(CachedChannelParticipants(participants: updatedParticipants)) - if let bannedCount = cachedData.participantsSummary.bannedCount { - return updatedData.withUpdatedParticipantsSummary(cachedData.participantsSummary.withUpdatedBannedCount(bannedCount + 1)) - } else { - return updatedData - } - } else { - return cachedData - } - }) - } |> then(updateChannelParticipantsSummary(account: account, peerId: peerId)) - } } else { return .complete() } diff --git a/TelegramCore/UpdateCachedChannelParticipants.swift b/TelegramCore/UpdateCachedChannelParticipants.swift index def1f657bf..0eeab6783c 100644 --- a/TelegramCore/UpdateCachedChannelParticipants.swift +++ b/TelegramCore/UpdateCachedChannelParticipants.swift @@ -16,7 +16,7 @@ func fetchAndUpdateCachedParticipants(peerId: PeerId, network: Network, postbox: |> mapToSignal { result -> Signal in return postbox.modify { modifier -> Void in switch result { - case let .channelParticipants(_, participants, users): + case let .channelParticipants(count, participants, users): var peers: [Peer] = [] var peerPresences: [PeerId: PeerPresence] = [:] for user in users { @@ -37,7 +37,7 @@ func fetchAndUpdateCachedParticipants(peerId: PeerId, network: Network, postbox: modifier.updatePeerCachedData(peerIds: [peerId], update: { peerId, currentData in if let currentData = currentData as? CachedChannelData { - return currentData.withUpdatedTopParticipants(parsedParticipants) + return currentData.withUpdatedTopParticipants(parsedParticipants).withUpdatedParticipantsSummary(currentData.participantsSummary.withUpdatedMemberCount(count)) } else { return currentData }