use of net.iGap.realm.RealmRoomMessage 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.realm.RealmRoomMessage in project iGap-Android by KianIranian-STDG.
the class DownloadObject method createForThumb.
public static DownloadObject createForThumb(RealmRoomMessage message, boolean big) {
final RealmRoomMessage finalMessage = RealmRoomMessage.getFinalMessage(message);
if (finalMessage == null || finalMessage.attachment == null) {
return null;
}
final RealmThumbnail thumbnail = big ? finalMessage.attachment.largeThumbnail : finalMessage.attachment.smallThumbnail;
if (thumbnail == null || thumbnail.size == 0 || (thumbnail.cacheId == null || thumbnail.cacheId.isEmpty())) {
return null;
}
DownloadObject struct = new DownloadObject();
struct.selector = big ? LARGE_THUMBNAIL_VALUE : SMALL_THUMBNAIL_VALUE;
struct.key = createKey(thumbnail.cacheId, struct.selector);
struct.thumbCacheId = thumbnail.cacheId;
struct.mainCacheId = finalMessage.attachment.cacheId;
struct.fileToken = finalMessage.attachment.token;
struct.fileName = finalMessage.attachment.name;
struct.fileSize = big ? finalMessage.attachment.largeThumbnail.size : finalMessage.attachment.smallThumbnail.size;
struct.mimeType = struct.extractMime(struct.fileName);
struct.publicUrl = struct.getPublicUrl(finalMessage.attachment.url);
struct.priority = HttpRequest.PRIORITY.PRIORITY_HIGH;
String path = suitableAppFilePath(finalMessage.getMessageType());
struct.destFile = new File(path + "/" + struct.thumbCacheId + "_" + struct.mimeType);
struct.tempFile = new File(G.context.getCacheDir() + "/" + struct.key);
struct.messageType = ProtoGlobal.RoomMessageType.valueOf(finalMessage.messageType);
if (struct.tempFile.exists()) {
struct.offset = struct.tempFile.length();
if (struct.offset > 0 && struct.fileSize > 0) {
struct.progress = (int) ((struct.offset * 100) / struct.fileSize);
}
}
return struct;
}
use of net.iGap.realm.RealmRoomMessage in project iGap-Android by KianIranian-STDG.
the class StructMessageInfo method getRealmChannelExtraOfMessage.
private RealmChannelExtra getRealmChannelExtraOfMessage(RealmRoomMessage message) {
if (message.getChannelExtra() != null) {
return message.getChannelExtra();
} else {
DbManager.getInstance().doRealmTransactionLowPriorityAsync(realm -> {
RealmRoomMessage newMessage = realm.where(RealmRoomMessage.class).equalTo("messageId", message.getMessageId()).findFirst();
RealmChannelExtra channelExtra = realm.where(RealmChannelExtra.class).equalTo("messageId", message.getMessageId()).findFirst();
if (newMessage != null && channelExtra != null) {
newMessage.setChannelExtra(channelExtra);
}
});
return DbManager.getInstance().doRealmTask(realm -> {
RealmChannelExtra realmChannelExtra = realm.where(RealmChannelExtra.class).equalTo("messageId", message.getMessageId()).findFirst();
if (realmChannelExtra != null) {
realmChannelExtra = realm.copyFromRealm(realmChannelExtra);
}
return realmChannelExtra;
});
}
}
use of net.iGap.realm.RealmRoomMessage in project iGap-Android by KianIranian-STDG.
the class FragmentChat method initMain.
private void initMain() {
HelperGetMessageState.clearMessageViews();
initPinedMessage();
viewMicRecorder = rootView.findViewById(R.id.layout_mic_recorde);
prgWaiting = rootView.findViewById(R.id.chl_prgWaiting);
AppUtils.setProgresColler(prgWaiting);
voiceRecord = new VoiceRecord(G.fragmentActivity, viewMicRecorder, viewAttachFile, this);
prgWaiting.setVisibility(View.VISIBLE);
txtEmptyMessages = rootView.findViewById(R.id.empty_messages);
if (isBot) {
txtEmptyMessages.setText(G.fragmentActivity.getResources().getString(R.string.empty_text_dr_bot));
txtChannelMute.setText(R.string.start);
iconChannelMute.setText("");
}
lastDateCalendar.clear();
locationManager = (LocationManager) G.fragmentActivity.getSystemService(LOCATION_SERVICE);
/**
* Hint: don't need to get info here. currently do this action in {{@link #startPageFastInitialize()}}
* Bundle extras = getArguments();
* if (extras != null) {
* mRoomId = extras.getLong("RoomId");
* isGoingFromUserLink = extras.getBoolean("GoingFromUserLink");
* isNotJoin = extras.getBoolean("ISNotJoin");
* userName = extras.getString("UserName");
* messageId = extras.getLong("MessageId");
* }
*/
/**
* get userId . use in chat set action.
*/
RealmUserInfo realmUserInfo = DbManager.getInstance().doRealmTask(realm -> {
return realm.where(RealmUserInfo.class).findFirst();
});
if (realmUserInfo == null) {
// finish();
finishChat();
return;
}
userId = realmUserInfo.getUserId();
managedRoom = getRoom();
if (managedRoom != null) {
// room exist
title = managedRoom.getTitle();
initialize = managedRoom.getInitials();
color = managedRoom.getColor();
isChatReadOnly = managedRoom.getReadOnly();
unreadCount = managedRoom.getUnreadCount();
savedScrollMessageId = managedRoom.getLastScrollPositionMessageId();
savedScrollDocumentId = managedRoom.getLastScrollPositionDocumentId();
firstVisiblePositionOffset = managedRoom.getLastScrollPositionOffset();
if (messageId != 0) {
savedScrollMessageId = messageId;
savedScrollDocumentId = documentId;
firstVisiblePositionOffset = 0;
}
if (chatType == CHAT) {
RealmRegisteredInfo realmRegisteredInfo = DbManager.getInstance().doRealmTask(realm -> {
return RealmRegisteredInfo.getRegistrationInfo(realm, chatPeerId);
});
if (realmRegisteredInfo != null) {
initialize = realmRegisteredInfo.getInitials();
color = realmRegisteredInfo.getColor();
phoneNumber = realmRegisteredInfo.getPhoneNumber();
if (realmRegisteredInfo.getId() == Config.drIgapPeerId) {
// if (realmRegisteredInfo.getUsername().equalsIgnoreCase("")) {
initDrBot();
}
} else {
title = managedRoom.getTitle();
initialize = managedRoom.getInitials();
color = managedRoom.getColor();
userStatus = G.fragmentActivity.getResources().getString(R.string.last_seen_recently);
}
} else if (chatType == GROUP) {
RealmGroupRoom realmGroupRoom = managedRoom.getGroupRoom();
groupRole = realmGroupRoom.getRole();
groupParticipantsCountLabel = realmGroupRoom.getParticipantsCountLabel();
} else if (chatType == CHANNEL) {
RealmChannelRoom realmChannelRoom = managedRoom.getChannelRoom();
channelRole = realmChannelRoom.getRole();
channelParticipantsCountLabel = realmChannelRoom.getParticipantsCountLabel();
}
} else {
// chatPeerId = extras.getLong("peerId");
chatType = CHAT;
RealmRegisteredInfo realmRegisteredInfo = DbManager.getInstance().doRealmTask(realm -> {
return RealmRegisteredInfo.getRegistrationInfo(realm, chatPeerId);
});
if (realmRegisteredInfo != null) {
title = realmRegisteredInfo.getDisplayName();
initialize = realmRegisteredInfo.getInitials();
color = realmRegisteredInfo.getColor();
lastSeen = realmRegisteredInfo.getLastSeen();
userStatus = realmRegisteredInfo.getStatus();
}
}
initComponent();
initAppbarSelected();
getDraft();
getUserInfo();
insertSharedData();
if (structIGSticker != null) {
G.handler.postDelayed(() -> sendStickerAsMessage(structIGSticker), 1000);
}
RealmRoomMessage rm = null;
RealmResults<RealmRoomMessage> result = DbManager.getInstance().doRealmTask(realm -> {
return realm.where(RealmRoomMessage.class).equalTo("roomId", mRoomId).findAll();
});
if (result.size() > 0) {
rm = result.last();
if (rm != null && rm.getMessage() != null) {
if (rm.getRealmAdditional() != null && (rm.getRealmAdditional().getAdditionalType() == Additional.WEB_VIEW.getAdditional())) {
String additionalData = rm.getRealmAdditional().getAdditionalData();
if (!additionalData.isEmpty())
openWebViewForSpecialUrlChat(additionalData);
}
}
}
FragmentShearedMedia.goToPositionFromShardMedia = new FragmentShearedMedia.GoToPositionFromShardMedia() {
@Override
public void goToPosition(Long messageId, long documentId) {
if (messageId != 0) {
savedScrollMessageId = messageId;
savedScrollDocumentId = documentId;
firstVisiblePositionOffset = 0;
if (goToPositionWithAnimation(savedScrollMessageId, 2000)) {
savedScrollMessageId = 0;
savedScrollDocumentId = 0;
} else {
RealmRoomMessage rm = DbManager.getInstance().doRealmTask(realm -> {
return realm.where(RealmRoomMessage.class).equalTo("messageId", messageId).findFirst();
});
rm = RealmRoomMessage.getFinalMessage(rm);
if (rm != null) {
resetMessagingValue();
savedScrollMessageId = FragmentChat.messageId = messageId;
savedScrollDocumentId = FragmentChat.documentId = documentId;
firstVisiblePositionOffset = 0;
getMessages();
}
}
}
}
};
sendChatTracker();
}
use of net.iGap.realm.RealmRoomMessage 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);
}
});
}
Aggregations