Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OsmNoteQuestController: surveyme override and regex test update #6075

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -196,16 +196,22 @@ private fun Note.shouldShowAsQuest(
// don't show notes hidden by user
if (id in blockedNoteIds) return false

// don't show notes where user replied last unless he wrote a survey required marker
if (comments.last().isReplyFromUser(userId)
/*
We usually don't show notes where either the user is the last responder, or the
note was created with the app and has no replies.
If the most recent comment contains "#surveyme", we want to show the note regardless.
kmpoppe marked this conversation as resolved.
Show resolved Hide resolved
See https://github.com/streetcomplete/StreetComplete/issues/6052#issuecomment-2567163451
*/
if (
(
comments.last().isReplyFromUser(userId) ||
(probablyCreatedByUserInThisApp(userId) && !hasReplies)
)
&& !comments.last().containsSurveyRequiredMarker()
) {
return false
}

// newly created notes by user should not be shown if it was both created in this app and has no replies yet
if (probablyCreatedByUserInThisApp(userId) && !hasReplies) return false

/*
many notes are created to report problems on the map that cannot be resolved
through an on-site survey.
Expand Down Expand Up @@ -250,7 +256,7 @@ private fun Note.containsSurveyRequiredMarker(): Boolean =
comments.any { it.containsSurveyRequiredMarker() }

private fun NoteComment.containsSurveyRequiredMarker(): Boolean =
text?.matches(".*#surveyme.*".toRegex()) == true
text?.contains("#surveyme", ignoreCase = true) == true

private fun Note.probablyCreatedByUserInThisApp(userId: Long): Boolean {
val firstComment = comments.first()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,33 @@ class OsmNoteQuestControllerTest {
assertNotNull(ctrl.getVisible(1))
}

@Test fun `get note quest created in app without comments and without survey required marker returns null`() {
on(noteSource.get(1)).thenReturn(note(comments = listOf(
comment(text = "this is a non-question test note\n\nCreated via StreetComplete 60.1", user = User(id = 100, "Blaubär")),
)))
on(userDataSource.userId).thenReturn(1)

assertNull(ctrl.getVisible(1))
}

@Test fun `get note quest created in app without comments and with survey required marker returns non-null`() {
on(noteSource.get(1)).thenReturn(note(comments = listOf(
comment(text = "this is a non-question test note #surveyme\n\nCreated via StreetComplete 60.1", user = User(id = 100, "Blaubär")),
)))
on(userDataSource.userId).thenReturn(1)

assertNotNull(ctrl.getVisible(1))
}

@Test fun `get note quest created in app without comments and with survey required marker (ignore case) returns non-null`() {
on(noteSource.get(1)).thenReturn(note(comments = listOf(
comment(text = "this is a non-question test note #SurVEyMe\n\nCreated via StreetComplete 60.1", user = User(id = 100, "Blaubär")),
)))
on(userDataSource.userId).thenReturn(1)

assertNotNull(ctrl.getVisible(1))
}

@Test fun `get quest not phrased as question returns null`() {
on(noteSource.get(1)).thenReturn(note(comments = listOf(
comment(text = "test")
Expand Down