[guardian-dev] Fwd: Re: [PATCH 0/3] Some fixes for XMPP contact list creation
Nathan Freitas
nathan at freitas.net
Tue Nov 23 12:38:13 EST 2010
-------- Original Message --------
Subject: Re: [PATCH 0/3] Some fixes for XMPP contact list creation
Date: Tue, 23 Nov 2010 12:33:14 -0500
From: Nathan of Guardian <nathan at guardianproject.info>
Organization: The Guardian Project
To: Adrian-Ken Rueegsegger <ken at codelabs.ch>
CC: guardian-dev at lists.mymayfirst.org
Adrian,
As you can see your patches have been applied to master branch. They
seem to be working well now, though I have only really tested them at
this point with my Google Talk account, and no other service. At this
point, with your patch, and an additional fix I just made around
presence callback monitoring, we are seeing a more complete buddy list
load along with changing presence values on those users.
I think we will have to move the "General" string into a strings.xml
file so that we can localize it properly.
There were also a few changes I have made in my effort to debug the
issue with the "General" group presence not being updated. You can see
my patch below that I am about to commit.
I have also put in some debug statements that show how properly get the
Android debugger to work for background services
("android.os.Debug.waitForDebugger();"). These are commented out, but
left in where they might be needed for further debugging.
+nathan
**
diff --git a/src/org/gitian/android/im/plugin/xmpp/XmppConnection.java
b/src/org/gitian/android/im/plugin/xmpp/XmppConnection.java
index a248d0d..f2283c4 100755
--- a/src/org/gitian/android/im/plugin/xmpp/XmppConnection.java
+++ b/src/org/gitian/android/im/plugin/xmpp/XmppConnection.java
@@ -83,7 +83,6 @@ public class XmppConnection extends ImConnection {
mExecutor = Executors.newSingleThreadExecutor();
xmppConnection = this;
-
}
public void sendMessage(org.jivesoftware.smack.packet.Message msg) {
@@ -102,10 +101,14 @@ public class XmppConnection extends ImConnection {
@Override
protected void doUpdateUserPresenceAsync(Presence presence) {
+
+ //android.os.Debug.waitForDebugger();
+
String statusText = presence.getStatusText();
Type type = Type.available;
Mode mode = Mode.available;
int priority = 20;
+
if (presence.getStatus() == Presence.AWAY) {
priority = 10;
mode = Mode.away;
@@ -123,6 +126,7 @@ public class XmppConnection extends ImConnection {
type = Type.unavailable;
statusText = "Offline";
}
+
org.jivesoftware.smack.packet.Presence packet =
new org.jivesoftware.smack.packet.Presence(type, statusText,
priority, mode);
mConnection.sendPacket(packet);
@@ -305,6 +309,9 @@ public class XmppConnection extends ImConnection {
@Override
public void processPacket(Packet packet) {
+
+ //android.os.Debug.waitForDebugger();
+
org.jivesoftware.smack.packet.Presence presence =
(org.jivesoftware.smack.packet.Presence)packet;
if (presence.getType() == Type.subscribe) {
String address = parseAddressBase(presence.getFrom());
@@ -312,6 +319,19 @@ public class XmppConnection extends ImConnection {
Contact contact = findOrCreateContact(address);
mContactListManager.getSubscriptionRequestListener().onSubScriptionRequest(contact);
}
+ else if (presence.getType() == Type.available)
+ {
+ String address = parseAddressBase(presence.getFrom());
+ Log.i(TAG, "got 'available' from " + address);
+
+
+ }
+ else if (presence.getType() == Type.unavailable)
+ {
+ String address = parseAddressBase(presence.getFrom());
+ Log.i(TAG, "got 'unavailable' from " + address);
+ }
+
}
}, new PacketTypeFilter(org.jivesoftware.smack.packet.Presence.class));
@@ -386,7 +406,9 @@ public class XmppConnection extends ImConnection {
org.jivesoftware.smack.packet.Presence presence =
new
org.jivesoftware.smack.packet.Presence(org.jivesoftware.smack.packet.Presence.Type.available);
+
mConnection.sendPacket(presence);
+
}
void disconnected(ImErrorInfo info) {
@@ -667,8 +689,10 @@ public class XmppConnection extends ImConnection {
Roster roster = mConnection.getRoster();
roster.setSubscriptionMode(Roster.SubscriptionMode.manual);
listenToRoster(roster);
+
Set<String> seen = new HashSet<String>();
for (Iterator<RosterGroup> giter = roster.getGroups().iterator();
giter.hasNext();) {
+
RosterGroup group = giter.next();
Collection<Contact> contacts =
fillContacts(group.getEntries().iterator(), seen);
ContactList cl = new ContactList(mUser.getAddress(),
group.getName(), true, contacts, this);
@@ -678,37 +702,61 @@ public class XmppConnection extends ImConnection {
notifyContactListLoaded(cl);
notifyContactsPresenceUpdated(contacts.toArray(new Contact[0]));
}
+
if (roster.getUnfiledEntryCount() > 0) {
+
roster.createGroup("General");
Collection<Contact> contacts =
fillContacts(roster.getUnfiledEntries().iterator(), null);
ContactList cl = new ContactList(mUser.getAddress(), "General" ,
true, contacts, this);
+
+ //n8fr8: adding this contact list to the master list manager seems
like the righ thing to do
+ mContactLists.add(cl);
mDefaultContactList = cl;
notifyContactListLoaded(cl);
+
+ //n8fr8: also needs to ping the presence status change, too!
+ notifyContactsPresenceUpdated(contacts.toArray(new Contact[0]));
+
}
notifyContactListsLoaded();
+
+
}
private void listenToRoster(final Roster roster) {
+
roster.addRosterListener(new RosterListener() {
@Override
public void presenceChanged(org.jivesoftware.smack.packet.Presence
presence) {
+
+ //android.os.Debug.waitForDebugger(); //this is for debugging a
service
+
String user = parseAddressBase(presence.getFrom());
+
Contact contact = mContactListManager.getContact(user);
+
if (contact == null)
+ {
+ Log.d(TAG, "Got present update for NULL user: " + user);
return;
+ }
+
Contact []contacts = new Contact[] { contact };
// Get it from the roster - it handles priorities, etc.
presence = roster.getPresence(user);
+
int type = Presence.AVAILABLE;
Mode rmode = presence.getMode();
Type rtype = presence.getType();
+
if (rmode == Mode.away || rmode == Mode.xa)
type = Presence.AWAY;
if (rmode == Mode.dnd)
type = Presence.DO_NOT_DISTURB;
if (rtype == Type.unavailable)
type = Presence.OFFLINE;
+
contact.setPresence(new Presence(type, presence.getStatus(), null,
null, Presence.CLIENT_TYPE_DEFAULT));
notifyContactsPresenceUpdated(contacts);
}
@@ -717,6 +765,9 @@ public class XmppConnection extends ImConnection {
public void entriesUpdated(Collection<String> addresses) {
// TODO update contact list entries from remote
Log.d(TAG, "roster entries updated");
+
+
+
}
@Override
On 11/20/2010 10:56 AM, Adrian-Ken Rueegsegger wrote:
> There are some issues in Gibber with regards to contact list creation. Some
> users have filed reports to the github site saying that the contact list is not
> properly populated.
>
> The bug was that only contacts which belong to a group were processed so all
> others simply did not show up. The first patch fixes this by adding all unfiled
> entries in the user's roster to the default list.
>
> The other two patches are some minor cleanup/refactor patches. My Java is
> rather rusty since I have not used it in years so I would be glad if you could
> comment on the patches and also on the style and provide some information on how
> to things should be done properly. Also since this is my first submission of
> patches to this project I was not sure what the prefered workflow is. Please
> tell me if sending patches to the dev mailing list is not the proper way and how
> it should be done properly. Thanks!
>
> Cheers,
> Adrian
More information about the Guardian-dev
mailing list