Skip to content

Fix group notification classification in INSendMessageIntent #5699

@ianalexander

Description

@ianalexander

Steps to reproduce

Context

iOS has a feature where it can automatically announce push notifications as they come in. In order for this to work, chat apps can classify those push notifications as direct messages or group messages.

These ios settings then appear in the notification settings that allow users to enable or disable announcements for each type. You can choose to only announce direct messages, as an example.

Problem

With only "Announce direct messages" enabled in the iOS notification settings above, the app will announce every single notification I receive -- including group messages that are not direct messages.

Steps to reproduce

  1. Put in airpods
  2. Go to iOS notification settings for element x, ensure announce notifications is enabled, and only "direct messages" are enabled
  3. Receive a message in a room
  4. Observe the room message is announced, despite only "direct messages" are enabled for announcements

Proposed solution

Today, in addCommunicationContext, when a notification belonged to a group room, the recipients array of the INSendMessageIntent was being populated with both the sender and the current user (me):

if let groupInfo = icon.groupInfo {
let meHandle = INPersonHandle(value: notificationContent.receiverID, type: .unknown)
let me = INPerson(personHandle: meHandle, nameComponents: nil, displayName: nil, image: nil, contactIdentifier: nil, customIdentifier: nil, isMe: true)
speakableGroupName = INSpeakableString(spokenPhrase: groupInfo.displayName)
recipients = [sender, me]
}
let intent = INSendMessageIntent(recipients: recipients,
outgoingMessageType: .outgoingMessageText,
content: nil,
speakableGroupName: speakableGroupName,
conversationIdentifier: notificationContent.roomID,
serviceName: nil,
sender: sender,
attachments: nil)

According to Apple's INSendMessageIntent documentation, the sender parameter defines who sent the message, while the recipients parameter defines the destination users of the message. It says not to include the sender or current user in recipients:

For group message intents, provide an array that contains the other participants of the message for the recipients parameter. For example, in a group of three participants that includes the current user, the sender of the message and the current user are already represented. The recipients array contains one object — the other recipient. Group conversations can also provide a speakableGroupName if the conversation has a name.

I believe when handling an incoming group notification, including the sender inside the recipients destination array causes some kind of issue. I think iOS interprets a conversation containing only the sender and the receiver (me) as a 1:1 direct message, which overrides the group layout rules and ignores the speakableGroupName.

I believe the right way to fix this is to simply set recipients to nil and keep the speakableGroupName value:

let intent = INSendMessageIntent(recipients: nil,
                                         outgoingMessageType: .outgoingMessageText,
                                         content: nil,
                                         speakableGroupName: speakableGroupName,
                                         conversationIdentifier: notificationContent.roomID,
                                         serviceName: nil,
                                         sender: sender,
                                         attachments: nil)

I don't have an ios dev license to check this myself but based on the docs I've read I think this is right.

Outcome

What did you expect?

I expect with only "direct messages" enabled for announcement, room messages are not announced.

What happened instead?

With only "direct messages" enabled for announcement, every notification is announced, including room notifications.

Your phone model

No response

Operating system version

No response

Application version

No response

Homeserver

No response

Will you send logs?

No

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions