Skip to content

Commit

Permalink
Use data from broadcast about specific contact (fix #358)
Browse files Browse the repository at this point in the history
Signed-off-by: Daniele Ricci <[email protected]>
  • Loading branch information
daniele-athome committed Mar 26, 2015
1 parent ae2f251 commit 22b05b4
Showing 1 changed file with 36 additions and 37 deletions.
73 changes: 36 additions & 37 deletions app/src/main/java/org/kontalk/ui/ComposeMessageFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -1926,39 +1926,40 @@ public void onReceive(Context context, Intent intent) {
String action = intent.getAction();

if (MessageCenterService.ACTION_PRESENCE.equals(action)) {
String from = intent.getStringExtra(MessageCenterService.EXTRA_FROM);
String bareFrom = from != null ? XmppStringUtils.parseBareJid(from) : null;

// we handle only (un)available presence stanzas
String type = intent.getStringExtra(MessageCenterService.EXTRA_TYPE);
// we are receiving a presence from our peer
if (from != null && bareFrom.equalsIgnoreCase(mUserJID)) {

if (type == null) {
// no roster entry found, request subscription
// we handle only (un)available presence stanzas
String type = intent.getStringExtra(MessageCenterService.EXTRA_TYPE);

// pre-approve our presence if we don't have contact's key
Intent i = new Intent(context, MessageCenterService.class);
i.setAction(MessageCenterService.ACTION_PRESENCE);
i.putExtra(MessageCenterService.EXTRA_TO, mUserJID);
i.putExtra(MessageCenterService.EXTRA_TYPE, Presence.Type.subscribed.name());
context.startService(i);
if (type == null) {
// no roster entry found, request subscription

// request subscription
i = new Intent(context, MessageCenterService.class);
i.setAction(MessageCenterService.ACTION_PRESENCE);
i.putExtra(MessageCenterService.EXTRA_TO, mUserJID);
i.putExtra(MessageCenterService.EXTRA_TYPE, Presence.Type.subscribe.name());
context.startService(i);
// pre-approve our presence if we don't have contact's key
Intent i = new Intent(context, MessageCenterService.class);
i.setAction(MessageCenterService.ACTION_PRESENCE);
i.putExtra(MessageCenterService.EXTRA_TO, mUserJID);
i.putExtra(MessageCenterService.EXTRA_TYPE, Presence.Type.subscribed.name());
context.startService(i);

setStatusText(getString(R.string.invitation_sent_label));
}
// request subscription
i = new Intent(context, MessageCenterService.class);
i.setAction(MessageCenterService.ACTION_PRESENCE);
i.putExtra(MessageCenterService.EXTRA_TO, mUserJID);
i.putExtra(MessageCenterService.EXTRA_TYPE, Presence.Type.subscribe.name());
context.startService(i);

else if (Presence.Type.available.name().equals(type) || Presence.Type.unavailable.name().equals(type)) {
setStatusText(getString(R.string.invitation_sent_label));
}

CharSequence statusText = null;
// (un)available presence
else if (Presence.Type.available.name().equals(type) || Presence.Type.unavailable.name().equals(type)) {

String from = intent.getStringExtra(MessageCenterService.EXTRA_FROM);
String bareFrom = from != null ? XmppStringUtils.parseBareJid(from) : null;
CharSequence statusText = null;

// we are receiving a presence from our peer, upgrade available resources
if (from != null && bareFrom.equalsIgnoreCase(mUserJID)) {
// really not much sense in requesting the key for a non-existing contact
Contact contact = mConversation != null ? mConversation.getContact() : null;
if (contact != null) {
Expand All @@ -1983,8 +1984,7 @@ else if (Presence.Type.available.name().equals(type) || Presence.Type.unavailabl
if (Presence.Type.available.toString().equals(type)) {
mAvailableResources.add(from);
statusText = getString(R.string.seen_online_label);
}
else if (Presence.Type.unavailable.toString().equals(type)) {
} else if (Presence.Type.unavailable.toString().equals(type)) {
mAvailableResources.remove(from);
/*
* All available resources have gone. Mark
Expand All @@ -1999,24 +1999,23 @@ else if (Presence.Type.unavailable.toString().equals(type)) {
long stamp = intent.getLongExtra(MessageCenterService.EXTRA_STAMP, -1);
if (stamp >= 0 && ((System.currentTimeMillis() - stamp) > PRESENCE_DELAY_THRESHOLD)) {
statusText = MessageUtils.formatRelativeTimeSpan(context, stamp);
}
else {
} else {
statusText = getString(R.string.seen_moment_ago_label);
}
}
}
}

if (statusText != null) {
mCurrentStatus = statusText;
if (!mIsTyping)
setStatusText(statusText);
if (statusText != null) {
mCurrentStatus = statusText;
if (!mIsTyping)
setStatusText(statusText);
}
}
}

// subscription accepted, probe presence
else if (Presence.Type.subscribed.name().equals(type)) {
presenceSubscribe();
// subscription accepted, probe presence
else if (Presence.Type.subscribed.name().equals(type)) {
presenceSubscribe();
}
}
}

Expand Down

0 comments on commit 22b05b4

Please sign in to comment.