Implement copy restriction and send as peer

This commit is contained in:
Ilya Laktyushin
2021-11-05 21:45:48 +04:00
parent 003d263ebd
commit 1a717fbda5
37 changed files with 1004 additions and 216 deletions

View File

@@ -115,6 +115,8 @@ private func filterMessageAttributesForOutgoingMessage(_ attributes: [MessageAtt
return true
case _ as ForwardOptionsMessageAttribute:
return true
case _ as SendAsMessageAttribute:
return true
default:
return false
}
@@ -134,6 +136,8 @@ private func filterMessageAttributesForForwardedMessage(_ attributes: [MessageAt
return true
case _ as ForwardOptionsMessageAttribute:
return true
case _ as SendAsMessageAttribute:
return true
default:
return false
}
@@ -451,20 +455,7 @@ func enqueueMessages(transaction: Transaction, account: Account, peerId: PeerId,
break
}
}
let authorId: PeerId?
if let peer = peer as? TelegramChannel {
if case .broadcast = peer.info {
authorId = peer.id
} else if case .group = peer.info, peer.hasPermission(.canBeAnonymous) {
authorId = peer.id
} else {
authorId = account.peerId
}
} else {
authorId = account.peerId
}
let (tags, globalTags) = tagsForStoreMessage(incoming: false, attributes: attributes, media: mediaList, textEntities: entitiesAttribute?.entities, isPinned: false)
var localTags: LocalMessageTags = []
@@ -476,6 +467,7 @@ func enqueueMessages(transaction: Transaction, account: Account, peerId: PeerId,
var messageNamespace = Namespaces.Message.Local
var effectiveTimestamp = timestamp
var sendAsPeer: Peer?
for attribute in attributes {
if let attribute = attribute as? OutgoingScheduleInfoMessageAttribute {
if attribute.scheduleTime == scheduleWhenOnlineTimestamp, let presence = peerPresence as? TelegramUserPresence, case let .present(statusTimestamp) = presence.status, statusTimestamp >= timestamp {
@@ -483,9 +475,27 @@ func enqueueMessages(transaction: Transaction, account: Account, peerId: PeerId,
messageNamespace = Namespaces.Message.ScheduledLocal
effectiveTimestamp = attribute.scheduleTime
}
break
} else if let attribute = attribute as? SendAsMessageAttribute {
if let peer = transaction.getPeer(attribute.peerId) {
sendAsPeer = peer
}
}
}
let authorId: PeerId?
if let sendAsPeer = sendAsPeer {
authorId = sendAsPeer.id
} else if let peer = peer as? TelegramChannel {
if case .broadcast = peer.info {
authorId = peer.id
} else if case .group = peer.info, peer.hasPermission(.canBeAnonymous) {
authorId = peer.id
} else {
authorId = account.peerId
}
} else {
authorId = account.peerId
}
if messageNamespace != Namespaces.Message.ScheduledLocal {
attributes.removeAll(where: { $0 is OutgoingScheduleInfoMessageAttribute })