use of net.iGap.realm.RealmRoom in project iGap-Android by KianIranian-STDG.
the class AbstractMessage method forwardMessageIfNeeded.
@CallSuper
protected void forwardMessageIfNeeded(VH holder) {
NewChatItemHolder mHolder;
if (holder instanceof NewChatItemHolder)
mHolder = (NewChatItemHolder) holder;
else
return;
/**
* set forward container visible if message was forwarded, otherwise, gone it
*/
View cslr_ll_forward22 = ((NewChatItemHolder) holder).getContentBloke().findViewById(R.id.cslr_ll_forward);
if (cslr_ll_forward22 != null) {
mHolder.getContentBloke().removeView(cslr_ll_forward22);
}
if (messageObject.forwardedMessage != null) {
View forwardView = ViewMaker.getViewForward(((NewChatItemHolder) holder).getContext());
forwardView.setOnLongClickListener(getLongClickPerform(holder));
forwardView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (FragmentChat.isInSelectionMode) {
holder.itemView.performLongClick();
} else {
// TODO: 12/29/20 MESSAGE_REFACTOR
if (messageObject.username != null && messageObject.username.length() > 0) {
// TODO: fixed this and do not use G.currentActivity
HelperUrl.checkUsernameAndGoToRoomWithMessageId(G.currentActivity, messageObject.username, HelperUrl.ChatEntry.profile, (messageObject.forwardedMessage.id * (-1)), messageObject.forwardedMessage.documentId);
}
}
}
});
AppCompatTextView txtPrefixForwardFrom = forwardView.findViewById(R.id.cslr_txt_prefix_forward);
txtPrefixForwardFrom.setTypeface(ResourcesCompat.getFont(txtPrefixForwardFrom.getContext(), R.font.main_font));
AppCompatTextView txtForwardFrom = forwardView.findViewById(R.id.cslr_txt_forward_from);
txtForwardFrom.setTypeface(ResourcesCompat.getFont(txtPrefixForwardFrom.getContext(), R.font.main_font));
/**
* if forward message from chat or group , sender is user
* but if message forwarded from channel sender is room
*/
RealmRegisteredInfo info = DbManager.getInstance().doRealmTask(realm -> {
return RealmRegisteredInfo.getRegistrationInfo(realm, messageObject.forwardedMessage.userId);
});
// TODO: 12/29/20 MESSAGE_REFACTOR
if (info != null) {
if (RealmRegisteredInfo.needUpdateUser(info.getId(), info.getCacheId())) {
if (!updateForwardInfo.containsKey(info.getId())) {
updateForwardInfo.put(info.getId(), messageObject.id + "");
}
}
txtForwardFrom.setText(EmojiManager.getInstance().replaceEmoji(info.getDisplayName(), txtForwardFrom.getPaint().getFontMetricsInt()));
if (info.getUsername() != null)
messageObject.username = info.getUsername();
txtForwardFrom.setTextColor(theme.getForwardFromTextColor(txtForwardFrom.getContext()));
} else if (messageObject.forwardedMessage.userId != 0) {
if (RealmRegisteredInfo.needUpdateUser(messageObject.forwardedMessage.userId, null)) {
if (!updateForwardInfo.containsKey(messageObject.forwardedMessage.userId)) {
updateForwardInfo.put(messageObject.forwardedMessage.userId, messageObject.id + "");
}
}
} else {
RealmRoom realmRoom = DbManager.getInstance().doRealmTask(realm -> {
return realm.where(RealmRoom.class).equalTo("id", messageObject.forwardedMessage.roomId).findFirst();
});
if (realmRoom != null) {
txtForwardFrom.setText(EmojiManager.getInstance().replaceEmoji(realmRoom.getTitle(), txtForwardFrom.getPaint().getFontMetricsInt()));
txtForwardFrom.setTextColor(theme.getForwardFromTextColor(txtForwardFrom.getContext()));
switch(realmRoom.getType()) {
case CHANNEL:
messageObject.username = realmRoom.getChannelRoom() != null ? realmRoom.getChannelRoom().getUsername() : "";
break;
case GROUP:
messageObject.username = realmRoom.getGroupRoom() != null ? realmRoom.getGroupRoom().getUsername() : "";
break;
}
} else {
if (realmRoomForwardedFrom != null) {
switch(realmRoomForwardedFrom.getType()) {
case CHANNEL:
if (realmRoomForwardedFrom.getChannelRoom() != null && realmRoomForwardedFrom.getChannelRoom().getUsername() != null) {
messageObject.username = realmRoomForwardedFrom.getChannelRoom().getUsername();
} else {
messageObject.username = holder.itemView.getResources().getString(R.string.private_channel);
}
break;
case GROUP:
messageObject.username = realmRoomForwardedFrom.getGroupRoom().getUsername();
break;
}
if (RealmRoom.needUpdateRoomInfo(realmRoomForwardedFrom.getId())) {
if (!updateForwardInfo.containsKey(realmRoomForwardedFrom.getId())) {
updateForwardInfo.put(realmRoomForwardedFrom.getId(), messageObject.id + "");
}
}
txtForwardFrom.setText(EmojiManager.getInstance().replaceEmoji(realmRoomForwardedFrom.getTitle(), txtForwardFrom.getPaint().getFontMetricsInt()));
txtForwardFrom.setTextColor(theme.getForwardFromTextColor(txtForwardFrom.getContext()));
} else {
if (RealmRoom.needUpdateRoomInfo(messageObject.forwardedMessage.roomId)) {
if (!updateForwardInfo.containsKey(messageObject.forwardedMessage.roomId)) {
updateForwardInfo.put(messageObject.forwardedMessage.roomId, messageObject.id + "");
}
}
}
}
}
// must call measure!
txtPrefixForwardFrom.measure(0, 0);
txtForwardFrom.measure(0, 0);
int maxWith = txtPrefixForwardFrom.getMeasuredWidth() + txtForwardFrom.getMeasuredWidth() + i_Dp(R.dimen.dp32);
if (minWith < maxWith) {
minWith = maxWith;
}
mHolder.getContentBloke().setMinimumWidth(Math.min(minWith, G.maxChatBox));
mHolder.getContentBloke().addView(forwardView, 0, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
}
}
use of net.iGap.realm.RealmRoom in project iGap-Android by KianIranian-STDG.
the class AbstractMessage method setMessage.
public AbstractMessage setMessage(MessageObject message) {
// TODO: 12/29/20 MESSAGE_REFACTOR
messageObject = message;
attachment = messageObject.getAttachment();
additional = messageObject.getAdditional();
if ((messageObject.forwardedMessage != null)) {
long messageId = messageObject.forwardedMessage.id;
if (messageObject.forwardedMessage.id < 0) {
messageId = messageId * (-1);
}
DbManager.getInstance().doRealmTask(realm -> {
RealmRoom realmRoomForwardedFrom22 = realm.where(RealmRoom.class).equalTo("id", messageObject.forwardedMessage.roomId).findFirst();
if (realmRoomForwardedFrom22 != null && realmRoomForwardedFrom22.isValid())
realmRoomForwardedFrom = realm.copyFromRealm(realmRoomForwardedFrom22);
});
} else {
realmRoomForwardedFrom = null;
}
if (messageObject.forwardedMessage != null) {
myText = new SpannableString(messageObject.forwardedMessage.message);
} else if (messageObject.message != null) {
myText = new SpannableString(messageObject.message);
} else {
myText = new SpannableString("");
}
updateMessageText();
return AbstractMessage.this;
}
use of net.iGap.realm.RealmRoom in project iGap-Android by KianIranian-STDG.
the class RoomListAdapter method createListener.
@Override
protected OrderedRealmCollectionChangeListener<RealmResults<RealmRoom>> createListener() {
return (OrderedRealmCollectionChangeListener<RealmResults<RealmRoom>>) (collection, changeSet) -> {
if (G.onUnreadChange != null) {
int unreadCount = 0;
for (RealmRoom room : collection) {
if (!room.getMute() && !room.isDeleted() && room.getUnreadCount() > 0) {
unreadCount += room.getUnreadCount();
}
}
G.onUnreadChange.onChange(unreadCount, false);
}
callBack.needShowEmptyView(getData() == null || getData().size() <= 0);
if (changeSet.getState() == OrderedCollectionChangeSet.State.INITIAL) {
callBack.needShowLoadProgress(false);
notifyDataSetChanged();
return;
}
// For deletions, the adapter has to be notified in reverse order.
OrderedCollectionChangeSet.Range[] deletions = changeSet.getDeletionRanges();
for (int i = deletions.length - 1; i >= 0; i--) {
OrderedCollectionChangeSet.Range range = deletions[i];
notifyItemRangeRemoved(range.startIndex, range.length);
}
if (deletions.length > 0 && selectedRoom.size() > 0) {
selectedRoom.clear();
callBack.needCheckMultiSelect();
}
OrderedCollectionChangeSet.Range[] insertions = changeSet.getInsertionRanges();
for (OrderedCollectionChangeSet.Range range : insertions) {
notifyItemRangeInserted(range.startIndex, range.length);
}
if (!updateOnModification) {
return;
}
OrderedCollectionChangeSet.Range[] modifications = changeSet.getChangeRanges();
for (OrderedCollectionChangeSet.Range range : modifications) {
notifyItemRangeChanged(range.startIndex, range.length);
}
};
}
use of net.iGap.realm.RealmRoom in project iGap-Android by KianIranian-STDG.
the class ResendMessage method resend.
private void resend(final boolean all) {
if (!RequestManager.getInstance(AccountManager.selectedAccount).isUserLogin()) {
return;
}
DbManager.getInstance().doRealmTask(realm -> {
realm.executeTransactionAsync(new Realm.Transaction() {
@Override
public void execute(Realm realm) {
for (MessageObject message : mMessages) {
if (all) {
RealmRoomMessage.setStatus(realm, message.id, ProtoGlobal.RoomMessageStatus.SENDING);
} else {
if (message.id == mSelectedMessageID) {
RealmRoomMessage.setStatus(realm, message.id, ProtoGlobal.RoomMessageStatus.SENDING);
break;
}
}
}
}
}, () -> {
if (all) {
mListener.resendAllMessages();
} else {
mListener.resendMessage();
}
for (int i = 0; i < mMessages.size(); i++) {
final int j = i;
if (all) {
if (FragmentChat.allowResendMessage(mMessages.get(j).id)) {
G.handler.postDelayed(new Runnable() {
@Override
public void run() {
DbManager.getInstance().doRealmTask(realm1 -> {
RealmRoomMessage roomMessage = realm1.where(RealmRoomMessage.class).equalTo("messageId", mMessages.get(j).id).findFirst();
MessageObject resendMessageObject = MessageObject.create(roomMessage);
if (resendMessageObject != null) {
RealmRoom realmRoom = realm1.where(RealmRoom.class).equalTo("id", resendMessageObject.roomId).findFirst();
if (realmRoom != null) {
if (resendMessageObject.attachment == null) {
ProtoGlobal.Room.Type roomType = realmRoom.getType();
ChatSendMessageUtil.getInstance(AccountManager.selectedAccount).build(roomType, resendMessageObject.roomId, resendMessageObject);
} else {
if (resendMessageObject.additional != null && resendMessageObject.additional.type == 4) {
ChatSendMessageUtil.getInstance(AccountManager.selectedAccount).build(realmRoom.getType(), resendMessageObject.roomId, resendMessageObject);
} else {
RealmRoomMessage message = realm.copyFromRealm(roomMessage);
UploadObject fileObject = UploadObject.createForMessage(message, realmRoom.getType());
if (fileObject != null) {
Uploader.getInstance().upload(fileObject);
}
}
}
}
}
});
}
}, 1000 * j);
}
} else {
if (mMessages.get(j).id == mSelectedMessageID) {
if (FragmentChat.allowResendMessage(mSelectedMessageID)) {
RealmRoomMessage roomMessage = realm.where(RealmRoomMessage.class).equalTo("messageId", mMessages.get(j).id).findFirst();
MessageObject resendMessageObject = MessageObject.create(roomMessage);
if (resendMessageObject != null) {
RealmRoom realmRoom = realm.where(RealmRoom.class).equalTo("id", resendMessageObject.roomId).findFirst();
if (realmRoom != null) {
ProtoGlobal.Room.Type roomType = realmRoom.getType();
if (resendMessageObject.attachment == null) {
ChatSendMessageUtil.getInstance(AccountManager.selectedAccount).build(roomType, resendMessageObject.roomId, resendMessageObject);
} else {
if (resendMessageObject.additional != null && resendMessageObject.additional.type == 4) {
ChatSendMessageUtil.getInstance(AccountManager.selectedAccount).build(realmRoom.getType(), resendMessageObject.roomId, resendMessageObject);
} else {
RealmRoomMessage message = realm.copyFromRealm(roomMessage);
UploadObject fileObject = UploadObject.createForMessage(message, realmRoom.getType());
if (fileObject != null) {
Uploader.getInstance().upload(fileObject);
}
}
}
}
}
break;
}
}
}
}
});
});
}
use of net.iGap.realm.RealmRoom in project iGap-Android by KianIranian-STDG.
the class FragmentContactsProfileViewModel method mainStart.
private void mainStart() {
if (enterFrom.equals(ProtoGlobal.Room.Type.GROUP.toString()) || roomId == 0) {
RealmRoom realmRoom = DbManager.getInstance().doRealmTask(realm -> {
return realm.where(RealmRoom.class).equalTo("chatRoom.peer_id", userId).findFirst();
});
if (realmRoom != null) {
shearedId = realmRoom.getId();
}
} else {
shearedId = roomId;
}
if (!RealmRoom.isNotificationServices(roomId)) {
isShowReportView.set(true);
} else {
isShowReportView.set(false);
}
if (userId == AccountManager.getInstance().getCurrentUser().getId()) {
cloudVisibility.postValue(true);
} else
cloudVisibility.postValue(false);
registeredInfo = DbManager.getInstance().doRealmTask(realm -> {
return RealmRegisteredInfo.getRegistrationInfo(realm, userId);
});
if (registeredInfo != null) {
registeredInfo.addChangeListener((RealmObjectChangeListener<RealmRegisteredInfo>) (realmModel, changeSet) -> {
if (changeSet != null) {
for (int i = 0; i < changeSet.getChangedFields().length; i++) {
if (changeSet.getChangedFields()[i].equals("blockUser")) {
userBlockState.set(realmModel.isBlockUser() ? R.string.un_block_user : R.string.block);
}
}
}
});
isBot = registeredInfo.isBot();
if (isBot || userId == AccountManager.getInstance().getCurrentUser().getId()) {
callVisibility.setValue(View.GONE);
menuVisibility.setValue(View.GONE);
videoCallVisibility.setValue(View.GONE);
} else {
callVisibility.setValue(View.VISIBLE);
menuVisibility.setValue(View.VISIBLE);
videoCallVisibility.setValue(View.VISIBLE);
}
isBlockUser = registeredInfo.isBlockUser();
userBlockState.set(isBlockUser ? R.string.un_block_user : R.string.block);
registeredInfo.addChangeListener(element -> isBlockUser = registeredInfo.isBlockUser());
DbManager.getInstance().doRealmTask(realm -> {
if (registeredInfo.getLastAvatar(realm) != null) {
String mainFilePath = registeredInfo.getLastAvatar(realm).getFile().getLocalFilePath();
if (mainFilePath != null && new File(mainFilePath).exists()) {
// if main image is exist showing that
avatarPath = mainFilePath;
} else {
avatarPath = registeredInfo.getLastAvatar(realm).getFile().getLocalThumbnailPath();
}
avatarList = registeredInfo.getAvatars(realm);
}
});
}
RealmContacts realmUser = DbManager.getInstance().doRealmTask(realm -> {
return realm.where(RealmContacts.class).equalTo("id", userId).findFirst();
});
if (registeredInfo != null) {
if (registeredInfo.getDisplayName() != null && !registeredInfo.getDisplayName().equals("")) {
contactName.setValue(registeredInfo.getDisplayName());
} else {
contactName.setValue(G.fragmentActivity.getResources().getString(R.string.nick_name_not_exist));
}
if (registeredInfo.getBio() == null || registeredInfo.getBio().length() == 0) {
bioVisibility.set(View.GONE);
} else {
bioVisibility.set(View.VISIBLE);
bio.set(registeredInfo.getBio());
}
username.set(registeredInfo.getUsername());
phone.set(registeredInfo.getPhoneNumber());
phoneNumber = "+" + registeredInfo.getPhoneNumber();
firstName = registeredInfo.getFirstName();
lastName = registeredInfo.getLastName();
lastSeenValue = registeredInfo.getLastSeen();
color = registeredInfo.getColor();
initials = registeredInfo.getInitials();
userStatus = registeredInfo.getStatus();
isVerified = registeredInfo.isVerified();
} else if (realmUser != null) {
if (realmUser.getDisplay_name() != null && !realmUser.getDisplay_name().equals("")) {
contactName.setValue(realmUser.getDisplay_name());
} else {
contactName.setValue(G.fragmentActivity.getResources().getString(R.string.nick_name_not_exist));
}
username.set(realmUser.getUsername());
phone.set(Long.toString(realmUser.getPhone()));
phoneNumber = "+" + realmUser.getPhone();
firstName = realmUser.getFirst_name();
lastName = realmUser.getLast_name();
lastSeenValue = realmUser.getLast_seen();
color = realmUser.getColor();
initials = realmUser.getInitials();
isVerified = realmUser.isVerified();
if (realmUser.getBio() == null || realmUser.getBio().length() == 0) {
bioVisibility.set(View.GONE);
} else {
bioVisibility.set(View.VISIBLE);
bio.set(realmUser.getBio());
}
}
if (isVerified) {
verifyTextVisibility.set(View.VISIBLE);
} else {
verifyTextVisibility.set(View.INVISIBLE);
}
// todo: fixed it two times check it and first and her
if (userId != 134 && AccountManager.getInstance().getCurrentUser().getId() != userId) {
RealmCallConfig callConfig = DbManager.getInstance().doRealmTask(realm -> {
return realm.where(RealmCallConfig.class).findFirst();
});
if (callConfig != null) {
if (isBot) {
callVisibility.setValue(View.GONE);
videoCallVisibility.setValue(View.GONE);
} else {
if (callConfig.isVoice_calling()) {
callVisibility.setValue(View.VISIBLE);
}
if (callConfig.isVideo_calling()) {
videoCallVisibility.setValue(View.VISIBLE);
}
}
} else {
new RequestSignalingGetConfiguration().signalingGetConfiguration();
}
} else {
callVisibility.setValue(View.GONE);
videoCallVisibility.setValue(View.GONE);
}
RealmContacts realmContacts = DbManager.getInstance().doRealmTask(realm -> {
return realm.where(RealmContacts.class).equalTo("phone", Long.parseLong(phone.get())).findFirst();
});
/**
* if this user isn't in my contacts don't show phone number
*/
if (realmContacts == null && enterFrom.equals(ProtoGlobal.Room.Type.GROUP.toString())) {
showNumber.set(false);
disableDeleteContact = true;
menuVisibility.setValue(View.GONE);
}
if (!G.isAppRtl) {
textsGravity.set(Gravity.LEFT);
} else {
textsGravity.set(Gravity.RIGHT);
}
setUserStatus(userStatus, lastSeenValue);
setAvatar.setValue(userId != AccountManager.getInstance().getCurrentUser().getId());
// todo: change it
FragmentShearedMedia.getCountOfSharedMedia(shearedId);
if (registeredInfo == null) {
callVisibility.setValue(View.GONE);
menuVisibility.setValue(View.GONE);
videoCallVisibility.setValue(View.GONE);
}
}
Aggregations