Skip to content

Commit

Permalink
Merge pull request #1378 from nextcloud/note-to-self
Browse files Browse the repository at this point in the history
πŸ“ Note to self
  • Loading branch information
SystemKeeper authored Oct 18, 2023
2 parents 1ae45d8 + 5317771 commit 4862f3f
Show file tree
Hide file tree
Showing 11 changed files with 103 additions and 17 deletions.
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 @@ import QuickLook
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
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 @@ import UIKit
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 @@ import UIKit
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 @@ -1479,12 +1480,20 @@ import UIKit
}

// 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
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

0 comments on commit 4862f3f

Please sign in to comment.