use of net.iGap.realm.RealmRoomMessage 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);
}
}
}
use of net.iGap.realm.RealmRoomMessage in project iGap-Android by KianIranian-STDG.
the class ActivityPopUpNotification method sendMessage.
public static void sendMessage(final String message, final long mRoomId, ProtoGlobal.Room.Type chatType) {
RealmRoomMessage roomMessage = RealmRoomMessage.makeTextMessage(mRoomId, message);
HelperRealm.copyOrUpdateToRealm(roomMessage);
ChatSendMessageUtil.getInstance(AccountManager.selectedAccount).newBuilder(chatType, ProtoGlobal.RoomMessageType.TEXT, mRoomId).message(message).sendMessage(roomMessage.getMessageId() + "");
}
use of net.iGap.realm.RealmRoomMessage in project iGap-Android by KianIranian-STDG.
the class UploadManager method uploadMessageAndSend.
public void uploadMessageAndSend(ProtoGlobal.Room.Type roomType, RealmRoomMessage message, boolean ignoreCompress) {
Log.d("bagi", "uploadMessageAndSend" + message.getMessageId());
if (message.isManaged()) {
uploadMessageAndSend(roomType, DbManager.getInstance().doRealmTask(realm -> {
return realm.copyFromRealm(message);
}), ignoreCompress);
return;
}
if (message.getForwardMessage() != null || message.getAttachment() == null || message.getMessageType() == ProtoGlobal.RoomMessageType.STICKER || message.getMessageType() == ProtoGlobal.RoomMessageType.CONTACT) {
MessageObject uploadMessage = MessageObject.create(message);
ChatSendMessageUtil.getInstance(AccountManager.selectedAccount).build(roomType, message.getRoomId(), uploadMessage);
return;
}
Log.d("bagi", "uploadMessageAndSend222");
String savePathVideoCompress = G.DIR_TEMP + "/VIDEO_" + message.getMessageId() + ".mp4";
File compressFile = new File(savePathVideoCompress);
File CompletedCompressFile = new File(savePathVideoCompress.replace(".mp4", "_finish.mp4"));
if (!CompletedCompressFile.exists() && !ignoreCompress && (message.getMessageType() == ProtoGlobal.RoomMessageType.VIDEO || message.getMessageType() == ProtoGlobal.RoomMessageType.VIDEO_TEXT)) {
if (pendingCompressTasks.containsKey(message.getMessageId() + ""))
return;
Log.d("bagi", "uploadMessageAndSend33");
CompressTask compressTask = new CompressTask(message.getMessageId() + "", message.getAttachment().getLocalFilePath(), savePathVideoCompress, new OnCompress() {
@Override
public void onCompressProgress(String id, int percent) {
Log.d("bagi", "onCompressProgress" + percent);
G.runOnUiThread(() -> EventManager.getInstance(AccountManager.selectedAccount).postEvent(EventManager.ON_UPLOAD_COMPRESS, id, percent));
}
@Override
public void onCompressFinish(String id, boolean compress, boolean isCancel) {
Log.d("bagi", "onCompressFinish" + message.getMessageId());
if (compress && compressFile.exists() && compressFile.length() < (new File(message.getAttachment().getLocalFilePath())).length()) {
compressFile.renameTo(CompletedCompressFile);
message.attachment.size = CompletedCompressFile.length();
G.runOnUiThread(() -> EventManager.getInstance(AccountManager.selectedAccount).postEvent(EventManager.ON_UPLOAD_COMPRESS, id, 100, CompletedCompressFile.length()));
uploadMessageAndSend(roomType, message, ignoreCompress);
} else {
if (compressFile.exists()) {
compressFile.delete();
}
G.runOnUiThread(() -> EventManager.getInstance(AccountManager.selectedAccount).postEvent(EventManager.ON_UPLOAD_COMPRESS, id, 100));
uploadMessageAndSend(roomType, message, true);
}
}
});
if (compressFile.exists()) {
compressFile.delete();
}
pendingCompressTasks.put(message.getMessageId() + "", compressTask);
mThreadPoolExecutor.execute(compressTask);
return;
}
CompressTask compressTask = pendingCompressTasks.remove(message.getMessageId() + "");
if ((message.getMessageType() == ProtoGlobal.RoomMessageType.VIDEO || message.getMessageType() == ProtoGlobal.RoomMessageType.VIDEO_TEXT) && !ignoreCompress && (compressTask == null || !CompletedCompressFile.exists()))
return;
Log.d("bagi", "after Compress");
OnUploadListener onUploadListener = new OnUploadListener() {
@Override
public void onProgress(String id, int progress) {
Log.d("bagi", progress + "uploadMessageAndSend2");
G.runOnUiThread(() -> EventManager.getInstance(AccountManager.selectedAccount).postEvent(EventManager.ON_UPLOAD_PROGRESS, id, progress, message.attachment.size));
}
@Override
public void onFinish(String id, String token) {
Log.d("bagi", "uploadMessageAndSendonFinish");
if (CompletedCompressFile.exists()) {
CompletedCompressFile.delete();
}
HelperSetAction.sendCancel(message.getMessageId());
DbManager.getInstance().doRealmTransaction(realm -> {
RealmAttachment.updateToken(message.getMessageId(), token);
});
/**
* this code should exist in under of other codes in this block
*/
if (message.getReplyTo() == null) {
ChatSendMessageUtil.getInstance(AccountManager.selectedAccount).newBuilder(roomType, message.getMessageType(), message.getRoomId()).attachment(token).message(message.getMessage()).sendMessage(message.getMessageId() + "");
} else {
ChatSendMessageUtil.getInstance(AccountManager.selectedAccount).newBuilder(roomType, message.getMessageType(), message.getRoomId()).replyMessage(message.getReplyTo().getMessageId()).attachment(token).message(message.getMessage()).sendMessage(message.getMessageId() + "");
}
pendingUploadTasks.remove(id);
}
@Override
public void onError(String id) {
Log.d("bagi", "uploadMessageAndSendError");
pendingUploadTasks.remove(id);
HelperSetAction.sendCancel(Long.parseLong(id));
makeFailed(id);
}
};
UploadTask uploadTask;
if (CompletedCompressFile.exists()) {
uploadTask = new UploadTask(message, CompletedCompressFile.getAbsolutePath(), onUploadListener);
} else {
uploadTask = new UploadTask(message, onUploadListener);
}
if (!pendingUploadTasks.containsKey(uploadTask.identity)) {
pendingUploadTasks.put(uploadTask.identity, uploadTask);
mThreadPoolExecutor.execute(uploadTask);
HelperSetAction.setActionFiles(message.getRoomId(), message.getMessageId(), HelperSetAction.getAction(message.getMessageType()), roomType);
G.runOnUiThread(() -> EventManager.getInstance(AccountManager.selectedAccount).postEvent(EventManager.ON_UPLOAD_PROGRESS, message.getMessageId() + "", 1));
}
}
use of net.iGap.realm.RealmRoomMessage in project iGap-Android by KianIranian-STDG.
the class SearchFragment method fillMessages.
private void fillMessages(String text) {
DbManager.getInstance().doRealmTask(realm -> {
final RealmResults<RealmRoomMessage> results = realm.where(RealmRoomMessage.class).contains("message", text, Case.INSENSITIVE).equalTo("deleted", false).isNotEmpty("message").findAll();
if (results != null && results.size() > 0) {
addHeader(G.fragmentActivity.getResources().getString(R.string.messages));
for (RealmRoomMessage roomMessage : results) {
StructSearch item = new StructSearch();
item.time = roomMessage.getUpdateTime();
item.comment = roomMessage.getMessage();
item.id = roomMessage.getRoomId();
item.type = SearchType.message;
item.messageId = roomMessage.getMessageId();
RealmRoom realmRoom = realm.where(RealmRoom.class).equalTo("id", roomMessage.getRoomId()).findFirst();
if (realmRoom != null) {
// room exist
item.name = realmRoom.getTitle();
item.initials = realmRoom.getInitials();
item.color = realmRoom.getColor();
item.roomType = realmRoom.getType();
item.avatar = realmRoom.getAvatar();
if (realmRoom.getType() == ProtoGlobal.Room.Type.CHANNEL && realmRoom.getChannelRoom().isVerified() || realmRoom.getType() == CHAT && realmRoom.getChatRoom().isVerified()) {
item.isVerified = true;
}
if (realmRoom.getType() == ProtoGlobal.Room.Type.CHAT && realmRoom.getChatRoom() != null) {
item.idDetectAvatar = realmRoom.getChatRoom().getPeerId();
} else {
if (realmRoom.getType() == ProtoGlobal.Room.Type.GROUP && realmRoom.getGroupRoom() != null) {
item.userName = realmRoom.getGroupRoom().getUsername();
} else if (realmRoom.getType() == ProtoGlobal.Room.Type.CHANNEL && realmRoom.getChannelRoom() != null) {
item.userName = realmRoom.getChannelRoom().getUsername();
}
item.idDetectAvatar = realmRoom.getId();
}
list.add(item);
}
}
}
});
}
use of net.iGap.realm.RealmRoomMessage in project iGap-Android by KianIranian-STDG.
the class ShowMediaListener method getRoomMediaMessages.
private List<RealmRoomMessage> getRoomMediaMessages(Bundle bundle) {
if (bundle != null) {
long mRoomId = bundle.getLong(RealmConstants.REALM_ROOM_ID, 0L);
long selectedFileToken = bundle.getLong(RealmConstants.REALM_SELECTED_IMAGE);
String[] messageTypeImageVideo = new String[] { ProtoGlobal.RoomMessageType.VIDEO.toString(), ProtoGlobal.RoomMessageType.VIDEO_TEXT.toString(), ProtoGlobal.RoomMessageType.IMAGE.toString(), ProtoGlobal.RoomMessageType.IMAGE_TEXT.toString() };
List<RealmRoomMessage> realmRoomMessages = DbManager.getInstance().doRealmTask(realm -> {
return realm.copyFromRealm(realm.where(RealmRoomMessage.class).equalTo(RealmConstants.REALM_ROOM_ID, mRoomId).in(RealmConstants.REALM_MESSAGE_TYPE, messageTypeImageVideo).or().equalTo(RealmConstants.REALM_ROOM_ID, mRoomId).isNotNull(RealmConstants.REALM_FORWARD_MESSAGE).findAll().sort(RealmConstants.REALM_UPDATE_TIME, Sort.ASCENDING));
});
List messageTypesList = Arrays.asList(messageTypeImageVideo);
ArrayList<RealmRoomMessage> roomMessagesImageVideo = new ArrayList<>(realmRoomMessages);
for (RealmRoomMessage roomMessageObj : realmRoomMessages) {
if (roomMessageObj.forwardMessage != null && !messageTypesList.contains(roomMessageObj.forwardMessage.messageType)) {
roomMessagesImageVideo.remove(roomMessageObj);
}
}
for (int i = roomMessagesImageVideo.size() - 1; i >= 0; i--) {
if (selectedFileToken == roomMessagesImageVideo.get(i).messageId) {
selectedFile = i;
break;
}
}
return roomMessagesImageVideo;
} else {
return null;
}
}
Aggregations