mirror of
https://github.com/ChronosX88/Influence.git
synced 2024-11-23 10:02:18 +00:00
Made unread messages counting
This commit is contained in:
parent
88c061da45
commit
ba2fbc2d0e
@ -84,4 +84,8 @@ public class LocalDBWrapper {
|
|||||||
long messageID = dbInstance.messageDao().getLastMessageByChatID(chatID);
|
long messageID = dbInstance.messageDao().getLastMessageByChatID(chatID);
|
||||||
return getMessageByID(messageID);
|
return getMessageByID(messageID);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void updateChatUnreadMessagesCount(String chatID, int unreadMessagesCount) {
|
||||||
|
dbInstance.chatDao().updateUnreadMessagesCount(chatID, unreadMessagesCount);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -33,12 +33,15 @@ public class NetworkHandler implements IncomingChatMessageListener {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void newIncomingMessage(EntityBareJid from, Message message, Chat chat) {
|
public void newIncomingMessage(EntityBareJid from, Message message, Chat chat) {
|
||||||
|
String chatID = chat.getXmppAddressOfChatPartner().asUnescapedString();
|
||||||
if(LocalDBWrapper.getChatByChatID(from.asEntityBareJidString()) == null) {
|
if(LocalDBWrapper.getChatByChatID(from.asEntityBareJidString()) == null) {
|
||||||
LocalDBWrapper.createChatEntry(chat.getXmppAddressOfChatPartner().asUnescapedString(), chat.getXmppAddressOfChatPartner().asBareJid().asUnescapedString());
|
LocalDBWrapper.createChatEntry(chatID, chat.getXmppAddressOfChatPartner().asBareJid().asUnescapedString());
|
||||||
}
|
}
|
||||||
long messageID = LocalDBWrapper.createMessageEntry(chat.getXmppAddressOfChatPartner().asUnescapedString(), from.asUnescapedString(), TrueTime.now().getTime(), message.getBody(), true, false);
|
long messageID = LocalDBWrapper.createMessageEntry(chatID, from.asUnescapedString(), TrueTime.now().getTime(), message.getBody(), true, false);
|
||||||
|
int newUnreadMessagesCount = LocalDBWrapper.getChatByChatID(chatID).unreadMessagesCount + 1;
|
||||||
|
LocalDBWrapper.updateChatUnreadMessagesCount(chatID, newUnreadMessagesCount);
|
||||||
|
|
||||||
EventBus.getDefault().post(new NewMessageEvent(chat.getXmppAddressOfChatPartner().toString(), messageID));
|
EventBus.getDefault().post(new NewMessageEvent(chatID, messageID));
|
||||||
EventBus.getDefault().post(new LastMessageEvent(chat.getXmppAddressOfChatPartner().toString(), new GenericMessage(LocalDBWrapper.getMessageByID(messageID))));
|
EventBus.getDefault().post(new LastMessageEvent(chatID, new GenericMessage(LocalDBWrapper.getMessageByID(messageID))));
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -33,12 +33,10 @@ import io.github.chronosx88.influence.models.roomEntities.MessageEntity;
|
|||||||
public class ChatLogic implements CoreContracts.IChatLogicContract {
|
public class ChatLogic implements CoreContracts.IChatLogicContract {
|
||||||
private String chatID;
|
private String chatID;
|
||||||
private ChatEntity chatEntity;
|
private ChatEntity chatEntity;
|
||||||
//private KeyPairManager keyPairManager;
|
|
||||||
|
|
||||||
public ChatLogic(ChatEntity chatEntity) {
|
public ChatLogic(ChatEntity chatEntity) {
|
||||||
this.chatEntity = chatEntity;
|
this.chatEntity = chatEntity;
|
||||||
this.chatID = chatEntity.jid;
|
this.chatID = chatEntity.jid;
|
||||||
//this.keyPairManager = new KeyPairManager();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -75,4 +75,8 @@ public class GenericDialog implements IDialog {
|
|||||||
public int getUnreadCount() {
|
public int getUnreadCount() {
|
||||||
return unreadMessagesCount;
|
return unreadMessagesCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setUnreadMessagesCount(int unreadMessagesCount) {
|
||||||
|
this.unreadMessagesCount = unreadMessagesCount;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -44,4 +44,7 @@ public interface ChatDao {
|
|||||||
|
|
||||||
@Query("DELETE FROM chats")
|
@Query("DELETE FROM chats")
|
||||||
void clearChats();
|
void clearChats();
|
||||||
|
|
||||||
|
@Query("UPDATE chats SET unreadMessagesCount = :unreadMessagesCount WHERE jid = :chatID")
|
||||||
|
void updateUnreadMessagesCount(String chatID, int unreadMessagesCount);
|
||||||
}
|
}
|
||||||
|
@ -74,7 +74,7 @@ class ChatPresenter(private val view: CoreContracts.IChatViewContract, private v
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onDestroy() {
|
override fun onDestroy() {
|
||||||
//
|
EventBus.getDefault().unregister(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||||
@ -82,6 +82,7 @@ class ChatPresenter(private val view: CoreContracts.IChatViewContract, private v
|
|||||||
if(event.chatID.equals(chatEntity!!.jid)) {
|
if(event.chatID.equals(chatEntity!!.jid)) {
|
||||||
val messageID = event.messageID
|
val messageID = event.messageID
|
||||||
chatAdapter.addToStart(GenericMessage(LocalDBWrapper.getMessageByID(messageID)), true)
|
chatAdapter.addToStart(GenericMessage(LocalDBWrapper.getMessageByID(messageID)), true)
|
||||||
|
LocalDBWrapper.updateChatUnreadMessagesCount(chatEntity.jid, 0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,27 +17,17 @@
|
|||||||
package io.github.chronosx88.influence.presenters;
|
package io.github.chronosx88.influence.presenters;
|
||||||
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.graphics.Bitmap;
|
|
||||||
import android.graphics.BitmapFactory;
|
|
||||||
|
|
||||||
import androidx.appcompat.app.AlertDialog;
|
import androidx.appcompat.app.AlertDialog;
|
||||||
|
|
||||||
import com.amulyakhare.textdrawable.TextDrawable;
|
|
||||||
import com.amulyakhare.textdrawable.util.ColorGenerator;
|
|
||||||
import com.stfalcon.chatkit.dialogs.DialogsListAdapter;
|
import com.stfalcon.chatkit.dialogs.DialogsListAdapter;
|
||||||
|
|
||||||
import org.greenrobot.eventbus.EventBus;
|
import org.greenrobot.eventbus.EventBus;
|
||||||
import org.greenrobot.eventbus.Subscribe;
|
import org.greenrobot.eventbus.Subscribe;
|
||||||
import org.greenrobot.eventbus.ThreadMode;
|
import org.greenrobot.eventbus.ThreadMode;
|
||||||
import org.jivesoftware.smack.roster.RosterEntry;
|
|
||||||
import org.jxmpp.jid.EntityBareJid;
|
|
||||||
import org.jxmpp.jid.impl.JidCreate;
|
|
||||||
import org.jxmpp.stringprep.XmppStringprepException;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.Set;
|
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
import io.github.chronosx88.influence.R;
|
import io.github.chronosx88.influence.R;
|
||||||
@ -115,6 +105,8 @@ public class DialogListPresenter implements CoreContracts.IDialogListPresenterCo
|
|||||||
intent.putExtra("chatName", LocalDBWrapper.getChatByChatID(chatID).chatName);
|
intent.putExtra("chatName", LocalDBWrapper.getChatByChatID(chatID).chatName);
|
||||||
intent.putExtra("chatAvatar", AppHelper.avatarsCache.get(chatID));
|
intent.putExtra("chatAvatar", AppHelper.avatarsCache.get(chatID));
|
||||||
view.startActivity(intent);
|
view.startActivity(intent);
|
||||||
|
setUnreadMessagesCount(chatID, 0);
|
||||||
|
LocalDBWrapper.updateChatUnreadMessagesCount(chatID, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
@ -161,6 +153,17 @@ public class DialogListPresenter implements CoreContracts.IDialogListPresenterCo
|
|||||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||||
public void onLastMessage(LastMessageEvent event) {
|
public void onLastMessage(LastMessageEvent event) {
|
||||||
dialogListAdapter.updateDialogWithMessage(event.chatID, event.message);
|
dialogListAdapter.updateDialogWithMessage(event.chatID, event.message);
|
||||||
|
GenericDialog dialog = new GenericDialog(LocalDBWrapper.getChatByChatID(event.chatID));
|
||||||
|
dialog.setLastMessage(event.message);
|
||||||
|
dialogListAdapter.updateItemById(dialog);
|
||||||
dialogListAdapter.sort(dialogComparator);
|
dialogListAdapter.sort(dialogComparator);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void setUnreadMessagesCount(String chatID, int unreadMessagesCount) {
|
||||||
|
GenericDialog dialog = dialogListAdapter.getItemById(chatID);
|
||||||
|
if(dialog != null) {
|
||||||
|
dialog.setUnreadMessagesCount(unreadMessagesCount);
|
||||||
|
dialogListAdapter.updateItemById(dialog);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -84,6 +84,7 @@ class ChatActivity : AppCompatActivity(), CoreContracts.IChatViewContract {
|
|||||||
override fun onDestroy() {
|
override fun onDestroy() {
|
||||||
super.onDestroy()
|
super.onDestroy()
|
||||||
presenter!!.onDestroy()
|
presenter!!.onDestroy()
|
||||||
|
presenter = null
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun setAdapter(adapter: MessagesListAdapter<GenericMessage>) {
|
override fun setAdapter(adapter: MessagesListAdapter<GenericMessage>) {
|
||||||
|
Loading…
Reference in New Issue
Block a user