Signed-off-by: Marcel Müller <marcel-mueller@gmx.de>
This commit is contained in:
Marcel Müller 2024-10-27 13:06:10 +01:00 коммит произвёл Ivan Sein
Родитель 03ab5de8f2
Коммит f0c84ffd60
7 изменённых файлов: 48 добавлений и 46 удалений

Просмотреть файл

@ -155,7 +155,6 @@ extern NSInteger const kReceivedChatMessagesLimit;
- (NSURLSessionDataTask *)getContactsForAccount:(TalkAccount *)account forRoom:(NSString *)room groupRoom:(BOOL)groupRoom withSearchParam:(NSString *)search andCompletionBlock:(GetContactsCompletionBlock)block;
// Rooms Controller
- (NSURLSessionDataTask *)deleteRoom:(NSString *)token forAccount:(TalkAccount *)account withCompletionBlock:(DeleteRoomCompletionBlock)block;
- (NSURLSessionDataTask *)setPassword:(NSString *)password toRoom:(NSString *)token forAccount:(TalkAccount *)account withCompletionBlock:(SetPasswordCompletionBlock)block;
- (NSURLSessionDataTask *)joinRoom:(NSString *)token forAccount:(TalkAccount *)account withCompletionBlock:(JoinRoomCompletionBlock)block;
- (NSURLSessionDataTask *)exitRoom:(NSString *)token forAccount:(TalkAccount *)account withCompletionBlock:(ExitRoomCompletionBlock)block;

Просмотреть файл

@ -312,30 +312,6 @@ NSInteger const kReceivedChatMessagesLimit = 100;
#pragma mark - Rooms Controller
- (NSURLSessionDataTask *)deleteRoom:(NSString *)token forAccount:(TalkAccount *)account withCompletionBlock:(DeleteRoomCompletionBlock)block
{
NSString *encodedToken = [token stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLHostAllowedCharacterSet]];
NSString *endpoint = [NSString stringWithFormat:@"room/%@", encodedToken];
NSInteger conversationAPIVersion = [self conversationAPIVersionForAccount:account];
NSString *URLString = [self getRequestURLForEndpoint:endpoint withAPIVersion:conversationAPIVersion forAccount:account];
NCAPISessionManager *apiSessionManager = [_apiSessionManagers objectForKey:account.accountId];
NSURLSessionDataTask *task = [apiSessionManager DELETE:URLString parameters:nil success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
if (block) {
block(nil);
}
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
NSInteger statusCode = [self getResponseStatusCode:task.response];
[self checkResponseStatusCode:statusCode forAccount:account];
if (block) {
block(error);
}
}];
return task;
}
- (NSURLSessionDataTask *)setPassword:(NSString *)password toRoom:(NSString *)token forAccount:(TalkAccount *)account withCompletionBlock:(SetPasswordCompletionBlock)block
{
NSString *encodedToken = [token stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLHostAllowedCharacterSet]];

Просмотреть файл

@ -158,6 +158,18 @@ import Foundation
}
}
public func deleteRoom(_ token: String, forAccount account: TalkAccount, completionBlock: @escaping (_ error: Error?) -> Void) {
guard let apiSessionManager = self.apiSessionManagers.object(forKey: account.accountId) as? NCAPISessionManager,
let encodedToken = token.addingPercentEncoding(withAllowedCharacters: .urlHostAllowed)
else { return }
let urlString = self.getRequestURL(forConversationEndpoint: "room/\(encodedToken)", for: account)
apiSessionManager.deleteOcs(urlString, account: account) { _, error in
completionBlock(error)
}
}
// MARK: - Federation
public func acceptFederationInvitation(for accountId: String, with invitationId: Int, completionBlock: @escaping (_ success: Bool) -> Void) {

Просмотреть файл

@ -1117,7 +1117,7 @@ typedef enum FileAction {
- (void)deleteRoom
{
[[NCAPIController sharedInstance] deleteRoom:_room.token forAccount:[[NCDatabaseManager sharedInstance] activeAccount] withCompletionBlock:^(NSError *error) {
[[NCAPIController sharedInstance] deleteRoom:_room.token forAccount:[[NCDatabaseManager sharedInstance] activeAccount] completionBlock:^(NSError *error) {
if (!error) {
if (self->_chatViewController) {
[self->_chatViewController leaveChat];

Просмотреть файл

@ -1155,7 +1155,7 @@ typedef enum RoomsSections {
[self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
}
[[NCAPIController sharedInstance] deleteRoom:room.token forAccount:[[NCDatabaseManager sharedInstance] activeAccount] withCompletionBlock:^(NSError *error) {
[[NCAPIController sharedInstance] deleteRoom:room.token forAccount:[[NCDatabaseManager sharedInstance] activeAccount] completionBlock:^(NSError *error) {
if (error) {
NSLog(@"Error deleting room: %@", error.description);
}

Просмотреть файл

@ -22,8 +22,6 @@ extension XCTestCase {
}
func checkRoomExists(roomName: String, withAccount account: TalkAccount, completion: ((NCRoom?) -> Void)? = nil) {
let exp = expectation(description: "\(#function)\(#line)")
NCAPIController.sharedInstance().getRooms(forAccount: account, updateStatus: false, modifiedSince: 0) { roomsDict, error in
XCTAssertNil(error)
@ -32,10 +30,18 @@ extension XCTestCase {
XCTAssertNotNil(room)
completion?(room)
exp.fulfill()
}
}
waitForExpectations(timeout: TestConstants.timeoutLong, handler: nil)
func checkRoomNotExists(roomName: String, withAccount account: TalkAccount, completion: (() -> Void)? = nil) {
NCAPIController.sharedInstance().getRooms(forAccount: account, updateStatus: false, modifiedSince: 0) { roomsDict, error in
XCTAssertNil(error)
let rooms = self.getRoomDict(from: roomsDict!)
let room = rooms.first(where: { $0.displayName == roomName })
XCTAssertNil(room)
completion?()
}
}
}

Просмотреть файл

@ -25,7 +25,7 @@ final class IntegrationRoomTest: TestBase {
waitForExpectations(timeout: TestConstants.timeoutLong, handler: nil)
}
func testRoomCreation() throws {
func testRoomCreationAndDeletion() throws {
let activeAccount = NCDatabaseManager.sharedInstance().activeAccount()
let roomName = "Integration Test Room " + UUID().uuidString
@ -34,12 +34,21 @@ final class IntegrationRoomTest: TestBase {
// Create a room
NCAPIController.sharedInstance().createRoom(forAccount: activeAccount, withInvite: nil, ofType: .public, andName: roomName) { _, error in
XCTAssertNil(error)
exp.fulfill()
self.checkRoomExists(roomName: roomName, withAccount: activeAccount) { room in
// Delete the room again
NCAPIController.sharedInstance().deleteRoom(room!.token, forAccount: activeAccount) { error in
XCTAssertNil(error)
self.checkRoomNotExists(roomName: roomName, withAccount: activeAccount) {
exp.fulfill()
}
}
}
}
waitForExpectations(timeout: TestConstants.timeoutLong, handler: nil)
self.checkRoomExists(roomName: roomName, withAccount: activeAccount)
}
func testRoomDescription() throws {
@ -67,14 +76,14 @@ final class IntegrationRoomTest: TestBase {
// Set a description
NCAPIController.sharedInstance().setRoomDescription(roomDescription, forRoom: roomToken, forAccount: activeAccount) { error in
XCTAssertNil(error)
expDescription.fulfill()
self.checkRoomExists(roomName: roomName, withAccount: activeAccount) { room in
XCTAssertEqual(room?.roomDescription, roomDescription)
expDescription.fulfill()
}
}
waitForExpectations(timeout: TestConstants.timeoutLong, handler: nil)
self.checkRoomExists(roomName: roomName, withAccount: activeAccount) { room in
XCTAssertEqual(room?.roomDescription, roomDescription)
}
}
func testRoomRename() throws {
@ -102,14 +111,14 @@ final class IntegrationRoomTest: TestBase {
// Set a new name
NCAPIController.sharedInstance().renameRoom(roomToken, forAccount: activeAccount, withName: roomNameNew) { error in
XCTAssertNil(error)
expNewName.fulfill()
self.checkRoomExists(roomName: roomNameNew, withAccount: activeAccount) { room in
XCTAssertEqual(room?.displayName, roomNameNew)
expNewName.fulfill()
}
}
waitForExpectations(timeout: TestConstants.timeoutLong, handler: nil)
self.checkRoomExists(roomName: roomNameNew, withAccount: activeAccount) { room in
XCTAssertEqual(room?.displayName, roomNameNew)
}
}
func testRoomPublicPrivate() throws {