Search in sources :

Example 1 with RequestClientGetRoom

use of net.iGap.request.RequestClientGetRoom in project iGap-Android by KianIranian-STDG.

the class FragmentNewGroupViewModel method getRoom.

private void getRoom(final long roomId, final ProtoGlobal.Room.Type typeCreate, boolean isGroup) {
    G.onClientGetRoomResponse = new OnClientGetRoomResponse() {

        @Override
        public void onClientGetRoomResponse(final ProtoGlobal.Room room, ProtoClientGetRoom.ClientGetRoomResponse.Builder builder, RequestClientGetRoom.IdentityClientGetRoom identity) {
            if (identity.createRoomMode != RequestClientGetRoom.CreateRoomMode.requestFromOwner) {
                return;
            }
            try {
                G.handler.post(new Runnable() {

                    @Override
                    public void run() {
                        if (existAvatar) {
                            showProgressBar();
                            if (room.getType() == ProtoGlobal.Room.Type.GROUP) {
                                new RequestGroupAvatarAdd().groupAvatarAdd(roomId, token);
                            } else {
                                new RequestChannelAvatarAdd().channelAvatarAdd(roomId, token);
                            }
                        } else {
                            hideProgressBar();
                            if (isGroup) {
                                createdRoomId.postValue(roomId);
                            } else {
                                goToContactGroupPage.setValue(new ContactGroupFragmentModel(roomId, room.getGroupRoomExtra().getParticipantsCountLimitLabel(), typeCreate.toString(), true));
                            }
                        }
                    }
                });
            } catch (IllegalStateException e) {
                e.printStackTrace();
            }
        }

        @Override
        public void onError(int majorCode, int minorCode) {
            hideProgressBar();
        }

        @Override
        public void onTimeOut() {
            hideProgressBar();
        }
    };
    new RequestClientGetRoom().clientGetRoom(roomId, RequestClientGetRoom.CreateRoomMode.requestFromOwner);
}
Also used : RequestChannelAvatarAdd(net.iGap.request.RequestChannelAvatarAdd) ProtoGlobal(net.iGap.proto.ProtoGlobal) OnClientGetRoomResponse(net.iGap.observers.interfaces.OnClientGetRoomResponse) RequestClientGetRoom(net.iGap.request.RequestClientGetRoom) OnClientGetRoomResponse(net.iGap.observers.interfaces.OnClientGetRoomResponse) RequestGroupAvatarAdd(net.iGap.request.RequestGroupAvatarAdd)

Example 2 with RequestClientGetRoom

use of net.iGap.request.RequestClientGetRoom in project iGap-Android by KianIranian-STDG.

the class FragmentNewGroupViewModel method getChannelRoom.

private void getChannelRoom(final long roomId) {
    G.onClientGetRoomResponse = new OnClientGetRoomResponse() {

        @Override
        public void onClientGetRoomResponse(final ProtoGlobal.Room room, ProtoClientGetRoom.ClientGetRoomResponse.Builder builder, RequestClientGetRoom.IdentityClientGetRoom identity) {
            if (identity.createRoomMode != RequestClientGetRoom.CreateRoomMode.requestFromOwner) {
                return;
            }
            G.onClientGetRoomResponse = null;
            G.handler.post(new Runnable() {

                @Override
                public void run() {
                    mInviteLink = room.getChannelRoomExtra().getPrivateExtra().getInviteLink();
                    if (existAvatar) {
                        MessageController.getInstance(currentAccount).saveChannelAvatar(imagePath, room.getId());
                    } else {
                        hideProgressBar();
                        goToCreateChannelPage.setValue(new CreateChannelModel(room.getId(), mInviteLink, token));
                    }
                }
            });
        }

        @Override
        public void onError(int majorCode, int minorCode) {
            G.onClientGetRoomResponse = null;
        }

        @Override
        public void onTimeOut() {
            G.onClientGetRoomResponse = null;
        }
    };
    new RequestClientGetRoom().clientGetRoom(roomId, RequestClientGetRoom.CreateRoomMode.requestFromOwner);
}
Also used : RequestClientGetRoom(net.iGap.request.RequestClientGetRoom) OnClientGetRoomResponse(net.iGap.observers.interfaces.OnClientGetRoomResponse) ProtoGlobal(net.iGap.proto.ProtoGlobal) OnClientGetRoomResponse(net.iGap.observers.interfaces.OnClientGetRoomResponse)

