-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: tehcneko <[email protected]>
- Loading branch information
Showing
10 changed files
with
626 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
363 changes: 363 additions & 0 deletions
363
TMessagesProj/src/main/java/tw/nekomimi/nekogram/helpers/CloudSettingsHelper.java
Large diffs are not rendered by default.
Oops, something went wrong.
121 changes: 121 additions & 0 deletions
121
TMessagesProj/src/main/java/tw/nekomimi/nekogram/helpers/CloudStorageHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
package tw.nekomimi.nekogram.helpers; | ||
|
||
import android.util.SparseArray; | ||
|
||
import com.google.gson.Gson; | ||
|
||
import org.telegram.messenger.AccountInstance; | ||
import org.telegram.messenger.AndroidUtilities; | ||
import org.telegram.messenger.Utilities; | ||
import org.telegram.tgnet.TLRPC; | ||
|
||
import java.util.HashMap; | ||
|
||
public class CloudStorageHelper extends AccountInstance { | ||
|
||
private static final SparseArray<CloudStorageHelper> Instance = new SparseArray<>(); | ||
private static final long WEBVIEW_BOT_ID = 1433866570L; | ||
private static final String WEBVIEW_BOT = "NextAloneBot"; | ||
|
||
private final Gson gson = new Gson(); | ||
|
||
public CloudStorageHelper(int num) { | ||
super(num); | ||
} | ||
|
||
public static CloudStorageHelper getInstance(int num) { | ||
CloudStorageHelper localInstance = Instance.get(num); | ||
if (localInstance == null) { | ||
synchronized (CloudStorageHelper.class) { | ||
localInstance = Instance.get(num); | ||
if (localInstance == null) { | ||
Instance.put(num, localInstance = new CloudStorageHelper(num)); | ||
} | ||
} | ||
} | ||
return localInstance; | ||
} | ||
|
||
private void invokeWebViewCustomMethod(String method, String data, Utilities.Callback2<String, String> callback) { | ||
invokeWebViewCustomMethod(method, data, true, callback); | ||
} | ||
|
||
private void invokeWebViewCustomMethod(String method, String data, boolean searchUser, Utilities.Callback2<String, String> callback) { | ||
TLRPC.User user = getMessagesController().getUser(WEBVIEW_BOT_ID); | ||
if (user == null) { | ||
if (searchUser) { | ||
getUserHelper().resolveUser(WEBVIEW_BOT, WEBVIEW_BOT_ID, arg -> invokeWebViewCustomMethod(method, data, false, callback)); | ||
} else { | ||
callback.run(null, "USER_NOT_FOUND"); | ||
} | ||
return; | ||
} | ||
TLRPC.TL_bots_invokeWebViewCustomMethod req = new TLRPC.TL_bots_invokeWebViewCustomMethod(); | ||
req.bot = getMessagesController().getInputUser(user); | ||
req.custom_method = method; | ||
req.params = new TLRPC.TL_dataJSON(); | ||
req.params.data = data; | ||
getConnectionsManager().sendRequest(req, (res, error) -> AndroidUtilities.runOnUIThread(() -> { | ||
if (callback != null) { | ||
if (error != null) { | ||
callback.run(null, error.text); | ||
} else if (res instanceof TLRPC.TL_dataJSON) { | ||
callback.run(((TLRPC.TL_dataJSON) res).data, null); | ||
} else { | ||
callback.run(null, null); | ||
} | ||
} | ||
})); | ||
} | ||
|
||
public void setItem(String key, String value, Utilities.Callback2<String, String> callback) { | ||
HashMap<String, String> map = new HashMap<>(); | ||
map.put("key", key); | ||
map.put("value", value); | ||
invokeWebViewCustomMethod("saveStorageValue", gson.toJson(map), callback); | ||
} | ||
|
||
public void getItem(String key, Utilities.Callback2<String, String> callback) { | ||
getItems(new String[]{key}, (res, error) -> { | ||
if (error == null) { | ||
callback.run(res.get(key), null); | ||
} else { | ||
callback.run(null, error); | ||
} | ||
}); | ||
} | ||
|
||
public void getItems(String[] keys, Utilities.Callback2<HashMap<String, String>, String> callback) { | ||
HashMap<String, String[]> map = new HashMap<>(); | ||
map.put("keys", keys); | ||
invokeWebViewCustomMethod("getStorageValues", gson.toJson(map), (res, error) -> { | ||
if (error == null) { | ||
//noinspection unchecked | ||
callback.run(gson.fromJson(res, HashMap.class), null); | ||
} else { | ||
callback.run(null, error); | ||
} | ||
}); | ||
} | ||
|
||
public void removeItem(String key, Utilities.Callback2<String, String> callback) { | ||
removeItems(new String[]{key}, callback); | ||
} | ||
|
||
public void removeItems(String[] keys, Utilities.Callback2<String, String> callback) { | ||
HashMap<String, String[]> map = new HashMap<>(); | ||
map.put("keys", keys); | ||
invokeWebViewCustomMethod("deleteStorageValues", gson.toJson(map), callback); | ||
} | ||
|
||
public void getKeys(Utilities.Callback2<String[], String> callback) { | ||
invokeWebViewCustomMethod("getStorageKeys", "{}", (res, error) -> { | ||
if (error == null) { | ||
String[] keys = gson.fromJson(res, String[].class); | ||
callback.run(keys, null); | ||
} else { | ||
callback.run(null, error); | ||
} | ||
}); | ||
} | ||
} |
75 changes: 75 additions & 0 deletions
75
TMessagesProj/src/main/java/tw/nekomimi/nekogram/helpers/UserHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package tw.nekomimi.nekogram.helpers; | ||
|
||
import android.app.Activity; | ||
import android.os.Bundle; | ||
import android.text.TextUtils; | ||
import android.util.SparseArray; | ||
|
||
import org.telegram.messenger.AndroidUtilities; | ||
import org.telegram.messenger.BaseController; | ||
import org.telegram.messenger.ChatObject; | ||
import org.telegram.messenger.LocaleController; | ||
import org.telegram.messenger.R; | ||
import org.telegram.messenger.UserConfig; | ||
import org.telegram.messenger.Utilities; | ||
import org.telegram.messenger.browser.Browser; | ||
import org.telegram.tgnet.ConnectionsManager; | ||
import org.telegram.tgnet.RequestDelegate; | ||
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.ProfileActivity; | ||
import org.telegram.ui.TopicsFragment; | ||
|
||
import java.util.HashMap; | ||
import java.util.Locale; | ||
|
||
public class UserHelper extends BaseController { | ||
|
||
private static final SparseArray<UserHelper> Instance = new SparseArray<>(); | ||
|
||
public UserHelper(int num) { | ||
super(num); | ||
} | ||
|
||
public static UserHelper getInstance(int num) { | ||
UserHelper localInstance = Instance.get(num); | ||
if (localInstance == null) { | ||
synchronized (UserHelper.class) { | ||
localInstance = Instance.get(num); | ||
if (localInstance == null) { | ||
Instance.put(num, localInstance = new UserHelper(num)); | ||
} | ||
} | ||
} | ||
return localInstance; | ||
} | ||
|
||
void resolveUser(String userName, long userId, Utilities.Callback<TLRPC.User> callback) { | ||
resolvePeer(userName, peer -> { | ||
if (peer instanceof TLRPC.TL_peerUser) { | ||
callback.run(peer.user_id == userId ? getMessagesController().getUser(userId) : null); | ||
} else { | ||
callback.run(null); | ||
} | ||
}); | ||
} | ||
|
||
private void resolvePeer(String userName, Utilities.Callback<TLRPC.Peer> callback) { | ||
TLRPC.TL_contacts_resolveUsername req = new TLRPC.TL_contacts_resolveUsername(); | ||
req.username = userName; | ||
getConnectionsManager().sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> { | ||
if (response != null) { | ||
TLRPC.TL_contacts_resolvedPeer res = (TLRPC.TL_contacts_resolvedPeer) response; | ||
getMessagesController().putUsers(res.users, false); | ||
getMessagesController().putChats(res.chats, false); | ||
getMessagesStorage().putUsersAndChats(res.users, res.chats, true, true); | ||
callback.run(res.peer); | ||
} else { | ||
callback.run(null); | ||
} | ||
})); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<vector android:height="72dp" | ||
android:viewportHeight="24" | ||
android:viewportWidth="24" | ||
android:width="72dp" | ||
xmlns:android="http://schemas.android.com/apk/res/android"> | ||
<path | ||
android:fillColor="@android:color/white" | ||
android:pathData="M19.35,10.04C18.67,6.59 15.64,4 12,4 9.11,4 6.6,5.64 5.35,8.04 2.34,8.36 0,10.91 0,14c0,3.31 2.69,6 6,6h13c2.76,0 5,-2.24 5,-5 0,-2.64 -2.05,-4.78 -4.65,-4.96zM19,18H6c-2.21,0 -4,-1.79 -4,-4s1.79,-4 4,-4h0.71C7.37,7.69 9.48,6 12,6c3.04,0 5.5,2.46 5.5,5.5v0.5H19c1.66,0 3,1.34 3,3s-1.34,3 -3,3z" /> | ||
</vector> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<vector xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:width="24dp" | ||
android:height="24dp" | ||
android:viewportWidth="24" | ||
android:viewportHeight="24"> | ||
<path | ||
android:fillColor="@android:color/white" | ||
android:pathData="M24,17.48c0,1.38 -1.12,2.5 -2.5,2.5L15,20c-1.66,0 -3,-1.34 -3,-3c0,-1.6 1.26,-2.9 2.84,-2.98C15.4,12.83 16.6,12 18,12c1.76,0 3.2,1.3 3.45,2.99c0.02,0 0.03,-0.01 0.05,-0.01C22.88,14.98 24,16.1 24,17.48zM10,15c0,-0.55 -0.45,-1 -1,-1s-1,0.45 -1,1v1.44c-1.22,-1.1 -2,-2.67 -2,-4.44c0,-2.38 1.39,-4.43 3.4,-5.4C9.77,6.42 10,6.04 10,5.63c0,-0.71 -0.73,-1.18 -1.37,-0.88C5.89,6.03 4,8.79 4,12c0,2.4 1.06,4.54 2.73,6H5c-0.55,0 -1,0.45 -1,1s0.45,1 1,1h4c0.55,0 1,-0.45 1,-1V15zM19,6c0.55,0 1,-0.45 1,-1s-0.45,-1 -1,-1h-4c-0.55,0 -1,0.45 -1,1v4c0,0.55 0.45,1 1,1s1,-0.45 1,-1V7.56c0.98,0.89 1.68,2.08 1.92,3.44l2.02,0c-0.25,-1.99 -1.23,-3.74 -2.66,-5H19z" /> | ||
</vector> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters