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);
}
}
}
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);
}
});
}
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("");
}
}
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);
}
}
}
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);
}
}
Aggregations