Merge pull request #1303 from mlc/rick_roll_domains
Rick roll instead of logging in on selected domains. This is not censorship, but rather a choice by this house who will facilitate our services to.
This commit is contained in:
commit
5d04a7ccda
|
@ -34,6 +34,8 @@ import com.keylesspalace.tusky.entity.AccessToken
|
|||
import com.keylesspalace.tusky.entity.AppCredentials
|
||||
import com.keylesspalace.tusky.network.MastodonApi
|
||||
import com.keylesspalace.tusky.util.ThemeUtils
|
||||
import com.keylesspalace.tusky.util.rickRoll
|
||||
import com.keylesspalace.tusky.util.shouldRickRoll
|
||||
import kotlinx.android.synthetic.main.activity_login.*
|
||||
import okhttp3.HttpUrl
|
||||
import retrofit2.Call
|
||||
|
@ -138,6 +140,11 @@ class LoginActivity : BaseActivity(), Injectable {
|
|||
return
|
||||
}
|
||||
|
||||
if (shouldRickRoll(this, domain)) {
|
||||
rickRoll(this)
|
||||
return
|
||||
}
|
||||
|
||||
val callback = object : Callback<AppCredentials> {
|
||||
override fun onResponse(call: Call<AppCredentials>,
|
||||
response: Response<AppCredentials>) {
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
package com.keylesspalace.tusky.util
|
||||
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.net.Uri
|
||||
import com.keylesspalace.tusky.R
|
||||
|
||||
fun shouldRickRoll(context: Context, domain: String) =
|
||||
context.resources.getStringArray(R.array.rick_roll_domains).any { candidate ->
|
||||
domain.equals(candidate, true) || domain.endsWith(".$candidate", true)
|
||||
}
|
||||
|
||||
fun rickRoll(context: Context) {
|
||||
val uri = Uri.parse(context.getString(R.string.rick_roll_url))
|
||||
val intent = Intent(Intent.ACTION_VIEW, uri).apply {
|
||||
addCategory(Intent.CATEGORY_BROWSABLE)
|
||||
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
}
|
||||
context.startActivity(intent)
|
||||
}
|
|
@ -104,4 +104,10 @@
|
|||
%1$s; %2$s; %3$s, %13$s %4$s, %5$s; %6$s, %7$s, %8$s, %9$s; %10$s, %11$s, %12$s
|
||||
</string>
|
||||
|
||||
<string-array name="rick_roll_domains" translatable="false">
|
||||
<item>gab.com</item>
|
||||
<item>gab.ai</item>
|
||||
</string-array>
|
||||
|
||||
<string name="rick_roll_url">https://www.youtube.com/watch?v=dQw4w9WgXcQ</string>
|
||||
</resources>
|
||||
|
|
|
@ -0,0 +1,34 @@
|
|||
package com.keylesspalace.tusky.util
|
||||
|
||||
import android.app.Activity
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||
import com.keylesspalace.tusky.FakeTuskyApplication
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.robolectric.Robolectric
|
||||
import org.robolectric.annotation.Config
|
||||
|
||||
@Config(application = FakeTuskyApplication::class)
|
||||
@RunWith(AndroidJUnit4::class)
|
||||
class RickRollTest {
|
||||
private lateinit var activity: Activity
|
||||
@Before
|
||||
fun setupActivity() {
|
||||
val controller = Robolectric.buildActivity(Activity::class.java)
|
||||
activity = controller.get()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testShouldRickRoll() {
|
||||
listOf("gab.Com", "social.gab.ai", "whatever.GAB.com").forEach {
|
||||
rollableDomain -> assertTrue(shouldRickRoll(activity, rollableDomain))
|
||||
}
|
||||
|
||||
listOf("chaos.social", "notgab.com").forEach {
|
||||
notRollableDomain -> assertFalse(shouldRickRoll(activity, notRollableDomain))
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue