@Override public void receivedDelete(Chat chat, String nid) { Chat localChat = chatHelper.getChat(chat.getNetworkChatID()); if (chat.isAdmin(nid)) { if (localChat != null && localChat.isGroupChat()) { chatHelper.delete(chat); } } else { if (localChat != null && localChat.isGroupChat()) { chatHelper.removeReceiver(chat, contactHelper.getContactByNetworkingID(nid)); } } }
/** * Initialises a new ChatHanlder with the given context and messaging protocol. Also starts * observing the chat model. * * <p>This class needs the network identifier of the current device. If the own network identifier * is not jet set in the model, this method will throw a null pointer exception. * * @param context the current application context * @param messagingProtocol the current messaging protocol */ public ChatHandler(Context context, MessagingProtocol messagingProtocol) { this.context = context; chatHelper = HelperFactory.getChatHelper(context); contactHelper = HelperFactory.getContacHelper(context); chatHelper.addObserver(this); this.messagingProtocol = messagingProtocol; self = HelperFactory.getContacHelper(context).getSelf(); }
@Override public void receivedUpdate(Chat chat) { if (!containsSelf(chat)) { return; } if (!chat.isGroupChat()) { Chat oldChat = chatHelper.getChat(chat.getNetworkChatID()); if (oldChat == null) { Contact self = contactHelper.getSelf(); for (Contact c : chat.getReceivers()) { if (!c.getNetworkingId().equals(self.getNetworkingId())) { chat.setTitle(c.getName(context)); } } } else { chat.setTitle(oldChat.getTitle()); } } chatHelper.update(chat); }
@Override public void receivedInsert(Chat chat) { chatHelper.insert(chat); }