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

Add support for archived conversations #1810

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
3 changes: 3 additions & 0 deletions .pyspelling.wordlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,6 @@ CallKit
Unban
unban
Zammad
Unarchive
unarchive
unarchived
34 changes: 34 additions & 0 deletions NextcloudTalk/NCAPIControllerExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
}

apiSessionManager.getOcs(urlString, account: account, parameters: parameters) { ocs, error in
// TODO: Move away from generic dictionary return type

Check warning on line 32 in NextcloudTalk/NCAPIControllerExtensions.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

Todo Violation: TODOs should be resolved (Move away from generic diction...) (todo)
// let rooms = ocs?.dataArrayDict.compactMap { NCRoom(dictionary: $0, andAccountId: account.accountId) }
completionBlock(ocs?.dataArrayDict, error)
}
Expand Down Expand Up @@ -282,7 +282,7 @@

// MARK: - Ban

public func banActor(for accountId: String, in roomToken: String, with actorType: String, with actorId: String, with internalNote: String?, completionBlock: @escaping (_ success: Bool) -> Void) {

Check warning on line 285 in NextcloudTalk/NCAPIControllerExtensions.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

Function Parameter Count Violation: Function should have 5 parameters or less: it currently has 6 (function_parameter_count)
guard let account = NCDatabaseManager.sharedInstance().talkAccount(forAccountId: accountId),
let apiSessionManager = self.apiSessionManagers.object(forKey: account.accountId) as? NCAPISessionManager
else {
Expand Down Expand Up @@ -343,4 +343,38 @@
completionBlock(false)
}
}

// MARK: - Archived conversations

public func archiveRoom(_ token: String, forAccount account: TalkAccount, completionBlock: @escaping (_ success: Bool) -> Void) {
guard let encodedToken = token.addingPercentEncoding(withAllowedCharacters: .urlHostAllowed),
let apiSessionManager = self.apiSessionManagers.object(forKey: account.accountId) as? NCAPISessionManager
else {
completionBlock(false)
return
}

let apiVersion = self.conversationAPIVersion(for: account)
let urlString = self.getRequestURL(forEndpoint: "room/\(encodedToken)/archive", withAPIVersion: apiVersion, for: account)

apiSessionManager.postOcs(urlString, account: account) { _, error in
completionBlock(error == nil)
}
}

public func unarchiveRoom(_ token: String, forAccount account: TalkAccount, completionBlock: @escaping (_ success: Bool) -> Void) {
guard let encodedToken = token.addingPercentEncoding(withAllowedCharacters: .urlHostAllowed),
let apiSessionManager = self.apiSessionManagers.object(forKey: account.accountId) as? NCAPISessionManager
else {
completionBlock(false)
return
}

let apiVersion = self.conversationAPIVersion(for: account)
let urlString = self.getRequestURL(forEndpoint: "room/\(encodedToken)/archive", withAPIVersion: apiVersion, for: account)

apiSessionManager.deleteOcs(urlString, account: account) { _, error in
completionBlock(error == nil)
}
}
}
1 change: 1 addition & 0 deletions NextcloudTalk/NCDatabaseManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ extern NSString * const kCapabilityChatReadLast;
extern NSString * const kCapabilityBanV1;
extern NSString * const kCapabilityMentionPermissions;
extern NSString * const kCapabilityEditMessagesNoteToSelf;
extern NSString * const kCapabilityArchivedConversations;

extern NSString * const kNotificationsCapabilityExists;

Expand Down
3 changes: 2 additions & 1 deletion NextcloudTalk/NCDatabaseManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

NSString *const kTalkDatabaseFolder = @"Library/Application Support/Talk";
NSString *const kTalkDatabaseFileName = @"talk.realm";
uint64_t const kTalkDatabaseSchemaVersion = 68;
uint64_t const kTalkDatabaseSchemaVersion = 69;

NSString * const kCapabilitySystemMessages = @"system-messages";
NSString * const kCapabilityNotificationLevels = @"notification-levels";
Expand Down Expand Up @@ -75,6 +75,7 @@
NSString * const kCapabilityBanV1 = @"ban-v1";
NSString * const kCapabilityMentionPermissions = @"mention-permissions";
NSString * const kCapabilityEditMessagesNoteToSelf = @"edit-messages-note-to-self";
NSString * const kCapabilityArchivedConversations = @"archived-conversations";

NSString * const kNotificationsCapabilityExists = @"exists";

Expand Down
1 change: 1 addition & 0 deletions NextcloudTalk/NCRoom.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ extern NSString * const NCRoomObjectTypeRoom;
@property (nonatomic, copy) NSString *remoteToken;
@property (nonatomic, copy) NSString *lastReceivedProxyHash;
@property (nonatomic, assign) NSInteger mentionPermissions;
@property (nonatomic, assign) BOOL isArchived;

+ (instancetype)roomWithDictionary:(NSDictionary *)roomDict;
+ (instancetype)roomWithDictionary:(NSDictionary *)roomDict andAccountId:(NSString *)accountId;
Expand Down
4 changes: 3 additions & 1 deletion NextcloudTalk/NCRoom.m
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ + (instancetype)roomWithDictionary:(NSDictionary *)roomDict
room.remoteServer = [roomDict objectForKey:@"remoteServer"];
room.remoteToken = [roomDict objectForKey:@"remoteToken"];
room.mentionPermissions = [[roomDict objectForKey:@"mentionPermissions"] integerValue];
room.isArchived = [[roomDict objectForKey:@"isArchived"] boolValue];

// Local-only field -> update only if there's actually a value
if ([roomDict objectForKey:@"pendingMessage"] != nil) {
Expand All @@ -80,7 +81,7 @@ + (instancetype)roomWithDictionary:(NSDictionary *)roomDict
} else {
room.displayName = [displayName stringValue];
}

id participants = [roomDict objectForKey:@"participants"];
if ([participants isKindOfClass:[NSDictionary class]]) {
room.participants = (RLMArray<RLMString> *)[participants allKeys];
Expand Down Expand Up @@ -191,6 +192,7 @@ + (void)updateRoom:(NCRoom *)managedRoom withRoom:(NCRoom *)room
managedRoom.remoteToken = room.remoteToken;
managedRoom.remoteServer = room.remoteServer;
managedRoom.mentionPermissions = room.mentionPermissions;
managedRoom.isArchived = room.isArchived;
}

+ (NSString *)primaryKey {
Expand Down
Loading
Loading