Add XEP-0245 (/me command) support
This commit is contained in:
parent
12d63f2612
commit
3c5224251c
|
@ -9,6 +9,7 @@
|
|||
* XEP-0198: Stream Management
|
||||
* XEP-0234: Jingle File Transfer
|
||||
* XEP-0237: Roster Versioning
|
||||
* XEP-0245: The /me Command
|
||||
* XEP-0249: Direct MUC Invitations (receiving only)
|
||||
* XEP-0260: Jingle SOCKS5 Bytestreams Transport Method
|
||||
* XEP-0261: Jingle In-Band Bytestreams Transport Method
|
||||
|
|
|
@ -36,17 +36,18 @@ public class Message extends AbstractEntity {
|
|||
public static final int TYPE_STATUS = 3;
|
||||
public static final int TYPE_PRIVATE = 4;
|
||||
|
||||
public static String CONVERSATION = "conversationUuid";
|
||||
public static String COUNTERPART = "counterpart";
|
||||
public static String TRUE_COUNTERPART = "trueCounterpart";
|
||||
public static String BODY = "body";
|
||||
public static String TIME_SENT = "timeSent";
|
||||
public static String ENCRYPTION = "encryption";
|
||||
public static String STATUS = "status";
|
||||
public static String TYPE = "type";
|
||||
public static String REMOTE_MSG_ID = "remoteMsgId";
|
||||
public static String SERVER_MSG_ID = "serverMsgId";
|
||||
public static String RELATIVE_FILE_PATH = "relativeFilePath";
|
||||
public static final String CONVERSATION = "conversationUuid";
|
||||
public static final String COUNTERPART = "counterpart";
|
||||
public static final String TRUE_COUNTERPART = "trueCounterpart";
|
||||
public static final String BODY = "body";
|
||||
public static final String TIME_SENT = "timeSent";
|
||||
public static final String ENCRYPTION = "encryption";
|
||||
public static final String STATUS = "status";
|
||||
public static final String TYPE = "type";
|
||||
public static final String REMOTE_MSG_ID = "remoteMsgId";
|
||||
public static final String SERVER_MSG_ID = "serverMsgId";
|
||||
public static final String RELATIVE_FILE_PATH = "relativeFilePath";
|
||||
|
||||
public boolean markable = false;
|
||||
protected String conversationUuid;
|
||||
protected Jid counterpart;
|
||||
|
@ -348,17 +349,35 @@ public class Message extends AbstractEntity {
|
|||
}
|
||||
|
||||
public boolean mergeable(final Message message) {
|
||||
return message != null && (message.getType() == Message.TYPE_TEXT && this.getDownloadable() == null && message.getDownloadable() == null && message.getEncryption() != Message.ENCRYPTION_PGP && this.getType() == message.getType() && this.getStatus() == message.getStatus() && this.getEncryption() == message.getEncryption() && this.getCounterpart() != null && this.getCounterpart().equals(message.getCounterpart()) && (message.getTimeSent() - this.getTimeSent()) <= (Config.MESSAGE_MERGE_WINDOW * 1000) && !message.bodyContainsDownloadable() && !this.bodyContainsDownloadable());
|
||||
return message != null &&
|
||||
(message.getType() == Message.TYPE_TEXT &&
|
||||
this.getDownloadable() == null &&
|
||||
message.getDownloadable() == null &&
|
||||
message.getEncryption() != Message.ENCRYPTION_PGP &&
|
||||
this.getType() == message.getType() &&
|
||||
this.getStatus() == message.getStatus() &&
|
||||
this.getEncryption() == message.getEncryption() &&
|
||||
this.getCounterpart() != null &&
|
||||
this.getCounterpart().equals(message.getCounterpart()) &&
|
||||
(message.getTimeSent() - this.getTimeSent()) <= (Config.MESSAGE_MERGE_WINDOW * 1000) &&
|
||||
!message.bodyContainsDownloadable() &&
|
||||
!this.bodyContainsDownloadable() &&
|
||||
!this.body.startsWith("/me ")
|
||||
);
|
||||
}
|
||||
|
||||
public String getMergedBody() {
|
||||
Message next = this.next();
|
||||
final Message next = this.next();
|
||||
if (this.mergeable(next)) {
|
||||
return body.trim() + '\n' + next.getMergedBody();
|
||||
return getBody() + '\n' + next.getMergedBody();
|
||||
}
|
||||
return body.trim();
|
||||
}
|
||||
|
||||
public boolean hasMeCommand() {
|
||||
return getMergedBody().startsWith("/me ");
|
||||
}
|
||||
|
||||
public int getMergedStatus() {
|
||||
return getStatus();
|
||||
}
|
||||
|
|
|
@ -657,7 +657,7 @@ public class ConversationFragment extends Fragment {
|
|||
}
|
||||
}
|
||||
conversation.populateWithMessages(ConversationFragment.this.messageList);
|
||||
for (Message message : this.messageList) {
|
||||
for (final Message message : this.messageList) {
|
||||
if (message.getEncryption() == Message.ENCRYPTION_PGP
|
||||
&& (message.getStatus() == Message.STATUS_RECEIVED || message
|
||||
.getStatus() >= Message.STATUS_SEND)
|
||||
|
|
|
@ -1,5 +1,15 @@
|
|||
package eu.siacs.conversations.ui.adapter;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Typeface;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import eu.siacs.conversations.R;
|
||||
|
@ -10,15 +20,6 @@ import eu.siacs.conversations.entities.Message;
|
|||
import eu.siacs.conversations.ui.ConversationActivity;
|
||||
import eu.siacs.conversations.ui.XmppActivity;
|
||||
import eu.siacs.conversations.utils.UIHelper;
|
||||
import android.content.Context;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Typeface;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
public class ConversationAdapter extends ArrayAdapter<Conversation> {
|
||||
|
||||
|
|
|
@ -144,12 +144,7 @@ public class MessageAdapter extends ArrayAdapter<Message> {
|
|||
break;
|
||||
default:
|
||||
if (multiReceived) {
|
||||
Contact contact = message.getContact();
|
||||
if (contact != null) {
|
||||
info = contact.getDisplayName();
|
||||
} else {
|
||||
info = getDisplayedMucCounterpart(message.getCounterpart());
|
||||
}
|
||||
info = getMessageDisplayName(message);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -218,15 +213,42 @@ public class MessageAdapter extends ArrayAdapter<Message> {
|
|||
viewHolder.messageBody.setTextIsSelectable(false);
|
||||
}
|
||||
|
||||
private void displayTextMessage(ViewHolder viewHolder, Message message) {
|
||||
private String getMessageDisplayName(final Message message) {
|
||||
if (message.getStatus() == Message.STATUS_RECEIVED) {
|
||||
if (message.getConversation().getMode() == Conversation.MODE_MULTI) {
|
||||
return getDisplayedMucCounterpart(message.getCounterpart());
|
||||
} else {
|
||||
final Contact contact = message.getContact();
|
||||
return contact != null ? contact.getDisplayName() : "";
|
||||
}
|
||||
} else {
|
||||
if (message.getConversation().getMode() == Conversation.MODE_MULTI) {
|
||||
return getDisplayedMucCounterpart(message.getConversation().getJid());
|
||||
} else {
|
||||
final Jid jid = message.getConversation().getAccount().getJid();
|
||||
return jid.hasLocalpart() ? jid.getLocalpart() : jid.toDomainJid().toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void displayTextMessage(final ViewHolder viewHolder, final Message message) {
|
||||
if (viewHolder.download_button != null) {
|
||||
viewHolder.download_button.setVisibility(View.GONE);
|
||||
}
|
||||
viewHolder.image.setVisibility(View.GONE);
|
||||
viewHolder.messageBody.setVisibility(View.VISIBLE);
|
||||
if (message.getBody() != null) {
|
||||
final String nick = getMessageDisplayName(message);
|
||||
final String formattedBody = message.getMergedBody().replaceAll("^/me ", nick + " ");
|
||||
if (message.getType() != Message.TYPE_PRIVATE) {
|
||||
if (message.hasMeCommand()) {
|
||||
final Spannable span = new SpannableString(formattedBody);
|
||||
span.setSpan(new StyleSpan(Typeface.BOLD_ITALIC), 0, nick.length(),
|
||||
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||
viewHolder.messageBody.setText(span);
|
||||
} else {
|
||||
viewHolder.messageBody.setText(message.getMergedBody());
|
||||
}
|
||||
} else {
|
||||
String privateMarker;
|
||||
if (message.getStatus() <= Message.STATUS_RECEIVED) {
|
||||
|
@ -241,15 +263,19 @@ public class MessageAdapter extends ArrayAdapter<Message> {
|
|||
}
|
||||
privateMarker = activity.getString(R.string.private_message_to, to);
|
||||
}
|
||||
SpannableString span = new SpannableString(privateMarker + " "
|
||||
+ message.getBody());
|
||||
span.setSpan(
|
||||
new ForegroundColorSpan(activity
|
||||
final Spannable span = new SpannableString(privateMarker + " "
|
||||
+ formattedBody);
|
||||
span.setSpan(new ForegroundColorSpan(activity
|
||||
.getSecondaryTextColor()), 0, privateMarker
|
||||
.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||
span.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), 0,
|
||||
span.setSpan(new StyleSpan(Typeface.BOLD), 0,
|
||||
privateMarker.length(),
|
||||
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||
if (message.hasMeCommand()) {
|
||||
span.setSpan(new StyleSpan(Typeface.BOLD_ITALIC), privateMarker.length() + 1,
|
||||
privateMarker.length() + 1 + nick.length(),
|
||||
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||
}
|
||||
viewHolder.messageBody.setText(span);
|
||||
}
|
||||
} else {
|
||||
|
@ -281,7 +307,7 @@ public class MessageAdapter extends ArrayAdapter<Message> {
|
|||
viewHolder.image.setVisibility(View.GONE);
|
||||
viewHolder.messageBody.setVisibility(View.GONE);
|
||||
viewHolder.download_button.setVisibility(View.VISIBLE);
|
||||
viewHolder.download_button.setText(activity.getString(R.string.open_file,file.getMimeType()));
|
||||
viewHolder.download_button.setText(activity.getString(R.string.open_file, file.getMimeType()));
|
||||
viewHolder.download_button.setOnClickListener(new OnClickListener() {
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in New Issue