Skip to content

Commit

Permalink
Merge pull request #458 from Kommunicate-io/CM-1756
Browse files Browse the repository at this point in the history
[CM-1756] Fixed typing indicator and you have no conversation showing for the first time
  • Loading branch information
pranaysaini04 authored Dec 18, 2023
2 parents 0933f67 + 85763a5 commit 815a169
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 27 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
The changelog for [Kommunicate-Android-Chat-SDK](https://github.com/Kommunicate-io/Kommunicate-Android-Chat-SDK). Also see the
[releases](https://github.com/Kommunicate-io/Kommunicate-Android-Chat-SDK/releases) on Github.

## Unreleased
1) Fixed typing indicator for welcome message
2) Fixed "no conversations" showing sometimes for the first time when conversation is created
## Kommunicate Android SDK 2.8.8
1) Fixed crash while deleting message on agent app
## Kommunicate Android SDK 2.8.7
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,10 +188,6 @@ public Contact addMTMessage(Message message, int index) {
message.setHidden(true);
}

if (!TextUtils.isEmpty(message.getKeyString()) && messageDatabaseService.isMessagePresent(message.getKeyString())){
return receiverContact;
}

messageDatabaseService.createMessage(message);

//Check if we are........container is already opened...don't send broadcast
Expand Down Expand Up @@ -503,6 +499,7 @@ public synchronized void processFirebaseMessages(Message messageToProcess) {
}
if (message.getType().equals(Message.MessageType.MT_INBOX.getValue())) {
addMTMessage(message, 0);
MobiComUserPreference.getInstance(context).setLastSyncTime(String.valueOf(message.getCreatedAtTime()));
}
if(baseContactService.isContactPresent(message.getContactIds())) {
Contact contact = baseContactService.getContactById(message.getContactIds());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,11 @@ public long createMessage(final Message message) {
if (message.getMessageId() != null) {
return message.getMessageId();
}
id = createSingleMessage(message);
if (isMessagePresent(message.getKeyString())) {
id = getMessage(message.getKeyString()).getMessageId();
} else {
id = createSingleMessage(message);
}
message.setMessageId(id);
if (message.isSentToMany()) {
String[] toList = message.getTo().trim().replace("undefined,", "").split(",");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ protected void onResume() {
}

protected void syncMessages() {
new KmSyncMessageTask(this, true).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
new KmSyncMessageTask(this, false).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,7 @@ public abstract class MobiComConversationFragment extends Fragment implements Vi
protected boolean isApiAutoSuggest = false;
protected Map<String, String> autoSuggestHeaders;
protected String autoSuggestUrl;
private Set<Message> botDelayMessageList;
public void setEmojiIconHandler(EmojiconHandler emojiIconHandler) {
this.emojiIconHandler = emojiIconHandler;
}
Expand Down Expand Up @@ -1643,7 +1644,14 @@ public void addMessage(final Message message) {
if (botMessageDelayInterval > 0 && message.getGroupId() != null && message.getGroupId() != 0 && !TextUtils.isEmpty(message.getTo())) {
Contact contact = appContactService.getContactById(message.getTo());
if (contact != null && User.RoleType.BOT.getValue().equals(contact.getRoleType())) {
botTypingDelayManager.addMessage(message);
if (botDelayMessageList == null || !botDelayMessageList.contains(message)){
if (botDelayMessageList == null){
botDelayMessageList = new HashSet<>();
}
botDelayMessageList.add(message);
botTypingDelayManager.addMessage(message);
emptyTextView.setVisibility(GONE);
}
return;
}
}
Expand Down Expand Up @@ -3436,9 +3444,11 @@ else if (!alCustomizationSettings.isAgentApp() && channel != null && channel.get
toolbarTitleText.setText(channel.getName());
}

setStatusDots(false, true); //setting the status dot as offline
if (toolbarSubtitleText != null) {
toolbarSubtitleText.setVisibility(View.GONE);
if(alCustomizationSettings.isAgentApp()){
setStatusDots(false, true); //setting the status dot as offline
if (toolbarSubtitleText != null) {
toolbarSubtitleText.setVisibility(View.GONE);
}
}
}

Expand Down Expand Up @@ -3958,7 +3968,7 @@ public String getMessageType(Message lastMessage) {
return type;
}

public class DownloadConversation extends AsyncTask<Void, Integer, Long> {
public class DownloadConversation extends AsyncTask<Void, Integer, Long> implements KmBotTypingDelayManager.MessageDispatcher {

private RecyclerView recyclerView;
private int firstVisibleItem;
Expand All @@ -3969,6 +3979,7 @@ public class DownloadConversation extends AsyncTask<Void, Integer, Long> {
private List<Conversation> conversationList;
private String messageSearchString;
private List<Message> nextMessageList = new ArrayList<Message>();
private boolean isNewConversation;

public DownloadConversation(RecyclerView recyclerView, boolean initial, int firstVisibleItem, int amountVisible, int totalItems, Contact contact, Channel channel, Integer conversationId, String messageSearchString) {
this.recyclerView = recyclerView;
Expand Down Expand Up @@ -4044,6 +4055,7 @@ protected Long doInBackground(Void... voids) {


nextMessageList = conversationService.getMessages(lastConversationloadTime + 1L, null, contact, channel, conversationId, false, !TextUtils.isEmpty(messageSearchString));
isNewConversation = isNewConversation(nextMessageList);
} else if (firstVisibleItem == 1 && loadMore && !messageList.isEmpty()) {
loadMore = false;
Long endTime = null;
Expand All @@ -4055,6 +4067,7 @@ protected Long doInBackground(Void... voids) {
break;
}
nextMessageList = conversationService.getMessages(null, endTime, contact, channel, conversationId, false, !TextUtils.isEmpty(messageSearchString));
isNewConversation = isNewConversation(nextMessageList);
}
if (BroadcastService.isContextBasedChatEnabled()) {
conversations = ConversationService.getInstance(getActivity()).getConversationList(channel, contact);
Expand Down Expand Up @@ -4111,6 +4124,16 @@ protected Long doInBackground(Void... voids) {
return 0L;
}

private boolean isNewConversation(List<Message> nextMessageList) {
if (nextMessageList.size() == 0){
return false;
}
long createdTimeInMilliSec = nextMessageList.get(0).getCreatedAtTime();
long currentTimeInMilliSec = System.currentTimeMillis();
long diff = currentTimeInMilliSec - createdTimeInMilliSec;
return diff < 5000;
}

@Override
protected void onPostExecute(Long result) {
super.onPostExecute(result);
Expand All @@ -4129,31 +4152,57 @@ protected void onPostExecute(Long result) {
nextMessageList.remove(nextMessageList.size() - 1);
}

for (Message message : nextMessageList) {
if (initial && !messageList.contains(message)) {
messageList.add(message);
Contact assignee = new ContactDatabase(getContext()).getContactById(channel.getConversationAssignee());

if (isNewConversation && assignee != null && assignee.getRoleType().equals(User.RoleType.BOT.getValue()) && botMessageDelayInterval > 0) {
KmBotTypingDelayManager kmBotTypingDelayManager = new KmBotTypingDelayManager(getContext(), this);
handleTypingMessage(false);
for (Message message : nextMessageList) {
if (initial && !messageList.contains(message)) {
if (TextUtils.isEmpty(message.getKeyString())){
messageList.add(0,message);
selfDestructMessage(message);
setupConversationScreen();
handleTypingMessage(true);
} else if (botDelayMessageList == null || !botDelayMessageList.contains(message)){
if (botDelayMessageList == null){
botDelayMessageList = new HashSet<>();
}
botDelayMessageList.add(message);
kmBotTypingDelayManager.addMessage(message);
}
}
}
selfDestructMessage(message);
} else {
for (Message message : nextMessageList) {
if (initial && !messageList.contains(message)) {
messageList.add(message);
}
selfDestructMessage(message);
}
setupConversationScreen();
}
}

private void setupConversationScreen() {
if (initial) {
recyclerDetailConversationAdapter.searchString = searchString;
emptyTextView.setVisibility(messageList.isEmpty() ? VISIBLE : View.GONE);
emptyTextView.setVisibility(messageList.isEmpty() && (botDelayMessageList == null || botDelayMessageList.isEmpty()) ? VISIBLE : View.GONE);
if(messageList.isEmpty()) {
linearLayoutManager.setStackFromEnd(false);

} else if (!messageList.isEmpty()) {
if (!TextUtils.isEmpty(searchString)) {
int height = recyclerView.getHeight();
int itemHeight = recyclerView.getChildAt(0).getHeight();
recyclerView.requestFocusFromTouch();
recyclerView.scrollTo(scrollToFirstSearchIndex() + 1, height / 2 - itemHeight / 2);
} else {
if(!recyclerView.canScrollVertically(1) || !recyclerView.canScrollVertically(-1)) {
linearLayoutManager.setStackFromEnd(false);
}
linearLayoutManager.scrollToPositionWithOffset(messageList.size() - 1, 0);
}
if (!TextUtils.isEmpty(searchString)) {
int height = recyclerView.getHeight();
int itemHeight = recyclerView.getChildAt(0).getHeight();
recyclerView.requestFocusFromTouch();
recyclerView.scrollTo(scrollToFirstSearchIndex() + 1, height / 2 - itemHeight / 2);
} else {
if(!recyclerView.canScrollVertically(1) || !recyclerView.canScrollVertically(-1)) {
linearLayoutManager.setStackFromEnd(false);
}
linearLayoutManager.scrollToPositionWithOffset(messageList.size() - 1, 0);
}
}
} else if (!nextMessageList.isEmpty()) {
messageList.addAll(0, nextMessageList);
Expand Down Expand Up @@ -4254,6 +4303,16 @@ public void run() {
checkForAutoSuggestions();
checkForCustomInput();
}

@Override
public void onMessageQueued(Message message) {
updateTypingStatus(message.getTo(),true);
}

@Override
public void onMessageDispatched(Message message) {
handleAddMessage(message);
}
}

public void checkForAutoSuggestions() {
Expand Down

0 comments on commit 815a169

Please sign in to comment.