Example 3 with RequestClientGetRoom

use of net.iGap.request.RequestClientGetRoom in project iGap-Android by KianIranian-STDG.

the class MessageDataStorage method updateRoomAddedStory.

public void updateRoomAddedStory(final List<ProtoGlobal.Story> stories) {
    storageQueue.postRunnable(() -> {
        FileLog.i(TAG, "updateRoomAddedStory roomId " + stories.get(0).getRoomId() + " storiesId " + stories.get(0).getId());
        try {
            database.beginTransaction();
            RealmRoom realmRoom = database.where(RealmRoom.class).equalTo("id", stories.get(0).getRoomId()).findFirst();
            if (realmRoom != null && realmRoom.getTitle() != null) {
                RealmStory realmStory;
                if (stories.get(0).getUserId() == AccountManager.getInstance().getCurrentUser().getId()) {
                    realmStory = database.where(RealmStory.class).equalTo("sessionId", AccountManager.getInstance().getCurrentUser().getId()).equalTo("userId", stories.get(0).getUserId()).findFirst();
                } else {
                    realmStory = database.where(RealmStory.class).equalTo("sessionId", AccountManager.getInstance().getCurrentUser().getId()).equalTo("roomId", stories.get(0).getRoomId()).findFirst();
                }
                if (realmStory == null) {
                    realmStory = database.createObject(RealmStory.class, SUID.id().get());
                }
                List<StoryObject> storyObjects = new ArrayList<>();
                for (int i = 0; i < stories.size(); i++) {
                    if (stories.get(i).getTypeValue() == 0) {
                        StoryObject storyObject = StoryObject.create(stories.get(i), i, realmRoom.getTitle(), realmRoom != null ? realmRoom.getColor() : "#4aca69", true, realmRoom.getType() == ProtoGlobal.Room.Type.CHANNEL && realmRoom.getChannelRoom().isVerified());
                        storyObjects.add(storyObject);
                    }
                }
                realmStory.setLastCreatedAt(storyObjects.get(storyObjects.size() - 1).createdAt);
                realmStory.setDisplayName(realmRoom.getTitle());
                realmStory.setProfileColor(realmRoom.getColor());
                realmStory.setSessionId(AccountManager.getInstance().getCurrentUser().getId());
                if (stories.get(0).getUserId() != AccountManager.getInstance().getCurrentUser().getId()) {
                    realmStory.setUserId(0);
                    realmStory.setOrginatorValue(1);
                    realmStory.setVerified(realmRoom.getType() == ProtoGlobal.Room.Type.CHANNEL && realmRoom.getChannelRoom().isVerified());
                } else {
                    realmStory.setUserId(AccountManager.getInstance().getCurrentUser().getId());
                }
                realmStory.setRoomId(stories.get(0).getRoomId());
                realmStory.setSeenAll(false);
                realmStory.setRealmStoryProtos(database, storyObjects);
                int[] storyUnReadCount = new int[1];
                RealmResults<RealmStory> otherStories = database.where(RealmStory.class).equalTo("sessionId", AccountManager.getInstance().getCurrentUser().getId()).notEqualTo("userId", AccountManager.getInstance().getCurrentUser().getId()).equalTo("isSeenAll", false).findAll();
                if (otherStories != null && otherStories.size() > 0) {
                    storyUnReadCount[0] = otherStories.size();
                } else {
                    storyUnReadCount[0] = 0;
                }
                database.commitTransaction();
                G.runOnUiThread(() -> {
                    if (G.onUnreadChange != null) {
                        G.onUnreadChange.onChange(storyUnReadCount[0], true);
                    }
                    getEventManager().postEvent(EventManager.STORY_USER_ADD_NEW);
                });
            } else {
                new RequestClientGetRoom().clientGetRoom(stories.get(0).getRoomId(), RequestClientGetRoom.CreateRoomMode.justInfo);
            }
        } catch (Exception e) {
            FileLog.e(e);
        }
    });
}
Also used : MainStoryObject(net.iGap.story.MainStoryObject) StoryObject(net.iGap.story.StoryObject) RequestClientGetRoom(net.iGap.request.RequestClientGetRoom) RealmStory(net.iGap.realm.RealmStory) ArrayList(java.util.ArrayList) RealmRoom(net.iGap.realm.RealmRoom)

