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;
}
}
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);
}
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);
}
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;
}
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);
}
});
}
}
Aggregations