Skip to content

Commit

Permalink
#4090 - Added voice messages switch to the labs section in settings.
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanceriu committed Jul 16, 2021
1 parent ec33ec8 commit 089c688
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Config/BuildSettings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ final class BuildSettings: NSObject {

// MARK: - Voice Message

static let voiceMessagesEnabled = true
static let voiceMessagesEnabled = false

// MARK: - HTTP
/// Additional HTTP headers will be sent by all requests. Not recommended to use request-specific headers, like `Authorization`.
Expand Down
1 change: 1 addition & 0 deletions Riot/Assets/en.lproj/Vector.strings
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,7 @@ Tap the + to start adding people.";
"settings_labs_create_conference_with_jitsi" = "Create conference calls with jitsi";
"settings_labs_message_reaction" = "React to messages with emoji";
"settings_labs_enable_ringing_for_group_calls" = "Ring for group calls";
"settings_labs_voice_messages" = "Voice messages";

"settings_version" = "Version %@";
"settings_olm_version" = "Olm Version %@";
Expand Down
4 changes: 4 additions & 0 deletions Riot/Generated/Strings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4378,6 +4378,10 @@ internal enum VectorL10n {
internal static var settingsLabsMessageReaction: String {
return VectorL10n.tr("Vector", "settings_labs_message_reaction")
}
/// Voice messages
internal static var settingsLabsVoiceMessages: String {
return VectorL10n.tr("Vector", "settings_labs_voice_messages")
}
/// Mark all messages as read
internal static var settingsMarkAllAsRead: String {
return VectorL10n.tr("Vector", "settings_mark_all_as_read")
Expand Down
14 changes: 14 additions & 0 deletions Riot/Managers/Settings/RiotSettings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ final class RiotSettings: NSObject {
static let roomCreationScreenRoomIsPublic = "roomCreationScreenRoomIsPublic"
static let allowInviteExernalUsers = "allowInviteExernalUsers"
static let enableRingingForGroupCalls = "enableRingingForGroupCalls"
static let enableVoiceMessages = "enableVoiceMessages"
static let roomSettingsScreenShowLowPriorityOption = "roomSettingsScreenShowLowPriorityOption"
static let roomSettingsScreenShowDirectChatOption = "roomSettingsScreenShowDirectChatOption"
static let roomSettingsScreenAllowChangingAccessSettings = "roomSettingsScreenAllowChangingAccessSettings"
Expand Down Expand Up @@ -92,6 +93,11 @@ final class RiotSettings: NSObject {
return userDefaults
}()

private override init() {
super.init()
defaults.register(defaults: [UserDefaultsKeys.enableVoiceMessages: BuildSettings.voiceMessagesEnabled])
}

// MARK: Servers

var homeserverUrlString: String {
Expand Down Expand Up @@ -214,6 +220,14 @@ final class RiotSettings: NSObject {
}
}

var enableVoiceMessages: Bool {
get {
return defaults.bool(forKey: UserDefaultsKeys.enableVoiceMessages)
} set {
defaults.set(newValue, forKey: UserDefaultsKeys.enableVoiceMessages)
}
}

// MARK: Calls

/// Indicate if `allowStunServerFallback` settings has been set once.
Expand Down
6 changes: 3 additions & 3 deletions Riot/Modules/Room/Views/InputToolbar/RoomInputToolbarView.m
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ - (void)awakeFromNib

- (void)setVoiceMessageToolbarView:(UIView *)voiceMessageToolbarView
{
if (BuildSettings.voiceMessagesEnabled == NO) {
if (RiotSettings.shared.enableVoiceMessages == NO) {
return;
}

Expand Down Expand Up @@ -407,7 +407,7 @@ - (void)setActionMenuOpened:(BOOL)actionMenuOpened
[UIView animateWithDuration:kActionMenuContentAlphaAnimationDuration delay:_actionMenuOpened ? 0 : .1 options:UIViewAnimationOptionCurveEaseIn animations:^{
self->messageComposerContainer.alpha = actionMenuOpened ? 0 : 1;
self.rightInputToolbarButton.alpha = self->growingTextView.text.length == 0 || actionMenuOpened ? 0 : 1;
if (BuildSettings.voiceMessagesEnabled)
if (RiotSettings.shared.enableVoiceMessages)
{
self.voiceMessageToolbarView.alpha = self->growingTextView.text.length > 0 || actionMenuOpened ? 0 : 1;
}
Expand Down Expand Up @@ -443,7 +443,7 @@ - (void)updateUIWithTextMessage:(NSString *)textMessage animated:(BOOL)animated
{
self.actionMenuOpened = NO;

if (BuildSettings.voiceMessagesEnabled == NO) {
if (RiotSettings.shared.enableVoiceMessages == NO) {
self.rightInputToolbarButton.alpha = textMessage.length ? 1.0f : 0.0f;
self.messageComposerContainerTrailingConstraint.constant = (textMessage.length ? self.frame.size.width - self.rightInputToolbarButton.frame.origin.x : 0.0f) + kComposerContainerTrailingPadding;

Expand Down
25 changes: 24 additions & 1 deletion Riot/Modules/Settings/SettingsViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@

enum
{
LABS_ENABLE_RINGING_FOR_GROUP_CALLS_INDEX = 0
LABS_ENABLE_RINGING_FOR_GROUP_CALLS_INDEX = 0,
LABS_ENABLE_VOICE_MESSAGES = 1
};

enum
Expand Down Expand Up @@ -487,6 +488,7 @@ - (void)updateSections
{
Section *sectionLabs = [Section sectionWithTag:SECTION_TAG_LABS];
[sectionLabs addRowWithTag:LABS_ENABLE_RINGING_FOR_GROUP_CALLS_INDEX];
[sectionLabs addRowWithTag:LABS_ENABLE_VOICE_MESSAGES];
sectionLabs.headerTitle = NSLocalizedStringFromTable(@"settings_labs", @"Vector", nil);
if (sectionLabs.hasAnyRows)
{
Expand Down Expand Up @@ -2263,6 +2265,17 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N

[labelAndSwitchCell.mxkSwitch addTarget:self action:@selector(toggleEnableRingingForGroupCalls:) forControlEvents:UIControlEventValueChanged];

cell = labelAndSwitchCell;
} else if (row == LABS_ENABLE_VOICE_MESSAGES)
{
MXKTableViewCellWithLabelAndSwitch *labelAndSwitchCell = [self getLabelAndSwitchCell:tableView forIndexPath:indexPath];

labelAndSwitchCell.mxkLabel.text = NSLocalizedStringFromTable(@"settings_labs_voice_messages", @"Vector", nil);
labelAndSwitchCell.mxkSwitch.on = RiotSettings.shared.enableVoiceMessages;
labelAndSwitchCell.mxkSwitch.onTintColor = ThemeService.shared.theme.tintColor;

[labelAndSwitchCell.mxkSwitch addTarget:self action:@selector(toggleEnableVoiceMessages:) forControlEvents:UIControlEventValueChanged];

cell = labelAndSwitchCell;
}
}
Expand Down Expand Up @@ -2963,6 +2976,16 @@ - (void)toggleEnableRingingForGroupCalls:(UISwitch *)sender
}
}

- (void)toggleEnableVoiceMessages:(UISwitch *)sender
{
if (sender)
{
RiotSettings.shared.enableVoiceMessages = sender.isOn;

[self.tableView reloadData];
}
}

- (void)togglePinRoomsWithMissedNotif:(id)sender
{
UISwitch *switchButton = (UISwitch*)sender;
Expand Down

0 comments on commit 089c688

Please sign in to comment.