Example 4 with RequestClientGetRoom

use of net.iGap.request.RequestClientGetRoom in project iGap-Android by KianIranian-STDG.

the class HelperUrl method joinToRoom.

private static void joinToRoom(FragmentActivity activity, String token, final ProtoGlobal.Room room) {
    if (RequestManager.getInstance(AccountManager.selectedAccount).isUserLogin()) {
        showIndeterminateProgressDialog(activity);
        G.onClientJoinByInviteLink = new OnClientJoinByInviteLink() {

            @Override
            public void onClientJoinByInviteLinkResponse(long roomId) {
                closeDialogWaiting();
                new RequestClientGetRoom().clientGetRoom(roomId, RequestClientGetRoom.CreateRoomMode.requestFromOwner);
                if (roomId != FragmentChat.lastChatRoomId) {
                    new GoToChatActivity(roomId).startActivity(activity);
                }
                G.onClientJoinByInviteLink = null;
            }

            @Override
            public void onError(int majorCode, int minorCode) {
                closeDialogWaiting();
                G.onClientJoinByInviteLink = null;
            }
        };
        new RequestClientJoinByInviteLink().clientJoinByInviteLink(token);
    } else {
        closeDialogWaiting();
        HelperError.showSnackMessage(G.context.getString(R.string.there_is_no_connection_to_server), false);
    }
}
Also used : RequestClientJoinByInviteLink(net.iGap.request.RequestClientJoinByInviteLink) RequestClientGetRoom(net.iGap.request.RequestClientGetRoom) TextPaint(android.text.TextPaint) OnClientJoinByInviteLink(net.iGap.observers.interfaces.OnClientJoinByInviteLink)

Example 5 with RequestClientGetRoom

use of net.iGap.request.RequestClientGetRoom in project iGap-Android by KianIranian-STDG.

the class HelperUrl method goToActivityFromFCM.

