Skip to content

Commit

Permalink
Merge pull request #442 from Kommunicate-io/CM-1239
Browse files Browse the repository at this point in the history
[CM-1239] Fixed typing indicator appearing after welcome message was received
  • Loading branch information
pranaysaini04 authored Nov 2, 2023
2 parents ca4175e + 1f240c7 commit 2325c41
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 17 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ The changelog for [Kommunicate-Android-Chat-SDK](https://github.com/Kommunicate-
[releases](https://github.com/Kommunicate-io/Kommunicate-Android-Chat-SDK/releases) on Github.

## Unreleased
1) Added configuration for form submit button in hidePostCTA

1) Fixed typing indicator appearing after welcome message was received
## Kommunicate Android SDK 2.8.4
1) Reduce time taken for conversation creation
## Kommunicate Android SDK 2.8.3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1632,6 +1632,38 @@ public void updateMessageMetadata(String keyString) {
}

public void addMessage(final Message message) {

String senderId = message.getTo();
boolean isSentMessage = message.getType().equals(Message.MessageType.MT_OUTBOX.getValue());

if(messageList.isEmpty() && !isSentMessage) {
boolean sentByBot = senderId != null && Objects.equals(new ContactDatabase(getContext()).getContactById(senderId).getRoleType(), User.RoleType.BOT.getValue());
if (sentByBot){
return;
}
}

hideAwayMessage(message);
if(messageList.contains(message)) {
updateMessage(message);
}
if (ApplozicService.getContext(getContext()) instanceof KmOnMessageListener) {
((KmOnMessageListener) ApplozicService.getContext(getContext())).onNewMessage(message, channel, contact);
}

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);
return;
}
}

handleAddMessage(message);
}

public void addMessageForNewConversation(final Message message) {

hideAwayMessage(message);
if(messageList.contains(message)) {
updateMessage(message);
Expand Down Expand Up @@ -1953,23 +1985,23 @@ public void fetchBotTypeAndToggleCharLimitExceededMessage() {
}

public void loadConversation(Channel channel, Integer conversationId) {
loadConversation(null, channel, conversationId, messageSearchString);
loadConversation(null, channel, conversationId, messageSearchString, false);
}

public void loadConversation(Contact contact, Integer conversationId) {
loadConversation(contact, null, conversationId, messageSearchString);
loadConversation(contact, null, conversationId, messageSearchString, false);
}

//With search
public void loadConversation(Contact contact, Integer conversationId, String messageSearchString) {
loadConversation(contact, null, conversationId, messageSearchString);
loadConversation(contact, null, conversationId, messageSearchString, false);
}

public void loadConversation(Channel channel, Integer conversationId, String messageSearchString) {
loadConversation(null, channel, conversationId, messageSearchString);
loadConversation(null, channel, conversationId, messageSearchString, false);
}

public void loadConversation(final Contact contact, final Channel channel, final Integer conversationId, final String searchString) {
public void loadConversation(final Contact contact, final Channel channel, final Integer conversationId, final String searchString, boolean isNewConversation) {
if (downloadConversation != null) {
downloadConversation.cancel(true);
}
Expand Down Expand Up @@ -2077,7 +2109,7 @@ public void checkPermission(KmStoragePermission storagePermission) {
processMobiTexterUserCheck();


downloadConversation = new DownloadConversation(recyclerView, true, 1, 0, 0, contact, channel, conversationId, messageSearchString);
downloadConversation = new DownloadConversation(recyclerView, true, 1, 0, 0, contact, channel, conversationId, messageSearchString, isNewConversation);
downloadConversation.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);

if (hideExtendedSendingOptionLayout) {
Expand Down Expand Up @@ -2646,7 +2678,7 @@ public void forwardMessage(Message messageToForward, Contact contact, Channel ch
filePath = messageToForward.getFilePaths().get(0);
}
this.messageToForward = messageToForward;
loadConversation(contact, channel, currentConversationId, null);
loadConversation(contact, channel, currentConversationId, null, false);

}

Expand Down Expand Up @@ -3295,8 +3327,11 @@ public void onResume() {
SyncCallService.refreshView = false;
}

boolean isNewConversation = false;

if (channel != null && !channel.isUserPresentInChannel(MobiComUserPreference
.getInstance(getContext()).getUserId())) {
isNewConversation = true;
Channel newChannel = ChannelService.getInstance(getActivity()).getChannelByChannelKey(channel.getKey());
if (newChannel != null && newChannel.getType() != null && Channel.GroupType.OPEN.getValue().equals(newChannel.getType())) {
MobiComUserPreference.getInstance(getActivity()).setNewMessageFlag(true);
Expand All @@ -3308,7 +3343,7 @@ public void onResume() {
}

if (messageList.isEmpty()) {
loadConversation(contact, channel, currentConversationId, messageSearchString);
loadConversation(contact, channel, currentConversationId, messageSearchString, isNewConversation);
} else if (MobiComUserPreference.getInstance(getActivity()).getNewMessageFlag()) {
loadnewMessageOnResume(contact, channel, currentConversationId);
}
Expand Down Expand Up @@ -3429,9 +3464,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 @@ -3962,6 +3999,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 All @@ -3973,6 +4011,17 @@ public DownloadConversation(RecyclerView recyclerView, boolean initial, int firs
this.messageSearchString = messageSearchString;
}

public DownloadConversation(RecyclerView recyclerView, boolean initial, int firstVisibleItem, int amountVisible, int totalItems, Contact contact, Channel channel, Integer conversationId, String messageSearchString, boolean isNewConversation) {
this.recyclerView = recyclerView;
this.initial = initial;
this.firstVisibleItem = firstVisibleItem;
this.contact = contact;
this.channel = channel;
this.conversationId = conversationId;
this.messageSearchString = messageSearchString;
this.isNewConversation = isNewConversation;
}

@Override
protected void onPreExecute() {
super.onPreExecute();
Expand Down Expand Up @@ -4122,16 +4171,29 @@ 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) {
for (Message message : nextMessageList) {
if (initial && !messageList.contains(message) && !TextUtils.isEmpty(message.getKeyString())) {
addMessageForNewConversation(message);
}
}
} else {
for (Message message : nextMessageList) {
if (initial && !messageList.contains(message)) {
messageList.add(message);
}
selfDestructMessage(message);
}
selfDestructMessage(message);
}

if (initial) {
recyclerDetailConversationAdapter.searchString = searchString;
emptyTextView.setVisibility(messageList.isEmpty() ? VISIBLE : View.GONE);
emptyTextView.setVisibility(!messageList.isEmpty() || (assignee != null && Objects.equals(assignee.getRoleType(), User.RoleType.BOT.getValue())) ? GONE : VISIBLE);
if(messageList.isEmpty()) {
linearLayoutManager.setStackFromEnd(false);

Expand Down

0 comments on commit 2325c41

Please sign in to comment.