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 {
/**
* @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);
if (chat != null && chat instanceof RoomChat) {
return (RoomChat) chat;
......
......@@ -153,7 +153,7 @@ public class RoomChat extends AbstractChat {
return subject;
}
MultiUserChat getMultiUserChat() {
public MultiUserChat getMultiUserChat() {
return multiUserChat;
}
......
......@@ -260,7 +260,7 @@ public class VCardManager implements OnLoadListener, OnPacketListener,
}
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();
if (connectionThread == null) {
......
......@@ -36,6 +36,7 @@ import com.xabber.android.data.connection.OnPacketListener;
import com.xabber.android.data.entity.BaseEntity;
import com.xabber.android.data.entity.NestedMap;
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.roster.OnRosterReceivedListener;
import com.xabber.android.data.roster.OnStatusChangeListener;
......@@ -171,7 +172,7 @@ public class MessageManager implements OnLoadListener, OnPacketListener, OnDisco
* @return
*/
private RegularChat createChat(String account, String user) {
RegularChat chat = new RegularChat(account, Jid.getBareAddress(user));
RegularChat chat = new RegularChat(account, user);
addChat(chat);
return chat;
}
......@@ -477,10 +478,23 @@ public class MessageManager implements OnLoadListener, OnPacketListener, OnDisco
// archive have been received.
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();
boolean processed = false;
for (AbstractChat chat : chats.getNested(account).values()) {
if (chat.onPacket(bareAddress, packet)) {
if (chat.onPacket(contact, packet)) {
processed = true;
break;
}
......@@ -499,7 +513,7 @@ public class MessageManager implements OnLoadListener, OnPacketListener, OnDisco
return;
}
}
createChat(account, user).onPacket(bareAddress, packet);
createChat(account, user).onPacket(contact, packet);
}
}
......
......@@ -19,6 +19,7 @@ import com.xabber.android.data.NetworkException;
import com.xabber.android.data.SettingsManager;
import com.xabber.android.data.SettingsManager.SecurityOtrMode;
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.OTRUnencryptedException;
import com.xabber.android.data.extension.otr.SecurityLevel;
......@@ -58,10 +59,12 @@ public class RegularChat extends AbstractChat {
@Override
public String getTo() {
if (resource == null)
if (resource == null
|| (MUCManager.getInstance().hasRoom(account, Jid.getBareAddress(user)) && getType() != Message.Type.groupchat )) {
return user;
else
} else {
return user + "/" + resource;
}
}
@Override
......
......@@ -56,6 +56,11 @@ public class ContactVcardViewerFragment extends Fragment implements OnContactCha
private VCard vCard;
private boolean vCardError;
private View progressBar;
private Listener listener;
interface Listener {
void onVCardReceived();
}
public static ContactVcardViewerFragment newInstance(String account, String user) {
ContactVcardViewerFragment fragment = new ContactVcardViewerFragment();
......@@ -67,6 +72,12 @@ public class ContactVcardViewerFragment extends Fragment implements OnContactCha
return fragment;
}
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
listener = (Listener) activity;
}
@Override
public void onCreate(Bundle savedInstanceState) {
......@@ -160,6 +171,13 @@ public class ContactVcardViewerFragment extends Fragment implements OnContactCha
}
}
@Override
public void onDetach() {
super.onDetach();
listener = null;
}
@Override
public void onVCardReceived(String account, String bareAddress, VCard vCard) {
if (!this.account.equals(account) || !this.user.equals(bareAddress)) {
......@@ -168,6 +186,7 @@ public class ContactVcardViewerFragment extends Fragment implements OnContactCha
this.vCard = vCard;
this.vCardError = false;
updateVCard();
listener.onVCardReceived();
progressBar.setVisibility(View.GONE);
}
......
......@@ -43,7 +43,7 @@ import java.util.Collection;
import java.util.List;
public class ContactViewer extends ManagedActivity implements
OnContactChangedListener, OnAccountChangedListener {
OnContactChangedListener, OnAccountChangedListener, ContactVcardViewerFragment.Listener {
protected ContactTitleExpandableToolbarInflater contactTitleExpandableToolbarInflater;
private String account;
......@@ -92,7 +92,7 @@ public class ContactViewer extends ManagedActivity implements
}
} else {
account = getAccount(getIntent());
bareAddress = Jid.getBareAddress(getUser(getIntent()));
bareAddress = getUser(getIntent());
}
if (bareAddress != null && bareAddress.equalsIgnoreCase(GroupManager.IS_ACCOUNT)) {
......@@ -170,4 +170,9 @@ public class ContactViewer extends ManagedActivity implements
protected String getBareAddress() {
return bareAddress;
}
@Override
public void onVCardReceived() {
contactTitleExpandableToolbarInflater.onResume();
}
}
......@@ -20,14 +20,17 @@ import android.os.Bundle;
import android.support.v4.app.NavUtils;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.AdapterView;
import com.xabber.android.R;
import com.xabber.android.data.Application;
import com.xabber.android.data.LogManager;
import com.xabber.android.data.account.OnAccountChangedListener;
import com.xabber.android.data.entity.BaseEntity;
import com.xabber.android.data.extension.muc.MUCManager;
import com.xabber.android.data.intent.AccountIntentBuilder;
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.ui.adapter.OccupantListAdapter;
import com.xabber.android.ui.helper.BarPainter;
......@@ -42,7 +45,7 @@ import java.util.Collection;
* @author alexander.ivanov
*/
public class OccupantList extends ManagedListActivity implements
OnAccountChangedListener, OnContactChangedListener {
OnAccountChangedListener, OnContactChangedListener, AdapterView.OnItemClickListener {
private String account;
private String room;
......@@ -92,6 +95,8 @@ public class OccupantList extends ManagedListActivity implements
listAdapter = new OccupantListAdapter(this, account, room);
setListAdapter(listAdapter);
getListView().setOnItemClickListener(this);
}
@Override
......@@ -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
.getAccountAvatar(account));
else
avatarView.setImageDrawable(AvatarManager.getInstance()
.getOccupantAvatar(room + "/" + occupant.getNickname()));
.getUserAvatarForContactList(room + "/" + occupant.getNickname()));
affilationView.setImageLevel(occupant.getAffiliation().ordinal());
nameView.setText(occupant.getNickname());
int textStyle;
......
......@@ -100,6 +100,10 @@ public class ContactTitleExpandableToolbarInflater implements ObservableScrollVi
}
});
updateTitle();
}
public void updateTitle() {
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