mirror of
https://github.com/moparisthebest/Conversations
synced 2024-12-17 21:22:24 -05:00
Add XEP-0245 (/me command) support
This commit is contained in:
parent
12d63f2612
commit
3c5224251c
@ -9,6 +9,7 @@
|
|||||||
* XEP-0198: Stream Management
|
* XEP-0198: Stream Management
|
||||||
* XEP-0234: Jingle File Transfer
|
* XEP-0234: Jingle File Transfer
|
||||||
* XEP-0237: Roster Versioning
|
* XEP-0237: Roster Versioning
|
||||||
|
* XEP-0245: The /me Command
|
||||||
* XEP-0249: Direct MUC Invitations (receiving only)
|
* XEP-0249: Direct MUC Invitations (receiving only)
|
||||||
* XEP-0260: Jingle SOCKS5 Bytestreams Transport Method
|
* XEP-0260: Jingle SOCKS5 Bytestreams Transport Method
|
||||||
* XEP-0261: Jingle In-Band 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_STATUS = 3;
|
||||||
public static final int TYPE_PRIVATE = 4;
|
public static final int TYPE_PRIVATE = 4;
|
||||||
|
|
||||||
public static String CONVERSATION = "conversationUuid";
|
public static final String CONVERSATION = "conversationUuid";
|
||||||
public static String COUNTERPART = "counterpart";
|
public static final String COUNTERPART = "counterpart";
|
||||||
public static String TRUE_COUNTERPART = "trueCounterpart";
|
public static final String TRUE_COUNTERPART = "trueCounterpart";
|
||||||
public static String BODY = "body";
|
public static final String BODY = "body";
|
||||||
public static String TIME_SENT = "timeSent";
|
public static final String TIME_SENT = "timeSent";
|
||||||
public static String ENCRYPTION = "encryption";
|
public static final String ENCRYPTION = "encryption";
|
||||||
public static String STATUS = "status";
|
public static final String STATUS = "status";
|
||||||
public static String TYPE = "type";
|
public static final String TYPE = "type";
|
||||||
public static String REMOTE_MSG_ID = "remoteMsgId";
|
public static final String REMOTE_MSG_ID = "remoteMsgId";
|
||||||
public static String SERVER_MSG_ID = "serverMsgId";
|
public static final String SERVER_MSG_ID = "serverMsgId";
|
||||||
public static String RELATIVE_FILE_PATH = "relativeFilePath";
|
public static final String RELATIVE_FILE_PATH = "relativeFilePath";
|
||||||
|
|
||||||
public boolean markable = false;
|
public boolean markable = false;
|
||||||
protected String conversationUuid;
|
protected String conversationUuid;
|
||||||
protected Jid counterpart;
|
protected Jid counterpart;
|
||||||
@ -348,17 +349,35 @@ public class Message extends AbstractEntity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean mergeable(final Message message) {
|
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() {
|
public String getMergedBody() {
|
||||||
Message next = this.next();
|
final Message next = this.next();
|
||||||
if (this.mergeable(next)) {
|
if (this.mergeable(next)) {
|
||||||
return body.trim() + '\n' + next.getMergedBody();
|
return getBody() + '\n' + next.getMergedBody();
|
||||||
}
|
}
|
||||||
return body.trim();
|
return body.trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean hasMeCommand() {
|
||||||
|
return getMergedBody().startsWith("/me ");
|
||||||
|
}
|
||||||
|
|
||||||
public int getMergedStatus() {
|
public int getMergedStatus() {
|
||||||
return getStatus();
|
return getStatus();
|
||||||
}
|
}
|
||||||
|
@ -657,7 +657,7 @@ public class ConversationFragment extends Fragment {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
conversation.populateWithMessages(ConversationFragment.this.messageList);
|
conversation.populateWithMessages(ConversationFragment.this.messageList);
|
||||||
for (Message message : this.messageList) {
|
for (final Message message : this.messageList) {
|
||||||
if (message.getEncryption() == Message.ENCRYPTION_PGP
|
if (message.getEncryption() == Message.ENCRYPTION_PGP
|
||||||
&& (message.getStatus() == Message.STATUS_RECEIVED || message
|
&& (message.getStatus() == Message.STATUS_RECEIVED || message
|
||||||
.getStatus() >= Message.STATUS_SEND)
|
.getStatus() >= Message.STATUS_SEND)
|
||||||
|
@ -1,5 +1,15 @@
|
|||||||
package eu.siacs.conversations.ui.adapter;
|
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 java.util.List;
|
||||||
|
|
||||||
import eu.siacs.conversations.R;
|
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.ConversationActivity;
|
||||||
import eu.siacs.conversations.ui.XmppActivity;
|
import eu.siacs.conversations.ui.XmppActivity;
|
||||||
import eu.siacs.conversations.utils.UIHelper;
|
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> {
|
public class ConversationAdapter extends ArrayAdapter<Conversation> {
|
||||||
|
|
||||||
|
@ -144,12 +144,7 @@ public class MessageAdapter extends ArrayAdapter<Message> {
|
|||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
if (multiReceived) {
|
if (multiReceived) {
|
||||||
Contact contact = message.getContact();
|
info = getMessageDisplayName(message);
|
||||||
if (contact != null) {
|
|
||||||
info = contact.getDisplayName();
|
|
||||||
} else {
|
|
||||||
info = getDisplayedMucCounterpart(message.getCounterpart());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -218,15 +213,42 @@ public class MessageAdapter extends ArrayAdapter<Message> {
|
|||||||
viewHolder.messageBody.setTextIsSelectable(false);
|
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) {
|
if (viewHolder.download_button != null) {
|
||||||
viewHolder.download_button.setVisibility(View.GONE);
|
viewHolder.download_button.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
viewHolder.image.setVisibility(View.GONE);
|
viewHolder.image.setVisibility(View.GONE);
|
||||||
viewHolder.messageBody.setVisibility(View.VISIBLE);
|
viewHolder.messageBody.setVisibility(View.VISIBLE);
|
||||||
if (message.getBody() != null) {
|
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.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());
|
viewHolder.messageBody.setText(message.getMergedBody());
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
String privateMarker;
|
String privateMarker;
|
||||||
if (message.getStatus() <= Message.STATUS_RECEIVED) {
|
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);
|
privateMarker = activity.getString(R.string.private_message_to, to);
|
||||||
}
|
}
|
||||||
SpannableString span = new SpannableString(privateMarker + " "
|
final Spannable span = new SpannableString(privateMarker + " "
|
||||||
+ message.getBody());
|
+ formattedBody);
|
||||||
span.setSpan(
|
span.setSpan(new ForegroundColorSpan(activity
|
||||||
new ForegroundColorSpan(activity
|
|
||||||
.getSecondaryTextColor()), 0, privateMarker
|
.getSecondaryTextColor()), 0, privateMarker
|
||||||
.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||||
span.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), 0,
|
span.setSpan(new StyleSpan(Typeface.BOLD), 0,
|
||||||
privateMarker.length(),
|
privateMarker.length(),
|
||||||
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
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);
|
viewHolder.messageBody.setText(span);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user