Skip to content

Commit a750ee9

Browse files
Merge pull request #630 from Kommunicate-io/development
Release v2.14.1
2 parents b50ca2d + 8d5ee6b commit a750ee9

File tree

11 files changed

+220
-14
lines changed

11 files changed

+220
-14
lines changed

kommunicate/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ android {
1818
compileSdk 34
1919
targetSdkVersion 35
2020
versionCode 1
21-
versionName "2.14.0"
21+
versionName "2.14.1"
2222
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
2323
buildConfigField "String", "KOMMUNICATE_VERSION", "\"" + versionName + "\""
2424
buildConfigField "String", "CHAT_SERVER_URL", '"https://chat.kommunicate.io"'

kommunicate/src/main/java/io/kommunicate/database/DatabaseMigrationHelper.kt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,14 @@ import kotlin.Throws
1111
object DatabaseMigrationHelper {
1212
private const val TEMP_ENCRYPTED_DB_NAME = "temp_encrypted.db"
1313

14+
// Check if table exists in destination DB
15+
private fun tableExists(db: SQLiteDatabase, tableName: String): Boolean {
16+
return db.rawQuery(
17+
"SELECT 1 FROM sqlite_master WHERE type='table' AND name=? LIMIT 1",
18+
arrayOf(tableName)
19+
).use { cursor -> cursor.moveToFirst() }
20+
}
21+
1422
@JvmStatic
1523
@Throws(Exception::class)
1624
fun migrateDatabase(context: Context, dbName: String) {
@@ -83,6 +91,12 @@ object DatabaseMigrationHelper {
8391
continue
8492
}
8593

94+
// Verifies if table exist
95+
if (tableExists(destinationDb, tableName)) {
96+
println("Table $tableName already exists in destination DB, skipping creation.")
97+
continue
98+
}
99+
86100
// Copy table schema
87101
val createTableSql = getTableCreateSql(sourceDb, tableName)
88102
destinationDb.execSQL(createTableSql)

kommunicate/src/main/java/io/kommunicate/devkit/api/conversation/MobiComMessageService.java

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,8 @@ public synchronized void syncMessages() {
265265
boolean syncChannel = false;
266266
boolean syncChannelForMetadata = false;
267267
boolean syncGroupOfTwoForBlockList = false;
268+
Set<String> syncChannelKeys = new HashSet<>();
269+
Set<String> syncChannelForMetadataKeys = new HashSet<>();
268270

269271
Utils.printLog(context, TAG, "Starting syncMessages for lastSyncTime: " + userpref.getLastSyncTime());
270272
SyncMessageFeed syncMessageFeed = messageClientService.getMessageFeed(userpref.getLastSyncTime(), false);
@@ -291,9 +293,9 @@ public synchronized void syncMessages() {
291293
for (int i = messageList.size() - 1; i >= 0; i--) {
292294
if (Message.ContentType.CHANNEL_CUSTOM_MESSAGE.getValue().equals(messageList.get(i).getContentType())) {
293295
if (messageList.get(i).isGroupMetaDataUpdated()) {
294-
syncChannelForMetadata = true;
296+
syncChannelForMetadataKeys.add(messageList.get(i).getClientGroupId());
295297
} else if (channelLastSyncTime == 0L || messageList.get(i).getCreatedAtTime() > channelLastSyncTime) {
296-
syncChannel = true;
298+
syncChannelKeys.add(messageList.get(i).getClientGroupId());
297299
}
298300
//Todo: fix this, what if there are mulitple messages.
299301
ChannelService.isUpdateTitle = true;
@@ -305,6 +307,16 @@ public synchronized void syncMessages() {
305307
MobiComUserPreference.getInstance(context).setLastInboxSyncTime(messageList.get(i).getCreatedAtTime());
306308
}
307309

310+
syncChannelKeys.removeAll(syncChannelForMetadataKeys);
311+
312+
for (String channelkey : syncChannelKeys) {
313+
ChannelService.getInstance(context).syncInfoChannels(false, channelkey);
314+
}
315+
316+
for (String channelkey : syncChannelForMetadataKeys) {
317+
ChannelService.getInstance(context).syncInfoChannels(true, channelkey);
318+
}
319+
308320
if (syncChannel) {
309321
ChannelService.getInstance(context).syncChannels(false);
310322
}
@@ -459,9 +471,9 @@ public synchronized void processInstantMessage(Message message) {
459471
Long channelLastSyncTime = Long.parseLong(MobiComUserPreference.getInstance(context).getChannelSyncTime());
460472
if (Message.ContentType.CHANNEL_CUSTOM_MESSAGE.getValue().equals(message.getContentType())) {
461473
if (message.isGroupMetaDataUpdated()) {
462-
ChannelService.getInstance(context).syncChannels(true);
474+
ChannelService.getInstance(context).syncInfoChannels(true, message.getClientGroupId());
463475
} else if (channelLastSyncTime == 0L || message.getCreatedAtTime() > channelLastSyncTime) {
464-
ChannelService.getInstance(context).syncChannels(false);
476+
ChannelService.getInstance(context).syncInfoChannels(false, message.getClientGroupId());
465477
}
466478
}
467479
Channel channel = ChannelService.getInstance(context).getChannelInfo(message.getGroupId());

kommunicate/src/main/java/io/kommunicate/devkit/channel/service/ChannelClientService.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import java.util.List;
2727
import java.util.Set;
2828

29+
import io.kommunicate.devkit.sync.SyncChannelInfoFeed;
2930
import io.kommunicate.models.InQueueData;
3031

3132
/**
@@ -35,6 +36,7 @@ public class ChannelClientService extends MobiComKitClientService {
3536
private static final String CHANNEL_INFO_URL = "/rest/ws/group/info";
3637
// private static final String CHANNEL_SYNC_URL = "/rest/ws/group/list";
3738
private static final String CHANNEL_SYNC_URL = "/rest/ws/group/v5/list";
39+
private static final String CHANNEL_INFO_SYNC_URL = "/rest/ws/group/v2/info";
3840
private static final String CREATE_CHANNEL_URL = "/rest/ws/group/v2.1/create";
3941
private static final String IN_QUEUE_MESSAGE_URL = "/rest/ws/group/waiting/list?teamId=";
4042
private static final String CREATE_MULTIPLE_CHANNEL_URL = "/rest/ws/group/create/multiple";
@@ -94,6 +96,10 @@ public String getChannelSyncUrl() {
9496
return getBaseUrl() + CHANNEL_SYNC_URL;
9597
}
9698

99+
public String getSingleChannelInfoSyncUrl() {
100+
return getBaseUrl() + CHANNEL_INFO_SYNC_URL;
101+
}
102+
97103
public String getCreateChannelUrl() {
98104
return getBaseUrl() + CREATE_CHANNEL_URL;
99105
}
@@ -235,6 +241,25 @@ public SyncChannelFeed getChannelFeed(String lastChannelSyncTime) {
235241
}
236242
}
237243

244+
public SyncChannelInfoFeed getSingleChannelFeed(String channelKey) {
245+
if (TextUtils.isEmpty(channelKey)) {
246+
Utils.printLog(context, TAG, "Channel key is empty or null");
247+
return null;
248+
}
249+
String url = getSingleChannelInfoSyncUrl() + "?" +
250+
GROUP_ID
251+
+ "=" + channelKey;
252+
try {
253+
String response = httpRequestUtils.getResponse(url, appli_json,
254+
appli_json);
255+
Utils.printLog(context, TAG, "Channel Info sync call response for channelKey " + channelKey + " : " + response);
256+
return (SyncChannelInfoFeed) GsonUtils.getObjectFromJson(response, SyncChannelInfoFeed.class);
257+
} catch (Exception e) {
258+
Utils.printLog(context, TAG, "Error getting channel info: " + e.getMessage());
259+
return null;
260+
}
261+
}
262+
238263
@Deprecated
239264
public ChannelFeed createChannel(ChannelInfo channelInfo) {
240265
ChannelFeed channelFeed = null;

kommunicate/src/main/java/io/kommunicate/devkit/channel/service/ChannelService.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import io.kommunicate.commons.people.channel.Channel;
3333
import io.kommunicate.commons.people.channel.ChannelUserMapper;
3434
import io.kommunicate.commons.task.CoreTask;
35+
import io.kommunicate.devkit.sync.SyncChannelInfoFeed;
3536

3637
import java.util.ArrayList;
3738
import java.util.HashSet;
@@ -265,6 +266,27 @@ public synchronized void syncChannels(boolean isMetadataUpdate) {
265266
}
266267
}
267268

269+
public synchronized void syncInfoChannels(boolean isMetadataUpdate, String channelKey) {
270+
try {
271+
final MobiComUserPreference userpref = MobiComUserPreference.getInstance(context);
272+
SyncChannelInfoFeed syncChannelFeed = channelClientService.getSingleChannelFeed(channelKey);
273+
if (syncChannelFeed == null || !syncChannelFeed.isSuccess()) {
274+
return;
275+
}
276+
277+
if (syncChannelFeed.getResponse() != null) {
278+
processChannelFeedForSync(syncChannelFeed.getResponse());
279+
BroadcastService.sendUpdate(context, isMetadataUpdate, BroadcastService
280+
.INTENT_ACTIONS.CHANNEL_SYNC.toString());
281+
}
282+
if(!TextUtils.isEmpty(syncChannelFeed.getGeneratedAt())) {
283+
userpref.setChannelSyncTime(syncChannelFeed.getGeneratedAt());
284+
}
285+
} catch (Exception e) {
286+
e.printStackTrace();
287+
}
288+
}
289+
268290
public synchronized void syncChannels() {
269291
syncChannels(false);
270292
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package io.kommunicate.devkit.sync;
2+
3+
import io.kommunicate.commons.json.JsonMarker;
4+
import io.kommunicate.devkit.feed.ChannelFeed;
5+
6+
public class SyncChannelInfoFeed extends JsonMarker {
7+
8+
private static final String SUCCESS = "success";
9+
10+
private String status;
11+
private String generatedAt;
12+
private ChannelFeed response; // Changed from groupPxys to ChannelFeed
13+
14+
public String getStatus() {
15+
return status;
16+
}
17+
18+
public void setStatus(String status) {
19+
this.status = status;
20+
}
21+
22+
public String getGeneratedAt() {
23+
return generatedAt;
24+
}
25+
26+
public void setGeneratedAt(String generatedAt) {
27+
this.generatedAt = generatedAt;
28+
}
29+
30+
public ChannelFeed getResponse() {
31+
return response;
32+
}
33+
34+
public void setResponse(ChannelFeed response) {
35+
this.response = response;
36+
}
37+
38+
public boolean isSuccess() {
39+
return SUCCESS.equals(status);
40+
}
41+
42+
@Override
43+
public String toString() {
44+
return "SyncChannelInfoFeed{" +
45+
"status='" + status + '\'' +
46+
", generatedAt='" + generatedAt + '\'' +
47+
", response=" + response +
48+
'}';
49+
}
50+
}

kommunicate/src/main/java/io/kommunicate/utils/KmUtils.kt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,9 @@ object KmUtils {
5858
&& !isDebuggable)
5959
&& (MobiComUserPreference.getInstance(context).pricingPackage == PackageType.STARTUP.value
6060
|| MobiComUserPreference.getInstance(context).pricingPackage == PackageType.START_MONTHLY.value
61-
|| MobiComUserPreference.getInstance(context).pricingPackage == PackageType.START_YEARLY.value)
61+
|| MobiComUserPreference.getInstance(context).pricingPackage == PackageType.START_YEARLY.value
62+
|| MobiComUserPreference.getInstance(context).pricingPackage == PackageType.TRIAL_ACCOUNT.value
63+
|| MobiComUserPreference.getInstance(context).pricingPackage == PackageType.CHURNED_ACCOUNT.value)
6264
if (customToolbarLayout != null) {
6365
customToolbarLayout.visibility = View.GONE
6466
}
@@ -256,6 +258,8 @@ object KmUtils {
256258
EARLY_BIRD_MONTHLY(107),
257259
EARLY_BIRD_YEARLY(108),
258260
START_MONTHLY(112),
259-
START_YEARLY(113)
261+
START_YEARLY(113),
262+
TRIAL_ACCOUNT(111),
263+
CHURNED_ACCOUNT(100),
260264
}
261265
}

kommunicateui/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ android {
1616
targetSdkVersion 35
1717
minSdkVersion 21
1818
versionCode 1
19-
versionName "2.14.0"
19+
versionName "2.14.1"
2020
buildToolsVersion = '34.0.0'
2121
consumerProguardFiles 'proguard-rules.txt'
2222
vectorDrawables.useSupportLibrary = true

kommunicateui/src/main/java/io/kommunicate/ui/conversation/activity/ConversationActivity.java

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@
123123

124124
import io.kommunicate.async.KmSyncMessageTask;
125125
import io.kommunicate.usecase.AutoSuggestionsUseCase;
126+
import io.kommunicate.utils.KmAppSettingPreferences;
126127
import io.kommunicate.utils.KmConstants;
127128
import io.kommunicate.utils.KmUtils;
128129
import io.sentry.Hint;
@@ -362,6 +363,31 @@ public boolean onSupportNavigateUp() {
362363
return false;
363364
}
364365

366+
private void showDisconnectionMessage() {
367+
serviceDisconnectionLayout.setVisibility(View.VISIBLE);
368+
369+
// Hide all messages initially
370+
findViewById(R.id.trialUserMessage).setVisibility(View.GONE);
371+
findViewById(R.id.mobileNotSupportedInPlan).setVisibility(View.GONE);
372+
findViewById(R.id.churnedAccountID).setVisibility(View.GONE);
373+
374+
String subscriptionDetails = KmAppSettingPreferences.getCurrentSubscriptionDetails();
375+
if (subscriptionDetails == null) {
376+
findViewById(R.id.mobileNotSupportedInPlan).setVisibility(View.VISIBLE);
377+
return;
378+
}
379+
380+
String lowerCaseSub = subscriptionDetails.toLowerCase();
381+
382+
if (lowerCaseSub.contains("trial")) {
383+
findViewById(R.id.trialUserMessage).setVisibility(View.VISIBLE);
384+
} else if (lowerCaseSub.contains("churn")) {
385+
findViewById(R.id.churnedAccountID).setVisibility(View.VISIBLE);
386+
} else {
387+
findViewById(R.id.mobileNotSupportedInPlan).setVisibility(View.VISIBLE);
388+
}
389+
}
390+
365391
@Override
366392
protected void onCreate(Bundle savedInstanceState) {
367393
super.onCreate(savedInstanceState);
@@ -403,6 +429,9 @@ protected void onCreate(Bundle savedInstanceState) {
403429
childFragmentLayout = (RelativeLayout) findViewById(R.id.layout_child_activity);
404430
contactsGroupId = MobiComUserPreference.getInstance(this).getContactsGroupId();
405431
serviceDisconnectionLayout = findViewById(R.id.serviceDisconnectionLayout);
432+
TextView mobileNotSupportedInPlanMessage = findViewById(R.id.mobileNotSupportedInPlan);
433+
TextView trialUserMessage = findViewById(R.id.trialUserMessage);
434+
TextView churnedAccountIDMessage = findViewById(R.id.churnedAccountID);
406435
deviceRootedLayout = findViewById(R.id.deviceRootedLayout);
407436
if (Utils.hasMarshmallow() && !customizationSettings.isGlobalStoragePermissionDisabled()) {
408437
applozicPermission.checkRuntimePermissionForStorage();
@@ -414,7 +443,7 @@ protected void onCreate(Bundle savedInstanceState) {
414443
retry = 0;
415444

416445
if (KmUtils.isServiceDisconnected(this, customizationSettings != null && customizationSettings.isAgentApp(), customToolbarLayout)) {
417-
serviceDisconnectionLayout.setVisibility(View.VISIBLE);
446+
showDisconnectionMessage();
418447
} else if(KmUtils.isDeviceRooted()) {
419448
deviceRootedLayout.setVisibility(View.VISIBLE);
420449
} else {
@@ -587,7 +616,7 @@ protected void onNewIntent(Intent intent) {
587616

588617
try {
589618
if (KmUtils.isServiceDisconnected(this, customizationSettings != null && customizationSettings.isAgentApp(), customToolbarLayout)) {
590-
serviceDisconnectionLayout.setVisibility(View.VISIBLE);
619+
showDisconnectionMessage();
591620
} else {
592621
if (intent.getExtras() != null) {
593622
if (intent.getExtras().getBoolean(SENT_FROM_NOTIFICATION)) {

kommunicateui/src/main/res/layout/km_service_disconnection_layout.xml

Lines changed: 51 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@
3232
android:layout_gravity="center_horizontal"
3333
android:layout_marginTop="7dp" />
3434

35+
<!-- Message 1 -->
3536
<TextView
37+
android:id="@+id/trialUserMessage"
3638
android:layout_width="wrap_content"
3739
android:layout_height="wrap_content"
3840
android:layout_gravity="center_horizontal"
@@ -45,9 +47,55 @@
4547
android:letterSpacing="0.06"
4648
android:lineSpacingExtra="7sp"
4749
android:minLines="3"
48-
android:text="@string/account_disconnection_message"
50+
android:text="@string/trial_user_disconnection_message"
4951
android:gravity="center"
5052
android:textColor="@color/km_service_disconnection_text_color"
5153
android:textSize="14sp"
52-
android:textStyle="normal" />
53-
</LinearLayout>
54+
android:textStyle="normal"
55+
android:visibility="gone" />
56+
57+
<!-- Message 2 -->
58+
<TextView
59+
android:id="@+id/mobileNotSupportedInPlan"
60+
android:layout_width="wrap_content"
61+
android:layout_height="wrap_content"
62+
android:layout_gravity="center_horizontal"
63+
android:layout_marginLeft="39dp"
64+
android:layout_marginStart="39dp"
65+
android:layout_marginEnd="40dp"
66+
android:layout_marginRight="40dp"
67+
android:layout_marginTop="10dp"
68+
android:fontFamily="sans-serif"
69+
android:letterSpacing="0.06"
70+
android:lineSpacingExtra="7sp"
71+
android:minLines="3"
72+
android:text="@string/mobile_not_supported_message"
73+
android:gravity="center"
74+
android:textColor="@color/km_service_disconnection_text_color"
75+
android:textSize="14sp"
76+
android:textStyle="normal"
77+
android:visibility="gone" />
78+
79+
<!-- Message 3 -->
80+
<TextView
81+
android:id="@+id/churnedAccountID"
82+
android:layout_width="wrap_content"
83+
android:layout_height="wrap_content"
84+
android:layout_gravity="center_horizontal"
85+
android:layout_marginLeft="39dp"
86+
android:layout_marginStart="39dp"
87+
android:layout_marginEnd="40dp"
88+
android:layout_marginRight="40dp"
89+
android:layout_marginTop="10dp"
90+
android:fontFamily="sans-serif"
91+
android:letterSpacing="0.06"
92+
android:lineSpacingExtra="7sp"
93+
android:minLines="3"
94+
android:text="@string/churned_user_disconnection_message"
95+
android:gravity="center"
96+
android:textColor="@color/km_service_disconnection_text_color"
97+
android:textSize="14sp"
98+
android:textStyle="normal"
99+
android:visibility="gone" />
100+
101+
</LinearLayout>

0 commit comments

Comments
 (0)