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

📝 Note to self #1378

Merged
merged 8 commits into from
Oct 18, 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
29 changes: 29 additions & 0 deletions NextcloudTalk/BaseChatViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -926,6 +926,35 @@
self.presentWithNavigation(shareViewController, animated: true)
}

func didPressNoteToSelf(for message: NCChatMessage) {
let activeAccount = NCDatabaseManager.sharedInstance().activeAccount()

NCAPIController.sharedInstance().getNoteToSelfRoom(for: activeAccount) { roomDict, error in
if error == nil, let room = NCRoom(dictionary: roomDict, andAccountId: activeAccount.accountId) {

if message.isObjectShare() {
NCAPIController.sharedInstance().shareRichObject(message.richObjectFromObjectShare(), inRoom: room.token, for: activeAccount) { error in
if error == nil {
self.view.makeToast(NSLocalizedString("Added note to self", comment: ""), duration: 1.5, position: CSToastPositionCenter)
} else {
self.view.makeToast(NSLocalizedString("An error occurred while adding note", comment: ""), duration: 1.5, position: CSToastPositionCenter)
}
}
} else {
NCAPIController.sharedInstance().sendChatMessage(message.parsedMessage().string, toRoom: room.token, displayName: nil, replyTo: -1, referenceId: nil, silently: false, for: activeAccount) { error in
if error == nil {
self.view.makeToast(NSLocalizedString("Added note to self", comment: ""), duration: 1.5, position: CSToastPositionCenter)
} else {
self.view.makeToast(NSLocalizedString("An error occurred while adding note", comment: ""), duration: 1.5, position: CSToastPositionCenter)
}
}
}
} else {
self.view.makeToast(NSLocalizedString("An error occurred while adding note", comment: ""), duration: 1.5, position: CSToastPositionCenter)
}
}
}

func didPressResend(for message: NCChatMessage) {
// Make sure there's no unread message separator, as the indexpath could be invalid after removing a message
self.removeUnreadMessagesSeparator()
Expand Down Expand Up @@ -2327,7 +2356,7 @@
return super.numberOfSections(in: tableView)
}

// TODO: There should be a better place to do this

Check warning on line 2359 in NextcloudTalk/BaseChatViewController.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

