@Override public void sendMessage(final FriendMessage message) { HashMap<String, Friend> friends = AccountManager.getInstance().getFriends(); Friend friend = friends.get(message.getTo()); Screenname buddy = new Screenname(friend.getUserName()); Conversation c = (Conversation) friend.getUserInfo(); if (c == null) { c = connection.getIcbmService().getImConversation(buddy); friend.setUserInfo(c); } Message oscarMessage = new Message() { public boolean isAutoResponse() { return false; } public String getMessageBody() { return message.getMessage(); } }; c.sendMessage(oscarMessage); Friend recipient = friends.get(message.getTo()); accountListener.didReceiveMessageForFriend(message, recipient); }
private void removeUnused() { Conversation[] cons = getArray(); for (int i = 0; i < cons.length; i++) { Conversation c = cons[i]; if (!c.isUsed()) { removeConversation(c.getRmt_ip(), c.getLcl_port(), c.getRmt_port()); } } }
public void readIn(DataInputStream din) throws IOException { Iterator it = allConversations.iterator(); while (it.hasNext()) { Conversation conv = (Conversation) it.next(); conv.setUsed(false); } int count = din.readInt(); for (int i = 0; i < count; i++) { readConv.readIn(din); Conversation existing = findConversation(readConv.getRmt_ip(), readConv.getLcl_port(), readConv.getRmt_port()); existing.setUsed(true); existing.setInfo(readConv); } removeUnused(); }
private void gc() { if (gcTime == -1) { return; } long curTime = System.currentTimeMillis(); if ((curTime - lastTime) > gcTime) { int collected = 0; lastTime = curTime; Conversation[] cons = getArray(); for (int i = 0; i < cons.length; i++) { Conversation c = cons[i]; long l = c.getLastActive(); if ((curTime - l) > convTime) { collected++; removeConversation(c.getRmt_ip(), c.getLcl_port(), c.getRmt_port()); } } } }