Search in sources :

Example 16 with RealmRoom

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

the class GoToChatActivity method startActivity.

public void startActivity(FragmentActivity activity) {
    String roomName = "";
    if (FragmentChat.mForwardMessages != null || HelperGetDataFromOtherApp.hasSharedData || FragmentChat.structIGSticker != null) {
        roomName = DbManager.getInstance().doRealmTask(realm -> {
            RealmRoom realmRoom = realm.where(RealmRoom.class).equalTo("id", roomid).findFirst();
            if (realmRoom != null) {
                if (realmRoom.getReadOnly() || hasSendMessagePermission() || (realmRoom.getType() != ProtoGlobal.Room.Type.CHAT && FragmentChat.structIGSticker != null) || (realmRoom.getType() == ProtoGlobal.Room.Type.CHAT && realmRoom.getChatRoom() != null && RealmRoom.isBot(realmRoom.getChatRoom().getPeerId()))) {
                    if (activity != null && !(activity).isFinishing()) {
                        new MaterialDialog.Builder(activity).title(R.string.dialog_readonly_chat).positiveText(R.string.ok).show();
                    }
                    return null;
                }
                return realmRoom.getTitle();
            } else if (peerID > 0) {
                RealmRegisteredInfo _RegisteredInfo = RealmRegisteredInfo.getRegistrationInfo(realm, peerID);
                if (_RegisteredInfo != null) {
                    return _RegisteredInfo.getDisplayName();
                }
            }
            return "";
        });
        if (roomName == null) {
            return;
        }
    }
    if (HelperGetDataFromOtherApp.hasSharedData) {
        String message = G.context.getString(R.string.send_message_to) + " " + roomName;
        MaterialDialog.Builder mDialog = new MaterialDialog.Builder(activity).title(message).positiveText(R.string.ok).negativeText(R.string.cancel).onPositive(new MaterialDialog.SingleButtonCallback() {

            @Override
            public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                FragmentChat fragmentChat = new FragmentChat();
                fragmentChat.setArguments(getBundle());
                fragmentChatBackStack(activity);
                new HelperFragment(activity.getSupportFragmentManager(), fragmentChat).setReplace(false).load();
            }
        }).onNegative((dialog, which) -> {
            HelperGetDataFromOtherApp.hasSharedData = false;
            // revert main rooms list from share mode
            if (activity instanceof ActivityMain) {
                ((ActivityMain) activity).checkHasSharedData(false);
            }
        }).neutralText(R.string.another_room).onNeutral((dialog, which) -> dialog.dismiss());
        if (!activity.isFinishing()) {
            mDialog.show();
        }
    } else if (FragmentChat.structIGSticker != null) {
        String message = G.context.getString(R.string.send_message_to) + " " + roomName;
        MaterialDialog.Builder mDialog = new MaterialDialog.Builder(activity).title(message).positiveText(R.string.ok).negativeText(R.string.cancel).onPositive((dialog, which) -> {
            FragmentChat fragmentChat = new FragmentChat();
            fragmentChat.setArguments(getBundle());
            fragmentChatBackStack(activity);
            new HelperFragment(activity.getSupportFragmentManager(), fragmentChat).setReplace(false).load();
        }).onNegative((dialog, which) -> {
            FragmentChat.structIGSticker = null;
            if (activity instanceof ActivityMain) {
                ((ActivityMain) activity).checkHasSharedData(false);
            }
        }).neutralText(R.string.another_room).onNeutral((dialog, which) -> dialog.dismiss());
        if (!activity.isFinishing()) {
            mDialog.show();
        }
    } else if (FragmentChat.mForwardMessages != null) {
        String message = G.context.getString(R.string.send_forward_to) + " " + roomName + "?";
        MaterialDialog.Builder mDialog = new MaterialDialog.Builder(activity).title(message).positiveText(R.string.ok).negativeText(R.string.cancel).onPositive(new MaterialDialog.SingleButtonCallback() {

            @Override
            public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                loadChatFragment(activity);
            }
        }).onNegative((dialog, which) -> {
            disableForwardMessage(activity);
            FragmentChat.mForwardMessages = null;
        }).neutralText(R.string.another_room).onNeutral((dialog, which) -> dialog.dismiss());
        if (!(activity).isFinishing()) {
            mDialog.show();
        }
    } else {
        loadChatFragment(activity);
    }
}
Also used : Bundle(android.os.Bundle) RealmRoomAccess(net.iGap.realm.RealmRoomAccess) ActivityMain(net.iGap.activities.ActivityMain) NonNull(androidx.annotation.NonNull) AccountManager(net.iGap.module.accountManager.AccountManager) DialogAction(com.afollestad.materialdialogs.DialogAction) RealmRoom(net.iGap.realm.RealmRoom) FragmentActivity(androidx.fragment.app.FragmentActivity) G(net.iGap.G) Lifecycle(androidx.lifecycle.Lifecycle) List(java.util.List) RealmRegisteredInfo(net.iGap.realm.RealmRegisteredInfo) FragmentChat(net.iGap.fragments.FragmentChat) Fragment(androidx.fragment.app.Fragment) ProtoGlobal(net.iGap.proto.ProtoGlobal) R(net.iGap.R) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) DbManager(net.iGap.module.accountManager.DbManager) Log(android.util.Log) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) RealmRegisteredInfo(net.iGap.realm.RealmRegisteredInfo) ActivityMain(net.iGap.activities.ActivityMain) DialogAction(com.afollestad.materialdialogs.DialogAction) NonNull(androidx.annotation.NonNull) RealmRoom(net.iGap.realm.RealmRoom) FragmentChat(net.iGap.fragments.FragmentChat)

Example 17 with RealmRoom

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

the class BotInit method checkDrIgap.

public static void checkDrIgap() {
    if (!BotInit.getCheckDrIgap())
        return;
    new RequestClientGetPromote().getPromote();
    G.ipromote = new Ipromote() {

        @Override
        public void onGetPromoteResponse(ProtoClientGetPromote.ClientGetPromoteResponse.Builder builder) {
            setCheckDrIgap(false);
            ArrayList<Long> promoteIds = new ArrayList<>();
            for (int i = 0; i < builder.getPromoteList().size(); i++) promoteIds.add(builder.getPromoteList().get(i).getId());
            DbManager.getInstance().doRealmTask(realm -> {
                realm.executeTransaction(new Realm.Transaction() {

                    @Override
                    public void execute(Realm realm) {
                        RealmResults<RealmRoom> roomList = realm.where(RealmRoom.class).equalTo("isFromPromote", true).findAll();
                        for (RealmRoom room : roomList) {
                            if (!promoteIds.contains(room.getPromoteId())) {
                                room.setFromPromote(false);
                                RoomController.getInstance(AccountManager.selectedAccount).clientPinRoom(room.getId(), false);
                            }
                        }
                    }
                });
                for (int i = builder.getPromoteList().size() - 1; i >= 0; i--) {
                    ProtoClientGetPromote.ClientGetPromoteResponse.Promote.Type TYPE = builder.getPromoteList().get(i).getType();
                    RealmRoom realmRoom;
                    if (TYPE == ProtoClientGetPromote.ClientGetPromoteResponse.Promote.Type.USER) {
                        realmRoom = realm.where(RealmRoom.class).equalTo("chatRoom.peer_id", builder.getPromoteList().get(i).getId()).equalTo("isFromPromote", true).findFirst();
                    } else {
                        realmRoom = realm.where(RealmRoom.class).equalTo("id", builder.getPromoteList().get(i).getId()).equalTo("isFromPromote", true).findFirst();
                    }
                    if (realmRoom == null) {
                        if (TYPE == ProtoClientGetPromote.ClientGetPromoteResponse.Promote.Type.USER) {
                            // RealmRoom.setPromote(builder.getPromoteList().get(i).getId(), TYPE);
                            G.onChatGetRoom = new OnChatGetRoom() {

                                @Override
                                public void onChatGetRoom(final ProtoGlobal.Room room) {
                                    G.onChatGetRoom = null;
                                    DbManager.getInstance().doRealmTransaction(realm1 -> {
                                        RealmRoom realmRoom1 = RealmRoom.putOrUpdate(room, realm1);
                                        realmRoom1.setFromPromote(true);
                                        realmRoom1.setPromoteId(realmRoom1.getChatRoom().getPeerId());
                                    // RealmRoom.setPromote(2297310L, ProtoClientGetPromote.ClientGetPromoteResponse.Promote.Type.USER);
                                    });
                                    RoomController.getInstance(AccountManager.selectedAccount).clientPinRoom(room.getId(), true);
                                    ActivityPopUpNotification.sendMessage("/start", room.getId(), ProtoGlobal.Room.Type.CHAT);
                                }

                                @Override
                                public void onChatGetRoomTimeOut() {
                                }

                                @Override
                                public void onChatGetRoomError(int majorCode, int minorCode) {
                                }
                            };
                            new RequestChatGetRoom().chatGetRoom(builder.getPromoteList().get(i).getId());
                        } else {
                            new RequestClientGetRoom().clientGetRoom(builder.getPromoteList().get(i).getId(), RequestClientGetRoom.CreateRoomMode.getPromote);
                        }
                    } else {
                        RoomController.getInstance(AccountManager.selectedAccount).clientPinRoom(realmRoom.getId(), true);
                    }
                }
            });
        }
    };
}
Also used : LinearLayout(android.widget.LinearLayout) TypeToken(com.google.gson.reflect.TypeToken) NonNull(androidx.annotation.NonNull) RequestClientGetRoom(net.iGap.request.RequestClientGetRoom) GsonBuilder(com.google.gson.GsonBuilder) G(net.iGap.G) RealmUserInfo(net.iGap.realm.RealmUserInfo) JSONException(org.json.JSONException) AdditionalType(net.iGap.module.additionalData.AdditionalType) Gson(com.google.gson.Gson) View(android.view.View) ProtoClientGetPromote(net.iGap.proto.ProtoClientGetPromote) ContextCompat(androidx.core.content.ContextCompat) Realm(io.realm.Realm) RealmRoom(net.iGap.realm.RealmRoom) AppCompatButton(androidx.appcompat.widget.AppCompatButton) ViewGroup(android.view.ViewGroup) OnChatGetRoom(net.iGap.observers.interfaces.OnChatGetRoom) TextView(android.widget.TextView) ViewMaker.i_Dp(net.iGap.adapter.items.chat.ViewMaker.i_Dp) G.isLocationFromBot(net.iGap.G.isLocationFromBot) G.context(net.iGap.G.context) RelativeLayout(android.widget.RelativeLayout) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) RequestChatGetRoom(net.iGap.request.RequestChatGetRoom) AppCompatTextView(androidx.appcompat.widget.AppCompatTextView) Context(android.content.Context) ResourcesCompat(androidx.core.content.res.ResourcesCompat) ActivityPopUpNotification(net.iGap.activities.ActivityPopUpNotification) HelperUrl(net.iGap.helper.HelperUrl) AccountManager(net.iGap.module.accountManager.AccountManager) HashMap(java.util.HashMap) InputMethodManager(android.view.inputmethod.InputMethodManager) ArrayList(java.util.ArrayList) ButtonActionType(net.iGap.module.additionalData.ButtonActionType) Toast(android.widget.Toast) RealmRoomMessage(net.iGap.realm.RealmRoomMessage) Ipromote(net.iGap.observers.interfaces.Ipromote) RoomController(net.iGap.controllers.RoomController) MessageObject(net.iGap.structs.MessageObject) RealmResults(io.realm.RealmResults) RequestClientGetPromote(net.iGap.request.RequestClientGetPromote) DialogAction(com.afollestad.materialdialogs.DialogAction) Color(android.graphics.Color) Gravity(android.view.Gravity) SharedPreferences(android.content.SharedPreferences) ViewMaker(net.iGap.adapter.items.chat.ViewMaker) ButtonEntity(net.iGap.module.additionalData.ButtonEntity) ProtoGlobal(net.iGap.proto.ProtoGlobal) R(net.iGap.R) Activity(android.app.Activity) DbManager(net.iGap.module.accountManager.DbManager) JSONArray(org.json.JSONArray) RequestChatGetRoom(net.iGap.request.RequestChatGetRoom) ArrayList(java.util.ArrayList) RequestClientGetPromote(net.iGap.request.RequestClientGetPromote) Ipromote(net.iGap.observers.interfaces.Ipromote) AdditionalType(net.iGap.module.additionalData.AdditionalType) ButtonActionType(net.iGap.module.additionalData.ButtonActionType) OnChatGetRoom(net.iGap.observers.interfaces.OnChatGetRoom) RequestClientGetRoom(net.iGap.request.RequestClientGetRoom) RealmRoom(net.iGap.realm.RealmRoom) Realm(io.realm.Realm) RequestClientGetRoom(net.iGap.request.RequestClientGetRoom) RealmRoom(net.iGap.realm.RealmRoom) OnChatGetRoom(net.iGap.observers.interfaces.OnChatGetRoom) RequestChatGetRoom(net.iGap.request.RequestChatGetRoom)

