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 committed Sep 20, 2024
1 parent d2bc9f5 commit 568a084
Show file tree
Hide file tree
Showing 8 changed files with 309 additions and 46 deletions.
34 changes: 34 additions & 0 deletions NextcloudTalk/NCAPIControllerExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -343,4 +343,38 @@ import Foundation
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

0 comments on commit 568a084

Please sign in to comment.