Search in sources :

Example 1 with Room

use of eu.siacs.conversations.entities.Room in project Conversations by siacs.

the class ChannelSearchResultAdapter method onCreateContextMenu.

@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
    final Activity activity = XmppActivity.find(v);
    final Object tag = v.getTag();
    if (activity != null && tag instanceof Room) {
        activity.getMenuInflater().inflate(R.menu.channel_item_context, menu);
        this.current = (Room) tag;
    }
}
Also used : XmppActivity(eu.siacs.conversations.ui.XmppActivity) Activity(android.app.Activity) Room(eu.siacs.conversations.entities.Room)

Example 2 with Room

use of eu.siacs.conversations.entities.Room in project Conversations by siacs.

the class IqParser method parseRoom.

public static Room parseRoom(IqPacket packet) {
    final Element query = packet.findChild("query", Namespace.DISCO_INFO);
    if (query == null) {
        return null;
    }
    final Element x = query.findChild("x");
    if (x == null) {
        return null;
    }
    final Element identity = query.findChild("identity");
    Data data = Data.parse(x);
    String address = packet.getFrom().toString();
    String name = identity == null ? null : identity.getAttribute("name");
    String roomName = data.getValue("muc#roomconfig_roomname");
    String description = data.getValue("muc#roominfo_description");
    String language = data.getValue("muc#roominfo_lang");
    String occupants = data.getValue("muc#roominfo_occupants");
    int nusers;
    try {
        nusers = occupants == null ? 0 : Integer.parseInt(occupants);
    } catch (NumberFormatException e) {
        nusers = 0;
    }
    return new Room(address, TextUtils.isEmpty(roomName) ? name : roomName, description, language, nusers);
}
Also used : Element(eu.siacs.conversations.xml.Element) Data(eu.siacs.conversations.xmpp.forms.Data) Room(eu.siacs.conversations.entities.Room)

Example 3 with Room

use of eu.siacs.conversations.entities.Room in project Conversations by siacs.

the class ChannelSearchResultAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(@NonNull ViewHolder viewHolder, int position) {
    final Room searchResult = getItem(position);
    viewHolder.binding.name.setText(searchResult.getName());
    final String description = searchResult.getDescription();
    final String language = searchResult.getLanguage();
    if (TextUtils.isEmpty(description)) {
        viewHolder.binding.description.setVisibility(View.GONE);
    } else {
        viewHolder.binding.description.setText(description);
        viewHolder.binding.description.setVisibility(View.VISIBLE);
    }
    if (language == null || language.length() != 2) {
        viewHolder.binding.language.setVisibility(View.GONE);
    } else {
        viewHolder.binding.language.setText(language.toUpperCase(Locale.ENGLISH));
        viewHolder.binding.language.setVisibility(View.VISIBLE);
    }
    final Jid room = searchResult.getRoom();
    viewHolder.binding.room.setText(room != null ? room.asBareJid().toString() : "");
    AvatarWorkerTask.loadAvatar(searchResult, viewHolder.binding.avatar, R.dimen.avatar);
    final View root = viewHolder.binding.getRoot();
    root.setTag(searchResult);
    root.setOnClickListener(v -> listener.onChannelSearchResult(searchResult));
    root.setOnCreateContextMenuListener(this);
}
Also used : Jid(eu.siacs.conversations.xmpp.Jid) Room(eu.siacs.conversations.entities.Room) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView)

Example 4 with Room

use of eu.siacs.conversations.entities.Room in project Conversations by siacs.

the class ChannelDiscoveryActivity method onContextItemSelected.

@Override
public boolean onContextItemSelected(MenuItem item) {
    final Room room = adapter.getCurrent();
    if (room != null) {
        switch(item.getItemId()) {
            case R.id.share_with:
                StartConversationActivity.shareAsChannel(this, room.address);
                return true;
            case R.id.open_join_dialog:
                final Intent intent = new Intent(this, StartConversationActivity.class);
                intent.setAction(Intent.ACTION_VIEW);
                intent.putExtra("force_dialog", true);
                intent.setData(Uri.parse(String.format("xmpp:%s?join", room.address)));
                startActivity(intent);
                return true;
        }
    }
    return false;
}
Also used : Intent(android.content.Intent) Room(eu.siacs.conversations.entities.Room)

Example 5 with Room

use of eu.siacs.conversations.entities.Room in project Conversations by siacs.

the class ChannelDiscoveryService method discoverChannelsLocalServers.

private void discoverChannelsLocalServers(final String query, final OnChannelSearchResultsFound listener) {
    final Map<Jid, Account> localMucService = getLocalMucServices();
    Log.d(Config.LOGTAG, "checking with " + localMucService.size() + " muc services");
    if (localMucService.size() == 0) {
        listener.onChannelSearchResultsFound(Collections.emptyList());
        return;
    }
    if (!query.isEmpty()) {
        final List<Room> cached = cache.getIfPresent(key(Method.LOCAL_SERVER, ""));
        if (cached != null) {
            final List<Room> results = copyMatching(cached, query);
            cache.put(key(Method.LOCAL_SERVER, query), results);
            listener.onChannelSearchResultsFound(results);
        }
    }
    final AtomicInteger queriesInFlight = new AtomicInteger();
    final List<Room> rooms = new ArrayList<>();
    for (Map.Entry<Jid, Account> entry : localMucService.entrySet()) {
        IqPacket itemsRequest = service.getIqGenerator().queryDiscoItems(entry.getKey());
        queriesInFlight.incrementAndGet();
        service.sendIqPacket(entry.getValue(), itemsRequest, (account, itemsResponse) -> {
            if (itemsResponse.getType() == IqPacket.TYPE.RESULT) {
                final List<Jid> items = IqParser.items(itemsResponse);
                for (Jid item : items) {
                    IqPacket infoRequest = service.getIqGenerator().queryDiscoInfo(item);
                    queriesInFlight.incrementAndGet();
                    service.sendIqPacket(account, infoRequest, new OnIqPacketReceived() {

                        @Override
                        public void onIqPacketReceived(Account account, IqPacket infoResponse) {
                            if (infoResponse.getType() == IqPacket.TYPE.RESULT) {
                                final Room room = IqParser.parseRoom(infoResponse);
                                if (room != null) {
                                    rooms.add(room);
                                }
                                if (queriesInFlight.decrementAndGet() <= 0) {
                                    finishDiscoSearch(rooms, query, listener);
                                }
                            } else {
                                queriesInFlight.decrementAndGet();
                            }
                        }
                    });
                }
            }
            if (queriesInFlight.decrementAndGet() <= 0) {
                finishDiscoSearch(rooms, query, listener);
            }
        });
    }
}
Also used : Account(eu.siacs.conversations.entities.Account) Jid(eu.siacs.conversations.xmpp.Jid) OnIqPacketReceived(eu.siacs.conversations.xmpp.OnIqPacketReceived) ArrayList(java.util.ArrayList) IqPacket(eu.siacs.conversations.xmpp.stanzas.IqPacket) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Room(eu.siacs.conversations.entities.Room) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

Room (eu.siacs.conversations.entities.Room)5 Jid (eu.siacs.conversations.xmpp.Jid)2 Activity (android.app.Activity)1 Intent (android.content.Intent)1 View (android.view.View)1 RecyclerView (androidx.recyclerview.widget.RecyclerView)1 Account (eu.siacs.conversations.entities.Account)1 XmppActivity (eu.siacs.conversations.ui.XmppActivity)1 Element (eu.siacs.conversations.xml.Element)1 OnIqPacketReceived (eu.siacs.conversations.xmpp.OnIqPacketReceived)1 Data (eu.siacs.conversations.xmpp.forms.Data)1 IqPacket (eu.siacs.conversations.xmpp.stanzas.IqPacket)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1