use of org.telegram.tgnet.NativeByteBuffer in project Telegram-FOSS by Telegram-FOSS-Team.
the class MessagesController method loadUnknownChannel.
protected void loadUnknownChannel(final TLRPC.Chat channel, long taskId) {
if (!(channel instanceof TLRPC.TL_channel) || gettingUnknownChannels.indexOfKey(channel.id) >= 0) {
return;
}
if (channel.access_hash == 0) {
if (taskId != 0) {
getMessagesStorage().removePendingTask(taskId);
}
return;
}
TLRPC.TL_inputPeerChannel inputPeer = new TLRPC.TL_inputPeerChannel();
inputPeer.channel_id = channel.id;
inputPeer.access_hash = channel.access_hash;
gettingUnknownChannels.put(channel.id, true);
TLRPC.TL_messages_getPeerDialogs req = new TLRPC.TL_messages_getPeerDialogs();
TLRPC.TL_inputDialogPeer inputDialogPeer = new TLRPC.TL_inputDialogPeer();
inputDialogPeer.peer = inputPeer;
req.peers.add(inputDialogPeer);
long newTaskId;
if (taskId == 0) {
NativeByteBuffer data = null;
try {
data = new NativeByteBuffer(4 + channel.getObjectSize());
data.writeInt32(0);
channel.serializeToStream(data);
} catch (Exception e) {
FileLog.e(e);
}
newTaskId = getMessagesStorage().createPendingTask(data);
} else {
newTaskId = taskId;
}
getConnectionsManager().sendRequest(req, (response, error) -> {
if (response != null) {
TLRPC.TL_messages_peerDialogs res = (TLRPC.TL_messages_peerDialogs) response;
if (!res.dialogs.isEmpty() && !res.chats.isEmpty()) {
TLRPC.TL_dialog dialog = (TLRPC.TL_dialog) res.dialogs.get(0);
TLRPC.TL_messages_dialogs dialogs = new TLRPC.TL_messages_dialogs();
dialogs.dialogs.addAll(res.dialogs);
dialogs.messages.addAll(res.messages);
dialogs.users.addAll(res.users);
dialogs.chats.addAll(res.chats);
processLoadedDialogs(dialogs, null, dialog.folder_id, 0, 1, DIALOGS_LOAD_TYPE_CHANNEL, false, false, false);
}
}
if (newTaskId != 0) {
getMessagesStorage().removePendingTask(newTaskId);
}
gettingUnknownChannels.delete(channel.id);
});
}
use of org.telegram.tgnet.NativeByteBuffer in project Telegram-FOSS by Telegram-FOSS-Team.
the class MessagesController method markMessageAsRead2.
public void markMessageAsRead2(long dialogId, int mid, TLRPC.InputChannel inputChannel, int ttl, long taskId) {
if (mid == 0 || ttl <= 0) {
return;
}
if (DialogObject.isChatDialog(dialogId) && inputChannel == null) {
inputChannel = getInputChannel(dialogId);
if (inputChannel == null) {
return;
}
}
long newTaskId;
if (taskId == 0) {
NativeByteBuffer data = null;
try {
data = new NativeByteBuffer(20 + (inputChannel != null ? inputChannel.getObjectSize() : 0));
data.writeInt32(23);
data.writeInt64(dialogId);
data.writeInt32(mid);
data.writeInt32(ttl);
if (inputChannel != null) {
inputChannel.serializeToStream(data);
}
} catch (Exception e) {
FileLog.e(e);
}
newTaskId = getMessagesStorage().createPendingTask(data);
} else {
newTaskId = taskId;
}
int time = getConnectionsManager().getCurrentTime();
getMessagesStorage().createTaskForMid(dialogId, mid, time, time, ttl, false);
if (inputChannel != null) {
TLRPC.TL_channels_readMessageContents req = new TLRPC.TL_channels_readMessageContents();
req.channel = inputChannel;
req.id.add(mid);
getConnectionsManager().sendRequest(req, (response, error) -> {
if (newTaskId != 0) {
getMessagesStorage().removePendingTask(newTaskId);
}
});
} else {
TLRPC.TL_messages_readMessageContents req = new TLRPC.TL_messages_readMessageContents();
req.id.add(mid);
getConnectionsManager().sendRequest(req, (response, error) -> {
if (error == null) {
TLRPC.TL_messages_affectedMessages res = (TLRPC.TL_messages_affectedMessages) response;
processNewDifferenceParams(-1, res.pts, -1, res.pts_count);
}
if (newTaskId != 0) {
getMessagesStorage().removePendingTask(newTaskId);
}
});
}
}
use of org.telegram.tgnet.NativeByteBuffer in project Telegram-FOSS by Telegram-FOSS-Team.
the class MessagesController method addDialogToFolder.
public int addDialogToFolder(ArrayList<Long> dialogIds, int folderId, int pinnedNum, ArrayList<TLRPC.TL_inputFolderPeer> peers, long taskId) {
TLRPC.TL_folders_editPeerFolders req = new TLRPC.TL_folders_editPeerFolders();
boolean[] folderCreated = null;
long newTaskId;
if (taskId == 0) {
boolean added = false;
long selfUserId = getUserConfig().getClientUserId();
int size = 0;
for (int a = 0, N = dialogIds.size(); a < N; a++) {
long dialogId = dialogIds.get(a);
if (!DialogObject.isChatDialog(dialogId) && !DialogObject.isUserDialog(dialogId) && !DialogObject.isEncryptedDialog(dialogId)) {
continue;
}
if (folderId == 1 && (dialogId == selfUserId || dialogId == 777000 || isPromoDialog(dialogId, false))) {
continue;
}
TLRPC.Dialog dialog = dialogs_dict.get(dialogId);
if (dialog == null) {
continue;
}
added = true;
dialog.folder_id = folderId;
if (pinnedNum > 0) {
dialog.pinned = true;
dialog.pinnedNum = pinnedNum;
} else {
dialog.pinned = false;
dialog.pinnedNum = 0;
}
if (folderCreated == null) {
folderCreated = new boolean[1];
ensureFolderDialogExists(folderId, folderCreated);
}
if (DialogObject.isEncryptedDialog(dialogId)) {
getMessagesStorage().setDialogsFolderId(null, null, dialogId, folderId);
} else {
TLRPC.TL_inputFolderPeer folderPeer = new TLRPC.TL_inputFolderPeer();
folderPeer.folder_id = folderId;
folderPeer.peer = getInputPeer(dialogId);
req.folder_peers.add(folderPeer);
size += folderPeer.getObjectSize();
}
}
if (!added) {
return 0;
}
sortDialogs(null);
getNotificationCenter().postNotificationName(NotificationCenter.dialogsNeedReload);
if (size != 0) {
NativeByteBuffer data = null;
try {
data = new NativeByteBuffer(4 + 4 + 4 + size);
data.writeInt32(17);
data.writeInt32(folderId);
data.writeInt32(req.folder_peers.size());
for (int a = 0, N = req.folder_peers.size(); a < N; a++) {
req.folder_peers.get(a).serializeToStream(data);
}
} catch (Exception e) {
FileLog.e(e);
}
newTaskId = getMessagesStorage().createPendingTask(data);
} else {
newTaskId = 0;
}
} else {
req.folder_peers = peers;
newTaskId = taskId;
}
if (!req.folder_peers.isEmpty()) {
getConnectionsManager().sendRequest(req, (response, error) -> {
if (error == null) {
processUpdates((TLRPC.Updates) response, false);
}
if (newTaskId != 0) {
getMessagesStorage().removePendingTask(newTaskId);
}
});
getMessagesStorage().setDialogsFolderId(null, req.folder_peers, 0, folderId);
}
return folderCreated == null ? 0 : (folderCreated[0] ? 2 : 1);
}
use of org.telegram.tgnet.NativeByteBuffer in project Telegram-FOSS by Telegram-FOSS-Team.
the class MessagesController method saveWallpaperToServer.
public void saveWallpaperToServer(File path, Theme.OverrideWallpaperInfo info, boolean install, long taskId) {
if (uploadingWallpaper != null) {
File finalPath = new File(ApplicationLoader.getFilesDirFixed(), info.originalFileName);
if (path != null && (path.getAbsolutePath().equals(uploadingWallpaper) || path.equals(finalPath))) {
uploadingWallpaperInfo = info;
return;
}
getFileLoader().cancelFileUpload(uploadingWallpaper, false);
uploadingWallpaper = null;
uploadingWallpaperInfo = null;
}
if (path != null) {
uploadingWallpaper = path.getAbsolutePath();
uploadingWallpaperInfo = info;
getFileLoader().uploadFile(uploadingWallpaper, false, true, ConnectionsManager.FileTypePhoto);
} else if (!info.isDefault() && !info.isColor() && info.wallpaperId > 0 && !info.isTheme()) {
TLRPC.InputWallPaper inputWallPaper;
if (info.wallpaperId > 0) {
TLRPC.TL_inputWallPaper inputWallPaperId = new TLRPC.TL_inputWallPaper();
inputWallPaperId.id = info.wallpaperId;
inputWallPaperId.access_hash = info.accessHash;
inputWallPaper = inputWallPaperId;
} else {
TLRPC.TL_inputWallPaperSlug inputWallPaperSlug = new TLRPC.TL_inputWallPaperSlug();
inputWallPaperSlug.slug = info.slug;
inputWallPaper = inputWallPaperSlug;
}
TLRPC.TL_wallPaperSettings settings = new TLRPC.TL_wallPaperSettings();
settings.blur = info.isBlurred;
settings.motion = info.isMotion;
if (info.color != 0) {
settings.background_color = info.color & 0x00ffffff;
settings.flags |= 1;
settings.intensity = (int) (info.intensity * 100);
settings.flags |= 8;
}
if (info.gradientColor1 != 0) {
settings.second_background_color = info.gradientColor1 & 0x00ffffff;
settings.rotation = AndroidUtilities.getWallpaperRotation(info.rotation, true);
settings.flags |= 16;
}
if (info.gradientColor2 != 0) {
settings.third_background_color = info.gradientColor2 & 0x00ffffff;
settings.flags |= 32;
}
if (info.gradientColor3 != 0) {
settings.fourth_background_color = info.gradientColor3 & 0x00ffffff;
settings.flags |= 64;
}
TLObject req;
if (install) {
TLRPC.TL_account_installWallPaper request = new TLRPC.TL_account_installWallPaper();
request.wallpaper = inputWallPaper;
request.settings = settings;
req = request;
} else {
TLRPC.TL_account_saveWallPaper request = new TLRPC.TL_account_saveWallPaper();
request.wallpaper = inputWallPaper;
request.settings = settings;
req = request;
}
long newTaskId;
if (taskId != 0) {
newTaskId = taskId;
} else {
NativeByteBuffer data = null;
try {
data = new NativeByteBuffer(1024);
data.writeInt32(21);
data.writeBool(info.isBlurred);
data.writeBool(info.isMotion);
data.writeInt32(info.color);
data.writeInt32(info.gradientColor1);
data.writeInt32(info.rotation);
data.writeDouble(info.intensity);
data.writeBool(install);
data.writeString(info.slug);
data.writeString(info.originalFileName);
data.limit(data.position());
} catch (Exception e) {
FileLog.e(e);
}
newTaskId = getMessagesStorage().createPendingTask(data);
}
getConnectionsManager().sendRequest(req, (response, error) -> getMessagesStorage().removePendingTask(newTaskId));
}
if ((info.isColor() || info.gradientColor2 != 0) && info.wallpaperId <= 0) {
TLRPC.WallPaper wallPaper;
if (info.isColor()) {
wallPaper = new TLRPC.TL_wallPaperNoFile();
} else {
wallPaper = new TLRPC.TL_wallPaper();
wallPaper.slug = info.slug;
wallPaper.document = new TLRPC.TL_documentEmpty();
}
if (info.wallpaperId == 0) {
wallPaper.id = Utilities.random.nextLong();
if (wallPaper.id > 0) {
wallPaper.id = -wallPaper.id;
}
} else {
wallPaper.id = info.wallpaperId;
}
wallPaper.dark = MotionBackgroundDrawable.isDark(info.color, info.gradientColor1, info.gradientColor2, info.gradientColor3);
wallPaper.flags |= 4;
wallPaper.settings = new TLRPC.TL_wallPaperSettings();
wallPaper.settings.blur = info.isBlurred;
wallPaper.settings.motion = info.isMotion;
if (info.color != 0) {
wallPaper.settings.background_color = info.color;
wallPaper.settings.flags |= 1;
wallPaper.settings.intensity = (int) (info.intensity * 100);
wallPaper.settings.flags |= 8;
}
if (info.gradientColor1 != 0) {
wallPaper.settings.second_background_color = info.gradientColor1;
wallPaper.settings.rotation = AndroidUtilities.getWallpaperRotation(info.rotation, true);
wallPaper.settings.flags |= 16;
}
if (info.gradientColor2 != 0) {
wallPaper.settings.third_background_color = info.gradientColor2;
wallPaper.settings.flags |= 32;
}
if (info.gradientColor3 != 0) {
wallPaper.settings.fourth_background_color = info.gradientColor3;
wallPaper.settings.flags |= 64;
}
ArrayList<TLRPC.WallPaper> arrayList = new ArrayList<>();
arrayList.add(wallPaper);
getMessagesStorage().putWallpapers(arrayList, -3);
getMessagesStorage().getWallpapers();
}
}
use of org.telegram.tgnet.NativeByteBuffer in project Telegram-FOSS by Telegram-FOSS-Team.
the class MessagesController method pinDialog.
public boolean pinDialog(long dialogId, boolean pin, TLRPC.InputPeer peer, long taskId) {
TLRPC.Dialog dialog = dialogs_dict.get(dialogId);
if (dialog == null || dialog.pinned == pin) {
return dialog != null;
}
int folderId = dialog.folder_id;
ArrayList<TLRPC.Dialog> dialogs = getDialogs(folderId);
dialog.pinned = pin;
if (pin) {
int maxPinnedNum = 0;
for (int a = 0; a < dialogs.size(); a++) {
TLRPC.Dialog d = dialogs.get(a);
if (d instanceof TLRPC.TL_dialogFolder) {
continue;
}
if (!d.pinned) {
if (d.id != promoDialogId) {
break;
}
continue;
}
maxPinnedNum = Math.max(d.pinnedNum, maxPinnedNum);
}
dialog.pinnedNum = maxPinnedNum + 1;
} else {
dialog.pinnedNum = 0;
}
sortDialogs(null);
if (!pin && !dialogs.isEmpty() && dialogs.get(dialogs.size() - 1) == dialog && !dialogsEndReached.get(folderId)) {
dialogs.remove(dialogs.size() - 1);
}
getNotificationCenter().postNotificationName(NotificationCenter.dialogsNeedReload);
if (!DialogObject.isEncryptedDialog(dialogId)) {
if (taskId != -1) {
TLRPC.TL_messages_toggleDialogPin req = new TLRPC.TL_messages_toggleDialogPin();
req.pinned = pin;
if (peer == null) {
peer = getInputPeer(dialogId);
}
if (peer instanceof TLRPC.TL_inputPeerEmpty) {
return false;
}
TLRPC.TL_inputDialogPeer inputDialogPeer = new TLRPC.TL_inputDialogPeer();
inputDialogPeer.peer = peer;
req.peer = inputDialogPeer;
long newTaskId;
if (taskId == 0) {
NativeByteBuffer data = null;
try {
data = new NativeByteBuffer(16 + peer.getObjectSize());
data.writeInt32(4);
data.writeInt64(dialogId);
data.writeBool(pin);
peer.serializeToStream(data);
} catch (Exception e) {
FileLog.e(e);
}
newTaskId = getMessagesStorage().createPendingTask(data);
} else {
newTaskId = taskId;
}
getConnectionsManager().sendRequest(req, (response, error) -> {
if (newTaskId != 0) {
getMessagesStorage().removePendingTask(newTaskId);
}
});
}
}
getMessagesStorage().setDialogPinned(dialogId, dialog.pinnedNum);
return true;
}
Aggregations