public static void goToActivityFromFCM(FragmentActivity activity, final long roomId, final long peerId) {
    if (roomId != FragmentChat.lastChatRoomId) {
        DbManager.getInstance().doRealmTask(realm -> {
            RealmRoom realmRoom = realm.where(RealmRoom.class).equalTo("id", roomId).findFirst();
            if (realmRoom != null) {
                // room with given roomID exists.
                new GoToChatActivity(realmRoom.getId()).startActivity(activity);
            } else if (peerId > 0) {
                realmRoom = realm.where(RealmRoom.class).equalTo("chatRoom.peer_id", peerId).findFirst();
                if (realmRoom != null) {
                    new GoToChatActivity(realmRoom.getId()).startActivity(activity);
                } else {
                    G.onChatGetRoom = new OnChatGetRoom() {

                        @Override
                        public void onChatGetRoom(final ProtoGlobal.Room room) {
                            DbManager.getInstance().doRealmTask(new DbManager.RealmTask() {

                                @Override
                                public void doTask(Realm realm1) {
                                    realm1.executeTransaction(new Realm.Transaction() {

                                        @Override
                                        public void execute(Realm realm) {
                                            if (realm.where(RealmRoom.class).equalTo("id", room.getId()).findFirst() == null) {
                                                RealmRoom realmRoom1 = RealmRoom.putOrUpdate(room, realm);
                                                realmRoom1.setDeleted(true);
                                            } else {
                                                RealmRoom.putOrUpdate(room, realm);
                                            }
                                        }
                                    });
                                }
                            });
                            G.handler.postDelayed(new Runnable() {

                                @Override
                                public void run() {
                                    new GoToChatActivity(room.getId()).setPeerID(peerId).startActivity(activity);
                                    G.onChatGetRoom = null;
                                }
                            }, 500);
                        }

                        @Override
                        public void onChatGetRoomTimeOut() {
                        }

                        @Override
                        public void onChatGetRoomError(int majorCode, int minorCode) {
                        }
                    };
                    new RequestChatGetRoom().chatGetRoom(peerId);
                }
            } else {
                G.onClientGetRoomResponse = new OnClientGetRoomResponse() {

                    @Override
                    public void onClientGetRoomResponse(ProtoGlobal.Room room, ProtoClientGetRoom.ClientGetRoomResponse.Builder builder, RequestClientGetRoom.IdentityClientGetRoom identity) {
                        G.onClientGetRoomResponse = null;
                        G.handler.postDelayed(() -> {
                            new GoToChatActivity(room.getId()).setPeerID(peerId).startActivity(activity);
                            G.onChatGetRoom = null;
                        }, 500);
                    }

                    @Override
                    public void onError(int majorCode, int minorCode) {
                    }

                    @Override
                    public void onTimeOut() {
                    }
                };
                new RequestClientGetRoom().clientGetRoom(roomId, null);
                Toast.makeText(activity, "Please Wait...", Toast.LENGTH_SHORT).show();
            }
        });
    }
}
Also used : RequestChatGetRoom(net.iGap.request.RequestChatGetRoom) SpannableStringBuilder(android.text.SpannableStringBuilder) DbManager(net.iGap.module.accountManager.DbManager) OnChatGetRoom(net.iGap.observers.interfaces.OnChatGetRoom) RequestClientGetRoom(net.iGap.request.RequestClientGetRoom) OnClientGetRoomResponse(net.iGap.observers.interfaces.OnClientGetRoomResponse) RealmRoom(net.iGap.realm.RealmRoom) ProtoClientGetRoom(net.iGap.proto.ProtoClientGetRoom) RequestClientGetRoom(net.iGap.request.RequestClientGetRoom) RealmRoom(net.iGap.realm.RealmRoom) OnChatGetRoom(net.iGap.observers.interfaces.OnChatGetRoom) RequestChatGetRoom(net.iGap.request.RequestChatGetRoom) ProtoClientGetRoom(net.iGap.proto.ProtoClientGetRoom) Realm(io.realm.Realm)

Aggregations

RequestClientGetRoom (net.iGap.request.RequestClientGetRoom)13 RealmRoom (net.iGap.realm.RealmRoom)7 OnClientGetRoomResponse (net.iGap.observers.interfaces.OnClientGetRoomResponse)4 ProtoGlobal (net.iGap.proto.ProtoGlobal)4 ArrayList (java.util.ArrayList)3 Realm (io.realm.Realm)2 RealmResults (io.realm.RealmResults)2 DbManager (net.iGap.module.accountManager.DbManager)2 OnChatGetRoom (net.iGap.observers.interfaces.OnChatGetRoom)2 RealmRoomMessage (net.iGap.realm.RealmRoomMessage)2 RequestChatGetRoom (net.iGap.request.RequestChatGetRoom)2 Activity (android.app.Activity)1 Context (android.content.Context)1 SharedPreferences (android.content.SharedPreferences)1 Color (android.graphics.Color)1 SpannableStringBuilder (android.text.SpannableStringBuilder)1 TextPaint (android.text.TextPaint)1 Gravity (android.view.Gravity)1 View (android.view.View)1 ViewGroup (android.view.ViewGroup)1