private void enumerateMessages() {
   idsOfTheMessagesToFind.clear();
   for (ConversationOneMessage oMsg : oMsgs) {
     oMsg.listOrder = 0;
     oMsg.historyOrder = 0;
   }
   OrderCounters order = new OrderCounters();
   for (int ind = oMsgs.size() - 1; ind >= 0; ind--) {
     ConversationOneMessage oMsg = oMsgs.get(ind);
     if (oMsg.listOrder < 0) {
       continue;
     }
     enumerateBranch(oMsg, order, 0);
   }
 }
 public void findRepliesRecursively(ConversationOneMessage oMsg) {
   MyLog.v(this, "findReplies for id=" + oMsg.msgId);
   List<Long> replies = MyProvider.getReplyIds(oMsg.msgId);
   oMsg.nReplies = replies.size();
   for (long replyId : replies) {
     ConversationOneMessage oMsgReply = new ConversationOneMessage(replyId, oMsg.replyLevel + 1);
     findPreviousMessagesRecursively(oMsgReply);
   }
 }
 private void enumerateBranch(ConversationOneMessage oMsg, OrderCounters order, int indent) {
   if (!addMessageIdToFind(oMsg.msgId)) {
     return;
   }
   int indentNext = indent;
   oMsg.historyOrder = order.history++;
   oMsg.listOrder = order.list--;
   oMsg.indentLevel = indent;
   if ((oMsg.nReplies > 1 || oMsg.nParentReplies > 1) && indentNext < MAX_INDENT_LEVEL) {
     indentNext++;
   }
   for (int ind = oMsgs.size() - 1; ind >= 0; ind--) {
     ConversationOneMessage reply = oMsgs.get(ind);
     if (reply.inReplyToMsgId == oMsg.msgId) {
       reply.nParentReplies = oMsg.nReplies;
       enumerateBranch(reply, order, indentNext);
     }
   }
 }
 private void checkInReplyToNameOf(ConversationOneMessage oMsg) {
   if (!SharedPreferencesUtil.isEmpty(oMsg.inReplyToName)) {
     MyLog.v(
         this,
         "Message id="
             + oMsg.msgId
             + " has reply to name ("
             + oMsg.inReplyToName
             + ") but no reply to message id");
     // Don't try to retrieve this message again.
     // It looks like such messages really exist.
     ConversationOneMessage oMsg2 = new ConversationOneMessage(0, oMsg.replyLevel - 1);
     // This allows to place the message on the timeline correctly
     oMsg2.createdDate = oMsg.createdDate - 60000;
     oMsg2.author = oMsg.inReplyToName;
     oMsg2.body = "(" + context.getText(R.string.id_of_this_message_was_not_specified) + ")";
     addMessageToList(oMsg2);
   }
 }
 private void findPreviousMessagesRecursively(ConversationOneMessage oMsg) {
   if (!addMessageIdToFind(oMsg.msgId)) {
     return;
   }
   findRepliesRecursively(oMsg);
   MyLog.v(this, "findPreviousMessages id=" + oMsg.msgId);
   loadMessageFromDatabase(oMsg);
   if (oMsg.isLoaded()) {
     if (addMessageToList(oMsg)) {
       if (oMsg.inReplyToMsgId != 0) {
         findPreviousMessagesRecursively(
             new ConversationOneMessage(oMsg.inReplyToMsgId, oMsg.replyLevel - 1));
       } else {
         checkInReplyToNameOf(oMsg);
       }
     }
   } else {
     retrieveFromInternet(oMsg.msgId);
   }
 }
  private void loadMessageFromCursor(ConversationOneMessage oMsg, Cursor cursor) {
    /**
     * IDs of all known senders of this message except for the Author These "senders" reblogged the
     * message
     */
    Set<Long> rebloggers = new HashSet<Long>();
    int ind = 0;
    do {
      long senderId = cursor.getLong(cursor.getColumnIndex(Msg.SENDER_ID));
      long authorId = cursor.getLong(cursor.getColumnIndex(Msg.AUTHOR_ID));
      long linkedUserId = cursor.getLong(cursor.getColumnIndex(User.LINKED_USER_ID));

      if (ind == 0) {
        // This is the same for all retrieved rows
        oMsg.inReplyToMsgId = cursor.getLong(cursor.getColumnIndex(Msg.IN_REPLY_TO_MSG_ID));
        oMsg.createdDate = cursor.getLong(cursor.getColumnIndex(Msg.CREATED_DATE));
        oMsg.author = cursor.getString(cursor.getColumnIndex(User.AUTHOR_NAME));
        oMsg.body = cursor.getString(cursor.getColumnIndex(Msg.BODY));
        String via = cursor.getString(cursor.getColumnIndex(Msg.VIA));
        if (!TextUtils.isEmpty(via)) {
          oMsg.via = Html.fromHtml(via).toString().trim();
        }
        if (MyPreferences.showAvatars()) {
          oMsg.avatarDrawable =
              new AvatarDrawable(
                  authorId, cursor.getString(cursor.getColumnIndex(Avatar.FILE_NAME)));
        }
        int colIndex = cursor.getColumnIndex(User.IN_REPLY_TO_NAME);
        if (colIndex > -1) {
          oMsg.inReplyToName = cursor.getString(colIndex);
          if (TextUtils.isEmpty(oMsg.inReplyToName)) {
            oMsg.inReplyToName = "";
          }
        }
        colIndex = cursor.getColumnIndex(User.RECIPIENT_NAME);
        if (colIndex > -1) {
          oMsg.recipientName = cursor.getString(colIndex);
          if (TextUtils.isEmpty(oMsg.recipientName)) {
            oMsg.recipientName = "";
          }
        }
      }

      if (senderId != authorId) {
        rebloggers.add(senderId);
      }
      if (linkedUserId != 0) {
        if (oMsg.linkedUserId == 0) {
          oMsg.linkedUserId = linkedUserId;
        }
        if (cursor.getInt(cursor.getColumnIndex(MsgOfUser.REBLOGGED)) == 1
            && linkedUserId != authorId) {
          rebloggers.add(linkedUserId);
        }
        if (cursor.getInt(cursor.getColumnIndex(MsgOfUser.FAVORITED)) == 1) {
          oMsg.favorited = true;
        }
      }

      ind++;
    } while (cursor.moveToNext());

    for (long rebloggerId : rebloggers) {
      if (!TextUtils.isEmpty(oMsg.rebloggersString)) {
        oMsg.rebloggersString += ", ";
      }
      oMsg.rebloggersString += MyProvider.userIdToName(rebloggerId);
    }
  }