mirror of
https://github.com/ArcaneChat/android.git
synced 2026-07-03 14:05:24 +02:00
Make 'GroupCreateFinalActivity' work.
This commit is contained in:
@@ -783,112 +783,6 @@ public class MessagesController implements NotificationCenter.NotificationCenter
|
||||
public void markDialogAsRead(final long dialog_id, final int max_id, final int max_positive_id, final int max_date, final boolean was, final boolean popup) {
|
||||
}
|
||||
|
||||
public int createChat(String title, ArrayList<Integer> selectedContacts, final String about, int type, final BaseFragment fragment) {
|
||||
/*
|
||||
if (type == ChatObject.CHAT_TYPE_BROADCAST) {
|
||||
TLRPC.TL_chat chat = new TLRPC.TL_chat();
|
||||
chat.id = UserConfig.lastBroadcastId;
|
||||
chat.title = title;
|
||||
chat.photo = new TLRPC.TL_chatPhotoEmpty();
|
||||
chat.participants_count = selectedContacts.size();
|
||||
chat.date = (int) (System.currentTimeMillis() / 1000);
|
||||
chat.version = 1;
|
||||
UserConfig.lastBroadcastId--;
|
||||
putChat(chat, false);
|
||||
ArrayList<TLRPC.Chat> chatsArrays = new ArrayList<>();
|
||||
chatsArrays.add(chat);
|
||||
MessagesStorage.getInstance().putUsersAndChats(null, chatsArrays, true, true);
|
||||
|
||||
TLRPC.TL_chatFull chatFull = new TLRPC.TL_chatFull();
|
||||
chatFull.id = chat.id;
|
||||
chatFull.chat_photo = new TLRPC.TL_photoEmpty();
|
||||
chatFull.notify_settings = new TLRPC.TL_peerNotifySettingsEmpty();
|
||||
chatFull.exported_invite = new TLRPC.TL_chatInviteEmpty();
|
||||
chatFull.participants = new TLRPC.TL_chatParticipants();
|
||||
chatFull.participants.chat_id = chat.id;
|
||||
chatFull.participants.admin_id = UserConfig.getClientUserId();
|
||||
chatFull.participants.version = 1;
|
||||
for (int a = 0; a < selectedContacts.size(); a++) {
|
||||
TLRPC.TL_chatParticipant participant = new TLRPC.TL_chatParticipant();
|
||||
participant.user_id = selectedContacts.get(a);
|
||||
participant.inviter_id = UserConfig.getClientUserId();
|
||||
participant.date = (int) (System.currentTimeMillis() / 1000);
|
||||
chatFull.participants.participants.add(participant);
|
||||
}
|
||||
//MessagesStorage.getInstance().updateChatInfo(chatFull, false);
|
||||
|
||||
TLRPC.TL_messageService newMsg = new TLRPC.TL_messageService();
|
||||
newMsg.action = new TLRPC.TL_messageActionCreatedBroadcastList();
|
||||
newMsg.local_id = newMsg.id = UserConfig.getNewMessageId();
|
||||
newMsg.from_id = UserConfig.getClientUserId();
|
||||
newMsg.dialog_id = AndroidUtilities.makeBroadcastId(chat.id);
|
||||
newMsg.to_id = new TLRPC.TL_peerChat();
|
||||
newMsg.to_id.chat_id = chat.id;
|
||||
newMsg.date = ConnectionsManager.getInstance().getCurrentTime();
|
||||
newMsg.random_id = 0;
|
||||
newMsg.flags |= TLRPC.MESSAGE_FLAG_HAS_FROM_ID;
|
||||
UserConfig.saveConfig(false);
|
||||
MessageObject newMsgObj = new MessageObject(newMsg, users, true);
|
||||
newMsgObj.messageOwner.send_state = MessageObject.MESSAGE_SEND_STATE_SENT;
|
||||
|
||||
ArrayList<MessageObject> objArr = new ArrayList<>();
|
||||
objArr.add(newMsgObj);
|
||||
ArrayList<TLRPC.Message> arr = new ArrayList<>();
|
||||
arr.add(newMsg);
|
||||
//MessagesStorage.getInstance().putMessages(arr, false, true, false, 0);
|
||||
updateInterfaceWithMessages(newMsg.dialog_id, objArr);
|
||||
NotificationCenter.getInstance().postNotificationName(NotificationCenter.dialogsNeedReload);
|
||||
NotificationCenter.getInstance().postNotificationName(NotificationCenter.chatDidCreated, chat.id);
|
||||
|
||||
return 0;
|
||||
} else if (type == ChatObject.CHAT_TYPE_CHAT) {
|
||||
TLRPC.TL_messages_createChat req = new TLRPC.TL_messages_createChat();
|
||||
req.title = title;
|
||||
for (int a = 0; a < selectedContacts.size(); a++) {
|
||||
TLRPC.User user = getUser(selectedContacts.get(a));
|
||||
if (user == null) {
|
||||
continue;
|
||||
}
|
||||
req.users.add(getInputUser(user));
|
||||
}
|
||||
return ConnectionsManager.getInstance().sendRequest(req, new RequestDelegate() {
|
||||
@Override
|
||||
public void run(TLObject response, final TLRPC.TL_error error) {
|
||||
if (error != null) {
|
||||
AndroidUtilities.runOnUIThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (error.text.startsWith("FLOOD_WAIT")) {
|
||||
AlertsCreator.showFloodWaitAlert(error.text, fragment);
|
||||
} else {
|
||||
AlertsCreator.showAddUserAlert(error.text, fragment, false);
|
||||
}
|
||||
NotificationCenter.getInstance().postNotificationName(NotificationCenter.chatDidFailCreate);
|
||||
}
|
||||
});
|
||||
return;
|
||||
}
|
||||
final TLRPC.Updates updates = (TLRPC.Updates) response;
|
||||
processUpdates(updates, false);
|
||||
AndroidUtilities.runOnUIThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
putUsers(updates.users, false);
|
||||
putChats(updates.chats, false);
|
||||
if (updates.chats != null && !updates.chats.isEmpty()) {
|
||||
NotificationCenter.getInstance().postNotificationName(NotificationCenter.chatDidCreated, updates.chats.get(0).id);
|
||||
} else {
|
||||
NotificationCenter.getInstance().postNotificationName(NotificationCenter.chatDidFailCreate);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}, ConnectionsManager.RequestFlagFailOnServerErrors);
|
||||
}
|
||||
*/
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void addUserToChat(final int chat_id, final TLRPC.User user, final TLRPC.ChatFull info, int count_fwd, String botHash, final BaseFragment fragment) {
|
||||
}
|
||||
|
||||
|
||||
@@ -111,6 +111,7 @@ public class ContactsActivity extends BaseFragment implements NotificationCenter
|
||||
super.onFragmentCreate();
|
||||
NotificationCenter.getInstance().addObserver(this, NotificationCenter.contactsDidLoaded);
|
||||
NotificationCenter.getInstance().addObserver(this, NotificationCenter.updateInterfaces);
|
||||
NotificationCenter.getInstance().addObserver(this, NotificationCenter.chatDidCreated);
|
||||
NotificationCenter.getInstance().addObserver(this, NotificationCenter.closeChats);
|
||||
|
||||
if( do_what == SELECT_CONTACT_FOR_NEW_CHAT )
|
||||
@@ -140,6 +141,7 @@ public class ContactsActivity extends BaseFragment implements NotificationCenter
|
||||
super.onFragmentDestroy();
|
||||
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.contactsDidLoaded);
|
||||
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.updateInterfaces);
|
||||
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.chatDidCreated);
|
||||
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.closeChats);
|
||||
delegate = null;
|
||||
}
|
||||
@@ -518,6 +520,8 @@ public class ContactsActivity extends BaseFragment implements NotificationCenter
|
||||
}
|
||||
} else if (id == NotificationCenter.closeChats) {
|
||||
removeSelfFromStack();
|
||||
} else if (id == NotificationCenter.chatDidCreated) {
|
||||
removeSelfFromStack();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
package org.telegram.ui;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.app.ProgressDialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
@@ -32,9 +31,8 @@ import android.widget.Toast;
|
||||
import org.telegram.messenger.AndroidUtilities;
|
||||
import org.telegram.messenger.ChatObject;
|
||||
import org.telegram.messenger.LocaleController;
|
||||
import org.telegram.tgnet.ConnectionsManager;
|
||||
import org.telegram.messenger.MrMailbox;
|
||||
import org.telegram.tgnet.TLRPC;
|
||||
import org.telegram.messenger.FileLog;
|
||||
import org.telegram.messenger.MessagesController;
|
||||
import org.telegram.messenger.NotificationCenter;
|
||||
import org.telegram.messenger.R;
|
||||
@@ -61,10 +59,7 @@ public class GroupCreateFinalActivity extends BaseFragment implements Notificati
|
||||
private ArrayList<Integer> selectedContacts;
|
||||
private BackupImageView avatarImage;
|
||||
private AvatarDrawable avatarDrawable;
|
||||
private boolean createAfterUpload;
|
||||
private boolean donePressed;
|
||||
private AvatarUpdater avatarUpdater = new AvatarUpdater();
|
||||
private ProgressDialog progressDialog = null;
|
||||
private String nameToSet = null;
|
||||
private int chatType = ChatObject.CHAT_TYPE_CHAT;
|
||||
|
||||
@@ -93,22 +88,7 @@ public class GroupCreateFinalActivity extends BaseFragment implements Notificati
|
||||
}
|
||||
}
|
||||
if (!usersToLoad.isEmpty()) {
|
||||
//final Semaphore semaphore = new Semaphore(0);
|
||||
final ArrayList<TLRPC.User> users = new ArrayList<>();
|
||||
/*
|
||||
MessagesStorage.getInstance().getStorageQueue().postRunnable(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
users.addAll(MessagesStorage.getInstance().getUsers(usersToLoad));
|
||||
semaphore.release();
|
||||
}
|
||||
});
|
||||
*/
|
||||
/*try {
|
||||
semaphore.acquire();
|
||||
} catch (Exception e) {
|
||||
FileLog.e("messenger", e);
|
||||
}*/
|
||||
if (usersToLoad.size() != users.size()) {
|
||||
return false;
|
||||
}
|
||||
@@ -144,32 +124,20 @@ public class GroupCreateFinalActivity extends BaseFragment implements Notificati
|
||||
public View createView(Context context) {
|
||||
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
|
||||
actionBar.setAllowOverlayTitle(true);
|
||||
/*if (chatType == ChatObject.CHAT_TYPE_BROADCAST) {
|
||||
actionBar.setTitle(LocaleController.getString("NewBroadcastList", R.string.NewBroadcastList));
|
||||
} else*/ {
|
||||
actionBar.setTitle(LocaleController.getString("NewGroup", R.string.NewGroup));
|
||||
}
|
||||
|
||||
actionBar.setTitle(LocaleController.getString("NewGroup", R.string.NewGroup));
|
||||
actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
|
||||
@Override
|
||||
public void onItemClick(int id) {
|
||||
if (id == -1) {
|
||||
finishFragment();
|
||||
} else if (id == done_button) {
|
||||
if (donePressed) {
|
||||
return;
|
||||
}
|
||||
if (nameTextView.getText().length() == 0) {
|
||||
return;
|
||||
}
|
||||
donePressed = true;
|
||||
|
||||
/*if (chatType == ChatObject.CHAT_TYPE_BROADCAST) {
|
||||
MessagesController.getInstance().createChat(nameTextView.getText().toString(), selectedContacts, null, chatType, GroupCreateFinalActivity.this);
|
||||
} else*/ {
|
||||
if (avatarUpdater.uploadingAvatar != null) {
|
||||
createAfterUpload = true;
|
||||
} else {
|
||||
Toast.makeText(getParentActivity(), LocaleController.getString("NotYetImplemented", R.string.NotYetImplemented), Toast.LENGTH_LONG).show();
|
||||
return;
|
||||
/*NotificationCenter.getInstance().postNotificationName(NotificationCenter.chatDidCreated, chat_id);
|
||||
{
|
||||
progressDialog = new ProgressDialog(getParentActivity());
|
||||
progressDialog.setMessage(LocaleController.getString("Loading", R.string.Loading));
|
||||
progressDialog.setCanceledOnTouchOutside(false);
|
||||
@@ -190,8 +158,8 @@ public class GroupCreateFinalActivity extends BaseFragment implements Notificati
|
||||
}
|
||||
});
|
||||
progressDialog.show();
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -213,7 +181,7 @@ public class GroupCreateFinalActivity extends BaseFragment implements Notificati
|
||||
|
||||
avatarImage = new BackupImageView(context);
|
||||
avatarImage.setRoundRadius(AndroidUtilities.dp(32));
|
||||
avatarDrawable.setInfoByName(null);
|
||||
avatarDrawable.setInfoByName("?");
|
||||
avatarImage.setImageDrawable(avatarDrawable);
|
||||
frameLayout.addView(avatarImage);
|
||||
FrameLayout.LayoutParams layoutParams1 = (FrameLayout.LayoutParams) avatarImage.getLayoutParams();
|
||||
@@ -225,7 +193,7 @@ public class GroupCreateFinalActivity extends BaseFragment implements Notificati
|
||||
layoutParams1.rightMargin = LocaleController.isRTL ? AndroidUtilities.dp(16) : 0;
|
||||
layoutParams1.gravity = Gravity.TOP | (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT);
|
||||
avatarImage.setLayoutParams(layoutParams1);
|
||||
/*if (chatType != ChatObject.CHAT_TYPE_BROADCAST)*/ {
|
||||
{
|
||||
avatarDrawable.setDrawPhoto(true);
|
||||
avatarImage.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
@@ -288,7 +256,7 @@ public class GroupCreateFinalActivity extends BaseFragment implements Notificati
|
||||
layoutParams1.rightMargin = LocaleController.isRTL ? AndroidUtilities.dp(96) : AndroidUtilities.dp(16);
|
||||
layoutParams1.gravity = Gravity.CENTER_VERTICAL;
|
||||
nameTextView.setLayoutParams(layoutParams1);
|
||||
/*if (chatType != ChatObject.CHAT_TYPE_BROADCAST)*/ {
|
||||
{
|
||||
nameTextView.addTextChangedListener(new TextWatcher() {
|
||||
@Override
|
||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
||||
@@ -302,14 +270,16 @@ public class GroupCreateFinalActivity extends BaseFragment implements Notificati
|
||||
|
||||
@Override
|
||||
public void afterTextChanged(Editable s) {
|
||||
avatarDrawable.setInfoByName(nameTextView.length() > 0 ? nameTextView.getText().toString() : null);
|
||||
avatarDrawable.setInfoByName(nameTextView.length() > 0 ? nameTextView.getText().toString() : "?");
|
||||
avatarImage.invalidate();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
GreySectionCell sectionCell = new GreySectionCell(context);
|
||||
sectionCell.setText(LocaleController.formatPluralString("Members", selectedContacts.size()));
|
||||
sectionCell.setText(
|
||||
LocaleController.getString("MeAnd", R.string.MeAnd) + " " +
|
||||
LocaleController.formatPluralString("Members", selectedContacts.size()));
|
||||
linearLayout.addView(sectionCell);
|
||||
|
||||
listView = new ListView(context);
|
||||
@@ -394,6 +364,7 @@ public class GroupCreateFinalActivity extends BaseFragment implements Notificati
|
||||
updateVisibleRows(mask);
|
||||
}
|
||||
} else if (id == NotificationCenter.chatDidFailCreate) {
|
||||
/*
|
||||
if (progressDialog != null) {
|
||||
try {
|
||||
progressDialog.dismiss();
|
||||
@@ -401,8 +372,9 @@ public class GroupCreateFinalActivity extends BaseFragment implements Notificati
|
||||
FileLog.e("messenger", e);
|
||||
}
|
||||
}
|
||||
donePressed = false;
|
||||
*/
|
||||
} else if (id == NotificationCenter.chatDidCreated) {
|
||||
/*
|
||||
if (progressDialog != null) {
|
||||
try {
|
||||
progressDialog.dismiss();
|
||||
@@ -410,6 +382,8 @@ public class GroupCreateFinalActivity extends BaseFragment implements Notificati
|
||||
FileLog.e("messenger", e);
|
||||
}
|
||||
}
|
||||
*/
|
||||
/*
|
||||
int chat_id = (Integer)args[0];
|
||||
NotificationCenter.getInstance().postNotificationName(NotificationCenter.closeChats);
|
||||
Bundle args2 = new Bundle();
|
||||
@@ -418,6 +392,7 @@ public class GroupCreateFinalActivity extends BaseFragment implements Notificati
|
||||
if (uploadedAvatar != null) {
|
||||
MessagesController.getInstance().changeChatAvatar(chat_id, uploadedAvatar);
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
@@ -457,8 +432,13 @@ public class GroupCreateFinalActivity extends BaseFragment implements Notificati
|
||||
view = new UserCell(mContext, 1, 0);
|
||||
}
|
||||
|
||||
TLRPC.User user = MessagesController.getInstance().getUser(selectedContacts.get(i));
|
||||
((UserCell) view).setData(123, 0, "erruser", "errstatus", 0);
|
||||
int curr_user_id = selectedContacts.get(i);
|
||||
|
||||
long hContact = MrMailbox.MrMailboxGetContact(MrMailbox.hMailbox, curr_user_id);
|
||||
|
||||
((UserCell) view).setData(curr_user_id, 0, MrMailbox.MrContactGetDisplayName(hContact), MrMailbox.MrContactGetAddr(hContact), 0);
|
||||
|
||||
MrMailbox.MrContactUnref(hContact);
|
||||
return view;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user