Skip to content

DBR - 5 - Config message handling #451

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

Open
wants to merge 16 commits into
base: feature/database-relocation
Choose a base branch
from
Open
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
18 changes: 17 additions & 1 deletion .drone.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ local sim_keepalive = {
depends_on: ['Boot Test Simulator'],
};
local sim_delete_cmd = 'if [ -f build/artifacts/sim_uuid ]; then rm -f /Users/$USER/sim-keepalive/$(<./build/artifacts/sim_uuid); fi';
local clear_spm_cache_on_commit_trigger = {
name: 'Reset SPM Cache if Needed',
commands: [
'./Scripts/reset_spm_cache.sh',
],
};


[
// Unit tests (PRs only)
Expand All @@ -56,15 +63,20 @@ local sim_delete_cmd = 'if [ -f build/artifacts/sim_uuid ]; then rm -f /Users/$U
trigger: { event: { exclude: ['push'] } },
steps: [
version_info,
clear_spm_cache_on_commit_trigger,

boot_simulator(),
sim_keepalive,
{
name: 'Build and Run Tests',
commands: [
'NSUnbufferedIO=YES set -o pipefail && xcodebuild test -project Session.xcodeproj -scheme Session -derivedDataPath ./build/derivedData -resultBundlePath ./build/artifacts/testResults.xcresult -parallelizeTargets -destination "platform=iOS Simulator,id=$(<./build/artifacts/sim_uuid)" -parallel-testing-enabled NO -test-timeouts-enabled YES -maximum-test-execution-time-allowance 10 -collect-test-diagnostics never 2>&1 | xcbeautify --is-ci',
'echo "Explicitly running unit tests on `App_Store_Release` configuration to ensure optimisation behaviour is consistent"',
'echo "If tests fail inconsistently from local builds this is likely the difference"',
'echo ""',
'NSUnbufferedIO=YES set -o pipefail && xcodebuild test -project Session.xcodeproj -scheme Session -derivedDataPath ./build/derivedData -resultBundlePath ./build/artifacts/testResults.xcresult -parallelizeTargets -configuration "App_Store_Release" -destination "platform=iOS Simulator,id=$(<./build/artifacts/sim_uuid)" -parallel-testing-enabled NO -test-timeouts-enabled YES -maximum-test-execution-time-allowance 10 -collect-test-diagnostics never ENABLE_TESTABILITY=YES 2>&1 | xcbeautify --is-ci',
],
depends_on: [
'Reset SPM Cache if Needed',
'Boot Test Simulator'
],
},
Expand Down Expand Up @@ -110,12 +122,16 @@ local sim_delete_cmd = 'if [ -f build/artifacts/sim_uuid ]; then rm -f /Users/$U
trigger: { event: { exclude: ['pull_request'] } },
steps: [
version_info,
clear_spm_cache_on_commit_trigger,
{
name: 'Build',
commands: [
'mkdir build',
'NSUnbufferedIO=YES set -o pipefail && xcodebuild archive -project Session.xcodeproj -scheme Session -derivedDataPath ./build/derivedData -parallelizeTargets -configuration "App_Store_Release" -sdk iphonesimulator -archivePath ./build/Session_sim.xcarchive -destination "generic/platform=iOS Simulator" | xcbeautify --is-ci',
],
depends_on: [
'Reset SPM Cache if Needed'
]
},
{
name: 'Upload artifacts',
Expand Down
18 changes: 18 additions & 0 deletions Scripts/reset_spm_cache.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env bash

set -e

green="\e[32;1m"

if echo "${DRONE_COMMIT_MESSAGE}" | grep -q -F "[Reset SPM]"; then
echo "Trigger phrase found in commit message. Clearing SPM caches..."

echo "--> Clearing global SwiftPM caches..."
rm -rf /Users/drone/.swiftpm || echo "Warning: Failed to remove Users/drone/.swiftpm"
rm -rf /Users/drone/Library/org.swift.swiftpm || echo "Warning: Failed to remove Users/drone/Library/org.swift.swiftpm"
rm -rf /Users/drone/Library/Caches/org.swift.swiftpm || echo "Warning: Failed to remove Users/drone/Library/Caches/org.swift.swiftpm"

echo -e "\n${green}SPM caches cleared."
else
echo -e "\n${green}Trigger phrase not found. Skipping SPM cache clearing."
fi
134 changes: 98 additions & 36 deletions Session.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/session-foundation/libsession-util-spm",
"state" : {
"revision" : "7c6665ffe8a458f57aa3cf9115873c7be9efe7cb",
"version" : "1.3.1"
"revision" : "250c672e7d51b950004900b8422040bbedf5580a",
"version" : "1.4.0"
}
},
{
Expand Down
155 changes: 29 additions & 126 deletions Session/Closed Groups/EditGroupViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -450,50 +450,23 @@ class EditGroupViewModel: SessionTableViewModel, NavigatableStateHolder, Editabl
footerAccessibility: Accessibility(
identifier: "Confirm invite button"
),
onSubmit: { [weak self, threadId, dependencies] in
switch try? SessionId.Prefix(from: threadId) {
case .group:
return .callback { viewModel, selectedMemberInfo in
let updatedMemberIds: Set<String> = currentMemberIds
.inserting(contentsOf: selectedMemberInfo.map { $0.profileId }.asSet())

guard updatedMemberIds.count <= LibSession.sizeMaxGroupMemberCount else {
throw UserListError.error("groupAddMemberMaximum".localized())
}

// Adding members is an async process and after adding members we
// want to return to the edit group screen so the admin can see the
// invitation statuses
self?.addMembers(
currentGroupName: currentGroupName,
memberInfo: selectedMemberInfo.map { ($0.profileId, $0.profile) }
)
self?.dismissScreen()
}

case .standard: // Assume it's a legacy group
return .publisher { [dependencies, threadId] _, selectedMemberInfo in
let updatedMemberIds: Set<String> = currentMemberIds
.inserting(contentsOf: selectedMemberInfo.map { $0.profileId }.asSet())

guard updatedMemberIds.count <= LibSession.sizeMaxGroupMemberCount else {
return Fail(error: .error("groupAddMemberMaximum".localized()))
.eraseToAnyPublisher()
}

return MessageSender.update(
legacyGroupSessionId: threadId,
with: updatedMemberIds,
name: currentGroupName,
using: dependencies
)
.mapError { _ in
UserListError.error("deleteAfterLegacyGroupsGroupUpdateErrorTitle".localized())
}
.eraseToAnyPublisher()
}

default: return .none
onSubmit: { [weak self] in
.callback { viewModel, selectedMemberInfo in
let updatedMemberIds: Set<String> = currentMemberIds
.inserting(contentsOf: selectedMemberInfo.map { $0.profileId }.asSet())

guard updatedMemberIds.count <= LibSession.sizeMaxGroupMemberCount else {
throw UserListError.error("groupAddMemberMaximum".localized())
}

// Adding members is an async process and after adding members we
// want to return to the edit group screen so the admin can see the
// invitation statuses
self?.addMembers(
currentGroupName: currentGroupName,
memberInfo: selectedMemberInfo.map { ($0.profileId, $0.profile) }
)
self?.dismissScreen()
}
}(),
using: dependencies
Expand Down Expand Up @@ -782,88 +755,18 @@ class EditGroupViewModel: SessionTableViewModel, NavigatableStateHolder, Editabl
cancelStyle: .alert_text,
dismissOnConfirm: false,
onConfirm: { [weak self, threadId, dependencies] modal in
switch try? SessionId.Prefix(from: threadId) {
case .group:
MessageSender
.removeGroupMembers(
groupSessionId: threadId,
memberIds: memberIds,
removeTheirMessages: dependencies[feature: .updatedGroupsRemoveMessagesOnKick],
sendMemberChangedMessage: true,
using: dependencies
)
.subscribe(on: DispatchQueue.global(qos: .userInitiated), using: dependencies)
.sinkUntilComplete()
self?.selectedIdsSubject.send((currentGroupName, []))
modal.dismiss(animated: true)

case .standard: // Assume it's a legacy group
let updatedMemberIds: Set<String> = (self?.tableData
.first(where: { $0.model == .members })?
.elements
.compactMap { item -> String? in
switch item.id {
case .member(let profileId): return profileId
default: return nil
}
})
.defaulting(to: [])
.asSet()
.removing(contentsOf: memberIds)

let viewController = ModalActivityIndicatorViewController(canCancel: false) { [weak self, dependencies, threadId] modalActivityIndicator in
MessageSender
.update(
legacyGroupSessionId: threadId,
with: updatedMemberIds,
name: currentGroupName,
using: dependencies
)
.eraseToAnyPublisher()
.subscribe(on: DispatchQueue.global(qos: .userInitiated), using: dependencies)
.receive(on: DispatchQueue.main, using: dependencies)
.sinkUntilComplete(
receiveCompletion: { [weak self] result in
modalActivityIndicator.dismiss(completion: {
switch result {
case .finished:
self?.selectedIdsSubject.send((currentGroupName, []))
modalActivityIndicator.dismiss {
modal.dismiss(animated: true)
}

case .failure:
self?.transitionToScreen(
ConfirmationModal(
info: ConfirmationModal.Info(
title: "theError".localized(),
body: .text("deleteAfterLegacyGroupsGroupUpdateErrorTitle".localized()),
cancelTitle: "okay".localized(),
cancelStyle: .alert_text
)
),
transitionType: .present
)
}
})
}
)
}
self?.transitionToScreen(viewController, transitionType: .present)

default:
self?.transitionToScreen(
ConfirmationModal(
info: ConfirmationModal.Info(
title: "theError".localized(),
body: .text("deleteAfterLegacyGroupsGroupUpdateErrorTitle".localized()),
cancelTitle: "okay".localized(),
cancelStyle: .alert_text
)
),
transitionType: .present
)
}
MessageSender
.removeGroupMembers(
groupSessionId: threadId,
memberIds: memberIds,
removeTheirMessages: dependencies[feature: .updatedGroupsRemoveMessagesOnKick],
sendMemberChangedMessage: true,
using: dependencies
)
.subscribe(on: DispatchQueue.global(qos: .userInitiated), using: dependencies)
.sinkUntilComplete()
self?.selectedIdsSubject.send((currentGroupName, []))
modal.dismiss(animated: true)
}
)
)
Expand Down
34 changes: 9 additions & 25 deletions Session/Closed Groups/NewClosedGroupVC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ final class NewClosedGroupVC: BaseVC, UITableViewDataSource, UITableViewDelegate
accessibility: Accessibility(label: "Version warning banner")
)
)
result.isHidden = !dependencies[feature: .updatedGroups]

return result
}()
Expand Down Expand Up @@ -395,31 +394,16 @@ final class NewClosedGroupVC: BaseVC, UITableViewDataSource, UITableViewDelegate
}
let selectedProfiles: [(String, Profile?)] = self.selectedProfiles
.reduce(into: []) { result, next in result.append((next.key, next.value)) }
let message: String? = (dependencies[feature: .updatedGroups] || selectedProfiles.count <= 20 ? nil : "deleteAfterLegacyGroupsGroupCreation".localized()
)

