Skip to content

Commit 0b6dcd3

Browse files
committed
fix(community): chat preview, search, localization
1 parent fa35cb8 commit 0b6dcd3

18 files changed

Lines changed: 212 additions & 85 deletions

File tree

‎Telegram/Telegram-iOS/en.lproj/Localizable.strings‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16443,6 +16443,8 @@ Error: %8$@";
1644316443
"Community.View.ChatsLimitReached" = "Sorry, this community has reached the maximum number of chats.";
1644416444
"Community.Request.UnknownRequester" = "Someone";
1644516445
"Community.Request.RequesterSuggestsGroup" = "%@ suggests this group:";
16446+
"Community.Request.RequesterSuggestsChannel" = "%@ suggests this channel:";
16447+
"Community.Request.RequesterSuggestsBot" = "%@ suggests this bot:";
1644616448
"Community.Request.PrivateStatus" = "visible only to its members";
1644716449
"Community.Request.Decline" = "Decline";
1644816450
"Community.Request.Add" = "Add";
@@ -16517,6 +16519,11 @@ Error: %8$@";
1651716519
"Community.Add.VisibilityHiddenInfo" = "Only invited members and community admins will see this chat.";
1651816520
"Community.Add.ActionAddToCommunity" = "Add to Community";
1651916521

16522+
"Community.Add.Confirm.TextGroup" = "If this group is approved by a community admin, its members will be able to join or request to join other chats in the community.";
16523+
"Community.Add.Confirm.TextChannel" = "If this channel is approved by a community admin, its subscribers will be able to join or request to join other chats in the community.";
16524+
"Community.Add.Confirm.TextBot" = "If this bot is approved by a community admin, community members will be able to see and use it.";
16525+
"Community.Add.Confirm.Add" = "Add";
16526+
1652016527
"Community.AddChat.Title" = "Add a Chat";
1652116528
"Community.AddChat.Description" = "Select a chat to add to this community";
1652216529

@@ -16528,6 +16535,7 @@ Error: %8$@";
1652816535
"Privacy.GroupsAndChannels.InviteToCommunityError" = "Sorry, you cannot add %@ to the community because of %@'s privacy settings.";
1652916536

1653016537
"Notification.CommunityAddedGroup" = "%1$@ added this group to %2$@ community";
16538+
"Notification.CommunityAddedGroupUnknown" = "This group was added to %1$@ community";
1653116539
"Notification.CommunityAddedGroupYou" = "You added this group to %1$@ community";
1653216540
"Notification.CommunityRemovedGroup" = "%1$@ removed this group from a community";
1653316541
"Notification.CommunityRemovedGroupYou" = "You removed this group from a community";

