Remove unneeded FileDidUpload and FileDidFailUpload notifications.

This commit is contained in:
B. Petersen
2017-03-09 19:08:48 +01:00
parent 29ec49b806
commit 758dfbaa67
4 changed files with 3 additions and 200 deletions
@@ -30,9 +30,7 @@ import com.b44t.ui.SettingsAdvActivity;
import java.util.ArrayList;
public class MessagesController implements NotificationCenter.NotificationCenterDelegate {
private String uploadingAvatar = null;
public class MessagesController {
public int fontSize;
@@ -63,78 +61,11 @@ public class MessagesController implements NotificationCenter.NotificationCenter
public MessagesController() {
ImageLoader.getInstance();
NotificationCenter.getInstance().addObserver(this, NotificationCenter.FileDidUpload);
NotificationCenter.getInstance().addObserver(this, NotificationCenter.FileDidFailUpload);
NotificationCenter.getInstance().addObserver(this, NotificationCenter.FileDidLoaded);
NotificationCenter.getInstance().addObserver(this, NotificationCenter.FileDidFailedLoad);
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
fontSize = preferences.getInt("msg_font_size", SettingsAdvActivity.defMsgFontSize());
}
@Override
public void didReceivedNotification(int id, Object... args) {
if (id == NotificationCenter.FileDidUpload) {
final String location = (String) args[0];
final TLRPC.InputFile file = (TLRPC.InputFile) args[1];
if (uploadingAvatar != null && uploadingAvatar.equals(location)) {
/*TLRPC.TL_photos_uploadProfilePhoto req = new TLRPC.TL_photos_uploadProfilePhoto();
req.caption = "";
req.crop = new TLRPC.TL_inputPhotoCropAuto();
req.file = file;
req.geo_point = new TLRPC.TL_inputGeoPointEmpty();*/
/*ConnectionsManager.getInstance().sendRequest(req, new RequestDelegate() {
@Override
public void run(TLObject response, TLRPC.TL_error error) {
if (error == null) {
TLRPC.User user = getUser(UserConfig.getClientUserId());
if (user == null) {
user = UserConfig.getCurrentUser();
putUser(user, true);
} else {
UserConfig.setCurrentUser(user);
}
if (user == null) {
return;
}
TLRPC.TL_photos_photo photo = (TLRPC.TL_photos_photo) response;
ArrayList<TLRPC.PhotoSize> sizes = photo.photo.sizes;
TLRPC.PhotoSize smallSize = FileLoader.getClosestPhotoSizeWithSize(sizes, 100);
TLRPC.PhotoSize bigSize = FileLoader.getClosestPhotoSizeWithSize(sizes, 1000);
user.photo = new TLRPC.TL_userProfilePhoto();
user.photo.photo_id = photo.photo.id;
if (smallSize != null) {
user.photo.photo_small = smallSize.location;
}
if (bigSize != null) {
user.photo.photo_big = bigSize.location;
} else if (smallSize != null) {
user.photo.photo_small = smallSize.location;
}
//MessagesStorage.getInstance().clearUserPhotos(user.id);
ArrayList<TLRPC.User> users = new ArrayList<>();
users.add(user);
//MessagesStorage.getInstance().putUsersAndChats(users, null, false, true);
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public void run() {
NotificationCenter.getInstance().postNotificationName(NotificationCenter.updateInterfaces, UPDATE_MASK_AVATAR);
UserConfig.saveConfig(true);
}
});
}
}
});*/
}
} else if (id == NotificationCenter.FileDidFailUpload) {
final String location = (String) args[0];
if (uploadingAvatar != null && uploadingAvatar.equals(location)) {
uploadingAvatar = null;
}
}
}
public TLRPC.User getUser(Integer id) {
// EDIT BY MR - additional information should be loaded as needed by the caller
TLRPC.User u = new TLRPC.User();
@@ -68,9 +68,6 @@ public class NotificationCenter {
public static final int didUpdatedConnectionState = totalEvents++;
public static final int emojiDidLoaded = totalEvents++;
public static final int FileDidUpload = totalEvents++;
public static final int FileDidFailUpload = totalEvents++;
//public static final int FileUploadProgressChanged = totalEvents++;
public static final int FileLoadProgressChanged = totalEvents++;
public static final int FileDidLoaded = totalEvents++;
public static final int FileDidFailedLoad = totalEvents++;
@@ -60,8 +60,6 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter
}
public SendMessagesHelper() {
NotificationCenter.getInstance().addObserver(this, NotificationCenter.FileDidUpload);
NotificationCenter.getInstance().addObserver(this, NotificationCenter.FileDidFailUpload);
NotificationCenter.getInstance().addObserver(this, NotificationCenter.FilePreparingStarted);
NotificationCenter.getInstance().addObserver(this, NotificationCenter.FileNewChunkAvailable);
NotificationCenter.getInstance().addObserver(this, NotificationCenter.FilePreparingFailed);
@@ -87,97 +85,7 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter
@Override
public void didReceivedNotification(int id, final Object... args) {
if (id == NotificationCenter.FileDidUpload) {
/*
final String location = (String) args[0];
final TLRPC.InputFile file = (TLRPC.InputFile) args[1];
final TLRPC.InputEncryptedFile encryptedFile = (TLRPC.InputEncryptedFile) args[2];
ArrayList<DelayedMessage> arr = delayedMessages.get(location);
if (arr != null) {
for (int a = 0; a < arr.size(); a++) {
DelayedMessage message = arr.get(a);
TLRPC.InputMedia media = null;
if (message.sendRequest instanceof TLRPC.TL_messages_sendMedia) {
media = ((TLRPC.TL_messages_sendMedia) message.sendRequest).media;
} else if (message.sendRequest instanceof TLRPC.TL_messages_sendBroadcast) {
media = ((TLRPC.TL_messages_sendBroadcast) message.sendRequest).media;
}
if (file != null && media != null) {
if (message.type == 0) {
media.file = file;
performSendMessageRequest(message.sendRequest, message.obj, message.originalPath);
} else if (message.type == 1) {
if (media.file == null) {
media.file = file;
if (media.thumb == null && message.location != null) {
performSendDelayedMessage(message);
} else {
performSendMessageRequest(message.sendRequest, message.obj, message.originalPath);
}
} else {
media.thumb = file;
performSendMessageRequest(message.sendRequest, message.obj, message.originalPath);
}
} else if (message.type == 2) {
if (media.file == null) {
media.file = file;
if (media.thumb == null && message.location != null) {
performSendDelayedMessage(message);
} else {
performSendMessageRequest(message.sendRequest, message.obj, message.originalPath);
}
} else {
media.thumb = file;
performSendMessageRequest(message.sendRequest, message.obj, message.originalPath);
}
} else if (message.type == 3) {
media.file = file;
performSendMessageRequest(message.sendRequest, message.obj, message.originalPath);
}
arr.remove(a);
a--;
} else if (encryptedFile != null && message.sendEncryptedRequest != null) {
if (message.sendEncryptedRequest.media instanceof TLRPC.TL_decryptedMessageMediaVideo || message.sendEncryptedRequest.media instanceof TLRPC.TL_decryptedMessageMediaPhoto) {
long size = (Long) args[5];
message.sendEncryptedRequest.media.size = (int) size;
}
message.sendEncryptedRequest.media.key = (byte[]) args[3];
message.sendEncryptedRequest.media.iv = (byte[]) args[4];
//SecretChatHelper.getInstance().performSendEncryptedRequest(message.sendEncryptedRequest, message.obj.messageOwner, message.encryptedChat, encryptedFile, message.originalPath, message.obj);
arr.remove(a);
a--;
}
}
if (arr.isEmpty()) {
delayedMessages.remove(location);
}
}
*/
} else if (id == NotificationCenter.FileDidFailUpload) {
/*
final String location = (String) args[0];
final boolean enc = (Boolean) args[1];
ArrayList<DelayedMessage> arr = delayedMessages.get(location);
if (arr != null) {
for (int a = 0; a < arr.size(); a++) {
DelayedMessage obj = arr.get(a);
if (enc && obj.sendEncryptedRequest != null || !enc && obj.sendRequest != null) {
//MessagesStorage.getInstance().markMessageAsSendError(obj.obj.messageOwner);
obj.obj.messageOwner.send_state = MessageObject.MESSAGE_SEND_STATE_SEND_ERROR;
arr.remove(a);
a--;
NotificationCenter.getInstance().postNotificationName(NotificationCenter.messageSendError, obj.obj.getId());
processSentMessage(obj.obj.getId());
}
}
if (arr.isEmpty()) {
delayedMessages.remove(location);
}
}
*/
}
else if (id == NotificationCenter.FilePreparingStarted)
if (id == NotificationCenter.FilePreparingStarted)
{
// encoding started
}
@@ -40,7 +40,6 @@ import com.b44t.messenger.MediaController;
import com.b44t.messenger.TLRPC;
import com.b44t.messenger.FileLoader;
import com.b44t.messenger.FileLog;
import com.b44t.messenger.NotificationCenter;
import com.b44t.messenger.UserConfig;
import com.b44t.ui.LaunchActivity;
import com.b44t.ui.PhotoAlbumPickerActivity;
@@ -51,7 +50,7 @@ import com.b44t.ui.PhotoViewer;
import java.io.File;
import java.util.ArrayList;
public class AvatarUpdater implements NotificationCenter.NotificationCenterDelegate, PhotoCropActivity.PhotoEditActivityDelegate {
public class AvatarUpdater implements PhotoCropActivity.PhotoEditActivityDelegate {
public String currentPicturePath;
private TLRPC.PhotoSize smallPhoto;
@@ -214,8 +213,6 @@ public class AvatarUpdater implements NotificationCenter.NotificationCenterDeleg
} else {
UserConfig.saveConfig(false);
uploadingAvatar = FileLoader.getInstance().getDirectory(FileLoader.MEDIA_DIR_CACHE) + "/" + bigPhoto.location.volume_id + "_" + bigPhoto.location.local_id + ".jpg";
NotificationCenter.getInstance().addObserver(AvatarUpdater.this, NotificationCenter.FileDidUpload);
NotificationCenter.getInstance().addObserver(AvatarUpdater.this, NotificationCenter.FileDidFailUpload);
//FileLoader.getInstance().uploadFile(uploadingAvatar, false, true);
}
}
@@ -225,34 +222,4 @@ public class AvatarUpdater implements NotificationCenter.NotificationCenterDeleg
public void didFinishEdit(Bitmap bitmap) {
processBitmap(bitmap);
}
@Override
public void didReceivedNotification(int id, final Object... args) {
if (id == NotificationCenter.FileDidUpload) {
String location = (String)args[0];
if (uploadingAvatar != null && location.equals(uploadingAvatar)) {
NotificationCenter.getInstance().removeObserver(AvatarUpdater.this, NotificationCenter.FileDidUpload);
NotificationCenter.getInstance().removeObserver(AvatarUpdater.this, NotificationCenter.FileDidFailUpload);
if (delegate != null) {
delegate.didUploadedPhoto((TLRPC.InputFile)args[1], smallPhoto, bigPhoto);
}
uploadingAvatar = null;
if (clearAfterUpdate) {
parentFragment = null;
delegate = null;
}
}
} else if (id == NotificationCenter.FileDidFailUpload) {
String location = (String)args[0];
if (uploadingAvatar != null && location.equals(uploadingAvatar)) {
NotificationCenter.getInstance().removeObserver(AvatarUpdater.this, NotificationCenter.FileDidUpload);
NotificationCenter.getInstance().removeObserver(AvatarUpdater.this, NotificationCenter.FileDidFailUpload);
uploadingAvatar = null;
if (clearAfterUpdate) {
parentFragment = null;
delegate = null;
}
}
}
}
}