Search in sources :

Example 11 with Verified

use of im.actor.runtime.annotations.Verified in project actor-platform by actorapp.

the class DialogsActor method onUserChanged.

@Verified
private Promise<Void> onUserChanged(User user) {
    Dialog dialog = dialogs.getValue(user.peer().getUnuqueId());
    if (dialog != null) {
        // Ignore if nothing changed
        if (dialog.getDialogTitle().equals(user.getName()) && equalsE(dialog.getDialogAvatar(), user.getAvatar())) {
            return Promise.success(null);
        }
        // Update dialog peer info
        Dialog updated = dialog.editPeerInfo(user.getName(), user.getAvatar());
        addOrUpdateItem(updated);
        updateSearch(updated);
    }
    return Promise.success(null);
}
Also used : Dialog(im.actor.core.entity.Dialog) Verified(im.actor.runtime.annotations.Verified)

Example 12 with Verified

use of im.actor.runtime.annotations.Verified in project actor-platform by actorapp.

the class DialogsActor method onHistoryLoaded.

@Verified
private Promise<Void> onHistoryLoaded(List<DialogHistory> history) {
    ArrayList<Dialog> updated = new ArrayList<Dialog>();
    for (DialogHistory dialogHistory : history) {
        // Ignore already available dialogs
        if (dialogs.getValue(dialogHistory.getPeer().getUnuqueId()) != null) {
            continue;
        }
        PeerDesc peerDesc = buildPeerDesc(dialogHistory.getPeer());
        if (peerDesc == null) {
            continue;
        }
        ContentDescription description = ContentDescription.fromContent(dialogHistory.getContent());
        DialogBuilder builder = new DialogBuilder().setPeer(dialogHistory.getPeer()).setDialogTitle(peerDesc.getTitle()).setDialogAvatar(peerDesc.getAvatar()).setSortKey(dialogHistory.getSortDate()).setRid(dialogHistory.getRid()).setTime(dialogHistory.getDate()).setMessageType(description.getContentType()).setText(description.getText()).setSenderId(dialogHistory.getSenderId()).setRelatedUid(description.getRelatedUser()).setUnreadCount(dialogHistory.getUnreadCount());
        if (dialogHistory.isRead()) {
            builder.updateKnownReadDate(dialogHistory.getDate());
            builder.updateKnownReceiveDate(dialogHistory.getDate());
        } else if (dialogHistory.isReceived()) {
            builder.updateKnownReceiveDate(dialogHistory.getDate());
        }
        updated.add(builder.createDialog());
    }
    addOrUpdateItems(updated);
    updateSearch(updated);
    notifyState(true);
    return Promise.success(null);
}
Also used : Dialog(im.actor.core.entity.Dialog) DialogHistory(im.actor.core.modules.messaging.history.entity.DialogHistory) ArrayList(java.util.ArrayList) ContentDescription(im.actor.core.entity.ContentDescription) DialogBuilder(im.actor.core.entity.DialogBuilder) Verified(im.actor.runtime.annotations.Verified)

Example 13 with Verified

use of im.actor.runtime.annotations.Verified in project actor-platform by actorapp.

the class DialogsActor method onMessage.

@Verified
private Promise<Void> onMessage(Peer peer, Message message, boolean forceWrite, int counter) {
    long start = im.actor.runtime.Runtime.getCurrentTime();
    PeerDesc peerDesc = buildPeerDesc(peer);
    if (peerDesc == null) {
        Log.d("DialogsActor", "unknown peer desc");
        return Promise.success(null);
    }
    if (message == null) {
        // Ignore empty message if not forcing write
        if (!forceWrite) {
            Log.d("DialogsActor", "not force");
            return Promise.success(null);
        }
        // Else perform chat clear
        onChatClear(peer);
    } else {
        Dialog dialog = dialogs.getValue(peer.getUnuqueId());
        ContentDescription contentDescription = ContentDescription.fromContent(message.getContent());
        DialogBuilder builder = new DialogBuilder().setRid(message.getRid()).setTime(message.getDate()).setMessageType(contentDescription.getContentType()).setText(contentDescription.getText()).setRelatedUid(contentDescription.getRelatedUser()).setSenderId(message.getSenderId()).setDialogTitle(peerDesc.getTitle()).setDialogAvatar(peerDesc.getAvatar()).setIsBot(peerDesc.isBot()).setIsChannel(peerDesc.isChannel());
        if (counter >= 0) {
            builder.setUnreadCount(counter);
        }
        boolean forceUpdate = false;
        boolean needUpdateSearch = false;
        if (dialog != null) {
            // Ignore old messages if no force
            if (!forceWrite && dialog.getSortDate() > message.getSortDate()) {
                Log.d("DialogsActor", "too old");
                return Promise.success(null);
            }
            builder.setPeer(dialog.getPeer()).setSortKey(dialog.getSortDate()).updateKnownReceiveDate(dialog.getKnownReceiveDate()).updateKnownReadDate(dialog.getKnownReadDate());
            // Do not push up dialogs for silent messages
            if (!contentDescription.isSilent()) {
                builder.setSortKey(message.getSortDate());
            }
        } else {
            // Do not create dialogs for silent messages
            if (contentDescription.isSilent()) {
                Log.d("DialogsActor", "is silent in");
                return Promise.success(null);
            }
            builder.setPeer(peer).setSortKey(message.getSortDate());
            needUpdateSearch = true;
            forceUpdate = true;
        }
        Dialog dialog1 = builder.createDialog();
        addOrUpdateItem(dialog1);
        if (needUpdateSearch) {
            updateSearch(dialog1);
        }
        notifyState(forceUpdate);
    }
    return Promise.success(null);
}
Also used : Dialog(im.actor.core.entity.Dialog) ContentDescription(im.actor.core.entity.ContentDescription) DialogBuilder(im.actor.core.entity.DialogBuilder) Verified(im.actor.runtime.annotations.Verified)

Example 14 with Verified

use of im.actor.runtime.annotations.Verified in project actor-platform by actorapp.

the class UserRouter method onLoadFullUser.

//
// Users changed
//
@Verified
private void onLoadFullUser(int uid) {
    if (requestedFullUsers.contains(uid)) {
        return;
    }
    requestedFullUsers.add(uid);
    freeze();
    users().getValueAsync(uid).flatMap((Function<User, Promise<Tuple2<ResponseLoadFullUsers, User>>>) u -> {
        if (!u.isHaveExtension()) {
            ArrayList<ApiUserOutPeer> users = new ArrayList<>();
            users.add(new ApiUserOutPeer(u.getUid(), u.getAccessHash()));
            return api(new RequestLoadFullUsers(users)).map(responseLoadFullUsers -> new Tuple2<>(responseLoadFullUsers, u));
        } else {
            if (!getUserVM(uid).isInPhoneBook().get()) {
                return checkIsInPhoneBook(u).flatMap(new Function<Void, Promise<Tuple2<ResponseLoadFullUsers, User>>>() {

                    @Override
                    public Promise<Tuple2<ResponseLoadFullUsers, User>> apply(Void aVoid) {
                        return Promise.failure(new RuntimeException("Already loaded"));
                    }
                });
            } else {
                return Promise.failure(new RuntimeException("Already loaded"));
            }
        }
    }).then(r -> {
        User upd = r.getT2().updateExt(r.getT1().getFullUsers().get(0));
        users().addOrUpdateItem(upd);
    }).chain(r -> checkIsInPhoneBook(r.getT2().updateExt(r.getT1().getFullUsers().get(0)))).after((r, e) -> unfreeze());
}
Also used : ModuleContext(im.actor.core.modules.ModuleContext) ContactRecord(im.actor.core.entity.ContactRecord) PhoneBookContact(im.actor.core.entity.PhoneBookContact) ApiUser(im.actor.core.api.ApiUser) UpdateUserContactsChanged(im.actor.core.api.updates.UpdateUserContactsChanged) ApiMapValue(im.actor.core.api.ApiMapValue) ApiBotCommand(im.actor.core.api.ApiBotCommand) PhoneBookEmail(im.actor.core.entity.PhoneBookEmail) PromisesArray(im.actor.runtime.promise.PromisesArray) RouterLoadFullUser(im.actor.core.modules.users.router.entity.RouterLoadFullUser) UpdateContactRegistered(im.actor.core.api.updates.UpdateContactRegistered) UpdateUserNameChanged(im.actor.core.api.updates.UpdateUserNameChanged) ContactRecordType(im.actor.core.entity.ContactRecordType) Tuple2(im.actor.runtime.function.Tuple2) UpdateUserBlocked(im.actor.core.api.updates.UpdateUserBlocked) Void(im.actor.runtime.actors.messages.Void) Verified(im.actor.runtime.annotations.Verified) UserPhone(im.actor.core.viewmodel.UserPhone) ResponseLoadFullUsers(im.actor.core.api.rpc.ResponseLoadFullUsers) UpdateUserAvatarChanged(im.actor.core.api.updates.UpdateUserAvatarChanged) List(java.util.List) UpdateUserAboutChanged(im.actor.core.api.updates.UpdateUserAboutChanged) ModuleActor(im.actor.core.modules.ModuleActor) ArrayListUserPhone(im.actor.core.viewmodel.generics.ArrayListUserPhone) UpdateUserFullExtChanged(im.actor.core.api.updates.UpdateUserFullExtChanged) UserEmail(im.actor.core.viewmodel.UserEmail) Peer(im.actor.core.entity.Peer) UpdateUserExtChanged(im.actor.core.api.updates.UpdateUserExtChanged) MessageState(im.actor.core.entity.MessageState) Message(im.actor.core.entity.Message) ApiUserOutPeer(im.actor.core.api.ApiUserOutPeer) ApiAvatar(im.actor.core.api.ApiAvatar) ApiContactRecord(im.actor.core.api.ApiContactRecord) UpdateUserTimeZoneChanged(im.actor.core.api.updates.UpdateUserTimeZoneChanged) Function(im.actor.runtime.function.Function) ServiceUserRegistered(im.actor.core.entity.content.ServiceUserRegistered) PhoneBookProvider(im.actor.core.providers.PhoneBookProvider) Promise(im.actor.runtime.promise.Promise) UpdateUserBotCommandsChanged(im.actor.core.api.updates.UpdateUserBotCommandsChanged) UpdateUserNickChanged(im.actor.core.api.updates.UpdateUserNickChanged) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) User(im.actor.core.entity.User) UpdateUserLocalNameChanged(im.actor.core.api.updates.UpdateUserLocalNameChanged) ArrayListUserEmail(im.actor.core.viewmodel.generics.ArrayListUserEmail) JavaUtil.equalsE(im.actor.core.util.JavaUtil.equalsE) UpdateUserUnblocked(im.actor.core.api.updates.UpdateUserUnblocked) RequestLoadFullUsers(im.actor.core.api.rpc.RequestLoadFullUsers) ContactsSyncActor(im.actor.core.modules.contacts.ContactsSyncActor) UserVM(im.actor.core.viewmodel.UserVM) RouterFetchMissingUsers(im.actor.core.modules.users.router.entity.RouterFetchMissingUsers) BookImportStorage(im.actor.core.modules.contacts.entity.BookImportStorage) RouterApplyUsers(im.actor.core.modules.users.router.entity.RouterApplyUsers) UpdateUserPreferredLanguagesChanged(im.actor.core.api.updates.UpdateUserPreferredLanguagesChanged) Log(im.actor.runtime.Log) PhoneBookPhone(im.actor.core.entity.PhoneBookPhone) Update(im.actor.core.network.parser.Update) RouterUserUpdate(im.actor.core.modules.users.router.entity.RouterUserUpdate) RequestLoadFullUsers(im.actor.core.api.rpc.RequestLoadFullUsers) ApiUser(im.actor.core.api.ApiUser) RouterLoadFullUser(im.actor.core.modules.users.router.entity.RouterLoadFullUser) User(im.actor.core.entity.User) ApiUserOutPeer(im.actor.core.api.ApiUserOutPeer) ArrayList(java.util.ArrayList) Function(im.actor.runtime.function.Function) Promise(im.actor.runtime.promise.Promise) Tuple2(im.actor.runtime.function.Tuple2) Void(im.actor.runtime.actors.messages.Void) ResponseLoadFullUsers(im.actor.core.api.rpc.ResponseLoadFullUsers) Verified(im.actor.runtime.annotations.Verified)

Aggregations

Verified (im.actor.runtime.annotations.Verified)14 Dialog (im.actor.core.entity.Dialog)5 UserVM (im.actor.core.viewmodel.UserVM)4 ContentDescription (im.actor.core.entity.ContentDescription)3 DialogBuilder (im.actor.core.entity.DialogBuilder)3 Message (im.actor.core.entity.Message)3 Peer (im.actor.core.entity.Peer)3 UserPresence (im.actor.core.viewmodel.UserPresence)3 ArrayList (java.util.ArrayList)3 ApiAvatar (im.actor.core.api.ApiAvatar)2 ApiBotCommand (im.actor.core.api.ApiBotCommand)2 ApiContactRecord (im.actor.core.api.ApiContactRecord)2 ApiMapValue (im.actor.core.api.ApiMapValue)2 ApiUser (im.actor.core.api.ApiUser)2 ApiUserOutPeer (im.actor.core.api.ApiUserOutPeer)2 RequestLoadFullUsers (im.actor.core.api.rpc.RequestLoadFullUsers)2 ResponseLoadFullUsers (im.actor.core.api.rpc.ResponseLoadFullUsers)2 UpdateContactRegistered (im.actor.core.api.updates.UpdateContactRegistered)2 UpdateUserAboutChanged (im.actor.core.api.updates.UpdateUserAboutChanged)2 UpdateUserAvatarChanged (im.actor.core.api.updates.UpdateUserAvatarChanged)2