正在查看: CallApp v2.226 应用的 TwitterHelper.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
正在查看: CallApp v2.226 应用的 TwitterHelper.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
package com.callapp.contacts.api.helper.twitter;
import a1.d0;
import android.accounts.Account;
import android.accounts.AccountManager;
import android.app.Activity;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.util.Pair;
import com.callapp.common.model.json.JSONSocialNetworkID;
import com.callapp.common.util.Objects;
import com.callapp.common.util.RegexUtils;
import com.callapp.contacts.CallAppApplication;
import com.callapp.contacts.R;
import com.callapp.contacts.api.helper.common.LoginListener;
import com.callapp.contacts.api.helper.common.RemoteAccountHelper;
import com.callapp.contacts.api.helper.gmail.GmailManager;
import com.callapp.contacts.loader.social.QuotaReachedException;
import com.callapp.contacts.loader.social.UnauthorizedAccessErrorException;
import com.callapp.contacts.loader.social.UserNotFoundException;
import com.callapp.contacts.manager.FeedbackManager;
import com.callapp.contacts.manager.UserProfileManager;
import com.callapp.contacts.manager.analytics.AnalyticsManager;
import com.callapp.contacts.manager.cache.CacheManager;
import com.callapp.contacts.manager.popup.PopupManager;
import com.callapp.contacts.manager.preferences.Prefs;
import com.callapp.contacts.manager.task.OutcomeListener;
import com.callapp.contacts.model.Constants;
import com.callapp.contacts.model.Friend;
import com.callapp.contacts.model.PersonData;
import com.callapp.contacts.model.UsageCounter;
import com.callapp.contacts.model.contact.ContactData;
import com.callapp.contacts.model.contact.DataSource;
import com.callapp.contacts.util.Activities;
import com.callapp.contacts.util.ArrayUtils;
import com.callapp.contacts.util.CLog;
import com.callapp.contacts.util.PackageUtils;
import com.callapp.contacts.util.UpdateUserProfileUtil;
import com.callapp.contacts.util.http.HttpRequest;
import com.callapp.contacts.util.http.HttpUtils;
import com.callapp.contacts.util.webview.AuthWebViewDialog;
import com.callapp.framework.util.CollectionUtils;
import com.callapp.framework.util.StringUtils;
import com.twitter.sdk.android.core.TwitterApiException;
import com.twitter.sdk.android.core.TwitterAuthConfig;
import com.twitter.sdk.android.core.TwitterAuthException;
import com.twitter.sdk.android.core.TwitterAuthToken;
import com.twitter.sdk.android.core.TwitterException;
import com.twitter.sdk.android.core.b;
import com.twitter.sdk.android.core.c;
import com.twitter.sdk.android.core.h;
import com.twitter.sdk.android.core.i;
import com.twitter.sdk.android.core.internal.oauth.OAuthResponse;
import com.twitter.sdk.android.core.j;
import com.twitter.sdk.android.core.m;
import com.twitter.sdk.android.core.models.ApiError;
import com.twitter.sdk.android.core.models.Card;
import com.twitter.sdk.android.core.models.Coordinates;
import com.twitter.sdk.android.core.models.Place;
import com.twitter.sdk.android.core.models.Tweet;
import com.twitter.sdk.android.core.models.TweetEntities;
import com.twitter.sdk.android.core.models.User;
import com.twitter.sdk.android.core.n;
import com.twitter.sdk.android.core.o;
import com.twitter.sdk.android.core.q;
import com.twitter.sdk.android.core.services.AccountService;
import com.twitter.sdk.android.core.services.StatusesService;
import com.twitter.sdk.android.core.t;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.atomic.AtomicReference;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import retrofit2.Response;
import s4.y;
import uq.l;
public class TwitterHelper extends RemoteAccountHelper {
public static TwitterHelper h;
public final Object c = new Object();
public CustomTwitterServiceApiClient d;
public l e;
public TwitterAuthToken f;
public CallAppOAuth1aService g;
class AnonymousClass6 extends RemoteAccountHelper.SocialCallable<List> {
public final boolean a;
public AnonymousClass6(boolean z) {
this.a = z;
}
@Override
public final Object a() {
TwitterHelper twitterHelper = TwitterHelper.this;
try {
User myUser = twitterHelper.getMyUser();
ArrayList arrayList = null;
if (myUser != null) {
long j = -1;
boolean z = false;
while (!z) {
IDs I = TwitterHelper.I(twitterHelper, myUser.screenName, myUser.idStr, j);
if (I != null) {
long[] iDs = I.getIDs();
if (iDs != null && iDs.length > 0) {
arrayList = new ArrayList();
long[] jArr = new long[100];
for (int i = 0; i <= iDs.length / 100; i++) {
if (i == iDs.length / 100) {
jArr = new long[iDs.length % 100];
}
if (jArr.length > 0) {
System.arraycopy(iDs, i * 100, jArr, 0, jArr.length);
List P = TwitterHelper.P(twitterHelper, jArr);
if (CollectionUtils.h(P)) {
arrayList.addAll(P);
}
}
}
}
j = I.getNextCursor();
CallAppTwitterRateLimit rateLimit = I.getRateLimit();
if (j > 0) {
if (rateLimit != null && rateLimit.getRemaining() <= 0) {
}
}
}
z = true;
}
}
if (!CollectionUtils.h(arrayList)) {
return new ArrayList();
}
Collections.sort(arrayList, new Comparator<User>(this) {
@Override
public final int compare(User user, User user2) {
return StringUtils.c(user.name, user2.name, true);
}
});
return this.a ? new ArrayList(arrayList.subList(0, Math.min(arrayList.size(), 100))) : arrayList;
} catch (TwitterException e) {
throw new TwitterApiRuntimeException(e);
}
}
@Override
public String getCacheKey() {
return "twitter_followers_" + this.a;
}
@Override
public int getCacheTtl() {
return R.integer.twitter_friends_ttl_minutes;
}
@Override
public int getRefreshInterval() {
return R.integer.twitter_friends_refresh_minutes;
}
}
public class CustomTwitterServiceApiClient extends m {
public CustomTwitterServiceApiClient(TwitterHelper twitterHelper, t tVar) {
super(tVar);
}
public CallAppTwitterService getCustomService() {
return (CallAppTwitterService) a(CallAppTwitterService.class);
}
public CustomTwitterServiceApiClient(TwitterHelper twitterHelper) {
}
}
public static class TwitterApiRuntimeException extends RuntimeException {
public TwitterApiRuntimeException(Throwable th) {
super(th);
}
}
private TwitterHelper() {
if (CallAppApplication.get().isUnitTestMode()) {
return;
}
o.a aVar = new o.a(CallAppApplication.get());
aVar.c = new TwitterAuthConfig("AaMTvkoPxVnh9AQW8jrwAQ", "4Qme3Xi36ET97QywsZ4kzjL7CXzJLRUADFgqYqv6Sw");
if (Prefs.q.get().booleanValue()) {
aVar.b = new c(3);
aVar.d = Boolean.TRUE;
}
com.twitter.sdk.android.core.l.c(new o(aVar.a, aVar.b, aVar.c, (ExecutorService) null, aVar.d, (n) null));
}
public static IDs I(TwitterHelper twitterHelper, String str, String str2, long j) {
twitterHelper.getClass();
try {
Response execute = twitterHelper.getTwitterKitClient().getCustomService().getFollowersId(str, str2, String.valueOf(j), true).execute();
if (execute == null) {
return null;
}
Object obj = execute.b;
okhttp3.Response response = execute.a;
if (!response.isSuccessful()) {
return null;
}
((IDs) obj).setRateLimit(new CallAppTwitterRateLimit(response.headers()));
return (IDs) obj;
} catch (IOException e) {
e.getMessage();
StringUtils.I(TwitterHelper.class);
CLog.a();
return null;
}
}
public static IDs K(TwitterHelper twitterHelper, String str, String str2, long j) {
twitterHelper.getClass();
try {
Response execute = twitterHelper.getTwitterKitClient().getCustomService().getFriendsId(str, str2, String.valueOf(j), true).execute();
if (execute == null) {
return null;
}
Object obj = execute.b;
okhttp3.Response response = execute.a;
if (!response.isSuccessful()) {
return null;
}
((IDs) obj).setRateLimit(new CallAppTwitterRateLimit(response.headers()));
return (IDs) obj;
} catch (IOException e) {
e.getMessage();
StringUtils.I(TwitterHelper.class);
CLog.a();
return null;
}
}
public static Tweet M(TwitterHelper twitterHelper, String str) {
m a;
twitterHelper.getClass();
try {
q c = q.c();
t b = c.a.b();
if (b == null) {
if (c.f == null) {
synchronized (c) {
if (c.f == null) {
c.f = new m();
}
}
}
a = c.f;
} else {
a = c.a(b);
}
StatusesService statusesService = a.getStatusesService();
Boolean bool = Boolean.FALSE;
Boolean bool2 = Boolean.TRUE;
Response execute = statusesService.userTimeline((Long) null, str, 1, (Long) null, (Long) null, bool, bool2, (Boolean) null, bool2).execute();
if (execute == null) {
return null;
}
Object obj = execute.b;
if (execute.a.isSuccessful()) {
return CollectionUtils.h((Collection) obj) ? (Tweet) ((List) obj).get(0) : new Tweet((Coordinates) null, (String) null, (Object) null, (TweetEntities) null, (TweetEntities) null, -1, false, (String) null, -1L, (String) null, (String) null, -1L, (String) null, -1L, (String) null, (String) null, (Place) null, false, (Object) null, -1L, (String) null, (Tweet) null, -1, false, (Tweet) null, (String) null, (String) null, (List) null, false, (User) null, false, (List) null, (String) null, (Card) null);
}
return null;
} catch (IOException e) {
e.getMessage();
StringUtils.I(TwitterHelper.class);
CLog.a();
return null;
}
}
public static User O(TwitterHelper twitterHelper, String str) {
twitterHelper.getClass();
try {
Response execute = twitterHelper.getTwitterKitClient().getCustomService().show(str).execute();
if (execute == null || !execute.a.isSuccessful()) {
return null;
}
return (User) execute.b;
} catch (IOException e) {
e.getMessage();
StringUtils.I(TwitterHelper.class);
CLog.a();
return null;
}
}
public static List P(TwitterHelper twitterHelper, long[] jArr) {
twitterHelper.getClass();
if (jArr == null || jArr.length == 0) {
throw new TwitterException("Empty list");
}
StringBuilder sb2 = new StringBuilder();
for (long j : jArr) {
sb2.append(j);
sb2.append(",");
}
sb2.deleteCharAt(sb2.length() - 1);
try {
Response execute = twitterHelper.getTwitterKitClient().getCustomService().lookup(sb2.toString(), true).execute();
if (execute == null || !execute.a.isSuccessful()) {
return null;
}
return (List) execute.b;
} catch (IOException e) {
e.getMessage();
StringUtils.I(TwitterHelper.class);
CLog.a();
return null;
}
}
public static List Q(TwitterHelper twitterHelper, String str) {
twitterHelper.getClass();
try {
Response execute = twitterHelper.getTwitterKitClient().getCustomService().searchUser(str, 20L, 0L, true).execute();
if (execute == null || !execute.a.isSuccessful()) {
return null;
}
return (List) execute.b;
} catch (IOException e) {
e.getMessage();
StringUtils.I(TwitterHelper.class);
CLog.a();
return null;
}
}
public static void R(TwitterHelper twitterHelper, ArrayList arrayList) {
final List<User> followingByTheUser = twitterHelper.getFollowingByTheUser();
final List list = (List) twitterHelper.H(twitterHelper.new AnonymousClass6(true), List.class, true, false, true);
Collections.sort(arrayList, new Comparator<User>(twitterHelper) {
@Override
public final int compare(User user, User user2) {
User user3 = user;
User user4 = user2;
if (Objects.a(user3, user4)) {
return 0;
}
if (user3 == null) {
return 1;
}
if (user4 == null) {
return -1;
}
List list2 = followingByTheUser;
int i = CollectionUtils.b(list2, user3) ? -2 : 0;
int i2 = CollectionUtils.b(list2, user4) ? -2 : 0;
List list3 = list;
int compare = Integer.compare(i + (CollectionUtils.b(list3, user3) ? -1 : 0), i2 + (CollectionUtils.b(list3, user4) ? -1 : 0));
if (compare != 0) {
return compare;
}
String str = user3.name;
if (StringUtils.t(str)) {
return 1;
}
return str.compareToIgnoreCase(user4.name);
}
});
}
public static void S(StringBuilder sb2) {
String twitterAccount = getTwitterAccount();
if (StringUtils.t(twitterAccount)) {
twitterAccount = GmailManager.get().getGmailAccount();
}
if (StringUtils.x(twitterAccount)) {
y.m(sb2, "&", "screen_name", "=", twitterAccount);
}
}
public static boolean Y(Context context, String str, Runnable runnable) {
if (!HttpUtils.a()) {
FeedbackManager.j(context);
return false;
}
String C = d0.C("https://twitter.com/", str);
if (!StringUtils.x(C)) {
return true;
}
if (!isTwitterAppInstalled()) {
Activities.v(context, C, runnable);
return true;
}
Intent intent = new Intent("android.intent.action.VIEW", Uri.parse(C));
if (Activities.l(intent)) {
Activities.J(context, intent);
return true;
}
Activities.v(context, C, runnable);
return true;
}
public static TwitterHelper get() {
synchronized (TwitterHelper.class) {
try {
if (h == null) {
h = new TwitterHelper();
}
} catch (Throwable th) {
throw th;
}
}
return h;
}
private List<User> getFollowingByTheUser() {
return (List) H(new RemoteAccountHelper.SocialCallable<List>() {
@Override
public final Object a() {
TwitterHelper twitterHelper = TwitterHelper.this;
try {
Set friendIDs = twitterHelper.getFriendIDs();
List P = CollectionUtils.h(friendIDs) ? TwitterHelper.P(twitterHelper, ArrayUtils.c((Long[]) friendIDs.toArray(new Long[friendIDs.size()]))) : null;
if (!CollectionUtils.h(P)) {
return new ArrayList();
}
ArrayList arrayList = new ArrayList(new HashSet(P));
Collections.sort(arrayList, new Comparator<User>(this) {
@Override
public final int compare(User user, User user2) {
return StringUtils.c(user.name, user2.name, true);
}
});
return arrayList;
} catch (TwitterException e) {
throw new TwitterApiRuntimeException(e);
}
}
@Override
public String getCacheKey() {
return "twitter_friends";
}
@Override
public int getCacheTtl() {
return R.integer.twitter_friends_ttl_minutes;
}
@Override
public int getRefreshInterval() {
return R.integer.twitter_friends_refresh_minutes;
}
}, List.class, true, false, true);
}
public Set<Long> getFriendIDs() {
return (Set) H(new RemoteAccountHelper.SocialCallable<HashSet>() {
@Override
public final Object a() {
TwitterHelper twitterHelper = TwitterHelper.this;
HashSet hashSet = new HashSet();
try {
User myUser = twitterHelper.getMyUser();
if (myUser != null) {
long j = -1;
boolean z = false;
while (!z) {
IDs K = TwitterHelper.K(twitterHelper, myUser.screenName, myUser.idStr, j);
if (K != null) {
long[] iDs = K.getIDs();
if (iDs != null && iDs.length > 0) {
Collections.addAll(hashSet, ArrayUtils.b(iDs));
}
j = K.getNextCursor();
CallAppTwitterRateLimit rateLimit = K.getRateLimit();
if (j > 0) {
if (rateLimit != null && rateLimit.getRemaining() <= 0) {
}
}
}
z = true;
}
}
return hashSet;
} catch (TwitterException e) {
throw new TwitterApiRuntimeException(e);
}
}
@Override
public String getCacheKey() {
return "twitter_friends_ids";
}
@Override
public int getCacheTtl() {
return R.integer.twitter_friends_ttl_minutes;
}
}, HashSet.class, true, false, true);
}
public Map<String, User> getFriendsMap() {
HashMap hashMap = (HashMap) CacheManager.get().c("twitter_friends_map", HashMap.class, false, false);
if (!CollectionUtils.i(hashMap)) {
List<User> T = T(true, false);
if (CollectionUtils.h(T)) {
hashMap = new HashMap();
for (User user : T) {
hashMap.put(user.screenName, user);
}
if (CollectionUtils.i(hashMap)) {
CacheManager.get().h(HashMap.class, "twitter_friends_map", hashMap, R.integer.twitter_friends_ttl_minutes);
}
}
}
return hashMap;
}
public User getMyUser() {
try {
AccountService accountService = getTwitterKitClient().getAccountService();
Boolean bool = Boolean.TRUE;
Response execute = accountService.verifyCredentials(bool, bool, bool).execute();
if (execute == null || !execute.a.isSuccessful()) {
return null;
}
return (User) execute.b;
} catch (IOException e) {
e.getMessage();
StringUtils.I(TwitterHelper.class);
CLog.a();
return null;
}
}
private static String getTwitterAccount() {
for (Account account : AccountManager.get(CallAppApplication.get()).getAccounts()) {
if (account.type.contains("twitter")) {
return account.name;
}
}
return null;
}
private com.callapp.contacts.api.helper.twitter.TwitterHelper.CustomTwitterServiceApiClient getTwitterKitClient() {
throw new UnsupportedOperationException("Method not decompiled: com.callapp.contacts.api.helper.twitter.TwitterHelper.getTwitterKitClient():com.callapp.contacts.api.helper.twitter.TwitterHelper$CustomTwitterServiceApiClient");
}
private String getTwitterScreenName() {
try {
t b = q.c().a.b();
if (b == null) {
return null;
}
return b.c();
} catch (TwitterException e) {
X(e, false);
return null;
}
}
public static boolean isTwitterAppInstalled() {
return PackageUtils.a(CallAppApplication.get(), "com.twitter.android") != null;
}
@Override
public final void C(ContactData contactData, JSONSocialNetworkID jSONSocialNetworkID) {
contactData.getDeviceData().setTwitterScreenName(jSONSocialNetworkID);
contactData.updateTwitterScreenName();
}
public final List T(boolean z, boolean z2) {
Throwable th;
if (!isLoggedIn()) {
return null;
}
String str = "twitter_friends_sorted_" + z;
synchronized (str.intern()) {
try {
try {
List list = (List) CacheManager.get().c(str, List.class, false, false);
if (list == null && HttpUtils.a()) {
ArrayList arrayList = new ArrayList();
List<User> followingByTheUser = getFollowingByTheUser();
if (CollectionUtils.h(followingByTheUser)) {
try {
arrayList.addAll(followingByTheUser);
} catch (Throwable th2) {
th = th2;
throw th;
}
}
if (z) {
List list2 = (List) H(new AnonymousClass6(z2), List.class, true, false, true);
if (CollectionUtils.h(list2)) {
arrayList.addAll(list2);
}
}
ArrayList arrayList2 = new ArrayList(new HashSet(arrayList));
Collections.sort(arrayList2, new Comparator<User>(this) {
@Override
public final int compare(User user, User user2) {
return StringUtils.c(user.name, user2.name, true);
}
});
CacheManager.get().h(List.class, str, arrayList2, R.integer.twitter_friends_ttl_minutes);
AnalyticsManager.get().q(Constants.SYNCERS, "Twitter friends count", null, arrayList2.size(), new String[0]);
list = arrayList2;
}
return list;
} catch (Throwable th3) {
th = th3;
th = th;
throw th;
}
} catch (Throwable th4) {
th = th4;
th = th;
throw th;
}
}
}
public final String U(final String str) {
return (String) H(new RemoteAccountHelper.SocialCallable<String>() {
@Override
public final Object a() {
String str2 = str;
if (!StringUtils.x(str2)) {
return "";
}
UsageCounter usageCounter = UsageCounter.twitterTweets;
int integer = CallAppApplication.get().getResources().getInteger(R.integer.twitter_tweet_period_in_minutes);
int integer2 = CallAppApplication.get().getResources().getInteger(R.integer.twitter_tweet_period_request_limit);
TwitterHelper twitterHelper = TwitterHelper.this;
twitterHelper.s(usageCounter, integer, integer2, true);
try {
Tweet M = TwitterHelper.M(twitterHelper, str2);
return M != null ? M.text : "";
} catch (TwitterException e) {
throw new TwitterApiRuntimeException(e);
}
}
@Override
public String getCacheKey() {
return "twitter_user_last_tweet_" + str;
}
@Override
public int getCacheTtl() {
return R.integer.twitter_last_tweet_ttl_minutes;
}
}, String.class, true, false, true);
}
public final String V(String str, String str2) {
if (!StringUtils.x(str)) {
return null;
}
String p = androidx.fragment.app.n.p("twitter_user_profile_image_url_", str2, "_", str);
String str3 = (String) CacheManager.get().c(p, String.class, false, false);
if (str3 == null && HttpUtils.a()) {
s(UsageCounter.twitterPicture, CallAppApplication.get().getResources().getInteger(R.integer.twitter_show_period_in_minutes), CallAppApplication.get().getResources().getInteger(R.integer.twitter_show_period_request_limit), true);
User W = W(str, false);
if (W != null) {
String replace = (W.defaultProfileImage || !StringUtils.x(W.profileImageUrl)) ? "" : W.profileImageUrl.replace("_normal", "CALLAPP#@#CALLAPP").replace("_bigger", "CALLAPP#@#CALLAPP").replace("_mini", "CALLAPP#@#CALLAPP").replace("CALLAPP#@#CALLAPP", str2);
CacheManager.get().h(String.class, p, replace, R.integer.twitter_profile_image_url_ttl_minutes);
return replace;
}
}
return str3;
}
public final User W(final String str, boolean z) {
return (User) H(new RemoteAccountHelper.SocialCallable<User>() {
@Override
public final Object a() {
String str2 = str;
if (StringUtils.x(str2)) {
TwitterHelper twitterHelper = TwitterHelper.this;
Map friendsMap = twitterHelper.getFriendsMap();
r2 = CollectionUtils.i(friendsMap) ? (User) friendsMap.get(str2) : null;
if (r2 == null && HttpUtils.a()) {
twitterHelper.s(UsageCounter.twitterUser, CallAppApplication.get().getResources().getInteger(R.integer.twitter_show_period_in_minutes), CallAppApplication.get().getResources().getInteger(R.integer.twitter_show_period_request_limit), true);
try {
User O = TwitterHelper.O(twitterHelper, str2);
if (O != null) {
return O;
}
} catch (TwitterException e) {
throw new TwitterApiRuntimeException(e);
}
}
}
return r2;
}
@Override
public String getCacheKey() {
return "twitter_user_" + str;
}
@Override
public int getCacheTtl() {
return R.integer.twitter_user_cache_ttl_minutes;
}
}, User.class, true, z, true);
}
public final void X(TwitterException twitterException, boolean z) {
CLog.b(TwitterHelper.class, twitterException);
String message = twitterException.getMessage();
boolean z2 = twitterException instanceof TwitterApiException;
if (z2) {
ApiError apiError = ((TwitterApiException) twitterException).a;
if ((apiError == null ? 0 : apiError.code) == 0 && twitterException.getMessage().equals("401 ")) {
return;
}
}
if (twitterException.getMessage().equalsIgnoreCase("429 ")) {
throw new QuotaReachedException((Throwable) twitterException);
}
if ((twitterException instanceof TwitterAuthException) || ((StringUtils.x(message) && message.contains("401:Authentication credentials") && message.contains("were missing or incorrect")) || twitterException.getMessage().equalsIgnoreCase("215 "))) {
Prefs.P0.set(null);
throw new UnauthorizedAccessErrorException((Throwable) twitterException);
}
if (z) {
if (twitterException.getMessage().equalsIgnoreCase("34") && StringUtils.x(message) && message.contains("Sorry, that page does not exist")) {
throw new UserNotFoundException(twitterException);
}
if (z2) {
ApiError apiError2 = ((TwitterApiException) twitterException).a;
if ((apiError2 == null ? 0 : apiError2.code) == 50 && StringUtils.x(message)) {
if ((apiError2 == null ? null : apiError2.message).contains("User not found")) {
throw new UserNotFoundException(twitterException);
}
}
}
}
if (z2) {
ApiError apiError3 = ((TwitterApiException) twitterException).a;
int i = apiError3 != null ? apiError3.code : 0;
if (i == 89 || i == 239) {
this.d = null;
}
}
}
public final void Z() {
String f = Activities.f(R.string.twitter_post_url, HttpUtils.getCallAppDomain());
if (isLoggedIn() && HttpUtils.a()) {
try {
} catch (TwitterException e) {
X(e, false);
}
if (isReadyForRemoteCalls()) {
try {
Response execute = getTwitterKitClient().getCustomService().postStatus(f).execute();
if (execute != null) {
if (execute.a.isSuccessful()) {
return;
}
}
} catch (IOException e2) {
e2.getMessage();
StringUtils.I(TwitterHelper.class);
CLog.a();
}
AnalyticsManager.get().p(Constants.FAILED, "Failed to post", getName());
}
}
}
@Override
public final void a(String str) {
try {
CallAppOAuth1aService callAppOAuth1aService = this.g;
if (callAppOAuth1aService != null) {
callAppOAuth1aService.c(new b() {
public final void a(TwitterException twitterException) {
TwitterHelper.this.onError(twitterException.getMessage());
}
public final void b(i iVar) {
TwitterHelper twitterHelper = TwitterHelper.this;
Object obj = iVar.a;
if (obj == null) {
twitterHelper.onError("");
return;
}
twitterHelper.d = null;
h hVar = q.c().a;
OAuthResponse oAuthResponse = (OAuthResponse) obj;
TwitterAuthToken twitterAuthToken = oAuthResponse.authToken;
hVar.f(new t(new TwitterAuthToken(twitterAuthToken.token, twitterAuthToken.secret), oAuthResponse.userId, oAuthResponse.userName));
TwitterAuthToken twitterAuthToken2 = oAuthResponse.authToken;
Prefs.P0.set(new Pair(twitterAuthToken2.token, twitterAuthToken2.secret));
twitterHelper.A();
twitterHelper.onComplete();
}
}, this.f, str);
}
} catch (TwitterException e) {
X(e, false);
onError(e.getMessage());
}
}
@Override
public final HttpRequest b(HttpRequest httpRequest) {
String twitterScreenName = getTwitterScreenName();
if (StringUtils.x(twitterScreenName)) {
if (httpRequest == null) {
httpRequest = UpdateUserProfileUtil.b();
}
UpdateUserProfileUtil.a(httpRequest, new Pair("twtscrname", twitterScreenName));
}
return httpRequest;
}
@Override
public final void f() {
if (isLoggedIn() && HttpUtils.a() && isReadyForRemoteCalls()) {
String twitterScreenName = getTwitterScreenName();
CacheManager.get().f(User.class, "twitter_user_" + twitterScreenName);
UserProfileManager.get().c(4);
}
CacheManager.get().f(List.class, "twitter_friends_sorted_" + Boolean.TRUE);
CacheManager.get().f(List.class, "twitter_friends_sorted_" + Boolean.FALSE);
Prefs.P0.set(null);
h hVar = q.c().a;
hVar.d();
AtomicReference atomicReference = hVar.f;
if (atomicReference.get() != null) {
hVar.a(((j) atomicReference.get()).b());
}
this.e = null;
this.d = null;
}
@Override
public final void g(final Activity activity) {
if (isLoggedIn()) {
onComplete();
return;
}
if (isNativeAppInstalled()) {
l lVar = new l();
this.e = lVar;
lVar.a(activity, new b() {
public final void a(TwitterException twitterException) {
AnalyticsManager.get().o(Constants.REGISTRATION, "Twitter SDK TwitterException");
String message = twitterException.getMessage();
TwitterHelper twitterHelper = TwitterHelper.this;
twitterHelper.onError(message);
twitterHelper.e = null;
}
public final void b(i iVar) {
TwitterHelper twitterHelper = TwitterHelper.this;
twitterHelper.d = null;
TwitterAuthToken a = ((t) iVar.a).a();
Prefs.P0.set(new Pair(a.token, a.secret));
twitterHelper.A();
twitterHelper.onComplete();
twitterHelper.e = null;
}
});
} else {
b bVar = new b() {
public final void a(TwitterException twitterException) {
CLog.b(TwitterHelper.class, twitterException);
TwitterHelper.this.onError(twitterException.getMessage());
}
public final void b(i iVar) {
TwitterAuthToken twitterAuthToken = ((OAuthResponse) iVar.a).authToken;
TwitterHelper twitterHelper = TwitterHelper.this;
twitterHelper.f = twitterAuthToken;
StringBuilder p = k2.t.p("https://api.twitter.com/oauth/authorize?", "oauth_token=");
p.append(twitterHelper.f.token);
TwitterHelper.S(p);
PopupManager popupManager = PopupManager.get();
String sb2 = p.toString();
DialogInterface.OnCancelListener onCancelListener = new DialogInterface.OnCancelListener() {
@Override
public final void onCancel(DialogInterface dialogInterface) {
StringUtils.I(getClass());
CLog.a();
LoginListener loginListener = TwitterHelper.this.b;
if (loginListener != null) {
loginListener.onCancel();
}
}
};
Activity activity2 = activity;
popupManager.c(activity2, new AuthWebViewDialog(activity2, sb2, onCancelListener, twitterHelper), true);
}
};
CallAppOAuth1aService callAppOAuth1aService = new CallAppOAuth1aService(q.c(), new vq.i());
this.g = callAppOAuth1aService;
callAppOAuth1aService.d(bVar);
}
}
@Override
public int getApiConstantNetworkId() {
return 4;
}
@Override
public String getCurrentUserId() {
if (isLoggedIn() && HttpUtils.a() && isReadyForRemoteCalls()) {
return getTwitterScreenName();
}
return null;
}
@Override
public DataSource getDataSource() {
return DataSource.twitter;
}
@Override
public long getFriendsCount() {
if (CollectionUtils.h(T(true, true))) {
return r0.size();
}
return 0L;
}
public User getLoggedInUser() {
if (isLoggedIn() && HttpUtils.a() && isReadyForRemoteCalls()) {
try {
return W(getTwitterScreenName(), false);
} catch (IllegalStateException unused) {
} catch (TwitterException e) {
X(e, false);
}
}
return null;
}
@Override
public String getName() {
return Activities.getString(R.string.twitter);
}
@Override
public String getUserName() {
return getCurrentUserId();
}
@Override
public final boolean i() {
if (isLoggedIn() && HttpUtils.a() && isReadyForRemoteCalls()) {
try {
Response execute = getTwitterKitClient().getCustomService().follow("getcallapp", false).execute();
if (execute != null) {
if (execute.a.isSuccessful()) {
return true;
}
}
} catch (IOException e) {
e.getMessage();
StringUtils.I(TwitterHelper.class);
CLog.a();
}
}
return false;
}
@Override
public boolean isLoggedIn() {
return Prefs.P0.isNotNull();
}
@Override
public boolean isNativeAppInstalled() {
return isTwitterAppInstalled();
}
@Override
public boolean isReadyForRemoteCalls() {
try {
return getTwitterKitClient() != null;
} catch (TwitterException unused) {
return false;
}
}
@Override
public final JSONSocialNetworkID j(ContactData contactData) {
return contactData.getTwitterScreenName();
}
@Override
public final Map k(boolean z, boolean z2) {
List<User> T = T(z2, true);
if (!CollectionUtils.h(T)) {
return Collections.EMPTY_MAP;
}
HashMap hashMap = new HashMap(T.size());
for (User user : T) {
String str = user.name;
if (z && StringUtils.x(str)) {
str = str.toLowerCase();
}
String str2 = user.screenName;
hashMap.put(str2, new Friend(str2, str, user.description));
}
return hashMap;
}
@Override
public final String m(String str) {
if (!StringUtils.t(str) && str.contains("twitter.com")) {
Pattern c = RegexUtils.c("(?:http:\\/\\/)?(?:www.)?twitter.com\\/(?:(?:\\w)*#!\\/)?([\\w\\-\\.]*)?");
if (!StringUtils.t(str)) {
Matcher matcher = c.matcher(str);
if (matcher.find()) {
String group = matcher.group(1);
if (StringUtils.x(group)) {
return group;
}
}
}
}
return null;
}
@Override
public final String n(String str) {
return V(str, "");
}
@Override
public final List o(final String str) {
return (List) H(new RemoteAccountHelper.SocialCallable<List>() {
@Override
public final Object a() {
TwitterHelper twitterHelper = TwitterHelper.this;
String str2 = str;
boolean z = false;
User W = twitterHelper.W(str2, false);
if (W != null && W.friendsCount <= 500) {
Set friendIDs = twitterHelper.getFriendIDs();
if (!CollectionUtils.f(friendIDs)) {
try {
HashSet hashSet = new HashSet();
long j = -1;
while (!z) {
IDs K = TwitterHelper.K(twitterHelper, str2, null, j);
if (K != null) {
long[] iDs = K.getIDs();
if (iDs != null && iDs.length > 0) {
Collections.addAll(hashSet, ArrayUtils.b(iDs));
}
j = K.getNextCursor();
CallAppTwitterRateLimit rateLimit = K.getRateLimit();
if (j > 0) {
if (rateLimit != null && rateLimit.getRemaining() <= 0) {
}
}
}
z = true;
}
ArrayList arrayList = new ArrayList();
if (CollectionUtils.h(hashSet)) {
Iterator it = hashSet.iterator();
while (it.hasNext()) {
Long l = (Long) it.next();
if (friendIDs.contains(l)) {
arrayList.add(l);
}
if (arrayList.size() >= 50) {
break;
}
}
}
ArrayList arrayList2 = new ArrayList();
if (CollectionUtils.h(arrayList)) {
List P = TwitterHelper.P(twitterHelper, ArrayUtils.c((Long[]) arrayList.toArray(new Long[arrayList.size()])));
if (CollectionUtils.h(P)) {
Iterator it2 = P.iterator();
while (it2.hasNext()) {
arrayList2.add(new PersonData((User) it2.next()));
}
}
}
return arrayList2;
} catch (TwitterException e) {
throw new TwitterApiRuntimeException(e);
}
}
}
return null;
}
@Override
public String getCacheKey() {
return "twitter_mutualfriends_pd_" + str;
}
@Override
public int getCacheTtl() {
return R.integer.twitter_mutual_friends_cache_ttl_minutes;
}
}, List.class, true, false, true);
}
@Override
public final String q(String str) {
String V = V(str, "_bigger");
if (u(V)) {
return null;
}
return V;
}
@Override
public final String r(String str) {
User W = W(str, true);
if (W != null) {
return W.name;
}
return null;
}
@Override
public final Object t(RemoteAccountHelper.SocialCallable socialCallable, boolean z) {
try {
return socialCallable.a();
} catch (TwitterApiRuntimeException e) {
Throwable cause = e.getCause();
if (cause == null) {
CLog.b(getClass(), e);
return null;
}
if (!(cause instanceof TwitterException)) {
return null;
}
X((TwitterException) cause, z);
return null;
}
}
@Override
public final boolean u(String str) {
return StringUtils.t(str) || str.contains("default_profile");
}
@Override
public final void y(Context context, String str, Runnable runnable, OutcomeListener outcomeListener) {
RemoteAccountHelper.B(outcomeListener, Y(context, str, runnable));
}
@Override
public final List z(final String str) {
List list = (List) H(new RemoteAccountHelper.SocialCallable<List>() {
@Override
public final Object a() {
TwitterHelper twitterHelper = TwitterHelper.this;
String str2 = str;
ArrayList arrayList = null;
if (!StringUtils.x(str2)) {
return null;
}
try {
twitterHelper.s(UsageCounter.twitterSearchRequests, CallAppApplication.get().getResources().getInteger(R.integer.twitter_search_period_in_minutes), CallAppApplication.get().getResources().getInteger(R.integer.twitter_search_period_request_limit), true);
List Q = TwitterHelper.Q(twitterHelper, str2);
if (!twitterHelper.a) {
FeedbackManager.get().b("searched " + twitterHelper.getName(), 17, 0);
}
if (CollectionUtils.h(Q)) {
arrayList = new ArrayList(Q);
TwitterHelper.R(twitterHelper, arrayList);
}
return arrayList == null ? Collections.EMPTY_LIST : arrayList;
} catch (TwitterException e) {
throw new TwitterApiRuntimeException(e);
}
}
@Override
public String getCacheKey() {
return "twitter_search_" + str;
}
@Override
public int getCacheTtl() {
return R.integer.twitter_search_ttl_minutes;
}
}, List.class, true, false, true);
if (list == null || list.isEmpty()) {
return null;
}
ArrayList arrayList = new ArrayList(list.size());
Iterator it = list.iterator();
while (it.hasNext()) {
arrayList.add(new PersonData((User) it.next()));
}
return arrayList;
}
}