Skip to content

Commit efb1476

Browse files
authored
Merge pull request #6045 from vector-im/ismail/6038_threads_server_check
2 parents c3d7d1e + 36e5147 commit efb1476

File tree

8 files changed

+97
-14
lines changed

8 files changed

+97
-14
lines changed

Riot/Assets/en.lproj/Vector.strings

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,8 @@ Tap the + to start adding people.";
507507
"threads_beta_information_link" = "Learn more";
508508
"threads_beta_enable" = "Try it out";
509509
"threads_beta_cancel" = "Not now";
510+
"threads_discourage_information_1" = "Your homeserver does not currently support threads, so this feature may be unreliable. Some threaded messages may not be reliably available. ";
511+
"threads_discourage_information_2" = "\n\nDo you want to enable threads anyway?";
510512

511513
"media_type_accessibility_image" = "Image";
512514
"media_type_accessibility_audio" = "Audio";

Riot/Generated/Strings.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7703,6 +7703,14 @@ public class VectorL10n: NSObject {
77037703
public static var threadsBetaTitle: String {
77047704
return VectorL10n.tr("Vector", "threads_beta_title")
77057705
}
7706+
/// Your homeserver does not currently support threads, so this feature may be unreliable. Some threaded messages may not be reliably available.
7707+
public static var threadsDiscourageInformation1: String {
7708+
return VectorL10n.tr("Vector", "threads_discourage_information_1")
7709+
}
7710+
/// \n\nDo you want to enable threads anyway?
7711+
public static var threadsDiscourageInformation2: String {
7712+
return VectorL10n.tr("Vector", "threads_discourage_information_2")
7713+
}
77067714
/// Threads help keep your conversations on-topic and easy to track.
77077715
public static var threadsEmptyInfoAll: String {
77087716
return VectorL10n.tr("Vector", "threads_empty_info_all")

Riot/Modules/Room/RoomViewController.m

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3485,9 +3485,7 @@ - (void)showAdditionalActionsMenuForEvent:(MXEvent*)selectedEvent inCell:(id<MXK
34853485

34863486
MXWeakify(self);
34873487

3488-
BOOL showThreadOption = RiotSettings.shared.enableThreads
3489-
&& !self.roomDataSource.threadId
3490-
&& !selectedEvent.threadId;
3488+
BOOL showThreadOption = [self showThreadOptionForEvent:selectedEvent];
34913489
if (showThreadOption && [self canCopyEvent:selectedEvent andCell:cell])
34923490
{
34933491
[self.eventMenuBuilder addItemWithType:EventMenuItemTypeCopy
@@ -6417,7 +6415,7 @@ - (void)removeMXSessionStateChangeNotificationsListener
64176415

64186416
BOOL showMoreOption = (event.isState && RiotSettings.shared.roomContextualMenuShowMoreOptionForStates)
64196417
|| (!event.isState && RiotSettings.shared.roomContextualMenuShowMoreOptionForMessages);
6420-
BOOL showThreadOption = !self.roomDataSource.threadId && !event.threadId;
6418+
BOOL showThreadOption = [self showThreadOptionForEvent:event];
64216419

64226420
NSMutableArray<RoomContextualMenuItem*> *items = [NSMutableArray arrayWithCapacity:5];
64236421

@@ -6808,6 +6806,13 @@ - (RoomContextualMenuItem *)moreMenuItemWithEvent:(MXEvent*)event andCell:(id<MX
68086806

68096807
#pragma mark - Threads
68106808

6809+
- (BOOL)showThreadOptionForEvent:(MXEvent*)event
6810+
{
6811+
return !self.roomDataSource.threadId
6812+
&& !event.threadId
6813+
&& (RiotSettings.shared.enableThreads || self.mainSession.store.supportedMatrixVersions.supportsThreads);
6814+
}
6815+
68116816
- (void)showThreadsNotice
68126817
{
68136818
if (!self.threadsNoticeModalPresenter)
@@ -6845,7 +6850,9 @@ - (void)showThreadsBetaForEvent:(MXEvent *)event
68456850
self.threadsBetaBridgePresenter = nil;
68466851
}
68476852

6848-
self.threadsBetaBridgePresenter = [[ThreadsBetaCoordinatorBridgePresenter alloc] initWithThreadId:event.eventId];
6853+
self.threadsBetaBridgePresenter = [[ThreadsBetaCoordinatorBridgePresenter alloc] initWithThreadId:event.eventId
6854+
infoText:VectorL10n.threadsBetaInformation
6855+
additionalText:nil];
68496856
self.threadsBetaBridgePresenter.delegate = self;
68506857

68516858
[self.threadsBetaBridgePresenter presentFrom:self.presentedViewController?:self animated:YES];

Riot/Modules/Settings/SettingsViewController.m

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,8 @@ @interface SettingsViewController () <UITextFieldDelegate, MXKCountryPickerViewC
187187
SettingsDiscoveryTableViewSectionDelegate, SettingsDiscoveryViewModelCoordinatorDelegate,
188188
SettingsIdentityServerCoordinatorBridgePresenterDelegate,
189189
ServiceTermsModalCoordinatorBridgePresenterDelegate,
190-
TableViewSectionsDelegate>
190+
TableViewSectionsDelegate,
191+
ThreadsBetaCoordinatorBridgePresenterDelegate>
191192
{
192193
// Current alert (if any).
193194
__weak UIAlertController *currentAlert;
@@ -288,6 +289,8 @@ @interface SettingsViewController () <UITextFieldDelegate, MXKCountryPickerViewC
288289

289290
@property (nonatomic, strong) UserInteractiveAuthenticationService *userInteractiveAuthenticationService;
290291

292+
@property (nonatomic, strong) ThreadsBetaCoordinatorBridgePresenter *threadsBetaBridgePresenter;
293+
291294
/**
292295
Whether or not to check for contacts access after the user accepts the service terms. The value of this property is
293296
set automatically when calling `prepareIdentityServiceAndPresentTermsWithSession:checkingAccessForContactsOnAccept`
@@ -3254,8 +3257,31 @@ - (void)toggleEnableRingingForGroupCalls:(UISwitch *)sender
32543257

32553258
- (void)toggleEnableThreads:(UISwitch *)sender
32563259
{
3257-
RiotSettings.shared.enableThreads = sender.isOn;
3258-
MXSDKOptions.sharedInstance.enableThreads = sender.isOn;
3260+
if (sender.isOn && !self.mainSession.store.supportedMatrixVersions.supportsThreads)
3261+
{
3262+
// user wants to turn on the threads setting but the server does not support it
3263+
if (self.threadsBetaBridgePresenter)
3264+
{
3265+
[self.threadsBetaBridgePresenter dismissWithAnimated:YES completion:nil];
3266+
self.threadsBetaBridgePresenter = nil;
3267+
}
3268+
3269+
self.threadsBetaBridgePresenter = [[ThreadsBetaCoordinatorBridgePresenter alloc] initWithThreadId:@""
3270+
infoText:VectorL10n.threadsDiscourageInformation1
3271+
additionalText:VectorL10n.threadsDiscourageInformation2];
3272+
self.threadsBetaBridgePresenter.delegate = self;
3273+
3274+
[self.threadsBetaBridgePresenter presentFrom:self.presentedViewController?:self animated:YES];
3275+
return;
3276+
}
3277+
3278+
[self enableThreads:sender.isOn];
3279+
}
3280+
3281+
- (void)enableThreads:(BOOL)enable
3282+
{
3283+
RiotSettings.shared.enableThreads = enable;
3284+
MXSDKOptions.sharedInstance.enableThreads = enable;
32593285
[[MXKRoomDataSourceManager sharedManagerForMatrixSession:self.mainSession] reset];
32603286
[[AppDelegate theDelegate] restoreEmptyDetailsViewController];
32613287
}
@@ -4724,4 +4750,24 @@ - (void)tableViewSectionsDidUpdateSections:(TableViewSections *)sections
47244750
[self.tableView reloadData];
47254751
}
47264752

4753+
#pragma mark - ThreadsBetaCoordinatorBridgePresenterDelegate
4754+
4755+
- (void)threadsBetaCoordinatorBridgePresenterDelegateDidTapEnable:(ThreadsBetaCoordinatorBridgePresenter *)coordinatorBridgePresenter
4756+
{
4757+
MXWeakify(self);
4758+
[self.threadsBetaBridgePresenter dismissWithAnimated:YES completion:^{
4759+
MXStrongifyAndReturnIfNil(self);
4760+
[self enableThreads:YES];
4761+
}];
4762+
}
4763+
4764+
- (void)threadsBetaCoordinatorBridgePresenterDelegateDidTapCancel:(ThreadsBetaCoordinatorBridgePresenter *)coordinatorBridgePresenter
4765+
{
4766+
MXWeakify(self);
4767+
[self.threadsBetaBridgePresenter dismissWithAnimated:YES completion:^{
4768+
MXStrongifyAndReturnIfNil(self);
4769+
[self updateSections];
4770+
}];
4771+
}
4772+
47274773
@end

Riot/Modules/Threads/Beta/ThreadsBetaCoordinator.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,10 @@ final class ThreadsBetaCoordinator: NSObject, ThreadsBetaCoordinatorProtocol {
2626
// MARK: Private
2727

2828
private let threadId: String
29+
private let infoText: String
30+
private let additionalText: String?
2931
private lazy var viewController: ThreadsBetaViewController = {
30-
let result = ThreadsBetaViewController.instantiate()
32+
let result = ThreadsBetaViewController.instantiate(infoText: infoText, additionalText: additionalText)
3133
result.didTapEnableButton = { [weak self] in
3234
guard let self = self else { return }
3335
RiotSettings.shared.enableThreads = true
@@ -50,8 +52,10 @@ final class ThreadsBetaCoordinator: NSObject, ThreadsBetaCoordinatorProtocol {
5052

5153
// MARK: - Setup
5254

53-
init(threadId: String) {
55+
init(threadId: String, infoText: String, additionalText: String?) {
5456
self.threadId = threadId
57+
self.infoText = infoText
58+
self.additionalText = additionalText
5559
}
5660

5761
// MARK: - Public

Riot/Modules/Threads/Beta/ThreadsBetaCoordinatorBridgePresenter.swift

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ final class ThreadsBetaCoordinatorBridgePresenter: NSObject {
3838
// MARK: Private
3939

4040
public let threadId: String
41+
public let infoText: String
42+
public let additionalText: String?
4143
private let slidingModalPresenter = SlidingModalPresenter()
4244
private var coordinator: ThreadsBetaCoordinator?
4345

@@ -47,16 +49,20 @@ final class ThreadsBetaCoordinatorBridgePresenter: NSObject {
4749

4850
// MARK: - Setup
4951

50-
init(threadId: String) {
52+
init(threadId: String, infoText: String, additionalText: String?) {
5153
self.threadId = threadId
54+
self.infoText = infoText
55+
self.additionalText = additionalText
5256
super.init()
5357
}
5458

5559
// MARK: - Public
5660

5761
func present(from viewController: UIViewController, animated: Bool) {
5862

59-
let threadsBetaCoordinator = ThreadsBetaCoordinator(threadId: threadId)
63+
let threadsBetaCoordinator = ThreadsBetaCoordinator(threadId: threadId,
64+
infoText: infoText,
65+
additionalText: additionalText)
6066
threadsBetaCoordinator.delegate = self
6167
guard let presentable = threadsBetaCoordinator.toPresentable() as? SlidingModalPresentable.ViewControllerType else {
6268
MXLog.error("[ThreadsBetaCoordinatorBridgePresenter] Presentable is not 'SlidingModalPresentable'")

Riot/Modules/Threads/Beta/ThreadsBetaViewController.swift

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ class ThreadsBetaViewController: UIViewController {
3939
// MARK: Private
4040

4141
private var theme: Theme!
42+
private var infoText: String!
43+
private var additionalText: String?
4244

4345
// MARK: Public
4446

@@ -69,9 +71,11 @@ class ThreadsBetaViewController: UIViewController {
6971

7072
// MARK: - Setup
7173

72-
@objc class func instantiate() -> ThreadsBetaViewController {
74+
@objc class func instantiate(infoText: String, additionalText: String?) -> ThreadsBetaViewController {
7375
let viewController = StoryboardScene.ThreadsBetaViewController.initialScene.instantiate()
7476
viewController.theme = ThemeService.shared().theme
77+
viewController.infoText = infoText
78+
viewController.additionalText = additionalText
7579
return viewController
7680
}
7781

@@ -98,12 +102,17 @@ class ThreadsBetaViewController: UIViewController {
98102
guard let font = self.informationTextView.font else {
99103
return
100104
}
101-
let attributedString = NSMutableAttributedString(string: VectorL10n.threadsBetaInformation,
105+
let attributedString = NSMutableAttributedString(string: infoText,
102106
attributes: [.font: font])
103107
let link = NSAttributedString(string: VectorL10n.threadsBetaInformationLink,
104108
attributes: [.link: Constants.learnMoreLink,
105109
.font: font])
106110
attributedString.append(link)
111+
112+
if let additionalText = additionalText {
113+
attributedString.append(NSAttributedString(string: additionalText,
114+
attributes: [.font: font]))
115+
}
107116
self.informationTextView.attributedText = attributedString
108117
}
109118

changelog.d/6038.change

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Settings: Add threads discourage view when server doesn't support threads.

0 commit comments

Comments
 (0)