use of com.xabber.android.data.NetworkException in project xabber-android by redsolution.
the class MessageManager method exportChat.
/**
* Export chat to file with specified name.
*
* @param account
* @param user
* @param fileName
* @throws NetworkException
*/
public File exportChat(String account, String user, String fileName) throws NetworkException {
final File file = new File(Environment.getExternalStorageDirectory(), fileName);
try {
BufferedWriter out = new BufferedWriter(new FileWriter(file));
final String titleName = RosterManager.getInstance().getName(account, user) + " (" + user + ")";
out.write("<html><head><title>");
out.write(StringUtils.escapeHtml(titleName));
out.write("</title></head><body>");
final AbstractChat abstractChat = getChat(account, user);
if (abstractChat != null) {
final boolean isMUC = abstractChat instanceof RoomChat;
final String accountName = AccountManager.getInstance().getNickName(account);
final String userName = RosterManager.getInstance().getName(account, user);
for (MessageItem messageItem : abstractChat.getMessages()) {
if (messageItem.getAction() != null) {
continue;
}
final String name;
if (isMUC) {
name = messageItem.getResource();
} else {
if (messageItem.isIncoming()) {
name = userName;
} else {
name = accountName;
}
}
out.write("<b>");
out.write(StringUtils.escapeHtml(name));
out.write("</b> (");
out.write(StringUtils.getDateTimeText(messageItem.getTimestamp()));
out.write(")<br />\n<p>");
out.write(StringUtils.escapeHtml(messageItem.getText()));
out.write("</p><hr />\n");
}
}
out.write("</body></html>");
out.close();
} catch (IOException e) {
throw new NetworkException(R.string.FILE_NOT_FOUND);
}
return file;
}
use of com.xabber.android.data.NetworkException in project xabber-android by redsolution.
the class ReceiptManager method onPacket.
@Override
public void onPacket(ConnectionItem connection, String bareAddress, Stanza packet) {
if (!(connection instanceof AccountItem))
return;
String account = ((AccountItem) connection).getAccount();
final String user = packet.getFrom();
if (user == null)
return;
if (!(packet instanceof Message))
return;
final Message message = (Message) packet;
if (message.getType() == Message.Type.error) {
final MessageItem messageItem = sent.remove(account, message.getPacketID());
if (messageItem != null && !messageItem.isError()) {
messageItem.markAsError();
Application.getInstance().runInBackground(new Runnable() {
@Override
public void run() {
if (messageItem.getId() != null)
MessageTable.getInstance().markAsError(messageItem.getId());
}
});
MessageManager.getInstance().onChatChanged(messageItem.getChat().getAccount(), messageItem.getChat().getUser(), false);
}
} else {
// TODO setDefaultAutoReceiptMode should be used
for (ExtensionElement packetExtension : message.getExtensions()) if (packetExtension instanceof DeliveryReceiptRequest) {
String id = message.getPacketID();
if (id == null)
continue;
Message receipt = new Message(user);
receipt.addExtension(new DeliveryReceipt(id));
// the key problem is Thread - smack does not keep it in auto reply
receipt.setThread(message.getThread());
try {
ConnectionManager.getInstance().sendStanza(account, receipt);
} catch (NetworkException e) {
LogManager.exception(this, e);
}
}
}
}
use of com.xabber.android.data.NetworkException in project xabber-android by redsolution.
the class OTRManager method initSmp.
/**
* Initiate request using SM protocol.
*/
public void initSmp(String account, String user, String question, String secret) throws NetworkException {
LogManager.i(this, "initializing smp... " + user);
removeSMRequest(account, user);
addSMProgress(account, user);
try {
getOrCreateSession(account, user).initSmp(question, secret);
} catch (OtrException e) {
throw new NetworkException(R.string.OTR_ERROR, e);
}
}
use of com.xabber.android.data.NetworkException in project xabber-android by redsolution.
the class OTRManager method startSession.
public void startSession(String account, String user) throws NetworkException {
LogManager.i(this, "Starting session for " + user);
try {
getOrCreateSession(account, user).startSession();
} catch (OtrException e) {
throw new NetworkException(R.string.OTR_ERROR, e);
}
LogManager.i(this, "Started session for " + user);
}
use of com.xabber.android.data.NetworkException in project xabber-android by redsolution.
the class OTRManager method respondSmp.
/**
* Respond using SM protocol.
*/
public void respondSmp(String account, String user, String question, String secret) throws NetworkException {
LogManager.i(this, "responding smp... " + user);
removeSMRequest(account, user);
addSMProgress(account, user);
try {
getOrCreateSession(account, user).respondSmp(question, secret);
} catch (OtrException e) {
throw new NetworkException(R.string.OTR_ERROR, e);
}
}
Aggregations