Todo Violation: TODOs should be resolved (There should be a better place...) (todo)
if tableView == self.tableView, !self.dateSections.isEmpty {
tableView.backgroundView = nil
} else {
Expand Down Expand Up @@ -2719,7 +2748,7 @@
let maxPreviewWidth = self.view.bounds.size.width - self.view.safeAreaInsets.left - self.view.safeAreaInsets.right
let maxPreviewHeight = self.view.bounds.size.height * 0.6

// TODO: Take padding into account

Check warning on line 2751 in NextcloudTalk/BaseChatViewController.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

Todo Violation: TODOs should be resolved (Take padding into account) (todo)
let maxTextWidth = maxPreviewWidth - kChatCellAvatarHeight

// We need to get the height of the original cell to center the preview correctly (as the preview is always non-grouped)
Expand Down
17 changes: 13 additions & 4 deletions NextcloudTalk/ChatViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@
private lazy var voiceCallButton: BarButtonItemWithActivity = {
let voiceCallButton = self.getBarButton(forVideo: false)

videoCallButton.accessibilityLabel = NSLocalizedString("Voice call", comment: "")
videoCallButton.accessibilityHint = NSLocalizedString("Double tap to start a voice call", comment: "")
voiceCallButton.accessibilityLabel = NSLocalizedString("Voice call", comment: "")
voiceCallButton.accessibilityHint = NSLocalizedString("Double tap to start a voice call", comment: "")

return voiceCallButton
}()
Expand Down Expand Up @@ -148,7 +148,8 @@
public override func viewDidLoad() {
super.viewDidLoad()

if NCSettingsController.sharedInstance().callsEnabledCapability() {
if NCSettingsController.sharedInstance().callsEnabledCapability() &&
room.type != kNCRoomTypeChangelog && room.type != kNCRoomTypeNoteToSelf {
let fixedSpace = UIBarButtonItem(systemItem: .fixedSpace)
fixedSpace.width = 16
self.navigationItem.rightBarButtonItems = [videoCallButton, fixedSpace, voiceCallButton]
Expand Down Expand Up @@ -926,7 +927,7 @@

if let indexPathUnreadMessageSeparator = self.indexPathForUnreadMessageSeparator() {
tableView.scrollToRow(at: indexPathUnreadMessageSeparator, at: .middle, animated: true)
} else if (shouldScrollOnNewMessages || messages.containsUserMessage()), let lastIndexPath = self.getLastRealMessage()?.indexPath {

Check warning on line 930 in NextcloudTalk/ChatViewController.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

Control Statement Violation: `if`, `for`, `guard`, `switch`, `while`, and `catch` statements shouldn't unnecessarily wrap their conditionals or arguments in parentheses (control_statement)
tableView.scrollToRow(at: lastIndexPath, at: .none, animated: true)
} else if self.firstUnreadMessage == nil, newMessagesContainVisibleMessages, let firstNewMessage = messages.first {
// This check is needed since several calls to receiveMessages API might be needed
Expand Down Expand Up @@ -1479,12 +1480,20 @@
}

// Forward option (only normal messages for now)
if message.file() == nil && message.poll() == nil && !message.isDeletedMessage() {
if message.file() == nil, message.poll() == nil, !message.isDeletedMessage() {
actions.append(UIAction(title: NSLocalizedString("Forward", comment: ""), image: .init(systemName: "arrowshape.turn.up.right")) { _ in
self.didPressForward(for: message)
})
}

// Note to self
if message.file() == nil, message.poll() == nil, !message.isDeletedMessage(), room.type != kNCRoomTypeNoteToSelf,
NCDatabaseManager.sharedInstance().serverHasTalkCapability(kCapabilityNoteToSelf) {
actions.append(UIAction(title: NSLocalizedString("Note to self", comment: ""), image: .init(systemName: "square.and.pencil")) { _ in
self.didPressNoteToSelf(for: message)
})
}

// Remind me later
if !message.sendingFailed, !message.isOfflineMessage, NCDatabaseManager.sharedInstance().serverHasTalkCapability(kCapabilityRemindMeLater) {
let deferredMenuElement = UIDeferredMenuElement.uncached { [weak self] completion in
Expand Down Expand Up @@ -1603,13 +1612,13 @@
}

extension Notification.Name {
static let NCChatViewControllerReplyPrivatelyNotification = Notification.Name(rawValue: "NCChatViewControllerReplyPrivatelyNotification")

Check warning on line 1615 in NextcloudTalk/ChatViewController.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

Identifier Name Violation: Variable name 'NCChatViewControllerReplyPrivatelyNotification' should be between 0 and 40 characters long (identifier_name)
static let NCChatViewControllerForwardNotification = Notification.Name(rawValue: "NCChatViewControllerForwardNotification")
static let NCChatViewControllerTalkToUserNotification = Notification.Name(rawValue: "NCChatViewControllerTalkToUserNotification")

Check warning on line 1617 in NextcloudTalk/ChatViewController.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

Identifier Name Violation: Variable name 'NCChatViewControllerTalkToUserNotification' should be between 0 and 40 characters long (identifier_name)
}

@objc extension NSNotification {
public static let NCChatViewControllerReplyPrivatelyNotification = Notification.Name.NCChatViewControllerReplyPrivatelyNotification

Check warning on line 1621 in NextcloudTalk/ChatViewController.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

Identifier Name Violation: Variable name 'NCChatViewControllerReplyPrivatelyNotification' should be between 0 and 40 characters long (identifier_name)
public static let NCChatViewControllerForwardNotification = Notification.Name.NCChatViewControllerForwardNotification
public static let NCChatViewControllerTalkToUserNotification = Notification.Name.NCChatViewControllerTalkToUserNotification

Check warning on line 1623 in NextcloudTalk/ChatViewController.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

Identifier Name Violation: Variable name 'NCChatViewControllerTalkToUserNotification' should be between 0 and 40 characters long (identifier_name)
}
1 change: 1 addition & 0 deletions NextcloudTalk/NCAPIController.h
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ extern NSInteger const kReceivedChatMessagesLimit;
// Rooms Controller
- (NSURLSessionDataTask *)getRoomsForAccount:(TalkAccount *)account updateStatus:(BOOL)updateStatus modifiedSince:(NSInteger)modifiedSince withCompletionBlock:(GetRoomsCompletionBlock)block;
- (NSURLSessionDataTask *)getRoomForAccount:(TalkAccount *)account withToken:(NSString *)token withCompletionBlock:(GetRoomCompletionBlock)block;
- (NSURLSessionDataTask *)getNoteToSelfRoomForAccount:(TalkAccount *)account withCompletionBlock:(GetRoomCompletionBlock)block;
- (NSURLSessionDataTask *)getListableRoomsForAccount:(TalkAccount *)account withSearchTerm:(NSString *)searchTerm andCompletionBlock:(GetRoomsCompletionBlock)block;
- (NSURLSessionDataTask *)createRoomForAccount:(TalkAccount *)account with:(NSString *)invite ofType:(NCRoomType)type andName:(NSString *)roomName withCompletionBlock:(CreateRoomCompletionBlock)block;
- (NSURLSessionDataTask *)renameRoom:(NSString *)token forAccount:(TalkAccount *)account withName:(NSString *)newName andCompletionBlock:(RenameRoomCompletionBlock)block;
Expand Down
28 changes: 28 additions & 0 deletions NextcloudTalk/NCAPIController.m
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,34 @@ - (NSURLSessionDataTask *)getRoomForAccount:(TalkAccount *)account withToken:(NS
return task;
}

- (NSURLSessionDataTask *)getNoteToSelfRoomForAccount:(TalkAccount *)account withCompletionBlock:(GetRoomCompletionBlock)block
{
NSString *endpoint = [NSString stringWithFormat:@"room/note-to-self"];
NSInteger conversationAPIVersion = [self conversationAPIVersionForAccount:account];
NSString *URLString = [self getRequestURLForEndpoint:endpoint withAPIVersion:conversationAPIVersion forAccount:account];

NCAPISessionManager *apiSessionManager = [_apiSessionManagers objectForKey:account.accountId];
NSURLSessionDataTask *task = [apiSessionManager GET:URLString parameters:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
NSDictionary *roomDict = [[responseObject objectForKey:@"ocs"] objectForKey:@"data"];
NSHTTPURLResponse *response = ((NSHTTPURLResponse *)[task response]);
NSDictionary *headers = [self getResponseHeaders:response];

[self checkResponseHeaders:headers forAccount:account];

if (block) {
block(roomDict, 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;
}

- (NSURLSessionDataTask *)getListableRoomsForAccount:(TalkAccount *)account withSearchTerm:(NSString *)searchTerm andCompletionBlock:(GetRoomsCompletionBlock)block
{
NSString *endpoint = @"listed-room";
Expand Down
1 change: 1 addition & 0 deletions NextcloudTalk/NCDatabaseManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ extern NSString * const kCapabilityTypingIndicators;
extern NSString * const kCapabilityPublishingPermissions;
extern NSString * const kCapabilityRemindMeLater;
extern NSString * const kCapabilityMarkdownMessages;
extern NSString * const kCapabilityNoteToSelf;

extern NSString * const kNotificationsCapabilityExists;

Expand Down
1 change: 1 addition & 0 deletions NextcloudTalk/NCDatabaseManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
NSString * const kCapabilityPublishingPermissions = @"publishing-permissions";
NSString * const kCapabilityRemindMeLater = @"remind-me-later";
NSString * const kCapabilityMarkdownMessages = @"markdown-messages";
NSString * const kCapabilityNoteToSelf = @"note-to-self";

NSString * const kNotificationsCapabilityExists = @"exists";

Expand Down
3 changes: 2 additions & 1 deletion NextcloudTalk/NCRoom.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ typedef enum NCRoomType {
kNCRoomTypeGroup,
kNCRoomTypePublic,
kNCRoomTypeChangelog,
kNCRoomTypeFormerOneToOne
kNCRoomTypeFormerOneToOne,
kNCRoomTypeNoteToSelf
} NCRoomType;

typedef enum NCRoomNotificationLevel {
Expand Down
2 changes: 1 addition & 1 deletion NextcloudTalk/NCRoom.m
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ - (BOOL)isNameEditable
- (BOOL)isLockedOneToOne
{
return (self.type == kNCRoomTypeOneToOne && [[NCDatabaseManager sharedInstance] serverHasTalkCapability:kCapabilityLockedOneToOneRooms])
|| self.type == kNCRoomTypeFormerOneToOne;
|| self.type == kNCRoomTypeFormerOneToOne || self.type == kNCRoomTypeNoteToSelf;
}

- (BOOL)userCanStartCall
Expand Down
22 changes: 14 additions & 8 deletions NextcloudTalk/RoomInfoTableViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ - (NSArray *)getRoomInfoSections
[sections addObject:[NSNumber numberWithInt:kRoomInfoSectionSharedItems]];
}
// Notifications section
if ([[NCDatabaseManager sharedInstance] serverHasTalkCapability:kCapabilityNotificationLevels]) {
if ([self getNotificationsActions].count > 0) {
[sections addObject:[NSNumber numberWithInt:kRoomInfoSectionNotifications]];
}
// Conversation section
Expand Down Expand Up @@ -339,6 +339,11 @@ - (NSInteger)getSectionForRoomInfoSection:(RoomInfoSection)section
- (NSArray *)getNotificationsActions
{
NSMutableArray *actions = [[NSMutableArray alloc] init];

if (_room.type == kNCRoomTypeChangelog || _room.type == kNCRoomTypeNoteToSelf) {
return actions;
}

// Chat notifications levels action
if ([[NCDatabaseManager sharedInstance] serverHasTalkCapability:kCapabilityNotificationLevels]) {
[actions addObject:[NSNumber numberWithInt:kNotificationActionChatNotifications]];
Expand Down Expand Up @@ -426,7 +431,7 @@ - (NSArray *)getConversationActions
}
}

if (_room.type != kNCRoomTypeChangelog) {
if (_room.type != kNCRoomTypeChangelog && _room.type != kNCRoomTypeNoteToSelf) {
[actions addObject:[NSNumber numberWithInt:kConversationActionShareLink]];
}

Expand Down Expand Up @@ -467,15 +472,16 @@ - (NSArray *)getRoomDestructiveActions
{
NSMutableArray *actions = [[NSMutableArray alloc] init];
// Leave room
if (_room.isLeavable) {
if (_room.isLeavable && _room.type != kNCRoomTypeNoteToSelf) {
[actions addObject:[NSNumber numberWithInt:kDestructiveActionLeave]];
}
// Clear history
if (_room.canModerate && [[NCDatabaseManager sharedInstance] serverHasTalkCapability:kCapabilityClearHistory]) {
if ((_room.canModerate || _room.type == kNCRoomTypeNoteToSelf) &&
[[NCDatabaseManager sharedInstance] serverHasTalkCapability:kCapabilityClearHistory]) {
[actions addObject:[NSNumber numberWithInt:kDestructiveActionClearHistory]];
}
// Delete room
if (_room.canModerate) {
if (_room.canModerate || _room.type == kNCRoomTypeNoteToSelf) {
[actions addObject:[NSNumber numberWithInt:kDestructiveActionDelete]];
}
return [NSArray arrayWithArray:actions];
Expand Down Expand Up @@ -1374,7 +1380,7 @@ - (void)removeParticipant:(NCRoomParticipant *)participant

- (NSString *)detailedNameForParticipant:(NCRoomParticipant *)participant
{
if (participant.canModerate && (_room.type == kNCRoomTypeOneToOne || _room.type == kNCRoomTypeFormerOneToOne)) {
if (participant.canModerate && (_room.type == kNCRoomTypeOneToOne || _room.type == kNCRoomTypeFormerOneToOne || _room.type == kNCRoomTypeNoteToSelf)) {
return participant.displayName;
}
return participant.detailedName;
Expand Down Expand Up @@ -1699,7 +1705,7 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N

cell.roomNameTextField.userInteractionEnabled = NO;

if (_room.canModerate) {
if (_room.canModerate || _room.type == kNCRoomTypeNoteToSelf) {
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
cell.userInteractionEnabled = YES;
} else {
Expand Down Expand Up @@ -2261,7 +2267,7 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
switch (section) {
case kRoomInfoSectionName:
{
if (_room.canModerate) {
if (_room.canModerate || _room.type == kNCRoomTypeNoteToSelf) {
[self presentNameInfoViewController];
}
}
Expand Down
7 changes: 4 additions & 3 deletions NextcloudTalk/RoomsTableViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -1124,7 +1124,8 @@ - (void)presentMoreActionsForRoomAtIndexPath:(NSIndexPath *)indexPath
}
}
// Notification levels
if ([[NCDatabaseManager sharedInstance] serverHasTalkCapability:kCapabilityNotificationLevels]) {
if ([[NCDatabaseManager sharedInstance] serverHasTalkCapability:kCapabilityNotificationLevels] &&
room.type != kNCRoomTypeChangelog && room.type != kNCRoomTypeNoteToSelf) {
UIAlertAction *notificationsAction = [UIAlertAction actionWithTitle:[NSString stringWithFormat:NSLocalizedString(@"Notifications: %@", nil), room.notificationLevelString]
style:UIAlertActionStyleDefault
handler:^void (UIAlertAction *action) {
Expand All @@ -1135,7 +1136,7 @@ - (void)presentMoreActionsForRoomAtIndexPath:(NSIndexPath *)indexPath
}

// Share link
if (room.type != kNCRoomTypeChangelog) {
if (room.type != kNCRoomTypeChangelog && room.type != kNCRoomTypeNoteToSelf) {
// Share Link
UIAlertAction *shareLinkAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"Share link", nil)
style:UIAlertActionStyleDefault
Expand Down Expand Up @@ -1271,7 +1272,7 @@ - (UISwipeActionsConfiguration *)tableView:(UITableView *)tableView trailingSwip
// Do not show swipe actions for open conversations or messages
if ((tableView == _resultTableViewController.tableView && room.listable) || !room) {return nil;}

if (room.isLeavable) {
if (room.isLeavable && room.type != kNCRoomTypeNoteToSelf) {
deleteAction = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleDestructive title:nil
handler:^(UIContextualAction * _Nonnull action, __kindof UIView * _Nonnull sourceView, void (^ _Nonnull completionHandler)(BOOL)) {
[self leaveRoomAtIndexPath:indexPath];
Expand Down
9 changes: 9 additions & 0 deletions NextcloudTalk/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@
/* No comment provided by engineer. */
"Add to favorites" = "Add to favorites";

/* No comment provided by engineer. */
"Added note to self" = "Added note to self";

/* No comment provided by engineer. */
"Address" = "Address";

Expand Down Expand Up @@ -220,6 +223,9 @@
/* No comment provided by engineer. */
"An error occurred while adding a reaction to message" = "An error occurred while adding a reaction to message";

/* No comment provided by engineer. */
"An error occurred while adding note" = "An error occurred while adding note";

/* No comment provided by engineer. */
"An error occurred while clearing status message" = "An error occurred while clearing status message";

Expand Down Expand Up @@ -1153,6 +1159,9 @@
/* No comment provided by engineer. */
"Not supported" = "Not supported";

/* No comment provided by engineer. */
"Note to self" = "Note to self";

/* No comment provided by engineer. */
"Notifications" = "Notifications";

Expand Down
Loading