Search in sources :

Example 1 with RealmStoryViewInfo

use of net.iGap.realm.RealmStoryViewInfo in project iGap-Android by KianIranian-STDG.

the class MessageDataStorage method updateOwnViews.

public void updateOwnViews(List<ProtoStoryGetOwnStoryViews.GroupedViews> groupedViews) {
    CountDownLatch countdown = new CountDownLatch(1);
    storageQueue.postRunnable(() -> {
        try {
            database.executeTransaction(realm -> {
                int counter = 0;
                for (int i = 0; i < groupedViews.size(); i++) {
                    // for (int j = 0; j < groupedViews.get(i).getStoryViewsList().size(); j++) {
                    // if (groupedViews.get(i).getStoryViewsList().get(j).getUserId() != AccountManager.getInstance().getCurrentUser().getId()) {
                    // counter++;
                    // }
                    // }
                    RealmStoryProto realmStoryProto = realm.where(RealmStoryProto.class).equalTo("isForReply", false).equalTo("storyId", groupedViews.get(i).getStoryId()).findFirst();
                    if (realmStoryProto != null) {
                        // realmStoryProto.setViewCount(counter);
                        boolean isExist = false;
                        for (int j = 0; j < groupedViews.get(i).getStoryViewsList().size(); j++) {
                            RealmRegisteredInfo realmRegisteredInfo = database.where(RealmRegisteredInfo.class).equalTo("id", groupedViews.get(i).getStoryViewsList().get(j).getUserId()).findFirst();
                            RealmStoryViewInfo realmStoryViewInfo;
                            realmStoryViewInfo = realm.where(RealmStoryViewInfo.class).equalTo("id", groupedViews.get(i).getStoryId()).equalTo("userId", groupedViews.get(i).getStoryViewsList().get(j).getUserId()).findFirst();
                            if (realmStoryViewInfo == null) {
                                realmStoryViewInfo = realm.createObject(RealmStoryViewInfo.class);
                            } else {
                                isExist = true;
                            }
                            if (realmRegisteredInfo == null) {
                                realmStoryViewInfo.setDisplayName("");
                                new RequestUserInfo().userInfo(groupedViews.get(i).getStoryViewsList().get(j).getUserId());
                            } else {
                                realmStoryViewInfo.setDisplayName(realmRegisteredInfo.getDisplayName());
                                realmStoryViewInfo.setProfileColor(realmRegisteredInfo.getColor());
                            }
                            realmStoryViewInfo.setId(groupedViews.get(i).getStoryId());
                            realmStoryViewInfo.setUserId(groupedViews.get(i).getStoryViewsList().get(j).getUserId());
                            realmStoryViewInfo.setCreatedTime(groupedViews.get(i).getStoryViewsList().get(j).getViewedAt());
                            if (isExist) {
                                realmStoryProto.getRealmStoryViewInfos().remove(realmStoryViewInfo);
                            }
                            realmStoryProto.getRealmStoryViewInfos().add(realmStoryViewInfo);
                            isExist = false;
                        }
                    }
                    counter = 0;
                }
            });
            G.runOnUiThread(() -> getEventManager().postEvent(EventManager.STORY_VIEWS_FETCHED));
            countdown.countDown();
        } catch (Exception e) {
            FileLog.e(e);
        } finally {
            countdown.countDown();
        }
    });
    try {
        countdown.await();
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
}
Also used : RealmStoryProto(net.iGap.realm.RealmStoryProto) RequestUserInfo(net.iGap.request.RequestUserInfo) RealmStoryViewInfo(net.iGap.realm.RealmStoryViewInfo) CountDownLatch(java.util.concurrent.CountDownLatch) RealmRegisteredInfo(net.iGap.realm.RealmRegisteredInfo)

Example 2 with RealmStoryViewInfo

use of net.iGap.realm.RealmStoryViewInfo in project iGap-Android by KianIranian-STDG.

the class MessageDataStorage method storySetDisplayName.

public void storySetDisplayName(long userId, String displayName) {
    CountDownLatch countDownLatch = new CountDownLatch(1);
    storageQueue.postRunnable(() -> {
        try {
            database.executeTransaction(realm -> {
                RealmStory realmStory = realm.where(RealmStory.class).equalTo("sessionId", AccountManager.getInstance().getCurrentUser().getId()).equalTo("userId", userId).findFirst();
                RealmResults<RealmStoryViewInfo> realmStoryViewInfo = realm.where(RealmStoryViewInfo.class).equalTo("userId", userId).findAll();
                if (realmStoryViewInfo != null && realmStoryViewInfo.size() > 0) {
                    for (int i = 0; i < realmStoryViewInfo.size(); i++) {
                        realmStoryViewInfo.get(i).setDisplayName(displayName);
                    }
                }
                if (realmStory != null) {
                    realmStory.setDisplayName(displayName);
                    if (realmStory.getRealmStoryProtos() != null && realmStory.getRealmStoryProtos().size() > 0) {
                        for (int i = 0; i < realmStory.getRealmStoryProtos().size(); i++) {
                            if (realmStory.getRealmStoryProtos().get(i) != null && !realmStory.getRealmStoryProtos().get(i).isForRoom()) {
                                realmStory.getRealmStoryProtos().get(i).setDisplayName(displayName);
                            }
                        }
                    }
                    G.runOnUiThread(() -> EventManager.getInstance(AccountManager.selectedAccount).postEvent(EventManager.STORY_USER_INFO, userId));
                }
            });
            countDownLatch.countDown();
        } catch (Exception e) {
            FileLog.e(e);
        } finally {
            countDownLatch.countDown();
        }
    });
    try {
        countDownLatch.await();
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
}
Also used : RealmStory(net.iGap.realm.RealmStory) RealmStoryViewInfo(net.iGap.realm.RealmStoryViewInfo) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 3 with RealmStoryViewInfo

use of net.iGap.realm.RealmStoryViewInfo in project iGap-Android by KianIranian-STDG.

the class MessageDataStorage method userAddViewStory.

public void userAddViewStory(long storyId, int viewdAt, long viewdUserId, long storyOwnerUserId) {
    storageQueue.postRunnable(() -> {
        FileLog.i(TAG, "deleteUserStoryId " + storyId);
        try {
            database.beginTransaction();
            RealmRegisteredInfo realmRegisteredInfo = database.where(RealmRegisteredInfo.class).equalTo("id", viewdUserId).findFirst();
            RealmStoryProto realmStoryProto = database.where(RealmStoryProto.class).equalTo("sessionId", AccountManager.getInstance().getCurrentUser().getId()).equalTo("isForReply", false).equalTo("storyId", storyId).findFirst();
            if (realmStoryProto != null) {
                realmStoryProto.setSeen(true);
                realmStoryProto.setViewCount(realmStoryProto.getViewCount() + 1);
                boolean isExist = false;
                RealmStoryViewInfo realmStoryViewInfo;
                realmStoryViewInfo = database.where(RealmStoryViewInfo.class).equalTo("id", storyId).equalTo("userId", viewdUserId).findFirst();
                if (realmStoryViewInfo == null) {
                    realmStoryViewInfo = database.createObject(RealmStoryViewInfo.class);
                } else {
                    isExist = true;
                }
                if (realmRegisteredInfo == null) {
                    realmStoryViewInfo.setDisplayName("");
                    new RequestUserInfo().userInfo(viewdUserId);
                } else {
                    realmStoryViewInfo.setProfileColor(realmRegisteredInfo.getColor());
                    realmStoryViewInfo.setDisplayName(realmRegisteredInfo.getDisplayName());
                }
                realmStoryViewInfo.setId(storyId);
                realmStoryViewInfo.setUserId(viewdUserId);
                realmStoryViewInfo.setCreatedTime(viewdAt);
                if (isExist) {
                    realmStoryProto.getRealmStoryViewInfos().remove(realmStoryViewInfo);
                }
                realmStoryProto.getRealmStoryViewInfos().add(realmStoryViewInfo);
                isExist = false;
            }
            RealmStory realmStory = database.where(RealmStory.class).equalTo("sessionId", AccountManager.getInstance().getCurrentUser().getId()).equalTo("userId", storyOwnerUserId).findFirst();
            if (realmStory != null) {
                int counter = 0;
                for (int i = 0; i < realmStory.getRealmStoryProtos().size(); i++) {
                    if (realmStory.getRealmStoryProtos().get(i).isSeen()) {
                        counter++;
                    }
                }
                if (counter == realmStory.getRealmStoryProtos().size()) {
                    RealmStory userRealmStory = database.where(RealmStory.class).equalTo("sessionId", AccountManager.getInstance().getCurrentUser().getId()).equalTo("userId", storyOwnerUserId).findFirst();
                    if (userRealmStory != null) {
                        userRealmStory.setSeenAll(true);
                    }
                }
            }
            database.commitTransaction();
            G.runOnUiThread(() -> getEventManager().postEvent(EventManager.STORY_USER_ADD_VIEW));
        } catch (Exception e) {
            FileLog.e(e);
        }
    });
}
Also used : RealmStoryProto(net.iGap.realm.RealmStoryProto) RequestUserInfo(net.iGap.request.RequestUserInfo) RealmStory(net.iGap.realm.RealmStory) RealmStoryViewInfo(net.iGap.realm.RealmStoryViewInfo) RealmRegisteredInfo(net.iGap.realm.RealmRegisteredInfo)

Aggregations

RealmStoryViewInfo (net.iGap.realm.RealmStoryViewInfo)3 CountDownLatch (java.util.concurrent.CountDownLatch)2 RealmRegisteredInfo (net.iGap.realm.RealmRegisteredInfo)2 RealmStory (net.iGap.realm.RealmStory)2 RealmStoryProto (net.iGap.realm.RealmStoryProto)2 RequestUserInfo (net.iGap.request.RequestUserInfo)2