Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remind me later #1320

Merged
merged 8 commits into from
Aug 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions NextcloudTalk.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
1F1C999E2909846400EACF02 /* BGTaskHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1FD9182828C55A73009092AB /* BGTaskHelper.swift */; };
1F24B5A228E0648600654457 /* ReferenceGithubView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1F24B5A128E0648600654457 /* ReferenceGithubView.swift */; };
1F24B5A428E0649200654457 /* ReferenceGithubView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 1F24B5A328E0649200654457 /* ReferenceGithubView.xib */; };
1F371A372A7B921A006CBFB3 /* DatePickerTextField.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1F371A362A7B921A006CBFB3 /* DatePickerTextField.swift */; };
1F3C419F29EDAC7D00F58435 /* RoomAvatarInfoTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1F3C419E29EDAC7D00F58435 /* RoomAvatarInfoTableViewController.swift */; };
1F3C41A129EDAC8800F58435 /* RoomAvatarInfoTableViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 1F3C41A029EDAC8800F58435 /* RoomAvatarInfoTableViewController.xib */; };
1F3C41A329EDF05700F58435 /* AvatarEditView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1F3C41A229EDF05700F58435 /* AvatarEditView.swift */; };
Expand Down Expand Up @@ -435,6 +436,7 @@
1F1C0D8829AFB89900D17C6D /* VLCKitVideoViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VLCKitVideoViewController.swift; sourceTree = "<group>"; };
1F24B5A128E0648600654457 /* ReferenceGithubView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ReferenceGithubView.swift; sourceTree = "<group>"; };
1F24B5A328E0649200654457 /* ReferenceGithubView.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = ReferenceGithubView.xib; sourceTree = "<group>"; };
1F371A362A7B921A006CBFB3 /* DatePickerTextField.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatePickerTextField.swift; sourceTree = "<group>"; };
1F3C419E29EDAC7D00F58435 /* RoomAvatarInfoTableViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RoomAvatarInfoTableViewController.swift; sourceTree = "<group>"; };
1F3C41A029EDAC8800F58435 /* RoomAvatarInfoTableViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = RoomAvatarInfoTableViewController.xib; sourceTree = "<group>"; };
1F3C41A229EDF05700F58435 /* AvatarEditView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AvatarEditView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1111,6 +1113,7 @@
1F61C76A285F65E1004D74D8 /* SimpleTableViewController.swift */,
1FB6678E28CE381300D29F8D /* SubtitleTableViewCell.swift */,
1F468E7728DCC7310099597B /* EmojiTextField.swift */,
1F371A362A7B921A006CBFB3 /* DatePickerTextField.swift */,
2C16A82B28E7284D00EDE523 /* NCButton.swift */,
1F11FB7129C07B04001E21E7 /* NCZoomableView.swift */,
1F8995B22970644C00CABA33 /* ColorGenerator.swift */,
Expand Down Expand Up @@ -2216,6 +2219,7 @@
1FB52E762842C75E00AC741B /* QRCodeLoginController.swift in Sources */,
2C4446D8265814D100DF1DBC /* ServerCapabilities.m in Sources */,
DA66582D27B6A73800B46B11 /* UserProfileTableViewController+DelegateMethods.swift in Sources */,
1F371A372A7B921A006CBFB3 /* DatePickerTextField.swift in Sources */,
1F5CDF642584E78900B0026E /* NCChatFileStatus.m in Sources */,
1FE0C56E2A0531270083576A /* ReferenceTalkView.swift in Sources */,
2CBF82C11FD5AE3F00636459 /* NCPushProxySessionManager.m in Sources */,
Expand Down
79 changes: 79 additions & 0 deletions NextcloudTalk/DatePickerTextField.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
//
// Copyright (c) 2023 Marcel Müller <[email protected]>
//
// Author Marcel Müller <[email protected]>
//
// GNU GPL version 3 or any later version
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//

@objcMembers class DatePickerTextField: UITextField {

public let datePicker = UIDatePicker()

override init(frame: CGRect) {
super.init(frame: frame)

self.commonInit()
}

required init?(coder: NSCoder) {
super.init(coder: coder)

self.commonInit()
}

private func commonInit() {
self.tintColor = .clear
}

public func getDate(startingDate: Date?, minimumDate: Date?, completion: @escaping (Date) -> Void) {
guard self.canBecomeFirstResponder else {
return
}

datePicker.datePickerMode = .dateAndTime
datePicker.locale = .current
datePicker.preferredDatePickerStyle = .wheels

if let startingDate {
datePicker.date = startingDate
}

if let minimumDate {
datePicker.minimumDate = minimumDate
}

self.inputView = datePicker

let cancelButton = UIBarButtonItem(systemItem: .cancel, primaryAction: UIAction { [weak self] _ in
self?.resignFirstResponder()
})

let doneButton = UIBarButtonItem(systemItem: .done, primaryAction: UIAction { [weak self] _ in
if let self {
completion(self.datePicker.date)
self.resignFirstResponder()
}
})

let toolBar = UIToolbar(frame: .init(x: 0, y: 0, width: 320, height: 44))
toolBar.setItems([cancelButton, UIBarButtonItem(systemItem: .flexibleSpace), doneButton], animated: false)

self.inputAccessoryView = toolBar

self.becomeFirstResponder()
}
}
10 changes: 10 additions & 0 deletions NextcloudTalk/NCAPIController.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,10 @@ typedef void (^StopRecordingCompletionBlock)(NSError *error);
typedef void (^DismissStoredRecordingNotificationCompletionBlock)(NSError *error);
typedef void (^ShareStoredRecordingCompletionBlock)(NSError *error);