Example 18 with RealmRoom

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

the class AppUtils method updateBadgeOnly.

public static int[] updateBadgeOnly(Realm realm, long roomId) {
    int unreadMessageCount = 0;
    int chatCount = 0;
    int[] result = new int[2];
    RealmResults<RealmRoom> realmRooms = realm.where(RealmRoom.class).equalTo("keepRoom", false).equalTo("mute", false).equalTo("isDeleted", false).notEqualTo("id", roomId).findAll();
    for (RealmRoom realmRoom1 : realmRooms) {
        if (realmRoom1.getUnreadCount() > 0) {
            unreadMessageCount += realmRoom1.getUnreadCount();
            ++chatCount;
        }
    }
    try {
        ShortcutBadger.applyCount(G.context, unreadMessageCount);
    } catch (Exception e) {
        e.printStackTrace();
    }
    result[0] = unreadMessageCount;
    result[1] = chatCount;
    return result;
}
Also used : RealmRoom(net.iGap.realm.RealmRoom) FileNotFoundException(java.io.FileNotFoundException)

Example 19 with RealmRoom

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

the class ChatSendMessageUtil method onRoomMessageReceive.

private void onRoomMessageReceive(long roomId, ProtoGlobal.RoomMessage roomMessage, ProtoGlobal.Room.Type roomType) {
    DbManager.getInstance().doRealmTransaction(realm -> {
        RealmRoom room = realm.where(RealmRoom.class).equalTo("id", roomId).findFirst();
        final RealmRoomMessage realmRoomMessage = realm.where(RealmRoomMessage.class).equalTo("messageId", roomMessage.getMessageId()).findFirst();
        if (room != null && realmRoomMessage != null) {
            /**
             * client checked  (room.getUnreadCount() <= 1)  because in HelperMessageResponse unreadCount++
             */
            if (room.getUnreadCount() <= 1) {
                realmRoomMessage.setFutureMessageId(realmRoomMessage.getMessageId());
            }
        }
    });
    /**
     * don't send update status for own message
     */
    if (roomMessage.getAuthor().getUser() != null && roomMessage.getAuthor().getUser().getUserId() != AccountManager.getInstance().getCurrentUser().getId()) {
        if (roomType == ProtoGlobal.Room.Type.CHAT) {
            getMessageController().sendUpdateStatus(roomType.getNumber(), roomId, roomMessage.getMessageId(), roomMessage.getDocumentId(), ProtoGlobal.RoomMessageStatus.DELIVERED_VALUE);
        } else if (roomType == ProtoGlobal.Room.Type.GROUP && roomMessage.getStatus() == ProtoGlobal.RoomMessageStatus.SENT) {
            getMessageController().sendUpdateStatus(roomType.getNumber(), roomId, roomMessage.getMessageId(), roomMessage.getDocumentId(), ProtoGlobal.RoomMessageStatus.DELIVERED_VALUE);
        }
    }
}
Also used : RealmRoom(net.iGap.realm.RealmRoom) RealmRoomMessage(net.iGap.realm.RealmRoomMessage)

Example 20 with RealmRoom

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

the class ClientGetRoomResponse method handler.

@Override
public void handler() {
    super.handler();
    final ProtoClientGetRoom.ClientGetRoomResponse.Builder clientGetRoom = (ProtoClientGetRoom.ClientGetRoomResponse.Builder) message;
    DbManager.getInstance().doRealmTransaction(realm -> {
        final RequestClientGetRoom.IdentityClientGetRoom identityClientGetRoom = ((RequestClientGetRoom.IdentityClientGetRoom) identity);
        final RequestClientGetRoom.CreateRoomMode roomMode = identityClientGetRoom.createRoomMode;
        if (roomMode != null && roomMode == RequestClientGetRoom.CreateRoomMode.justInfo) {
            if (!RealmRoom.isMainRoom(clientGetRoom.getRoom().getId())) {
                RealmRoom realmRoom = RealmRoom.putOrUpdate(clientGetRoom.getRoom(), realm);
                realmRoom.setDeleted(true);
                realmRoom.setKeepRoom(true);
            }
            /**
             * update log message in realm room message after get room info
             */
            if (HelperLogMessage.logMessageUpdateList.containsKey(clientGetRoom.getRoom().getId())) {
                G.handler.postDelayed(new Runnable() {

                    @Override
                    public void run() {
                        HelperLogMessage.updateLogMessageAfterGetUserInfo(clientGetRoom.getRoom().getId());
                    }
                }, 500);
            }
            return;
        }
        if (roomMode != null && roomMode == RequestClientGetRoom.CreateRoomMode.getPromote) {
            if (!RealmRoom.isMainRoom(clientGetRoom.getRoom().getId())) {
                RealmRoom realmRoom = RealmRoom.putOrUpdate(clientGetRoom.getRoom(), realm);
                realmRoom.setFromPromote(true);
                realmRoom.setPromoteId(clientGetRoom.getRoom().getId());
                realmRoom.setDeleted(true);
                realmRoom.setKeepRoom(false);
                if (clientGetRoom.getRoom().hasChannelRoomExtra()) {
                    new RequestClientJoinByUsername().clientJoinByUsername(clientGetRoom.getRoom().getChannelRoomExtra().getPublicExtra().getUsername(), clientGetRoom.getRoom().getId());
                } else {
                    new RequestClientJoinByUsername().clientJoinByUsername(clientGetRoom.getRoom().getGroupRoomExtra().getPublicExtra().getUsername(), clientGetRoom.getRoom().getId());
                }
            // 
            }
            return;
        }
        if (clientGetRoom.getRoom().getType() == ProtoGlobal.Room.Type.CHAT) {
            new HelperGetUserInfo(new OnGetUserInfo() {

                @Override
                public void onGetUserInfo(ProtoGlobal.RegisteredUser registeredUser) {
                    new Handler(Looper.getMainLooper()).post(new Runnable() {

                        @Override
                        public void run() {
                            DbManager.getInstance().doRealmTask(realm1 -> {
                                realm1.executeTransactionAsync(new Realm.Transaction() {

                                    @Override
                                    public void execute(Realm realm1) {
                                        putOrUpdate(clientGetRoom.getRoom(), realm1);
                                    }
                                }, new Realm.Transaction.OnSuccess() {

                                    @Override
                                    public void onSuccess() {
                                        if (G.onClientGetRoomResponse != null) {
                                            G.onClientGetRoomResponse.onClientGetRoomResponse(clientGetRoom.getRoom(), clientGetRoom, identityClientGetRoom);
                                        }
                                    }
                                });
                            });
                        }
                    });
                }
            }).getUserInfo(clientGetRoom.getRoom().getChatRoomExtra().getPeer().getId());
        } else {
            putOrUpdate(clientGetRoom.getRoom(), realm);
            G.handler.postDelayed(new Runnable() {

                @Override
                public void run() {
                    if (G.onClientGetRoomResponse != null) {
                        G.onClientGetRoomResponse.onClientGetRoomResponse(clientGetRoom.getRoom(), clientGetRoom, identityClientGetRoom);
                    }
                }
            }, 500);
        }
    });
    MessageDataStorage.getInstance(AccountManager.selectedAccount).storySetDisplayName(clientGetRoom.getRoom().getId(), clientGetRoom.getRoom().getTitle(), clientGetRoom.getRoom().getType() == ProtoGlobal.Room.Type.CHANNEL && clientGetRoom.getRoom().getChannelRoomExtra().getVerified());
    // update chat message header forward after get user or room info
    if (AbstractMessage.updateForwardInfo != null) {
        if (AbstractMessage.updateForwardInfo.containsKey(clientGetRoom.getRoom().getId())) {
            String messageId = AbstractMessage.updateForwardInfo.get(clientGetRoom.getRoom().getId());
            AbstractMessage.updateForwardInfo.remove(clientGetRoom.getRoom().getId());
            if (FragmentChat.onUpdateUserOrRoomInfo != null) {
                FragmentChat.onUpdateUserOrRoomInfo.onUpdateUserOrRoomInfo(messageId);
            }
        }
    }
}
Also used : Realm(io.realm.Realm) ProtoClientGetRoom(net.iGap.proto.ProtoClientGetRoom) RequestClientJoinByUsername(net.iGap.request.RequestClientJoinByUsername) AccountManager(net.iGap.module.accountManager.AccountManager) RequestClientGetRoom(net.iGap.request.RequestClientGetRoom) RealmRoom(net.iGap.realm.RealmRoom) G(net.iGap.G) ProtoError(net.iGap.proto.ProtoError) HelperGetUserInfo(net.iGap.helper.HelperGetUserInfo) FragmentChat(net.iGap.fragments.FragmentChat) HelperLogMessage(net.iGap.helper.HelperLogMessage) RealmRoom.putOrUpdate(net.iGap.realm.RealmRoom.putOrUpdate) Handler(android.os.Handler) Looper(android.os.Looper) ProtoGlobal(net.iGap.proto.ProtoGlobal) MessageDataStorage(net.iGap.controllers.MessageDataStorage) OnGetUserInfo(net.iGap.observers.interfaces.OnGetUserInfo) DbManager(net.iGap.module.accountManager.DbManager) AbstractMessage(net.iGap.adapter.items.chat.AbstractMessage) Handler(android.os.Handler) RequestClientJoinByUsername(net.iGap.request.RequestClientJoinByUsername) OnGetUserInfo(net.iGap.observers.interfaces.OnGetUserInfo) RequestClientGetRoom(net.iGap.request.RequestClientGetRoom) HelperGetUserInfo(net.iGap.helper.HelperGetUserInfo) RealmRoom(net.iGap.realm.RealmRoom) ProtoClientGetRoom(net.iGap.proto.ProtoClientGetRoom) Realm(io.realm.Realm)

Aggregations

RealmRoom (net.iGap.realm.RealmRoom)80 ArrayList (java.util.ArrayList)28 ProtoGlobal (net.iGap.proto.ProtoGlobal)27 RealmRoomMessage (net.iGap.realm.RealmRoomMessage)27 DbManager (net.iGap.module.accountManager.DbManager)26 View (android.view.View)23 G (net.iGap.G)23 List (java.util.List)19 R (net.iGap.R)19 SuppressLint (android.annotation.SuppressLint)18 TextView (android.widget.TextView)18 AccountManager (net.iGap.module.accountManager.AccountManager)18 RealmRegisteredInfo (net.iGap.realm.RealmRegisteredInfo)18 Bundle (android.os.Bundle)17 MaterialDialog (com.afollestad.materialdialogs.MaterialDialog)17 RecyclerView (androidx.recyclerview.widget.RecyclerView)16 AvatarHandler (net.iGap.helper.avatar.AvatarHandler)16 Context (android.content.Context)15 NonNull (androidx.annotation.NonNull)15 HelperFragment (net.iGap.helper.HelperFragment)15