use of eu.siacs.conversations.entities.Conversation in project Conversations by siacs.
the class XmppConnectionService method deleteAccount.
public void deleteAccount(final Account account) {
final boolean connected = account.getStatus() == Account.State.ONLINE;
synchronized (this.conversations) {
if (connected) {
account.getAxolotlService().deleteOmemoIdentity();
}
for (final Conversation conversation : conversations) {
if (conversation.getAccount() == account) {
if (conversation.getMode() == Conversation.MODE_MULTI) {
if (connected) {
leaveMuc(conversation);
}
}
conversations.remove(conversation);
mNotificationService.clear(conversation);
}
}
if (account.getXmppConnection() != null) {
new Thread(() -> disconnect(account, !connected)).start();
}
final Runnable runnable = () -> {
if (!databaseBackend.deleteAccount(account)) {
Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": unable to delete account");
}
};
mDatabaseWriterExecutor.execute(runnable);
this.accounts.remove(account);
this.mRosterSyncTaskManager.clear(account);
updateAccountUi();
mNotificationService.updateErrorNotification();
syncEnabledAccountSetting();
toggleForegroundService();
}
}
use of eu.siacs.conversations.entities.Conversation in project Conversations by siacs.
the class XmppConnectionService method notifyAccountAvatarHasChanged.
public void notifyAccountAvatarHasChanged(final Account account) {
final XmppConnection connection = account.getXmppConnection();
if (connection != null && connection.getFeatures().bookmarksConversion()) {
Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": avatar changed. resending presence to online group chats");
for (Conversation conversation : conversations) {
if (conversation.getAccount() == account && conversation.getMode() == Conversational.MODE_MULTI) {
final MucOptions mucOptions = conversation.getMucOptions();
if (mucOptions.online()) {
PresencePacket packet = mPresenceGenerator.selfPresence(account, Presence.Status.ONLINE, mucOptions.nonanonymous());
packet.setTo(mucOptions.getSelf().getFullJid());
connection.sendPresencePacket(packet);
}
}
}
}
}
use of eu.siacs.conversations.entities.Conversation in project Conversations by siacs.
the class XmppConnectionService method expireOldMessages.
public void expireOldMessages(final boolean resetHasMessagesLeftOnServer) {
mLastExpiryRun.set(SystemClock.elapsedRealtime());
mDatabaseWriterExecutor.execute(() -> {
long timestamp = getAutomaticMessageDeletionDate();
if (timestamp > 0) {
databaseBackend.expireOldMessages(timestamp);
synchronized (XmppConnectionService.this.conversations) {
for (Conversation conversation : XmppConnectionService.this.conversations) {
conversation.expireOldMessages(timestamp);
if (resetHasMessagesLeftOnServer) {
conversation.messagesLoaded.set(true);
conversation.setHasMessagesLeftOnServer(true);
}
}
}
updateConversationUi();
}
});
}
use of eu.siacs.conversations.entities.Conversation in project Conversations by siacs.
the class XmppConnectionService method processModifiedBookmark.
private void processModifiedBookmark(Bookmark bookmark, final boolean pep, final boolean synchronizeWithBookmarks) {
final Account account = bookmark.getAccount();
Conversation conversation = find(bookmark);
if (conversation != null) {
if (conversation.getMode() != Conversation.MODE_MULTI) {
return;
}
bookmark.setConversation(conversation);
if (pep && synchronizeWithBookmarks && !bookmark.autojoin()) {
Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": archiving conference (" + conversation.getJid() + ") after receiving pep");
archiveConversation(conversation, false);
} else {
final MucOptions mucOptions = conversation.getMucOptions();
if (mucOptions.getError() == MucOptions.Error.NICK_IN_USE) {
final String current = mucOptions.getActualNick();
final String proposed = mucOptions.getProposedNick();
if (current != null && !current.equals(proposed)) {
Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": proposed nick changed after bookmark push " + current + "->" + proposed);
joinMuc(conversation);
}
}
}
} else if (synchronizeWithBookmarks && bookmark.autojoin()) {
conversation = findOrCreateConversation(account, bookmark.getFullJid(), true, true, false);
bookmark.setConversation(conversation);
}
}
use of eu.siacs.conversations.entities.Conversation in project Conversations by siacs.
the class XmppConnectionService method joinMuc.
private void joinMuc(Conversation conversation, final OnConferenceJoined onConferenceJoined, final boolean followedInvite) {
final Account account = conversation.getAccount();
synchronized (account.pendingConferenceJoins) {
account.pendingConferenceJoins.remove(conversation);
}
synchronized (account.pendingConferenceLeaves) {
account.pendingConferenceLeaves.remove(conversation);
}
if (account.getStatus() == Account.State.ONLINE) {
synchronized (account.inProgressConferenceJoins) {
account.inProgressConferenceJoins.add(conversation);
}
if (Config.MUC_LEAVE_BEFORE_JOIN) {
sendPresencePacket(account, mPresenceGenerator.leave(conversation.getMucOptions()));
}
conversation.resetMucOptions();
if (onConferenceJoined != null) {
conversation.getMucOptions().flagNoAutoPushConfiguration();
}
conversation.setHasMessagesLeftOnServer(false);
fetchConferenceConfiguration(conversation, new OnConferenceConfigurationFetched() {
private void join(Conversation conversation) {
Account account = conversation.getAccount();
final MucOptions mucOptions = conversation.getMucOptions();
if (mucOptions.nonanonymous() && !mucOptions.membersOnly() && !conversation.getBooleanAttribute("accept_non_anonymous", false)) {
synchronized (account.inProgressConferenceJoins) {
account.inProgressConferenceJoins.remove(conversation);
}
mucOptions.setError(MucOptions.Error.NON_ANONYMOUS);
updateConversationUi();
if (onConferenceJoined != null) {
onConferenceJoined.onConferenceJoined(conversation);
}
return;
}
final Jid joinJid = mucOptions.getSelf().getFullJid();
Log.d(Config.LOGTAG, account.getJid().asBareJid().toString() + ": joining conversation " + joinJid.toString());
PresencePacket packet = mPresenceGenerator.selfPresence(account, Presence.Status.ONLINE, mucOptions.nonanonymous() || onConferenceJoined != null);
packet.setTo(joinJid);
Element x = packet.addChild("x", "http://jabber.org/protocol/muc");
if (conversation.getMucOptions().getPassword() != null) {
x.addChild("password").setContent(mucOptions.getPassword());
}
if (mucOptions.mamSupport()) {
// Use MAM instead of the limited muc history to get history
x.addChild("history").setAttribute("maxchars", "0");
} else {
// Fallback to muc history
x.addChild("history").setAttribute("since", PresenceGenerator.getTimestamp(conversation.getLastMessageTransmitted().getTimestamp()));
}
sendPresencePacket(account, packet);
if (onConferenceJoined != null) {
onConferenceJoined.onConferenceJoined(conversation);
}
if (!joinJid.equals(conversation.getJid())) {
conversation.setContactJid(joinJid);
databaseBackend.updateConversation(conversation);
}
if (mucOptions.mamSupport()) {
getMessageArchiveService().catchupMUC(conversation);
}
if (mucOptions.isPrivateAndNonAnonymous()) {
fetchConferenceMembers(conversation);
if (followedInvite) {
final Bookmark bookmark = conversation.getBookmark();
if (bookmark != null) {
if (!bookmark.autojoin()) {
bookmark.setAutojoin(true);
createBookmark(account, bookmark);
}
} else {
saveConversationAsBookmark(conversation, null);
}
}
}
synchronized (account.inProgressConferenceJoins) {
account.inProgressConferenceJoins.remove(conversation);
sendUnsentMessages(conversation);
}
}
@Override
public void onConferenceConfigurationFetched(Conversation conversation) {
if (conversation.getStatus() == Conversation.STATUS_ARCHIVED) {
Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": conversation (" + conversation.getJid() + ") got archived before IQ result");
return;
}
join(conversation);
}
@Override
public void onFetchFailed(final Conversation conversation, final String errorCondition) {
if (conversation.getStatus() == Conversation.STATUS_ARCHIVED) {
Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": conversation (" + conversation.getJid() + ") got archived before IQ result");
return;
}
if ("remote-server-not-found".equals(errorCondition)) {
synchronized (account.inProgressConferenceJoins) {
account.inProgressConferenceJoins.remove(conversation);
}
conversation.getMucOptions().setError(MucOptions.Error.SERVER_NOT_FOUND);
updateConversationUi();
} else {
join(conversation);
fetchConferenceConfiguration(conversation);
}
}
});
updateConversationUi();
} else {
synchronized (account.pendingConferenceJoins) {
account.pendingConferenceJoins.add(conversation);
}
conversation.resetMucOptions();
conversation.setHasMessagesLeftOnServer(false);
updateConversationUi();
}
}
Aggregations