Commit 4e52fa0c authored by Thomas's avatar Thomas
Browse files

Fix issue #136 - Mentions are lost when replying to a own message

parent 0c19da62
Loading
Loading
Loading
Loading
+1 −2
Original line number Diff line number Diff line
@@ -62,8 +62,7 @@
            android:configChanges="keyboardHidden|orientation|screenSize" />
        <activity
            android:name=".activities.ComposeActivity"
            android:configChanges="keyboardHidden|orientation|screenSize"
            android:windowSoftInputMode="adjustPan|adjustResize"
            android:configChanges="orientation|screenSize"
            android:label="@string/compose" />
        <activity
            android:name=".activities.StatusInfoActivity"
+18 −20
Original line number Diff line number Diff line
@@ -247,29 +247,27 @@ public class ComposeActivity extends BaseActivity implements ComposeAdapter.Mana
                    statusList.add(statusReply);
                    int statusCount = statusList.size();
                    statusDraftList.get(0).in_reply_to_id = statusReply.id;
                    statusDraftList.get(0).mentions = statusReply.mentions;
                    if (statusReply.spoiler_text != null) {
                        statusDraftList.get(0).spoiler_text = statusReply.spoiler_text;
                    }
                    if (statusDraftList.get(0).mentions == null) {
                    //We change order for mentions
                    //At first place the account that has been mentioned if it's not our
                    statusDraftList.get(0).mentions = new ArrayList<>();
                    }
                    //We will add the mentioned account in mention if not the current user nor if it is already mentioned
                    if (statusReply.account != null && statusReply.account.acct != null && !statusReply.account.id.equals(BaseMainActivity.currentUserID)) {
                        boolean canBeAdded = true;
                        for (Mention mention : statusDraftList.get(0).mentions) {
                            if (mention.acct.compareToIgnoreCase(statusReply.account.acct) == 0) {
                                mention.id = null;
                                canBeAdded = false;
                            }
                        }
                        if (canBeAdded) {
                    if (!statusReply.account.acct.equalsIgnoreCase(MainActivity.accountWeakReference.get().mastodon_account.acct)) {
                        Mention mention = new Mention();
                        mention.acct = "@" + statusReply.account.acct;
                        mention.url = statusReply.account.url;
                        mention.username = statusReply.account.username;
                        statusDraftList.get(0).mentions.add(mention);
                    }

                    //There are other mentions to
                    if (statusReply.mentions != null && statusReply.mentions.size() > 0) {
                        for (Mention mentionTmp : statusReply.mentions) {
                            if (!mentionTmp.acct.equalsIgnoreCase(statusReply.account.acct) && !mentionTmp.acct.equalsIgnoreCase(MainActivity.accountWeakReference.get().mastodon_account.acct)) {
                                statusDraftList.get(0).mentions.add(mentionTmp);
                            }
                        }
                    }
                    if (statusReply.spoiler_text != null) {
                        statusDraftList.get(0).spoiler_text = statusReply.spoiler_text;
                    }
                    //StatusDraftList at this point should only have one element
                    statusList.addAll(statusDraftList);
+0 −2
Original line number Diff line number Diff line
@@ -9,7 +9,6 @@ import android.graphics.Typeface;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.animation.AnticipateOvershootInterpolator;
@@ -413,7 +412,6 @@ public class EditImageActivity extends BaseActivity implements OnPhotoEditorList
                mPropertiesBSFragment.show(getSupportFragmentManager(), mPropertiesBSFragment.getTag());
                break;
            case CROP:
                Log.v(Helper.TAG, "crop! " + uri);
                CropImage.activity(uri)
                        .start(this);
                break;
+6 −14
Original line number Diff line number Diff line
@@ -187,13 +187,7 @@ public class ComposeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
            //Retrieves mentioned accounts + OP and adds them at the beginin of the toot
            final SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(context);
            Mention inReplyToUser = null;
            for (Mention mention : statusDraft.mentions) {
                //Mentioned account has a null id
                if (mention.id == null) {
                    inReplyToUser = mention;
                    break;
                }
            }
            inReplyToUser = statusDraft.mentions.get(0);
            if (statusDraft.text == null) {
                statusDraft.text = "";
            }
@@ -201,22 +195,20 @@ public class ComposeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
            boolean capitalize = sharedpreferences.getBoolean(context.getString(R.string.SET_CAPITALIZE), true);
            if (inReplyToUser != null) {
                if (capitalize) {
                    statusDraft.text = inReplyToUser.acct + "\n";
                    statusDraft.text = inReplyToUser.acct.startsWith("@") ? inReplyToUser.acct + "\n" : "@" + inReplyToUser.acct + "\n";
                } else {
                    statusDraft.text = inReplyToUser.acct + " ";
                    statusDraft.text = inReplyToUser.acct.startsWith("@") ? inReplyToUser.acct + " " : "@" + inReplyToUser.acct + " ";
                }
            }
            holder.binding.content.setText(statusDraft.text);
            statusDraft.cursorPosition = statusDraft.text.length();
            if (statusDraft.mentions.size() > 1) {
                statusDraft.text += "\n";
                for (Mention mention : statusDraft.mentions) {
                    if (mention.id != null && mention.acct != null && !mention.id.equals(BaseMainActivity.currentUserID)) {
                        String tootTemp = String.format("@%s ", mention.acct);
                for (int i = 1; i < statusDraft.mentions.size(); i++) {
                    String tootTemp = String.format("@%s ", statusDraft.mentions.get(i).acct);
                    statusDraft.text = String.format("%s ", (statusDraft.text + tootTemp.trim()));
                }
            }
            }
            holder.binding.content.setText(statusDraft.text);
            updateCharacterCount(holder);
            holder.binding.content.requestFocus();