Fixed an issue where group invite auto accept wasn't sending a response

pull/894/head
Morgan Pretty 2 years ago
parent 82a739697d
commit c862b0e30a

@ -181,12 +181,12 @@ public extension ClosedGroup {
case userGroup case userGroup
} }
static func approveGroup( @discardableResult static func approveGroup(
_ db: Database, _ db: Database,
group: ClosedGroup, group: ClosedGroup,
calledFromConfigHandling: Bool, calledFromConfigHandling: Bool,
using dependencies: Dependencies using dependencies: Dependencies
) throws { ) throws -> Job? {
guard let userED25519KeyPair: KeyPair = Identity.fetchUserEd25519KeyPair(db, using: dependencies) else { guard let userED25519KeyPair: KeyPair = Identity.fetchUserEd25519KeyPair(db, using: dependencies) else {
throw MessageReceiverError.noUserED25519KeyPair throw MessageReceiverError.noUserED25519KeyPair
} }
@ -223,7 +223,20 @@ public extension ClosedGroup {
) )
} }
/// Start polling /// Schedule a `pollResponseJob` to be triggered once the first poll completes the start polling
let pollResponseJob: Job? = dependencies[singleton: .jobRunner].add(
db,
job: Job(variant: .manualResultJob),
canStartJob: true,
using: dependencies
)
dependencies[singleton: .groupsPoller].afterNextPoll(for: group.id) { _ in
dependencies[singleton: .jobRunner].manuallyTriggerResult(
pollResponseJob,
result: .succeeded,
using: dependencies
)
}
dependencies[singleton: .groupsPoller].startIfNeeded(for: group.id, using: dependencies) dependencies[singleton: .groupsPoller].startIfNeeded(for: group.id, using: dependencies)
/// Subscribe for group push notifications /// Subscribe for group push notifications
@ -239,6 +252,8 @@ public extension ClosedGroup {
.subscribe(on: DispatchQueue.global(qos: .userInitiated), using: dependencies) .subscribe(on: DispatchQueue.global(qos: .userInitiated), using: dependencies)
.sinkUntilComplete() .sinkUntilComplete()
} }
return pollResponseJob
} }
static func removeData( static func removeData(

@ -134,8 +134,7 @@ extension MessageReceiver {
groupSessionId: message.groupSessionId, groupSessionId: message.groupSessionId,
using: dependencies using: dependencies
) )
let pollResponseJob: Job? = try MessageReceiver.handleNewGroup(
try MessageReceiver.handleNewGroup(
db, db,
groupSessionId: message.groupSessionId.hexString, groupSessionId: message.groupSessionId.hexString,
groupIdentityPrivateKey: nil, groupIdentityPrivateKey: nil,
@ -190,8 +189,28 @@ extension MessageReceiver {
).inserted(db) ).inserted(db)
/// Notify the user about the group message request if needed /// Notify the user about the group message request if needed
guard !inviteSenderIsApproved else { return } switch inviteSenderIsApproved {
/// If the sender was approved then this group will be auto-accepted and we should send the
/// `GroupUpdateInviteResponseMessage` to the group
case true:
/// If we aren't creating a new thread (ie. sending a message request) then send a
/// `GroupUpdateInviteResponseMessage` to the group (this allows other members
/// to know that the user has joined the group)
try MessageSender.send(
db,
message: GroupUpdateInviteResponseMessage(
isApproved: true,
sentTimestamp: UInt64(SnodeAPI.currentOffsetTimestampMs(using: dependencies))
),
interactionId: nil,
threadId: message.groupSessionId.hexString,
threadVariant: .group,
after: pollResponseJob,
using: dependencies
)
/// If the sender wasn't approved this is a message request so we should notify the user about the invite
case false:
let isMainAppActive: Bool = dependencies[defaults: .appGroup, key: .isMainAppActive] let isMainAppActive: Bool = dependencies[defaults: .appGroup, key: .isMainAppActive]
dependencies[singleton: .notificationsManager].notifyUser( dependencies[singleton: .notificationsManager].notifyUser(
db, db,
@ -208,8 +227,9 @@ extension MessageReceiver {
using: dependencies using: dependencies
) )
} }
}
internal static func handleNewGroup( @discardableResult internal static func handleNewGroup(
_ db: Database, _ db: Database,
groupSessionId: String, groupSessionId: String,
groupIdentityPrivateKey: Data?, groupIdentityPrivateKey: Data?,
@ -219,7 +239,7 @@ extension MessageReceiver {
invited: Bool, invited: Bool,
calledFromConfigHandling: Bool, calledFromConfigHandling: Bool,
using dependencies: Dependencies using dependencies: Dependencies
) throws { ) throws -> Job? {
// Create the group // Create the group
try SessionThread.fetchOrCreate( try SessionThread.fetchOrCreate(
db, db,
@ -254,9 +274,9 @@ extension MessageReceiver {
} }
// If the group is not in the invite state then handle the approval process // If the group is not in the invite state then handle the approval process
guard !invited else { return } guard !invited else { return nil }
try ClosedGroup.approveGroup( return try ClosedGroup.approveGroup(
db, db,
group: closedGroup, group: closedGroup,
calledFromConfigHandling: calledFromConfigHandling, calledFromConfigHandling: calledFromConfigHandling,

Loading…
Cancel
Save