Skip to content

Commit

Permalink
always show notes that contain the #surveyme marker (fixes #2641)
Browse files Browse the repository at this point in the history
  • Loading branch information
westnordost committed Mar 11, 2021
1 parent 6065361 commit b3ad39b
Showing 1 changed file with 13 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class OsmNotesDownloader @Inject constructor(
* Likely, if something is posed as a question, the reporter expects someone to
* answer/comment on it, so let's only show these */
val showNonQuestionNotes = preferences.getBoolean(Prefs.SHOW_NOTES_NOT_PHRASED_AS_QUESTIONS, false)
return !(quest.probablyContainsQuestion() || showNonQuestionNotes)
return !(quest.probablyContainsQuestion() || quest.note.containsSurveyRequiredMarker() || showNonQuestionNotes)
}

private fun shouldMakeNoteClosed(userId: Long?, note: Note): Boolean {
Expand All @@ -77,12 +77,13 @@ class OsmNotesDownloader @Inject constructor(
}
}

private fun Note.containsSurveyRequiredMarker(): Boolean {
val surveyRequiredMarker = "#surveyme"
return comments.any { it.text?.matches(".*$surveyRequiredMarker.*".toRegex()) == true }
}

private fun Note.containsCommentFromUser(userId: Long): Boolean {
for (comment in comments) {
val isComment = comment.action == NoteComment.Action.COMMENTED
if (comment.isFromUser(userId) && isComment) return true
}
return false
return comments.any { it.isFromUser(userId) && it.isComment }
}

private fun Note.probablyCreatedByUserInApp(userId: Long): Boolean {
Expand All @@ -91,6 +92,9 @@ private fun Note.probablyCreatedByUserInApp(userId: Long): Boolean {
return firstComment.isFromUser(userId) && isViaApp
}

private fun NoteComment.isFromUser(userId: Long): Boolean {
return user != null && user.id == userId
}
private val NoteComment.isComment: Boolean get() =
action == NoteComment.Action.COMMENTED

private fun NoteComment.isFromUser(userId: Long): Boolean =
user?.id == userId

0 comments on commit b3ad39b

Please sign in to comment.