示例#1
0
    @Override
    public synchronized void onTransferProgress(
        boolean outgoing, String offerId, String from, String url, float percentF) {

      int percent = (int) (100 * percentF);

      String[] path = url.split("/");
      String sanitizedPath = SystemServices.sanitize(path[path.length - 1]);

      try {
        final int N = mRemoteListeners.beginBroadcast();
        for (int i = 0; i < N; i++) {
          IChatListener listener = mRemoteListeners.getBroadcastItem(i);
          try {
            listener.onIncomingFileTransferProgress(sanitizedPath, percent);
          } catch (RemoteException e) {
            // The RemoteCallbackList will take care of removing the
            // dead listeners.
          }
        }
      } catch (Exception e) {
        Log.e(ImApp.LOG_TAG, "error broadcasting progress", e);
      } finally {
        mRemoteListeners.finishBroadcast();
      }
    }
示例#2
0
    public synchronized boolean onIncomingMessage(
        ChatSession ses, final org.awesomeapp.messenger.model.Message msg) {
      String body = msg.getBody();
      String username = msg.getFrom().getAddress();
      String bareUsername = msg.getFrom().getBareAddress();
      String nickname = getNickName(username);
      long time = msg.getDateTime().getTime();

      if (msg.getID() != null && Imps.messageExists(mContentResolver, msg.getID())) {
        return false; // this message is a duplicate
      }

      insertOrUpdateChat(body);

      boolean wasMessageSeen = false;

      if (msg.getID() == null) insertMessageInDb(nickname, body, time, msg.getType());
      else insertMessageInDb(nickname, body, time, msg.getType(), 0, msg.getID());

      int N = mRemoteListeners.beginBroadcast();
      for (int i = 0; i < N; i++) {
        IChatListener listener = mRemoteListeners.getBroadcastItem(i);
        try {
          boolean wasSeen = listener.onIncomingMessage(ChatSessionAdapter.this, msg);

          if (wasSeen) wasMessageSeen = wasSeen;

        } catch (RemoteException e) {
          // The RemoteCallbackList will take care of removing the
          // dead listeners.
        }
      }
      mRemoteListeners.finishBroadcast();

      // Due to the move to fragments, we could have listeners for ChatViews that are not visible on
      // the screen.
      // This is for fragments adjacent to the current one.  Therefore we can't use the existence of
      // listeners
      // as a filter on notifications.
      if (!wasMessageSeen) {
        // reinstated body display here in the notification; perhaps add preferences to turn that
        // off
        mStatusBarNotifier.notifyChat(
            mConnection.getProviderId(),
            mConnection.getAccountId(),
            getId(),
            bareUsername,
            nickname,
            body,
            false);
      }

      mHasUnreadMessages = true;
      return true;
    }
示例#3
0
    @Override
    public synchronized boolean onTransferRequested(
        String offerId, String from, String to, String transferUrl) {

      mAcceptTransfer = false;
      mWaitingForResponse = true;
      mLastFileUrl = transferUrl;

      if (mAcceptAllTransfer) {
        mAcceptTransfer = true;
        mWaitingForResponse = false;
        mLastTransferFrom = from;
        mLastTransferUrl = transferUrl;

        mDataHandler.acceptTransfer(mLastFileUrl, from);
      } else {
        try {
          final int N = mRemoteListeners.beginBroadcast();

          if (N > 0) {
            for (int i = 0; i < N; i++) {
              IChatListener listener = mRemoteListeners.getBroadcastItem(i);
              try {
                listener.onIncomingFileTransfer(from, transferUrl);
              } catch (RemoteException e) {
                // The RemoteCallbackList will take care of removing the
                // dead listeners.
              }
            }
          } else {
            mLastTransferFrom = from;
            mLastTransferUrl = transferUrl;
            String nickname = getNickName(from);

            // reinstated body display here in the notification; perhaps add preferences to turn
            // that off
            mStatusBarNotifier.notifyChat(
                mConnection.getProviderId(),
                mConnection.getAccountId(),
                getId(),
                from,
                nickname,
                "Incoming file request",
                false);
          }
        } finally {
          mRemoteListeners.finishBroadcast();
        }

        mAcceptTransfer = false; // for now, wait for the user callback
      }

      return mAcceptTransfer;
    }
示例#4
0
 public void notifyChatSessionConverted() {
   final int N = mRemoteListeners.beginBroadcast();
   for (int i = 0; i < N; i++) {
     IChatListener listener = mRemoteListeners.getBroadcastItem(i);
     try {
       listener.onConvertedToGroupChat(ChatSessionAdapter.this);
     } catch (RemoteException e) {
       // The RemoteCallbackList will take care of removing the
       // dead listeners.
     }
   }
   mRemoteListeners.finishBroadcast();
 }
示例#5
0
 public void onError(ChatGroup group, final ImErrorInfo error) {
   // TODO: insert an error message?
   final int N = mRemoteListeners.beginBroadcast();
   for (int i = 0; i < N; i++) {
     IChatListener listener = mRemoteListeners.getBroadcastItem(i);
     try {
       listener.onInviteError(ChatSessionAdapter.this, error);
     } catch (RemoteException e) {
       // The RemoteCallbackList will take care of removing the
       // dead listeners.
     }
   }
   mRemoteListeners.finishBroadcast();
 }
示例#6
0
  public void setContactTyping(Contact contact, boolean isTyping) {

    int N = mRemoteListeners.beginBroadcast();
    for (int i = 0; i < N; i++) {
      IChatListener listener = mRemoteListeners.getBroadcastItem(i);
      try {
        listener.onContactTyping(ChatSessionAdapter.this, contact, isTyping);
      } catch (RemoteException e) {
        // The RemoteCallbackList will take care of removing the
        // dead listeners.
      }
    }
    mRemoteListeners.finishBroadcast();
  }
示例#7
0
    public void onMemberLeft(ChatGroup group, final Contact contact) {
      deleteGroupMemberInDb(contact);

      final int N = mRemoteListeners.beginBroadcast();
      for (int i = 0; i < N; i++) {
        IChatListener listener = mRemoteListeners.getBroadcastItem(i);
        try {
          listener.onContactLeft(ChatSessionAdapter.this, contact);
        } catch (RemoteException e) {
          // The RemoteCallbackList will take care of removing the
          // dead listeners.
        }
      }
      mRemoteListeners.finishBroadcast();
    }
示例#8
0
    @Override
    public void onIncomingReceipt(ChatSession ses, String id) {
      Imps.updateConfirmInDb(mContentResolver, mContactId, id, true);

      synchronized (mRemoteListeners) {
        int N = mRemoteListeners.beginBroadcast();
        for (int i = 0; i < N; i++) {
          IChatListener listener = mRemoteListeners.getBroadcastItem(i);
          try {
            listener.onIncomingReceipt(ChatSessionAdapter.this, id);
          } catch (RemoteException e) {
            // The RemoteCallbackList will take care of removing the
            // dead listeners.
          }
        }
        mRemoteListeners.finishBroadcast();
      }
    }
示例#9
0
    public void onSendMessageError(
        ChatSession ses,
        final org.awesomeapp.messenger.model.Message msg,
        final ImErrorInfo error) {
      insertMessageInDb(
          null, null, System.currentTimeMillis(), Imps.MessageType.OUTGOING, error.getCode(), null);

      final int N = mRemoteListeners.beginBroadcast();
      for (int i = 0; i < N; i++) {
        IChatListener listener = mRemoteListeners.getBroadcastItem(i);
        try {
          listener.onSendMessageError(ChatSessionAdapter.this, msg, error);
        } catch (RemoteException e) {
          // The RemoteCallbackList will take care of removing the
          // dead listeners.
        }
      }
      mRemoteListeners.finishBroadcast();
    }
示例#10
0
    @Override
    public synchronized void onTransferFailed(
        boolean outgoing, String offerId, String from, String url, String reason) {

      String[] path = url.split("/");
      String sanitizedPath = SystemServices.sanitize(path[path.length - 1]);

      final int N = mRemoteListeners.beginBroadcast();
      for (int i = 0; i < N; i++) {
        IChatListener listener = mRemoteListeners.getBroadcastItem(i);
        try {
          listener.onIncomingFileTransferError(sanitizedPath, reason);
        } catch (RemoteException e) {
          // The RemoteCallbackList will take care of removing the
          // dead listeners.
        }
      }
      mRemoteListeners.finishBroadcast();
    }
示例#11
0
    @Override
    public void onStatusChanged(ChatSession session, SessionStatus status) {
      final int N = mRemoteListeners.beginBroadcast();
      for (int i = 0; i < N; i++) {
        IChatListener listener = mRemoteListeners.getBroadcastItem(i);
        try {
          listener.onStatusChanged(ChatSessionAdapter.this);
        } catch (RemoteException e) {
          // The RemoteCallbackList will take care of removing the
          // dead listeners.   // TODO Auto-generated method stub
        }
      }
      mRemoteListeners.finishBroadcast();
      mDataHandler.onOtrStatusChanged(status);

      if (status == SessionStatus.ENCRYPTED) {
        sendPostponedMessages();
      }

      mLastSessionStatus = status;
    }
示例#12
0
    @Override
    public void onTransferComplete(
        boolean outgoing,
        String offerId,
        String from,
        String url,
        String mimeType,
        String filePath) {

      try {

        if (outgoing) {
          Imps.updateConfirmInDb(service.getContentResolver(), mContactId, offerId, true);
        } else {

          try {
            boolean isVerified = getDefaultOtrChatSession().isKeyVerified(from);

            int type =
                isVerified
                    ? Imps.MessageType.INCOMING_ENCRYPTED_VERIFIED
                    : Imps.MessageType.INCOMING_ENCRYPTED;

            insertOrUpdateChat(filePath);

            Uri messageUri =
                Imps.insertMessageInDb(
                    service.getContentResolver(),
                    mIsGroupChat,
                    getId(),
                    true,
                    from,
                    filePath,
                    System.currentTimeMillis(),
                    type,
                    0,
                    offerId,
                    mimeType);

            int percent = (int) (100);

            String[] path = url.split("/");
            String sanitizedPath = SystemServices.sanitize(path[path.length - 1]);

            final int N = mRemoteListeners.beginBroadcast();
            for (int i = 0; i < N; i++) {
              IChatListener listener = mRemoteListeners.getBroadcastItem(i);
              try {
                listener.onIncomingFileTransferProgress(sanitizedPath, percent);
              } catch (RemoteException e) {
                // The RemoteCallbackList will take care of removing the
                // dead listeners.
              }
            }
            mRemoteListeners.finishBroadcast();

            if (N == 0) {
              String nickname = getNickName(from);

              mStatusBarNotifier.notifyChat(
                  mConnection.getProviderId(),
                  mConnection.getAccountId(),
                  getId(),
                  from,
                  nickname,
                  service.getString(R.string.file_notify_text, mimeType, nickname),
                  false);
            }
          } catch (Exception e) {
            Log.e(ImApp.LOG_TAG, "Error updating file transfer progress", e);
          }
        }

        /**
         * if (mimeType != null && mimeType.startsWith("audio")) { MediaPlayer mp = new
         * MediaPlayer(); try { mp.setDataSource(file.getCanonicalPath());
         *
         * <p>mp.prepare(); mp.start();
         *
         * <p>} catch (IOException e) { // TODO Auto-generated catch block //e.printStackTrace(); }
         * }
         */
      } catch (Exception e) {
        //   mHandler.showAlert(service.getString(R.string.error_chat_file_transfer_title),
        // service.getString(R.string.error_chat_file_transfer_body));
        OtrDebugLogger.log("error reading file", e);
      }
    }