Commit 4198c098 authored by Grigory Fedorov's avatar Grigory Fedorov

First implementation of MUC private chats.

parent 4070b26c
...@@ -125,7 +125,7 @@ public class MUCManager implements OnLoadListener, OnPacketListener { ...@@ -125,7 +125,7 @@ public class MUCManager implements OnLoadListener, OnPacketListener {
/** /**
* @return <code>null</code> if does not exists. * @return <code>null</code> if does not exists.
*/ */
private RoomChat getRoomChat(String account, String room) { public RoomChat getRoomChat(String account, String room) {
AbstractChat chat = MessageManager.getInstance().getChat(account, room); AbstractChat chat = MessageManager.getInstance().getChat(account, room);
if (chat != null && chat instanceof RoomChat) { if (chat != null && chat instanceof RoomChat) {
return (RoomChat) chat; return (RoomChat) chat;
......
...@@ -153,7 +153,7 @@ public class RoomChat extends AbstractChat { ...@@ -153,7 +153,7 @@ public class RoomChat extends AbstractChat {
return subject; return subject;
} }
MultiUserChat getMultiUserChat() { public MultiUserChat getMultiUserChat() {
return multiUserChat; return multiUserChat;
} }
......
...@@ -260,7 +260,7 @@ public class VCardManager implements OnLoadListener, OnPacketListener, ...@@ -260,7 +260,7 @@ public class VCardManager implements OnLoadListener, OnPacketListener,
} }
private void requestVCard(final String account, final String srcUser) { private void requestVCard(final String account, final String srcUser) {
final String user = Jid.getBareAddress(srcUser); final String user = srcUser;
ConnectionThread connectionThread = AccountManager.getInstance().getAccount(account).getConnectionThread(); ConnectionThread connectionThread = AccountManager.getInstance().getAccount(account).getConnectionThread();
if (connectionThread == null) { if (connectionThread == null) {
......
...@@ -36,6 +36,7 @@ import com.xabber.android.data.connection.OnPacketListener; ...@@ -36,6 +36,7 @@ import com.xabber.android.data.connection.OnPacketListener;
import com.xabber.android.data.entity.BaseEntity; import com.xabber.android.data.entity.BaseEntity;
import com.xabber.android.data.entity.NestedMap; import com.xabber.android.data.entity.NestedMap;
import com.xabber.android.data.extension.archive.MessageArchiveManager; import com.xabber.android.data.extension.archive.MessageArchiveManager;
import com.xabber.android.data.extension.muc.MUCManager;
import com.xabber.android.data.extension.muc.RoomChat; import com.xabber.android.data.extension.muc.RoomChat;
import com.xabber.android.data.roster.OnRosterReceivedListener; import com.xabber.android.data.roster.OnRosterReceivedListener;
import com.xabber.android.data.roster.OnStatusChangeListener; import com.xabber.android.data.roster.OnStatusChangeListener;
...@@ -171,7 +172,7 @@ public class MessageManager implements OnLoadListener, OnPacketListener, OnDisco ...@@ -171,7 +172,7 @@ public class MessageManager implements OnLoadListener, OnPacketListener, OnDisco
* @return * @return
*/ */
private RegularChat createChat(String account, String user) { private RegularChat createChat(String account, String user) {
RegularChat chat = new RegularChat(account, Jid.getBareAddress(user)); RegularChat chat = new RegularChat(account, user);
addChat(chat); addChat(chat);
return chat; return chat;
} }
...@@ -477,10 +478,23 @@ public class MessageManager implements OnLoadListener, OnPacketListener, OnDisco ...@@ -477,10 +478,23 @@ public class MessageManager implements OnLoadListener, OnPacketListener, OnDisco
// archive have been received. // archive have been received.
return; return;
} }
String contact = bareAddress;
if (packet instanceof Message) {
Message message = (Message) packet;
if (MUCManager.getInstance().hasRoom(account, bareAddress)
&& message.getType() != Message.Type.groupchat ) {
contact = packet.getFrom();
}
}
final String user = packet.getFrom(); final String user = packet.getFrom();
boolean processed = false; boolean processed = false;
for (AbstractChat chat : chats.getNested(account).values()) { for (AbstractChat chat : chats.getNested(account).values()) {
if (chat.onPacket(bareAddress, packet)) { if (chat.onPacket(contact, packet)) {
processed = true; processed = true;
break; break;
} }
...@@ -499,7 +513,7 @@ public class MessageManager implements OnLoadListener, OnPacketListener, OnDisco ...@@ -499,7 +513,7 @@ public class MessageManager implements OnLoadListener, OnPacketListener, OnDisco
return; return;
} }
} }
createChat(account, user).onPacket(bareAddress, packet); createChat(account, user).onPacket(contact, packet);
} }
} }
......
...@@ -19,6 +19,7 @@ import com.xabber.android.data.NetworkException; ...@@ -19,6 +19,7 @@ import com.xabber.android.data.NetworkException;
import com.xabber.android.data.SettingsManager; import com.xabber.android.data.SettingsManager;
import com.xabber.android.data.SettingsManager.SecurityOtrMode; import com.xabber.android.data.SettingsManager.SecurityOtrMode;
import com.xabber.android.data.extension.archive.MessageArchiveManager; import com.xabber.android.data.extension.archive.MessageArchiveManager;
import com.xabber.android.data.extension.muc.MUCManager;
import com.xabber.android.data.extension.otr.OTRManager; import com.xabber.android.data.extension.otr.OTRManager;
import com.xabber.android.data.extension.otr.OTRUnencryptedException; import com.xabber.android.data.extension.otr.OTRUnencryptedException;
import com.xabber.android.data.extension.otr.SecurityLevel; import com.xabber.android.data.extension.otr.SecurityLevel;
...@@ -58,10 +59,12 @@ public class RegularChat extends AbstractChat { ...@@ -58,10 +59,12 @@ public class RegularChat extends AbstractChat {
@Override @Override
public String getTo() { public String getTo() {
if (resource == null) if (resource == null
|| (MUCManager.getInstance().hasRoom(account, Jid.getBareAddress(user)) && getType() != Message.Type.groupchat )) {
return user; return user;
else } else {
return user + "/" + resource; return user + "/" + resource;
}
} }
@Override @Override
......
...@@ -56,6 +56,11 @@ public class ContactVcardViewerFragment extends Fragment implements OnContactCha ...@@ -56,6 +56,11 @@ public class ContactVcardViewerFragment extends Fragment implements OnContactCha
private VCard vCard; private VCard vCard;
private boolean vCardError; private boolean vCardError;
private View progressBar; private View progressBar;
private Listener listener;
interface Listener {
void onVCardReceived();
}
public static ContactVcardViewerFragment newInstance(String account, String user) { public static ContactVcardViewerFragment newInstance(String account, String user) {
ContactVcardViewerFragment fragment = new ContactVcardViewerFragment(); ContactVcardViewerFragment fragment = new ContactVcardViewerFragment();
...@@ -67,6 +72,12 @@ public class ContactVcardViewerFragment extends Fragment implements OnContactCha ...@@ -67,6 +72,12 @@ public class ContactVcardViewerFragment extends Fragment implements OnContactCha
return fragment; return fragment;
} }
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
listener = (Listener) activity;
}
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
...@@ -160,6 +171,13 @@ public class ContactVcardViewerFragment extends Fragment implements OnContactCha ...@@ -160,6 +171,13 @@ public class ContactVcardViewerFragment extends Fragment implements OnContactCha
} }
} }
@Override
public void onDetach() {
super.onDetach();
listener = null;
}
@Override @Override
public void onVCardReceived(String account, String bareAddress, VCard vCard) { public void onVCardReceived(String account, String bareAddress, VCard vCard) {
if (!this.account.equals(account) || !this.user.equals(bareAddress)) { if (!this.account.equals(account) || !this.user.equals(bareAddress)) {
...@@ -168,6 +186,7 @@ public class ContactVcardViewerFragment extends Fragment implements OnContactCha ...@@ -168,6 +186,7 @@ public class ContactVcardViewerFragment extends Fragment implements OnContactCha
this.vCard = vCard; this.vCard = vCard;
this.vCardError = false; this.vCardError = false;
updateVCard(); updateVCard();
listener.onVCardReceived();
progressBar.setVisibility(View.GONE); progressBar.setVisibility(View.GONE);
} }
......
...@@ -43,7 +43,7 @@ import java.util.Collection; ...@@ -43,7 +43,7 @@ import java.util.Collection;
import java.util.List; import java.util.List;
public class ContactViewer extends ManagedActivity implements public class ContactViewer extends ManagedActivity implements
OnContactChangedListener, OnAccountChangedListener { OnContactChangedListener, OnAccountChangedListener, ContactVcardViewerFragment.Listener {
protected ContactTitleExpandableToolbarInflater contactTitleExpandableToolbarInflater; protected ContactTitleExpandableToolbarInflater contactTitleExpandableToolbarInflater;
private String account; private String account;
...@@ -92,7 +92,7 @@ public class ContactViewer extends ManagedActivity implements ...@@ -92,7 +92,7 @@ public class ContactViewer extends ManagedActivity implements
} }
} else { } else {
account = getAccount(getIntent()); account = getAccount(getIntent());
bareAddress = Jid.getBareAddress(getUser(getIntent())); bareAddress = getUser(getIntent());
} }
if (bareAddress != null && bareAddress.equalsIgnoreCase(GroupManager.IS_ACCOUNT)) { if (bareAddress != null && bareAddress.equalsIgnoreCase(GroupManager.IS_ACCOUNT)) {
...@@ -170,4 +170,9 @@ public class ContactViewer extends ManagedActivity implements ...@@ -170,4 +170,9 @@ public class ContactViewer extends ManagedActivity implements
protected String getBareAddress() { protected String getBareAddress() {
return bareAddress; return bareAddress;
} }
@Override
public void onVCardReceived() {
contactTitleExpandableToolbarInflater.onResume();
}
} }
...@@ -20,14 +20,17 @@ import android.os.Bundle; ...@@ -20,14 +20,17 @@ import android.os.Bundle;
import android.support.v4.app.NavUtils; import android.support.v4.app.NavUtils;
import android.support.v7.widget.Toolbar; import android.support.v7.widget.Toolbar;
import android.view.View; import android.view.View;
import android.widget.AdapterView;
import com.xabber.android.R; import com.xabber.android.R;
import com.xabber.android.data.Application; import com.xabber.android.data.Application;
import com.xabber.android.data.LogManager;
import com.xabber.android.data.account.OnAccountChangedListener; import com.xabber.android.data.account.OnAccountChangedListener;
import com.xabber.android.data.entity.BaseEntity; import com.xabber.android.data.entity.BaseEntity;
import com.xabber.android.data.extension.muc.MUCManager; import com.xabber.android.data.extension.muc.MUCManager;
import com.xabber.android.data.intent.AccountIntentBuilder; import com.xabber.android.data.intent.AccountIntentBuilder;
import com.xabber.android.data.intent.EntityIntentBuilder; import com.xabber.android.data.intent.EntityIntentBuilder;
import com.xabber.android.data.message.MessageManager;
import com.xabber.android.data.roster.OnContactChangedListener; import com.xabber.android.data.roster.OnContactChangedListener;
import com.xabber.android.ui.adapter.OccupantListAdapter; import com.xabber.android.ui.adapter.OccupantListAdapter;
import com.xabber.android.ui.helper.BarPainter; import com.xabber.android.ui.helper.BarPainter;
...@@ -42,7 +45,7 @@ import java.util.Collection; ...@@ -42,7 +45,7 @@ import java.util.Collection;
* @author alexander.ivanov * @author alexander.ivanov
*/ */
public class OccupantList extends ManagedListActivity implements public class OccupantList extends ManagedListActivity implements
OnAccountChangedListener, OnContactChangedListener { OnAccountChangedListener, OnContactChangedListener, AdapterView.OnItemClickListener {
private String account; private String account;
private String room; private String room;
...@@ -92,6 +95,8 @@ public class OccupantList extends ManagedListActivity implements ...@@ -92,6 +95,8 @@ public class OccupantList extends ManagedListActivity implements
listAdapter = new OccupantListAdapter(this, account, room); listAdapter = new OccupantListAdapter(this, account, room);
setListAdapter(listAdapter); setListAdapter(listAdapter);
getListView().setOnItemClickListener(this);
} }
@Override @Override
...@@ -123,4 +128,15 @@ public class OccupantList extends ManagedListActivity implements ...@@ -123,4 +128,15 @@ public class OccupantList extends ManagedListActivity implements
} }
} }
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
com.xabber.android.data.extension.muc.Occupant occupant
= (com.xabber.android.data.extension.muc.Occupant) listAdapter.getItem(position);
LogManager.i(this, occupant.getNickname());
String occupantFullJid = room + "/" + occupant.getNickname();
MessageManager.getInstance().openChat(account, occupantFullJid);
startActivity(ChatViewer.createSpecificChatIntent(this, account, occupantFullJid));
}
} }
...@@ -99,7 +99,7 @@ public class OccupantListAdapter extends BaseAdapter implements ...@@ -99,7 +99,7 @@ public class OccupantListAdapter extends BaseAdapter implements
.getAccountAvatar(account)); .getAccountAvatar(account));
else else
avatarView.setImageDrawable(AvatarManager.getInstance() avatarView.setImageDrawable(AvatarManager.getInstance()
.getOccupantAvatar(room + "/" + occupant.getNickname())); .getUserAvatarForContactList(room + "/" + occupant.getNickname()));
affilationView.setImageLevel(occupant.getAffiliation().ordinal()); affilationView.setImageLevel(occupant.getAffiliation().ordinal());
nameView.setText(occupant.getNickname()); nameView.setText(occupant.getNickname());
int textStyle; int textStyle;
......
...@@ -100,6 +100,10 @@ public class ContactTitleExpandableToolbarInflater implements ObservableScrollVi ...@@ -100,6 +100,10 @@ public class ContactTitleExpandableToolbarInflater implements ObservableScrollVi
} }
}); });
updateTitle();
}
public void updateTitle() {
ContactTitleInflater.updateTitle(titleView, activity, abstractContact); ContactTitleInflater.updateTitle(titleView, activity, abstractContact);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment