2

I have been able to create the if statement that checks for the string and it returns the toast message that i created but it keeps showing the toast message every time i open the chat. even if the most recent message doesn't contain the string I am looking for so i am assume it isn't checking to see if it is the last message received and it doesn't check to see if it is unread. the code is below. the reason i am trying to do this is because my parents share a facebook account and i want an easy way to display if the message is signed mom or dad. the code below only has the check for mom once it works i will be adding the check for dad signature. I am using the open source message client Xabber. Thank you for help.

  public void setVisibleChat(String account, String user) {
    final boolean remove = !AccountManager.getInstance()
            .getArchiveMode(account).saveLocally();
    AbstractChat chat = getChat(account, user);
    if (chat == null)
        chat = createChat(account, user);
    else {
        // Mark messages as read and them delete from db if necessary.
        final ArrayList<MessageItem> messageItems = new ArrayList<MessageItem>();
        for (MessageItem messageItem : chat.getMessages()) {
                if (!messageItem.isRead()) {
                messageItem.markAsRead();
                messageItems.add(messageItem);
            }

            if (chat.getLastText().contains("Mom") && (!messageItem.isRead()));{
                Toast.makeText(Application.getInstance(), "Message from Mom!", Toast.LENGTH_SHORT).show();
            }

        }
        Application.getInstance().runInBackground(new Runnable() {
            @Override
            public void run() {
                Collection<Long> ids = getMessageIds(messageItems, remove);
                if (remove)
                    MessageTable.getInstance().removeMessages(ids);
                else
                    MessageTable.getInstance().markAsRead(ids);
            }
        });
    }
    visibleChat = chat;
}
  • Hi, I am also trying to get the same Read status of MessageItem in android xabber. but messageItem.isRead() always returning true even when receiver didn't opened the message. can you suggest me if you have any idea about this issue – Raj Apr 21 '15 at 15:17
  • @Raj you should probably post your code so people in this community have a better understanding of what could possibly be going wrong. I stopped working in this project a while ago after my parents got smart phones and they setup individual FB accounts so i didnt have the need anymore. I believe I had it working almost perfectly at the time but dont have the code anymore. Post the code and I will do my best to help you. – user3561802 Apr 22 '15 at 21:25
  • Hi, I have updated the exact issue with code snippets as a separate Question. Below is the url. http://stackoverflow.com/questions/29776948/issue-with-android-xabbar-message-read-status – Raj Apr 23 '15 at 05:22

1 Answers1

1

You've got an extra semi-colon here

if (chat.getLastText().contains("Mom") && (!messageItem.isRead())); <------

So your next block of code containing the Toast show statement will always be executed.

Remove the semi-colon

Andrew Fielden
  • 3,751
  • 3
  • 31
  • 47
  • Thank you for the prompt response. unfortunatly now the toast doesnt come up at all i am guessing i need to change what the if statement is checking. if (chat.getLastText() must not be the right. – user3561802 Apr 22 '14 at 21:09
  • No problem. You can run the app in debug mode, and set a breakpoint in the code. This will allow you to step through and pinpoint the cause of your problem. If my answer has helped you, please at least upvote it. If it helped you solve the problem, please accept it. Thanks – Andrew Fielden Apr 22 '14 at 21:11
  • this did work partially it is still not checking to see if the message is unread. But it is better then it was. i cant up vote i don't have enough rep. again thank you so much. just have to work on the && statement. – user3561802 Apr 22 '14 at 21:25
  • Hi, I am also trying to get the same Read status of MessageItem in android xabber. but messageItem.isRead() always returning true even when receiver didn't opened the message. can you suggest me if you have any idea about this issue – Raj Apr 21 '15 at 15:17