Commit 70255cb4 authored by Sébastien Blin's avatar Sébastien Blin Committed by Adrien Béraud

filetransfer: add multiple preferences

also fix account id detection

Change-Id: Ia4e297bd9e93acb2770077a4517442aef64f43fe
parent c5e5eb0f
......@@ -79,6 +79,21 @@ public:
*/
static QString createDefaultDirectory();
/**
* Accept transfer from untrusted contacts
*/
bool acceptFromUnstrusted {false};
/**
* Accept transfer from trusted contacts
*/
bool automaticAcceptTransfer {true};
/**
* Automatically accept transfer under
*/
unsigned acceptBehindMb {20} /* Mb */;
Q_SIGNALS:
/**
* Connect this signal to know when a data transfer is incoming.
......
......@@ -2157,9 +2157,10 @@ ConversationModel::getNumberOfUnreadMessagesFor(const QString& convUid)
}
bool
ConversationModelPimpl::usefulDataFromDataTransfer(long long dringId, const datatransfer::Info&,
ConversationModelPimpl::usefulDataFromDataTransfer(long long dringId, const datatransfer::Info& info,
int& interactionId, QString& convId)
{
if (info.accountId != linked.owner.id) return false;
try {
interactionId = lrc.getDataTransferModel().getInteractionIdFromDringId(dringId);
} catch (const std::out_of_range& e) {
......@@ -2254,16 +2255,19 @@ ConversationModelPimpl::slotTransferStatusAwaitingHost(long long dringId, datatr
dirtyConversations = {true, true};
emit linked.interactionStatusUpdated(convId, interactionId, itCopy);
// Only accept if contact is added
try {
auto contactUri = conversations[conversationIdx].participants.front();
auto contactInfo = linked.owner.contactModel->getContact(contactUri);
if (contactInfo.profileInfo.type != profile::Type::RING) return;
} catch (...) {
return;
if (!lrc.getDataTransferModel().acceptFromUnstrusted) {
try {
auto contactUri = conversations[conversationIdx].participants.front();
auto contactInfo = linked.owner.contactModel->getContact(contactUri);
if (contactInfo.profileInfo.type == profile::Type::PENDING) return;
} catch (...) {
return;
}
}
// If it's an accepted file type and less than 20 MB, accept transfer.
if (info.totalSize < 20 * 1024 * 1024) {
acceptTransfer(convId, interactionId, info.displayName);
if (lrc.getDataTransferModel().automaticAcceptTransfer) {
if (lrc.getDataTransferModel().acceptBehindMb == 0 || info.totalSize < lrc.getDataTransferModel().acceptBehindMb * 1024 * 1024)
acceptTransfer(convId, interactionId, info.displayName);
}
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment