Skip to content

Commit 0b9840c

Browse files
MarcinSwierczekBen Moore
authored andcommitted
Merging version 1.0.2 to Master (#6)
* participant finished typing message in a conversation API and event (#4) * foundation - moved foundation specific config to ComapiConfig class, extend Role builder APIs, Sender obj constructor added, APIs adjusted for chat module * Foundation module - added messaging service method queryConversationEvents that fixes list of available events in the response. Messaging service method queryEvents has been deprecated. (cherry picked from commit 07029b4) * Added missing description getter in conversation. * extended public MessageToSend obj API to allow injection of metadata by other modules * added patch profile service API * added eTags to conversation and profile socket events model * moved isPublic conversation to base class * Added new API for getting all conversations, the return type is extended with information about last sent event id, participant count and eTag per conversation. * added event id to message sent response * Added configuration to switch of FCM registration to avoid initialisation error if Firebase not configured. Added tests for patching profile. * Updated Readme.
1 parent 1799b86 commit 0b9840c

Some content is hidden

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

48 files changed

+1534
-165
lines changed

COMAPI/foundation/src/main/java/com/comapi/BaseClient.java

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,8 @@ public abstract class BaseClient<T> implements IClient<T> {
116116
* Initialise ComapiImpl client instance.
117117
*
118118
* @param application Application context.
119-
* @param instance Client instance.
120-
* @param adapter Observables to callbacks adapter.
119+
* @param instance Client instance.
120+
* @param adapter Observables to callbacks adapter.
121121
* @return Observable returning client instance.
122122
*/
123123
<E extends BaseClient> Observable<E> initialise(@NonNull final Application application, @NonNull final E instance, @NonNull final CallbackAdapter adapter) {
@@ -138,7 +138,7 @@ public Observable<SessionData> call(Boolean state) {
138138
}
139139
})
140140
.flatMap(session -> {
141-
if (state.get() == GlobalState.SESSION_ACTIVE) {
141+
if (state.get() == GlobalState.SESSION_ACTIVE && config.isFcmEnabled()) {
142142
return instance.service.updatePushToken()
143143
.doOnNext(sessionComapiResultPair -> log.d("Push token updated"))
144144
.doOnError(throwable -> log.f("Error updating push token", throwable))
@@ -150,12 +150,12 @@ public SessionData call(Throwable throwable) {
150150
}
151151
});
152152
}
153-
return Observable.just(session);
153+
return Observable.fromCallable(() -> session);
154154
})
155155
.map(result -> instance);
156156

157157
} else if (state.get() >= GlobalState.INITIALISED) {
158-
return Observable.just(instance);
158+
return Observable.fromCallable(() -> instance);
159159
} else {
160160
return Observable.error(new ComapiException("Initialise in progress. Shouldn't be called twice. Ignoring."));
161161
}
@@ -165,7 +165,7 @@ public SessionData call(Throwable throwable) {
165165
* Performs basic initialisation.
166166
*
167167
* @param application Application application.
168-
* @param adapter Observables to callbacks adapter.
168+
* @param adapter Observables to callbacks adapter.
169169
* @return Observable emitting True if initialisation ended successfully.
170170
*/
171171
private Observable<Boolean> init(@NonNull final Application application, @NonNull final CallbackAdapter adapter) {
@@ -209,7 +209,14 @@ private Observable<Boolean> init(@NonNull final Application application, @NonNul
209209
//services
210210
service = new InternalService(application, adapter, dataMgr, pushMgr, config.getApiSpaceId(), application.getPackageName(), log);
211211
RestApi restApi = service.initialiseRestClient(logConfig.getNetworkLevel().getValue(), baseURIs);
212-
SessionController sessionController = service.initialiseSessionController(application, new SessionCreateManager(new AtomicBoolean()), pushMgr, state, config.getAuthenticator(), restApi, new Handler(mainLooper), listenerListAdapter);
212+
SessionController sessionController = service.initialiseSessionController(application,
213+
new SessionCreateManager(new AtomicBoolean()),
214+
pushMgr,
215+
state,
216+
config.getAuthenticator(),
217+
restApi, new Handler(mainLooper),
218+
config.isFcmEnabled(),
219+
listenerListAdapter);
213220

214221
//sockets
215222
SocketController socketController = service.initialiseSocketClient(sessionController, listenerListAdapter, baseURIs);

COMAPI/foundation/src/main/java/com/comapi/BaseConfig.java

Lines changed: 21 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,6 @@ public abstract class BaseConfig<T extends BaseConfig<T>> {
4343

4444
protected String apiSpaceId;
4545

46-
protected IStateListener stateListener;
47-
48-
protected IProfileListener profileListener;
49-
5046
protected CallbackAdapter callbackAdapter;
5147

5248
protected int logSizeLimit;
@@ -55,6 +51,8 @@ public abstract class BaseConfig<T extends BaseConfig<T>> {
5551

5652
private PushTokenProvider pushTokenProvider;
5753

54+
protected boolean fcmEnabled = true;
55+
5856
/**
5957
* Gets Comapi ApiSpace identifier.
6058
*
@@ -91,24 +89,6 @@ PushMessageListener getPushMessageListener() {
9189
return pushMessageListener;
9290
}
9391

94-
/**
95-
* Gets listener for SDK state changes.
96-
*
97-
* @return Listener for SDK state changes.
98-
*/
99-
protected IStateListener getStateListener() {
100-
return stateListener;
101-
}
102-
103-
/**
104-
* Gets listener for profile changes.
105-
*
106-
* @return Listener for profile changes.
107-
*/
108-
protected IProfileListener getProfileListener() {
109-
return profileListener;
110-
}
111-
11292
/**
11393
* Gets observables to callbacks adapter.
11494
*
@@ -145,6 +125,15 @@ PushTokenProvider getPushTokenProvider() {
145125
return pushTokenProvider;
146126
}
147127

128+
/**
129+
* Is Firebase Cloud Messaging configuraed and initialised. If yes the SDK will register FCM token on the server.
130+
*
131+
* @return True if Firebase Cloud Messaging is configured and initialised
132+
*/
133+
boolean isFcmEnabled() {
134+
return fcmEnabled;
135+
}
136+
148137
/**
149138
* Sets Comapi App Space identifier.
150139
*
@@ -189,30 +178,6 @@ public T authenticator(ComapiAuthenticator authenticator) {
189178
return getThis();
190179
}
191180

192-
/**
193-
* Sets listener for SDK state changes.
194-
*
195-
* @param stateListener {@link StateListener} callback for state changes.
196-
* @param <E> Extends {@link StateListener}
197-
* @return BaseURIs instance with new value set.
198-
*/
199-
public <E extends StateListener> T stateListener(E stateListener) {
200-
this.stateListener = stateListener;
201-
return getThis();
202-
}
203-
204-
/**
205-
* Sets listener for profile changes.
206-
*
207-
* @param profileListener {@link ProfileListener} callback for profile changes.
208-
* @param <E> Extends {@link ProfileListener}
209-
* @return BaseURIs instance with new value set.
210-
*/
211-
public <E extends ProfileListener> T profileListener(E profileListener) {
212-
this.profileListener = profileListener;
213-
return getThis();
214-
}
215-
216181
/**
217182
* Sets total file size limit for internal logs.
218183
*
@@ -246,6 +211,16 @@ T pushTokenProvider(PushTokenProvider pushTokenProvider) {
246211
return getThis();
247212
}
248213

214+
/**
215+
* Sets if Firebase Cloud Messaging is configured and initialised. If yes the SDK will register FCM token on the server.
216+
*
217+
* @param fcmEnabled True if Firebase Cloud Messaging is configured and initialised
218+
*/
219+
public T fcmEnabled(boolean fcmEnabled) {
220+
this.fcmEnabled = fcmEnabled;
221+
return getThis();
222+
}
223+
249224
/**
250225
* Sets observables to callbacks adapter. By Overriding CallbackAdapter#adapt(Observable, Callback) method you can change
251226
* e.g. the threads on which SDK subscribe to observable when callback APIs version are being called. By default they subscribe on

COMAPI/foundation/src/main/java/com/comapi/ClientHelper.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,9 @@ public static RxComapiService getComapiService(RxComapiClient client) {
6565
public static void resetShared() {
6666
RxComapi.reset();
6767
}
68+
69+
public static void resetChecks() {
70+
Comapi.reset();
71+
RxComapi.reset();
72+
}
6873
}

COMAPI/foundation/src/main/java/com/comapi/ComapiClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
import com.comapi.internal.CallbackAdapter;
2828

2929
/**
30-
* ComapiImpl Client implementation for foundation SDK. Handles initialisation and stores all internal objects.
30+
* Comapi Client implementation for foundation SDK. Handles initialisation and stores all internal objects.
3131
*
3232
* @author Marcin Swierczek
3333
* @since 1.0.0

COMAPI/foundation/src/main/java/com/comapi/ComapiConfig.java

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
package com.comapi;
2222

2323
import com.comapi.internal.IMessagingListener;
24+
import com.comapi.internal.IProfileListener;
25+
import com.comapi.internal.IStateListener;
2426

2527
/**
2628
* Class describing the initial configuration for a {@link ComapiClient} instance.
@@ -32,6 +34,10 @@ public class ComapiConfig extends BaseConfig<ComapiConfig> {
3234

3335
private IMessagingListener messagingListener;
3436

37+
private IStateListener stateListener;
38+
39+
private IProfileListener profileListener;
40+
3541
/**
3642
* Gets Comapi message listener.
3743
*
@@ -41,6 +47,24 @@ IMessagingListener getMessagingListener() {
4147
return messagingListener;
4248
}
4349

50+
/**
51+
* Gets listener for SDK state changes.
52+
*
53+
* @return Listener for SDK state changes.
54+
*/
55+
IStateListener getStateListener() {
56+
return stateListener;
57+
}
58+
59+
/**
60+
* Gets listener for profile changes.
61+
*
62+
* @return Listener for profile changes.
63+
*/
64+
IProfileListener getProfileListener() {
65+
return profileListener;
66+
}
67+
4468
/**
4569
* Sets Comapi message listener.
4670
*
@@ -52,6 +76,30 @@ public <E extends MessagingListener> ComapiConfig messagingListener(E messagingL
5276
return getThis();
5377
}
5478

79+
/**
80+
* Sets listener for SDK state changes.
81+
*
82+
* @param stateListener {@link StateListener} callback for state changes.
83+
* @param <E> Extends {@link StateListener}
84+
* @return BaseURIs instance with new value set.
85+
*/
86+
public <E extends StateListener> ComapiConfig stateListener(E stateListener) {
87+
this.stateListener = stateListener;
88+
return getThis();
89+
}
90+
91+
/**
92+
* Sets listener for profile changes.
93+
*
94+
* @param profileListener {@link ProfileListener} callback for profile changes.
95+
* @param <E> Extends {@link ProfileListener}
96+
* @return BaseURIs instance with new value set.
97+
*/
98+
public <E extends ProfileListener> ComapiConfig profileListener(E profileListener) {
99+
this.profileListener = profileListener;
100+
return getThis();
101+
}
102+
55103
@Override
56104
protected ComapiConfig getThis() {
57105
return this;

COMAPI/foundation/src/main/java/com/comapi/MessagingListener.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import com.comapi.internal.network.model.events.conversation.ParticipantAddedEvent;
2929
import com.comapi.internal.network.model.events.conversation.ParticipantRemovedEvent;
3030
import com.comapi.internal.network.model.events.conversation.ParticipantTypingEvent;
31+
import com.comapi.internal.network.model.events.conversation.ParticipantTypingOffEvent;
3132
import com.comapi.internal.network.model.events.conversation.ParticipantUpdatedEvent;
3233
import com.comapi.internal.network.model.events.conversation.message.MessageDeliveredEvent;
3334
import com.comapi.internal.network.model.events.conversation.message.MessageReadEvent;
@@ -118,4 +119,10 @@ public void onConversationUndeleted(ConversationUndeleteEvent event) {}
118119
*/
119120
public void onParticipantIsTyping(ParticipantTypingEvent event) {}
120121

122+
/**
123+
* Dispatch participant stopped typing event.
124+
*
125+
* @param event Event to dispatch.
126+
*/
127+
public void onParticipantTypingOff(ParticipantTypingOffEvent event) {}
121128
}

COMAPI/foundation/src/main/java/com/comapi/RxComapiClient.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public class RxComapiClient extends BaseClient<RxServiceAccessor> {
4444
*
4545
* @param config ComapiImpl configuration.
4646
*/
47-
RxComapiClient(final ComapiConfig config) {
47+
protected RxComapiClient(final ComapiConfig config) {
4848
super(config);
4949
}
5050

@@ -106,7 +106,7 @@ public void clean(@NonNull Context context) {
106106
*
107107
* @return Internal logger.
108108
*/
109-
Logger getLogger() {
109+
protected Logger getLogger() {
110110
return super.getLogger();
111111
}
112112

@@ -119,7 +119,7 @@ void addLifecycleListener(LifecycleListener listener) {
119119
super.addLifecycleListener(listener);
120120
}
121121

122-
RxComapiService getComapiService() {
122+
protected RxComapiService getComapiService() {
123123
return service;
124124
}
125125
}

0 commit comments

Comments
 (0)