Skip to content

Commit

Permalink
Show notification on remote unsubscribe / contact denial
Browse files Browse the repository at this point in the history
  • Loading branch information
tmolitor-stud-tu committed Jan 27, 2025
1 parent 206d4d9 commit 50cb223
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
40 changes: 40 additions & 0 deletions Monal/Classes/MLNotificationManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,46 @@ -(void) handleContactRefresh:(NSNotification*) notification
MLContact* contact = notification.userInfo[@"contact"];
NSString* idval = [NSString stringWithFormat:@"subscription(%@, %@)", contact.accountID, contact.contactJid];

//contact request denial or unsubscribe
if(notification.userInfo[@"unsubscribed"] != nil && [notification.userInfo[@"unsubscribed"] boolValue] == YES)
{
idval = [NSString stringWithFormat:@"unsubscription(%@, %@)", contact.accountID, contact.contactJid];

//unsubscribe
if(contact.isSubscribedTo)
{
UNMutableNotificationContent* content = [UNMutableNotificationContent new];
content.title = xmppAccount.connectionProperties.identity.jid;
content.body = [NSString stringWithFormat:NSLocalizedString(@"The user %@ (%@) removed you from their contact list. You can send out a new contact request, if you think this was a mistake.", @""), contact.contactDisplayName, contact.contactJid];
content.threadIdentifier = [self threadIdentifierWithContact:contact];
//don't simply use contact directly to make sure we always use a freshly created up to date contact when unpacking the userInfo dict
content.userInfo = @{
@"fromContactJid": contact.contactJid,
@"fromContactAccountID": contact.accountID,
};

DDLogDebug(@"Publishing notification with id %@", idval);
[self publishNotificationContent:content withID:idval];
}
//contact request denial
else
{
UNMutableNotificationContent* content = [UNMutableNotificationContent new];
content.title = xmppAccount.connectionProperties.identity.jid;
content.body = [NSString stringWithFormat:NSLocalizedString(@"The user %@ (%@) denied your contact request. You can try again, if you think this was a mistake.", @""), contact.contactDisplayName, contact.contactJid];
content.threadIdentifier = [self threadIdentifierWithContact:contact];
//don't simply use contact directly to make sure we always use a freshly created up to date contact when unpacking the userInfo dict
content.userInfo = @{
@"fromContactJid": contact.contactJid,
@"fromContactAccountID": contact.accountID,
};

DDLogDebug(@"Publishing notification with id %@", idval);
[self publishNotificationContent:content withID:idval];
}
return;
}

//remove contact requests notification once the contact request has been accepted
if(!contact.hasIncomingContactRequest)
{
Expand Down
15 changes: 15 additions & 0 deletions Monal/Classes/xmpp.m
Original file line number Diff line number Diff line change
Expand Up @@ -1942,6 +1942,21 @@ -(void) processInput:(MLXMLNode*) parsedStanza withDelayedReplay:(BOOL) delayedR
}];
}));
}

if([presenceNode check:@"/<type=unsubscribed>"])
{
// check if we need a contact request
NSDictionary* contactSub = [[DataLayer sharedInstance] getSubscriptionForContact:contact.contactJid andAccount:contact.accountID];
DDLogVerbose(@"Got unsubscribed/contact deny request of contact %@ having subscription status: %@", presenceNode.fromUser, contactSub);

//wait 1 sec for nickname and profile image to be processed, then send out kMonalContactRefresh notification
createTimer(1.0, (^{
[[MLNotificationQueue currentQueue] postNotificationName:kMonalContactRefresh object:self userInfo:@{
@"contact": [MLContact createContactFromJid:presenceNode.fromUser andAccountID:self.accountID],
@"unsubscribed": @YES,
}];
}));
}

if(contact.isMuc || [presenceNode check:@"{http://jabber.org/protocol/muc#user}x"] || [presenceNode check:@"{http://jabber.org/protocol/muc}x"])
{
Expand Down

0 comments on commit 50cb223

Please sign in to comment.