Skip to content
This repository has been archived by the owner on Sep 2, 2021. It is now read-only.

Commit

Permalink
addresses #177 multiple notification bug, and improves UI for friends
Browse files Browse the repository at this point in the history
  • Loading branch information
n8fr8 committed May 5, 2017
1 parent 84c54b7 commit 2d61deb
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@
import org.jivesoftware.smackx.xdata.FormField;
import org.jivesoftware.smackx.xdata.provider.DataFormProvider;
import org.jivesoftware.smackx.xhtmlim.provider.XHTMLExtensionProvider;
import org.jxmpp.jid.BareJid;
import org.jxmpp.jid.DomainBareJid;
import org.jxmpp.jid.EntityBareJid;
import org.jxmpp.jid.EntityFullJid;
Expand Down Expand Up @@ -422,28 +423,8 @@ private boolean loadVCard (ContentResolver resolver, String jid)
debug(TAG, "found avatar image in vcard for: " + bareJid.toString());
debug(TAG, "start avatar length: " + avatarBytes.length);

/**
int width = ImApp.DEFAULT_AVATAR_WIDTH;
int height = ImApp.DEFAULT_AVATAR_HEIGHT;
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeByteArray(avatarBytes, 0, avatarBytes.length,options);
options.inSampleSize = DatabaseUtils.calculateInSampleSize(options, width, height);
options.inJustDecodeBounds = false;
Bitmap b = BitmapFactory.decodeByteArray(avatarBytes, 0, avatarBytes.length,options);
b = Bitmap.createScaledBitmap(b, ImApp.DEFAULT_AVATAR_WIDTH, ImApp.DEFAULT_AVATAR_HEIGHT, false);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
b.compress(Bitmap.CompressFormat.JPEG, 80, stream);
byte[] avatarBytesCompressed = stream.toByteArray();
debug(TAG, "compressed avatar length: " + avatarBytesCompressed.length);**/

DatabaseUtils.insertAvatarBlob(resolver, Imps.Avatars.CONTENT_URI, mProviderId, mAccountId, avatarBytes, avatarHash, bareJid.toString());

// int providerId, int accountId, byte[] data, String hash,String contact
return true;
}
}
Expand Down Expand Up @@ -2947,22 +2928,44 @@ protected void doAddContactToListAsync(Contact contact, ContactList list, boolea
}

try {
rEntry = mRoster.getEntry(JidCreate.bareFrom(contact.getAddress().getBareAddress()));

BareJid jid = JidCreate.bareFrom(contact.getAddress().getBareAddress());

rEntry = mRoster.getEntry(jid);
RosterGroup rGroup = mRoster.getGroup(list.getName());

if (rGroup == null)
{
if (rEntry == null) {

addRosterEntry(contact.getAddress().getBareAddress(), contact.getName(), null, subPending, type);
rEntry = mRoster.getEntry(JidCreate.bareFrom(contact.getAddress().getBareAddress()));
rEntry = mRoster.getEntry(jid);
}

}
else if (rEntry == null)
{
addRosterEntry(contact.getAddress().getBareAddress(), contact.getName(), groups, subPending, type);
rEntry = mRoster.getEntry(JidCreate.bareFrom(contact.getAddress().getBareAddress()));
rEntry = mRoster.getEntry(jid);
}



if (autoSubscribedPresence) {

//i want your presence
org.jivesoftware.smack.packet.Presence reqSubscribe = new org.jivesoftware.smack.packet.Presence(
org.jivesoftware.smack.packet.Presence.Type.subscribe);
reqSubscribe.setTo(jid);
sendPacket(reqSubscribe);

mRoster.preApprove(jid);

ChatSession session = findOrCreateSession(contact.getAddress().toString(), false);

if (session != null)
session.setSubscribed(true);

}


Expand All @@ -2976,21 +2979,6 @@ else if (rEntry == null)
throw new ImException(msg);
}

if (autoSubscribedPresence) {

//i want your presence
org.jivesoftware.smack.packet.Presence reqSubscribe = new org.jivesoftware.smack.packet.Presence(
org.jivesoftware.smack.packet.Presence.Type.subscribe);
reqSubscribe.setTo(contact.getAddress().getBareAddress());
sendPacket(reqSubscribe);

ChatSession session = findOrCreateSession(contact.getAddress().toString(), false);

if (session != null)
session.setSubscribed(true);

}

notifyContactListUpdated(list, ContactListListener.LIST_CONTACT_ADDED, contact);

}
Expand Down Expand Up @@ -3080,14 +3068,8 @@ public void approveSubscriptionRequest(final Contact contact) {
response.setTo(contact.getAddress().getBareAddress());
sendPacket(response);

response = new org.jivesoftware.smack.packet.Presence(
org.jivesoftware.smack.packet.Presence.Type.subscribe);
response.setTo(contact.getAddress().getBareAddress());
sendPacket(response);


// try { mRoster.reload(); }
// catch (Exception e){}
try { mRoster.reload(); }
catch (Exception e){}

try
{
Expand Down Expand Up @@ -3981,10 +3963,12 @@ else if (presence.getType() == org.jivesoftware.smack.packet.Presence.Type.subsc
try
{
//i want your presence
/**
org.jivesoftware.smack.packet.Presence reqSubscribe = new org.jivesoftware.smack.packet.Presence(
org.jivesoftware.smack.packet.Presence.Type.subscribed);
reqSubscribe.setTo(contact.getAddress().getBareAddress());
sendPacket(reqSubscribe);
**/

if (contact == null) {
XmppAddress xAddr = new XmppAddress(presence.getFrom().toString());
Expand Down
28 changes: 10 additions & 18 deletions app/src/main/java/org/awesomeapp/messenger/ui/ConversationView.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import android.os.Message;
import android.os.RemoteException;
import android.provider.Browser;
import android.support.design.widget.Snackbar;
import android.support.v4.app.LoaderManager;
import android.support.v4.content.CursorLoader;
import android.support.v4.content.Loader;
Expand Down Expand Up @@ -84,6 +85,7 @@
import net.java.otr4j.session.SessionStatus;

import org.awesomeapp.messenger.ImApp;
import org.awesomeapp.messenger.MainActivity;
import org.awesomeapp.messenger.Preferences;
import org.awesomeapp.messenger.bho.DictionarySearch;
import org.awesomeapp.messenger.crypto.IOtrChatSession;
Expand Down Expand Up @@ -1252,24 +1254,14 @@ private void updateSessionInfo(Cursor c) {

mSubscriptionStatus = c.getInt(SUBSCRIPTION_STATUS_COLUMN);
if (mSubscriptionStatus == Imps.Contacts.SUBSCRIPTION_STATUS_SUBSCRIBE_PENDING) {
// bindSubscription(mProviderId, mRemoteAddress);

new android.support.v7.app.AlertDialog.Builder(mActivity)
.setTitle(mActivity.getString(R.string.add_friends))
.setMessage(mContext.getString(R.string.subscription_notify_text, mRemoteAddress))
.setPositiveButton(mActivity.getString(R.string.accept_invitation), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
approveSubscription();
}
})
.setNegativeButton(mActivity.getString(R.string.decline_subscription), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// do nothing
}
})
.setIcon(android.R.drawable.ic_dialog_alert)
.show();

Snackbar sb = Snackbar.make(mHistory, mContext.getString(R.string.subscription_prompt, mRemoteAddress), Snackbar.LENGTH_LONG);
sb.setAction(mActivity.getString(R.string.approve_subscription), new View.OnClickListener() {
@Override
public void onClick(View view) {
approveSubscription();
}
});
sb.show();
}

}
Expand Down

0 comments on commit 2d61deb

Please sign in to comment.