|
@@ -19,15 +19,20 @@ import org.telegram.cricdit.mvp.MoreGroupPresenter;
|
|
|
import org.telegram.cricdit.mvp.MoreGroupView;
|
|
|
import org.telegram.cricdit.utils.ToastUtil;
|
|
|
import org.telegram.messenger.AndroidUtilities;
|
|
|
+import org.telegram.messenger.ChatObject;
|
|
|
import org.telegram.messenger.LocaleController;
|
|
|
import org.telegram.messenger.MessagesController;
|
|
|
import org.telegram.messenger.MessagesStorage;
|
|
|
import org.telegram.messenger.R;
|
|
|
+import org.telegram.messenger.UserConfig;
|
|
|
import org.telegram.tgnet.ConnectionsManager;
|
|
|
import org.telegram.tgnet.TLObject;
|
|
|
import org.telegram.tgnet.TLRPC;
|
|
|
+import org.telegram.ui.ActionBar.AlertDialog;
|
|
|
import org.telegram.ui.ActionBar.BaseFragment;
|
|
|
import org.telegram.ui.ChatActivity;
|
|
|
+import org.telegram.ui.Components.JoinGroupAlert;
|
|
|
+import org.telegram.ui.LoginActivity;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
@@ -41,6 +46,7 @@ public class MoreGroupFragment implements BaseViewFragment, MoreGroupView {
|
|
|
private SmartRefreshLayout mRefreshLayout;
|
|
|
private MoreGroupAdapter mAdapter;
|
|
|
private List<MoreGroupBean.ListDTO> mMoreGroupBeanList;
|
|
|
+ private AlertDialog alertDialog;
|
|
|
|
|
|
|
|
|
public MoreGroupFragment(BaseFragment fragment) {
|
|
@@ -55,6 +61,8 @@ public class MoreGroupFragment implements BaseViewFragment, MoreGroupView {
|
|
|
private void initView(View view) {
|
|
|
mMoreGroupBeanList = new ArrayList<>();
|
|
|
|
|
|
+ alertDialog = new AlertDialog(mFragment.getParentActivity(), 3);
|
|
|
+
|
|
|
mRefreshLayout = view.findViewById(R.id.more_group_refresh_layout);
|
|
|
mRefreshLayout.setEnableLoadMore(false);
|
|
|
|
|
@@ -67,9 +75,30 @@ public class MoreGroupFragment implements BaseViewFragment, MoreGroupView {
|
|
|
View inflate = LayoutInflater.from(mFragment.getContext()).inflate(R.layout.layout_empty_view, null, false);
|
|
|
mAdapter.setEmptyView(inflate);
|
|
|
mAdapter.setOnItemClickListener((adapter, view1, position) -> {
|
|
|
- List<MoreGroupBean.ListDTO> data = mAdapter.getData();
|
|
|
- if (data != null && data.size() > 0) {
|
|
|
- jumpToChat(data.get(position).public_link, Long.parseLong(data.get(position).group_id));
|
|
|
+ if (UserConfig.getInstance(0).isClientActivated()) {
|
|
|
+ MoreGroupBean.ListDTO groupData = mAdapter.getData().get(position);
|
|
|
+ alertDialog.show();
|
|
|
+ if (!TextUtils.isEmpty(groupData.private_link)) {
|
|
|
+ newSkipUrl(groupData.private_link);
|
|
|
+ } else {
|
|
|
+ if (!TextUtils.isEmpty(groupData.public_link)) {
|
|
|
+ if (groupData.public_link.startsWith("https://t.me/")) {
|
|
|
+ newSkipUrl(groupData.public_link);
|
|
|
+ } else {
|
|
|
+ newSkipUrl("https://t.me/" + groupData.public_link);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (alertDialog != null) {
|
|
|
+ alertDialog.dismiss();
|
|
|
+ }
|
|
|
+ ToastUtil.show(mFragment.getParentActivity(), LocaleController.getString(R.string.CdExpiredGroup));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (alertDialog != null) {
|
|
|
+ alertDialog.dismiss();
|
|
|
+ }
|
|
|
+ mFragment.presentFragment(new LoginActivity());
|
|
|
}
|
|
|
});
|
|
|
mRecyclerView.setAdapter(mAdapter);
|
|
@@ -106,30 +135,92 @@ public class MoreGroupFragment implements BaseViewFragment, MoreGroupView {
|
|
|
return view;
|
|
|
}
|
|
|
|
|
|
- public void jumpToChat(String publicLink, long groupId) {
|
|
|
- TLObject req;
|
|
|
- if (!TextUtils.isEmpty(publicLink)) {
|
|
|
- TLRPC.Chat chatStor = MessagesController.getInstance(0).getChat(groupId);
|
|
|
- if (chatStor == null) {
|
|
|
- String publickLink = "";
|
|
|
- if (publicLink.startsWith(Constants.TEL_NORMAL_URL_PREFIX)) {
|
|
|
- publickLink = publicLink.split(Constants.TEL_NORMAL_URL_PREFIX)[1];
|
|
|
- } else {
|
|
|
- publickLink = publicLink;
|
|
|
- }
|
|
|
+// public void jumpToChat(String publicLink, long groupId) {
|
|
|
+// TLObject req;
|
|
|
+// if (!TextUtils.isEmpty(publicLink)) {
|
|
|
+// TLRPC.Chat chatStor = MessagesController.getInstance(0).getChat(groupId);
|
|
|
+// if (chatStor == null) {
|
|
|
+// String publickLink = "";
|
|
|
+// if (publicLink.startsWith(Constants.TEL_NORMAL_URL_PREFIX)) {
|
|
|
+// publickLink = publicLink.split(Constants.TEL_NORMAL_URL_PREFIX)[1];
|
|
|
+// } else {
|
|
|
+// publickLink = publicLink;
|
|
|
+// }
|
|
|
+//
|
|
|
+// TLRPC.TL_contacts_resolveUsername resolveUsername = new TLRPC.TL_contacts_resolveUsername();
|
|
|
+// resolveUsername.username = publickLink;
|
|
|
+// req = resolveUsername;
|
|
|
+//
|
|
|
+// ConnectionsManager.getInstance(0).sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> {
|
|
|
+// TLRPC.TL_contacts_resolvedPeer res = (TLRPC.TL_contacts_resolvedPeer) response;
|
|
|
+// if (error == null && res != null && res.chats != null) {
|
|
|
+// MessagesController.getInstance(0).putUsers(res.users, false);
|
|
|
+// MessagesController.getInstance(0).putChats(res.chats, false);
|
|
|
+// MessagesStorage.getInstance(0).putUsersAndChats(res.users, res.chats, false, true);
|
|
|
+// TLRPC.Chat chat = res.chats.get(0);
|
|
|
+// if (chat != null) {
|
|
|
+// Bundle args = new Bundle();
|
|
|
+// if (!res.chats.isEmpty()) {
|
|
|
+// args.putLong("chat_id", res.chats.get(0).id);
|
|
|
+// } else {
|
|
|
+// args.putLong("user_id", res.users.get(0).id);
|
|
|
+// }
|
|
|
+// mFragment.presentFragment(new ChatActivity(args));
|
|
|
+// } else {
|
|
|
+// if (mFragment != null && mFragment.getParentActivity() != null) {
|
|
|
+// ToastUtil.show(mFragment.getParentActivity(), LocaleController.getString(R.string.ExpiredLink));
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }));
|
|
|
+// } else {
|
|
|
+// Bundle args = new Bundle();
|
|
|
+// args.putLong("chat_id", chatStor.id);
|
|
|
+// mFragment.presentFragment(new ChatActivity(args));
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
|
|
|
- TLRPC.TL_contacts_resolveUsername resolveUsername = new TLRPC.TL_contacts_resolveUsername();
|
|
|
- resolveUsername.username = publickLink;
|
|
|
- req = resolveUsername;
|
|
|
+ public void newSkipUrl(String finalWorkingText) {
|
|
|
+ if (finalWorkingText.contains("https://t.me/")) {
|
|
|
+ int index = finalWorkingText.indexOf("https://t.me/");
|
|
|
+ int end = finalWorkingText.indexOf(" ", index);
|
|
|
+ String gName;
|
|
|
+ String group = "";
|
|
|
+ if (end != -1) {
|
|
|
+ gName = finalWorkingText.substring(index + "https://t.me/".length(), end);
|
|
|
+ } else {
|
|
|
+ gName = finalWorkingText.substring(index + "https://t.me/".length());
|
|
|
+ }
|
|
|
+ if (gName.startsWith("+")) {
|
|
|
+ group = gName.replace("+", "");
|
|
|
+ if (AndroidUtilities.isNumeric(group)) {
|
|
|
+ gName = group;
|
|
|
+ group = null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (TextUtils.isEmpty(group)) {
|
|
|
+ if (gName != null) {
|
|
|
+ TLObject req;
|
|
|
+ if (AndroidUtilities.isNumeric(gName)) {
|
|
|
+ TLRPC.TL_contacts_resolvePhone resolvePhone = new TLRPC.TL_contacts_resolvePhone();
|
|
|
+ resolvePhone.phone = gName;
|
|
|
+ req = resolvePhone;
|
|
|
+ } else {
|
|
|
+ TLRPC.TL_contacts_resolveUsername resolveUsername = new TLRPC.TL_contacts_resolveUsername();
|
|
|
+ resolveUsername.username = gName;
|
|
|
+ req = resolveUsername;
|
|
|
+ }
|
|
|
|
|
|
- ConnectionsManager.getInstance(0).sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> {
|
|
|
- TLRPC.TL_contacts_resolvedPeer res = (TLRPC.TL_contacts_resolvedPeer) response;
|
|
|
- if (error == null && res != null && res.chats != null) {
|
|
|
- MessagesController.getInstance(0).putUsers(res.users, false);
|
|
|
- MessagesController.getInstance(0).putChats(res.chats, false);
|
|
|
- MessagesStorage.getInstance(0).putUsersAndChats(res.users, res.chats, false, true);
|
|
|
- TLRPC.Chat chat = res.chats.get(0);
|
|
|
- if (chat != null) {
|
|
|
+ ConnectionsManager.getInstance(0).sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> {
|
|
|
+ if (alertDialog != null) {
|
|
|
+ alertDialog.dismiss();
|
|
|
+ }
|
|
|
+ TLRPC.TL_contacts_resolvedPeer res = (TLRPC.TL_contacts_resolvedPeer) response;
|
|
|
+ if (error == null && res != null && res.users != null) {
|
|
|
+ MessagesController.getInstance(0).putUsers(res.users, false);
|
|
|
+ MessagesController.getInstance(0).putChats(res.chats, false);
|
|
|
+ MessagesStorage.getInstance(0).putUsersAndChats(res.users, res.chats, false, true);
|
|
|
Bundle args = new Bundle();
|
|
|
if (!res.chats.isEmpty()) {
|
|
|
args.putLong("chat_id", res.chats.get(0).id);
|
|
@@ -137,18 +228,43 @@ public class MoreGroupFragment implements BaseViewFragment, MoreGroupView {
|
|
|
args.putLong("user_id", res.users.get(0).id);
|
|
|
}
|
|
|
mFragment.presentFragment(new ChatActivity(args));
|
|
|
+
|
|
|
} else {
|
|
|
- if (mFragment != null && mFragment.getParentActivity() != null) {
|
|
|
- ToastUtil.show(mFragment.getParentActivity(), LocaleController.getString(R.string.ExpiredLink));
|
|
|
+ ToastUtil.show(mFragment.getParentActivity(), LocaleController.getString("ExpiredLink", R.string.ExpiredLink));
|
|
|
+ }
|
|
|
+ }));
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ final TLRPC.TL_messages_checkChatInvite req = new TLRPC.TL_messages_checkChatInvite();
|
|
|
+ req.hash = group;
|
|
|
+ String finalGroup = group;
|
|
|
+ ConnectionsManager.getInstance(0).sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> {
|
|
|
+ if (alertDialog != null) {
|
|
|
+ alertDialog.dismiss();
|
|
|
+ }
|
|
|
+ if (error == null) {
|
|
|
+ TLRPC.ChatInvite invite = (TLRPC.ChatInvite) response;
|
|
|
+ if (invite.chat != null && (!ChatObject.isLeftFromChat(invite.chat) || !invite.chat.kicked && (!TextUtils.isEmpty(invite.chat.username) || invite instanceof TLRPC.TL_chatInvitePeek || invite.chat.has_geo))) {
|
|
|
+ MessagesController.getInstance(0).putChat(invite.chat, false);
|
|
|
+ ArrayList<TLRPC.Chat> chats = new ArrayList<>();
|
|
|
+ chats.add(invite.chat);
|
|
|
+ MessagesStorage.getInstance(0).putUsersAndChats(null, chats, false, true);
|
|
|
+ Bundle args = new Bundle();
|
|
|
+ args.putLong("chat_id", invite.chat.id);
|
|
|
+ mFragment.presentFragment(new ChatActivity(args));
|
|
|
+ } else {
|
|
|
+ if (mFragment != null) {
|
|
|
+ mFragment.showDialog(new JoinGroupAlert(mFragment.getParentActivity(), invite, finalGroup, mFragment, (mFragment instanceof ChatActivity ? ((ChatActivity) mFragment).themeDelegate : null)));
|
|
|
}
|
|
|
}
|
|
|
+ } else {
|
|
|
+ if (mFragment != null && mFragment.getParentActivity() != null) {
|
|
|
+ ToastUtil.show(mFragment.getParentActivity(), LocaleController.getString("ExpiredLink", R.string.ExpiredLink));
|
|
|
+ }
|
|
|
}
|
|
|
}));
|
|
|
- } else {
|
|
|
- Bundle args = new Bundle();
|
|
|
- args.putLong("chat_id", chatStor.id);
|
|
|
- mFragment.presentFragment(new ChatActivity(args));
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
}
|