Ejemplo n.º 1
0
    @Override
    public void processMessage(Chat chat, org.jivesoftware.smack.packet.Message message) {

      if (message.getBody() == null) {
        // TODO: investigate why some message bodies are null
        return;
      }

      // TODO: implement builder pattern for domain Message and Chat classes
      final Message m = new Message();
      m.setTimestamp(System.currentTimeMillis());
      m.setBody(message.getBody());
      m.setLocal(false);

      Log.d(
          TAG,
          String.format(
              "chatId %s message <%s> received from %s",
              currentChatId, m.getBody(), chat.getParticipant()));

      updateChatTimestamp(pocChat.getId());

      ContentValues values = new ContentValues();
      values.put(SQLiteHelper.COLUMN_BODY, m.getBody());
      values.put(SQLiteHelper.COLUMN_TIMESTAMP, m.getTimestamp()); // current time
      values.put(SQLiteHelper.COLUMN_IS_LOCAL, m.isLocal() ? 1 : 0);
      values.put(SQLiteHelper.COLUMN_CHAT_ID, pocChat.getId());

      // once insert is successful, loader updates the list automatically
      context.getContentResolver().insert(MessageProvider.URI_MESSAGES, values);

      // show the toast regardless if messages UI is opened
      showToast(context, m.getBody());
    }
Ejemplo n.º 2
0
 private void fireNewChatState(Chat chat, ChatState chatstate)
 {
     Iterator iterator = chat.getListeners().iterator();
     do
     {
         if (!iterator.hasNext())
         {
             break;
         }
         ChatMessageListener chatmessagelistener = (ChatMessageListener)iterator.next();
         if (chatmessagelistener instanceof ChatStateListener)
         {
             ((ChatStateListener)chatmessagelistener).stateChanged(chat, chatstate);
         }
     } while (true);
 }
Ejemplo n.º 3
0
 public void chatCreated(Chat chat, boolean flag)
 {
     chat.addMessageListener(this);
 }
Ejemplo n.º 4
0
 @Override
 public void chatCreated(Chat chat, boolean isLocal) {
   chat.addMessageListener(this);
 }