use of net.iGap.realm.RealmRoom in project iGap-Android by KianIranian-STDG.
the class GoToChatActivity method startActivity.
public void startActivity(FragmentActivity activity) {
String roomName = "";
if (FragmentChat.mForwardMessages != null || HelperGetDataFromOtherApp.hasSharedData || FragmentChat.structIGSticker != null) {
roomName = DbManager.getInstance().doRealmTask(realm -> {
RealmRoom realmRoom = realm.where(RealmRoom.class).equalTo("id", roomid).findFirst();
if (realmRoom != null) {
if (realmRoom.getReadOnly() || hasSendMessagePermission() || (realmRoom.getType() != ProtoGlobal.Room.Type.CHAT && FragmentChat.structIGSticker != null) || (realmRoom.getType() == ProtoGlobal.Room.Type.CHAT && realmRoom.getChatRoom() != null && RealmRoom.isBot(realmRoom.getChatRoom().getPeerId()))) {
if (activity != null && !(activity).isFinishing()) {
new MaterialDialog.Builder(activity).title(R.string.dialog_readonly_chat).positiveText(R.string.ok).show();
}
return null;
}
return realmRoom.getTitle();
} else if (peerID > 0) {
RealmRegisteredInfo _RegisteredInfo = RealmRegisteredInfo.getRegistrationInfo(realm, peerID);
if (_RegisteredInfo != null) {
return _RegisteredInfo.getDisplayName();
}
}
return "";
});
if (roomName == null) {
return;
}
}
if (HelperGetDataFromOtherApp.hasSharedData) {
String message = G.context.getString(R.string.send_message_to) + " " + roomName;
MaterialDialog.Builder mDialog = new MaterialDialog.Builder(activity).title(message).positiveText(R.string.ok).negativeText(R.string.cancel).onPositive(new MaterialDialog.SingleButtonCallback() {
@Override
public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
FragmentChat fragmentChat = new FragmentChat();
fragmentChat.setArguments(getBundle());
fragmentChatBackStack(activity);
new HelperFragment(activity.getSupportFragmentManager(), fragmentChat).setReplace(false).load();
}
}).onNegative((dialog, which) -> {
HelperGetDataFromOtherApp.hasSharedData = false;
// revert main rooms list from share mode
if (activity instanceof ActivityMain) {
((ActivityMain) activity).checkHasSharedData(false);
}
}).neutralText(R.string.another_room).onNeutral((dialog, which) -> dialog.dismiss());
if (!activity.isFinishing()) {
mDialog.show();
}
} else if (FragmentChat.structIGSticker != null) {
String message = G.context.getString(R.string.send_message_to) + " " + roomName;
MaterialDialog.Builder mDialog = new MaterialDialog.Builder(activity).title(message).positiveText(R.string.ok).negativeText(R.string.cancel).onPositive((dialog, which) -> {
FragmentChat fragmentChat = new FragmentChat();
fragmentChat.setArguments(getBundle());
fragmentChatBackStack(activity);
new HelperFragment(activity.getSupportFragmentManager(), fragmentChat).setReplace(false).load();
}).onNegative((dialog, which) -> {
FragmentChat.structIGSticker = null;
if (activity instanceof ActivityMain) {
((ActivityMain) activity).checkHasSharedData(false);
}
}).neutralText(R.string.another_room).onNeutral((dialog, which) -> dialog.dismiss());
if (!activity.isFinishing()) {
mDialog.show();
}
} else if (FragmentChat.mForwardMessages != null) {
String message = G.context.getString(R.string.send_forward_to) + " " + roomName + "?";
MaterialDialog.Builder mDialog = new MaterialDialog.Builder(activity).title(message).positiveText(R.string.ok).negativeText(R.string.cancel).onPositive(new MaterialDialog.SingleButtonCallback() {
@Override
public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
loadChatFragment(activity);
}
}).onNegative((dialog, which) -> {
disableForwardMessage(activity);
FragmentChat.mForwardMessages = null;
}).neutralText(R.string.another_room).onNeutral((dialog, which) -> dialog.dismiss());
if (!(activity).isFinishing()) {
mDialog.show();
}
} else {
loadChatFragment(activity);
}
}
use of net.iGap.realm.RealmRoom in project iGap-Android by KianIranian-STDG.
the class BotInit method checkDrIgap.
public static void checkDrIgap() {
if (!BotInit.getCheckDrIgap())
return;
new RequestClientGetPromote().getPromote();
G.ipromote = new Ipromote() {
@Override
public void onGetPromoteResponse(ProtoClientGetPromote.ClientGetPromoteResponse.Builder builder) {
setCheckDrIgap(false);
ArrayList<Long> promoteIds = new ArrayList<>();
for (int i = 0; i < builder.getPromoteList().size(); i++) promoteIds.add(builder.getPromoteList().get(i).getId());
DbManager.getInstance().doRealmTask(realm -> {
realm.executeTransaction(new Realm.Transaction() {
@Override
public void execute(Realm realm) {
RealmResults<RealmRoom> roomList = realm.where(RealmRoom.class).equalTo("isFromPromote", true).findAll();
for (RealmRoom room : roomList) {
if (!promoteIds.contains(room.getPromoteId())) {
room.setFromPromote(false);
RoomController.getInstance(AccountManager.selectedAccount).clientPinRoom(room.getId(), false);
}
}
}
});
for (int i = builder.getPromoteList().size() - 1; i >= 0; i--) {
ProtoClientGetPromote.ClientGetPromoteResponse.Promote.Type TYPE = builder.getPromoteList().get(i).getType();
RealmRoom realmRoom;
if (TYPE == ProtoClientGetPromote.ClientGetPromoteResponse.Promote.Type.USER) {
realmRoom = realm.where(RealmRoom.class).equalTo("chatRoom.peer_id", builder.getPromoteList().get(i).getId()).equalTo("isFromPromote", true).findFirst();
} else {
realmRoom = realm.where(RealmRoom.class).equalTo("id", builder.getPromoteList().get(i).getId()).equalTo("isFromPromote", true).findFirst();
}
if (realmRoom == null) {
if (TYPE == ProtoClientGetPromote.ClientGetPromoteResponse.Promote.Type.USER) {
// RealmRoom.setPromote(builder.getPromoteList().get(i).getId(), TYPE);
G.onChatGetRoom = new OnChatGetRoom() {
@Override
public void onChatGetRoom(final ProtoGlobal.Room room) {
G.onChatGetRoom = null;
DbManager.getInstance().doRealmTransaction(realm1 -> {
RealmRoom realmRoom1 = RealmRoom.putOrUpdate(room, realm1);
realmRoom1.setFromPromote(true);
realmRoom1.setPromoteId(realmRoom1.getChatRoom().getPeerId());
// RealmRoom.setPromote(2297310L, ProtoClientGetPromote.ClientGetPromoteResponse.Promote.Type.USER);
});
RoomController.getInstance(AccountManager.selectedAccount).clientPinRoom(room.getId(), true);
ActivityPopUpNotification.sendMessage("/start", room.getId(), ProtoGlobal.Room.Type.CHAT);
}
@Override
public void onChatGetRoomTimeOut() {
}
@Override
public void onChatGetRoomError(int majorCode, int minorCode) {
}
};
new RequestChatGetRoom().chatGetRoom(builder.getPromoteList().get(i).getId());
} else {
new RequestClientGetRoom().clientGetRoom(builder.getPromoteList().get(i).getId(), RequestClientGetRoom.CreateRoomMode.getPromote);
}
} else {
RoomController.getInstance(AccountManager.selectedAccount).clientPinRoom(realmRoom.getId(), true);
}
}
});
}
};
}
use of net.iGap.realm.RealmRoom in project iGap-Android by KianIranian-STDG.
the class AppUtils method updateBadgeOnly.
public static int[] updateBadgeOnly(Realm realm, long roomId) {
int unreadMessageCount = 0;
int chatCount = 0;
int[] result = new int[2];
RealmResults<RealmRoom> realmRooms = realm.where(RealmRoom.class).equalTo("keepRoom", false).equalTo("mute", false).equalTo("isDeleted", false).notEqualTo("id", roomId).findAll();
for (RealmRoom realmRoom1 : realmRooms) {
if (realmRoom1.getUnreadCount() > 0) {
unreadMessageCount += realmRoom1.getUnreadCount();
++chatCount;
}
}
try {
ShortcutBadger.applyCount(G.context, unreadMessageCount);
} catch (Exception e) {
e.printStackTrace();
}
result[0] = unreadMessageCount;
result[1] = chatCount;
return result;
}
use of net.iGap.realm.RealmRoom 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.RealmRoom in project iGap-Android by KianIranian-STDG.
the class ClientGetRoomResponse method handler.
@Override
public void handler() {
super.handler();
final ProtoClientGetRoom.ClientGetRoomResponse.Builder clientGetRoom = (ProtoClientGetRoom.ClientGetRoomResponse.Builder) message;
DbManager.getInstance().doRealmTransaction(realm -> {
final RequestClientGetRoom.IdentityClientGetRoom identityClientGetRoom = ((RequestClientGetRoom.IdentityClientGetRoom) identity);
final RequestClientGetRoom.CreateRoomMode roomMode = identityClientGetRoom.createRoomMode;
if (roomMode != null && roomMode == RequestClientGetRoom.CreateRoomMode.justInfo) {
if (!RealmRoom.isMainRoom(clientGetRoom.getRoom().getId())) {
RealmRoom realmRoom = RealmRoom.putOrUpdate(clientGetRoom.getRoom(), realm);
realmRoom.setDeleted(true);
realmRoom.setKeepRoom(true);
}
/**
* update log message in realm room message after get room info
*/
if (HelperLogMessage.logMessageUpdateList.containsKey(clientGetRoom.getRoom().getId())) {
G.handler.postDelayed(new Runnable() {
@Override
public void run() {
HelperLogMessage.updateLogMessageAfterGetUserInfo(clientGetRoom.getRoom().getId());
}
}, 500);
}
return;
}
if (roomMode != null && roomMode == RequestClientGetRoom.CreateRoomMode.getPromote) {
if (!RealmRoom.isMainRoom(clientGetRoom.getRoom().getId())) {
RealmRoom realmRoom = RealmRoom.putOrUpdate(clientGetRoom.getRoom(), realm);
realmRoom.setFromPromote(true);
realmRoom.setPromoteId(clientGetRoom.getRoom().getId());
realmRoom.setDeleted(true);
realmRoom.setKeepRoom(false);
if (clientGetRoom.getRoom().hasChannelRoomExtra()) {
new RequestClientJoinByUsername().clientJoinByUsername(clientGetRoom.getRoom().getChannelRoomExtra().getPublicExtra().getUsername(), clientGetRoom.getRoom().getId());
} else {
new RequestClientJoinByUsername().clientJoinByUsername(clientGetRoom.getRoom().getGroupRoomExtra().getPublicExtra().getUsername(), clientGetRoom.getRoom().getId());
}
//
}
return;
}
if (clientGetRoom.getRoom().getType() == ProtoGlobal.Room.Type.CHAT) {
new HelperGetUserInfo(new OnGetUserInfo() {
@Override
public void onGetUserInfo(ProtoGlobal.RegisteredUser registeredUser) {
new Handler(Looper.getMainLooper()).post(new Runnable() {
@Override
public void run() {
DbManager.getInstance().doRealmTask(realm1 -> {
realm1.executeTransactionAsync(new Realm.Transaction() {
@Override
public void execute(Realm realm1) {
putOrUpdate(clientGetRoom.getRoom(), realm1);
}
}, new Realm.Transaction.OnSuccess() {
@Override
public void onSuccess() {
if (G.onClientGetRoomResponse != null) {
G.onClientGetRoomResponse.onClientGetRoomResponse(clientGetRoom.getRoom(), clientGetRoom, identityClientGetRoom);
}
}
});
});
}
});
}
}).getUserInfo(clientGetRoom.getRoom().getChatRoomExtra().getPeer().getId());
} else {
putOrUpdate(clientGetRoom.getRoom(), realm);
G.handler.postDelayed(new Runnable() {
@Override
public void run() {
if (G.onClientGetRoomResponse != null) {
G.onClientGetRoomResponse.onClientGetRoomResponse(clientGetRoom.getRoom(), clientGetRoom, identityClientGetRoom);
}
}
}, 500);
}
});
MessageDataStorage.getInstance(AccountManager.selectedAccount).storySetDisplayName(clientGetRoom.getRoom().getId(), clientGetRoom.getRoom().getTitle(), clientGetRoom.getRoom().getType() == ProtoGlobal.Room.Type.CHANNEL && clientGetRoom.getRoom().getChannelRoomExtra().getVerified());
// update chat message header forward after get user or room info
if (AbstractMessage.updateForwardInfo != null) {
if (AbstractMessage.updateForwardInfo.containsKey(clientGetRoom.getRoom().getId())) {
String messageId = AbstractMessage.updateForwardInfo.get(clientGetRoom.getRoom().getId());
AbstractMessage.updateForwardInfo.remove(clientGetRoom.getRoom().getId());
if (FragmentChat.onUpdateUserOrRoomInfo != null) {
FragmentChat.onUpdateUserOrRoomInfo.onUpdateUserOrRoomInfo(messageId);
}
}
}
}
Aggregations