mirror of
https://github.com/moparisthebest/Conversations
synced 2024-11-28 11:42:15 -05:00
pending leaves and joins for muc
This commit is contained in:
parent
9cfb4ee6c3
commit
c65600edc9
@ -1,12 +1,9 @@
|
|||||||
package eu.siacs.conversations.entities;
|
package eu.siacs.conversations.entities;
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
|
|
||||||
import android.content.ContentValues;
|
import android.content.ContentValues;
|
||||||
|
|
||||||
public abstract class AbstractEntity implements Serializable {
|
public abstract class AbstractEntity {
|
||||||
|
|
||||||
private static final long serialVersionUID = -1895605706690653719L;
|
|
||||||
|
|
||||||
public static final String UUID = "uuid";
|
public static final String UUID = "uuid";
|
||||||
|
|
||||||
|
@ -4,6 +4,7 @@ import java.security.interfaces.DSAPublicKey;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
import java.util.concurrent.CopyOnWriteArrayList;
|
||||||
|
|
||||||
import net.java.otr4j.crypto.OtrCryptoEngineImpl;
|
import net.java.otr4j.crypto.OtrCryptoEngineImpl;
|
||||||
import net.java.otr4j.crypto.OtrCryptoException;
|
import net.java.otr4j.crypto.OtrCryptoException;
|
||||||
@ -18,8 +19,6 @@ import android.content.Context;
|
|||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
|
|
||||||
public class Account extends AbstractEntity{
|
public class Account extends AbstractEntity{
|
||||||
|
|
||||||
private static final long serialVersionUID = 6174825093869578035L;
|
|
||||||
|
|
||||||
public static final String TABLENAME = "accounts";
|
public static final String TABLENAME = "accounts";
|
||||||
|
|
||||||
@ -72,6 +71,9 @@ public class Account extends AbstractEntity{
|
|||||||
|
|
||||||
private List<Bookmark> bookmarks = new ArrayList<Bookmark>();
|
private List<Bookmark> bookmarks = new ArrayList<Bookmark>();
|
||||||
|
|
||||||
|
public List<Conversation> pendingConferenceJoins = new CopyOnWriteArrayList<Conversation>();
|
||||||
|
public List<Conversation> pendingConferenceLeaves = new CopyOnWriteArrayList<Conversation>();
|
||||||
|
|
||||||
public Account() {
|
public Account() {
|
||||||
this.uuid = "0";
|
this.uuid = "0";
|
||||||
}
|
}
|
||||||
|
@ -16,9 +16,6 @@ import android.database.Cursor;
|
|||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
|
|
||||||
public class Conversation extends AbstractEntity {
|
public class Conversation extends AbstractEntity {
|
||||||
|
|
||||||
private static final long serialVersionUID = -6727528868973996739L;
|
|
||||||
|
|
||||||
public static final String TABLENAME = "conversations";
|
public static final String TABLENAME = "conversations";
|
||||||
|
|
||||||
public static final int STATUS_AVAILABLE = 0;
|
public static final int STATUS_AVAILABLE = 0;
|
||||||
|
@ -7,8 +7,6 @@ import android.content.Context;
|
|||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
|
|
||||||
public class Message extends AbstractEntity {
|
public class Message extends AbstractEntity {
|
||||||
|
|
||||||
private static final long serialVersionUID = 7222081895167103025L;
|
|
||||||
|
|
||||||
public static final String TABLENAME = "messages";
|
public static final String TABLENAME = "messages";
|
||||||
|
|
||||||
|
@ -148,6 +148,12 @@ public class XmppConnectionService extends Service {
|
|||||||
mOnAccountUpdate.onAccountUpdate();;
|
mOnAccountUpdate.onAccountUpdate();;
|
||||||
}
|
}
|
||||||
if (account.getStatus() == Account.STATUS_ONLINE) {
|
if (account.getStatus() == Account.STATUS_ONLINE) {
|
||||||
|
for(Conversation conversation : account.pendingConferenceLeaves) {
|
||||||
|
leaveMuc(conversation);
|
||||||
|
}
|
||||||
|
for(Conversation conversation : account.pendingConferenceJoins) {
|
||||||
|
joinMuc(conversation);
|
||||||
|
}
|
||||||
mJingleConnectionManager.cancelInTransmission();
|
mJingleConnectionManager.cancelInTransmission();
|
||||||
List<Conversation> conversations = getConversations();
|
List<Conversation> conversations = getConversations();
|
||||||
for (int i = 0; i < conversations.size(); ++i) {
|
for (int i = 0; i < conversations.size(); ++i) {
|
||||||
@ -196,6 +202,21 @@ public class XmppConnectionService extends Service {
|
|||||||
private PendingIntent pendingPingIntent = null;
|
private PendingIntent pendingPingIntent = null;
|
||||||
private WakeLock wakeLock;
|
private WakeLock wakeLock;
|
||||||
private PowerManager pm;
|
private PowerManager pm;
|
||||||
|
private OnBindListener mOnBindListener = new OnBindListener() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onBind(final Account account) {
|
||||||
|
account.getRoster().clearPresences();
|
||||||
|
account.clearPresences(); // self presences
|
||||||
|
account.pendingConferenceJoins.clear();
|
||||||
|
account.pendingConferenceLeaves.clear();
|
||||||
|
fetchRosterFromServer(account);
|
||||||
|
fetchBookmarks(account);
|
||||||
|
sendPresencePacket(account, mPresenceGenerator.sendPresence(account));
|
||||||
|
connectMultiModeConversations(account);
|
||||||
|
updateConversationUi();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
public PgpEngine getPgpEngine() {
|
public PgpEngine getPgpEngine() {
|
||||||
if (pgpServiceConnection.isBound()) {
|
if (pgpServiceConnection.isBound()) {
|
||||||
@ -465,19 +486,7 @@ public class XmppConnectionService extends Service {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
connection.setOnBindListener(new OnBindListener() {
|
connection.setOnBindListener(this.mOnBindListener);
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onBind(final Account account) {
|
|
||||||
account.getRoster().clearPresences();
|
|
||||||
account.clearPresences(); // self presences
|
|
||||||
fetchRosterFromServer(account);
|
|
||||||
fetchBookmarks(account);
|
|
||||||
sendPresencePacket(account, mPresenceGenerator.sendPresence(account));
|
|
||||||
connectMultiModeConversations(account);
|
|
||||||
updateConversationUi();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return connection;
|
return connection;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -682,7 +691,6 @@ public class XmppConnectionService extends Service {
|
|||||||
if (storage!=null) {
|
if (storage!=null) {
|
||||||
for(Element item : storage.getChildren()) {
|
for(Element item : storage.getChildren()) {
|
||||||
if (item.getName().equals("conference")) {
|
if (item.getName().equals("conference")) {
|
||||||
Log.d(LOGTAG,item.toString());
|
|
||||||
Bookmark bookmark = Bookmark.parse(item,account);
|
Bookmark bookmark = Bookmark.parse(item,account);
|
||||||
bookmarks.add(bookmark);
|
bookmarks.add(bookmark);
|
||||||
Conversation conversation = findMuc(bookmark);
|
Conversation conversation = findMuc(bookmark);
|
||||||
@ -939,30 +947,36 @@ public class XmppConnectionService extends Service {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void joinMuc(Conversation conversation) {
|
public void joinMuc(Conversation conversation) {
|
||||||
Log.d(LOGTAG,"joining conversation "+conversation.getContactJid());
|
|
||||||
Account account = conversation.getAccount();
|
Account account = conversation.getAccount();
|
||||||
String nick = conversation.getMucOptions().getProposedNick();
|
account.pendingConferenceJoins.remove(conversation);
|
||||||
conversation.getMucOptions().setJoinNick(nick);
|
account.pendingConferenceLeaves.remove(conversation);
|
||||||
PresencePacket packet = new PresencePacket();
|
if (account.getStatus() == Account.STATUS_ONLINE) {
|
||||||
packet.setAttribute("to",conversation.getMucOptions().getJoinJid());
|
Log.d(LOGTAG,"joining conversation "+conversation.getContactJid());
|
||||||
Element x = new Element("x");
|
String nick = conversation.getMucOptions().getProposedNick();
|
||||||
x.setAttribute("xmlns", "http://jabber.org/protocol/muc");
|
conversation.getMucOptions().setJoinNick(nick);
|
||||||
String sig = account.getPgpSignature();
|
PresencePacket packet = new PresencePacket();
|
||||||
if (sig != null) {
|
packet.setAttribute("to",conversation.getMucOptions().getJoinJid());
|
||||||
packet.addChild("status").setContent("online");
|
Element x = new Element("x");
|
||||||
packet.addChild("x", "jabber:x:signed").setContent(sig);
|
x.setAttribute("xmlns", "http://jabber.org/protocol/muc");
|
||||||
|
String sig = account.getPgpSignature();
|
||||||
|
if (sig != null) {
|
||||||
|
packet.addChild("status").setContent("online");
|
||||||
|
packet.addChild("x", "jabber:x:signed").setContent(sig);
|
||||||
|
}
|
||||||
|
if (conversation.getMessages().size() != 0) {
|
||||||
|
final SimpleDateFormat mDateFormat = new SimpleDateFormat(
|
||||||
|
"yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", Locale.US);
|
||||||
|
mDateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
|
||||||
|
Date date = new Date(
|
||||||
|
conversation.getLatestMessage().getTimeSent() + 1000);
|
||||||
|
x.addChild("history").setAttribute("since",
|
||||||
|
mDateFormat.format(date));
|
||||||
|
}
|
||||||
|
packet.addChild(x);
|
||||||
|
sendPresencePacket(account, packet);
|
||||||
|
} else {
|
||||||
|
account.pendingConferenceJoins.add(conversation);
|
||||||
}
|
}
|
||||||
if (conversation.getMessages().size() != 0) {
|
|
||||||
final SimpleDateFormat mDateFormat = new SimpleDateFormat(
|
|
||||||
"yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", Locale.US);
|
|
||||||
mDateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
|
|
||||||
Date date = new Date(
|
|
||||||
conversation.getLatestMessage().getTimeSent() + 1000);
|
|
||||||
x.addChild("history").setAttribute("since",
|
|
||||||
mDateFormat.format(date));
|
|
||||||
}
|
|
||||||
packet.addChild(x);
|
|
||||||
sendPresencePacket(account, packet);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private OnRenameListener renameListener = null;
|
private OnRenameListener renameListener = null;
|
||||||
@ -1020,14 +1034,21 @@ public class XmppConnectionService extends Service {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void leaveMuc(Conversation conversation) {
|
public void leaveMuc(Conversation conversation) {
|
||||||
PresencePacket packet = new PresencePacket();
|
Account account = conversation.getAccount();
|
||||||
packet.setAttribute("to", conversation.getMucOptions().getJoinJid());
|
account.pendingConferenceJoins.remove(conversation);
|
||||||
packet.setAttribute("from", conversation.getAccount().getFullJid());
|
account.pendingConferenceLeaves.remove(conversation);
|
||||||
packet.setAttribute("type", "unavailable");
|
if (account.getStatus() == Account.STATUS_ONLINE) {
|
||||||
sendPresencePacket(conversation.getAccount(),packet);
|
PresencePacket packet = new PresencePacket();
|
||||||
conversation.getMucOptions().setOffline();
|
packet.setAttribute("to", conversation.getMucOptions().getJoinJid());
|
||||||
conversation.deregisterWithBookmark();
|
packet.setAttribute("from", conversation.getAccount().getFullJid());
|
||||||
Log.d(LOGTAG,conversation.getAccount().getJid()+" leaving muc "+conversation.getContactJid());
|
packet.setAttribute("type", "unavailable");
|
||||||
|
sendPresencePacket(conversation.getAccount(),packet);
|
||||||
|
conversation.getMucOptions().setOffline();
|
||||||
|
conversation.deregisterWithBookmark();
|
||||||
|
Log.d(LOGTAG,conversation.getAccount().getJid()+" leaving muc "+conversation.getContactJid());
|
||||||
|
} else {
|
||||||
|
account.pendingConferenceLeaves.add(conversation);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void disconnect(Account account, boolean force) {
|
public void disconnect(Account account, boolean force) {
|
||||||
@ -1210,7 +1231,7 @@ public class XmppConnectionService extends Service {
|
|||||||
x.addChild(invite);
|
x.addChild(invite);
|
||||||
packet.addChild(x);
|
packet.addChild(x);
|
||||||
sendMessagePacket(account,packet);
|
sendMessagePacket(account,packet);
|
||||||
|
Log.d(LOGTAG,packet.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean markMessage(Account account, String recipient, String uuid,
|
public boolean markMessage(Account account, String recipient, String uuid,
|
||||||
|
Loading…
Reference in New Issue
Block a user