-
Notifications
You must be signed in to change notification settings - Fork 72
add moderator tools #813
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
Open
liesandfish
wants to merge
1
commit into
Awful:develop
Choose a base branch
from
liesandfish:post-moderation-menu
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
add moderator tools #813
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 102 additions & 0 deletions
102
Awful.apk/src/main/java/com/ferg/awfulapp/popupmenu/ModeratePostMenu.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| package com.ferg.awfulapp.popupmenu | ||
|
|
||
| import android.os.Bundle | ||
| import androidx.annotation.DrawableRes | ||
| import androidx.annotation.StringRes | ||
| import com.ferg.awfulapp.AwfulActivity | ||
| import com.ferg.awfulapp.NavigationEvent | ||
| import com.ferg.awfulapp.R | ||
| import com.ferg.awfulapp.ThreadDisplayFragment | ||
| import com.ferg.awfulapp.popupmenu.ModeratePostMenu.ModerateMenuAction.EDIT_POST | ||
| import com.ferg.awfulapp.popupmenu.ModeratePostMenu.ModerateMenuAction.REQUEST_BAN | ||
| import com.ferg.awfulapp.popupmenu.ModeratePostMenu.ModerateMenuAction.REQUEST_PROBATION | ||
| import com.ferg.awfulapp.thread.AwfulMessage | ||
|
|
||
| /** | ||
| * Context menu with moderation actions for someone else's post. | ||
| * | ||
| * Shows an edit option when the post is editable by the current user, plus the modqueue | ||
| * probation/ban request options when the post carries modqueue controls. | ||
| */ | ||
| class ModeratePostMenu : BasePopupMenu<ModeratePostMenu.ModerateMenuAction>() { | ||
|
|
||
| private var threadId = 0 | ||
| private var postId = 0 | ||
| private var posterUserId = 0 | ||
| private var editable = false | ||
| private var hasModControls = false | ||
|
|
||
| companion object { | ||
| @JvmField | ||
| val TAG: String = ModeratePostMenu::class.java.simpleName | ||
|
|
||
| private const val ARG_THREAD_ID = "threadId" | ||
| private const val ARG_POST_ID = "postId" | ||
| private const val ARG_POSTER_USER_ID = "posterUserId" | ||
| private const val ARG_EDITABLE = "editable" | ||
| private const val ARG_HAS_MOD_CONTROLS = "hasModControls" | ||
|
|
||
| /** | ||
| * Get a moderation menu for a post, where [editable] adds the edit option and | ||
| * [hasModControls] adds the modqueue probation/ban request options. | ||
| */ | ||
| @JvmStatic | ||
| fun newInstance(threadId: Int, postId: Int, posterUserId: Int, editable: Boolean, hasModControls: Boolean) = | ||
| ModeratePostMenu().apply { | ||
| arguments = Bundle().apply { | ||
| putInt(ARG_THREAD_ID, threadId) | ||
| putInt(ARG_POST_ID, postId) | ||
| putInt(ARG_POSTER_USER_ID, posterUserId) | ||
| putBoolean(ARG_EDITABLE, editable) | ||
| putBoolean(ARG_HAS_MOD_CONTROLS, hasModControls) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| override fun init(args: Bundle) = with(args) { | ||
| threadId = getInt(ARG_THREAD_ID) | ||
| postId = getInt(ARG_POST_ID) | ||
| posterUserId = getInt(ARG_POSTER_USER_ID) | ||
| editable = getBoolean(ARG_EDITABLE) | ||
| hasModControls = getBoolean(ARG_HAS_MOD_CONTROLS) | ||
| } | ||
|
|
||
| override fun generateMenuItems() = | ||
| mutableListOf<ModerateMenuAction>() | ||
| .apply { if (editable) add(EDIT_POST) } | ||
| .apply { if (hasModControls) { add(REQUEST_PROBATION); add(REQUEST_BAN) } } | ||
|
|
||
| override fun getMenuLabel(action: ModerateMenuAction): String = getString(action.menuLabelRes) | ||
|
|
||
| override fun getTitle(): String = getString(R.string.action_moderate_post) | ||
|
|
||
| override fun onActionClicked(action: ModerateMenuAction) { | ||
| when (action) { | ||
| EDIT_POST -> | ||
| (targetFragment as? ThreadDisplayFragment) | ||
| ?.displayPostReplyDialog(threadId, postId, AwfulMessage.TYPE_EDIT) | ||
| REQUEST_PROBATION -> | ||
| navigateTo(NavigationEvent.ModQueueRequest(ban = false, userId = posterUserId, postId = postId, threadId = threadId)) | ||
| REQUEST_BAN -> | ||
| navigateTo(NavigationEvent.ModQueueRequest(ban = true, userId = posterUserId, postId = postId, threadId = threadId)) | ||
| } | ||
| } | ||
|
|
||
| private fun navigateTo(event: NavigationEvent) { | ||
| (activity as AwfulActivity?)?.navigate(event) | ||
| } | ||
|
|
||
| enum class ModerateMenuAction( | ||
| @DrawableRes private val iconResId: Int, | ||
| @StringRes val menuLabelRes: Int | ||
| ) : AwfulAction { | ||
|
|
||
| EDIT_POST(R.drawable.ic_create_dark, R.string.action_edit_post), | ||
| REQUEST_PROBATION(R.drawable.ic_history_dark_24dp, R.string.action_request_probation), | ||
| REQUEST_BAN(R.drawable.ic_gavel_dark_24dp, R.string.action_request_ban); | ||
|
|
||
| override fun getIconId() = iconResId | ||
| // labels are resolved from menuLabelRes in getMenuLabel above, where a Context is available | ||
| override fun getMenuLabel() = "" | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean if we're going for parity, mod tools should be available for your own posts as well. There have been some comedy self-probations in the past that I can remember.