Java Code Examples for org.telegram.tgnet.TLRPC#TL_contacts_getStatuses

The following examples show how to use org.telegram.tgnet.TLRPC#TL_contacts_getStatuses . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ContactsController.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
public void reloadContactsStatuses() {
    saveContactsLoadTime();
    MessagesController.getInstance(currentAccount).clearFullUsers();
    SharedPreferences preferences = MessagesController.getMainSettings(currentAccount);
    final SharedPreferences.Editor editor = preferences.edit();
    editor.putBoolean("needGetStatuses", true).commit();
    TLRPC.TL_contacts_getStatuses req = new TLRPC.TL_contacts_getStatuses();
    ConnectionsManager.getInstance(currentAccount).sendRequest(req, new RequestDelegate() {
        @Override
        public void run(final TLObject response, TLRPC.TL_error error) {
            if (error == null) {
                AndroidUtilities.runOnUIThread(new Runnable() {
                    @Override
                    public void run() {
                        editor.remove("needGetStatuses").commit();
                        TLRPC.Vector vector = (TLRPC.Vector) response;
                        if (!vector.objects.isEmpty()) {
                            ArrayList<TLRPC.User> dbUsersStatus = new ArrayList<>();
                            for (Object object : vector.objects) {
                                TLRPC.User toDbUser = new TLRPC.TL_user();
                                TLRPC.TL_contactStatus status = (TLRPC.TL_contactStatus) object;

                                if (status == null) {
                                    continue;
                                }
                                if (status.status instanceof TLRPC.TL_userStatusRecently) {
                                    status.status.expires = -100;
                                } else if (status.status instanceof TLRPC.TL_userStatusLastWeek) {
                                    status.status.expires = -101;
                                } else if (status.status instanceof TLRPC.TL_userStatusLastMonth) {
                                    status.status.expires = -102;
                                }

                                TLRPC.User user = MessagesController.getInstance(currentAccount).getUser(status.user_id);
                                if (user != null) {
                                    user.status = status.status;
                                }
                                toDbUser.status = status.status;
                                dbUsersStatus.add(toDbUser);
                            }
                            MessagesStorage.getInstance(currentAccount).updateUsers(dbUsersStatus, true, true, true);
                        }
                        NotificationCenter.getInstance(currentAccount).postNotificationName(NotificationCenter.updateInterfaces, MessagesController.UPDATE_MASK_STATUS);
                    }
                });
            }
        }
    });
}
 
Example 2
Source File: ContactsController.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
public void reloadContactsStatuses() {
    saveContactsLoadTime();
    MessagesController.getInstance(currentAccount).clearFullUsers();
    SharedPreferences preferences = MessagesController.getMainSettings(currentAccount);
    final SharedPreferences.Editor editor = preferences.edit();
    editor.putBoolean("needGetStatuses", true).commit();
    TLRPC.TL_contacts_getStatuses req = new TLRPC.TL_contacts_getStatuses();
    ConnectionsManager.getInstance(currentAccount).sendRequest(req, new RequestDelegate() {
        @Override
        public void run(final TLObject response, TLRPC.TL_error error) {
            if (error == null) {
                AndroidUtilities.runOnUIThread(new Runnable() {
                    @Override
                    public void run() {
                        editor.remove("needGetStatuses").commit();
                        TLRPC.Vector vector = (TLRPC.Vector) response;
                        if (!vector.objects.isEmpty()) {
                            ArrayList<TLRPC.User> dbUsersStatus = new ArrayList<>();
                            for (Object object : vector.objects) {
                                TLRPC.User toDbUser = new TLRPC.TL_user();
                                TLRPC.TL_contactStatus status = (TLRPC.TL_contactStatus) object;

                                if (status == null) {
                                    continue;
                                }
                                if (status.status instanceof TLRPC.TL_userStatusRecently) {
                                    status.status.expires = -100;
                                } else if (status.status instanceof TLRPC.TL_userStatusLastWeek) {
                                    status.status.expires = -101;
                                } else if (status.status instanceof TLRPC.TL_userStatusLastMonth) {
                                    status.status.expires = -102;
                                }

                                TLRPC.User user = MessagesController.getInstance(currentAccount).getUser(status.user_id);
                                if (user != null) {
                                    user.status = status.status;
                                }
                                toDbUser.status = status.status;
                                dbUsersStatus.add(toDbUser);
                            }
                            MessagesStorage.getInstance(currentAccount).updateUsers(dbUsersStatus, true, true, true);
                        }
                        NotificationCenter.getInstance(currentAccount).postNotificationName(NotificationCenter.updateInterfaces, MessagesController.UPDATE_MASK_STATUS);
                    }
                });
            }
        }
    });
}
 
