use of net.iGap.realm.RealmRoom in project iGap-Android by KianIranian-STDG.
the class MessageDataStorage method deleteRoomFromStorage.
public void deleteRoomFromStorage(long roomId) {
storageQueue.postRunnable(() -> {
FileLog.i(TAG, "deleteRoomFromStorage: " + roomId);
try {
database.beginTransaction();
RealmRoom realmRoom = database.where(RealmRoom.class).equalTo("id", roomId).findFirst();
if (realmRoom != null) {
realmRoom.deleteFromRealm();
}
database.where(RealmClientCondition.class).equalTo("roomId", roomId).findAll().deleteAllFromRealm();
database.where(RealmRoomMessage.class).equalTo("roomId", roomId).findAll().deleteAllFromRealm();
database.commitTransaction();
} catch (Exception e) {
FileLog.e(e);
}
});
}
use of net.iGap.realm.RealmRoom in project iGap-Android by KianIranian-STDG.
the class MessageDataStorage method updateRoomAddedStory.
public void updateRoomAddedStory(final List<ProtoGlobal.Story> stories) {
storageQueue.postRunnable(() -> {
FileLog.i(TAG, "updateRoomAddedStory roomId " + stories.get(0).getRoomId() + " storiesId " + stories.get(0).getId());
try {
database.beginTransaction();
RealmRoom realmRoom = database.where(RealmRoom.class).equalTo("id", stories.get(0).getRoomId()).findFirst();
if (realmRoom != null && realmRoom.getTitle() != null) {
RealmStory realmStory;
if (stories.get(0).getUserId() == AccountManager.getInstance().getCurrentUser().getId()) {
realmStory = database.where(RealmStory.class).equalTo("sessionId", AccountManager.getInstance().getCurrentUser().getId()).equalTo("userId", stories.get(0).getUserId()).findFirst();
} else {
realmStory = database.where(RealmStory.class).equalTo("sessionId", AccountManager.getInstance().getCurrentUser().getId()).equalTo("roomId", stories.get(0).getRoomId()).findFirst();
}
if (realmStory == null) {
realmStory = database.createObject(RealmStory.class, SUID.id().get());
}
List<StoryObject> storyObjects = new ArrayList<>();
for (int i = 0; i < stories.size(); i++) {
if (stories.get(i).getTypeValue() == 0) {
StoryObject storyObject = StoryObject.create(stories.get(i), i, realmRoom.getTitle(), realmRoom != null ? realmRoom.getColor() : "#4aca69", true, realmRoom.getType() == ProtoGlobal.Room.Type.CHANNEL && realmRoom.getChannelRoom().isVerified());
storyObjects.add(storyObject);
}
}
realmStory.setLastCreatedAt(storyObjects.get(storyObjects.size() - 1).createdAt);
realmStory.setDisplayName(realmRoom.getTitle());
realmStory.setProfileColor(realmRoom.getColor());
realmStory.setSessionId(AccountManager.getInstance().getCurrentUser().getId());
if (stories.get(0).getUserId() != AccountManager.getInstance().getCurrentUser().getId()) {
realmStory.setUserId(0);
realmStory.setOrginatorValue(1);
realmStory.setVerified(realmRoom.getType() == ProtoGlobal.Room.Type.CHANNEL && realmRoom.getChannelRoom().isVerified());
} else {
realmStory.setUserId(AccountManager.getInstance().getCurrentUser().getId());
}
realmStory.setRoomId(stories.get(0).getRoomId());
realmStory.setSeenAll(false);
realmStory.setRealmStoryProtos(database, storyObjects);
int[] storyUnReadCount = new int[1];
RealmResults<RealmStory> otherStories = database.where(RealmStory.class).equalTo("sessionId", AccountManager.getInstance().getCurrentUser().getId()).notEqualTo("userId", AccountManager.getInstance().getCurrentUser().getId()).equalTo("isSeenAll", false).findAll();
if (otherStories != null && otherStories.size() > 0) {
storyUnReadCount[0] = otherStories.size();
} else {
storyUnReadCount[0] = 0;
}
database.commitTransaction();
G.runOnUiThread(() -> {
if (G.onUnreadChange != null) {
G.onUnreadChange.onChange(storyUnReadCount[0], true);
}
getEventManager().postEvent(EventManager.STORY_USER_ADD_NEW);
});
} else {
new RequestClientGetRoom().clientGetRoom(stories.get(0).getRoomId(), RequestClientGetRoom.CreateRoomMode.justInfo);
}
} catch (Exception e) {
FileLog.e(e);
}
});
}
use of net.iGap.realm.RealmRoom in project iGap-Android by KianIranian-STDG.
the class MessageDataStorage method getRoom.
public RealmRoom getRoom(final long roomId) {
FileLog.i(TAG, "getRoom: " + roomId);
final CountDownLatch countDownLatch = new CountDownLatch(1);
final RealmRoom[] result = new RealmRoom[1];
storageQueue.postRunnable(() -> {
try {
RealmRoom realmRoom = database.where(RealmRoom.class).equalTo("id", roomId).findFirst();
if (realmRoom != null) {
result[0] = database.copyFromRealm(realmRoom);
}
countDownLatch.countDown();
} catch (Exception e) {
FileLog.e(e);
} finally {
countDownLatch.countDown();
}
});
try {
countDownLatch.await();
} catch (Exception e) {
FileLog.e(e);
}
Log.e(TAG, "getRoom: " + (result[0] != null ? result[0].getTitle() : "NULL"));
return result[0];
}
use of net.iGap.realm.RealmRoom in project iGap-Android by KianIranian-STDG.
the class MessageController method clearHistoryMessage.
public void clearHistoryMessage(final long roomId) {
if (roomId > 0) {
RealmRoom realmRoom = getMessageDataStorage().getRoom(roomId);
long clearMessageId;
if (realmRoom == null || !realmRoom.isLoaded() || !realmRoom.isValid()) {
return;
}
if (realmRoom.getLastMessage() != null) {
clearMessageId = realmRoom.getLastMessage().getMessageId();
} else {
clearMessageId = getMessageDataStorage().getRoomClearId(roomId);
}
if (clearMessageId == 0) {
return;
}
getMessageDataStorage().setRoomClearId(roomId, clearMessageId, true);
AbstractObject req = null;
if (realmRoom.getType() == ProtoGlobal.Room.Type.CHAT) {
IG_RPC.Chat_Clear_History historyReq = new IG_RPC.Chat_Clear_History();
historyReq.roomId = roomId;
historyReq.lastMessageId = clearMessageId;
req = historyReq;
} else if (realmRoom.getType() == ProtoGlobal.Room.Type.GROUP) {
IG_RPC.Group_Clear_History historyReq = new IG_RPC.Group_Clear_History();
historyReq.roomId = roomId;
historyReq.lastMessageId = clearMessageId;
req = historyReq;
}
getRequestManager().sendRequest(req, (response, error) -> {
if (error == null) {
long clearId = 0;
if (response instanceof IG_RPC.Res_Chat_Clear_History) {
IG_RPC.Res_Chat_Clear_History resClearMessage = (IG_RPC.Res_Chat_Clear_History) response;
clearId = resClearMessage.clearId;
} else if (response instanceof IG_RPC.Res_Group_Clear_History) {
IG_RPC.Res_Group_Clear_History resClearMessage = (IG_RPC.Res_Group_Clear_History) response;
clearId = resClearMessage.clearId;
}
getMessageDataStorage().clearRoomHistory(roomId, clearId);
}
});
}
}
use of net.iGap.realm.RealmRoom in project iGap-Android by KianIranian-STDG.
the class HelperUrl method goToActivity.
private static void goToActivity(FragmentActivity activity, final long roomId, final long peerId, ChatEntry chatEntry, final long messageId) {
switch(chatEntry) {
case chat:
if (roomId != FragmentChat.lastChatRoomId) {
DbManager.getInstance().doRealmTask(new DbManager.RealmTask() {
@Override
public void doTask(Realm realm) {
final RealmRoom realmRoom = realm.where(RealmRoom.class).equalTo("chatRoom.peer_id", peerId).findFirst();
if (realmRoom != null) {
new GoToChatActivity(realmRoom.getId()).setMessageID(messageId).startActivity(activity);
} else {
G.onChatGetRoom = new OnChatGetRoom() {
@Override
public void onChatGetRoom(final ProtoGlobal.Room room) {
DbManager.getInstance().doRealmTransaction(realm2 -> {
if (realm2.where(RealmRoom.class).equalTo("id", room.getId()).findFirst() == null) {
RealmRoom realmRoom1 = RealmRoom.putOrUpdate(room, realm2);
realmRoom1.setDeleted(true);
} else {
RealmRoom.putOrUpdate(room, realm2);
}
});
G.handler.postDelayed(new Runnable() {
@Override
public void run() {
new GoToChatActivity(room.getId()).setPeerID(peerId).startActivity(activity);
G.onChatGetRoom = null;
}
}, 500);
}
@Override
public void onChatGetRoomTimeOut() {
}
@Override
public void onChatGetRoomError(int majorCode, int minorCode) {
}
};
new RequestChatGetRoom().chatGetRoom(peerId);
}
}
});
}
break;
case profile:
G.handler.post(new Runnable() {
@Override
public void run() {
FragmentContactsProfile contactsProfile = new FragmentContactsProfile();
Bundle bundle = new Bundle();
bundle.putLong("peerId", peerId);
bundle.putLong("RoomId", roomId);
bundle.putString("enterFrom", GROUP.toString());
contactsProfile.setArguments(bundle);
new HelperFragment(activity.getSupportFragmentManager(), contactsProfile).setReplace(false).load();
}
});
break;
}
}
Aggregations