aboutsummaryrefslogtreecommitdiff
path: root/QSThingsPlugin/Actions
diff options
context:
space:
mode:
authorRuben Beltran del Rio <git@r.bdr.sh>2025-09-11 12:32:54 +0200
committerRuben Beltran del Rio <git@r.bdr.sh>2025-09-11 12:32:54 +0200
commit397cb011a540d53974a87d94a8ff8576e2024b63 (patch)
tree616de785531442329f42333724c9fa9a728cf4e3 /QSThingsPlugin/Actions
parent1613c951d49e6d85aff52f312d57fa087b35c079 (diff)
Add create actions
Diffstat (limited to 'QSThingsPlugin/Actions')
-rw-r--r--QSThingsPlugin/Actions/CompleteTaskAction.m7
-rw-r--r--QSThingsPlugin/Actions/CreateTaskAction.h13
-rw-r--r--QSThingsPlugin/Actions/CreateTaskAction.m47
3 files changed, 61 insertions, 6 deletions
diff --git a/QSThingsPlugin/Actions/CompleteTaskAction.m b/QSThingsPlugin/Actions/CompleteTaskAction.m
index 5ff1bd0..afc55ac 100644
--- a/QSThingsPlugin/Actions/CompleteTaskAction.m
+++ b/QSThingsPlugin/Actions/CompleteTaskAction.m
@@ -7,13 +7,8 @@ NS_ASSUME_NONNULL_BEGIN
- (QSObject *)completeTask:(QSObject *)directObject
{
NSSet *validTypes = [NSSet setWithObjects:kProjectType, kTaskType, nil];
- NSString *authenticationKey = [KeychainHelper authenticationKey];
- if (!authenticationKey) {
- NSLog(@"There is no authentication key.");
- }
-
- if (authenticationKey && [validTypes containsObject:directObject.primaryType]) {
+ if ([validTypes containsObject:directObject.primaryType]) {
NSDictionary *contents = [directObject objectForType:directObject.primaryType];
ThingsURLRoute route = ThingsURLRouteUpdate;
if (directObject.primaryType == kProjectType) {
diff --git a/QSThingsPlugin/Actions/CreateTaskAction.h b/QSThingsPlugin/Actions/CreateTaskAction.h
new file mode 100644
index 0000000..36c5c3c
--- /dev/null
+++ b/QSThingsPlugin/Actions/CreateTaskAction.h
@@ -0,0 +1,13 @@
+#import "Constants.h"
+#import "ThingsHelper.h"
+#import "TextParsingHelper.h"
+#import <Foundation/Foundation.h>
+#import <QSCore/QSCore.h>
+
+NS_ASSUME_NONNULL_BEGIN
+
+@interface CreateTaskAction : QSActionProvider
+
+@end
+
+NS_ASSUME_NONNULL_END
diff --git a/QSThingsPlugin/Actions/CreateTaskAction.m b/QSThingsPlugin/Actions/CreateTaskAction.m
new file mode 100644
index 0000000..f11936f
--- /dev/null
+++ b/QSThingsPlugin/Actions/CreateTaskAction.m
@@ -0,0 +1,47 @@
+#import "CreateTaskAction.h"
+
+NS_ASSUME_NONNULL_BEGIN
+
+@implementation CreateTaskAction
+
+- (QSObject *)createTask:(QSObject *)directObject
+{
+ NSString *contents = [directObject displayName];
+ if (contents) {
+ NSDictionary *parameters = [TextParsingHelper parseText: contents];
+ [ThingsHelper callRoute:ThingsURLRouteAdd withParameters:parameters];
+ } else {
+ NSLog(@"Could not get the text of the Things object.");
+ }
+ return directObject;
+}
+
+- (QSObject *)createTask:(QSObject *)directObject in:(QSObject *)indirectObject
+{
+ NSString *contents = [directObject displayName];
+
+ NSDictionary *indirectContents = [indirectObject objectForType:indirectObject.primaryType];
+ NSString *listId = nil;
+ if (indirectContents) {
+ listId = [indirectContents objectForKey:@"uuid"];
+ } else {
+ NSLog(@"Could not read the contents for the indirect object");
+ }
+
+ if (contents) {
+ NSMutableDictionary *parameters = [TextParsingHelper parseText: contents];
+ if (listId) {
+ [parameters setObject:listId forKey:@"list-id"];
+ } else {
+ NSLog(@"Could not find a list id");
+ }
+ [ThingsHelper callRoute:ThingsURLRouteAdd withParameters:parameters];
+ } else {
+ NSLog(@"Could not get the text of the Things object.");
+ }
+ return directObject;
+}
+
+@end
+
+NS_ASSUME_NONNULL_END