Beispiel #1
0
 public void sendPresenceRequest(String user, String type) {
   // HACK: remove the fake roster entry added by handleIncomingSubscribe()
   if ("unsubscribed".equals(type)) deleteRosterEntryFromDB(user);
   Presence response = new Presence(Presence.Type.valueOf(type));
   response.setTo(user);
   mXMPPConnection.sendPacket(response);
 }
Beispiel #2
0
  /**
   * Check the server connection, reconnect if needed.
   *
   * <p>This function will try to ping the server if we are connected, and try to reestablish a
   * connection otherwise.
   */
  public void sendServerPing() {
    if (mXMPPConnection == null || !mXMPPConnection.isAuthenticated()) {
      debugLog("Ping: requested, but not connected to server.");
      requestConnectionState(ConnectionState.ONLINE, false);
      return;
    }
    if (mPingID != null) {
      debugLog("Ping: requested, but still waiting for " + mPingID);
      return; // a ping is still on its way
    }

    if (mStreamHandler.isSmEnabled()) {
      debugLog("Ping: sending SM request");
      mPingID = "" + mStreamHandler.requestAck();
    } else {
      Ping ping = new Ping();
      ping.setType(Type.GET);
      ping.setTo(mConfig.server);
      mPingID = ping.getPacketID();
      debugLog("Ping: sending ping " + mPingID);
      mXMPPConnection.sendPacket(ping);
    }

    // register ping timeout handler: PACKET_TIMEOUT(30s) + 3s
    registerPongTimeout(PACKET_TIMEOUT + 3000, mPingID);
  }
Beispiel #3
0
  public void setStatusFromConfig() {
    // TODO: only call this when carbons changed, not on every presence change
    CarbonManager.getInstanceFor(mXMPPConnection).sendCarbonsEnabled(mConfig.messageCarbons);

    Presence presence = new Presence(Presence.Type.available);
    Mode mode = Mode.valueOf(mConfig.statusMode);
    presence.setMode(mode);
    presence.setStatus(mConfig.statusMessage);
    presence.setPriority(mConfig.priority);
    mXMPPConnection.sendPacket(presence);
    mConfig.presence_required = false;
  }
Beispiel #4
0
  private void tryToRemoveRosterEntry(String user) throws YaximXMPPException {
    try {
      RosterEntry rosterEntry = mRoster.getEntry(user);

      if (rosterEntry != null) {
        // first, unsubscribe the user
        Presence unsub = new Presence(Presence.Type.unsubscribed);
        unsub.setTo(rosterEntry.getUser());
        mXMPPConnection.sendPacket(unsub);
        // then, remove from roster
        mRoster.removeEntry(rosterEntry);
      }
    } catch (XMPPException e) {
      throw new YaximXMPPException("tryToRemoveRosterEntry", e);
    }
  }
Beispiel #5
0
 public void sendOfflineMessages() {
   Cursor cursor =
       mContentResolver.query(
           ChatProvider.CONTENT_URI, SEND_OFFLINE_PROJECTION, SEND_OFFLINE_SELECTION, null, null);
   final int _ID_COL = cursor.getColumnIndexOrThrow(ChatConstants._ID);
   final int JID_COL = cursor.getColumnIndexOrThrow(ChatConstants.JID);
   final int MSG_COL = cursor.getColumnIndexOrThrow(ChatConstants.MESSAGE);
   final int TS_COL = cursor.getColumnIndexOrThrow(ChatConstants.DATE);
   final int PACKETID_COL = cursor.getColumnIndexOrThrow(ChatConstants.PACKET_ID);
   ContentValues mark_sent = new ContentValues();
   mark_sent.put(ChatConstants.DELIVERY_STATUS, ChatConstants.DS_SENT_OR_READ);
   while (cursor.moveToNext()) {
     int _id = cursor.getInt(_ID_COL);
     String toJID = cursor.getString(JID_COL);
     String message = cursor.getString(MSG_COL);
     String packetID = cursor.getString(PACKETID_COL);
     long ts = cursor.getLong(TS_COL);
     Log.d(TAG, "sendOfflineMessages: " + toJID + " > " + message);
     final Message newMessage = new Message(toJID, Message.Type.chat);
     newMessage.setBody(message);
     DelayInformation delay = new DelayInformation(new Date(ts));
     newMessage.addExtension(delay);
     newMessage.addExtension(new DelayInfo(delay));
     newMessage.addExtension(new DeliveryReceiptRequest());
     if ((packetID != null) && (packetID.length() > 0)) {
       newMessage.setPacketID(packetID);
     } else {
       packetID = newMessage.getPacketID();
       mark_sent.put(ChatConstants.PACKET_ID, packetID);
     }
     Uri rowuri =
         Uri.parse(
             "content://" + ChatProvider.AUTHORITY + "/" + ChatProvider.TABLE_NAME + "/" + _id);
     mContentResolver.update(rowuri, mark_sent, null, null);
     mXMPPConnection.sendPacket(
         newMessage); // must be after marking delivered, otherwise it may override the
     // SendFailListener
   }
   cursor.close();
 }
Beispiel #6
0
 public void sendMessage(String toJID, String message) {
   final Message newMessage = new Message(toJID, Message.Type.chat);
   newMessage.setBody(message);
   newMessage.addExtension(new DeliveryReceiptRequest());
   if (isAuthenticated()) {
     addChatMessageToDB(
         ChatConstants.OUTGOING,
         toJID,
         message,
         ChatConstants.DS_SENT_OR_READ,
         System.currentTimeMillis(),
         newMessage.getPacketID());
     mXMPPConnection.sendPacket(newMessage);
   } else {
     // send offline -> store to DB
     addChatMessageToDB(
         ChatConstants.OUTGOING,
         toJID,
         message,
         ChatConstants.DS_NEW,
         System.currentTimeMillis(),
         newMessage.getPacketID());
   }
 }
Beispiel #7
0
 public void sendReceipt(String toJID, String id) {
   Log.d(TAG, "sending XEP-0184 ack to " + toJID + " id=" + id);
   final Message ack = new Message(toJID, Message.Type.normal);
   ack.addExtension(new DeliveryReceipt(id));
   mXMPPConnection.sendPacket(ack);
 }