Skip to content

Commit

Permalink
Add support for archived conversations
Browse files Browse the repository at this point in the history
Signed-off-by: Marcel Müller <[email protected]>
  • Loading branch information
SystemKeeper authored and Ivansss committed Nov 26, 2024
1 parent 9e0d11c commit ce0da7c
Show file tree
Hide file tree
Showing 9 changed files with 315 additions and 46 deletions.
3 changes: 3 additions & 0 deletions .pyspelling.wordlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,6 @@ Unban
unban
Zammad
Strikethrough
Unarchive
unarchive
unarchived
34 changes: 34 additions & 0 deletions NextcloudTalk/NCAPIControllerExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -525,4 +525,38 @@ import Foundation
completionBlock(UserAbsence(dictionary: dataDict))
}
}

// 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 @@ -75,6 +75,7 @@ extern NSString * const kCapabilityBanV1;
extern NSString * const kCapabilityMentionPermissions;
extern NSString * const kCapabilityEditMessagesNoteToSelf;
extern NSString * const kCapabilityChatSummary;
extern NSString * const kCapabilityArchivedConversations;

extern NSString * const kNotificationsCapabilityExists;

Expand Down
6 changes: 5 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 = 70;
uint64_t const kTalkDatabaseSchemaVersion = 71;

NSString * const kCapabilitySystemMessages = @"system-messages";
NSString * const kCapabilityNotificationLevels = @"notification-levels";
Expand Down Expand Up @@ -75,7 +75,11 @@
NSString * const kCapabilityBanV1 = @"ban-v1";
NSString * const kCapabilityMentionPermissions = @"mention-permissions";
NSString * const kCapabilityEditMessagesNoteToSelf = @"edit-messages-note-to-self";
<<<<<<< HEAD
NSString * const kCapabilityChatSummary = @"chat-summary-api";
=======
NSString * const kCapabilityArchivedConversations = @"archived-conversations";
>>>>>>> a878c847 (Add support for 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 _Nullable)roomWithDictionary:(NSDictionary * _Nullable)roomDict andAccountId:(NSString * _Nullable)accountId;
+ (void)updateRoom:(NCRoom * _Nonnull)managedRoom withRoom:(NCRoom * _Nonnull)room;
Expand Down
4 changes: 3 additions & 1 deletion NextcloudTalk/NCRoom.m
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ + (instancetype)roomWithDictionary:(NSDictionary *)roomDict andAccountId:(NSStri
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 @@ -83,7 +84,7 @@ + (instancetype)roomWithDictionary:(NSDictionary *)roomDict andAccountId:(NSStri
} 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 @@ -183,6 +184,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

0 comments on commit ce0da7c

Please sign in to comment.