Skip to content

Commit 1a76914

Browse files
authored
Merge pull request #5345 from vector-im/feature/ons/fix_unstable_prefixes
Support both unstable and stable prefixes
2 parents de14e10 + f4bdaf6 commit 1a76914

32 files changed

+162
-127
lines changed

changelog.d/5340.bugfix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Support both stable and unstable prefixes for Events about Polls and Location

matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/events/model/Event.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ fun Event.isAttachmentMessage(): Boolean {
349349
}
350350
}
351351

352-
fun Event.isPoll(): Boolean = getClearType() == EventType.POLL_START || getClearType() == EventType.POLL_END
352+
fun Event.isPoll(): Boolean = getClearType() in EventType.POLL_START || getClearType() in EventType.POLL_END
353353

354354
fun Event.isSticker(): Boolean = getClearType() == EventType.STICKER
355355

@@ -372,7 +372,7 @@ fun Event.getRelationContent(): RelationDefaultContent? {
372372
* Returns the poll question or null otherwise
373373
*/
374374
fun Event.getPollQuestion(): String? =
375-
getPollContent()?.pollCreationInfo?.question?.question
375+
getPollContent()?.getBestPollCreationInfo()?.question?.getBestQuestion()
376376

377377
/**
378378
* Returns the relation content for a specific type or null otherwise

matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/events/model/EventType.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,9 @@ object EventType {
103103
const val REACTION = "m.reaction"
104104

105105
// Poll
106-
const val POLL_START = "org.matrix.msc3381.poll.start"
107-
const val POLL_RESPONSE = "org.matrix.msc3381.poll.response"
108-
const val POLL_END = "org.matrix.msc3381.poll.end"
106+
val POLL_START = listOf("org.matrix.msc3381.poll.start", "m.poll.start")
107+
val POLL_RESPONSE = listOf("org.matrix.msc3381.poll.response", "m.poll.response")
108+
val POLL_END = listOf("org.matrix.msc3381.poll.end", "m.poll.end")
109109

110110
// Unwedging
111111
internal const val DUMMY = "m.dummy"

matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/model/message/MessageLocationContent.kt

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -39,37 +39,46 @@ data class MessageLocationContent(
3939
*/
4040
@Json(name = "geo_uri") val geoUri: String,
4141

42+
@Json(name = "m.relates_to") override val relatesTo: RelationDefaultContent? = null,
43+
@Json(name = "m.new_content") override val newContent: Content? = null,
4244
/**
4345
* See https://github.com/matrix-org/matrix-doc/blob/matthew/location/proposals/3488-location.md
4446
*/
45-
@Json(name = "org.matrix.msc3488.location") val locationInfo: LocationInfo? = null,
46-
47-
@Json(name = "m.relates_to") override val relatesTo: RelationDefaultContent? = null,
48-
@Json(name = "m.new_content") override val newContent: Content? = null,
49-
47+
@Json(name = "org.matrix.msc3488.location") val unstableLocationInfo: LocationInfo? = null,
48+
@Json(name = "m.location") val locationInfo: LocationInfo? = null,
49+
/**
50+
* Exact time that the data in the event refers to (milliseconds since the UNIX epoch)
51+
*/
52+
@Json(name = "org.matrix.msc3488.ts") val unstableTs: Long? = null,
53+
@Json(name = "m.ts") val ts: Long? = null,
54+
@Json(name = "org.matrix.msc1767.text") val unstableText: String? = null,
55+
@Json(name = "m.text") val text: String? = null,
5056
/**
5157
* m.asset defines a generic asset that can be used for location tracking but also in other places like
5258
* inventories, geofencing, checkins/checkouts etc.
5359
* It should contain a mandatory namespaced type key defining what particular asset is being referred to.
5460
* For the purposes of user location tracking m.self should be used in order to avoid duplicating the mxid.
5561
*/
56-
@Json(name = "m.asset") val locationAsset: LocationAsset? = null,
62+
@Json(name = "org.matrix.msc3488.asset") val unstableLocationAsset: LocationAsset? = null,
63+
@Json(name = "m.asset") val locationAsset: LocationAsset? = null
64+
) : MessageContent {
5765

58-
/**
59-
* Exact time that the data in the event refers to (milliseconds since the UNIX epoch)
60-
*/
61-
@Json(name = "org.matrix.msc3488.ts") val ts: Long? = null,
66+
fun getBestLocationInfo() = locationInfo ?: unstableLocationInfo
6267

63-
@Json(name = "org.matrix.msc1767.text") val text: String? = null
64-
) : MessageContent {
68+
fun getBestTs() = ts ?: unstableTs
69+
70+
fun getBestText() = text ?: unstableText
71+
72+
fun getBestLocationAsset() = locationAsset ?: unstableLocationAsset
6573

66-
fun getBestGeoUri() = locationInfo?.geoUri ?: geoUri
74+
fun getBestGeoUri() = getBestLocationInfo()?.geoUri ?: geoUri
6775

6876
/**
6977
* @return true if the location asset is a user location, not a generic one.
7078
*/
7179
fun isSelfLocation(): Boolean {
7280
// Should behave like m.self if locationAsset is null
81+
val locationAsset = getBestLocationAsset()
7382
return locationAsset?.type == null || locationAsset.type == LocationAssetType.SELF
7483
}
7584
}

matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/model/message/MessagePollContent.kt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,9 @@ data class MessagePollContent(
3131
@Json(name = "body") override val body: String = "",
3232
@Json(name = "m.relates_to") override val relatesTo: RelationDefaultContent? = null,
3333
@Json(name = "m.new_content") override val newContent: Content? = null,
34-
@Json(name = "org.matrix.msc3381.poll.start") val pollCreationInfo: PollCreationInfo? = null
35-
) : MessageContent
34+
@Json(name = "org.matrix.msc3381.poll.start") val unstablePollCreationInfo: PollCreationInfo? = null,
35+
@Json(name = "m.poll.start") val pollCreationInfo: PollCreationInfo? = null
36+
) : MessageContent {
37+
38+
fun getBestPollCreationInfo() = pollCreationInfo ?: unstablePollCreationInfo
39+
}

matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/model/message/MessagePollResponseContent.kt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,9 @@ data class MessagePollResponseContent(
3131
@Json(name = "body") override val body: String = "",
3232
@Json(name = "m.relates_to") override val relatesTo: RelationDefaultContent? = null,
3333
@Json(name = "m.new_content") override val newContent: Content? = null,
34-
@Json(name = "org.matrix.msc3381.poll.response") val response: PollResponse? = null
35-
) : MessageContent
34+
@Json(name = "org.matrix.msc3381.poll.response") val unstableResponse: PollResponse? = null,
35+
@Json(name = "m.response") val response: PollResponse? = null
36+
) : MessageContent {
37+
38+
fun getBestResponse() = response ?: unstableResponse
39+
}

matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/model/message/PollAnswer.kt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,9 @@ import com.squareup.moshi.JsonClass
2222
@JsonClass(generateAdapter = true)
2323
data class PollAnswer(
2424
@Json(name = "id") val id: String? = null,
25-
@Json(name = "org.matrix.msc1767.text") val answer: String? = null
26-
)
25+
@Json(name = "org.matrix.msc1767.text") val unstableAnswer: String? = null,
26+
@Json(name = "m.text") val answer: String? = null
27+
) {
28+
29+
fun getBestAnswer() = answer ?: unstableAnswer
30+
}

matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/model/message/PollCreationInfo.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ import com.squareup.moshi.JsonClass
2121

2222
@JsonClass(generateAdapter = true)
2323
data class PollCreationInfo(
24-
@Json(name = "question") val question: PollQuestion? = null,
25-
@Json(name = "kind") val kind: PollType? = PollType.DISCLOSED,
26-
@Json(name = "max_selections") val maxSelections: Int = 1,
27-
@Json(name = "answers") val answers: List<PollAnswer>? = null
24+
@Json(name = "question") val question: PollQuestion? = null,
25+
@Json(name = "kind") val kind: PollType? = PollType.DISCLOSED_UNSTABLE,
26+
@Json(name = "max_selections") val maxSelections: Int = 1,
27+
@Json(name = "answers") val answers: List<PollAnswer>? = null
2828
)

matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/model/message/PollQuestion.kt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,9 @@ import com.squareup.moshi.JsonClass
2121

2222
@JsonClass(generateAdapter = true)
2323
data class PollQuestion(
24-
@Json(name = "org.matrix.msc1767.text") val question: String? = null
25-
)
24+
@Json(name = "org.matrix.msc1767.text") val unstableQuestion: String? = null,
25+
@Json(name = "m.text") val question: String? = null
26+
) {
27+
28+
fun getBestQuestion() = question ?: unstableQuestion
29+
}

matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/model/message/PollType.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,17 @@ enum class PollType {
2525
* Voters should see results as soon as they have voted.
2626
*/
2727
@Json(name = "org.matrix.msc3381.poll.disclosed")
28+
DISCLOSED_UNSTABLE,
29+
30+
@Json(name = "m.poll.disclosed")
2831
DISCLOSED,
2932

3033
/**
3134
* Results should be only revealed when the poll is ended.
3235
*/
3336
@Json(name = "org.matrix.msc3381.poll.undisclosed")
37+
UNDISCLOSED_UNSTABLE,
38+
39+
@Json(name = "m.poll.undisclosed")
3440
UNDISCLOSED
3541
}

0 commit comments

Comments
 (0)