Merge pull request #5455 from vector-im/feature/ons/fix_poll_start_notifications

Show notification for poll start events but not for responses
This commit is contained in:
Onuray Sahin 2022-03-15 18:34:03 +03:00 committed by GitHub
commit db0cfd4704
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 10 additions and 3 deletions

1
changelog.d/4780.bugfix Normal file
View file

@ -0,0 +1 @@
Poll system notifications on Android are not user friendly

View file

@ -410,3 +410,5 @@ fun Event.isInvitation(): Boolean = type == EventType.STATE_ROOM_MEMBER &&
fun Event.getPollContent(): MessagePollContent? {
return content.toModel<MessagePollContent>()
}
fun Event.supportsNotification() = this.getClearType() in EventType.MESSAGE + EventType.POLL_START

View file

@ -97,6 +97,7 @@ internal fun RealmQuery<TimelineEventEntity>.filterEvents(filters: TimelineEvent
if (filters.filterEdits) {
not().like(TimelineEventEntityFields.ROOT.CONTENT, TimelineEventFilter.Content.EDIT)
not().like(TimelineEventEntityFields.ROOT.CONTENT, TimelineEventFilter.Content.RESPONSE)
not().like(TimelineEventEntityFields.ROOT.CONTENT, TimelineEventFilter.Content.REFERENCE)
}
if (filters.filterRedacted) {
not().like(TimelineEventEntityFields.ROOT.UNSIGNED_DATA, TimelineEventFilter.Unsigned.REDACTED)

View file

@ -26,6 +26,7 @@ internal object TimelineEventFilter {
internal object Content {
internal const val EDIT = """{*"m.relates_to"*"rel_type":*"m.replace"*}"""
internal const val RESPONSE = """{*"m.relates_to"*"rel_type":*"org.matrix.response"*}"""
internal const val REFERENCE = """{*"m.relates_to"*"rel_type":*"m.reference"*}"""
}
/**

View file

@ -31,6 +31,7 @@ import org.matrix.android.sdk.api.session.events.model.Event
import org.matrix.android.sdk.api.session.events.model.EventType
import org.matrix.android.sdk.api.session.events.model.isEdition
import org.matrix.android.sdk.api.session.events.model.isImageMessage
import org.matrix.android.sdk.api.session.events.model.supportsNotification
import org.matrix.android.sdk.api.session.events.model.toModel
import org.matrix.android.sdk.api.session.room.model.Membership
import org.matrix.android.sdk.api.session.room.model.RoomMemberContent
@ -94,7 +95,7 @@ class NotifiableEventResolver @Inject constructor(
}
suspend fun resolveInMemoryEvent(session: Session, event: Event, canBeReplaced: Boolean): NotifiableEvent? {
if (event.getClearType() != EventType.MESSAGE) return null
if (!event.supportsNotification()) return null
// Ignore message edition
if (event.isEdition()) return null
@ -153,7 +154,8 @@ class NotifiableEventResolver @Inject constructor(
event.attemptToDecryptIfNeeded(session)
// only convert encrypted messages to NotifiableMessageEvents
when (event.root.getClearType()) {
EventType.MESSAGE -> {
EventType.MESSAGE,
in EventType.POLL_START -> {
val body = displayableEventFormatter.format(event, isDm = room.roomSummary()?.isDirect.orFalse(), appendAuthor = false).toString()
val roomName = room.roomSummary()?.displayName ?: ""
val senderDisplayName = event.senderInfo.disambiguatedDisplayName
@ -185,7 +187,7 @@ class NotifiableEventResolver @Inject constructor(
soundName = null
)
}
else -> null
else -> null
}
}
}