ModalActivityIndicatorViewController.present(fromViewController: navigationController!, message: message) { [weak self, dependencies] activityIndicatorViewController in
let createPublisher: AnyPublisher<SessionThread, Error> = {
switch dependencies[feature: .updatedGroups] {
case true:
return MessageSender.createGroup(
name: name,
description: nil,
displayPictureData: nil,
members: selectedProfiles,
using: dependencies
)

case false:
return MessageSender.createLegacyClosedGroup(
name: name,
members: selectedProfiles.map { $0.0 }.asSet(),
using: dependencies
)
}
}()

createPublisher
ModalActivityIndicatorViewController.present(fromViewController: navigationController!) { [weak self, dependencies] activityIndicatorViewController in
MessageSender
.createGroup(
name: name,
description: nil,
displayPictureData: nil,
members: selectedProfiles,
using: dependencies
)
.subscribe(on: DispatchQueue.global(qos: .userInitiated))
.receive(on: DispatchQueue.main)
.sinkUntilComplete(
Expand Down
18 changes: 5 additions & 13 deletions Session/Conversations/Context Menu/ContextMenuVC+Action.swift
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,7 @@ extension ContextMenuVC {

static func viewModelCanReply(_ cellViewModel: MessageViewModel, using dependencies: Dependencies) -> Bool {
return (
(
cellViewModel.threadVariant != .legacyGroup ||
!dependencies[feature: .legacyGroupsDeprecated]
) && (
cellViewModel.threadVariant != .legacyGroup && (
cellViewModel.variant == .standardIncoming || (
cellViewModel.variant == .standardOutgoing &&
cellViewModel.state != .failed &&
Expand Down Expand Up @@ -202,10 +199,7 @@ extension ContextMenuVC {
}

let canRetry: Bool = (
(
cellViewModel.threadVariant != .legacyGroup ||
!dependencies[feature: .legacyGroupsDeprecated]
) &&
cellViewModel.threadVariant != .legacyGroup &&
cellViewModel.variant == .standardOutgoing && (
cellViewModel.state == .failed || (
cellViewModel.threadVariant == .contact &&
Expand Down Expand Up @@ -252,14 +246,12 @@ extension ContextMenuVC {
dependencies[singleton: .openGroupManager].isUserModeratorOrAdmin(
publicKey: threadViewModel.currentUserSessionId,
for: threadViewModel.openGroupRoomToken,
on: threadViewModel.openGroupServer
on: threadViewModel.openGroupServer,
currentUserSessionIds: (threadViewModel.currentUserSessionIds ?? [])
)
)
let shouldShowEmojiActions: Bool = {
guard
cellViewModel.threadVariant != .legacyGroup ||
!dependencies[feature: .legacyGroupsDeprecated]
else { return false }
guard cellViewModel.threadVariant != .legacyGroup else { return false }

if cellViewModel.threadVariant == .community {
return (
Expand Down
Loading