private void onLoadedMore(List<ApiDialog> rawDialogs) {
    final ArrayList<DialogHistory> dialogs = new ArrayList<>();
    long maxLoadedDate = Long.MAX_VALUE;
    for (ApiDialog dialog : rawDialogs) {

      dialogs.add(
          new DialogHistory(
              convert(dialog.getPeer()),
              dialog.getUnreadCount(),
              dialog.getSortDate(),
              dialog.getRid(),
              dialog.getDate(),
              dialog.getSenderUid(),
              AbsContent.fromMessage(dialog.getMessage()),
              dialog.getState() == ApiMessageState.READ,
              dialog.getState() == ApiMessageState.RECEIVED));

      maxLoadedDate = Math.min(dialog.getSortDate(), maxLoadedDate);
    }

    if (dialogs.size() > 0) {
      final long finalMaxLoadedDate = maxLoadedDate;
      context()
          .getMessagesModule()
          .getRouter()
          .onDialogsHistoryLoaded(dialogs)
          .then(
              (v) -> {
                if (dialogs.size() < LIMIT) {
                  markAsLoaded();
                } else {
                  markAsSliceLoaded(finalMaxLoadedDate);
                }
              });
    } else {
      markAsLoaded();
    }
  }
  @Override
  public void onPeerClicked(Peer peer) {
    Activity activity = getActivity();
    String name;
    if (peer.getPeerType() == PeerType.PRIVATE) {
      name = messenger().getUser(peer.getPeerId()).getName().get();
    } else if (peer.getPeerType() == PeerType.GROUP) {
      name = messenger().getGroup(peer.getPeerId()).getName().get();
    } else {
      activity.finish();
      return;
    }
    new AlertDialog.Builder(getActivity())
        .setMessage(getActivity().getString(R.string.confirm_share) + " " + name + "?")
        .setPositiveButton(
            R.string.dialog_ok,
            (dialog, which) -> {
              Intent intent = Intents.openDialog(peer, false, activity);

              if (shareAction.getForwardText() != null) {
                intent.putExtra(Intents.EXTRA_FORWARD_TEXT, shareAction.getForwardText());
              }
              if (shareAction.getForwardTextRaw() != null) {
                intent.putExtra(Intents.EXTRA_FORWARD_TEXT_RAW, shareAction.getForwardTextRaw());
              }
              if (shareAction.getForwardTextRaw() != null) {
                intent.putExtra(Intents.EXTRA_FORWARD_CONTENT, shareAction.getForwardTextRaw());
              }

              if (shareAction.getText() != null) {
                messenger().sendMessage(peer, shareAction.getText());
              } else if (shareAction.getUris().size() > 0) {
                for (String sendUri : shareAction.getUris()) {
                  executeSilent(messenger().sendUri(peer, Uri.parse(sendUri)));
                }
              } else if (shareAction.getUserId() != null) {
                String userName = users().get(shareAction.getUserId()).getName().get();
                String mentionTitle = "@".concat(userName);
                ArrayList<Integer> mention = new ArrayList<>();
                mention.add(shareAction.getUserId());
                messenger()
                    .sendMessage(
                        peer,
                        mentionTitle,
                        "["
                            .concat(mentionTitle)
                            .concat(
                                "](people://"
                                    .concat(Integer.toString(shareAction.getUserId()))
                                    .concat(")")),
                        mention);
              } else if (shareAction.getDocContent() != null) {
                try {
                  messenger().forwardContent(peer, AbsContent.parse(shareAction.getDocContent()));
                } catch (IOException e) {
                  e.printStackTrace();
                }
              }

              startActivity(intent);
              activity.finish();
              shareAction = null;
            })
        .setNegativeButton(
            R.string.dialog_cancel,
            (dialog, which) -> {
              dialog.dismiss();
            })
        .show();
  }
  private void performSendContent(final Peer peer, final long rid, AbsContent content) {
    WakeLock wakeLock = im.actor.runtime.Runtime.makeWakeLock();

    ApiMessage message;
    if (content instanceof TextContent) {
      message =
          new ApiTextMessage(
              ((TextContent) content).getText(),
              ((TextContent) content).getMentions(),
              ((TextContent) content).getTextMessageEx());
    } else if (content instanceof DocumentContent) {
      DocumentContent documentContent = (DocumentContent) content;

      FileRemoteSource source = (FileRemoteSource) documentContent.getSource();

      ApiDocumentEx documentEx = null;

      if (content instanceof PhotoContent) {
        PhotoContent photoContent = (PhotoContent) content;
        documentEx = new ApiDocumentExPhoto(photoContent.getW(), photoContent.getH());
      } else if (content instanceof VideoContent) {
        VideoContent videoContent = (VideoContent) content;
        documentEx =
            new ApiDocumentExVideo(
                videoContent.getW(), videoContent.getH(), videoContent.getDuration());
      } else if (content instanceof AnimationContent) {
        AnimationContent animationContent = (AnimationContent) content;
        documentEx = new ApiDocumentExAnimation(animationContent.getW(), animationContent.getH());
      } else if (content instanceof VoiceContent) {
        VoiceContent voiceContent = (VoiceContent) content;
        documentEx = new ApiDocumentExVoice(voiceContent.getDuration());
      }

      ApiFastThumb fastThumb = null;
      if (documentContent.getFastThumb() != null) {
        fastThumb =
            new ApiFastThumb(
                documentContent.getFastThumb().getW(),
                documentContent.getFastThumb().getH(),
                documentContent.getFastThumb().getImage());
      }

      message =
          new ApiDocumentMessage(
              source.getFileReference().getFileId(),
              source.getFileReference().getAccessHash(),
              source.getFileReference().getFileSize(),
              source.getFileReference().getFileName(),
              documentContent.getMimeType(),
              fastThumb,
              documentEx);
    } else if (content instanceof LocationContent) {
      message = new ApiJsonMessage(((LocationContent) content).getRawJson());
    } else if (content instanceof ContactContent) {
      message = new ApiJsonMessage(((ContactContent) content).getRawJson());
    } else if (content instanceof JsonContent) {
      message = new ApiJsonMessage(((JsonContent) content).getRawJson());
    } else if (content instanceof StickerContent) {
      message = ((ContentRemoteContainer) content.getContentContainer()).getMessage();
    } else {
      return;
    }

    performSendApiContent(peer, rid, message, wakeLock);
  }