Various Improvements

This commit is contained in:
Ilya Laktyushin 2021-11-02 22:18:31 +04:00
parent 5060701adb
commit 775d731aac
7 changed files with 70 additions and 15 deletions

View File

@ -6928,7 +6928,7 @@ Sorry for the inconvenience.";
"MemberRequests.RequestToJoinSentDescriptionGroup" = "You will be added to the group once it admins approve your request.";
"MemberRequests.RequestToJoinSentDescriptionChannel" = "You will be added to the channel once it admins approve your request.";
"Notification.JoinedChatByRequestYou" = "Your request to join the channel was approved";
"Notification.JoinedChannelByRequestYou" = "Your request to join the channel was approved";
"Notification.JoinedGroupByRequestYou" = "Your request to join the group was approved";
"Notification.JoinedGroupByRequest" = "%@ was accepted to the group chat";

View File

@ -68,6 +68,7 @@
- (SSignal *)captionSignalForItem:(NSObject<TGMediaEditableItem> *)item;
- (void)setCaption:(NSString *)caption entities:(NSArray *)entities forItem:(NSObject<TGMediaEditableItem> *)item;
- (bool)isForcedCaption;
- (void)setForcedCaption:(NSString *)caption entities:(NSArray *)entities;
- (NSObject<TGMediaEditAdjustments> *)adjustmentsForItem:(NSObject<TGMediaEditableItem> *)item;

View File

@ -908,6 +908,7 @@
NSNumber *groupedId;
NSInteger i = 0;
NSInteger num = 0;
bool grouping = selectionContext.grouping;
bool hasAnyTimers = false;
@ -938,15 +939,20 @@
asset = ((TGCameraCapturedVideo *)asset).originalAsset;
}
NSString *caption = [editingContext captionForItem:asset];
NSArray *entities = [editingContext entitiesForItem:asset];
if (editingContext.isForcedCaption && num > 0) {
caption = nil;
entities = nil;
}
switch (asset.type)
{
case TGMediaAssetPhotoType:
{
if (intent == TGMediaAssetsControllerSendFileIntent)
{
NSString *caption = [editingContext captionForItem:asset];
NSArray *entities = [editingContext entitiesForItem:asset];
[signals addObject:[[[TGMediaAssetImageSignals imageDataForAsset:asset allowNetworkAccess:false convertToJpeg:convertToJpeg] map:^NSDictionary *(TGMediaAssetImageData *assetData)
{
NSString *tempFileName = TGTemporaryFileName(nil);
@ -993,11 +999,10 @@
}]];
i++;
num++;
}
else
{
NSString *caption = [editingContext captionForItem:asset];
NSArray *entities = [editingContext entitiesForItem:asset];
id<TGMediaEditAdjustments> adjustments = [editingContext adjustmentsForItem:asset];
NSNumber *timer = [editingContext timerForItem:asset];
@ -1096,6 +1101,7 @@
}]];
i++;
num++;
}
else
{
@ -1181,6 +1187,7 @@
}
i++;
num++;
}
}
break;
@ -1189,8 +1196,6 @@
{
if (intent == TGMediaAssetsControllerSendFileIntent)
{
NSString *caption = [editingContext captionForItem:asset];
NSArray *entities = [editingContext entitiesForItem:asset];
id<TGMediaEditAdjustments> adjustments = [editingContext adjustmentsForItem:asset];
CGSize dimensions = asset.originalSize;
@ -1218,12 +1223,11 @@
}]];
i++;
num++;
}
else
{
TGVideoEditAdjustments *adjustments = (TGVideoEditAdjustments *)[editingContext adjustmentsForItem:asset];
NSString *caption = [editingContext captionForItem:asset];
NSArray *entities = [editingContext entitiesForItem:asset];
NSNumber *timer = [editingContext timerForItem:asset];
UIImage *(^cropVideoThumbnail)(UIImage *, CGSize, CGSize, bool) = ^UIImage *(UIImage *image, CGSize targetSize, CGSize sourceSize, bool resize)
@ -1288,6 +1292,7 @@
}]];
i++;
num++;
}
}
break;
@ -1300,8 +1305,6 @@
}
TGVideoEditAdjustments *adjustments = (TGVideoEditAdjustments *)[editingContext adjustmentsForItem:video];
NSString *caption = [editingContext captionForItem:video];
NSArray *entities = [editingContext entitiesForItem:video];
NSNumber *timer = [editingContext timerForItem:video];
UIImage *(^cropVideoThumbnail)(UIImage *, CGSize, CGSize, bool) = ^UIImage *(UIImage *image, CGSize targetSize, CGSize sourceSize, bool resize)
@ -1366,6 +1369,7 @@
}]];
i++;
num++;
}
break;

View File

@ -424,6 +424,10 @@
_captionPipe.sink([TGMediaCaptionUpdate captionUpdateWithItem:item caption:caption entities:entities]);
}
- (bool)isForcedCaption {
return _forcedCaption.length > 0;
}
- (void)setForcedCaption:(NSString *)caption entities:(NSArray *)entities
{
_forcedCaption = caption;

View File

@ -262,7 +262,9 @@ public func universalServiceMessageString(presentationData: (PresentationTheme,
attributedString = addAttributesToStringWithRanges(strings.Notification_JoinedGroupByLink(authorName)._tuple, body: bodyAttributes, argumentAttributes: peerMentionsAttributes(primaryTextColor: primaryTextColor, peerIds: [(0, message.author?.id)]))
}
case .joinedByRequest:
if message.author?.id == accountPeerId {
if message.author?.id.namespace == Namespaces.Peer.CloudChannel {
attributedString = NSAttributedString(string: strings.Notification_JoinedChannelByRequestYou, font: titleFont, textColor: primaryTextColor)
} else if message.author?.id == accountPeerId {
attributedString = NSAttributedString(string: strings.Notification_JoinedGroupByRequestYou, font: titleFont, textColor: primaryTextColor)
} else if let peerId = message.author?.id {
attributedString = addAttributesToStringWithRanges(strings.Notification_JoinedGroupByRequest(authorName)._tuple, body: bodyAttributes, argumentAttributes: peerMentionsAttributes(primaryTextColor: primaryTextColor, peerIds: [(0, peerId)]))

View File

@ -24,6 +24,7 @@ func chatHistoryEntriesForView(
updatingMedia: [MessageId: ChatUpdatingMessageMedia],
customChannelDiscussionReadState: MessageId?,
customThreadOutgoingReadState: MessageId?,
cachedData: CachedPeerData?,
adMessages: [Message]
) -> [ChatHistoryEntry] {
if historyAppearsCleared {
@ -32,6 +33,7 @@ func chatHistoryEntriesForView(
var entries: [ChatHistoryEntry] = []
var adminRanks: [PeerId: CachedChannelAdminRank] = [:]
var stickersEnabled = true
var channelPeer: Peer?
if case let .peer(peerId) = location, peerId.namespace == Namespaces.Peer.CloudChannel {
for additionalEntry in view.additionalData {
if case let .cacheEntry(id, data) = additionalEntry {
@ -39,14 +41,43 @@ func chatHistoryEntriesForView(
adminRanks = data.ranks
}
} else if case let .peer(_, peer) = additionalEntry, let channel = peer as? TelegramChannel, !channel.flags.contains(.isGigagroup) {
channelPeer = channel
if let defaultBannedRights = channel.defaultBannedRights, defaultBannedRights.flags.contains(.banSendStickers) {
stickersEnabled = false
}
}
}
}
var joinMessage: Message?
if case let .peer(peerId) = location, case let cachedData = cachedData as? CachedChannelData, let invitedOn = cachedData?.invitedOn {
joinMessage = Message(
stableId: UInt32.max - 1000,
stableVersion: 0,
id: MessageId(peerId: peerId, namespace: Namespaces.Message.Local, id: 0),
globallyUniqueId: nil,
groupingKey: nil,
groupInfo: nil,
threadId: nil,
timestamp: invitedOn,
flags: [.Incoming],
tags: [],
globalTags: [],
localTags: [],
forwardInfo: nil,
author: channelPeer,
text: "",
attributes: [],
media: [TelegramMediaAction(action: .joinedByRequest)],
peers: SimpleDictionary<PeerId, Peer>(),
associatedMessages: SimpleDictionary<MessageId, Message>(),
associatedMessageIds: []
)
}
var groupBucket: [(Message, Bool, ChatHistoryMessageSelection, ChatMessageEntryAttributes)] = []
var count = 0
loop: for entry in view.entries {
var message = entry.message
var isRead = entry.isRead
@ -55,6 +86,14 @@ func chatHistoryEntriesForView(
continue
}
if let maybeJoinMessage = joinMessage {
if message.timestamp > maybeJoinMessage.timestamp, (!view.holeEarlier || count > 0) {
entries.append(.MessageEntry(maybeJoinMessage, presentationData, false, nil, .none, ChatMessageEntryAttributes(rank: nil, isContact: false, contentTypeHint: .generic, updatingMedia: nil, isPlaying: false)))
joinMessage = nil
}
}
count += 1
if let customThreadOutgoingReadState = customThreadOutgoingReadState {
isRead = customThreadOutgoingReadState >= message.id
}
@ -95,7 +134,6 @@ func chatHistoryEntriesForView(
adminRank = adminRanks[author.id]
}
if presentationData.largeEmoji, message.media.isEmpty {
if stickersEnabled && message.text.count == 1, let _ = associatedData.animatedEmojiStickers[message.text.basicEmoji.0] {
contentTypeHint = .animatedEmoji
@ -142,6 +180,11 @@ func chatHistoryEntriesForView(
entries.append(.MessageGroupEntry(groupBucket[0].0.groupInfo!, groupBucket, presentationData))
}
if let maybeJoinMessage = joinMessage, !view.holeLater {
entries.append(.MessageEntry(maybeJoinMessage, presentationData, false, nil, .none, ChatMessageEntryAttributes(rank: nil, isContact: false, contentTypeHint: .generic, updatingMedia: nil, isPlaying: false)))
joinMessage = nil
}
if let maxReadIndex = view.maxReadIndex, includeUnreadEntry {
var i = 0
let unreadEntry: ChatHistoryEntry = .UnreadEntry(maxReadIndex, presentationData)

View File

@ -1045,6 +1045,7 @@ public final class ChatHistoryListNode: ListView, ChatHistoryNode {
updatingMedia: updatingMedia,
customChannelDiscussionReadState: customChannelDiscussionReadState,
customThreadOutgoingReadState: customThreadOutgoingReadState,
cachedData: data.cachedData,
adMessages: adMessages
)
let lastHeaderId = filteredEntries.last.flatMap { listMessageDateHeaderId(timestamp: $0.index.timestamp) } ?? 0