use of eu.siacs.conversations.entities.Conversation in project Conversations by siacs.
the class XmppConnectionService method disconnect.
private void disconnect(Account account, boolean force) {
if ((account.getStatus() == Account.State.ONLINE) || (account.getStatus() == Account.State.DISABLED)) {
final XmppConnection connection = account.getXmppConnection();
if (!force) {
List<Conversation> conversations = getConversations();
for (Conversation conversation : conversations) {
if (conversation.getAccount() == account) {
if (conversation.getMode() == Conversation.MODE_MULTI) {
leaveMuc(conversation, true);
}
}
}
sendOfflinePresence(account);
}
connection.disconnect(force);
}
}
use of eu.siacs.conversations.entities.Conversation in project Conversations by siacs.
the class UIHelper method getMessageDisplayName.
public static String getMessageDisplayName(final Message message) {
final Conversational conversation = message.getConversation();
if (message.getStatus() == Message.STATUS_RECEIVED) {
final Contact contact = message.getContact();
if (conversation.getMode() == Conversation.MODE_MULTI) {
if (contact != null) {
return contact.getDisplayName();
} else {
return getDisplayedMucCounterpart(message.getCounterpart());
}
} else {
return contact != null ? contact.getDisplayName() : "";
}
} else {
if (conversation instanceof Conversation && conversation.getMode() == Conversation.MODE_MULTI) {
return ((Conversation) conversation).getMucOptions().getSelf().getName();
} else {
final Account account = conversation.getAccount();
final Jid jid = account.getJid();
final String displayName = account.getDisplayName();
if (Strings.isNullOrEmpty(displayName)) {
return jid.getLocal() != null ? jid.getLocal() : jid.getDomain().toString();
} else {
return displayName;
}
}
}
}
use of eu.siacs.conversations.entities.Conversation in project Conversations by siacs.
the class XmppConnectionService method createAdhocConference.
public boolean createAdhocConference(final Account account, final String name, final Iterable<Jid> jids, final UiCallback<Conversation> callback) {
Log.d(Config.LOGTAG, account.getJid().asBareJid().toString() + ": creating adhoc conference with " + jids.toString());
if (account.getStatus() == Account.State.ONLINE) {
try {
String server = findConferenceServer(account);
if (server == null) {
if (callback != null) {
callback.error(R.string.no_conference_server_found, null);
}
return false;
}
final Jid jid = Jid.of(CryptoHelper.pronounceable(getRNG()), server, null);
final Conversation conversation = findOrCreateConversation(account, jid, true, false, true);
joinMuc(conversation, new OnConferenceJoined() {
@Override
public void onConferenceJoined(final Conversation conversation) {
final Bundle configuration = IqGenerator.defaultGroupChatConfiguration();
if (!TextUtils.isEmpty(name)) {
configuration.putString("muc#roomconfig_roomname", name);
}
pushConferenceConfiguration(conversation, configuration, new OnConfigurationPushed() {
@Override
public void onPushSucceeded() {
for (Jid invite : jids) {
invite(conversation, invite);
}
for (String resource : account.getSelfContact().getPresences().toResourceArray()) {
Jid other = account.getJid().withResource(resource);
Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": sending direct invite to " + other);
directInvite(conversation, other);
}
saveConversationAsBookmark(conversation, name);
if (callback != null) {
callback.success(conversation);
}
}
@Override
public void onPushFailed() {
archiveConversation(conversation);
if (callback != null) {
callback.error(R.string.conference_creation_failed, conversation);
}
}
});
}
});
return true;
} catch (IllegalArgumentException e) {
if (callback != null) {
callback.error(R.string.conference_creation_failed, null);
}
return false;
}
} else {
if (callback != null) {
callback.error(R.string.not_connected_try_again, null);
}
return false;
}
}
use of eu.siacs.conversations.entities.Conversation in project Conversations by siacs.
the class XmppConnectionService method resendFailedMessages.
public void resendFailedMessages(final Message message) {
final Collection<Message> messages = new ArrayList<>();
Message current = message;
while (current.getStatus() == Message.STATUS_SEND_FAILED) {
messages.add(current);
if (current.mergeable(current.next())) {
current = current.next();
} else {
break;
}
}
for (final Message msg : messages) {
msg.setTime(System.currentTimeMillis());
markMessage(msg, Message.STATUS_WAITING);
this.resendMessage(msg, false);
}
if (message.getConversation() instanceof Conversation) {
((Conversation) message.getConversation()).sort();
}
updateConversationUi();
}
use of eu.siacs.conversations.entities.Conversation in project Conversations by siacs.
the class XmppConnectionService method directReply.
private void directReply(final Conversation conversation, final String body, final String lastMessageUuid, final boolean dismissAfterReply) {
final Message inReplyTo = lastMessageUuid == null ? null : conversation.findMessageWithUuid(lastMessageUuid);
final Message message = new Message(conversation, body, conversation.getNextEncryption());
if (inReplyTo != null && inReplyTo.isPrivateMessage()) {
Message.configurePrivateMessage(message, inReplyTo.getCounterpart());
}
message.markUnread();
if (message.getEncryption() == Message.ENCRYPTION_PGP) {
getPgpEngine().encrypt(message, new UiCallback<Message>() {
@Override
public void success(Message message) {
if (dismissAfterReply) {
markRead((Conversation) message.getConversation(), true);
} else {
mNotificationService.pushFromDirectReply(message);
}
}
@Override
public void error(int errorCode, Message object) {
}
@Override
public void userInputRequired(PendingIntent pi, Message object) {
}
});
} else {
sendMessage(message);
if (dismissAfterReply) {
markRead(conversation, true);
} else {
mNotificationService.pushFromDirectReply(message);
}
}
}
Aggregations