typedef void (^SetReminderForMessage)(NSError *error);
typedef void (^DeleteReminderForMessage)(NSError *error);
typedef void (^GetReminderForMessage)(NSDictionary *responseDict, NSError *error);

extern NSInteger const APIv1;
extern NSInteger const APIv2;
extern NSInteger const APIv3;
Expand Down Expand Up @@ -307,4 +311,10 @@ extern NSInteger const kReceivedChatMessagesLimit;
- (NSURLSessionDataTask *)dismissStoredRecordingNotificationWithTimestamp:(NSString *)timestamp forRoom:(NSString *)token forAccount:(TalkAccount *)account withCompletionBlock:(DismissStoredRecordingNotificationCompletionBlock)block;
- (NSURLSessionDataTask *)shareStoredRecordingWithTimestamp:(NSString *)timestamp withFileId:(NSString *)fileId forRoom:(NSString *)token forAccount:(TalkAccount *)account withCompletionBlock:(ShareStoredRecordingCompletionBlock)block;

// Remind me later
- (NSURLSessionDataTask *)setReminderForMessage:(NCChatMessage *)message withTimestamp:(NSString *)timestamp withCompletionBlock:(SetReminderForMessage)block;
- (NSURLSessionDataTask *)deleteReminderForMessage:(NCChatMessage *)message withCompletionBlock:(DeleteReminderForMessage)block;
- (NSURLSessionDataTask *)getReminderForMessage:(NCChatMessage *)message withCompletionBlock:(GetReminderForMessage)block;


@end
80 changes: 80 additions & 0 deletions NextcloudTalk/NCAPIController.m
Original file line number Diff line number Diff line change
Expand Up @@ -3116,6 +3116,86 @@ - (NSURLSessionDataTask *)shareStoredRecordingWithTimestamp:(NSString *)timestam
return task;
}

#pragma mark - Remind me later

- (NSURLSessionDataTask *)setReminderForMessage:(NCChatMessage *)message withTimestamp:(NSString *)timestamp withCompletionBlock:(SetReminderForMessage)block
{
TalkAccount *account = [[NCDatabaseManager sharedInstance] talkAccountForAccountId:message.accountId];
NSInteger chatAPIVersion = [self chatAPIVersionForAccount:account];
NSString *encodedToken = [message.token stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLHostAllowedCharacterSet]];
NSString *endpoint = [NSString stringWithFormat:@"chat/%@/%ld/reminder", encodedToken, (long)message.messageId];
NSString *URLString = [self getRequestURLForEndpoint:endpoint withAPIVersion:chatAPIVersion forAccount:account];

NSDictionary *parameters = @{
@"timestamp" : timestamp
};

NCAPISessionManager *apiSessionManager = [_apiSessionManagers objectForKey:account.accountId];
NSURLSessionDataTask *task = [apiSessionManager POST:URLString parameters:parameters progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
if (block) {
block(nil);
}
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
NSInteger statusCode = [self getResponseStatusCode:task.response];
[self checkResponseStatusCode:statusCode forAccount:account];
if (block) {
block(error);
}
}];

return task;
}

- (NSURLSessionDataTask *)deleteReminderForMessage:(NCChatMessage *)message withCompletionBlock:(DeleteReminderForMessage)block
{
TalkAccount *account = [[NCDatabaseManager sharedInstance] talkAccountForAccountId:message.accountId];
NSInteger chatAPIVersion = [self chatAPIVersionForAccount:account];
NSString *encodedToken = [message.token stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLHostAllowedCharacterSet]];
NSString *endpoint = [NSString stringWithFormat:@"chat/%@/%ld/reminder", encodedToken, (long)message.messageId];
NSString *URLString = [self getRequestURLForEndpoint:endpoint withAPIVersion:chatAPIVersion forAccount:account];

NCAPISessionManager *apiSessionManager = [_apiSessionManagers objectForKey:account.accountId];
NSURLSessionDataTask *task = [apiSessionManager DELETE:URLString parameters:nil success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
if (block) {
NSDictionary *responseDict = [[responseObject objectForKey:@"ocs"] objectForKey:@"data"];
block(nil);
}
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
NSInteger statusCode = [self getResponseStatusCode:task.response];
[self checkResponseStatusCode:statusCode forAccount:account];
if (block) {
block(error);
}
}];

return task;
}

- (NSURLSessionDataTask *)getReminderForMessage:(NCChatMessage *)message withCompletionBlock:(GetReminderForMessage)block
{
TalkAccount *account = [[NCDatabaseManager sharedInstance] talkAccountForAccountId:message.accountId];
NSInteger chatAPIVersion = [self chatAPIVersionForAccount:account];
NSString *encodedToken = [message.token stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLHostAllowedCharacterSet]];
NSString *endpoint = [NSString stringWithFormat:@"chat/%@/%ld/reminder", encodedToken, (long)message.messageId];
NSString *URLString = [self getRequestURLForEndpoint:endpoint withAPIVersion:chatAPIVersion forAccount:account];

NCAPISessionManager *apiSessionManager = [_apiSessionManagers objectForKey:account.accountId];
NSURLSessionDataTask *task = [apiSessionManager GET:URLString parameters:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
if (block) {
NSDictionary *responseDict = [[responseObject objectForKey:@"ocs"] objectForKey:@"data"];
block(responseDict, nil);
}
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
NSInteger statusCode = [self getResponseStatusCode:task.response];
[self checkResponseStatusCode:statusCode forAccount:account];
if (block) {
block(nil, error);
}
}];

return task;
}

#pragma mark - Error handling

- (NSInteger)getResponseStatusCode:(NSURLResponse *)response
Expand Down
Loading
Loading