merged element 1.10.12 into bum

This commit is contained in:
Arnfried Griesert
2023-06-07 15:45:59 +02:00
132 changed files with 2750 additions and 2416 deletions
@@ -144,6 +144,15 @@
*/
- (CGFloat)rawTextHeight:(NSAttributedString*)attributedText;
/**
Return the raw height of the provided text by removing any vertical margin/inset and constraining the width.
@param attributedText the attributed text to measure
@param maxTextViewWidth the maximum text width
@return the computed height
*/
- (CGFloat)rawTextHeight:(NSAttributedString*)attributedText withMaxWidth:(CGFloat)maxTextViewWidth;
/**
Return the content size of a text view initialized with the provided attributed text.
CAUTION: This method runs only on main thread.
@@ -500,23 +500,34 @@
// Return the raw height of the provided text by removing any margin
- (CGFloat)rawTextHeight: (NSAttributedString*)attributedText
{
return [self rawTextHeight:attributedText withMaxWidth:_maxTextViewWidth];
}
// Return the raw height of the provided text by removing any vertical margin/inset and constraining the width.
- (CGFloat)rawTextHeight: (NSAttributedString*)attributedText withMaxWidth:(CGFloat)maxTextViewWidth
{
__block CGSize textSize;
if ([NSThread currentThread] != [NSThread mainThread])
{
dispatch_sync(dispatch_get_main_queue(), ^{
textSize = [self textContentSize:attributedText removeVerticalInset:YES];
textSize = [self textContentSize:attributedText removeVerticalInset:YES maxTextViewWidth:maxTextViewWidth];
});
}
else
{
textSize = [self textContentSize:attributedText removeVerticalInset:YES];
textSize = [self textContentSize:attributedText removeVerticalInset:YES maxTextViewWidth:maxTextViewWidth];
}
return textSize.height;
}
- (CGSize)textContentSize:(NSAttributedString*)attributedText removeVerticalInset:(BOOL)removeVerticalInset
{
return [self textContentSize:attributedText removeVerticalInset:removeVerticalInset maxTextViewWidth:_maxTextViewWidth];
}
- (CGSize)textContentSize:(NSAttributedString*)attributedText removeVerticalInset:(BOOL)removeVerticalInset maxTextViewWidth:(CGFloat)maxTextViewWidth
{
static UITextView* measurementTextView = nil;
static UITextView* measurementTextViewWithoutInset = nil;
@@ -535,7 +546,7 @@
// Select the right text view for measurement
UITextView *selectedTextView = (removeVerticalInset ? measurementTextViewWithoutInset : measurementTextView);
selectedTextView.frame = CGRectMake(0, 0, _maxTextViewWidth, 0);
selectedTextView.frame = CGRectMake(0, 0, maxTextViewWidth, 0);
selectedTextView.attributedText = attributedText;
// Force the layout manager to layout the text, fixes problems starting iOS 16
@@ -31,8 +31,6 @@
#import "MXKAppSettings.h"
#import "MXKSlashCommands.h"
#import "GeneratedInterface-Swift.h"
const BOOL USE_THREAD_TIMELINE = YES;
@@ -316,7 +314,7 @@ typedef NS_ENUM (NSUInteger, MXKRoomDataSourceError) {
_filterMessagesWithURL = NO;
emoteMessageSlashCommandPrefix = [NSString stringWithFormat:@"%@ ", kMXKSlashCmdEmote];
emoteMessageSlashCommandPrefix = [NSString stringWithFormat:@"%@ ", [MXKSlashCommandsHelper commandNameFor:MXKSlashCommandEmote]];
// Set default data and view classes
// Cell data
@@ -458,11 +456,6 @@ typedef NS_ENUM (NSUInteger, MXKRoomDataSourceError) {
}
- (void)reset
{
[self resetNotifying:YES];
}
- (void)resetNotifying:(BOOL)notify
{
if (roomDidFlushDataNotificationObserver)
{
@@ -558,12 +551,6 @@ typedef NS_ENUM (NSUInteger, MXKRoomDataSourceError) {
}
_serverSyncEventCount = 0;
// Notify the delegate to reload its tableview
if (notify && self.delegate)
{
[self.delegate dataSource:self didCellChange:nil];
}
}
- (void)reload
@@ -577,10 +564,16 @@ typedef NS_ENUM (NSUInteger, MXKRoomDataSourceError) {
[self setState:MXKDataSourceStatePreparing];
[self resetNotifying:notify];
[self reset];
// Reload
[self didMXSessionStateChange];
// Notify the delegate to refresh the tableview
if (notify && self.delegate)
{
[self.delegate dataSource:self didCellChange:nil];
}
}
- (void)destroy
@@ -1,34 +0,0 @@
/*
Copyright 2018 New Vector Ltd
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
@import Foundation;
/**
Slash commands used to perform actions from a room.
*/
FOUNDATION_EXPORT NSString *const kMXKSlashCmdChangeDisplayName;
FOUNDATION_EXPORT NSString *const kMXKSlashCmdEmote;
FOUNDATION_EXPORT NSString *const kMXKSlashCmdJoinRoom;
FOUNDATION_EXPORT NSString *const kMXKSlashCmdPartRoom;
FOUNDATION_EXPORT NSString *const kMXKSlashCmdInviteUser;
FOUNDATION_EXPORT NSString *const kMXKSlashCmdKickUser;
FOUNDATION_EXPORT NSString *const kMXKSlashCmdBanUser;
FOUNDATION_EXPORT NSString *const kMXKSlashCmdUnbanUser;
FOUNDATION_EXPORT NSString *const kMXKSlashCmdSetUserPowerLevel;
FOUNDATION_EXPORT NSString *const kMXKSlashCmdResetUserPowerLevel;
FOUNDATION_EXPORT NSString *const kMXKSlashCmdChangeRoomTopic;
FOUNDATION_EXPORT NSString *const kMXKSlashCmdDiscardSession;
@@ -1,30 +0,0 @@
/*
Copyright 2018 New Vector Ltd
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#import "MXKSlashCommands.h"
NSString *const kMXKSlashCmdChangeDisplayName = @"/nick";
NSString *const kMXKSlashCmdEmote = @"/me";
NSString *const kMXKSlashCmdJoinRoom = @"/join";
NSString *const kMXKSlashCmdPartRoom = @"/part";
NSString *const kMXKSlashCmdInviteUser = @"/invite";
NSString *const kMXKSlashCmdKickUser = @"/kick";
NSString *const kMXKSlashCmdBanUser = @"/ban";
NSString *const kMXKSlashCmdUnbanUser = @"/unban";
NSString *const kMXKSlashCmdSetUserPowerLevel = @"/op";
NSString *const kMXKSlashCmdResetUserPowerLevel = @"/deop";
NSString *const kMXKSlashCmdChangeRoomTopic = @"/topic";
NSString *const kMXKSlashCmdDiscardSession = @"/discardsession";
@@ -0,0 +1,101 @@
//
// Copyright 2023 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
@objc final class MXKSlashCommandsHelper: NSObject {
@objc static func commandNameFor(_ slashCommand: MXKSlashCommand) -> String {
slashCommand.cmd
}
@objc static func commandUsageFor(_ slashCommand: MXKSlashCommand) -> String {
"Usage: \(slashCommand.cmd) \(slashCommand.parametersFormat)"
}
}
@objc enum MXKSlashCommand: Int, CaseIterable {
case changeDisplayName
case emote
case joinRoom
case partRoom
case inviteUser
case kickUser
case banUser
case unbanUser
case setUserPowerLevel
case resetUserPowerLevel
case changeRoomTopic
case discardSession
var cmd: String {
switch self {
case .changeDisplayName:
return "/nick"
case .emote:
return "/me"
case .joinRoom:
return "/join"
case .partRoom:
return "/part"
case .inviteUser:
return "/invite"
case .kickUser:
return "/kick"
case .banUser:
return "/ban"
case .unbanUser:
return "/unban"
case .setUserPowerLevel:
return "/op"
case .resetUserPowerLevel:
return "/deop"
case .changeRoomTopic:
return "/topic"
case .discardSession:
return "/discardsession"
}
}
// Note: not localized for consistency, as commands are in english
// also translating these parameters could lead to inconsistency in
// the UI in case of languages with overlength translation.
var parametersFormat: String {
switch self {
case .changeDisplayName:
return "<display_name>"
case .emote:
return "<message>"
case .joinRoom:
return "<room-address>"
case .partRoom:
return "[<room-address>]"
case .inviteUser:
return "<user-id>"
case .kickUser:
return "<user-id> [<reason>]"
case .banUser:
return "<user-id> [<reason>]"
case .unbanUser:
return "<user-id>"
case .setUserPowerLevel:
return "<user-id> <power-level>"
case .resetUserPowerLevel:
return "<user-id>"
case .changeRoomTopic:
return "<topic>"
case .discardSession:
return ""
}
}
}