/** @param packet */
 public void processPacket(Packet packet) {
   PresenceIndicator.getDefault()
       .label
       .setText(
           KenaiUser.getOnlineUserCount() > 0
               ? KenaiUser.getOnlineUserCount() - 1 + ""
               : ""); // NOI18N
   PresenceIndicator.getDefault()
       .label
       .setToolTipText(
           NbBundle.getMessage(
               PresenceIndicator.class,
               "LBL_LoggedIn_Tooltip",
               KenaiUser.getOnlineUserCount() > 0 ? KenaiUser.getOnlineUserCount() - 1 : ""));
   for (MultiUserChat muc :
       KenaiConnection.getDefault(
               KenaiConnection.getKenai(StringUtils.parseBareAddress(packet.getFrom())))
           .getChats()) {
     String chatName = StringUtils.parseName(muc.getRoom());
     assert chatName != null : "muc.getRoom() = " + muc.getRoom(); // NOI18N
     ChatNotifications.getDefault()
         .getMessagingHandle(KenaiConnection.getKenaiProject(muc))
         .setOnlineCount(muc.getOccupantsCount());
   }
 }
Beispiel #2
0
  /**
   * leaves the muc and deletes its record from the db
   *
   * @param muc
   */
  private void leaveRoom(MultiUserChat muc) throws SmackException.NotConnectedException {
    mMucHelper.deleteMUC(muc.getRoom());
    if (muc.isJoined()) {
      muc.leave();
    }

    // Remove the room if mRooms contains it
    if (mRooms.size() > 0) {
      Integer i = getRoomInt(muc.getRoom());
      String number = mMucHelper.getNumber(muc.getRoom());
      mRoomNumbers.remove(i);
      mRooms.remove(number);
    }
  }
Beispiel #3
0
 private void registerRoom(
     MultiUserChat muc, String number, String name, Integer randomInt, int mode) {
   MUCPacketListener chatListener = new MUCPacketListener(number, muc, name, mode, mCtx);
   muc.addMessageListener(chatListener);
   mRoomNumbers.add(randomInt);
   mRooms.put(number, muc);
   mMucHelper.addMUC(muc.getRoom(), number, mode);
 }
Beispiel #4
0
 /**
  * Returns the MultiUserChat given in room name, which is a full JID (e.g.
  * [email protected]), if the room is in your internal data structure. Otherwise null
  * will be returned
  *
  * @param roomName - the full room name as JID
  * @return the room or null
  */
 public MultiUserChat getRoomViaRoomName(String roomName) {
   Collection<MultiUserChat> mucSet = mRooms.values();
   for (MultiUserChat muc : mucSet) {
     if (muc.getRoom().equals(roomName)) {
       return muc;
     }
   }
   return null;
 }
Beispiel #5
0
 /**
  * Constructor.
  *
  * @param chat The chat to adapt
  */
 public ChatMUCAdapter(final MultiUserChat chat, final BeemService service, String nick) {
   mAdaptee = chat;
   mParticipant = new Contact(chat.getRoom(), true);
   mMessages = new LinkedList<Message>();
   mAdaptee.addMessageListener(mMsgListener);
   mNick = nick;
   mService = service;
   // Join the MUC
   try {
     chat.join(nick);
   } catch (XMPPException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   }
 }
Beispiel #6
0
 /**
  * Writes a formatted message to a room and creates the room if necessary, followed by an invite
  * to the default notification address to join the room
  *
  * @param number
  * @param contact
  * @param message
  * @throws XMPPException
  */
 public void writeRoom(String number, String contact, XmppMsg message, int mode) throws Exception {
   MultiUserChat muc;
   muc = inviteRoom(number, contact, mode);
   if (muc != null) {
     try {
       Message msg = new Message(muc.getRoom());
       msg.setBody(message.generateFmtTxt());
       if (mode == MODE_SHELL) {
         XHTMLManager.addBody(msg, message.generateXHTMLText().toString());
       }
       msg.setType(Message.Type.groupchat);
       muc.sendMessage(msg);
     } catch (Exception e) {
       muc.sendMessage(message.generateTxt());
     }
   }
 }
