1
0
mirror of https://github.com/MGislv/NekoX.git synced 2024-06-30 10:14:04 +00:00

Avoid uploading same file twice, bug fixes

This commit is contained in:
DrKLO 2014-06-16 16:36:54 +04:00
parent a87968cefc
commit 358a067acc
20 changed files with 398 additions and 231 deletions

View File

@ -81,7 +81,7 @@ android {
defaultConfig {
minSdkVersion 8
targetSdkVersion 19
versionCode 257
versionName "1.5.4"
versionCode 258
versionName "1.5.5"
}
}

View File

@ -63,7 +63,8 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
private boolean paused = false;
private long lastPingTime = System.currentTimeMillis();
private long lastPushPingTime = System.currentTimeMillis();
private long lastPushPingTime = 0;
private boolean sendingPushPing = false;
private int nextSleepTimeout = 30000;
private long nextPingId = 0;
@ -88,7 +89,11 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
Utilities.stageQueue.handler.removeCallbacks(stageRunnable);
t = System.currentTimeMillis();
if (datacenters != null) {
if (lastPushPingTime < System.currentTimeMillis() - 29000) {
if (sendingPushPing && lastPushPingTime < System.currentTimeMillis() - 30000 || Math.abs(lastPushPingTime - System.currentTimeMillis()) > 60000 * 4) {
lastPushPingTime = 0;
sendingPushPing = false;
}
if (lastPushPingTime < System.currentTimeMillis() - 60000 * 3) {
lastPushPingTime = System.currentTimeMillis();
Datacenter datacenter = datacenterWithId(currentDatacenterId);
if (datacenter != null) {
@ -1955,31 +1960,35 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
if (UserConfig.isClientActivated() && !UserConfig.registeredForInternalPush && (connection.transportRequestClass & RPCRequest.RPCRequestClassPush) != 0) {
registerForPush();
}
TLRPC.TL_pong pong = (TLRPC.TL_pong)message;
long pingId = pong.ping_id;
if ((connection.transportRequestClass & RPCRequest.RPCRequestClassPush) == 0) {
TLRPC.TL_pong pong = (TLRPC.TL_pong) message;
long pingId = pong.ping_id;
ArrayList<Long> itemsToDelete = new ArrayList<Long>();
for (Long pid : pingIdToDate.keySet()) {
if (pid == pingId) {
int time = pingIdToDate.get(pid);
int pingTime = (int)(System.currentTimeMillis() / 1000) - time;
ArrayList<Long> itemsToDelete = new ArrayList<Long>();
for (Long pid : pingIdToDate.keySet()) {
if (pid == pingId) {
int time = pingIdToDate.get(pid);
int pingTime = (int) (System.currentTimeMillis() / 1000) - time;
if (Math.abs(pingTime) < 10) {
currentPingTime = (pingTime + currentPingTime) / 2;
if (Math.abs(pingTime) < 10) {
currentPingTime = (pingTime + currentPingTime) / 2;
if (messageId != 0) {
long timeMessage = getTimeFromMsgId(messageId);
long currentTime = System.currentTimeMillis();
timeDifference = (int)((timeMessage - currentTime) / 1000 - currentPingTime / 2.0);
if (messageId != 0) {
long timeMessage = getTimeFromMsgId(messageId);
long currentTime = System.currentTimeMillis();
timeDifference = (int) ((timeMessage - currentTime) / 1000 - currentPingTime / 2.0);
}
}
itemsToDelete.add(pid);
} else if (pid < pingId) {
itemsToDelete.add(pid);
}
itemsToDelete.add(pid);
} else if (pid < pingId) {
itemsToDelete.add(pid);
}
}
for (Long pid : itemsToDelete) {
pingIdToDate.remove(pid);
for (Long pid : itemsToDelete) {
pingIdToDate.remove(pid);
}
} else {
sendingPushPing = false;
}
} else if (message instanceof TLRPC.TL_futuresalts) {
TLRPC.TL_futuresalts futureSalts = (TLRPC.TL_futuresalts)message;
@ -2345,17 +2354,21 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
TLRPC.TL_ping_delay_disconnect ping = new TLRPC.TL_ping_delay_disconnect();
ping.ping_id = nextPingId++;
ping.disconnect_delay = 35;
pingIdToDate.put(ping.ping_id, (int)(System.currentTimeMillis() / 1000));
if (pingIdToDate.size() > 20) {
ArrayList<Long> itemsToDelete = new ArrayList<Long>();
for (Long pid : pingIdToDate.keySet()) {
if (pid < nextPingId - 10) {
itemsToDelete.add(pid);
if ((connection.transportRequestClass & RPCRequest.RPCRequestClassPush) != 0) {
ping.disconnect_delay = 60 * 7;
} else {
ping.disconnect_delay = 35;
pingIdToDate.put(ping.ping_id, (int) (System.currentTimeMillis() / 1000));
if (pingIdToDate.size() > 20) {
ArrayList<Long> itemsToDelete = new ArrayList<Long>();
for (Long pid : pingIdToDate.keySet()) {
if (pid < nextPingId - 10) {
itemsToDelete.add(pid);
}
}
for (Long pid : itemsToDelete) {
pingIdToDate.remove(pid);
}
}
for (Long pid : itemsToDelete) {
pingIdToDate.remove(pid);
}
}
@ -2377,6 +2390,9 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
if (connection != null && (push || !push && connection.channelToken != 0)) {
ByteBufferDesc transportData = generatePingData(connection);
if (transportData != null) {
if (push) {
sendingPushPing = true;
}
connection.sendData(null, transportData, false);
}
}
@ -2558,6 +2574,9 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
NotificationCenter.getInstance().postNotificationName(703, stateCopy);
}
});
} else if ((connection.transportRequestClass & RPCRequest.RPCRequestClassPush) != 0) {
sendingPushPing = false;
lastPushPingTime = System.currentTimeMillis() - 60000 * 3 + 5000;
}
}
@ -2566,6 +2585,10 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
Datacenter datacenter = datacenterWithId(connection.getDatacenterId());
if (datacenter.authKey != null) {
processRequestQueue(connection.transportRequestClass, connection.getDatacenterId());
if ((connection.transportRequestClass & RPCRequest.RPCRequestClassPush) != 0) {
sendingPushPing = false;
lastPushPingTime = System.currentTimeMillis() - 60000 * 3 + 10000;
}
}
}

View File

@ -181,6 +181,10 @@ public class ContactsController {
}
} catch (Exception e) {
FileLog.e("tmessages", e);
} finally {
if (pCur != null) {
pCur.close();
}
}
try {
pCur = cr.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, new String[]{ContactsContract.CommonDataKinds.Phone._COUNT}, null, null, null);
@ -195,6 +199,10 @@ public class ContactsController {
}
} catch (Exception e) {
FileLog.e("tmessages", e);
} finally {
if (pCur != null) {
pCur.close();
}
}
try {
pCur = cr.query(ContactsContract.Data.CONTENT_URI, new String[]{ContactsContract.Data._COUNT}, ContactsContract.Data.MIMETYPE + " = '" + ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE + "'", null, null);
@ -209,6 +217,10 @@ public class ContactsController {
}
} catch (Exception e) {
FileLog.e("tmessages", e);
} finally {
if (pCur != null) {
pCur.close();
}
}
try {
pCur = cr.query(ContactsContract.Data.CONTENT_URI, new String[]{ContactsContract.Data._ID}, ContactsContract.Data.MIMETYPE + " = '" + ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE + "'", null, ContactsContract.Data._ID + " desc LIMIT 1");
@ -223,6 +235,10 @@ public class ContactsController {
}
} catch (Exception e) {
FileLog.e("tmessages", e);
} finally {
if (pCur != null) {
pCur.close();
}
}
} catch (Exception e) {
FileLog.e("tmessages", e);

View File

@ -337,11 +337,11 @@ public class FileLoader {
return memCache.get(key) != null;
}
public void uploadFile(final String location, final byte[] key, final byte[] iv) {
public void uploadFile(final String location, final String originalLocation, final boolean encrypted) {
fileLoaderQueue.postRunnable(new Runnable() {
@Override
public void run() {
if (key != null) {
if (encrypted) {
if (uploadOperationPathsEnc.containsKey(location)) {
return;
}
@ -350,8 +350,8 @@ public class FileLoader {
return;
}
}
FileUploadOperation operation = new FileUploadOperation(location, key, iv);
if (key != null) {
FileUploadOperation operation = new FileUploadOperation(location, originalLocation, encrypted);
if (encrypted) {
uploadOperationPathsEnc.put(location, operation);
} else {
uploadOperationPaths.put(location, operation);
@ -369,7 +369,7 @@ public class FileLoader {
fileProgresses.remove(location);
}
});
if (key != null) {
if (encrypted) {
uploadOperationPathsEnc.remove(location);
} else {
uploadOperationPaths.remove(location);
@ -396,11 +396,11 @@ public class FileLoader {
public void run() {
fileProgresses.remove(location);
if (operation.state != 2) {
NotificationCenter.getInstance().postNotificationName(FileDidFailUpload, location, key != null);
NotificationCenter.getInstance().postNotificationName(FileDidFailUpload, location, encrypted);
}
}
});
if (key != null) {
if (encrypted) {
uploadOperationPathsEnc.remove(location);
} else {
uploadOperationPaths.remove(location);
@ -428,7 +428,7 @@ public class FileLoader {
Utilities.RunOnUIThread(new Runnable() {
@Override
public void run() {
NotificationCenter.getInstance().postNotificationName(FileUploadProgressChanged, location, progress, key != null);
NotificationCenter.getInstance().postNotificationName(FileUploadProgressChanged, location, progress, encrypted);
}
});
}

View File

@ -13,11 +13,14 @@ import java.io.FileInputStream;
import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.Locale;
import java.util.concurrent.Semaphore;
public class FileUploadOperation {
private int uploadChunkSize = 1024 * 32;
private String uploadingFilePath;
private String originalPath;
public int state = 0;
private byte[] readBuffer;
public FileUploadOperationDelegate delegate;
@ -30,6 +33,7 @@ public class FileUploadOperation {
private long currentUploaded = 0;
private byte[] key;
private byte[] iv;
private byte[] ivChange;
private int fingerprint;
private boolean isBigFile = false;
FileInputStream stream;
@ -41,12 +45,16 @@ public class FileUploadOperation {
public abstract void didChangedUploadProgress(FileUploadOperation operation, float progress);
}
public FileUploadOperation(String location, byte[] keyarr, byte[] ivarr) {
public FileUploadOperation(String location, String originalLocaltion, boolean encrypted) {
uploadingFilePath = location;
if (ivarr != null && keyarr != null) {
originalPath = originalLocaltion;
if (encrypted) {
iv = new byte[32];
key = keyarr;
System.arraycopy(ivarr, 0, iv, 0, 32);
key = new byte[32];
ivChange = new byte[32];
Utilities.random.nextBytes(iv);
Utilities.random.nextBytes(key);
System.arraycopy(iv, 0, ivChange, 0, 32);
try {
java.security.MessageDigest md = java.security.MessageDigest.getInstance("MD5");
byte[] arr = new byte[64];
@ -98,6 +106,26 @@ public class FileUploadOperation {
try {
if (stream == null) {
if (originalPath != null) {
Semaphore semaphore = new Semaphore(0);
ArrayList<TLObject> result = new ArrayList<TLObject>();
String path = originalPath;
if (key != null) {
path += "e";
}
MessagesStorage.getInstance().getSentFile(path, semaphore, result);
semaphore.acquire();
if (!result.isEmpty()) {
TLObject object = result.get(0);
if (object instanceof TLRPC.InputFile) {
delegate.didFinishUploadingFile(FileUploadOperation.this, (TLRPC.InputFile) object, null);
return;
} else if (object instanceof TLRPC.InputEncryptedFile) {
delegate.didFinishUploadingFile(FileUploadOperation.this, null, (TLRPC.InputEncryptedFile) object);
return;
}
}
}
File cacheFile = new File(uploadingFilePath);
stream = new FileInputStream(cacheFile);
totalFileSize = cacheFile.length();
@ -106,7 +134,7 @@ public class FileUploadOperation {
isBigFile = true;
}
uploadChunkSize = (int)Math.max(32, Math.ceil(totalFileSize / (1024.0f * 3000)));
uploadChunkSize = (int) Math.max(32, Math.ceil(totalFileSize / (1024.0f * 3000)));
if (1024 % uploadChunkSize != 0) {
int chunkSize = 64;
while (uploadChunkSize > chunkSize) {
@ -116,7 +144,7 @@ public class FileUploadOperation {
}
uploadChunkSize *= 1024;
totalPartsCount = (int)Math.ceil((float)totalFileSize / (float)uploadChunkSize);
totalPartsCount = (int) Math.ceil((float) totalFileSize / (float) uploadChunkSize);
readBuffer = new byte[uploadChunkSize];
}
@ -134,7 +162,7 @@ public class FileUploadOperation {
for (int a = 0; a < toAdd; a++) {
sendBuffer.writeByte(0);
}
Utilities.aesIgeEncryption2(sendBuffer.buffer, key, iv, true, true, readed + toAdd);
Utilities.aesIgeEncryption2(sendBuffer.buffer, key, ivChange, true, true, readed + toAdd);
}
sendBuffer.rewind();
if (!isBigFile) {
@ -161,55 +189,63 @@ public class FileUploadOperation {
return;
}
requestToken = ConnectionsManager.getInstance().performRpc(finalRequest, new RPCRequest.RPCRequestDelegate() {
@Override
public void run(TLObject response, TLRPC.TL_error error) {
requestToken = 0;
if (error == null) {
if (response instanceof TLRPC.TL_boolTrue) {
currentPartNum++;
delegate.didChangedUploadProgress(FileUploadOperation.this, (float)currentUploaded / (float)totalFileSize);
if (isLastPart) {
state = 3;
if (key == null) {
TLRPC.InputFile result;
if (isBigFile) {
result = new TLRPC.TL_inputFileBig();
} else {
result = new TLRPC.TL_inputFile();
result.md5_checksum = String.format(Locale.US, "%32s", new BigInteger(1, mdEnc.digest()).toString(16)).replace(' ', '0');
}
result.parts = currentPartNum;
result.id = currentFileId;
result.name = uploadingFilePath.substring(uploadingFilePath.lastIndexOf("/") + 1);
delegate.didFinishUploadingFile(FileUploadOperation.this, result, null);
} else {
TLRPC.InputEncryptedFile result;
if (isBigFile) {
result = new TLRPC.TL_inputEncryptedFileBigUploaded();
} else {
result = new TLRPC.TL_inputEncryptedFileUploaded();
result.md5_checksum = String.format(Locale.US, "%32s", new BigInteger(1, mdEnc.digest()).toString(16)).replace(' ', '0');
}
result.parts = currentPartNum;
result.id = currentFileId;
result.key_fingerprint = fingerprint;
delegate.didFinishUploadingFile(FileUploadOperation.this, null, result);
}
@Override
public void run(TLObject response, TLRPC.TL_error error) {
requestToken = 0;
if (error == null) {
if (response instanceof TLRPC.TL_boolTrue) {
currentPartNum++;
delegate.didChangedUploadProgress(FileUploadOperation.this, (float) currentUploaded / (float) totalFileSize);
if (isLastPart) {
state = 3;
if (key == null) {
TLRPC.InputFile result;
if (isBigFile) {
result = new TLRPC.TL_inputFileBig();
} else {
startUploadRequest();
result = new TLRPC.TL_inputFile();
result.md5_checksum = String.format(Locale.US, "%32s", new BigInteger(1, mdEnc.digest()).toString(16)).replace(' ', '0');
}
result.parts = currentPartNum;
result.id = currentFileId;
result.name = uploadingFilePath.substring(uploadingFilePath.lastIndexOf("/") + 1);
delegate.didFinishUploadingFile(FileUploadOperation.this, result, null);
if (originalPath != null) {
MessagesStorage.getInstance().putSentFile(originalPath, result, null, null);
}
} else {
delegate.didFailedUploadingFile(FileUploadOperation.this);
TLRPC.InputEncryptedFile result;
if (isBigFile) {
result = new TLRPC.TL_inputEncryptedFileBigUploaded();
} else {
result = new TLRPC.TL_inputEncryptedFileUploaded();
result.md5_checksum = String.format(Locale.US, "%32s", new BigInteger(1, mdEnc.digest()).toString(16)).replace(' ', '0');
}
result.parts = currentPartNum;
result.id = currentFileId;
result.key_fingerprint = fingerprint;
result.iv = iv;
result.key = key;
delegate.didFinishUploadingFile(FileUploadOperation.this, null, result);
if (originalPath != null) {
MessagesStorage.getInstance().putSentFile(originalPath + "e", result, key, iv);
}
}
} else {
delegate.didFailedUploadingFile(FileUploadOperation.this);
startUploadRequest();
}
} else {
delegate.didFailedUploadingFile(FileUploadOperation.this);
}
}, new RPCRequest.RPCProgressDelegate() {
@Override
public void progress(int length, int progress) {
} else {
delegate.didFailedUploadingFile(FileUploadOperation.this);
}
}
}, new RPCRequest.RPCProgressDelegate() {
@Override
public void progress(int length, int progress) {
}
}, null, true, RPCRequest.RPCRequestClassUploadMedia, ConnectionsManager.DEFAULT_DATACENTER_ID);
}
}, null, true, RPCRequest.RPCRequestClassUploadMedia, ConnectionsManager.DEFAULT_DATACENTER_ID);
}
}

View File

@ -127,6 +127,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
public TLRPC.TL_messages_sendMedia sendRequest;
public TLRPC.TL_decryptedMessage sendEncryptedRequest;
public int type;
public String originalPath;
public TLRPC.FileLocation location;
public TLRPC.TL_video videoLocation;
public TLRPC.TL_audio audioLocation;
@ -587,7 +588,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
public void uploadAndApplyUserAvatar(TLRPC.PhotoSize bigPhoto) {
if (bigPhoto != null) {
uploadingAvatar = Utilities.getCacheDir() + "/" + bigPhoto.location.volume_id + "_" + bigPhoto.location.local_id + ".jpg";
FileLoader.getInstance().uploadFile(uploadingAvatar, null, null);
FileLoader.getInstance().uploadFile(uploadingAvatar, null, false);
}
}
@ -1546,39 +1547,39 @@ public class MessagesController implements NotificationCenter.NotificationCenter
}
public void sendMessage(TLRPC.User user, long peer) {
sendMessage(null, 0, 0, null, null, null, null, user, null, null, peer);
sendMessage(null, 0, 0, null, null, null, null, user, null, null, null, peer);
}
public void sendMessage(MessageObject message, long peer) {
sendMessage(null, 0, 0, null, null, message, null, null, null, null, peer);
sendMessage(null, 0, 0, null, null, message, null, null, null, null, null, peer);
}
public void sendMessage(TLRPC.TL_document document, long peer) {
sendMessage(null, 0, 0, null, null, null, null, null, document, null, peer);
public void sendMessage(TLRPC.TL_document document, String originalPath, long peer) {
sendMessage(null, 0, 0, null, null, null, null, null, document, null, originalPath, peer);
}
public void sendMessage(String message, long peer) {
sendMessage(message, 0, 0, null, null, null, null, null, null, null, peer);
sendMessage(message, 0, 0, null, null, null, null, null, null, null, null, peer);
}
public void sendMessage(TLRPC.FileLocation location, long peer) {
sendMessage(null, 0, 0, null, null, null, location, null, null, null, peer);
sendMessage(null, 0, 0, null, null, null, location, null, null, null, null, peer);
}
public void sendMessage(double lat, double lon, long peer) {
sendMessage(null, lat, lon, null, null, null, null, null, null, null, peer);
sendMessage(null, lat, lon, null, null, null, null, null, null, null, null, peer);
}
public void sendMessage(TLRPC.TL_photo photo, long peer) {
sendMessage(null, 0, 0, photo, null, null, null, null, null, null, peer);
public void sendMessage(TLRPC.TL_photo photo, String originalPath, long peer) {
sendMessage(null, 0, 0, photo, null, null, null, null, null, null, originalPath, peer);
}
public void sendMessage(TLRPC.TL_video video, long peer) {
sendMessage(null, 0, 0, null, video, null, null, null, null, null, peer);
public void sendMessage(TLRPC.TL_video video, String originalPath, long peer) {
sendMessage(null, 0, 0, null, video, null, null, null, null, null, originalPath, peer);
}
public void sendMessage(TLRPC.TL_audio audio, long peer) {
sendMessage(null, 0, 0, null, null, null, null, null, null, audio, peer);
sendMessage(null, 0, 0, null, null, null, null, null, null, audio, null, peer);
}
private void processPendingEncMessages() {
@ -1708,7 +1709,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
performSendEncryptedRequest(reqSend, newMsgObj, encryptedChat, null);
}
private void sendMessage(String message, double lat, double lon, TLRPC.TL_photo photo, TLRPC.TL_video video, MessageObject msgObj, TLRPC.FileLocation location, TLRPC.User user, TLRPC.TL_document document, TLRPC.TL_audio audio, long peer) {
private void sendMessage(String message, double lat, double lon, TLRPC.TL_photo photo, TLRPC.TL_video video, MessageObject msgObj, TLRPC.FileLocation location, TLRPC.User user, TLRPC.TL_document document, TLRPC.TL_audio audio, String originalPath, long peer) {
TLRPC.Message newMsg = null;
int type = -1;
if (message != null) {
@ -1731,7 +1732,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
type = 2;
newMsg.message = "-1";
TLRPC.FileLocation location1 = photo.sizes.get(photo.sizes.size() - 1).location;
newMsg.attachPath = Utilities.getCacheDir() + "/" + location1.volume_id + "_" + location1.local_id + ".jpg";
newMsg.attachPath = originalPath;
} else if (video != null) {
newMsg = new TLRPC.TL_message();
newMsg.media = new TLRPC.TL_messageMediaVideo();
@ -1882,6 +1883,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
} else if (type == 2) {
reqSend.media = new TLRPC.TL_inputMediaUploadedPhoto();
DelayedMessage delayedMessage = new DelayedMessage();
delayedMessage.originalPath = originalPath;
delayedMessage.sendRequest = reqSend;
delayedMessage.type = 0;
delayedMessage.obj = newMsgObj;
@ -1893,6 +1895,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
reqSend.media.w = video.w;
reqSend.media.h = video.h;
DelayedMessage delayedMessage = new DelayedMessage();
delayedMessage.originalPath = originalPath;
delayedMessage.sendRequest = reqSend;
delayedMessage.type = 1;
delayedMessage.obj = newMsgObj;
@ -1921,6 +1924,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
reqSend.media.mime_type = document.mime_type;
reqSend.media.file_name = document.file_name;
DelayedMessage delayedMessage = new DelayedMessage();
delayedMessage.originalPath = originalPath;
delayedMessage.sendRequest = reqSend;
delayedMessage.type = 2;
delayedMessage.obj = newMsgObj;
@ -1931,6 +1935,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
reqSend.media = new TLRPC.TL_inputMediaUploadedAudio();
reqSend.media.duration = audio.duration;
DelayedMessage delayedMessage = new DelayedMessage();
delayedMessage.originalPath = originalPath;
delayedMessage.sendRequest = reqSend;
delayedMessage.type = 3;
delayedMessage.obj = newMsgObj;
@ -1950,10 +1955,6 @@ public class MessagesController implements NotificationCenter.NotificationCenter
performSendEncryptedRequest(reqSend, newMsgObj, encryptedChat, null);
} else if (type == 2) {
reqSend.media = new TLRPC.TL_decryptedMessageMediaPhoto();
reqSend.media.iv = new byte[32];
reqSend.media.key = new byte[32];
Utilities.random.nextBytes(reqSend.media.iv);
Utilities.random.nextBytes(reqSend.media.key);
TLRPC.PhotoSize small = photo.sizes.get(0);
TLRPC.PhotoSize big = photo.sizes.get(photo.sizes.size() - 1);
reqSend.media.thumb = small.bytes;
@ -1964,6 +1965,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
reqSend.media.size = big.size;
DelayedMessage delayedMessage = new DelayedMessage();
delayedMessage.originalPath = originalPath;
delayedMessage.sendEncryptedRequest = reqSend;
delayedMessage.type = 0;
delayedMessage.obj = newMsgObj;
@ -1972,10 +1974,6 @@ public class MessagesController implements NotificationCenter.NotificationCenter
performSendDelayedMessage(delayedMessage);
} else if (type == 3) {
reqSend.media = new TLRPC.TL_decryptedMessageMediaVideo();
reqSend.media.iv = new byte[32];
reqSend.media.key = new byte[32];
Utilities.random.nextBytes(reqSend.media.iv);
Utilities.random.nextBytes(reqSend.media.key);
reqSend.media.duration = video.duration;
reqSend.media.size = video.size;
reqSend.media.w = video.w;
@ -1985,6 +1983,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
reqSend.media.thumb_w = video.thumb.w;
DelayedMessage delayedMessage = new DelayedMessage();
delayedMessage.originalPath = originalPath;
delayedMessage.sendEncryptedRequest = reqSend;
delayedMessage.type = 1;
delayedMessage.obj = newMsgObj;
@ -2002,10 +2001,6 @@ public class MessagesController implements NotificationCenter.NotificationCenter
performSendEncryptedRequest(reqSend, newMsgObj, encryptedChat, null);
} else if (type == 7) {
reqSend.media = new TLRPC.TL_decryptedMessageMediaDocument();
reqSend.media.iv = new byte[32];
reqSend.media.key = new byte[32];
Utilities.random.nextBytes(reqSend.media.iv);
Utilities.random.nextBytes(reqSend.media.key);
reqSend.media.size = document.size;
if (!(document.thumb instanceof TLRPC.TL_photoSizeEmpty)) {
reqSend.media.thumb = document.thumb.bytes;
@ -2020,6 +2015,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
reqSend.media.mime_type = document.mime_type;
DelayedMessage delayedMessage = new DelayedMessage();
delayedMessage.originalPath = originalPath;
delayedMessage.sendEncryptedRequest = reqSend;
delayedMessage.type = 2;
delayedMessage.obj = newMsgObj;
@ -2028,14 +2024,11 @@ public class MessagesController implements NotificationCenter.NotificationCenter
performSendDelayedMessage(delayedMessage);
} else if (type == 8) {
reqSend.media = new TLRPC.TL_decryptedMessageMediaAudio();
reqSend.media.iv = new byte[32];
reqSend.media.key = new byte[32];
Utilities.random.nextBytes(reqSend.media.iv);
Utilities.random.nextBytes(reqSend.media.key);
reqSend.media.duration = audio.duration;
reqSend.media.size = audio.size;
DelayedMessage delayedMessage = new DelayedMessage();
delayedMessage.originalPath = originalPath;
delayedMessage.sendEncryptedRequest = reqSend;
delayedMessage.type = 3;
delayedMessage.obj = newMsgObj;
@ -2470,23 +2463,23 @@ public class MessagesController implements NotificationCenter.NotificationCenter
String location = Utilities.getCacheDir() + "/" + message.location.volume_id + "_" + message.location.local_id + ".jpg";
putToDelayedMessages(location, message);
if (message.sendRequest != null) {
FileLoader.getInstance().uploadFile(location, null, null);
FileLoader.getInstance().uploadFile(location, message.originalPath, false);
} else {
FileLoader.getInstance().uploadFile(location, message.sendEncryptedRequest.media.key, message.sendEncryptedRequest.media.iv);
FileLoader.getInstance().uploadFile(location, message.originalPath, true);
}
} else if (message.type == 1) {
if (message.sendRequest != null) {
if (message.sendRequest.media.thumb == null) {
String location = Utilities.getCacheDir() + "/" + message.location.volume_id + "_" + message.location.local_id + ".jpg";
putToDelayedMessages(location, message);
FileLoader.getInstance().uploadFile(location, null, null);
FileLoader.getInstance().uploadFile(location, message.originalPath + "thumb", false);
} else {
String location = message.videoLocation.path;
if (location == null) {
location = Utilities.getCacheDir() + "/" + message.videoLocation.id + ".mp4";
}
putToDelayedMessages(location, message);
FileLoader.getInstance().uploadFile(location, null, null);
FileLoader.getInstance().uploadFile(location, message.originalPath, false);
}
} else {
String location = message.videoLocation.path;
@ -2494,29 +2487,29 @@ public class MessagesController implements NotificationCenter.NotificationCenter
location = Utilities.getCacheDir() + "/" + message.videoLocation.id + ".mp4";
}
putToDelayedMessages(location, message);
FileLoader.getInstance().uploadFile(location, message.sendEncryptedRequest.media.key, message.sendEncryptedRequest.media.iv);
FileLoader.getInstance().uploadFile(location, message.originalPath, true);
}
} else if (message.type == 2) {
if (message.sendRequest != null && message.sendRequest.media.thumb == null && message.location != null) {
String location = Utilities.getCacheDir() + "/" + message.location.volume_id + "_" + message.location.local_id + ".jpg";
putToDelayedMessages(location, message);
FileLoader.getInstance().uploadFile(location, null, null);
FileLoader.getInstance().uploadFile(location, message.originalPath + "thumb", false);
} else {
String location = message.documentLocation.path;
putToDelayedMessages(location, message);
if (message.sendRequest != null) {
FileLoader.getInstance().uploadFile(location, null, null);
FileLoader.getInstance().uploadFile(location, message.originalPath, false);
} else {
FileLoader.getInstance().uploadFile(location, message.sendEncryptedRequest.media.key, message.sendEncryptedRequest.media.iv);
FileLoader.getInstance().uploadFile(location, message.originalPath, true);
}
}
} else if (message.type == 3) {
String location = message.audioLocation.path;
putToDelayedMessages(location, message);
if (message.sendRequest != null) {
FileLoader.getInstance().uploadFile(location, null, null);
FileLoader.getInstance().uploadFile(location, null, false);
} else {
FileLoader.getInstance().uploadFile(location, message.sendEncryptedRequest.media.key, message.sendEncryptedRequest.media.iv);
FileLoader.getInstance().uploadFile(location, null, true);
}
}
}
@ -2633,6 +2626,8 @@ public class MessagesController implements NotificationCenter.NotificationCenter
arr.remove(a);
a--;
} else if (encryptedFile != null && message.sendEncryptedRequest != null) {
message.sendEncryptedRequest.media.key = encryptedFile.key;
message.sendEncryptedRequest.media.iv = encryptedFile.iv;
performSendEncryptedRequest(message.sendEncryptedRequest, message.obj, message.encryptedChat, encryptedFile);
arr.remove(a);
a--;

View File

@ -97,6 +97,8 @@ public class MessagesStorage {
database.executeFast("CREATE TABLE user_contacts_v6(uid INTEGER PRIMARY KEY, fname TEXT, sname TEXT)").stepThis().dispose();
database.executeFast("CREATE TABLE user_phones_v6(uid INTEGER, phone TEXT, sphone TEXT, deleted INTEGER, PRIMARY KEY (uid, phone))").stepThis().dispose();
database.executeFast("CREATE TABLE sent_files(uid TEXT PRIMARY KEY, data BLOB, key BLOB, iv BLOB)").stepThis().dispose();
database.executeFast("CREATE INDEX IF NOT EXISTS mid_idx_randoms ON randoms(mid);").stepThis().dispose();
database.executeFast("CREATE INDEX IF NOT EXISTS sphone_deleted_idx_user_phones ON user_phones_v6(sphone, deleted);").stepThis().dispose();
@ -166,6 +168,8 @@ public class MessagesStorage {
database.executeFast("CREATE INDEX IF NOT EXISTS sphone_deleted_idx_user_phones ON user_phones_v6(sphone, deleted);").stepThis().dispose();
database.executeFast("CREATE INDEX IF NOT EXISTS mid_idx_randoms ON randoms(mid);").stepThis().dispose();
database.executeFast("CREATE TABLE IF NOT EXISTS sent_files(uid TEXT PRIMARY KEY, data BLOB, key BLOB, iv BLOB)").stepThis().dispose();
}
} catch (Exception e) {
FileLog.e("tmessages", e);
@ -1496,6 +1500,80 @@ public class MessagesStorage {
});
}
public void getSentFile(final String path, final Semaphore semaphore, final ArrayList<TLObject> result) {
if (path == null || semaphore == null || result == null) {
return;
}
storageQueue.postRunnable(new Runnable() {
@Override
public void run() {
try {
String id = Utilities.MD5(path);
if (id != null) {
SQLiteCursor cursor = database.queryFinalized("SELECT data, key, iv FROM sent_files WHERE uid = '" + id + "'");
if (cursor.next()) {
byte[] fileData = cursor.byteArrayValue(0);
if (fileData != null) {
SerializedData data = new SerializedData(fileData);
TLObject file = TLClassStore.Instance().TLdeserialize(data, data.readInt32());
if (file instanceof TLRPC.InputEncryptedFile) {
TLRPC.InputEncryptedFile encFile = (TLRPC.InputEncryptedFile)file;
encFile.key = cursor.byteArrayValue(1);
encFile.iv = cursor.byteArrayValue(2);
if (encFile.key != null && encFile.iv != null) {
result.add(file);
}
} else if (file instanceof TLRPC.InputFile) {
result.add(file);
}
}
}
cursor.dispose();
}
} catch (Exception e) {
FileLog.e("tmessages", e);
} finally {
semaphore.release();
}
}
});
}
public void putSentFile(final String path, final TLObject file, final byte[] key, final byte[] iv) {
if (path == null || file == null) {
return;
}
storageQueue.postRunnable(new Runnable() {
@Override
public void run() {
try {
String id = Utilities.MD5(path);
if (id != null) {
SQLitePreparedStatement state = null;
if (key != null && iv != null) {
state = database.executeFast("REPLACE INTO sent_files VALUES(?, ?, ?, ?)");
} else {
state = database.executeFast("REPLACE INTO sent_files VALUES(?, ?, NULL, NULL)");
}
state.requery();
SerializedData data = new SerializedData();
file.serializeToStream(data);
state.bindString(1, id);
state.bindByteArray(2, data.toByteArray());
if (key != null && iv != null) {
state.bindByteArray(3, key);
state.bindByteArray(4, iv);
}
state.step();
state.dispose();
}
} catch (Exception e) {
FileLog.e("tmessages", e);
}
}
});
}
public void getEncryptedChat(final int chat_id, final Semaphore semaphore, final ArrayList<TLObject> result) {
if (semaphore == null || result == null) {
return;

View File

@ -47,28 +47,44 @@ public class NativeLoader {
}
}
private static OutputStreamWriter streamWriter = null;
private static FileOutputStream stream = null;
private static void closeStream() {
try {
if (stream != null) {
streamWriter.close();
stream.close();
stream = null;
streamWriter = null;
}
} catch (Exception e) {
e.printStackTrace();
}
}
public static void writeNativeError(Context context, String info, Throwable throwable) {
try {
File sdCard = context.getFilesDir();
if (sdCard == null) {
return;
}
File file = new File(sdCard, "nativeer.log");
if (file == null) {
return;
}
if (stream == null) {
File sdCard = context.getFilesDir();
if (sdCard == null) {
return;
}
File file = new File(sdCard, "nativeer.log");
if (file == null) {
return;
}
FileOutputStream stream = new FileOutputStream(file);
OutputStreamWriter streamWriter = new OutputStreamWriter(stream);
streamWriter.write("info" + "\n");
stream = new FileOutputStream(file);
streamWriter = new OutputStreamWriter(stream);
}
streamWriter.write(info + "\n");
streamWriter.write(throwable + "\n");
StackTraceElement[] stack = throwable.getStackTrace();
for (StackTraceElement el : stack) {
streamWriter.write(el + "\n");
}
streamWriter.flush();
streamWriter.close();
stream.close();
} catch (Exception e) {
e.printStackTrace();
}
@ -147,9 +163,9 @@ public class NativeLoader {
return;
}
try {
cleanNativeLog(context);
cleanNativeLog(context);
try {
String folder = null;
long libSize = 0;
long libSize2 = 0;
@ -191,6 +207,7 @@ public class NativeLoader {
try {
System.loadLibrary("tmessages");
nativeLoaded = true;
closeStream();
return;
} catch (Error e) {
FileLog.e("tmessages", e);
@ -206,6 +223,7 @@ public class NativeLoader {
FileLog.d("tmessages", "Load local lib");
System.load(destLocalFile.getAbsolutePath());
nativeLoaded = true;
closeStream();
return;
} catch (Error e) {
FileLog.e("tmessages", e);
@ -230,6 +248,7 @@ public class NativeLoader {
try {
System.loadLibrary("tmessages");
nativeLoaded = true;
closeStream();
} catch (Error e) {
writeNativeError(context, "last chance", e);
FileLog.e("tmessages", e);

View File

@ -3783,14 +3783,6 @@ public class TLRPC {
}
}
public static class InputEncryptedFile extends TLObject {
public long id;
public long access_hash;
public int parts;
public int key_fingerprint;
public String md5_checksum;
}
public static class TL_inputEncryptedFile extends InputEncryptedFile {
public static int constructor = 0x5a17b5e5;
@ -9212,4 +9204,14 @@ public class TLRPC {
}
}
}
public static class InputEncryptedFile extends TLObject {
public long id;
public long access_hash;
public int parts;
public int key_fingerprint;
public String md5_checksum;
public byte[] key;
public byte[] iv;
}
}

View File

@ -135,7 +135,7 @@ public class TcpConnection extends ConnectionContext {
client.addListener(TcpConnection.this);
if ((transportRequestClass & RPCRequest.RPCRequestClassPush) != 0) {
if (isNextPort) {
client.setTimeout(15000);
client.setTimeout(20000);
} else {
client.setTimeout(30000);
}
@ -424,7 +424,7 @@ public class TcpConnection extends ConnectionContext {
datacenter.storeCurrentAddressAndPortNum();
isNextPort = false;
if ((transportRequestClass & RPCRequest.RPCRequestClassPush) != 0) {
client.setTimeout(40000);
client.setTimeout(60000 * 3 + 20000);
} else {
client.setTimeout(25000);
}

View File

@ -747,6 +747,9 @@ public class Utilities {
}
public static String MD5(String md5) {
if (md5 == null) {
return null;
}
try {
java.security.MessageDigest md = java.security.MessageDigest.getInstance("MD5");
byte[] array = md.digest(md5.getBytes());

View File

@ -1646,17 +1646,19 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
String tempPath = Utilities.getPath(data.getData());
boolean isGif = false;
String originalPath = null;
if (tempPath != null && tempPath.endsWith(".gif")) {
isGif = true;
} else if (tempPath == null) {
isGif = MediaController.isGif(data.getData());
if (isGif) {
originalPath = data.toString();
tempPath = MediaController.copyDocumentToCache(data.getData(), "gif");
}
}
if (tempPath != null && isGif) {
processSendingDocument(tempPath);
processSendingDocument(tempPath, originalPath);
} else {
processSendingPhoto(null, data.getData());
}
@ -1699,15 +1701,17 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
showAttachmentError();
return;
}
String originalPath = null;
String tempPath = Utilities.getPath(data.getData());
if (tempPath == null) {
originalPath = data.toString();
tempPath = MediaController.copyDocumentToCache(data.getData(), "file");
}
if (tempPath == null) {
showAttachmentError();
return;
}
processSendingDocument(tempPath);
processSendingDocument(tempPath, originalPath);
}
}
}
@ -1751,7 +1755,11 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
}
TLRPC.TL_photo photo = MessagesController.getInstance().generatePhotoSizes(imageFilePath, imageUri);
if (photo != null) {
MessagesController.getInstance().sendMessage(photo, dialog_id);
String originalPath = imageFilePath;
if (originalPath == null && imageUri != null) {
originalPath = imageUri.toString();
}
MessagesController.getInstance().sendMessage(photo, originalPath, dialog_id);
if (chatListView != null) {
chatListView.setSelection(messages.size() + 1);
}
@ -1790,16 +1798,21 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
Utilities.RunOnUIThread(new Runnable() {
@Override
public void run() {
processSendingDocument(finalPath);
processSendingDocument(finalPath, null);
}
});
} else {
final TLRPC.TL_photo photo = MessagesController.getInstance().generatePhotoSizes(path, uri);
String originalPath = path;
if (originalPath == null && uri != null) {
originalPath = uri.toString();
}
final String originalPathFinal = originalPath;
Utilities.RunOnUIThread(new Runnable() {
@Override
public void run() {
if (photo != null) {
MessagesController.getInstance().sendMessage(photo, dialog_id);
MessagesController.getInstance().sendMessage(photo, originalPathFinal, dialog_id);
if (chatListView != null) {
chatListView.setSelection(messages.size() + 1);
}
@ -1813,7 +1826,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
}).start();
}
public void processSendingDocument(String documentFilePath) {
public void processSendingDocument(String documentFilePath, String originalPathOverride) {
if (documentFilePath == null || documentFilePath.length() == 0) {
return;
}
@ -1864,7 +1877,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
document.thumb = new TLRPC.TL_photoSizeEmpty();
document.thumb.type = "s";
}
MessagesController.getInstance().sendMessage(document, dialog_id);
MessagesController.getInstance().sendMessage(document, originalPathOverride == null ? (documentFilePath + document.size) : originalPathOverride, dialog_id);
}
public void processSendingVideo(final String videoPath) {
@ -1899,7 +1912,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
mp.release();
MediaStore.Video.Media media = new MediaStore.Video.Media();
MessagesController.getInstance().sendMessage(video, dialog_id);
MessagesController.getInstance().sendMessage(video, videoPath, dialog_id);
if (chatListView != null) {
chatListView.setSelection(messages.size() + 1);
}
@ -3127,7 +3140,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
MessagesController.getInstance().sendMessage(selectedObject, dialog_id);
} else {
TLRPC.TL_photo photo = (TLRPC.TL_photo)selectedObject.messageOwner.media.photo;
MessagesController.getInstance().sendMessage(photo, dialog_id);
MessagesController.getInstance().sendMessage(photo, selectedObject.messageOwner.attachPath, dialog_id);
}
} else if (selectedObject.type == 3) {
if (selectedObject.messageOwner instanceof TLRPC.TL_messageForwarded) {
@ -3135,7 +3148,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
} else {
TLRPC.TL_video video = (TLRPC.TL_video)selectedObject.messageOwner.media.video;
video.path = selectedObject.messageOwner.attachPath;
MessagesController.getInstance().sendMessage(video, dialog_id);
MessagesController.getInstance().sendMessage(video, video.path, dialog_id);
}
} else if (selectedObject.type == 12 || selectedObject.type == 13) {
TLRPC.User user = MessagesController.getInstance().users.get(selectedObject.messageOwner.media.user_id);
@ -3143,7 +3156,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
} else if (selectedObject.type == 8 || selectedObject.type == 9) {
TLRPC.TL_document document = (TLRPC.TL_document)selectedObject.messageOwner.media.document;
document.path = selectedObject.messageOwner.attachPath;
MessagesController.getInstance().sendMessage(document, dialog_id);
MessagesController.getInstance().sendMessage(document, document.path, dialog_id);
} else if (selectedObject.type == 2) {
TLRPC.TL_audio audio = (TLRPC.TL_audio)selectedObject.messageOwner.media.audio;
audio.path = selectedObject.messageOwner.attachPath;
@ -3201,43 +3214,9 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
}
@Override
public void didSelectFile(DocumentSelectActivity activity, String path, String name, String ext, long size) {
public void didSelectFile(DocumentSelectActivity activity, String path) {
activity.finishFragment();
TLRPC.TL_document document = new TLRPC.TL_document();
document.id = 0;
document.user_id = UserConfig.getClientUserId();
document.date = ConnectionsManager.getInstance().getCurrentTime();
document.file_name = name;
document.size = (int)size;
document.dc_id = 0;
document.path = path;
if (ext.length() != 0) {
MimeTypeMap myMime = MimeTypeMap.getSingleton();
String mimeType = myMime.getMimeTypeFromExtension(ext.toLowerCase());
if (mimeType != null) {
document.mime_type = mimeType;
} else {
document.mime_type = "application/octet-stream";
}
} else {
document.mime_type = "application/octet-stream";
}
if (document.mime_type.equals("image/gif")) {
try {
Bitmap bitmap = FileLoader.loadBitmap(path, null, 90, 90);
if (bitmap != null) {
document.thumb = FileLoader.scaleAndSaveImage(bitmap, 90, 90, 80, currentEncryptedChat != null);
document.thumb.type = "s";
}
} catch (Exception e) {
FileLog.e("tmessages", e);
}
}
if (document.thumb == null) {
document.thumb = new TLRPC.TL_photoSizeEmpty();
document.thumb.type = "s";
}
MessagesController.getInstance().sendMessage(document, dialog_id);
processSendingDocument(path, null);
}
@Override
@ -3841,10 +3820,14 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
photoImage.setImage(message.messageOwner.action.newUserPhoto.photo_small, "50_50", Utilities.getUserAvatarForId(currentUser.id));
} else {
PhotoObject photo = PhotoObject.getClosestImageWithSize(message.photoThumbs, Utilities.dp(64), Utilities.dp(64));
if (photo.image != null) {
photoImage.setImageBitmap(photo.image);
if (photo != null) {
if (photo.image != null) {
photoImage.setImageBitmap(photo.image);
} else {
photoImage.setImage(photo.photoOwner.location, "50_50", Utilities.getGroupAvatarForId(currentChat.id));
}
} else {
photoImage.setImage(photo.photoOwner.location, "50_50", Utilities.getGroupAvatarForId(currentChat.id));
photoImage.setImageResource(Utilities.getGroupAvatarForId(currentChat.id));
}
}
photoImage.imageReceiver.setVisible(!PhotoViewer.getInstance().isShowingImage(message), false);

View File

@ -102,6 +102,7 @@ public class ContactAddActivity extends BaseFragment implements NotificationCent
onlineText = (TextView)fragmentView.findViewById(R.id.settings_online);
avatarImage = (BackupImageView)fragmentView.findViewById(R.id.settings_avatar_image);
avatarImage.processDetach = false;
phoneText = (TextView)fragmentView.findViewById(R.id.settings_name);
Typeface typeface = Utilities.getTypeface("fonts/rmedium.ttf");
phoneText.setTypeface(typeface);

View File

@ -85,7 +85,7 @@ public class CountrySelectActivity extends BaseFragment {
}
arr.add(c);
}
reader.close();//TODO
reader.close();
stream.close();
} catch (Exception e) {
FileLog.e("tmessages", e);

View File

@ -45,7 +45,7 @@ import java.util.HashMap;
public class DocumentSelectActivity extends BaseFragment {
public static abstract interface DocumentSelectActivityDelegate {
public void didSelectFile(DocumentSelectActivity activity, String path, String name, String ext, long size);
public void didSelectFile(DocumentSelectActivity activity, String path);
public void startDocumentSelectActivity();
}
@ -186,7 +186,7 @@ public class DocumentSelectActivity extends BaseFragment {
return;
}
if (delegate != null) {
delegate.didSelectFile(DocumentSelectActivity.this, file.getAbsolutePath(), item.title, item.ext, file.length());
delegate.didSelectFile(DocumentSelectActivity.this, file.getAbsolutePath());
}
}
}

View File

@ -498,14 +498,14 @@ public class LaunchActivity extends ActionBarActivity implements NotificationCen
fragment.processSendingText(sendingText);
}
if (documentPath != null) {
fragment.processSendingDocument(documentPath);
fragment.processSendingDocument(documentPath, null);
}
if (imagesPathArray != null) {
fragment.processSendingPhotos(null, imagesPathArray);
}
if (documentsPathArray != null) {
for (String path : documentsPathArray) {
fragment.processSendingDocument(path);
fragment.processSendingDocument(path, null);
}
}
if (contactsToSend != null && !contactsToSend.isEmpty()) {

View File

@ -148,21 +148,31 @@ public class UserProfileActivity extends BaseFragment implements NotificationCen
if (id == -1) {
finishFragment();
} else if (id == block_contact) {
TLRPC.User user = MessagesController.getInstance().users.get(user_id);
if (user == null) {
return;
}
TLRPC.TL_contacts_block req = new TLRPC.TL_contacts_block();
req.id = MessagesController.getInputUser(user);
TLRPC.TL_contactBlocked blocked = new TLRPC.TL_contactBlocked();
blocked.user_id = user_id;
blocked.date = (int)(System.currentTimeMillis() / 1000);
ConnectionsManager.getInstance().performRpc(req, new RPCRequest.RPCRequestDelegate() {
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
builder.setMessage(LocaleController.getString("AreYouSure", R.string.AreYouSure));
builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), new DialogInterface.OnClickListener() {
@Override
public void run(TLObject response, TLRPC.TL_error error) {
public void onClick(DialogInterface dialogInterface, int i) {
TLRPC.User user = MessagesController.getInstance().users.get(user_id);
if (user == null) {
return;
}
TLRPC.TL_contacts_block req = new TLRPC.TL_contacts_block();
req.id = MessagesController.getInputUser(user);
TLRPC.TL_contactBlocked blocked = new TLRPC.TL_contactBlocked();
blocked.user_id = user_id;
blocked.date = (int)(System.currentTimeMillis() / 1000);
ConnectionsManager.getInstance().performRpc(req, new RPCRequest.RPCRequestDelegate() {
@Override
public void run(TLObject response, TLRPC.TL_error error) {
}
}, null, true, RPCRequest.RPCRequestClassGeneric);
}
}, null, true, RPCRequest.RPCRequestClassGeneric);
});
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
showAlertDialog(builder);
} else if (id == add_contact) {
TLRPC.User user = MessagesController.getInstance().users.get(user_id);
Bundle args = new Bundle();

View File

@ -377,7 +377,7 @@ public class ActionBarLayer extends FrameLayout {
}
actionMode.setVisibility(GONE);
if (backButtonFrameLayout != null) {
backButtonFrameLayout.setVisibility(VISIBLE);
backButtonFrameLayout.setVisibility(isSearchFieldVisible || actionOverlay == null || actionOverlay.getVisibility() == GONE ? VISIBLE : INVISIBLE);
}
if (menu != null) {
menu.setVisibility(VISIBLE);
@ -471,10 +471,10 @@ public class ActionBarLayer extends FrameLayout {
return;
}
isBackOverlayVisible = visible;
positionBackOverlay(getMeasuredWidth(), getMeasuredHeight());
if (visible) {
((ActionBarActivity)getContext()).onOverlayShow(actionOverlay, parentFragment);
}
positionBackOverlay(getMeasuredWidth(), getMeasuredHeight());
}
private void positionBackOverlay(int widthMeasureSpec, int heightMeasureSpec) {

View File

@ -129,7 +129,7 @@ public class AvatarUpdater implements NotificationCenter.NotificationCenterDeleg
uploadingAvatar = Utilities.getCacheDir() + "/" + bigPhoto.location.volume_id + "_" + bigPhoto.location.local_id + ".jpg";
NotificationCenter.getInstance().addObserver(AvatarUpdater.this, FileLoader.FileDidUpload);
NotificationCenter.getInstance().addObserver(AvatarUpdater.this, FileLoader.FileDidFailUpload);
FileLoader.getInstance().uploadFile(uploadingAvatar, null, null);
FileLoader.getInstance().uploadFile(uploadingAvatar, null, false);
}
}
}

View File

@ -1,9 +1,10 @@
<FrameLayout
<org.telegram.ui.Views.FrameLayoutFixed
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="400dp"
android:layout_height="fill_parent"
android:background="@drawable/bar_selector"
android:id="@+id/back_button_background">
android:id="@+id/back_button_background"
android:layout_gravity="top">
<ProgressBar
android:layout_height="32dp"
@ -26,15 +27,15 @@
<TextView
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_width="wrap_content"
android:layout_marginLeft="52dp"
android:textColor="#ffffff"
android:textSize="17dp"
android:layout_gravity="center_vertical|left"
android:gravity="left"
android:gravity="top|left"
android:ellipsize="end"
android:singleLine="true"
android:paddingRight="2dp"
android:id="@+id/status_text"/>
</FrameLayout>
</org.telegram.ui.Views.FrameLayoutFixed>