@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)); } } }
private boolean containsSelf(Chat chat) { for (Contact c : chat.getReceivers()) { if (c.getNetworkingId().equals(self.getNetworkingId())) { return true; } } return false; }
@Test public void testShowDataList() throws IOException, NoSuchFieldException, IllegalAccessException { int before = adapter.getItemCount(); chatActivity.showDataList(null); Field field = ChatRecyclerAdapter.class.getDeclaredField("mDataList"); field.setAccessible(true); List<Data> dataList = (List<Data>) field.get(adapter); assertNull(dataList); chatActivity.showDataList(chat.getDataObjects()); dataList = (List<Data>) field.get(adapter); assertTrue(dataList != null); int after = adapter.getItemCount(); assertEquals(before, after); }
@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 inserted(Chat chat) { if (chat.isAdmin(self) && chat.isGroupChat()) { messagingProtocol.sendCreateChat(chat); } }
@Override public void updated(Chat chat) { if (chat.isAdmin(self)) { messagingProtocol.sendUpdateChat(chat); } }