Skip to content

Commit

Permalink
Add XEP-0245 (/me command) support
Browse files Browse the repository at this point in the history
  • Loading branch information
SamWhited committed Jan 11, 2015
1 parent 12d63f2 commit 3c52242
Show file tree
Hide file tree
Showing 5 changed files with 206 additions and 159 deletions.
1 change: 1 addition & 0 deletions docs/XEPs.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
47 changes: 33 additions & 14 deletions src/main/java/eu/siacs/conversations/entities/Message.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -348,17 +349,35 @@ public Message prev() {
}

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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -425,16 +425,16 @@ private void populateContextMenu(ContextMenu menu) {
if ((m.getType() != Message.TYPE_IMAGE && m.getDownloadable() == null)
|| m.getImageParams().url == null) {
copyUrl.setVisible(false);
}
}
if (m.getType() != Message.TYPE_TEXT
|| m.getDownloadable() != null
|| !m.bodyContainsDownloadable()) {
downloadImage.setVisible(false);
}
}
if (!((m.getDownloadable() != null && !(m.getDownloadable() instanceof DownloadablePlaceholder))
|| (m.isFileOrImage() && m.getStatus() == Message.STATUS_WAITING))) {
|| (m.isFileOrImage() && m.getStatus() == Message.STATUS_WAITING))) {
cancelTransmission.setVisible(false);
}
}
}
}

Expand Down Expand Up @@ -657,7 +657,7 @@ public void onClick(View v) {
}
}
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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -10,15 +20,6 @@
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> {

Expand Down
Loading

0 comments on commit 3c52242

Please sign in to comment.