‎submodules/AccountContext/Sources/AccountContext.swift‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1585,7 +1585,8 @@ public protocol SharedAccountContext: AnyObject {
15851585
func makeAccountFreezeInfoScreen(context: AccountContext) -> ViewController
15861586
func makeSendInviteLinkScreen(context: AccountContext, subject: SendInviteLinkScreenSubject, peers: [TelegramForbiddenInvitePeer], theme: PresentationTheme?) -> ViewController
15871587
func makeCommunitiesScreen(context: AccountContext, peerId: EnginePeer.Id?) -> ViewController
1588-
func makeCommunityAddScreen(context: AccountContext, communityId: EnginePeer.Id, peerId: EnginePeer.Id, completed: @escaping () -> Void) -> ViewController
1588+
func makeCommunityAddScreen(context: AccountContext, communityId: EnginePeer.Id, peerId: EnginePeer.Id, completed: @escaping (Bool) -> Void) -> ViewController
1589+
func makeCommunityAddScreen(context: AccountContext, communityId: EnginePeer.Id, peerId: EnginePeer.Id, requiresConfirmation: Bool, completed: @escaping (Bool) -> Void) -> ViewController
15891590
func makeCommunityAddScreen(context: AccountContext, peerId: EnginePeer.Id, initialVisibility: Bool, completed: @escaping (Bool) -> Void) -> ViewController
15901591
func makeCommunityEditScreen(context: AccountContext, communityId: EnginePeer.Id) -> ViewController
15911592
func makeCommunityEditScreen(context: AccountContext, mode: CommunityEditScreenMode, completed: @escaping () -> Void) -> ViewController

‎submodules/ChatListUI/Sources/ChatListSearchListPaneNode.swift‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -960,7 +960,7 @@ public enum ChatListSearchEntry: Comparable, Identifiable {
960960
} else if case .apps = key {
961961
headerType = .text(strings.ChatList_Search_SectionApps, AnyHashable("apps"))
962962
} else {
963-
if filter.contains(.onlyGroups) {
963+
if communityId != nil || filter.contains(.onlyGroups) {
964964
headerType = .chats
965965
} else {
966966
if let _ = requestPeerType {

‎submodules/ChatListUI/Sources/Node/ChatListItem.swift‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4217,8 +4217,8 @@ public class ChatListItemNode: ItemListRevealOptionsItemNode {
42174217
strongSelf.communityAvatarShadowNode.image = generateTintedImage(image: shadowImage, color: theme.titleColor.withAlphaComponent(0.9))
42184218

42194219
let aspectRatio = shadowImage.size.width / shadowImage.size.height
4220-
let shadowSize = CGSize(width: floor(avatarFrame.width * aspectRatio * 0.9), height: floor(avatarFrame.width * 0.93))
4221-
transition.updatePosition(node: strongSelf.communityAvatarShadowNode, position: CGPoint(x: avatarFrame.width * 0.5 + avatarScaleOffset - 10.0, y: avatarFrame.height * 0.5))
4220+
let shadowSize = CGSize(width: floor(avatarFrame.width * aspectRatio * 0.84), height: floor(avatarFrame.width * 0.97))
4221+
transition.updatePosition(node: strongSelf.communityAvatarShadowNode, position: CGPoint(x: avatarFrame.width * 0.5 + avatarScaleOffset - 12.0 + UIScreenPixel, y: avatarFrame.height * 0.5))
42224222
transition.updateBounds(node: strongSelf.communityAvatarShadowNode, bounds: CGRect(origin: CGPoint(), size: shadowSize))
42234223
transition.updateTransformScale(node: strongSelf.communityAvatarShadowNode, scale: avatarScale)
42244224
} else {

‎submodules/TelegramCore/Sources/TelegramEngine/Messages/SearchMessages.swift‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,10 @@ func _internal_searchMessages(account: Account, location: SearchMessagesLocation
537537
}
538538
|> mapToSignal { (nextRate, lowerBound, inputPeer, inputCommunity) in
539539
var flags = flags
540+
var folderId = folderId
540541
if inputCommunity != nil {
542+
flags = 0
543+
folderId = nil
541544
flags |= (1 << 4)
542545
}
543546
return account.network.request(Api.functions.messages.searchGlobal(flags: flags, folderId: folderId, community: inputCommunity, q: query, filter: filter, minDate: minDate ?? 0, maxDate: maxDate ?? (Int32.max - 1), offsetRate: nextRate, offsetPeer: inputPeer, offsetId: lowerBound?.id.id ?? 0, limit: limit), automaticFloodWait: false)

‎submodules/TelegramStringFormatting/Sources/ServiceMessageStrings.swift‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1935,7 +1935,12 @@ public func universalServiceMessageString(presentationData: (PresentationTheme,
19351935
let stringWithRanges = strings.Notification_CommunityRemovedGroup(peerName)._tuple
19361936
attributedString = NSAttributedString(attributedString: addAttributesToStringWithRanges(stringWithRanges, body: bodyAttributes, argumentAttributes: attributes))
19371937
} else {
1938-
let rawText = strings.Notification_CommunityAddedGroup(peerName, communityName).string
1938+
let rawText: String
1939+
if message.author?.id.namespace != Namespaces.Peer.CloudUser {
1940+
rawText = strings.Notification_CommunityAddedGroupUnknown(communityName).string
1941+
} else {
1942+
rawText = strings.Notification_CommunityAddedGroup(peerName, communityName).string
1943+
}
19391944
attributedString = NSAttributedString(string: rawText, font: titleFont, textColor: primaryTextColor)
19401945
}
19411946
}

‎submodules/TelegramUI/Components/Chat/ChatMessageCommunityChangedBubbleContentNode/Sources/ChatMessageCommunityChangedBubbleContentNode.swift‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,11 @@ public class ChatMessageCommunityChangedBubbleContentNode: ChatMessageBubbleCont
141141
if item.message.author?.id == item.context.account.peerId {
142142
text = item.presentationData.strings.Notification_CommunityAddedGroupYou("**\(community?.title ?? "")**").string
143143
} else {
144-
text = item.presentationData.strings.Notification_CommunityAddedGroup("**\(authorName)**","**\(community?.title ?? "")**").string
144+
if item.message.author?.id.namespace != Namespaces.Peer.CloudUser {
145+
text = item.presentationData.strings.Notification_CommunityAddedGroupUnknown("**\(community?.title ?? "")**").string
146+
} else {
147+
text = item.presentationData.strings.Notification_CommunityAddedGroup("**\(authorName)**", "**\(community?.title ?? "")**").string
148+
}
145149
}
146150
} else {
147151
text = item.presentationData.strings.Notification_CommunityAddedChannel("**\(community?.title ?? "")**").string
@@ -183,7 +187,7 @@ public class ChatMessageCommunityChangedBubbleContentNode: ChatMessageBubbleCont
183187

184188
let aspectRatio = shadowImage.size.width / shadowImage.size.height
185189
let shadowSize = CGSize(width: imageSize.width * aspectRatio, height: imageSize.width)
186-
strongSelf.avatarShadowNode.frame = shadowSize.centered(around: avatarFrame.center).offsetBy(dx: -12.0, dy: 0.0)
190+
strongSelf.avatarShadowNode.frame = shadowSize.centered(around: avatarFrame.center).offsetBy(dx: -11.0, dy: 0.0)
187191
} else {
188192
strongSelf.avatarShadowNode.isHidden = true
189193
}

‎submodules/TelegramUI/Components/Communities/CommunitiesScreen/Sources/CommunitiesScreen.swift‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ private final class CommunitiesScreenComponent: Component {
283283
context: component.context,
284284
communityId: community.id,
285285
peerId: peerId,
286-
completed: { [weak self] in
286+
completed: { [weak self] immediate in
287287
self?.dismissController()
288288
}
289289
)

‎submodules/TelegramUI/Components/Communities/CommunityAddScreen/BUILD‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ swift_library(
2121
"//submodules/TelegramCore",
2222
"//submodules/TelegramPresentationData",
2323
"//submodules/ItemListUI",
24+
"//submodules/PresentationDataUtils",
2425
"//submodules/TelegramUI/Components/AlertComponent",
2526
"//submodules/TelegramUI/Components/AvatarComponent",
2627
"//submodules/TelegramUI/Components/ButtonComponent",

‎submodules/TelegramUI/Components/Communities/CommunityAddScreen/Sources/CommunityAddScreen.swift‎

Lines changed: 68 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import BundleIconComponent
1616
import ListActionItemComponent
1717
import ListSectionComponent
1818
import AlertComponent
19+
import PresentationDataUtils
1920
import ItemListUI
2021

2122
private enum CommunityAddVisibility: Equatable {
@@ -502,19 +503,22 @@ private final class CommunityAddScreenComponent: Component {
502503
let context: AccountContext
503504
let subject: CommunityAddScreenSubject
504505
let peerId: EnginePeer.Id
505-
let completed: () -> Void
506+
let requiresConfirmation: Bool
507+
let completed: (Bool) -> Void
506508
let draftCompleted: (Bool) -> Void
507509

508510
init(
509511
context: AccountContext,
510512
subject: CommunityAddScreenSubject,
511513
peerId: EnginePeer.Id,
512-
completed: @escaping () -> Void,
514+
requiresConfirmation: Bool,
515+
completed: @escaping (Bool) -> Void,
513516
draftCompleted: @escaping (Bool) -> Void
514517
) {
515518
self.context = context
516519
self.subject = subject
517520
self.peerId = peerId
521+
self.requiresConfirmation = requiresConfirmation
518522
self.completed = completed
519523
self.draftCompleted = draftCompleted
520524
}
@@ -529,6 +533,9 @@ private final class CommunityAddScreenComponent: Component {
529533
if lhs.peerId != rhs.peerId {
530534
return false
531535
}
536+
if lhs.requiresConfirmation != rhs.requiresConfirmation {
537+
return false
538+
}
532539
return true
533540
}
534541

@@ -592,10 +599,7 @@ private final class CommunityAddScreenComponent: Component {
592599
}
593600

594601
private func performAdd() {
595-
guard let component = self.component else {
596-
return
597-
}
598-
if self.isSaving || self.peer == nil {
602+
guard let component = self.component, let peer = self.peer, !self.isSaving else {
599603
return
600604
}
601605

@@ -607,12 +611,43 @@ private final class CommunityAddScreenComponent: Component {
607611
return
608612
}
609613

610-
self.isSaving = true
611-
self.state?.updated(transition: .immediate)
614+
if !component.requiresConfirmation {
615+
self.performExistingAdd()
616+
return
617+
}
612618

613-
guard case let .existing(communityId) = component.subject else {
619+
guard let environment = self.environment, let controller = environment.controller() else {
614620
return
615621
}
622+
let alertText: String
623+
if case let .channel(channel) = peer, case .broadcast = channel.info {
624+
alertText = environment.strings.Community_Add_Confirm_TextChannel
625+
} else if case .user = peer {
626+
alertText = environment.strings.Community_Add_Confirm_TextBot
627+
} else {
628+
alertText = environment.strings.Community_Add_Confirm_TextGroup
629+
}
630+
controller.present(textAlertController(
631+
context: component.context,
632+
title: nil,
633+
text: alertText,
634+
actions: [
635+
TextAlertAction(type: .genericAction, title: environment.strings.Common_Cancel, action: {}),
636+
TextAlertAction(type: .defaultAction, title: environment.strings.Community_Add_Confirm_Add, action: { [weak self] in
637+
self?.performExistingAdd()
638+
})
639+
]
640+
), in: .window(.root))
641+
}
642+
643+
private func performExistingAdd() {
644+
guard let component = self.component, self.peer != nil, !self.isSaving, case let .existing(communityId) = component.subject else {
645+
return
646+
}
647+
648+
self.isSaving = true
649+
self.state?.updated(transition: .immediate)
650+
616651
self.actionDisposable.set((component.context.engine.peers.toggleCommunityPeerLink(
617652
communityId: communityId,
618653
peerId: component.peerId,
@@ -625,7 +660,7 @@ private final class CommunityAddScreenComponent: Component {
625660
self.isSaving = false
626661
if case .requestCreated = error {
627662
self.dismiss(animated: true, completion: {
628-
component.completed()
663+
component.completed(false)
629664
})
630665
} else if case .serverProvided = error {
631666
self.state?.updated(transition: .spring(duration: 0.35))
@@ -654,7 +689,7 @@ private final class CommunityAddScreenComponent: Component {
654689
}
655690
self.isSaving = false
656691
self.dismiss(animated: true, completion: {
657-
component.completed()
692+
component.completed(true)
658693
})
659694
}))
660695
}
@@ -750,18 +785,35 @@ private final class CommunityAddScreenComponent: Component {
750785
}
751786

752787
public final class CommunityAddScreen: ViewControllerComponentContainer {
788+
public convenience init(
789+
context: AccountContext,
790+
communityId: EnginePeer.Id,
791+
peerId: EnginePeer.Id,
792+
completed: @escaping (Bool) -> Void
793+
) {
794+
self.init(
795+
context: context,
796+
communityId: communityId,
797+
peerId: peerId,
798+
requiresConfirmation: false,
799+
completed: completed
800+
)
801+
}
802+
753803
public init(
754804
context: AccountContext,
755805
communityId: EnginePeer.Id,
756806
peerId: EnginePeer.Id,
757-
completed: @escaping () -> Void
807+
requiresConfirmation: Bool,
808+
completed: @escaping (Bool) -> Void
758809
) {
759810
super.init(
760811
context: context,
761812
component: CommunityAddScreenComponent(
762813
context: context,
763814
subject: .existing(communityId: communityId),
764815
peerId: peerId,
816+
requiresConfirmation: requiresConfirmation,
765817
completed: completed,
766818
draftCompleted: { _ in }
767819
),
@@ -778,16 +830,17 @@ public final class CommunityAddScreen: ViewControllerComponentContainer {
778830
context: AccountContext,
779831
peerId: EnginePeer.Id,
780832
initialVisibility: Bool,
781-
completed: @escaping (Bool) -> Void
833+
draftCompleted: @escaping (Bool) -> Void
782834
) {
783835
super.init(
784836
context: context,
785837
component: CommunityAddScreenComponent(
786838
context: context,
787839
subject: .draft(initialVisibility: initialVisibility),
788840
peerId: peerId,
789-
completed: {},
790-
draftCompleted: completed
841+
requiresConfirmation: false,
842+
completed: { _ in },
843+
draftCompleted: draftCompleted
791844
),
792845
navigationBarAppearance: .none,
793846
statusBarStyle: .ignore,

0 commit comments

Comments
 (0)