Skip to content

Commit 50cb223

Browse files
Show notification on remote unsubscribe / contact denial
1 parent 206d4d9 commit 50cb223

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

Monal/Classes/MLNotificationManager.m

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,46 @@ -(void) handleContactRefresh:(NSNotification*) notification
8080
MLContact* contact = notification.userInfo[@"contact"];
8181
NSString* idval = [NSString stringWithFormat:@"subscription(%@, %@)", contact.accountID, contact.contactJid];
8282

83+
//contact request denial or unsubscribe
84+
if(notification.userInfo[@"unsubscribed"] != nil && [notification.userInfo[@"unsubscribed"] boolValue] == YES)
85+
{
86+
idval = [NSString stringWithFormat:@"unsubscription(%@, %@)", contact.accountID, contact.contactJid];
87+
88+
//unsubscribe
89+
if(contact.isSubscribedTo)
90+
{
91+
UNMutableNotificationContent* content = [UNMutableNotificationContent new];
92+
content.title = xmppAccount.connectionProperties.identity.jid;
93+
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];
94+
content.threadIdentifier = [self threadIdentifierWithContact:contact];
95+
//don't simply use contact directly to make sure we always use a freshly created up to date contact when unpacking the userInfo dict
96+
content.userInfo = @{
97+
@"fromContactJid": contact.contactJid,
98+
@"fromContactAccountID": contact.accountID,
99+
};
100+
101+
DDLogDebug(@"Publishing notification with id %@", idval);
102+
[self publishNotificationContent:content withID:idval];
103+
}
104+
//contact request denial
105+
else
106+
{
107+
UNMutableNotificationContent* content = [UNMutableNotificationContent new];
108+
content.title = xmppAccount.connectionProperties.identity.jid;
109+
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];
110+
content.threadIdentifier = [self threadIdentifierWithContact:contact];
111+
//don't simply use contact directly to make sure we always use a freshly created up to date contact when unpacking the userInfo dict
112+
content.userInfo = @{
113+
@"fromContactJid": contact.contactJid,
114+
@"fromContactAccountID": contact.accountID,
115+
};
116+
117+
DDLogDebug(@"Publishing notification with id %@", idval);
118+
[self publishNotificationContent:content withID:idval];
119+
}
120+
return;
121+
}
122+
83123
//remove contact requests notification once the contact request has been accepted
84124
if(!contact.hasIncomingContactRequest)
85125
{

Monal/Classes/xmpp.m

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1942,6 +1942,21 @@ -(void) processInput:(MLXMLNode*) parsedStanza withDelayedReplay:(BOOL) delayedR
19421942
}];
19431943
}));
19441944
}
1945+
1946+
if([presenceNode check:@"/<type=unsubscribed>"])
1947+
{
1948+
// check if we need a contact request
1949+
NSDictionary* contactSub = [[DataLayer sharedInstance] getSubscriptionForContact:contact.contactJid andAccount:contact.accountID];
1950+
DDLogVerbose(@"Got unsubscribed/contact deny request of contact %@ having subscription status: %@", presenceNode.fromUser, contactSub);
1951+
1952+
//wait 1 sec for nickname and profile image to be processed, then send out kMonalContactRefresh notification
1953+
createTimer(1.0, (^{
1954+
[[MLNotificationQueue currentQueue] postNotificationName:kMonalContactRefresh object:self userInfo:@{
1955+
@"contact": [MLContact createContactFromJid:presenceNode.fromUser andAccountID:self.accountID],
1956+
@"unsubscribed": @YES,
1957+
}];
1958+
}));
1959+
}
19451960

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

0 commit comments

Comments
 (0)