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

GraphQL Migration #25

Merged
merged 10 commits into from
Oct 9, 2024
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
8 changes: 8 additions & 0 deletions .changeset/friendly-cats-beg.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"magicbell-android": major
---

Updated topic and category filtering APIs in `StorePredicate`

Previously one was able to filter for multiple topics and categories, but this functionality is now deprecated in favor of only filtering for a single topic and category.
Please reach out to us via the [Community](http://www.magicbell.com/community) if you need the previous functionality.
5 changes: 5 additions & 0 deletions .changeset/spotty-eels-hope.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"magicbell-android": minor
---

Fixed a bug where a topic filter value would be passed as a category
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -250,9 +250,9 @@ val unreadNotifications = user.store.build(read = false)

val archivedNotifications = user.store.build(archived = true)

val billingNotifications = user.store.build(categories = ["billing"])
val billingNotifications = user.store.build(category = "billing")

val firstOrderNotifications = user.store.build(topics = ["order:001"])
val firstOrderNotifications = user.store.build(topic = "order:001")
```

These are the attributes of a notification store:
Expand Down Expand Up @@ -328,16 +328,16 @@ These are the available options:

| Param | Options | Default | Description |
| ------------ | ---------------------------------- | -------------- | ------------------------------ |
| `read` | `true`, `false`, `nil` | `nil` | Filter by the `read` state (`nil` means unspecified) |
| `seen` | `true`, `false`, `nil` | `nil` | Filter by the `seen` state (`nil` means unspecified) |
| `archived` | `true`, `false` | `false` | Filter by the `archived` state |
| `categories` | `[String]` | `[]` | Filter by categories |
| `topics` | `[String]` | `[]` | Filter by topics |
| `read` | `true`, `false`, `null` | `null` | Filter by the `read` state (`null` means unspecified) |
| `seen` | `true`, `false`, `null` | `null` | Filter by the `seen` state (`null` means unspecified) |
| `archived` | `true`, `false` | `false` | Filter by the `archived` state |
| `category` | `String` | `null` | Filter by category |
| `topic` | `String` | `null` | Filter by topic |

For example, use this predicate to fetch unread notifications of the `"important"` category:

```kotlin
val predicate = StorePredicate(read = true, categories = ["important"])
val predicate = StorePredicate(read = true, category = "important")
val store = user.store.build(predicate)
```

Expand Down Expand Up @@ -392,7 +392,7 @@ for (notification in store) {
}

// As an array
val notifications = store.notifications()
val notifications = store.notifications
```

Enumeration is also available:
Expand Down
27 changes: 0 additions & 27 deletions sdk/src/main/assets/NotificationFragment

This file was deleted.

1 change: 0 additions & 1 deletion sdk/src/main/java/com/magicbell/sdk/SDKProvider.kt
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ internal class DefaultSDKModule(
coroutinesComponent.coroutineDispatcher,
coroutineScope,
MainThreadExecutor(Handler(Looper.getMainLooper())),
context,
notificationComponent,
storeRealTimeComponent,
configComponent
Expand Down
23 changes: 17 additions & 6 deletions sdk/src/main/java/com/magicbell/sdk/common/network/HttpClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,31 @@ import com.magicbell.sdk.common.environment.Environment
import com.magicbell.sdk.common.error.NetworkErrorEntity
import com.magicbell.sdk.common.error.NetworkException
import kotlinx.serialization.json.Json
import okhttp3.HttpUrl.Companion.toHttpUrlOrNull
import okhttp3.OkHttpClient
import okhttp3.Request
import okhttp3.RequestBody.Companion.toRequestBody

typealias HttpHeaders = Array<HeaderNameAndValue>
typealias HeaderNameAndValue = Pair<String, String>
typealias QueryParameters = List<Pair<String, String>>

internal interface HttpClient {
fun prepareRequest(
path: String,
externalId: String?,
email: String?,
hmac: String?,
httpMethod: HttpMethod = HttpMethod.Get,
httpMethod: HttpMethod = HttpMethod.Get(),
additionalHeaders: HttpHeaders = emptyArray()
): Request

suspend fun performRequest(request: Request): String?

sealed class HttpMethod(val name: String, val body: String? = null) {
object Get: HttpMethod("GET")
class Post(body: String = ""): HttpMethod("POST", body)
class Put(body: String = ""): HttpMethod("PUT", body)
sealed class HttpMethod(val name: String, val queryParams: QueryParameters? = null, val body: String? = null) {
class Get(queryParams: QueryParameters = listOf()) : HttpMethod("GET", queryParams = queryParams)
class Post(body: String = ""): HttpMethod("POST", body = body)
class Put(body: String = ""): HttpMethod("PUT", body = body)
object Delete: HttpMethod("DELETE")
}
}
Expand All @@ -37,8 +40,16 @@ internal class DefaultHttpClient(
) : HttpClient {

override fun prepareRequest(path: String, externalId: String?, email: String?, hmac: String?, httpMethod: HttpClient.HttpMethod, additionalHeaders: HttpHeaders): Request {
val urlBuilder = "${environment.baseUrl}/$path".toHttpUrlOrNull()!!.newBuilder()

httpMethod.queryParams?.let {
for ((key, value) in it) {
urlBuilder.addQueryParameter(key, value)
}
}

val request = Request.Builder()
.url("${environment.baseUrl}/$path")
.url(urlBuilder.build())
.addHeader("X-MAGICBELL-API-KEY", environment.apiKey)

hmac?.also {
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ internal class NotificationPreferencesNetworkDataSource(
query.externalId,
query.email,
query.hmac,
HttpClient.HttpMethod.Get,
HttpClient.HttpMethod.Get(),
arrayOf(Pair("accept-version", "v2"))
)

Expand Down
Loading
Loading