Search in sources :

Example 6 with MessageObject

use of net.iGap.structs.MessageObject in project iGap-Android by KianIranian-STDG.

the class FragmentMediaPlayer method getInfoRealm.

public void getInfoRealm() {
    if (MusicPlayer.mediaList.size() != 0) {
        changeListener = null;
        List<RealmRoomMessage> realmRoomMessages = null;
        try {
            realmRoomMessages = DbManager.getInstance().doRealmTask(realm -> {
                return realm.where(RealmRoomMessage.class).equalTo("roomId", MusicPlayer.roomId).notEqualTo("deleted", true).contains("messageType", ProtoGlobal.RoomMessageType.AUDIO.toString()).lessThan("messageId", MusicPlayer.mediaList.get(MusicPlayer.mediaList.size() - 1).id).findAll().sort("messageId", Sort.DESCENDING);
            });
        } catch (IllegalStateException e) {
        }
        if (realmRoomMessages != null && realmRoomMessages.size() > 0) {
            // mRealmList = RealmRoomMessage.filterMessage(getUiRealm(), MusicPlayer.roomId, ProtoGlobal.RoomMessageType.AUDIO);
            if (realmRoomMessages.size() > MusicPlayer.limitMediaList) {
                realmRoomMessages = realmRoomMessages.subList(0, MusicPlayer.limitMediaList);
            } else {
                realmRoomMessages = realmRoomMessages.subList(0, realmRoomMessages.size());
            }
            footerAdapter.clear();
            for (RealmRoomMessage r : realmRoomMessages) {
                MessageObject messageObject = MessageObject.create(r);
                if (messageObject.attachment.isFileExistsOnLocal(messageObject)) {
                    MusicPlayer.mediaList.add(messageObject);
                }
                fastItemAdapter.add(new AdapterListMusicPlayer().setItem(messageObject).withIdentifier(r.getMessageId()));
            }
        } else {
            if (isThereAnyMoreItemToLoad)
                new RequestClientSearchRoomHistory().clientSearchRoomHistory(MusicPlayer.roomId, nextMessageId, nextDocumentId, ProtoClientSearchRoomHistory.ClientSearchRoomHistory.Filter.AUDIO);
        }
    }
}
Also used : ActivityMediaPlayerLandBinding(net.iGap.databinding.ActivityMediaPlayerLandBinding) Bundle(android.os.Bundle) AppUtils(net.iGap.module.AppUtils) ProtoFileDownload(net.iGap.proto.ProtoFileDownload) ImageView(android.widget.ImageView) MessageProgress(net.iGap.messageprogress.MessageProgress) G(net.iGap.G) ItemAdapter(com.mikepenz.fastadapter.adapters.ItemAdapter) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) Log(android.util.Log) ArrayMap(androidx.collection.ArrayMap) DataBindingUtil(androidx.databinding.DataBindingUtil) OnComplete(net.iGap.observers.interfaces.OnComplete) ProgressItem(com.mikepenz.fastadapter_extensions.items.ProgressItem) OnProgress(net.iGap.messageprogress.OnProgress) ViewGroup(android.view.ViewGroup) EndlessRecyclerOnScrollListener(com.mikepenz.fastadapter_extensions.scroll.EndlessRecyclerOnScrollListener) List(java.util.List) TextView(android.widget.TextView) Nullable(androidx.annotation.Nullable) MusicPlayer(net.iGap.module.MusicPlayer) HttpRequest(net.iGap.module.downloader.HttpRequest) Sort(io.realm.Sort) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) NotNull(org.jetbrains.annotations.NotNull) DownloadObject(net.iGap.module.downloader.DownloadObject) RealmChangeListener(io.realm.RealmChangeListener) AttachmentObject(net.iGap.structs.AttachmentObject) AndroidUtils(net.iGap.module.AndroidUtils) ProtoClientSearchRoomHistory(net.iGap.proto.ProtoClientSearchRoomHistory) RequestClientSearchRoomHistory(net.iGap.request.RequestClientSearchRoomHistory) MediaMetadataRetriever(android.media.MediaMetadataRetriever) ActivityMediaPlayerBinding(net.iGap.databinding.ActivityMediaPlayerBinding) AbstractItem(com.mikepenz.fastadapter.items.AbstractItem) SlidingUpPanelLayout(com.sothree.slidinguppanel.SlidingUpPanelLayout) ArrayList(java.util.ArrayList) SeekBar(android.widget.SeekBar) RealmRoomMessage(net.iGap.realm.RealmRoomMessage) LayoutInflater(android.view.LayoutInflater) MessageObject(net.iGap.structs.MessageObject) RealmResults(io.realm.RealmResults) FragmentMediaPlayerViewModel(net.iGap.viewmodel.FragmentMediaPlayerViewModel) StructMessageOption(net.iGap.module.structs.StructMessageOption) Configuration(android.content.res.Configuration) ProtoGlobal(net.iGap.proto.ProtoGlobal) R(net.iGap.R) DbManager(net.iGap.module.accountManager.DbManager) FastItemAdapter(com.mikepenz.fastadapter.commons.adapters.FastItemAdapter) OnClientSearchRoomHistory(net.iGap.observers.interfaces.OnClientSearchRoomHistory) RequestClientSearchRoomHistory(net.iGap.request.RequestClientSearchRoomHistory) RealmRoomMessage(net.iGap.realm.RealmRoomMessage) MessageObject(net.iGap.structs.MessageObject)

Example 7 with MessageObject

use of net.iGap.structs.MessageObject in project iGap-Android by KianIranian-STDG.

the class FragmentChat method sendForwardedMessage.

private void sendForwardedMessage(final MessageObject sourceMessage, final long destinationRoomId, final boolean isSingleForward, int k, boolean isMessage) {
    final long messageId = AppUtils.makeRandomId();
    RealmRoom destinationRoom = DbManager.getInstance().doRealmTask(realm -> {
        return realm.where(RealmRoom.class).equalTo("id", destinationRoomId).findFirst();
    });
    if (destinationRoom == null || destinationRoom.getReadOnly()) {
        return;
    }
    final int type = destinationRoom.getType().getNumber();
    getMessageDataStorage().createForwardMessage(destinationRoomId, messageId, sourceMessage, isMessage, object -> {
        MessageObject createdForwardMessage = (MessageObject) object[0];
        RealmRoomMessage forwardedRealm = (RealmRoomMessage) object[1];
        Long sourceRoomId = (Long) object[2];
        Long sourceMessageId = (Long) object[3];
        if (forwardedRealm.isValid() && !createdForwardMessage.deleted) {
            if (isSingleForward || forwardedRealm.getRoomId() == mRoomId) {
                switchAddItem(new ArrayList<>(Collections.singletonList(new StructMessageInfo(forwardedRealm))), false);
                scrollToEnd();
            }
            getSendMessageUtil().buildForward(type, createdForwardMessage.roomId, createdForwardMessage, sourceRoomId, sourceMessageId);
        }
    });
}
Also used : StructMessageInfo(net.iGap.module.structs.StructMessageInfo) RealmRoom(net.iGap.realm.RealmRoom) RealmRoomMessage(net.iGap.realm.RealmRoomMessage) MessageObject(net.iGap.structs.MessageObject) SuppressLint(android.annotation.SuppressLint)

Example 8 with MessageObject

use of net.iGap.structs.MessageObject in project iGap-Android by KianIranian-STDG.

the class FragmentChat method receivedEvent.

@Override
public void receivedEvent(int id, int account, Object... args) {
    if (id == EventManager.CALL_STATE_CHANGED) {
        if (args == null || args.length == 0)
            return;
        boolean state = (boolean) args[0];
        changePinnedMessageVisibility(true, isPinAvailable, MusicPlayer.isMusicPlyerEnable, CallManager.getInstance().isCallAlive());
        G.handler.post(() -> {
            if (MusicPlayer.chatLayout != null)
                MusicPlayer.chatLayout.setVisibility(View.GONE);
            if (MusicPlayer.mainLayout != null)
                MusicPlayer.mainLayout.setVisibility(View.GONE);
        });
    } else if (id == EventManager.EMOJI_LOADED) {
        G.runOnUiThread(this::invalidateViews);
    } else if (id == EventManager.CHAT_BACKGROUND_CHANGED) {
        G.handler.post(() -> {
            String path = (String) args[0];
            if (new File(path).exists())
                ImageLoadingServiceInjector.inject().loadImage(imgBackGround, path, true);
        });
    } else if (id == EventManager.ON_MESSAGE_DELETE) {
        long roomId = (long) args[0];
        long messageId = (long) args[1];
        boolean update = (boolean) args[2];
        if (roomId == mRoomId) {
            G.runOnUiThread(() -> {
                if (mAdapter == null) {
                    return;
                }
                ArrayList<Long> messages = new ArrayList<>(1);
                messages.add(messageId);
                deleteSelectedMessageFromAdapter(messages);
                if (mReplayLayout != null && mReplayLayout.getVisibility() == View.VISIBLE) {
                    MessageObject roomMessage = (MessageObject) mReplayLayout.getTag();
                    if (roomMessage != null && messageId == roomMessage.id && update) {
                        clearReplyView();
                    }
                }
            });
        }
    } else if (id == EventManager.ON_EDIT_MESSAGE) {
        G.runOnUiThread(() -> {
            long roomId = (long) args[0];
            long messageId = (long) args[1];
            String newMessage = (String) args[2];
            boolean isUpdate = (boolean) args[3];
            if (mRoomId == roomId && mAdapter != null) {
                mAdapter.updateMessageText(messageId, newMessage);
                if (!isUpdate)
                    removeEditedMessage();
            }
        });
    } else if (id == EventManager.ON_PINNED_MESSAGE && (long) args[0] == mRoomId) {
        G.runOnUiThread(this::initPinedMessage);
    } else if (id == EventManager.CHAT_CLEAR_MESSAGE) {
        G.runOnUiThread(() -> {
            long roomId = (long) args[0];
            if (roomId == mRoomId) {
                long clearID = (long) args[1];
                onChatClearMessage(roomId, clearID);
            }
        });
    } else if (id == EventManager.CHANNEL_ADD_VOTE) {
        G.runOnUiThread(() -> {
            long roomId = (long) args[0];
            if (roomId == mRoomId) {
                long messageId = (long) args[1];
                String reactionCount = (String) args[2];
                ProtoGlobal.RoomMessageReaction reaction = (ProtoGlobal.RoomMessageReaction) args[3];
                if (mAdapter != null) {
                    mAdapter.updateVote(roomId, messageId, reactionCount, reaction);
                }
            }
        });
    } else if (id == EventManager.CHANNEL_GET_VOTE) {
        G.runOnUiThread(() -> {
            if (mAdapter != null) {
                List<ProtoChannelGetMessagesStats.ChannelGetMessagesStatsResponse.Stats> states = (List<ProtoChannelGetMessagesStats.ChannelGetMessagesStatsResponse.Stats>) args[0];
                for (final ProtoChannelGetMessagesStats.ChannelGetMessagesStatsResponse.Stats stats : states) {
                    mAdapter.updateMessageState(stats.getMessageId(), stats.getThumbsUpLabel(), stats.getThumbsDownLabel(), stats.getViewsLabel());
                }
            }
        });
    } else if (id == EventManager.CHANNEL_UPDATE_VOTE) {
        G.runOnUiThread(() -> {
            showVoteChannel = (boolean) args[1];
            if (mAdapter != null) {
                mAdapter.notifyDataSetChanged();
            }
        });
    } else if (id == EventManager.CHAT_UPDATE_STATUS) {
        G.runOnUiThread(() -> {
            long roomId = (long) args[0];
            long messageId = (long) args[1];
            ProtoGlobal.RoomMessageStatus status = (ProtoGlobal.RoomMessageStatus) args[2];
            if (roomId == mRoomId) {
                if (mAdapter != null) {
                    mAdapter.updateMessageStatus(messageId, status);
                }
            }
        });
    } else if (id == EventManager.MEDIA_PLAYER_STATE_CHANGED) {
        if (!MusicPlayer.isMusicPlyerEnable) {
            G.runOnUiThread(() -> changePinnedMessageVisibility(false, false, true, CallManager.getInstance().isCallAlive()));
            changeSpamLayoutPosition(false);
        } else {
            G.runOnUiThread(() -> changePinnedMessageVisibility(false, true, true, CallManager.getInstance().isCallAlive()));
            changeSpamLayoutPosition(true);
        }
    } else if (id == EventManager.NEXT_VOICE) {
        int roomType = (int) args[0];
        long roomId = (long) args[1];
        long messageId = (long) args[2];
        int roomMessageStatus = (int) args[3];
        int documentId = (int) args[4];
        getMessageController().sendUpdateStatus(roomType, roomId, messageId, documentId, roomMessageStatus);
    } else if (id == EventManager.ON_FILE_PICKED_FROM_INTENT) {
        Intent inputIntent = (Intent) args[0];
        if (inputIntent != null) {
            if (inputIntent.getData().toString().contains("media")) {
                sendMessage(request_code_pic_file, inputIntent.getData().toString());
            } else {
                Toast.makeText(context, R.string.enable_sending_non_media_file_soon, Toast.LENGTH_LONG).show();
            }
        // if (caption != null) edtChat.setText(caption);
        // for (String path : selectedPathList) {
        // sendMessage(request_code_pic_file, path);
        // edtChat.setText("");
        // }
        }
        edtChat.setText("");
    }
}
Also used : ArrayList(java.util.ArrayList) ProtoGlobal(net.iGap.proto.ProtoGlobal) ProtoChannelGetMessagesStats(net.iGap.proto.ProtoChannelGetMessagesStats) Intent(android.content.Intent) RealmString(net.iGap.realm.RealmString) HelperString(net.iGap.helper.HelperString) SuppressLint(android.annotation.SuppressLint) ProtoChannelGetMessagesStats(net.iGap.proto.ProtoChannelGetMessagesStats) RealmList(io.realm.RealmList) ArrayList(java.util.ArrayList) List(java.util.List) HelperSaveFile(net.iGap.helper.HelperSaveFile) File(java.io.File) AttachFile(net.iGap.module.AttachFile) MessageObject(net.iGap.structs.MessageObject)

Example 9 with MessageObject

use of net.iGap.structs.MessageObject in project iGap-Android by KianIranian-STDG.

the class FragmentChat method sendStickerAsMessage.

private void sendStickerAsMessage(StructIGSticker structIGSticker) {
    String additional = new Gson().toJson(structIGSticker);
    long identity = AppUtils.makeRandomId();
    int[] imageSize = AndroidUtils.getImageDimens(structIGSticker.getPath());
    RealmRoomMessage roomMessage = new RealmRoomMessage();
    roomMessage.setMessageId(identity);
    roomMessage.setMessageType(ProtoGlobal.RoomMessageType.STICKER);
    roomMessage.setRoomId(mRoomId);
    roomMessage.setMessage(structIGSticker.getName());
    roomMessage.setStatus(ProtoGlobal.RoomMessageStatus.SENDING.toString());
    roomMessage.setUserId(AccountManager.getInstance().getCurrentUser().getId());
    roomMessage.setCreateTime(TimeUtils.currentLocalTime());
    RealmAdditional realmAdditional = new RealmAdditional();
    realmAdditional.setId(AppUtils.makeRandomId());
    realmAdditional.setAdditionalType(structIGSticker.isGiftSticker() ? AdditionalType.GIFT_STICKER : AdditionalType.STICKER);
    realmAdditional.setAdditionalData(additional);
    roomMessage.setRealmAdditional(realmAdditional);
    RealmAttachment realmAttachment = new RealmAttachment();
    realmAttachment.setId(identity);
    realmAttachment.setLocalFilePath(structIGSticker.getPath());
    realmAttachment.setWidth(imageSize[0]);
    realmAttachment.setHeight(imageSize[1]);
    realmAttachment.setSize(new File(structIGSticker.getPath()).length());
    realmAttachment.setName(new File(structIGSticker.getPath()).getName());
    realmAttachment.setDuration(0);
    roomMessage.setAttachment(realmAttachment);
    roomMessage.getAttachment().setToken(structIGSticker.getToken());
    roomMessage.setAuthorHash(RealmUserInfo.getCurrentUserAuthorHash());
    roomMessage.setShowMessage(true);
    roomMessage.setCreateTime(TimeUtils.currentLocalTime());
    if (isReply()) {
        RealmRoomMessage copyReplyMessage = DbManager.getInstance().doRealmTask(realm -> {
            RealmRoomMessage copyReplyMessage1 = realm.where(RealmRoomMessage.class).equalTo("messageId", getReplyMessageId()).findFirst();
            if (copyReplyMessage1 != null) {
                return realm.copyFromRealm(copyReplyMessage1);
            }
            return null;
        });
        if (copyReplyMessage != null) {
            roomMessage.setReplyTo(copyReplyMessage);
        }
    }
    new Thread(() -> DbManager.getInstance().doRealmTransaction(realm -> {
        realm.copyToRealmOrUpdate(roomMessage);
        RealmStickerItem stickerItem = realm.where(RealmStickerItem.class).equalTo("id", structIGSticker.getId()).findFirst();
        if (stickerItem != null && stickerItem.isValid()) {
            stickerItem.setRecent();
        }
    })).start();
    MessageObject messageObject = MessageObject.create(roomMessage);
    scrollToEnd();
    if (isReply()) {
        mReplayLayout.setTag(null);
        mReplayLayout.setVisibility(View.GONE);
    }
    if (FragmentChat.structIGSticker != null) {
        FragmentChat.structIGSticker = null;
        if (getActivity() instanceof ActivityMain) {
            ((ActivityMain) getActivity()).checkHasSharedData(false);
        }
    }
}
Also used : RealmAdditional(net.iGap.realm.RealmAdditional) ActivityMain(net.iGap.activities.ActivityMain) Gson(com.google.gson.Gson) RealmString(net.iGap.realm.RealmString) HelperString(net.iGap.helper.HelperString) RealmRoomMessage(net.iGap.realm.RealmRoomMessage) RealmAttachment(net.iGap.realm.RealmAttachment) HelperSaveFile(net.iGap.helper.HelperSaveFile) File(java.io.File) AttachFile(net.iGap.module.AttachFile) MessageObject(net.iGap.structs.MessageObject) RealmStickerItem(net.iGap.realm.RealmStickerItem)

Example 10 with MessageObject

use of net.iGap.structs.MessageObject in project iGap-Android by KianIranian-STDG.

the class FragmentChat method onChatClearMessage.

public void onChatClearMessage(final long roomId, final long clearId) {
    // TODO: 12/28/20 MESSAGE_REFACTOR_NEED_TEST
    setDownBtnGone();
    saveMessageIdPositionState(0, 0);
    addToView = true;
    if (botInit != null)
        botInit.updateCommandList(false, "clear", getActivity(), false, null, 0, false);
    mAdapter.clear();
    recyclerView.removeAllViews();
    if (edtChat.getTag() != null && edtChat.getTag() instanceof StructMessageInfo) {
        edtChat.setTag(null);
    }
    if (mAdapter != null) {
        boolean cleared = false;
        if (mAdapter.getAdapterItemCount() > 1) {
            try {
                if (mAdapter.getAdapterItem(mAdapter.getAdapterItemCount() - 1).messageObject.id == clearId) {
                    cleared = true;
                    mAdapter.clear();
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        if (!cleared) {
            int selectedPosition = -1;
            for (int i = (mAdapter.getAdapterItemCount() - 1); i >= 0; i--) {
                try {
                    MessageObject messageObject = mAdapter.getAdapterItem(i).messageObject;
                    if (messageObject != null && messageObject.id == clearId) {
                        selectedPosition = i;
                        break;
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            if (selectedPosition != -1) {
                for (int i = selectedPosition; i >= 0; i--) {
                    mAdapter.remove(i);
                }
            }
        }
    }
    /**
     * remove tag from edtChat if the message has deleted
     */
    if (edtChat != null && edtChat.getTag() != null && edtChat.getTag() instanceof StructMessageInfo) {
        edtChat.setTag(null);
    }
}
Also used : StructMessageInfo(net.iGap.module.structs.StructMessageInfo) MessageObject(net.iGap.structs.MessageObject) IOException(java.io.IOException) JsonSyntaxException(com.google.gson.JsonSyntaxException) SuppressLint(android.annotation.SuppressLint)

Aggregations

MessageObject (net.iGap.structs.MessageObject)30 RealmRoomMessage (net.iGap.realm.RealmRoomMessage)18 ArrayList (java.util.ArrayList)13 File (java.io.File)11 RealmRoom (net.iGap.realm.RealmRoom)11 SuppressLint (android.annotation.SuppressLint)10 ProtoGlobal (net.iGap.proto.ProtoGlobal)10 NonNull (androidx.annotation.NonNull)9 TextView (android.widget.TextView)8 RecyclerView (androidx.recyclerview.widget.RecyclerView)8 List (java.util.List)8 G (net.iGap.G)8 HelperString (net.iGap.helper.HelperString)8 View (android.view.View)7 ImageView (android.widget.ImageView)7 Realm (io.realm.Realm)7 Intent (android.content.Intent)6 ViewGroup (android.view.ViewGroup)6 AppCompatTextView (androidx.appcompat.widget.AppCompatTextView)6 LinearLayoutManager (androidx.recyclerview.widget.LinearLayoutManager)6