Skip to content

Commit fd3e7da

Browse files
authored
Release 2.3.0
2 parents 7442407 + ae6f1dc commit fd3e7da

File tree

79 files changed

+4785
-2507
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+4785
-2507
lines changed
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
package Stacks.JavaKotlin
2+
3+
import com.simplito.java.privmx_endpoint.model.UserWithPubKey
4+
import com.simplito.java.privmx_endpoint_extra.model.SortOrder
5+
6+
fun creatingThreadWithCustomField() {
7+
val contextId = "CONTEXT_ID"
8+
val users: List<UserWithPubKey> = listOf(
9+
UserWithPubKey(user1Id, user1PublicKey),
10+
UserWithPubKey(user2Id, user2PublicKey)
11+
)
12+
val managers: List<UserWithPubKey> = listOf(
13+
UserWithPubKey(user1Id, user1PublicKey)
14+
)
15+
val privateMeta = "PRIVATE_META"
16+
17+
val publicMeta = """
18+
{
19+
"threadType": "special"
20+
"numberOfMessages": 20
21+
"tags": ["TAG1", "TAG2", "TAG3"]
22+
}
23+
""".trimIndent()
24+
25+
endpointSession.threadApi.createThread(
26+
contextId,
27+
users,
28+
managers,
29+
publicMeta.encodeToByteArray(),
30+
privateMeta.encodeToByteArray()
31+
)
32+
}
33+
34+
fun creatingQueryWithOneSpecifiedValue(): String {
35+
//Start snippet
36+
val query = """
37+
{
38+
"threadType": "special"
39+
}
40+
""".trimIndent()
41+
//End snippet
42+
43+
return query
44+
}
45+
46+
fun creatingQueryWithTwoSpecifiedValues(): String {
47+
//Start snippet
48+
val query = """
49+
{
50+
"numberOfMessages": { "${'$'}gt": 10 },
51+
"tags": "TAG2"
52+
}
53+
""".trimIndent()
54+
//End snippet
55+
56+
return query
57+
}
58+
59+
fun creatingQueryWithOrCondition(): String {
60+
//Start snippet
61+
val query = """
62+
{
63+
"${'$'}or": [
64+
{ "threadType": "archived"},
65+
{ "numberOfMessages": 20}
66+
]
67+
}
68+
""".trimIndent()
69+
//End snippet
70+
71+
return query
72+
}
73+
74+
fun listingThreadsWithCustomQueries(query: String) {
75+
val startIndex = 0L
76+
val pageSize = 100L
77+
val lastId = null
78+
79+
endpointSession.threadApi.listThreads(
80+
contextId,
81+
startIndex,
82+
pageSize,
83+
SortOrder.ASC,
84+
lastId,
85+
query
86+
)
87+
}

examples/privmx-snippets/src/main/kotlin/Stacks/JavaKotlin/PrivMXEndpointJava.kt

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
package Stacks.JavaKotlin
22

3+
import Stacks.JavaKotlin.events.eventApi
34
import Stacks.JavaKotlin.inboxes.inboxApi
45
import Stacks.JavaKotlin.stores.storeApi
56
import Stacks.JavaKotlin.threads.threadApi
7+
import com.simplito.java.privmx_endpoint.model.VerificationRequest
8+
import com.simplito.java.privmx_endpoint.modules.core.UserVerifierInterface
69
import com.simplito.java.privmx_endpoint_extra.lib.PrivmxEndpoint
710
import com.simplito.java.privmx_endpoint_extra.lib.PrivmxEndpointContainer
811
import com.simplito.java.privmx_endpoint_extra.model.Modules
@@ -33,13 +36,14 @@ val user2PublicKey = "PUBLIC_KEY_2"
3336
// END: Initial assumption snippet
3437

3538

