mirror of
https://gitlab.linphone.org/BC/public/linphone-iphone.git
synced 2026-02-07 14:18:25 +00:00
Implement notification mute for group & encrypted chatrooms
This commit is contained in:
parent
930dd74c89
commit
0e31b555c1
6 changed files with 52 additions and 12 deletions
|
|
@ -1721,13 +1721,6 @@ void on_chat_room_conference_alert(LinphoneChatRoom *cr, const LinphoneEventLog
|
|||
}
|
||||
}
|
||||
|
||||
-(BOOL) isConversationMuted {
|
||||
return FALSE; // TODO
|
||||
}
|
||||
-(void) toggleMuteConversation {
|
||||
// TODO
|
||||
}
|
||||
|
||||
-(void) showAddressAndIdentityPopup {
|
||||
|
||||
char *localAddress = linphone_address_as_string(linphone_chat_room_get_local_address(_chatRoom));
|
||||
|
|
@ -1799,7 +1792,8 @@ void on_chat_room_conference_alert(LinphoneChatRoom *cr, const LinphoneEventLog
|
|||
[PhoneMainView.instance popToView:view.compositeViewDescription];
|
||||
}
|
||||
if ((!isEncrypted && indexPath.row == 1) || (isEncrypted && indexPath.row == 3)) {
|
||||
[self toggleMuteConversation];
|
||||
[LinphoneManager setChatroomPushEnabled:_chatRoom withPushEnabled:![LinphoneManager getChatroomPushEnabled:_chatRoom]];
|
||||
[_popupMenu reloadData];
|
||||
}
|
||||
|
||||
if ((!isEncrypted && indexPath.row == 2) || (isEncrypted && indexPath.row == 4)) {
|
||||
|
|
@ -1865,12 +1859,12 @@ void on_chat_room_conference_alert(LinphoneChatRoom *cr, const LinphoneEventLog
|
|||
}
|
||||
|
||||
if ((isEncrypted && indexPath.row == 3) || (!isEncrypted && indexPath.row == 1)) {
|
||||
if ([self isConversationMuted]) {
|
||||
if ([LinphoneManager getChatroomPushEnabled:_chatRoom]) {
|
||||
cell.imageView.image = [LinphoneUtils resizeImage:[UIImage imageNamed:@"menu_notifications_off.png"] newSize:CGSizeMake(20, 25)];
|
||||
cell.textLabel.text = NSLocalizedString(@"NOT IMPLEMENTED",nil);
|
||||
cell.textLabel.text = NSLocalizedString(@"Mute notifications",nil);
|
||||
} else {
|
||||
cell.imageView.image = [LinphoneUtils resizeImage:[UIImage imageNamed:@"menu_notifications_on.png"] newSize:CGSizeMake(20, 25)];
|
||||
cell.textLabel.text = NSLocalizedString(@"NOT IMPLEMENTED",nil);
|
||||
cell.textLabel.text = NSLocalizedString(@"Un-mute notifications",nil);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -231,7 +231,9 @@ void deletion_chat_room_state_changed(LinphoneChatRoom *cr, LinphoneChatRoomStat
|
|||
}
|
||||
}
|
||||
[ftdToDelete cancel];
|
||||
|
||||
|
||||
// Re-enable push notification after deleting the chatroom, in order to get the notification if we are re-invited, or for secure 1-to-1 chatrooms.
|
||||
[LinphoneManager setChatroomPushEnabled:chatRoom withPushEnabled:TRUE];
|
||||
linphone_core_delete_chat_room(LC, chatRoom);
|
||||
chatRooms = chatRooms->next;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -192,6 +192,8 @@ typedef struct _LinphoneManagerSounds {
|
|||
- (BOOL)isCTCallCenterExist;
|
||||
- (void) checkLocalNetworkPermission;
|
||||
|
||||
+ (BOOL) getChatroomPushEnabled:(LinphoneChatRoom *)chatroom;
|
||||
+ (void) setChatroomPushEnabled:(LinphoneChatRoom *)chatroom withPushEnabled:(BOOL)enabled;
|
||||
|
||||
@property (readonly) BOOL isTesting;
|
||||
@property(readonly, strong) FastAddressBook *fastAddressBook;
|
||||
|
|
|
|||
|
|
@ -2303,6 +2303,31 @@ void linphone_iphone_conference_state_changed(LinphoneCore *lc, LinphoneConferen
|
|||
[NSNotificationCenter.defaultCenter postNotificationName:kLinphoneConfStateChanged object:nil userInfo:dict];
|
||||
}
|
||||
|
||||
+ (BOOL) getChatroomPushEnabled:(LinphoneChatRoom *)chatroom {
|
||||
bool currently_enabled = true;
|
||||
NSUserDefaults *defaults = [[NSUserDefaults alloc] initWithSuiteName:kLinphoneMsgNotificationAppGroupId];
|
||||
NSDictionary *chatroomsPushStatus = [defaults dictionaryForKey:@"chatroomsPushStatus"];
|
||||
if (chatroomsPushStatus != nil && chatroom) {
|
||||
char *uri = linphone_address_as_string_uri_only(linphone_chat_room_get_peer_address(chatroom));
|
||||
NSString* pushStatus = [chatroomsPushStatus objectForKey:[NSString stringWithUTF8String:uri]];
|
||||
currently_enabled = (pushStatus == nil) || [pushStatus isEqualToString:@"enabled"];
|
||||
ms_free(uri);
|
||||
}
|
||||
return currently_enabled;
|
||||
}
|
||||
|
||||
+ (void) setChatroomPushEnabled:(LinphoneChatRoom *)chatroom withPushEnabled:(BOOL)enabled {
|
||||
if (!chatroom) return;
|
||||
|
||||
NSUserDefaults *defaults = [[NSUserDefaults alloc] initWithSuiteName:kLinphoneMsgNotificationAppGroupId];
|
||||
NSMutableDictionary *chatroomsPushStatus = [[NSMutableDictionary alloc] initWithDictionary:[defaults dictionaryForKey:@"chatroomsPushStatus"]];
|
||||
if (chatroomsPushStatus == nil) chatroomsPushStatus = [[NSMutableDictionary dictionary] init];
|
||||
|
||||
char *uri = linphone_address_as_string_uri_only(linphone_chat_room_get_peer_address(chatroom));
|
||||
[chatroomsPushStatus setValue:(enabled ? @"enabled" : @"disabled") forKey:[NSString stringWithUTF8String:uri]];
|
||||
ms_free(uri);
|
||||
|
||||
[defaults setObject:chatroomsPushStatus forKey:@"chatroomsPushStatus"];
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
|
|||
|
|
@ -64,6 +64,21 @@ class NotificationService: UNNotificationServiceExtension {
|
|||
createCore()
|
||||
NotificationService.log.message(message: "received push payload : \(bestAttemptContent.userInfo.debugDescription)")
|
||||
|
||||
|
||||
let defaults = UserDefaults.init(suiteName: APP_GROUP_ID)
|
||||
if let chatroomsPushStatus = defaults?.dictionary(forKey: "chatroomsPushStatus") {
|
||||
let aps = bestAttemptContent.userInfo["aps"] as? NSDictionary
|
||||
let alert = aps?["alert"] as? NSDictionary
|
||||
let fromAddresses = alert?["loc-args"] as? [String]
|
||||
|
||||
if let from = fromAddresses?.first {
|
||||
if ((chatroomsPushStatus[from] as? String) == "disabled") {
|
||||
NotificationService.log.message(message: "message comes from a muted chatroom, ignore it")
|
||||
contentHandler(UNNotificationContent())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if let chatRoomInviteAddr = bestAttemptContent.userInfo["chat-room-addr"] as? String, !chatRoomInviteAddr.isEmpty {
|
||||
NotificationService.log.message(message: "fetch chat room for invite, addr: \(chatRoomInviteAddr)")
|
||||
let chatRoom = lc!.getNewChatRoomFromConfAddr(chatRoomAddr: chatRoomInviteAddr)
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@
|
|||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>com.apple.developer.usernotifications.filtering</key>
|
||||
<true/>
|
||||
<key>com.apple.security.application-groups</key>
|
||||
<array>
|
||||
<string>group.org.linphone.phone.msgNotification</string>
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue