Search in sources :

Example 1 with Contact

use of im.actor.core.entity.Contact in project actor-platform by actorapp.

the class ContactsSyncActor method updateEngineList.

private void updateEngineList() {
    if (ENABLE_LOG) {
        Log.d(TAG, "Saving contact EngineList");
    }
    ArrayList<User> userList = new ArrayList<>();
    for (int u : contacts) {
        userList.add(getUser(u));
    }
    Collections.sort(userList, (lhs, rhs) -> lhs.getName().compareTo(rhs.getName()));
    List<Contact> registeredContacts = new ArrayList<>();
    int index = -1;
    for (User userModel : userList) {
        Contact contact = new Contact(userModel.getUid(), (long) index--, userModel.getAvatar(), userModel.getName());
        registeredContacts.add(contact);
    }
    context().getContactsModule().getContacts().replaceItems(registeredContacts);
    Integer[] sorted = new Integer[contacts.size()];
    int sindex = 0;
    for (User userModel : userList) {
        sorted[sindex++] = userModel.getUid();
    }
    context().getSearchModule().onContactsChanged(sorted);
    notifyState();
}
Also used : ApiUser(im.actor.core.api.ApiUser) User(im.actor.core.entity.User) ArrayList(java.util.ArrayList) Contact(im.actor.core.entity.Contact)

Example 2 with Contact

use of im.actor.core.entity.Contact in project actor-platform by actorapp.

the class JsBindingModule method onFileLoaded.

@Override
public void onFileLoaded(HashSet<Long> fileId) {
    if (dialogsList != null) {
        for (JsDisplayListBind<JsDialog, Dialog> b : dialogsList.getActiveBinds()) {
            b.startReconverting();
            for (Dialog dialog : b.getRawItems()) {
                if (checkAvatar(dialog.getDialogAvatar(), fileId)) {
                    b.forceReconvert(dialog.getEngineId());
                }
            }
            b.stopReconverting();
        }
    }
    if (dialogsGroupedList != null) {
        ArrayList<DialogGroup> groups = context().getMessagesModule().getDialogGroupsVM().getGroupsValueModel().get();
        if (groups != null) {
            outer: for (DialogGroup g : groups) {
                for (DialogSmall ds : g.getDialogs()) {
                    if (checkAvatar(ds.getAvatar(), fileId)) {
                        context().getMessagesModule().getDialogGroupsVM().getGroupsValueModel().forceNotify();
                        break outer;
                    }
                }
            }
        }
    }
    if (contactsList != null) {
        for (JsDisplayListBind<JsContact, Contact> b : contactsList.getActiveBinds()) {
            b.startReconverting();
            for (Contact contact : b.getRawItems()) {
                if (checkAvatar(contact.getAvatar(), fileId)) {
                    b.forceReconvert(contact.getEngineId());
                }
            }
            b.stopReconverting();
        }
    }
    for (JsDisplayList<JsMessage, Message> messageList : messageLists.values()) {
        for (JsDisplayListBind<JsMessage, Message> b : messageList.getActiveBinds()) {
            b.startReconverting();
            for (Message message : b.getRawItems()) {
                UserVM user = context().getUsersModule().getUsers().get(message.getSenderId());
                if (checkAvatar(user.getAvatar().get(), fileId)) {
                    b.forceReconvert(message.getEngineId());
                    continue;
                }
                if (message.getContent() instanceof DocumentContent) {
                    DocumentContent doc = (DocumentContent) message.getContent();
                    if (doc.getSource() instanceof FileRemoteSource) {
                        if (fileId.contains(((FileRemoteSource) doc.getSource()).getFileReference().getFileId())) {
                            b.forceReconvert(message.getEngineId());
                        }
                    }
                }
                if (message.getContent() instanceof StickerContent) {
                    StickerContent content = (StickerContent) message.getContent();
                    if (content.getImage512() != null) {
                        long stickerFileId = content.getImage512().getReference().getFileId();
                        if (fileId.contains(stickerFileId)) {
                            b.forceReconvert(message.getEngineId());
                        }
                    } else if (content.getImage256() != null) {
                        long stickerFileId = content.getImage256().getReference().getFileId();
                        if (fileId.contains(stickerFileId)) {
                            b.forceReconvert(message.getEngineId());
                        }
                    }
                }
            }
            b.stopReconverting();
        }
    }
    for (JsBindedValue<JsUser> u : users.values()) {
        int uid = u.get().getUid();
        UserVM userVM = context().getUsersModule().getUsers().get(uid);
        if (checkAvatar(userVM.getAvatar().get(), fileId)) {
            u.changeValue(JsUser.fromUserVM(userVM, messenger));
        }
    }
    for (JsBindedValue<JsGroup> g : groups.values()) {
        int gid = g.get().getGid();
        GroupVM groupVM = context().getGroupsModule().getGroupsCollection().get(gid);
        if (checkAvatar(groupVM.getAvatar().get(), fileId)) {
            g.changeValue(JsGroup.fromGroupVM(groupVM, messenger));
        }
    }
    // 
    if (stickers != null) {
        outer: for (StickerPack stickerPack : messenger.getAvailableStickersVM().getOwnStickerPacks().get()) {
            for (Sticker s : stickerPack.getStickers()) {
                if (s.getImage256() != null && fileId.contains(s.getImage256().getFileId())) {
                    messenger.getAvailableStickersVM().getOwnStickerPacks().forceNotify();
                    break outer;
                }
            }
        }
    }
}
Also used : JsMessage(im.actor.core.js.entity.JsMessage) Message(im.actor.core.entity.Message) StickerPack(im.actor.core.entity.StickerPack) JsMessage(im.actor.core.js.entity.JsMessage) Sticker(im.actor.core.entity.Sticker) JsSticker(im.actor.core.js.entity.JsSticker) JsDialog(im.actor.core.js.entity.JsDialog) JsDialog(im.actor.core.js.entity.JsDialog) Dialog(im.actor.core.entity.Dialog) JsUser(im.actor.core.js.entity.JsUser) DialogSmall(im.actor.core.viewmodel.DialogSmall) StickerContent(im.actor.core.entity.content.StickerContent) GroupVM(im.actor.core.viewmodel.GroupVM) JsContact(im.actor.core.js.entity.JsContact) JsContact(im.actor.core.js.entity.JsContact) Contact(im.actor.core.entity.Contact) UserVM(im.actor.core.viewmodel.UserVM) FileRemoteSource(im.actor.core.entity.content.FileRemoteSource) DocumentContent(im.actor.core.entity.content.DocumentContent) JsDialogGroup(im.actor.core.js.entity.JsDialogGroup) DialogGroup(im.actor.core.viewmodel.DialogGroup) JsGroup(im.actor.core.js.entity.JsGroup)

Aggregations

Contact (im.actor.core.entity.Contact)2 ApiUser (im.actor.core.api.ApiUser)1 Dialog (im.actor.core.entity.Dialog)1 Message (im.actor.core.entity.Message)1 Sticker (im.actor.core.entity.Sticker)1 StickerPack (im.actor.core.entity.StickerPack)1 User (im.actor.core.entity.User)1 DocumentContent (im.actor.core.entity.content.DocumentContent)1 FileRemoteSource (im.actor.core.entity.content.FileRemoteSource)1 StickerContent (im.actor.core.entity.content.StickerContent)1 JsContact (im.actor.core.js.entity.JsContact)1 JsDialog (im.actor.core.js.entity.JsDialog)1 JsDialogGroup (im.actor.core.js.entity.JsDialogGroup)1 JsGroup (im.actor.core.js.entity.JsGroup)1 JsMessage (im.actor.core.js.entity.JsMessage)1 JsSticker (im.actor.core.js.entity.JsSticker)1 JsUser (im.actor.core.js.entity.JsUser)1 DialogGroup (im.actor.core.viewmodel.DialogGroup)1 DialogSmall (im.actor.core.viewmodel.DialogSmall)1 GroupVM (im.actor.core.viewmodel.GroupVM)1