Skip to content

Commit 9a5d748

Browse files
authored
Merge pull request #70 from parley-messaging/develop
3.11.0
2 parents 8fb7302 + 72e881f commit 9a5d748

24 files changed

+494
-350
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## 3.11.0 - Released 18 Sep 2024
4+
5+
- [Chat Message] Fixed an issue causing agent images not to load since 3.10.0.
6+
- [Network] Added support for providing a custom network session to prevent using Parley's default implementation. Check out the [Advanced - Network](https://github.com/parley-messaging/android-library?tab=readme-ov-file#network) section to use this.
7+
- [Network] *Important* `ParleyNetwork.setInterceptor()` is removed. Use a custom network session instead, or provide the interceptor with the default `RetrofitNetworkSession` of Parley, as described in the [Advanced - Network](https://github.com/parley-messaging/android-library?tab=readme-ov-file#network) section.
8+
39
## 3.10.0 - Released 30 Jul 2024
410

511
- [Source] Parley now uses Kotlin at certain parts. Make sure to configure Kotlin in your project in case it doesn't use Kotlin yet.

Gemfile.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,8 @@ GEM
163163
trailblazer-option (>= 0.1.1, < 0.2.0)
164164
uber (< 0.2.0)
165165
retriable (3.1.2)
166-
rexml (3.2.8)
167-
strscan (>= 3.0.9)
166+
rexml (3.3.6)
167+
strscan
168168
rouge (2.0.7)
169169
ruby2_keywords (0.0.5)
170170
rubyzip (2.3.2)
@@ -193,13 +193,13 @@ GEM
193193
unicode-display_width (1.8.0)
194194
webrick (1.7.0)
195195
word_wrap (1.0.0)
196-
xcodeproj (1.21.0)
196+
xcodeproj (1.25.0)
197197
CFPropertyList (>= 2.3.3, < 4.0)
198198
atomos (~> 0.1.3)
199199
claide (>= 1.0.2, < 2.0)
200200
colored2 (~> 3.1)
201201
nanaimo (~> 0.3.0)
202-
rexml (~> 3.2.4)
202+
rexml (>= 3.3.2, < 4.0)
203203
xcpretty (0.3.0)
204204
rouge (~> 2.0.7)
205205
xcpretty-travis-formatter (1.0.1)

README.md

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ allprojects {
5757
To integrate Parley, specify the following in your `app/build.gradle` file:
5858

5959
```groovy
60-
implementation 'com.github.parley-messaging:android-library:3.10.0'
60+
implementation 'com.github.parley-messaging:android-library:3.11.0'
6161
```
6262

6363
### Upgrading
@@ -222,10 +222,36 @@ Parley.setNetwork(network);
222222

223223
**Custom interceptor**
224224

225-
If needed to apply a custom interceptor, for example when the headers could be dynamic. This can be done by creating an `okhttp3.Interceptor` and attaching that to the ParleyNetwork:
225+
If the only need is to apply a custom interceptor to the default network session of Parley, for example when using dynamic headers. It's possible to create an `okhttp3.Interceptor`, create the default `RetrofitNetworkSession` with the interceptor and provide that to the `ParleyNetwork` configuration.
226226

227227
```java
228-
network.setInterceptor(interceptor);
228+
ParleyNetworkSession networkSession = new RetrofitNetworkSession(interceptor);
229+
ParleyNetwork network = new ParleyNetwork(
230+
"https://api.parley.nu/",
231+
"clientApi/v1.7/",
232+
ApiVersion.V1_7,
233+
R.xml.parley_network_security_config,
234+
networkSession
235+
);
236+
237+
Parley.setNetwork(network);
238+
```
239+
240+
**Custom network config**
241+
242+
If using a custom interceptor is not enough, it's also possible to fully create you own `ParleyNetworkSession` implementation. You'll need to implement the `ParleyNetworkSession` interface. Then provide the custom `ParleyNetworkSession` to the `ParleyNetwork` configuration:
243+
244+
```java
245+
ParleyNetworkSession networkSession = new CustomNetworkSession();
246+
ParleyNetwork network = new ParleyNetwork(
247+
"https://api.parley.nu/",
248+
"clientApi/v1.7/",
249+
ApiVersion.V1_7,
250+
R.xml.parley_network_security_config,
251+
networkSession
252+
);
253+
254+
Parley.setNetwork(network);
229255
```
230256

231257
**Custom SSL pinning**

app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ android {
99
minSdkVersion 21
1010
targetSdk 34
1111
versionCode 1
12-
versionName "3.10.0"
12+
versionName "3.11.0"
1313
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
1414
}
1515
buildTypes {
@@ -42,7 +42,7 @@ dependencies {
4242
implementation "com.google.firebase:firebase-messaging:23.4.1"
4343

4444
// Library
45-
// implementation 'com.github.parley-messaging:android-library:3.10.0' // Remote
45+
// implementation 'com.github.parley-messaging:android-library:3.11.0' // Remote
4646
implementation project(':parley') // Local
4747

4848
// Tests

app/src/main/java/nu/parley/ui/IdentifierActivity.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,8 @@
1010
import android.widget.ProgressBar;
1111
import android.widget.TextView;
1212

13-
import androidx.annotation.NonNull;
1413
import androidx.annotation.Nullable;
1514

16-
import com.google.android.gms.tasks.OnCompleteListener;
17-
import com.google.android.gms.tasks.Task;
1815
import com.google.firebase.messaging.FirebaseMessaging;
1916

2017
import java.security.InvalidKeyException;

parley/build.gradle

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ apply plugin: 'maven-publish'
33
apply plugin: 'org.jetbrains.kotlin.android'
44

55
group = 'com.github.parley-messaging'
6-
version = '3.10.0'
6+
version = '3.11.0'
77

88
android {
99
namespace 'nu.parley.android'
@@ -61,7 +61,10 @@ dependencies {
6161

6262
// Retrofit
6363
implementation "com.squareup.retrofit2:retrofit:2.9.0"
64-
implementation "com.squareup.retrofit2:converter-gson:2.9.0"
64+
implementation 'com.squareup.retrofit2:converter-scalars:2.9.0'
65+
66+
// Gson
67+
implementation "com.google.code.gson:gson:2.11.0"
6568

6669
// Glide
6770
implementation "com.github.bumptech.glide:glide:4.15.1"

parley/src/main/java/nu/parley/android/Parley.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,7 @@ private void configureI(Context context, String secret, @Nullable String uniqueD
581581
this.secret = secret;
582582

583583
if (uniqueDeviceIdentifier == null) {
584-
this.uniqueDeviceIdentifier = DeviceRepository.getDeviceId(context);
584+
this.uniqueDeviceIdentifier = DeviceRepository.Companion.getDeviceId(context);
585585
} else {
586586
this.uniqueDeviceIdentifier = uniqueDeviceIdentifier;
587587
}

parley/src/main/java/nu/parley/android/ParleyNetwork.java

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
package nu.parley.android;
22

3-
import androidx.annotation.Nullable;
43
import androidx.annotation.XmlRes;
54

6-
import java.util.Collections;
75
import java.util.HashMap;
86
import java.util.Map;
97

108
import nu.parley.android.data.model.ApiVersion;
11-
import okhttp3.Interceptor;
9+
import nu.parley.android.data.net.service.RetrofitNetworkSession;
10+
import nu.parley.android.data.net.service.ParleyNetworkSession;
1211

1312
/**
1413
* Provides the network configuration for Parley.
@@ -20,12 +19,11 @@ public final class ParleyNetwork {
2019

2120
public final String url;
2221
public final Map<String, String> headers;
23-
@Nullable
24-
public Interceptor interceptor;
2522
@XmlRes
2623
final Integer securityConfigResourceFile;
2724
public final String path;
2825
public final ApiVersion apiVersion;
26+
public final ParleyNetworkSession networkSession;
2927

3028
/**
3129
* Applies the default network settings of Parley.
@@ -36,6 +34,7 @@ public final class ParleyNetwork {
3634
this.apiVersion = ApiVersion.V1_7;
3735
this.securityConfigResourceFile = R.xml.parley_network_security_config;
3836
this.headers = new HashMap<>();
37+
this.networkSession = new RetrofitNetworkSession();
3938
}
4039

4140
/**
@@ -45,7 +44,17 @@ public final class ParleyNetwork {
4544
*/
4645
@SuppressWarnings("unused")
4746
public ParleyNetwork(String url, String path, ApiVersion apiVersion, @XmlRes Integer securityConfigResourceFile) {
48-
this(url, path, apiVersion, securityConfigResourceFile, new HashMap<String, String>());
47+
this(url, path, apiVersion, securityConfigResourceFile, new HashMap<String, String>(), new RetrofitNetworkSession());
48+
}
49+
50+
/**
51+
* Convenience for ParleyNetwork(url, path, apiVersion, securityConfigResourceFile, parleyNetworkSession).
52+
*
53+
* @see #ParleyNetwork(String, String, ApiVersion, Integer, Map)
54+
*/
55+
@SuppressWarnings("unused")
56+
public ParleyNetwork(String url, String path, ApiVersion apiVersion, @XmlRes Integer securityConfigResourceFile, ParleyNetworkSession parleyNetworkSession) {
57+
this(url, path, apiVersion, securityConfigResourceFile, new HashMap<String, String>(), parleyNetworkSession);
4958
}
5059

5160
/**
@@ -67,18 +76,29 @@ public ParleyNetwork(String url, String path, ApiVersion apiVersion, @XmlRes Int
6776
this.apiVersion = apiVersion;
6877
this.securityConfigResourceFile = securityConfigResourceFile;
6978
this.headers = headers;
79+
this.networkSession = new RetrofitNetworkSession();
7080
}
7181

72-
7382
/**
74-
* Sets the network interceptor for the Parley client.
83+
* Apply custom network settings. Parley requires SSL pinning, so it expects a valid security config file.
7584
*
76-
* @param interceptor the interceptor to set
77-
* @return the current instance of the Parley network configuration
85+
* <p>
86+
* <b>Note:</b>* Make sure to add the reference to the `AndroidManifest.xml` as well.
87+
* </p>
88+
*
89+
* @param url Url to your Parley backend service.
90+
* @param path Path to the Parley chat API.
91+
* @param apiVersion API version of the Parley chat API. Note that the `path` should use the same api version as well.
92+
* @param securityConfigResourceFile Android Network Security Configuration file xml resource with SSL Pinning configuration.
93+
* @param headers Additional headers to append to each network request of Parley.
7894
*/
79-
public ParleyNetwork setInterceptor(Interceptor interceptor) {
80-
this.interceptor = interceptor;
81-
return this;
95+
public ParleyNetwork(String url, String path, ApiVersion apiVersion, @XmlRes Integer securityConfigResourceFile, Map<String, String> headers, ParleyNetworkSession parleyNetworkSession) {
96+
this.url = url;
97+
this.path = path;
98+
this.apiVersion = apiVersion;
99+
this.securityConfigResourceFile = securityConfigResourceFile;
100+
this.headers = headers;
101+
this.networkSession = parleyNetworkSession;
82102
}
83103

84104
/**

parley/src/main/java/nu/parley/android/data/model/Message.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -255,11 +255,6 @@ public Media getMedia() {
255255

256256
@Nullable
257257
public String getImageUrl() {
258-
if (image != null) {
259-
// Legacy: Messages from clientApi 1.5 and lower
260-
return image;
261-
}
262-
263258
if (getMedia() != null && getMedia().getMimeType().isImage()) {
264259
if (localUrl == null) {
265260
// Messages from clientApi 1.6 and higher
@@ -270,6 +265,12 @@ public String getImageUrl() {
270265
}
271266
}
272267

268+
if (image != null) {
269+
// Legacy: Messages from clientApi 1.5 and lower.
270+
// Legacy: Agent messages have both media and image filled.
271+
return image;
272+
}
273+
273274
return null;
274275
}
275276

parley/src/main/java/nu/parley/android/data/net/Connectivity.java

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,14 @@
1818

1919
import nu.parley.android.Parley;
2020
import nu.parley.android.data.net.response.ParleyErrorResponse;
21+
import nu.parley.android.data.net.service.RetrofitNetworkSession;
22+
import nu.parley.android.data.net.service.ParleyNetworkSession;
2123
import okhttp3.Interceptor;
2224
import okhttp3.OkHttpClient;
2325
import okhttp3.Request;
2426
import okhttp3.Response;
2527
import retrofit2.Retrofit;
26-
import retrofit2.converter.gson.GsonConverterFactory;
28+
import retrofit2.converter.scalars.ScalarsConverterFactory;
2729

2830
public final class Connectivity {
2931

@@ -38,7 +40,7 @@ public final class Connectivity {
3840
public static Retrofit getRetrofit() {
3941
Retrofit.Builder retrofitBuilder = new Retrofit.Builder()
4042
.baseUrl(Parley.getInstance().getNetwork().getBaseUrl())
41-
.addConverterFactory(GsonConverterFactory.create())
43+
.addConverterFactory(ScalarsConverterFactory.create())
4244
.client(getOkHttpClient());
4345

4446
return retrofitBuilder.build();
@@ -116,10 +118,13 @@ public static Map<String, String> getParleyHeaders() {
116118
* @return the OkHttpClient.Builder with the added interceptor.
117119
*/
118120
private static OkHttpClient.Builder addInterceptor(OkHttpClient.Builder builder) {
119-
if (Parley.getInstance().getNetwork().interceptor != null) {
120-
return builder.addInterceptor(Parley.getInstance().getNetwork().interceptor);
121-
}
122-
return builder;
121+
ParleyNetworkSession networkSession = Parley.getInstance().getNetwork().networkSession;
122+
123+
if (!(networkSession instanceof RetrofitNetworkSession)) return builder;
124+
Interceptor interceptor = ((RetrofitNetworkSession) networkSession).getInterceptor();
125+
126+
if (interceptor == null) return builder;
127+
return builder.addInterceptor(interceptor);
123128
}
124129

125130
public static String toMediaUrl(String mediaId) {

0 commit comments

Comments
 (0)