36-
fun makeConnection(){
39+
fun makeConnection() {
3740
// START: Make connection snippet
3841
val pathToCerts = "PATH_TO_CERTS" // Path to .pem ssl certificate to connect with Privmx Bridge
3942
val initModules = setOf(
4043
Modules.THREAD, // initializes ThreadApi to working with Threads
4144
Modules.STORE, // initializes StoreApi to working with Stores
42-
Modules.INBOX // initializes InboxApi to working with Inboxes
45+
Modules.INBOX, // initializes InboxApi to working with Inboxes
46+
Modules.CUSTOM_EVENT // initializes EventApi to working with Custom Events
4347
) // set of modules to activate in new connection
4448

4549
val endpointContainer = PrivmxEndpointContainer().also {
@@ -54,30 +58,44 @@ fun makeConnection(){
5458
)
5559
// END: Make connection snippet
5660

57-
setupConnection(endpointContainer,endpointSession)
61+
setupConnection(endpointContainer, endpointSession)
5862
}
5963

60-
fun getEndpoint(){
64+
fun setUserVerifier() {
65+
val userVerifier: UserVerifierInterface = object : UserVerifierInterface {
66+
override fun verify(requests: List<VerificationRequest>): List<Boolean> {
67+
return requests.map { request ->
68+
// Your verification code for the request
69+
true
70+
}
71+
}
72+
}
73+
74+
endpointSession.connection.setUserVerifier(userVerifier)
75+
}
76+
77+
fun getEndpoint() {
6178
endpointContainer.getEndpoint(endpointSession.connection.connectionId)
6279
}
6380

64-
fun close(){
81+
fun close() {
6582
endpointContainer.close()
6683
}
6784

68-
fun disconnectAll(){
85+
fun disconnectAll() {
6986
endpointContainer.disconnectAll()
7087
}
7188

72-
fun disconnectById(){
89+
fun disconnectById() {
7390
endpointContainer.disconnect(endpointSession.connection.connectionId)
7491
}
7592

7693
//setup global connection variables
77-
private fun setupConnection(ct: PrivmxEndpointContainer, conn: PrivmxEndpoint){
94+
private fun setupConnection(ct: PrivmxEndpointContainer, conn: PrivmxEndpoint) {
7895
endpointContainer = ct
7996
endpointSession = conn
8097
threadApi = endpointSession.threadApi
8198
storeApi = endpointSession.storeApi
8299
inboxApi = endpointSession.inboxApi
100+
eventApi = endpointSession.eventApi
83101
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package Stacks.JavaKotlin.events
2+
3+
import Stacks.JavaKotlin.endpointSession
4+
import Stacks.JavaKotlin.user1Id
5+
import Stacks.JavaKotlin.user1PublicKey
6+
import Stacks.JavaKotlin.user2Id
7+
import Stacks.JavaKotlin.user2PublicKey
8+
import com.simplito.java.privmx_endpoint.model.UserWithPubKey
9+
import com.simplito.java.privmx_endpoint.modules.event.EventApi
10+
import com.simplito.java.privmx_endpoint_extra.events.EventType
11+
12+
lateinit var eventApi: EventApi
13+
14+
fun setEventApi() {
15+
val eventApi = endpointSession.eventApi
16+
}
17+
18+
fun emittingCustomEvents() {
19+
val contextId = "CONTEXT_ID"
20+
val channelName = "CHANNEL_NAME"
21+
22+
val users: List<UserWithPubKey> = listOf(
23+
UserWithPubKey(user1Id, user1PublicKey),
24+
UserWithPubKey(user2Id, user2PublicKey)
25+
)
26+
val eventData = "Custom Event Data"
27+
28+
endpointSession.eventApi.emitEvent(
29+
contextId, users, channelName, eventData.encodeToByteArray()
30+
)
31+
}
32+
33+
fun handlingCustomEvents() {
34+
val callbacksId = "CALLBACKS_ID"
35+
val contextId = "CONTEXT_ID"
36+
val channelName = "CHANNEL_NAME"
37+
38+
endpointSession.registerCallback(
39+
callbacksId,
40+
EventType.ContextCustomEvent(contextId, channelName)
41+
) { customEventData ->
42+
// Some actions when custom event arrives
43+
}
44+
}

privmx-endpoint-android/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ if (file("build-publish-maven.gradle").exists()) {
1414
apply from: "build-publish-maven.gradle"
1515
}
1616

17-
version = "2.2.2"
17+
version = '2.3.0'
1818

1919
android {
2020
namespace 'com.simplito.android.privmx_endpoint_wrapper'

privmx-endpoint-extra/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ if (file("build-publish-maven.gradle").exists()) {
1414
apply from: "build-publish-maven.gradle"
1515
}
1616

17-
version = '2.2.2'
17+
version = '2.3.0'
1818

1919
java {
2020
sourceCompatibility = JavaVersion.VERSION_1_8

privmx-endpoint-extra/src/main/java/com/simplito/java/privmx_endpoint_extra/events/EventType.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import com.simplito.java.privmx_endpoint.model.Message;
1818
import com.simplito.java.privmx_endpoint.model.Store;
1919
import com.simplito.java.privmx_endpoint.model.Thread;
20+
import com.simplito.java.privmx_endpoint.model.events.ContextCustomEventData;
2021
import com.simplito.java.privmx_endpoint.model.events.InboxDeletedEventData;
2122
import com.simplito.java.privmx_endpoint.model.events.InboxEntryDeletedEventData;
2223
import com.simplito.java.privmx_endpoint.model.events.StoreDeletedEventData;
@@ -297,4 +298,21 @@ public static EventType<InboxEntryDeletedEventData> InboxEntryDeletedEvent(Strin
297298
InboxEntryDeletedEventData.class
298299
);
299300
}
300-
}
301+
302+
/**
303+
* Returns instance to register for custom Context Events.
304+
*
305+
* @param contextId ID of the Context to observe
306+
* @param channelName name of the Channel
307+
* @return predefined event type to catch emitted custom Context events
308+
*/
309+
public static EventType<ContextCustomEventData> ContextCustomEvent(String contextId, String channelName) throws NullPointerException {
310+
if (contextId == null) throw new NullPointerException("Context id cannot be null");
311+
if (channelName == null) throw new NullPointerException("Channel name cannot be null");
312+
return new EventType<>(
313+
"context/" + contextId + "/" + channelName,
314+
"contextCustom",
315+
ContextCustomEventData.class
316+
);
317+
}
318+
}

privmx-endpoint-extra/src/main/java/com/simplito/java/privmx_endpoint_extra/lib/BasicPrivmxEndpoint.java

Lines changed: 43 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@
1111

1212
package com.simplito.java.privmx_endpoint_extra.lib;
1313

14+
import com.simplito.java.privmx_endpoint.model.PKIVerificationOptions;
1415
import com.simplito.java.privmx_endpoint.model.exceptions.NativeException;
1516
import com.simplito.java.privmx_endpoint.model.exceptions.PrivmxException;
1617
import com.simplito.java.privmx_endpoint.modules.core.Connection;
1718
import com.simplito.java.privmx_endpoint.modules.crypto.CryptoApi;
19+
import com.simplito.java.privmx_endpoint.modules.event.EventApi;
1820
import com.simplito.java.privmx_endpoint.modules.inbox.InboxApi;
1921
import com.simplito.java.privmx_endpoint.modules.store.StoreApi;
2022
import com.simplito.java.privmx_endpoint.modules.thread.ThreadApi;
@@ -44,6 +46,11 @@ public class BasicPrivmxEndpoint implements AutoCloseable {
4446
*/
4547
public final InboxApi inboxApi;
4648

49+
/**
50+
* Reference to Inbox module.
51+
*/
52+
public final EventApi eventApi;
53+
4754
/**
4855
* Reference to Connection module.
4956
*/
@@ -53,13 +60,14 @@ public class BasicPrivmxEndpoint implements AutoCloseable {
5360
/**
5461
* Initializes modules and connects to PrivMX Bridge server using given parameters.
5562
*
56-
* @param enableModule set of modules to initialize; should contain {@link Modules#THREAD }
57-
* to enable Thread module or {@link Modules#STORE } to enable Store module
58-
* @param bridgeUrl Bridge's Endpoint URL
59-
* @param solutionId {@code SolutionId} of the current project
60-
* @param userPrivateKey user private key used to authorize; generated from:
61-
* {@link CryptoApi#generatePrivateKey} or
62-
* {@link CryptoApi#derivePrivateKey}
63+
* @param enableModule set of modules to initialize; should contain {@link Modules#THREAD }
64+
* to enable Thread module or {@link Modules#STORE } to enable Store module
65+
* @param bridgeUrl Bridge Server URL
66+
* @param solutionId {@code SolutionId} of the current project
67+
* @param userPrivateKey user private key used to authorize; generated from:
68+
* {@link CryptoApi#generatePrivateKey} or
69+
* {@link CryptoApi#derivePrivateKey}
70+
* @param verificationOptions PrivMX Bridge server instance verification options using a PKI server
6371
* @throws IllegalStateException thrown if there is an exception during init modules
6472
* @throws PrivmxException thrown if there is a problem during login
6573
* @throws NativeException thrown if there is an <strong>unknown</strong> problem during login
@@ -68,16 +76,41 @@ public BasicPrivmxEndpoint(
6876
Set<Modules> enableModule,
6977
String userPrivateKey,
7078
String solutionId,
71-
String bridgeUrl
79+
String bridgeUrl,
80+
PKIVerificationOptions verificationOptions
7281
) throws IllegalStateException, PrivmxException, NativeException {
73-
connection = Connection.connect(userPrivateKey, solutionId, bridgeUrl);
82+
connection = Connection.connect(userPrivateKey, solutionId, bridgeUrl, verificationOptions);
7483
storeApi = enableModule.contains(Modules.STORE) ? new StoreApi(connection) : null;
7584
threadApi = enableModule.contains(Modules.THREAD) ? new ThreadApi(connection) : null;
7685
inboxApi = enableModule.contains(Modules.INBOX) ? new InboxApi(
7786
connection,
7887
threadApi,
7988
storeApi
8089
) : null;
90+
eventApi = enableModule.contains(Modules.CUSTOM_EVENT) ? new EventApi(connection) : null;
91+
}
92+
93+
/**
94+
* Initializes modules and connects to PrivMX Bridge server using given parameters.
95+
*
96+
* @param enableModule set of modules to initialize; should contain {@link Modules#THREAD }
97+
* to enable Thread module or {@link Modules#STORE } to enable Store module
98+
* @param bridgeUrl Bridge Server URL
99+
* @param solutionId {@code SolutionId} of the current project
100+
* @param userPrivateKey user private key used to authorize; generated from:
101+
* {@link CryptoApi#generatePrivateKey} or
102+
* {@link CryptoApi#derivePrivateKey}
103+
* @throws IllegalStateException thrown if there is an exception during init modules
104+
* @throws PrivmxException thrown if there is a problem during login
105+
* @throws NativeException thrown if there is an <strong>unknown</strong> problem during login
106+
*/
107+
public BasicPrivmxEndpoint(
108+
Set<Modules> enableModule,
109+
String userPrivateKey,
110+
String solutionId,
111+
String bridgeUrl
112+
) throws IllegalStateException, PrivmxException, NativeException {
113+
this(enableModule, userPrivateKey, solutionId, bridgeUrl, null);
81114
}
82115

83116
/**
@@ -90,6 +123,7 @@ public void close() throws Exception {
90123
if (threadApi != null) threadApi.close();
91124
if (storeApi != null) storeApi.close();
92125
if (inboxApi != null) inboxApi.close();
126+
if (eventApi != null) eventApi.close();
93127
if (connection != null) connection.close();
94128
}
95129
}

0 commit comments

Comments
 (0)