use of eu.siacs.conversations.xmpp.jid.Jid in project Conversations by siacs.
the class ExportLogsService method writeToFile.
private void writeToFile(Conversation conversation) {
Jid accountJid = resolveAccountUuid(conversation.getAccountUuid());
Jid contactJid = conversation.getJid();
File dir = new File(String.format(DIRECTORY_STRING_FORMAT, accountJid.toBareJid().toString()));
dir.mkdirs();
BufferedWriter bw = null;
try {
for (Message message : mDatabaseBackend.getMessagesIterable(conversation)) {
if (message == null)
continue;
if (message.getType() == Message.TYPE_TEXT || message.hasFileOnRemoteHost()) {
String date = simpleDateFormat.format(new Date(message.getTimeSent()));
if (bw == null) {
bw = new BufferedWriter(new FileWriter(new File(dir, contactJid.toBareJid().toString() + ".txt")));
}
String jid = null;
switch(message.getStatus()) {
case Message.STATUS_RECEIVED:
jid = getMessageCounterpart(message);
break;
case Message.STATUS_SEND:
case Message.STATUS_SEND_RECEIVED:
case Message.STATUS_SEND_DISPLAYED:
jid = accountJid.toBareJid().toString();
break;
}
if (jid != null) {
String body = message.hasFileOnRemoteHost() ? message.getFileParams().url.toString() : message.getBody();
bw.write(String.format(MESSAGE_STRING_FORMAT, date, jid, body.replace("\\\n", "\\ \n").replace("\n", "\\ \n")));
}
}
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (bw != null) {
bw.close();
}
} catch (IOException e1) {
e1.printStackTrace();
}
}
}
use of eu.siacs.conversations.xmpp.jid.Jid in project Conversations by siacs.
the class XmppConnectionService method sendReadMarker.
public void sendReadMarker(final Conversation conversation) {
final Message markable = conversation.getLatestMarkableMessage();
if (this.markRead(conversation)) {
updateConversationUi();
}
if (confirmMessages() && markable != null && markable.trusted() && markable.getRemoteMsgId() != null) {
Log.d(Config.LOGTAG, conversation.getAccount().getJid().toBareJid() + ": sending read marker to " + markable.getCounterpart().toString());
Account account = conversation.getAccount();
final Jid to = markable.getCounterpart();
MessagePacket packet = mMessageGenerator.confirm(account, to, markable.getRemoteMsgId());
this.sendMessagePacket(conversation.getAccount(), packet);
}
}
use of eu.siacs.conversations.xmpp.jid.Jid in project Conversations by siacs.
the class HttpUploadConnection method init.
public void init(Message message, boolean delay) {
this.message = message;
this.account = message.getConversation().getAccount();
this.file = mXmppConnectionService.getFileBackend().getFile(message, false);
this.mime = this.file.getMimeType();
this.delayed = delay;
if (Config.ENCRYPT_ON_HTTP_UPLOADED || message.getEncryption() == Message.ENCRYPTION_AXOLOTL || message.getEncryption() == Message.ENCRYPTION_OTR) {
this.key = new byte[48];
mXmppConnectionService.getRNG().nextBytes(this.key);
this.file.setKeyAndIv(this.key);
}
Pair<InputStream, Integer> pair;
try {
pair = AbstractConnectionManager.createInputStream(file, true);
} catch (FileNotFoundException e) {
Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": could not find file to upload - " + e.getMessage());
fail(e.getMessage());
return;
}
this.file.setExpectedSize(pair.second);
this.mFileInputStream = pair.first;
Jid host = account.getXmppConnection().findDiscoItemByFeature(Namespace.HTTP_UPLOAD);
IqPacket request = mXmppConnectionService.getIqGenerator().requestHttpUploadSlot(host, file, mime);
mXmppConnectionService.sendIqPacket(account, request, new OnIqPacketReceived() {
@Override
public void onIqPacketReceived(Account account, IqPacket packet) {
if (packet.getType() == IqPacket.TYPE.RESULT) {
Element slot = packet.findChild("slot", Namespace.HTTP_UPLOAD);
if (slot != null) {
try {
mGetUrl = new URL(slot.findChildContent("get"));
mPutUrl = new URL(slot.findChildContent("put"));
if (!canceled) {
new Thread(new FileUploader()).start();
}
return;
} catch (MalformedURLException e) {
//fall through
}
}
}
Log.d(Config.LOGTAG, account.getJid().toString() + ": invalid response to slot request " + packet);
fail(IqParser.extractErrorMessage(packet));
}
});
message.setTransferable(this);
mXmppConnectionService.markMessage(message, Message.STATUS_UNSEND);
}
use of eu.siacs.conversations.xmpp.jid.Jid in project Conversations by siacs.
the class JingleConnection method upgradeNamespace.
private void upgradeNamespace() {
Jid jid = this.message.getCounterpart();
String resource = jid != null ? jid.getResourcepart() : null;
if (resource != null) {
Presence presence = this.account.getRoster().getContact(jid).getPresences().getPresences().get(resource);
ServiceDiscoveryResult result = presence != null ? presence.getServiceDiscoveryResult() : null;
if (result != null) {
List<String> features = result.getFeatures();
if (features.contains(Content.Version.FT_4.getNamespace())) {
this.ftVersion = Content.Version.FT_4;
}
}
}
}
use of eu.siacs.conversations.xmpp.jid.Jid in project Conversations by siacs.
the class JingleConnectionManager method getPrimaryCandidate.
public void getPrimaryCandidate(Account account, final OnPrimaryCandidateFound listener) {
if (Config.DISABLE_PROXY_LOOKUP) {
listener.onPrimaryCandidateFound(false, null);
return;
}
if (!this.primaryCandidates.containsKey(account.getJid().toBareJid())) {
final Jid proxy = account.getXmppConnection().findDiscoItemByFeature(Namespace.BYTE_STREAMS);
if (proxy != null) {
IqPacket iq = new IqPacket(IqPacket.TYPE.GET);
iq.setTo(proxy);
iq.query(Namespace.BYTE_STREAMS);
account.getXmppConnection().sendIqPacket(iq, new OnIqPacketReceived() {
@Override
public void onIqPacketReceived(Account account, IqPacket packet) {
Element streamhost = packet.query().findChild("streamhost", Namespace.BYTE_STREAMS);
final String host = streamhost == null ? null : streamhost.getAttribute("host");
final String port = streamhost == null ? null : streamhost.getAttribute("port");
if (host != null && port != null) {
try {
JingleCandidate candidate = new JingleCandidate(nextRandomId(), true);
candidate.setHost(host);
candidate.setPort(Integer.parseInt(port));
candidate.setType(JingleCandidate.TYPE_PROXY);
candidate.setJid(proxy);
candidate.setPriority(655360 + 65535);
primaryCandidates.put(account.getJid().toBareJid(), candidate);
listener.onPrimaryCandidateFound(true, candidate);
} catch (final NumberFormatException e) {
listener.onPrimaryCandidateFound(false, null);
return;
}
} else {
listener.onPrimaryCandidateFound(false, null);
}
}
});
} else {
listener.onPrimaryCandidateFound(false, null);
}
} else {
listener.onPrimaryCandidateFound(true, this.primaryCandidates.get(account.getJid().toBareJid()));
}
}
Aggregations