private void updateDialog(QBDialog dialog, QBCustomObjectUpdateBuilder requestBuilder)
     throws QBResponseException {
   QBDialog updatedDialog = groupChatManager.updateDialog(dialog, requestBuilder);
   ArrayList<Integer> friendsList = new ArrayList<Integer>(updatedDialog.getOccupants());
   friendsList.remove(chatCreator.getId());
   notifyFriendsRoomUpdate(updatedDialog, friendsList);
   DatabaseManager.saveDialog(context, updatedDialog);
 }
 public void leaveDialogs() throws XMPPException, SmackException.NotConnectedException {
   if (groupDialogsList != null) {
     for (QBDialog dialog : groupDialogsList) {
       QBGroupChat roomChat = groupChatManager.getGroupChat(dialog.getRoomJid());
       if (roomChat != null && roomChat.isJoined()) {
         roomChat.leave();
       }
     }
   }
 }
 @Override
 public void execute(Bundle bundle) {
   QBDialog dialog = (QBDialog) bundle.getSerializable(QBServiceConsts.EXTRA_DIALOG);
   groupDialog =
       new GroupDialog(
           DatabaseManager.getDialogByDialogId(
               GroupDialogDetailsActivity.this, dialog.getDialogId()));
   updateOldGroupData();
   hideProgress();
 }
Пример #4
0
  private void initChat() {
    if (dialog.getType() == QBDialogType.GROUP) {
      chat = new GroupChatImpl(this);
      progressBar.setVisibility(View.VISIBLE);
      joinGroupChat();

    } else if (dialog.getType() == QBDialogType.PRIVATE) {
      Integer opponentID = ChatService.getInstance().getOpponentIDForPrivateDialog(dialog);
      chat = new PrivateChatImpl(this, opponentID);
      loadChatHistory();
    }
  }
 public void tryJoinRoomChats(List<QBDialog> chatDialogsList) {
   if (!chatDialogsList.isEmpty()) {
     DatabaseManager.saveDialogs(context, chatDialogsList);
     initGroupDialogsList();
     for (QBDialog dialog : chatDialogsList) {
       if (!QBDialogType.PRIVATE.equals(dialog.getType())) {
         groupDialogsList.add(dialog);
         tryJoinRoomChat(dialog);
       }
     }
   }
 }
 private void createDialogByNotification(QBChatMessage chatMessage) {
   long time;
   String roomJidId;
   time = DateUtilsCore.getCurrentTime();
   QBDialog dialog =
       ChatUtils.parseDialogFromMessage(context, chatMessage, chatMessage.getBody(), time);
   roomJidId = dialog.getRoomJid();
   if (roomJidId != null && !QBDialogType.PRIVATE.equals(dialog.getType())) {
     tryJoinRoomChat(dialog);
     new FindUnknownFriendsTask(context).execute(null, dialog);
     saveDialogToCache(context, dialog);
   }
 }
 private QBGroupChat createChatIfNotExist(QBDialog dialog) throws QBResponseException {
   boolean notNull = Utils.validateNotNull(groupChatManager);
   if (!notNull) {
     ErrorUtils.logError(TAG, " groupChatManager is NULL");
     throw new QBResponseException(context.getString(R.string.dlg_fail_create_chat));
   }
   groupChat = groupChatManager.getGroupChat(dialog.getRoomJid());
   if (groupChat == null) {
     groupChat = groupChatManager.createGroupChat(dialog.getRoomJid());
     groupChat.addMessageListener(roomChatMessageListener);
   }
   return groupChat;
 }
  public QBDialog createGroupChat(String name, List<Integer> friendIdsList, QBDialogType type)
      throws Exception {
    ArrayList<Integer> occupantIdsList = ChatUtils.getOccupantIdsWithUser(friendIdsList);

    QBDialog dialogToCreate = new QBDialog();
    dialogToCreate.setName(name);
    dialogToCreate.setType(type);
    dialogToCreate.setOccupantsIds(occupantIdsList);

    QBDialog dialog = groupChatManager.createDialog(dialogToCreate);

    joinRoomChat(dialog);
    inviteFriendsToRoom(dialog, friendIdsList);
    saveDialogToCache(context, dialog);
    return dialog;
  }
