From 5d56fd791f841d39249c0de43e997e65f74a6f7a Mon Sep 17 00:00:00 2001 From: fridtjof <2780577+fridtjof@users.noreply.github.com> Date: Fri, 22 Mar 2019 00:40:27 +0100 Subject: [PATCH 1/4] add a threadIdentifier to notifications and implement titles --- Riot/AppDelegate.m | 51 ++++++++++++++++++------ Riot/Assets/en.lproj/Localizable.strings | 11 +++++ 2 files changed, 50 insertions(+), 12 deletions(-) diff --git a/Riot/AppDelegate.m b/Riot/AppDelegate.m index 7985de290..c6a01d15a 100644 --- a/Riot/AppDelegate.m +++ b/Riot/AppDelegate.m @@ -1815,7 +1815,7 @@ NSString *const kAppDelegateNetworkStatusDidChangeNotification = @"kAppDelegateN }]; } -// iOS 10+, does the same thing as notificationBodyForEvent:pushRule:inAccount:onComplete: for now +// iOS 10+, does the same thing as notificationBodyForEvent:pushRule:inAccount:onComplete:, except with more features - (void)notificationContentForEvent:(MXEvent *)event pushRule:(MXPushRule *)rule inAccount:(MXKAccount *)account onComplete:(void (^)(UNMutableNotificationContent * _Nullable notificationContent))onComplete; { if (!event.content || !event.content.count) @@ -1835,7 +1835,10 @@ NSString *const kAppDelegateNetworkStatusDidChangeNotification = @"kAppDelegateN [room state:^(MXRoomState *roomState) { + NSString *notificationTitle; NSString *notificationBody; + + NSString *threadIdentifier = room.roomId; NSString *eventSenderName = [roomState.members memberName:event.sender]; if (event.eventType == MXEventTypeRoomMessage || event.eventType == MXEventTypeRoomEncrypted) @@ -1873,7 +1876,7 @@ NSString *const kAppDelegateNetworkStatusDidChangeNotification = @"kAppDelegateN } NSString *msgType = event.content[@"msgtype"]; - NSString *content = event.content[@"body"]; + NSString *messageContent = event.content[@"body"]; if (event.isEncrypted && !RiotSettings.shared.showDecryptedContentInNotifications) { @@ -1886,27 +1889,44 @@ NSString *const kAppDelegateNetworkStatusDidChangeNotification = @"kAppDelegateN // Display the room name only if it is different than the sender name if (roomDisplayName.length && ![roomDisplayName isEqualToString:eventSenderName]) { + notificationTitle = [NSString stringWithFormat:NSLocalizedString(@"MSG_FROM_USER_IN_ROOM_TITLE", nil), eventSenderName, roomDisplayName]; if ([msgType isEqualToString:@"m.text"]) - notificationBody = [NSString stringWithFormat:NSLocalizedString(@"MSG_FROM_USER_IN_ROOM_WITH_CONTENT", nil), eventSenderName,roomDisplayName, content]; + notificationBody = messageContent; else if ([msgType isEqualToString:@"m.emote"]) - notificationBody = [NSString stringWithFormat:NSLocalizedString(@"ACTION_FROM_USER_IN_ROOM", nil), roomDisplayName, eventSenderName, content]; + { + notificationTitle = nil; + // TODO: how should this look? /me style messages don't look right with a title + // maybe like this: + // title = roomDisplayName + // body = * eventSenderName messageContent + + notificationBody = [NSString stringWithFormat:NSLocalizedString(@"ACTION_FROM_USER_IN_ROOM", nil), roomDisplayName, eventSenderName, messageContent]; + } else if ([msgType isEqualToString:@"m.image"]) - notificationBody = [NSString stringWithFormat:NSLocalizedString(@"IMAGE_FROM_USER_IN_ROOM", nil), eventSenderName, content, roomDisplayName]; + notificationBody = NSLocalizedString(@"IMAGE_TEXT_WITH_TITLE", nil); else // Encrypted messages falls here - notificationBody = [NSString stringWithFormat:NSLocalizedString(@"MSG_FROM_USER_IN_ROOM", nil), eventSenderName, roomDisplayName]; + notificationBody = NSLocalizedString(@"MSG_TEXT_WITH_TITLE", nil); } else { + notificationTitle = eventSenderName; if ([msgType isEqualToString:@"m.text"]) - notificationBody = [NSString stringWithFormat:NSLocalizedString(@"MSG_FROM_USER_WITH_CONTENT", nil), eventSenderName, content]; + notificationBody = messageContent; else if ([msgType isEqualToString:@"m.emote"]) - notificationBody = [NSString stringWithFormat:NSLocalizedString(@"ACTION_FROM_USER", nil), eventSenderName, content]; + { + notificationTitle = nil; + // TODO: how should this look? /me style messages look weird with a title + // maybe like this: + // title = eventSenderName + // body = * messageContent + notificationBody = [NSString stringWithFormat:NSLocalizedString(@"ACTION_FROM_USER", nil), eventSenderName, messageContent]; + } else if ([msgType isEqualToString:@"m.image"]) - notificationBody = [NSString stringWithFormat:NSLocalizedString(@"IMAGE_FROM_USER", nil), eventSenderName, content]; + notificationBody = NSLocalizedString(@"IMAGE_TEXT_WITH_TITLE", nil); else // Encrypted messages falls here - notificationBody = [NSString stringWithFormat:NSLocalizedString(@"MSG_FROM_USER", nil), eventSenderName]; + notificationBody = NSLocalizedString(@"MSG_TEXT_WITH_TITLE", nil); } } else if (event.eventType == MXEventTypeCallInvite) @@ -1918,6 +1938,8 @@ NSString *const kAppDelegateNetworkStatusDidChangeNotification = @"kAppDelegateN notificationBody = [NSString stringWithFormat:NSLocalizedString(@"VOICE_CALL_FROM_USER", nil), eventSenderName]; else notificationBody = [NSString stringWithFormat:NSLocalizedString(@"VIDEO_CALL_FROM_USER", nil), eventSenderName]; + + threadIdentifier = nil; // call notifications should probably stand out from normal messages } else if (event.eventType == MXEventTypeRoomMember) { @@ -1933,13 +1955,18 @@ NSString *const kAppDelegateNetworkStatusDidChangeNotification = @"kAppDelegateN NSString *roomDisplayName = room.summary.displayname; if (roomDisplayName.length && ![roomDisplayName isEqualToString:eventSenderName]) - notificationBody = [NSString stringWithFormat:NSLocalizedString(@"MSG_FROM_USER_IN_ROOM", nil), eventSenderName, roomDisplayName]; + notificationTitle = [NSString stringWithFormat:NSLocalizedString(@"MSG_FROM_USER_IN_ROOM_TITLE", nil), eventSenderName, roomDisplayName]; else - notificationBody = [NSString stringWithFormat:NSLocalizedString(@"MSG_FROM_USER", nil), eventSenderName]; + notificationTitle = eventSenderName; + + notificationBody = NSLocalizedString(@"STICKER_TEXT_WITH_TITLE", nil); } UNMutableNotificationContent *content = [[UNMutableNotificationContent alloc] init]; + + [content setTitle:notificationTitle]; [content setBody:notificationBody]; + [content setThreadIdentifier:threadIdentifier]; onComplete(content); }]; diff --git a/Riot/Assets/en.lproj/Localizable.strings b/Riot/Assets/en.lproj/Localizable.strings index 33e5d39f4..53b8a579c 100644 --- a/Riot/Assets/en.lproj/Localizable.strings +++ b/Riot/Assets/en.lproj/Localizable.strings @@ -22,6 +22,9 @@ /* New message from a specific person in a named room */ "MSG_FROM_USER_IN_ROOM" = "%@ posted in %@"; +/* New message when a notification title is used */ +"MSG_TEXT_WITH_TITLE" = "Encrypted message"; + /** Single, unencrypted messages (where we can include the content */ /* New message from a specific person, not referencing a room. Content included. */ @@ -44,12 +47,18 @@ /* New action message from a specific person in a named room. */ "IMAGE_FROM_USER_IN_ROOM" = "%@ posted a picture %@ in %@"; +/* New action message, but the sender (and room) are already in the notification title */ +"IMAGE_TEXT_WITH_TITLE" = "📷 Picture"; + /* A single unread message in a room */ "SINGLE_UNREAD_IN_ROOM" = "You received a message in %@"; /* A single unread message */ "SINGLE_UNREAD" = "You received a message"; +/* Sticker, but with the sender (and room) already in the title */ +"STICKER_TEXT_WITH_TITLE" = "Sticker"; + /** Coalesced messages **/ /* Multiple unread messages in a room */ @@ -103,3 +112,5 @@ /* Incoming named video conference invite from a specific person */ "VIDEO_CONF_NAMED_FROM_USER" = "Video group call from %@: '%@'"; + +"MSG_FROM_USER_IN_ROOM_TITLE" = "%@ in %@"; \ No newline at end of file From 3f21c790bf827140014528740a384a3127950a02 Mon Sep 17 00:00:00 2001 From: fridtjof <2780577+fridtjof@users.noreply.github.com> Date: Fri, 22 Mar 2019 01:10:57 +0100 Subject: [PATCH 2/4] add additional notification titles --- Riot/AppDelegate.m | 19 ++++++++++++------- Riot/Assets/en.lproj/Localizable.strings | 12 ++++++++++-- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/Riot/AppDelegate.m b/Riot/AppDelegate.m index c6a01d15a..ed80fd1d2 100644 --- a/Riot/AppDelegate.m +++ b/Riot/AppDelegate.m @@ -1934,21 +1934,26 @@ NSString *const kAppDelegateNetworkStatusDidChangeNotification = @"kAppDelegateN NSString *sdp = event.content[@"offer"][@"sdp"]; BOOL isVideoCall = [sdp rangeOfString:@"m=video"].location != NSNotFound; - if (!isVideoCall) - notificationBody = [NSString stringWithFormat:NSLocalizedString(@"VOICE_CALL_FROM_USER", nil), eventSenderName]; - else - notificationBody = [NSString stringWithFormat:NSLocalizedString(@"VIDEO_CALL_FROM_USER", nil), eventSenderName]; + notificationTitle = eventSenderName; - threadIdentifier = nil; // call notifications should probably stand out from normal messages + if (!isVideoCall) + notificationBody = NSLocalizedString(@"VOICE_CALL", nil); + else + notificationBody = NSLocalizedString(@"VIDEO_CALL", nil); + + // call notifications should stand out from normal messages, so we don't stack them + threadIdentifier = nil; } else if (event.eventType == MXEventTypeRoomMember) { NSString *roomDisplayName = room.summary.displayname; + notificationTitle = roomDisplayName; + if (roomDisplayName.length && ![roomDisplayName isEqualToString:eventSenderName]) - notificationBody = [NSString stringWithFormat:NSLocalizedString(@"USER_INVITE_TO_NAMED_ROOM", nil), eventSenderName, roomDisplayName]; + notificationBody = [NSString stringWithFormat:NSLocalizedString(@"INVITE_BY_USER_TO_ROOM", nil), eventSenderName]; else - notificationBody = [NSString stringWithFormat:NSLocalizedString(@"USER_INVITE_TO_CHAT", nil), eventSenderName]; + notificationBody = NSLocalizedString(@"INVITE_TO_CHAT", nil); } else if (event.eventType == MXEventTypeSticker) { diff --git a/Riot/Assets/en.lproj/Localizable.strings b/Riot/Assets/en.lproj/Localizable.strings index 53b8a579c..38fca6c83 100644 --- a/Riot/Assets/en.lproj/Localizable.strings +++ b/Riot/Assets/en.lproj/Localizable.strings @@ -23,7 +23,7 @@ "MSG_FROM_USER_IN_ROOM" = "%@ posted in %@"; /* New message when a notification title is used */ -"MSG_TEXT_WITH_TITLE" = "Encrypted message"; +"MSG_TEXT_WITH_TITLE" = "Message"; /** Single, unencrypted messages (where we can include the content */ @@ -57,7 +57,7 @@ "SINGLE_UNREAD" = "You received a message"; /* Sticker, but with the sender (and room) already in the title */ -"STICKER_TEXT_WITH_TITLE" = "Sticker"; +"STICKER_TEXT_WITH_TITLE" = "💟 Sticker"; /** Coalesced messages **/ @@ -93,14 +93,22 @@ /* A user has invited you to a named room */ "USER_INVITE_TO_NAMED_ROOM" = "%@ has invited you to %@"; +"INVITE_TO_CHAT" = "You were invited to chat"; + +"INVITE_BY_USER_TO_ROOM" = "You were invited by %@"; + /** Calls **/ /* Incoming one-to-one voice call */ "VOICE_CALL_FROM_USER" = "Call from %@"; +"VOICE_CALL" = "📞 Call"; + /* Incoming one-to-one video call */ "VIDEO_CALL_FROM_USER" = "Video call from %@"; +"VIDEO_CALL" = "📹 Video call"; + /* Incoming unnamed voice conference invite from a specific person */ "VOICE_CONF_FROM_USER" = "Group call from %@"; From 689d05259023944f39257fb6fc817f4fa8eb1140 Mon Sep 17 00:00:00 2001 From: fridtjof <2780577+fridtjof@users.noreply.github.com> Date: Fri, 22 Mar 2019 01:20:50 +0100 Subject: [PATCH 3/4] finalize emote style notifications --- Riot/AppDelegate.m | 17 ++++------------- Riot/Assets/en.lproj/Localizable.strings | 5 +++++ 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/Riot/AppDelegate.m b/Riot/AppDelegate.m index ed80fd1d2..1bd28e594 100644 --- a/Riot/AppDelegate.m +++ b/Riot/AppDelegate.m @@ -1894,13 +1894,8 @@ NSString *const kAppDelegateNetworkStatusDidChangeNotification = @"kAppDelegateN notificationBody = messageContent; else if ([msgType isEqualToString:@"m.emote"]) { - notificationTitle = nil; - // TODO: how should this look? /me style messages don't look right with a title - // maybe like this: - // title = roomDisplayName - // body = * eventSenderName messageContent - - notificationBody = [NSString stringWithFormat:NSLocalizedString(@"ACTION_FROM_USER_IN_ROOM", nil), roomDisplayName, eventSenderName, messageContent]; + notificationTitle = roomDisplayName; + notificationBody = [NSString stringWithFormat:NSLocalizedString(@"ACTION_FROM_USER", nil), eventSenderName, messageContent]; } else if ([msgType isEqualToString:@"m.image"]) notificationBody = NSLocalizedString(@"IMAGE_TEXT_WITH_TITLE", nil); @@ -1915,12 +1910,8 @@ NSString *const kAppDelegateNetworkStatusDidChangeNotification = @"kAppDelegateN notificationBody = messageContent; else if ([msgType isEqualToString:@"m.emote"]) { - notificationTitle = nil; - // TODO: how should this look? /me style messages look weird with a title - // maybe like this: - // title = eventSenderName - // body = * messageContent - notificationBody = [NSString stringWithFormat:NSLocalizedString(@"ACTION_FROM_USER", nil), eventSenderName, messageContent]; + notificationTitle = eventSenderName; + notificationBody = [NSString stringWithFormat:NSLocalizedString(@"ACTION", nil), messageContent]; } else if ([msgType isEqualToString:@"m.image"]) notificationBody = NSLocalizedString(@"IMAGE_TEXT_WITH_TITLE", nil); diff --git a/Riot/Assets/en.lproj/Localizable.strings b/Riot/Assets/en.lproj/Localizable.strings index 38fca6c83..b387bfa82 100644 --- a/Riot/Assets/en.lproj/Localizable.strings +++ b/Riot/Assets/en.lproj/Localizable.strings @@ -39,6 +39,9 @@ /* New action message from a specific person in a named room. */ "ACTION_FROM_USER_IN_ROOM" = "%@: * %@ %@"; +/* New action message, sender is specified in notification title */ +"ACTION" = "* %@"; + /** Image Messages **/ /* New action message from a specific person, not referencing a room. */ @@ -93,8 +96,10 @@ /* A user has invited you to a named room */ "USER_INVITE_TO_NAMED_ROOM" = "%@ has invited you to %@"; +/* Same as USER_INVITE_TO_CHAT but the username is already displayed in the notification title */ "INVITE_TO_CHAT" = "You were invited to chat"; +/* Same as USER_INVITE_TO_NAMED_ROOM but the room name is already displayed in the notification title */ "INVITE_BY_USER_TO_ROOM" = "You were invited by %@"; /** Calls **/ From b8a314d7dbe0c7194cb3adc994e3556bfd74bd83 Mon Sep 17 00:00:00 2001 From: fridtjof <2780577+fridtjof@users.noreply.github.com> Date: Fri, 22 Mar 2019 01:30:20 +0100 Subject: [PATCH 4/4] update CHANGES.rst --- CHANGES.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGES.rst b/CHANGES.rst index f060e739d..fc8ea25b4 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -2,6 +2,8 @@ Changes in 0.8.5 (2019-xx-xx) =============================================== Improvements: + * Added titles to notifications on iOS 10+ (#2347). + * Implemented notification grouping (#2347). Bug fix: