mirror of https://github.com/M66B/FairEmail.git
Fixed reply all (3)
This commit is contained in:
parent
b6fd02234b
commit
5b704136ee
|
@ -3231,49 +3231,79 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
|
|||
}
|
||||
|
||||
private void onActionReplyMenu(final ActionData data) {
|
||||
Address[] all = data.message.getAll();
|
||||
Bundle args = new Bundle();
|
||||
args.putSerializable("message", data.message);
|
||||
|
||||
if (all.length == 0 &&
|
||||
data.message.list_post == null &&
|
||||
data.message.receipt_to == null &&
|
||||
(answers == 0 && Helper.isPro(context))) {
|
||||
onMenuReply(data, "reply");
|
||||
return;
|
||||
}
|
||||
|
||||
View anchor = bnvActions.findViewById(R.id.action_reply);
|
||||
PopupMenuLifecycle popupMenu = new PopupMenuLifecycle(context, powner, anchor);
|
||||
popupMenu.inflate(R.menu.menu_reply);
|
||||
popupMenu.getMenu().findItem(R.id.menu_reply_to_all).setVisible(all.length > 0);
|
||||
popupMenu.getMenu().findItem(R.id.menu_reply_list).setVisible(data.message.list_post != null);
|
||||
popupMenu.getMenu().findItem(R.id.menu_reply_receipt).setVisible(data.message.receipt_to != null);
|
||||
popupMenu.getMenu().findItem(R.id.menu_reply_answer).setVisible(answers != 0 || !Helper.isPro(context));
|
||||
|
||||
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
|
||||
new SimpleTask<EntityIdentity>() {
|
||||
@Override
|
||||
public boolean onMenuItemClick(MenuItem target) {
|
||||
switch (target.getItemId()) {
|
||||
case R.id.menu_reply_to_sender:
|
||||
onMenuReply(data, "reply");
|
||||
return true;
|
||||
case R.id.menu_reply_to_all:
|
||||
onMenuReply(data, "reply_all");
|
||||
return true;
|
||||
case R.id.menu_reply_list:
|
||||
onMenuReply(data, "list");
|
||||
return true;
|
||||
case R.id.menu_reply_receipt:
|
||||
onMenuReply(data, "receipt");
|
||||
return true;
|
||||
case R.id.menu_reply_answer:
|
||||
onMenuAnswer(data);
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
protected EntityIdentity onExecute(Context context, Bundle args) {
|
||||
TupleMessageEx message = (TupleMessageEx) args.getSerializable("message");
|
||||
if (message.identity == null)
|
||||
return null;
|
||||
|
||||
DB db = DB.getInstance(context);
|
||||
return db.identity().getIdentity(message.identity);
|
||||
}
|
||||
});
|
||||
popupMenu.show();
|
||||
|
||||
@Override
|
||||
protected void onExecuted(Bundle args, EntityIdentity identity) {
|
||||
TupleMessageEx message = (TupleMessageEx) args.getSerializable("message");
|
||||
|
||||
TupleMessageEx amessage = getMessage();
|
||||
if (amessage == null || !amessage.id.equals(message.id))
|
||||
return;
|
||||
|
||||
String via = (identity == null ? null : MessageHelper.canonicalAddress(identity.email));
|
||||
Address[] recipients = data.message.getAllRecipients(via);
|
||||
|
||||
if (recipients.length == 0 &&
|
||||
data.message.list_post == null &&
|
||||
data.message.receipt_to == null &&
|
||||
(answers == 0 && Helper.isPro(context))) {
|
||||
onMenuReply(data, "reply");
|
||||
return;
|
||||
}
|
||||
|
||||
View anchor = bnvActions.findViewById(R.id.action_reply);
|
||||
PopupMenuLifecycle popupMenu = new PopupMenuLifecycle(context, powner, anchor);
|
||||
popupMenu.inflate(R.menu.menu_reply);
|
||||
popupMenu.getMenu().findItem(R.id.menu_reply_to_all).setVisible(recipients.length > 0);
|
||||
popupMenu.getMenu().findItem(R.id.menu_reply_list).setVisible(data.message.list_post != null);
|
||||
popupMenu.getMenu().findItem(R.id.menu_reply_receipt).setVisible(data.message.receipt_to != null);
|
||||
popupMenu.getMenu().findItem(R.id.menu_reply_answer).setVisible(answers != 0 || !Helper.isPro(context));
|
||||
|
||||
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
|
||||
@Override
|
||||
public boolean onMenuItemClick(MenuItem target) {
|
||||
switch (target.getItemId()) {
|
||||
case R.id.menu_reply_to_sender:
|
||||
onMenuReply(data, "reply");
|
||||
return true;
|
||||
case R.id.menu_reply_to_all:
|
||||
onMenuReply(data, "reply_all");
|
||||
return true;
|
||||
case R.id.menu_reply_list:
|
||||
onMenuReply(data, "list");
|
||||
return true;
|
||||
case R.id.menu_reply_receipt:
|
||||
onMenuReply(data, "receipt");
|
||||
return true;
|
||||
case R.id.menu_reply_answer:
|
||||
onMenuAnswer(data);
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
});
|
||||
popupMenu.show();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onException(Bundle args, Throwable ex) {
|
||||
Helper.unexpectedError(context, owner, ex);
|
||||
}
|
||||
}.execute(context, owner, args, "message:reply");
|
||||
}
|
||||
|
||||
private void onMenuReply(final ActionData data, String action) {
|
||||
|
|
|
@ -40,6 +40,7 @@ import java.util.Objects;
|
|||
import java.util.Random;
|
||||
|
||||
import javax.mail.Address;
|
||||
import javax.mail.internet.InternetAddress;
|
||||
|
||||
import static androidx.room.ForeignKey.CASCADE;
|
||||
import static androidx.room.ForeignKey.SET_NULL;
|
||||
|
@ -159,16 +160,28 @@ public class EntityMessage implements Serializable {
|
|||
return sb.toString();
|
||||
}
|
||||
|
||||
Address[] getAll() {
|
||||
Address[] getAllRecipients(String via) {
|
||||
List<Address> addresses = new ArrayList<>();
|
||||
if (reply != null && reply.length > 0)
|
||||
addresses.addAll(Arrays.asList(reply));
|
||||
else if (to != null)
|
||||
addresses.addAll(Arrays.asList(to));
|
||||
|
||||
String r = null;
|
||||
Address[] replying = (reply == null || reply.length == 0 ? from : reply);
|
||||
if (replying != null && replying.length == 1)
|
||||
r = MessageHelper.canonicalAddress(((InternetAddress) replying[0]).getAddress());
|
||||
if (r == null && !r.equals(via)) {
|
||||
if (to != null)
|
||||
addresses.addAll(Arrays.asList(to));
|
||||
}
|
||||
|
||||
if (cc != null)
|
||||
addresses.addAll(Arrays.asList(cc));
|
||||
|
||||
// Filter self
|
||||
for (Address address : new ArrayList<>(addresses)) {
|
||||
String recipient = MessageHelper.canonicalAddress(((InternetAddress) address).getAddress());
|
||||
if (recipient.equals(via))
|
||||
addresses.remove(address);
|
||||
}
|
||||
|
||||
return addresses.toArray(new Address[0]);
|
||||
}
|
||||
|
||||
|
|
|
@ -2037,6 +2037,12 @@ public class FragmentCompose extends FragmentBase {
|
|||
draft.inreplyto = ref.msgid;
|
||||
draft.thread = ref.thread;
|
||||
|
||||
String via = null;
|
||||
if (ref.identity != null) {
|
||||
EntityIdentity v = db.identity().getIdentity(ref.identity);
|
||||
via = MessageHelper.canonicalAddress(v.email);
|
||||
}
|
||||
|
||||
if ("list".equals(action) && ref.list_post != null) {
|
||||
draft.to = ref.list_post;
|
||||
draft.from = ref.to;
|
||||
|
@ -2046,26 +2052,21 @@ public class FragmentCompose extends FragmentBase {
|
|||
} else {
|
||||
// Prevent replying to self
|
||||
String to = null;
|
||||
String via = null;
|
||||
Address[] recipient = (ref.reply == null || ref.reply.length == 0 ? ref.from : ref.reply);
|
||||
if (recipient != null && recipient.length > 0)
|
||||
to = MessageHelper.canonicalAddress(((InternetAddress) recipient[0]).getAddress());
|
||||
if (ref.identity != null) {
|
||||
EntityIdentity v = db.identity().getIdentity(ref.identity);
|
||||
via = MessageHelper.canonicalAddress(v.email);
|
||||
}
|
||||
Address[] replying = (ref.reply == null || ref.reply.length == 0 ? ref.from : ref.reply);
|
||||
if (replying != null && replying.length == 1)
|
||||
to = MessageHelper.canonicalAddress(((InternetAddress) replying[0]).getAddress());
|
||||
|
||||
if (to != null && to.equals(via)) {
|
||||
draft.to = ref.to;
|
||||
draft.from = ref.from;
|
||||
} else {
|
||||
draft.to = recipient;
|
||||
draft.to = replying;
|
||||
draft.from = ref.to;
|
||||
}
|
||||
}
|
||||
|
||||
if ("reply_all".equals(action))
|
||||
draft.cc = ref.getAll();
|
||||
draft.cc = ref.getAllRecipients(via);
|
||||
else if ("receipt".equals(action))
|
||||
draft.receipt_request = true;
|
||||
|
||||
|
|
Loading…
Reference in New Issue