element-ios/SiriIntents/IntentHandler.m
wtimme 2babca6d7b
Target SiriIntents: Split IntentHandler into smaller files (#6203)
* Add protocol `ContactResolving`

* Let the `IntentHandler` implement `ContactResolving` (#6203)

Nothing has changed about the implementation itself; this prepares
the separation of this logic into a dedicated unit.

* Prepare the separation of the contact resolver from the intents handler (#6203)

* Move the implementation of `ContactResolving` to a dedicated class (#6203)

* Move `ContactResolver` to a dedicated file (#6203)

* Prepare the separation of the `StartAudioCallIntentHandler` from `IntentsHandler` (#6203)

* Move the implementation of `INStartAudioCallIntentHandling` to a dedicated class (#6203)

* Prepare the separation of the `StartVideoCallIntentHandler` from `IntentsHandler` (#6203)

* Move the implementation of `INStartVideoCallIntentHandling` to a dedicated class (#6203)

* Prepare the separation of the `SendMessageIntentHandler` from `IntentsHandler` (#6203)

* Move the implementation of `INSendMessageIntentHandling` to a dedicated class (#6203)

* Remove unused property (#6203)

* Return `nil` if the requested intent cannot be handled (#6203)

* Initialize the intent handlers _after_ everything else is configured (#6203)

In `init()`, there might be some configuration being done that is
required for the handlers.

* Add changelog entry

* Move curly braces in Objective-C to dedicated lines

This ensures that the code follows the style that is present in other Objective-C files.

Co-authored-by: Doug <6060466+pixlwave@users.noreply.github.com>

* Inject the `ContactResolver` into the intent handlers during initialization

In #6365, @pixlwave pointed out that

> If the resolver ever gained a cache or stored properties it would
> help keep the memory usage down in the extension

* Prefer forward-declaration over import in Objective-C header files

Per @pixlwave, this helps prevent build failures:

> We had random cycle errors while building a while back and it was
> eventually solved by removing all imports of `GeneratedInterface-Swift.h`
> in every [Objective-C header] file.

Co-authored-by: Doug <6060466+pixlwave@users.noreply.github.com>
2022-07-06 09:39:38 +01:00

92 lines
3.1 KiB
Objective-C

/*
Copyright 2017 Vector Creations 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 "IntentHandler.h"
#import "GeneratedInterface-Swift.h"
#import "MXKAccountManager.h"
#import "ContactResolver.h"
#import "StartAudioCallIntentHandler.h"
#import "StartVideoCallIntentHandler.h"
#import "SendMessageIntentHandler.h"
#if __has_include(<MatrixSDK/MXJingleCallStack.h>)
#define CALL_STACK_JINGLE
#endif
@interface IntentHandler ()
// Build Settings
@property (nonatomic) id<Configurable> configuration;
@property (nonatomic) id<INStartAudioCallIntentHandling> startAudioCallIntentHandler;
@property (nonatomic) id<INStartVideoCallIntentHandling> startVideoCallIntentHandler;
@property (nonatomic) id<INSendMessageIntentHandling> sendMessageIntentHandler;
@end
@implementation IntentHandler
- (instancetype)init
{
self = [super init];
if (self)
{
// Set static application settings
_configuration = [CommonConfiguration new];
[_configuration setupSettings];
// NSLog -> console.log file when not debugging the app
MXLogConfiguration *configuration = [[MXLogConfiguration alloc] init];
configuration.logLevel = MXLogLevelVerbose;
configuration.logFilesSizeLimit = 0;
configuration.maxLogFilesCount = 10;
configuration.subLogName = @"siri";
// Redirect NSLogs to files only if we are not debugging
if (!isatty(STDERR_FILENO)) {
configuration.redirectLogsToFiles = YES;
}
[MXLog configure:configuration];
// Configure our analytics. It will start if the option is enabled
Analytics *analytics = Analytics.shared;
[MXSDKOptions sharedInstance].analyticsDelegate = analytics;
[analytics startIfEnabled];
id<ContactResolving> contactResolver = [[ContactResolver alloc] init];
_startAudioCallIntentHandler = [[StartAudioCallIntentHandler alloc] initWithContactResolver:contactResolver];
_startVideoCallIntentHandler = [[StartVideoCallIntentHandler alloc] initWithContactResolver:contactResolver];
_sendMessageIntentHandler = [[SendMessageIntentHandler alloc] initWithContactResolver:contactResolver];
}
return self;
}
- (id)handlerForIntent:(INIntent *)intent
{
if ([intent isKindOfClass:[INStartAudioCallIntent class]]) {
return self.startAudioCallIntentHandler;
} else if ([intent isKindOfClass:[INStartVideoCallIntent class]]) {
return self.startVideoCallIntentHandler;
} else if ([intent isKindOfClass:[INSendMessageIntent class]]) {
return self.sendMessageIntentHandler;
}
return nil;
}
@end