Skip to content

Commit

Permalink
Simplified recoveryKeyContext class
Browse files Browse the repository at this point in the history
  • Loading branch information
sacOO7 committed Nov 28, 2023
1 parent 180d68f commit 229617e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 20 deletions.
5 changes: 1 addition & 4 deletions lib/src/main/java/io/ably/lib/realtime/Connection.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,7 @@ public String createRecoveryKey() {
return null;
}

RecoveryKeyContext recoveryKey = new RecoveryKeyContext(key, serial);
recoveryKey.setChannelSerials(this.ably.getChannelSerials());

return recoveryKey.encode();
return new RecoveryKeyContext(key, serial, ably.getChannelSerials()).encode();
}

/**
Expand Down
12 changes: 2 additions & 10 deletions lib/src/main/java/io/ably/lib/types/RecoveryKeyContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ public class RecoveryKeyContext {
*/
private final Map<String, String> channelSerials = new HashMap<>();

public RecoveryKeyContext(String connectionKey, long msgSerial) {
public RecoveryKeyContext(String connectionKey, long msgSerial, Map<String, String> channelSerials) {
this.connectionKey = connectionKey;
this.msgSerial = msgSerial;
this.channelSerials.putAll(channelSerials);
}

public String getConnectionKey() {
Expand All @@ -37,15 +38,6 @@ public Map<String, String> getChannelSerials() {
return channelSerials;
}

public void setChannelSerials(Map<String, String> channelSerials) {
this.channelSerials.clear();
this.channelSerials.putAll(channelSerials);
}

public void addSerial(String channelName, String channelSerial) {
this.channelSerials.put(channelName, channelSerial);
}

public String encode() {
return Serialisation.gson.toJson(this);
}
Expand Down
11 changes: 5 additions & 6 deletions lib/src/test/java/io/ably/lib/types/RecoveryKeyContextTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,11 @@ public class RecoveryKeyContextTest {
public void should_encode_recovery_key_context_object() {
String expectedRecoveryKey =
"{\"connectionKey\":\"uniqueKey\",\"msgSerial\":1,\"channelSerials\":{\"channel1\":\"1\",\"channel2\":\"2\",\"channel3\":\"3\"}}";
RecoveryKeyContext recoveryKey = new RecoveryKeyContext("uniqueKey", 1);
Map<String, String> keys = new HashMap<>();
keys.put("channel1", "1");
keys.put("channel2", "2");
keys.put("channel3", "3");
recoveryKey.setChannelSerials(keys);
Map<String, String> serials = new HashMap<>();
serials.put("channel1", "1");
serials.put("channel2", "2");
serials.put("channel3", "3");
RecoveryKeyContext recoveryKey = new RecoveryKeyContext("uniqueKey", 1, serials);
String encodedRecoveryKey = recoveryKey.encode();
assertEquals(expectedRecoveryKey, encodedRecoveryKey);
}
Expand Down

0 comments on commit 229617e

Please sign in to comment.