Beispiel #7
0
    private void rejoinRooms() {
      String[][] mucDB = mMucHelper.getAllMUC();
      if (mucDB == null) {
        return;
      }

      for (String[] aMucDB : mucDB) {
        if (!mConnection.isAuthenticated()) {
          return;
        }

        Log.i(
            "Trying to reconnect to the room with parameters: Muc="
                + aMucDB[0]
                + ", Number="
                + aMucDB[1]
                + ", Mode="
                + aMucDB[2]);

        RoomInfo info = getRoomInfo(aMucDB[0]);
        // if info is not null, the room exists on the server, so lets check if we can reuse it
        if (info != null) {
          MultiUserChat muc = new MultiUserChat(mConnection, aMucDB[0]);
          int mode = Integer.parseInt(aMucDB[2]);
          // Hardcoded room name for shell
          String name =
              mode == MODE_SMS
                  ? ContactsManager.getContactName(mCtx, aMucDB[1])
                  : "Shell " + aMucDB[1];

          try {
            if (info.isPasswordProtected()) {
              muc.join(name, mSettings.roomPassword, mDiscussionHistory, JOIN_TIMEOUT);
            } else {
              muc.join(name, null, mDiscussionHistory, JOIN_TIMEOUT);

              // Openfire needs some time to collect the owners list
              try {
                Thread.sleep(REJOIN_ROOMS_SLEEP);
              } catch (InterruptedException e1) {
                /* Ignore */
              }
              // check here if we are still owner of these room, in case somebody has taken over
              // ownership
              // sadly getOwners() throws sometimes a 403 on my openfire server
              try {
                if (!affiliateCheck(muc.getOwners())) {
                  Log.i("rejoinRooms: leaving " + muc.getRoom() + " because affiliateCheck failed");
                  leaveRoom(muc);
                  continue;
                }

                // TODO this shouldn't happen any more
                // catch the 403 that sometimes shows up and fall back to some easier check if the
                // room
                // is still under our control
              } catch (XMPPException e) {
                Log.d("rejoinRooms: Exception, falling back", e);
                if (!(info.isMembersOnly() || info.isPasswordProtected())) {
                  Log.i(
                      "rejoinRooms: leaving "
                          + muc.getRoom()
                          + " because of membersOnly="
                          + info.isMembersOnly()
                          + " passwordProtected="
                          + info.isPasswordProtected());
                  leaveRoom(muc);
                  continue;
                }
              }
            }
            // looks like there is no one in the room
            if (info.getOccupantsCount() == 0) {
              Log.i("rejoinRooms: leaving " + muc.getRoom() + " because there is no one there");
              leaveRoom(muc);
              continue;
            }
          } catch (Exception e) {
            Log.i("rejoinRooms: leaving " + muc.getRoom() + " because of XMMPException", e);

            // TODO decide in which cases it would be the best to remove the room from the DB,
            // because of a persistent error
            // and in which cases the error will not be permanent
            if (mConnection.isAuthenticated()) {
              try {
                leaveRoom(muc);
              } catch (SmackException.NotConnectedException e1) {
                Log.i(
                    "rejoinRooms: error when leaving " + muc.getRoom() + " because of Exception",
                    e);
              }
              continue;
            } else {
              break;
            }
          }

          Log.i("Connected to the room '" + aMucDB[0]);

          // MUC has passed all tests and is fully usable
          registerRoom(muc, aMucDB[1], name, mode);
        } else {
          Log.i("The room '" + aMucDB[0] + "'is no more available");
          mMucHelper.deleteMUC(aMucDB[0]);
        }
      }
    }
Beispiel #8
0
 private void registerRoom(MultiUserChat muc, String number, String name, int mode) {
   String roomJID = muc.getRoom();
   Integer randomInt = getRoomInt(roomJID);
   registerRoom(muc, number, name, randomInt, mode);
 }
    @Override
    public void joinMuc(String roomName, String nickName) throws RemoteException {
      if (XmppSession.this.isConnected()) {
        try {
          muc = new MultiUserChat(connection, roomName + "@muc." + serveraddress);
          muc.join(nickName);
          Log.i("social-lable", "joined conversation!");
          occupants = new ArrayList<String>();
          Iterator<String> it = muc.getOccupants();
          while (it.hasNext()) {
            String s = it.next();
            occupants.add(s);
          }
          this.roomName = muc.getRoom();
          muc.addUserStatusListener(
              new DefaultUserStatusListener() {
                @Override
                public void kicked(String actor, String reason) {
                  if (listener != null) {
                    try {
                      listener.onMucKicked(null, actor, reason);
                    } catch (RemoteException e) {
                      Log.e("social-lable", "failed to handle kicked", e);
                    }
                  }
                }
              });
          muc.addParticipantStatusListener(
              new DefaultParticipantStatusListener() {
                @Override
                public void kicked(String participant, String actor, String reason) {
                  if (listener != null) {
                    try {
                      occupants.remove(participant);
                      listener.onMucKicked(participant, actor, reason);
                    } catch (RemoteException e) {
                      Log.e("social-lable", "failed to handle kicked", e);
                    }
                  }
                }

                @Override
                public void joined(String participant) {
                  if (listener != null) {
                    try {
                      occupants.add(participant);
                      listener.onMucJoined(participant);
                    } catch (RemoteException e) {
                      Log.e("social-lable", "failed to handle joined", e);
                    }
                  }
                }

                @Override
                public void left(String participant) {
                  if (listener != null) {
                    try {
                      listener.onMucLeft(participant);
                    } catch (RemoteException e) {
                      Log.e("social-lable", "failed to handle left", e);
                    }
                  }
                }
              });
          muc.addMessageListener(
              new PacketListener() {
                @Override
                public void processPacket(Packet packet) {
                  if (packet instanceof Message) {
                    Message msg = (Message) packet;
                    if (listener != null) {
                      Log.i("social-lable", "Received message : " + msg.getBody());
                      String from = msg.getFrom().replaceAll(muc.getRoom() + "/", "");
                      DelayInformation inf =
                          (DelayInformation) msg.getExtension("x", "jabber:x:delay");
                      Date sentDate;
                      if (inf != null) {
                        sentDate = inf.getStamp();
                      } else {
                        sentDate = new Date();
                      }
                      try {
                        listener.onMucMessage(from, msg.getBody(), sentDate.toString());
                      } catch (RemoteException e) {
                        Log.e("social-lable", "failed to handle message", e);
                      }
                    }
                  }
                }
              });
        } catch (XMPPException e) {
          Log.e("social-lable", "failed to join muc", e);
          throw new RemoteException(e.getMessage());
        }
      }
    }