Example 3
Source File: ContactsController.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
private void reloadContactsStatuses() {
    saveContactsLoadTime();
    getMessagesController().clearFullUsers();
    SharedPreferences preferences = MessagesController.getMainSettings(currentAccount);
    final SharedPreferences.Editor editor = preferences.edit();
    editor.putBoolean("needGetStatuses", true).commit();
    TLRPC.TL_contacts_getStatuses req = new TLRPC.TL_contacts_getStatuses();
    getConnectionsManager().sendRequest(req, (response, error) -> {
        if (error == null) {
            AndroidUtilities.runOnUIThread(() -> {
                editor.remove("needGetStatuses").commit();
                TLRPC.Vector vector = (TLRPC.Vector) response;
                if (!vector.objects.isEmpty()) {
                    ArrayList<TLRPC.User> dbUsersStatus = new ArrayList<>();
                    for (Object object : vector.objects) {
                        TLRPC.User toDbUser = new TLRPC.TL_user();
                        TLRPC.TL_contactStatus status = (TLRPC.TL_contactStatus) object;

                        if (status == null) {
                            continue;
                        }
                        if (status.status instanceof TLRPC.TL_userStatusRecently) {
                            status.status.expires = -100;
                        } else if (status.status instanceof TLRPC.TL_userStatusLastWeek) {
                            status.status.expires = -101;
                        } else if (status.status instanceof TLRPC.TL_userStatusLastMonth) {
                            status.status.expires = -102;
                        }

                        TLRPC.User user = getMessagesController().getUser(status.user_id);
                        if (user != null) {
                            user.status = status.status;
                        }
                        toDbUser.status = status.status;
                        dbUsersStatus.add(toDbUser);
                    }
                    getMessagesStorage().updateUsers(dbUsersStatus, true, true, true);
                }
                getNotificationCenter().postNotificationName(NotificationCenter.updateInterfaces, MessagesController.UPDATE_MASK_STATUS);
            });
        }
    });
}
 
Example 4
Source File: ContactsController.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
private void reloadContactsStatuses() {
    saveContactsLoadTime();
    getMessagesController().clearFullUsers();
    SharedPreferences preferences = MessagesController.getMainSettings(currentAccount);
    final SharedPreferences.Editor editor = preferences.edit();
    editor.putBoolean("needGetStatuses", true).commit();
    TLRPC.TL_contacts_getStatuses req = new TLRPC.TL_contacts_getStatuses();
    getConnectionsManager().sendRequest(req, (response, error) -> {
        if (error == null) {
            AndroidUtilities.runOnUIThread(() -> {
                editor.remove("needGetStatuses").commit();
                TLRPC.Vector vector = (TLRPC.Vector) response;
                if (!vector.objects.isEmpty()) {
                    ArrayList<TLRPC.User> dbUsersStatus = new ArrayList<>();
                    for (Object object : vector.objects) {
                        TLRPC.User toDbUser = new TLRPC.TL_user();
                        TLRPC.TL_contactStatus status = (TLRPC.TL_contactStatus) object;

                        if (status == null) {
                            continue;
                        }
                        if (status.status instanceof TLRPC.TL_userStatusRecently) {
                            status.status.expires = -100;
                        } else if (status.status instanceof TLRPC.TL_userStatusLastWeek) {
                            status.status.expires = -101;
                        } else if (status.status instanceof TLRPC.TL_userStatusLastMonth) {
                            status.status.expires = -102;
                        }

                        TLRPC.User user = getMessagesController().getUser(status.user_id);
                        if (user != null) {
                            user.status = status.status;
                        }
                        toDbUser.status = status.status;
                        dbUsersStatus.add(toDbUser);
                    }
                    getMessagesStorage().updateUsers(dbUsersStatus, true, true, true);
                }
                getNotificationCenter().postNotificationName(NotificationCenter.updateInterfaces, MessagesController.UPDATE_MASK_STATUS);
            });
        }
    });
}