Пример #9
0
        @Override
        public void connectionClosedOnError(final Exception e) {
          Log.i(TAG, "connectionClosedOnError: " + e.getLocalizedMessage());

          // leave active room
          //
          if (dialog.getType() == QBDialogType.GROUP) {
            ChatActivity.this.runOnUiThread(
                new Runnable() {
                  @Override
                  public void run() {
                    ((GroupChatImpl) chat).leave();
                  }
                });
          }
        }
Пример #10
0
        @Override
        public void reconnectionSuccessful() {
          Log.i(TAG, "reconnectionSuccessful");

          // Join active room
          //
          if (dialog.getType() == QBDialogType.GROUP) {
            ChatActivity.this.runOnUiThread(
                new Runnable() {
                  @Override
                  public void run() {
                    joinGroupChat();
                  }
                });
          }
        }
  private void saveChanges() {
    if (!isUserDataCorrect()) {
      DialogUtils.showLong(this, getString(R.string.gdd_name_not_entered));
      return;
    }

    dialogCurrent.setName(groupNameCurrent);

    if (isNeedUpdateAvatar) {
      new ReceiveFileFromBitmapTask(this).execute(imageUtils, avatarBitmapCurrent, true);
    } else {
      startUpdatingGroupDialog(null);
    }

    showProgress();
  }
Пример #12
0
  private void sendChatMessage(String messageText) {
    QBChatMessage chatMessage = new QBChatMessage();
    chatMessage.setBody(messageText);
    chatMessage.setProperty(PROPERTY_SAVE_TO_HISTORY, "1");
    chatMessage.setDateSent(new Date().getTime() / 1000);

    try {
      chat.sendMessage(chatMessage);
    } catch (XMPPException | SmackException.NotConnectedException e) {
      Log.e(TAG, "failed to send a message", e);
    }

    messageEditText.setText("");

    if (dialog.getType() == QBDialogType.PRIVATE) {
      showMessage(chatMessage);
    }
  }
  public void sendOccupantStatusGroup(String sendStr) {
    long time = DateUtilsCore.getCurrentTime();

    QBChatMessage chatMessage = new QBChatMessage();
    chatMessage.setBody(sendStr);
    chatMessage.setProperty(
        ChatUtils.PROPERTY_NOTIFICATION_TYPE, ChatUtils.PROPERTY_NOTIFICATION_TYPE_CREATE_CHAT);
    chatMessage.setProperty(ChatUtils.PROPERTY_DIALOG_ID, currentDialog.getDialogId());
    chatMessage.setProperty(ChatUtils.PROPERTY_ROOM_JID, currentDialog.getRoomJid());
    chatMessage.setProperty(
        ChatUtils.PROPERTY_OCCUPANTS_IDS,
        TextUtils.join(ChatUtils.OCCUPANT_IDS_DIVIDER, currentDialog.getOccupants()));
    chatMessage.setProperty(ChatUtils.PROPERTY_ROOM_NAME, currentDialog.getName());
    chatMessage.setProperty(
        ChatUtils.PROPERTY_DIALOG_TYPE_CODE, String.valueOf(currentDialog.getType().getCode()));
    chatMessage.setProperty(ChatUtils.PROPERTY_DATE_SENT, time + ConstsCore.EMPTY_STRING);
    chatMessage.setProperty(ChatUtils.PROPERTY_SAVE_TO_HISTORY, ChatUtils.VALUE_SAVE_TO_HISTORY);

    try {
      sendRoomMessage(chatMessage, currentDialog.getRoomJid(), currentDialog.getDialogId());
    } catch (QBResponseException e) {
      ErrorUtils.showError(context, e);
    }
  }
 public void updateDialog(QBDialog dialog, File inputFile) throws QBResponseException {
   QBFile file = QBContent.uploadFileTask(inputFile, true, (String) null);
   dialog.setPhoto(file.getPublicUrl());
   updateDialog(dialog, (QBCustomObjectUpdateBuilder) null);
 }
 protected GroupDialogOccupantsAdapter getFriendsAdapter() {
   if (dialogCurrent.getType() == QBDialogType.PUBLIC_GROUP)
     return new GroupDialogOccupantsAdapter(this, ChatUtils.getJoinUsers());
   else return new GroupDialogOccupantsAdapter(this, groupDialog.getOccupantList());
 }
 private void startLoadGroupDialog() {
   if (dialogCurrent.getType() == QBDialogType.PUBLIC_GROUP) initListView();
   else QBLoadGroupDialogCommand.start(this, dialogCurrent, groupDialog.getRoomJid());
 }
Пример #17
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_chat);

    Intent intent = getIntent();
    dialog = (QBDialog) intent.getSerializableExtra(EXTRA_DIALOG);

    messagesContainer = (ListView) findViewById(R.id.messagesContainer);
    messageEditText = (EditText) findViewById(R.id.messageEdit);
    progressBar = (ProgressBar) findViewById(R.id.progressBar);
    companionLabel = (TextView) findViewById(R.id.companionLabel);

    container = (RelativeLayout) findViewById(R.id.container);
    if (dialog.getType() == QBDialogType.GROUP) {
      TextView meLabel = (TextView) findViewById(R.id.meLabel);
      container.removeView(meLabel);
      container.removeView(companionLabel);
    } else if (dialog.getType() == QBDialogType.PRIVATE) {
      Integer opponentID = ChatService.getInstance().getOpponentIDForPrivateDialog(dialog);
      companionLabel.setText(
          ChatService.getInstance().getDialogsUsers().get(opponentID).getLogin());
    }

    sendButton = (Button) findViewById(R.id.chatSendButton);
    sendButton.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            String messageText = messageEditText.getText().toString();
            if (!TextUtils.isEmpty(messageText)) {
              sendChatMessage(messageText);
            }
          }
        });

    keyboardHandleLayout = (KeyboardHandleRelativeLayout) findViewById(R.id.sizeNotifierLayout);
    keyboardHandleLayout.listener = this;
    stickersFrame = findViewById(R.id.frame);
    stickerButton = (ImageView) findViewById(R.id.stickers_button);

    stickerButton.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            if (isStickersFrameVisible) {
              showKeyboard();
              stickerButton.setImageResource(R.drawable.ic_action_insert_emoticon);
            } else {
              if (keyboardHandleLayout.isKeyboardVisible()) {
                keyboardHandleLayout.hideKeyboard(
                    ChatActivity.this,
                    new KeyboardHandleRelativeLayout.OnKeyboardHideCallback() {
                      @Override
                      public void onKeyboardHide() {
                        stickerButton.setImageResource(R.drawable.ic_action_keyboard);
                        setStickersFrameVisible(true);
                      }
                    });
              } else {
                stickerButton.setImageResource(R.drawable.ic_action_keyboard);
                setStickersFrameVisible(true);
              }
            }
          }
        });
    updateStickersFrameParams();
    stickersFragment = (StickersFragment) getSupportFragmentManager().findFragmentById(R.id.frame);
    if (stickersFragment == null) {
      stickersFragment =
          new StickersFragment.Builder()
              .setStickerPlaceholderColorFilterRes(android.R.color.darker_gray)
              .build();
      getSupportFragmentManager().beginTransaction().replace(R.id.frame, stickersFragment).commit();
    }
    stickersFragment.setOnStickerSelectedListener(stickerSelectedListener);
    stickersFragment.setOnEmojiBackspaceClickListener(
        new OnEmojiBackspaceClickListener() {
          @Override
          public void onEmojiBackspaceClicked() {
            KeyEvent event =
                new KeyEvent(0, 0, 0, KeyEvent.KEYCODE_DEL, 0, 0, 0, 0, KeyEvent.KEYCODE_ENDCALL);
            messageEditText.dispatchKeyEvent(event);
          }
        });
    setStickersFrameVisible(isStickersFrameVisible);

    if (isSessionActive()) {
      initChat();
    }

    ChatService.getInstance().addConnectionListener(chatConnectionListener);
  }
 public void sendGroupMessage(String roomJidId, String message) throws QBResponseException {
   QBChatMessage chatMessage = getQBChatMessage(message, null);
   sendRoomMessage(chatMessage, roomJidId, currentDialog.getDialogId());
 }
 public void sendGroupMessageWithAttachImage(String roomJidId, QBFile file)
     throws QBResponseException {
   QBChatMessage chatMessage =
       getQBChatMessage(context.getString(R.string.dlg_attached_last_message), file);
   sendRoomMessage(chatMessage, roomJidId, currentDialog.getDialogId());
 }