aboutsummaryrefslogtreecommitdiffstats
path: root/src/main
diff options
context:
space:
mode:
authorChristian Schneppe <christian@pix-art.de>2017-03-11 12:08:30 +0100
committerChristian Schneppe <christian@pix-art.de>2017-03-11 20:14:57 +0100
commit3e932930713e1dfaf141878dfb6dea8fea23ab7a (patch)
treecf69f4ef2f0c364624f58216f11d8a7af00de328 /src/main
parent4980a39d8c8c250e3559926ee4f0034ec9d86e6f (diff)
send and parse Chat States to and from conferences
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/de/pixart/messenger/entities/Conversation.java2
-rw-r--r--src/main/java/de/pixart/messenger/entities/MucOptions.java35
-rw-r--r--src/main/java/de/pixart/messenger/generator/MessageGenerator.java2
-rw-r--r--src/main/java/de/pixart/messenger/parser/MessageParser.java27
-rw-r--r--src/main/java/de/pixart/messenger/services/XmppConnectionService.java6
-rw-r--r--src/main/java/de/pixart/messenger/ui/ConversationFragment.java5
6 files changed, 63 insertions, 14 deletions
diff --git a/src/main/java/de/pixart/messenger/entities/Conversation.java b/src/main/java/de/pixart/messenger/entities/Conversation.java
index fe8031b2a..082877ef7 100644
--- a/src/main/java/de/pixart/messenger/entities/Conversation.java
+++ b/src/main/java/de/pixart/messenger/entities/Conversation.java
@@ -209,7 +209,7 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl
}
public boolean setOutgoingChatState(ChatState state) {
- if (mode == MODE_MULTI) {
+ if (mode == MODE_MULTI && getNextCounterpart() != null) {
return false;
}
if (this.mOutgoingChatState != state) {
diff --git a/src/main/java/de/pixart/messenger/entities/MucOptions.java b/src/main/java/de/pixart/messenger/entities/MucOptions.java
index 5831a7da5..d3d0e3e9e 100644
--- a/src/main/java/de/pixart/messenger/entities/MucOptions.java
+++ b/src/main/java/de/pixart/messenger/entities/MucOptions.java
@@ -7,8 +7,10 @@ import java.util.HashSet;
import java.util.List;
import java.util.Set;
+import de.pixart.messenger.Config;
import de.pixart.messenger.R;
import de.pixart.messenger.utils.Namespace;
+import de.pixart.messenger.xmpp.chatstate.ChatState;
import de.pixart.messenger.xmpp.forms.Data;
import de.pixart.messenger.xmpp.forms.Field;
import de.pixart.messenger.xmpp.jid.InvalidJidException;
@@ -49,6 +51,18 @@ public class MucOptions {
return mAutoPushConfiguration;
}
+ public boolean isSelf(Jid counterpart) {
+ return counterpart.getResourcepart().equals(getActualNick());
+ }
+
+ public void resetChatState() {
+ synchronized (users) {
+ for (User user : users) {
+ user.chatState = Config.DEFAULT_CHATSTATE;
+ }
+ }
+ }
+
public enum Affiliation {
OWNER("owner", 4, R.string.owner),
ADMIN("admin", 3, R.string.admin),
@@ -154,6 +168,7 @@ public class MucOptions {
private long pgpKeyId = 0;
private Avatar avatar;
private MucOptions options;
+ private ChatState chatState = Config.DEFAULT_CHATSTATE;
public User(MucOptions options, Jid from) {
this.options = options;
@@ -319,6 +334,14 @@ public class MucOptions {
public Jid getRealJid() {
return realJid;
}
+
+ public boolean setChatState(ChatState chatState) {
+ if (this.chatState == chatState) {
+ return false;
+ }
+ this.chatState = chatState;
+ return true;
+ }
}
private Account account;
@@ -519,6 +542,18 @@ public class MucOptions {
}
}
+ public ArrayList<User> getUsersWithChatState(ChatState state) {
+ synchronized (users) {
+ ArrayList<User> list = new ArrayList<>();
+ for (User user : users) {
+ if (user.chatState == state) {
+ list.add(user);
+ }
+ }
+ return list;
+ }
+ }
+
public List<User> getUsers(int max) {
ArrayList<User> subset = new ArrayList<>();
HashSet<Jid> jids = new HashSet<>();
diff --git a/src/main/java/de/pixart/messenger/generator/MessageGenerator.java b/src/main/java/de/pixart/messenger/generator/MessageGenerator.java
index 1b1a3480a..b46d58574 100644
--- a/src/main/java/de/pixart/messenger/generator/MessageGenerator.java
+++ b/src/main/java/de/pixart/messenger/generator/MessageGenerator.java
@@ -151,7 +151,7 @@ public class MessageGenerator extends AbstractGenerator {
public MessagePacket generateChatState(Conversation conversation) {
final Account account = conversation.getAccount();
MessagePacket packet = new MessagePacket();
- packet.setType(MessagePacket.TYPE_CHAT);
+ packet.setType(conversation.getMode() == Conversation.MODE_MULTI ? MessagePacket.TYPE_GROUPCHAT : MessagePacket.TYPE_CHAT);
packet.setTo(conversation.getJid().toBareJid());
packet.setFrom(account.getJid());
packet.addChild(ChatState.toElement(conversation.getOutgoingChatState()));
diff --git a/src/main/java/de/pixart/messenger/parser/MessageParser.java b/src/main/java/de/pixart/messenger/parser/MessageParser.java
index 2fa7160b6..baa3b4d79 100644
--- a/src/main/java/de/pixart/messenger/parser/MessageParser.java
+++ b/src/main/java/de/pixart/messenger/parser/MessageParser.java
@@ -47,20 +47,29 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece
super(service);
}
- private boolean extractChatState(Conversation conversation, final MessagePacket packet) {
+ private boolean extractChatState(Conversation c, final boolean isTypeGroupChat, final MessagePacket packet) {
ChatState state = ChatState.parse(packet);
- if (state != null && conversation != null) {
- final Account account = conversation.getAccount();
+ if (state != null && c != null) {
+ final Account account = c.getAccount();
Jid from = packet.getFrom();
if (from.toBareJid().equals(account.getJid().toBareJid())) {
- conversation.setOutgoingChatState(state);
+ c.setOutgoingChatState(state);
if (state == ChatState.ACTIVE || state == ChatState.COMPOSING) {
- mXmppConnectionService.markRead(conversation);
+ mXmppConnectionService.markRead(c);
activateGracePeriod(account);
}
return false;
} else {
- return conversation.setIncomingChatState(state);
+ if (isTypeGroupChat) {
+ MucOptions.User user = c.getMucOptions().findUserByFullJid(from);
+ if (user != null) {
+ return user.setChatState(state);
+ } else {
+ return false;
+ }
+ } else {
+ return c.setIncomingChatState(state);
+ }
}
}
return false;
@@ -395,9 +404,7 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece
return;
}
- if (!isTypeGroupChat
- && query == null
- && extractChatState(mXmppConnectionService.find(account, counterpart.toBareJid()), packet)) {
+ if (query == null && extractChatState(mXmppConnectionService.find(account, counterpart.toBareJid()), isTypeGroupChat, packet)) {
mXmppConnectionService.updateConversationUi();
}
@@ -408,7 +415,7 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece
serverMsgId = extractStanzaId(packet, isTypeGroupChat, conversation);
}
if (isTypeGroupChat) {
- if (counterpart.getResourcepart().equals(conversation.getMucOptions().getActualNick())) {
+ if (conversation.getMucOptions().isSelf(counterpart)) {
status = Message.STATUS_SEND_RECEIVED;
isCarbon = true; //not really carbon but received from another resource
if (mXmppConnectionService.markMessage(conversation, remoteMsgId, status, serverMsgId)) {
diff --git a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java
index a97a0d78b..48c816f03 100644
--- a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java
+++ b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java
@@ -2239,7 +2239,11 @@ public class XmppConnectionService extends Service {
private void switchToForeground() {
final boolean broadcastLastActivity = broadcastLastActivity();
for (Conversation conversation : getConversations()) {
- conversation.setIncomingChatState(ChatState.ACTIVE);
+ if (conversation.getMode() == Conversation.MODE_MULTI) {
+ conversation.getMucOptions().resetChatState();
+ } else {
+ conversation.setIncomingChatState(Config.DEFAULT_CHATSTATE);
+ }
}
for (Account account : getAccounts()) {
if (account.getStatus() == Account.State.ONLINE) {
diff --git a/src/main/java/de/pixart/messenger/ui/ConversationFragment.java b/src/main/java/de/pixart/messenger/ui/ConversationFragment.java
index 053db4545..069708b26 100644
--- a/src/main/java/de/pixart/messenger/ui/ConversationFragment.java
+++ b/src/main/java/de/pixart/messenger/ui/ConversationFragment.java
@@ -862,7 +862,10 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
}
protected void privateMessageWith(final Jid counterpart) {
- this.mEditMessage.setText("");
+ if (conversation.setOutgoingChatState(Config.DEFAULT_CHATSTATE)) {
+ activity.xmppConnectionService.sendChatState(conversation);
+ }
+ this.mEditMessage.getEditableText().clear();
this.conversation.setNextCounterpart(counterpart);
updateChatMsgHint();
updateSendButton();