mirror of
https://gitlab.opencode.de/bwi/bundesmessenger/clients/bundesmessenger-ios.git
synced 2026-04-21 17:12:45 +02:00
b298dedc22
Merge commit 'f823ab9aae70e8d15ed7cc079210dd9bbbb6c8e1' into feature/foss_update_1_11_19 * commit 'f823ab9aae70e8d15ed7cc079210dd9bbbb6c8e1': finish version++ version++ comments update submodule remove obsolete tests removed unused code update submodule fix Libolm removal update license macro update license Prepare for new sprint # Conflicts: # Config/AppVersion.xcconfig # IDETemplateMacros.plist # LICENSE # README.md # Riot/Categories/MXSession+Riot.m # Riot/Managers/EncryptionKeyManager/EncryptionKeyManager.swift # Riot/Managers/KeyValueStorage/Extensions/Keychain.swift # Riot/Managers/KeyValueStorage/KeyValueStore.swift # Riot/Managers/KeyValueStorage/KeychainStore.swift # Riot/Managers/KeyValueStorage/MemoryStore.swift # Riot/Managers/PushNotification/PushNotificationService.m # Riot/Managers/Settings/RiotSettings.swift # Riot/Managers/Settings/Shared/RiotSharedSettings.swift # Riot/Modules/Analytics/AnalyticsUIElement.swift # Riot/Modules/Application/AppCoordinator.swift # Riot/Modules/Application/LegacyAppDelegate.h # Riot/Modules/Application/LegacyAppDelegate.m # Riot/Modules/Authentication/Legacy/AuthenticationViewController.h # Riot/Modules/Authentication/Legacy/AuthenticationViewController.m # Riot/Modules/Authentication/Legacy/Views/AuthInputsView.h # Riot/Modules/Authentication/Legacy/Views/AuthInputsView.m # Riot/Modules/Common/Recents/DataSources/RecentsDataSource.m # Riot/Modules/Common/Recents/RecentsViewController.m # Riot/Modules/Common/WebViewController/WebViewViewController.m # Riot/Modules/Contacts/Details/ContactDetailsViewController.m # Riot/Modules/Contacts/Views/ContactTableViewCell.m # Riot/Modules/Favorites/FavouritesViewController.h # Riot/Modules/Favorites/FavouritesViewController.m # Riot/Modules/GlobalSearch/UnifiedSearchViewController.m # Riot/Modules/People/PeopleViewController.h # Riot/Modules/People/PeopleViewController.m # Riot/Modules/Room/ContextualMenu/ReactionsMenu/ReactionsMenuViewModel.swift # Riot/Modules/Room/DataSources/RoomDataSource.m # Riot/Modules/Room/Files/RoomFilesViewController.m # Riot/Modules/Room/Members/Detail/RoomMemberDetailsViewController.m # Riot/Modules/Room/Members/RoomParticipantsViewController.m # Riot/Modules/Room/RoomViewController.m # Riot/Modules/Room/Settings/RoomSettingsViewController.m # Riot/Modules/Room/TimelineCells/RoomCreationIntro/RoomCreationIntroCell.swift # Riot/Modules/Room/TimelineCells/RoomCreationIntro/RoomCreationIntroCellContentView.swift # Riot/Modules/Room/TimelineCells/RoomCreationIntro/RoomCreationIntroViewData.swift # Riot/Modules/Room/TimelineCells/RoomTimelineCellIdentifier.h # Riot/Modules/Rooms/RoomsViewController.h # Riot/Modules/Rooms/ShowDirectory/Cells/Network/DirectoryNetworkTableHeaderFooterView.swift # Riot/Modules/Rooms/ShowDirectory/Cells/Room/DirectoryRoomTableViewCell.swift # Riot/Modules/Rooms/ShowDirectory/PublicRoomsDirectoryViewModel.swift # Riot/Modules/Secrets/Recover/RecoverWithKey/SecretsRecoveryWithKeyCoordinator.swift # Riot/Modules/Secrets/Recover/RecoverWithKey/SecretsRecoveryWithKeyViewController.swift # Riot/Modules/Secrets/Recover/RecoverWithPassphrase/SecretsRecoveryWithPassphraseCoordinator.swift # Riot/Modules/Secrets/Recover/RecoverWithPassphrase/SecretsRecoveryWithPassphraseViewController.swift # Riot/Modules/Secrets/Recover/SecretsRecoveryCoordinator.swift # Riot/Modules/SecureBackup/Setup/Intro/SecureBackupSetupIntroViewController.swift # Riot/Modules/SecureBackup/Setup/Intro/SecureBackupSetupIntroViewModel.swift # Riot/Modules/SecureBackup/Setup/Intro/SecureBackupSetupIntroViewModelType.swift # Riot/Modules/SetPinCode/PinCodePreferences.swift # Riot/Modules/SetPinCode/SetupBiometrics/BiometricsAuthenticationPresenter.swift # Riot/Modules/Settings/Security/ManageSession/ManageSessionViewController.m # Riot/Modules/Settings/Security/SecurityViewController.m # Riot/Modules/Settings/SettingsViewController.m # Riot/Modules/SplitView/SplitViewCoordinator.swift # Riot/Modules/SplitView/SplitViewCoordinatorType.swift # Riot/Modules/StartChat/StartChatViewController.m # Riot/Modules/TabBar/MasterTabBarController.h # Riot/Modules/TabBar/MasterTabBarController.m # Riot/Utils/EventFormatter.m # Riot/Utils/HTMLFormatter.swift # Riot/Utils/Tools.m # RiotNSE/NotificationService.swift
199 lines
5.9 KiB
Objective-C
199 lines
5.9 KiB
Objective-C
/*
|
|
Copyright 2024 New Vector Ltd.
|
|
Copyright 2016 OpenMarket Ltd
|
|
Copyright (c) 2021 BWI GmbH
|
|
|
|
SPDX-License-Identifier: AGPL-3.0-only
|
|
Please see LICENSE in the repository root for full details.
|
|
*/
|
|
|
|
#import "Tools.h"
|
|
#import "GeneratedInterface-Swift.h"
|
|
#import "MXKSwiftHeader.h"
|
|
|
|
#define MAX_BWI_IMAGE_SIZE 1600
|
|
|
|
@implementation Tools
|
|
|
|
+ (NSString *)presenceText:(MXUser *)user
|
|
{
|
|
NSString* presenceText = [VectorL10n roomParticipantsUnknown];
|
|
|
|
if (user)
|
|
{
|
|
switch (user.presence)
|
|
{
|
|
case MXPresenceOnline:
|
|
presenceText = [VectorL10n roomParticipantsOnline];
|
|
break;
|
|
|
|
case MXPresenceUnavailable:
|
|
presenceText = [VectorL10n roomParticipantsIdle];
|
|
break;
|
|
|
|
case MXPresenceUnknown:
|
|
// Fix https://github.com/vector-im/element-ios/issues/6597
|
|
// Return nil because we don't want to display anything if the status is unknown
|
|
return nil;
|
|
|
|
case MXPresenceOffline:
|
|
presenceText = [VectorL10n roomParticipantsOffline];
|
|
break;
|
|
|
|
default:
|
|
break;
|
|
}
|
|
|
|
if (user.currentlyActive)
|
|
{
|
|
presenceText = [presenceText stringByAppendingString:[NSString stringWithFormat:@" %@",[VectorL10n roomParticipantsNow]]];
|
|
}
|
|
else if (-1 != user.lastActiveAgo && 0 < user.lastActiveAgo)
|
|
{
|
|
presenceText = [presenceText stringByAppendingString:[NSString stringWithFormat:@" %@ %@",
|
|
[MXKTools formatSecondsIntervalFloored:(user.lastActiveAgo / 1000)],
|
|
[VectorL10n roomParticipantsAgo]]];
|
|
}
|
|
}
|
|
|
|
return presenceText;
|
|
}
|
|
|
|
#pragma mark - Universal link
|
|
|
|
+ (BOOL)isUniversalLink:(NSURL*)url
|
|
{
|
|
BOOL isUniversalLink = NO;
|
|
|
|
for (NSString *matrixPermalinkHost in BWIBuildSettings.shared.permalinkSupportedHosts)
|
|
{
|
|
if ([url.host isEqualToString:matrixPermalinkHost])
|
|
{
|
|
NSArray<NSString*> *hostPaths = BWIBuildSettings.shared.permalinkSupportedHosts[matrixPermalinkHost];
|
|
if (hostPaths.count)
|
|
{
|
|
// iOS Patch: fix urls before using it
|
|
NSURL *fixedURL = [Tools fixURLWithSeveralHashKeys:url];
|
|
|
|
if (NSNotFound != [hostPaths indexOfObject:fixedURL.path])
|
|
{
|
|
isUniversalLink = YES;
|
|
break;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
isUniversalLink = YES;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
// bwi: 5603 fix link in reply to - handle in app
|
|
if ([url.host isEqualToString:[AppConfigService.shared permalinkHost]]) {
|
|
isUniversalLink = YES;
|
|
}
|
|
else
|
|
{
|
|
NSURLComponents *components = [[NSURLComponents alloc] initWithString:[MXSDKOptions sharedInstance].clientPermalinkBaseUrl];
|
|
if (components)
|
|
{
|
|
if (components.host)
|
|
{
|
|
if ([url.host isEqualToString:components.host]) {
|
|
isUniversalLink = YES;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return isUniversalLink;
|
|
}
|
|
|
|
+ (NSURL *)fixURLWithSeveralHashKeys:(NSURL *)url
|
|
{
|
|
NSURL *fixedURL = url;
|
|
|
|
// The NSURL may have no fragment because it contains more that '%23' occurence
|
|
if (!url.fragment)
|
|
{
|
|
// Replacing the first '%23' occurence into a '#' makes NSURL works correctly
|
|
NSString *urlString = url.absoluteString;
|
|
NSRange range = [urlString rangeOfString:@"%23"];
|
|
if (NSNotFound != range.location)
|
|
{
|
|
urlString = [urlString stringByReplacingCharactersInRange:range withString:@"#"];
|
|
fixedURL = [NSURL URLWithString:urlString];
|
|
}
|
|
}
|
|
|
|
return fixedURL;
|
|
}
|
|
|
|
#pragma mark - String utilities
|
|
|
|
+ (NSAttributedString *)setTextColorAlpha:(CGFloat)alpha inAttributedString:(NSAttributedString*)attributedString
|
|
{
|
|
NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithAttributedString:attributedString];
|
|
|
|
// Check all attributes one by one
|
|
[string enumerateAttributesInRange:NSMakeRange(0, attributedString.length) options:0 usingBlock:^(NSDictionary *attrs, NSRange range, BOOL *stop)
|
|
{
|
|
// Replace only colored texts
|
|
if (attrs[NSForegroundColorAttributeName])
|
|
{
|
|
UIColor *color = attrs[NSForegroundColorAttributeName];
|
|
color = [color colorWithAlphaComponent:alpha];
|
|
|
|
NSMutableDictionary *newAttrs = [NSMutableDictionary dictionaryWithDictionary:attrs];
|
|
newAttrs[NSForegroundColorAttributeName] = color;
|
|
|
|
[string setAttributes:newAttrs range:range];
|
|
}
|
|
}];
|
|
|
|
return string;
|
|
}
|
|
|
|
#pragma mark - NSData utilities
|
|
|
|
+ (NSData*)mediaConvertMaxImageData:(NSData*) imageData withUTI:(MXKUTI *)uti
|
|
{
|
|
NSData *convertedData;
|
|
|
|
/**
|
|
* Reduce the image size to MAX_BWI_IMAGE_SIZE to be conform
|
|
* with the BWI back-end server system.
|
|
*/
|
|
CGSize newImageSize = CGSizeMake(MAX_BWI_IMAGE_SIZE, MAX_BWI_IMAGE_SIZE);
|
|
UIImage* convertedImage = [MXKTools resizeImageWithData:imageData toFitInSize:newImageSize];
|
|
|
|
if (convertedImage)
|
|
{
|
|
if ([uti.mimeType isEqualToString:@"image/png"])
|
|
{
|
|
convertedData = UIImagePNGRepresentation(convertedImage);
|
|
}
|
|
else if ([uti.mimeType isEqualToString:@"image/jpeg"])
|
|
{
|
|
convertedData = UIImageJPEGRepresentation(convertedImage, 0.9);
|
|
}
|
|
else
|
|
{
|
|
// Return the original image data pointer
|
|
return imageData;
|
|
}
|
|
}
|
|
|
|
return convertedData;
|
|
}
|
|
|
|
#pragma mark - Time utilities
|
|
|
|
+ (uint64_t)durationInMsFromDays:(uint)days
|
|
{
|
|
return days * (uint64_t)(86400000);
|
|
}
|
|
|
|
@end
|