use of net.iGap.request.RequestClientGetRoom in project iGap-Android by KianIranian-STDG.
the class HelperMember method addMember.
public static void addMember(long roomId, long userId, String role) {
if (userId == AccountManager.getInstance().getCurrentUser().getId()) {
new RequestClientGetRoom().clientGetRoom(roomId, null);
} else {
RealmMember.addMember(roomId, userId, role);
RealmRoom.updateMemberCount(roomId, true);
}
}
use of net.iGap.request.RequestClientGetRoom in project iGap-Android by KianIranian-STDG.
the class MessageDataStorage method updateUserAddedStoryWithStoryObjects.
public void updateUserAddedStoryWithStoryObjects(final List<ProtoStoryGetStories.GroupedStories> stories) {
storageQueue.postRunnable(() -> {
try {
database.beginTransaction();
List<StoryObject> storyObjects = new ArrayList<>();
if (stories.size() > 0 && stories.size() >= database.where(RealmStory.class).equalTo("sessionId", AccountManager.getInstance().getCurrentUser().getId()).findAll().size()) {
for (int i = 0; i < stories.size(); i++) {
if (stories.get(i).getStoriesList().size() > 0) {
RealmRegisteredInfo realmRegisteredInfo = database.where(RealmRegisteredInfo.class).equalTo("id", stories.get(i).getOriginatorId()).findFirst();
boolean isForRoom = false;
RealmRoom realmRoom = null;
for (int j = 0; j < stories.get(i).getStoriesList().size(); j++) {
if (stories.get(i).getStoriesList().get(j).getRoomId() != 0) {
realmRoom = database.where(RealmRoom.class).equalTo("id", stories.get(i).getStoriesList().get(j).getRoomId()).findFirst();
isForRoom = true;
if (realmRoom == null) {
new RequestClientGetRoom().clientGetRoom(stories.get(i).getStoriesList().get(j).getRoomId(), RequestClientGetRoom.CreateRoomMode.justInfo);
}
} else {
isForRoom = false;
}
storyObjects.add(StoryObject.create(stories.get(i).getStoriesList().get(j), j, stories.get(i).getSelf() && isForRoom && realmRoom != null ? realmRoom.getTitle() : stories.get(i).getOriginatorName(), !stories.get(i).getSelf() && isForRoom ? realmRoom != null ? realmRoom.getColor() : "#4aca69" : realmRegisteredInfo != null ? realmRegisteredInfo.getColor() : "#4aca69", isForRoom, isForRoom && realmRoom != null && realmRoom.getType() == ProtoGlobal.Room.Type.CHANNEL && realmRoom.getChannelRoom().isVerified()));
}
putStoriesToDatabase(database, stories.get(i).getSeenAllGroupStories(), stories.get(i).getOriginatorId(), storyObjects, stories.get(i).getOriginatorName(), realmRegisteredInfo != null ? realmRegisteredInfo.getColor() : "#4aca69", stories.get(i).getOriginatorValue(), !stories.get(i).getSelf() && stories.get(i).getOriginatorValue() == 1 && (realmRoom != null && realmRoom.getType() == ProtoGlobal.Room.Type.CHANNEL) && realmRoom.getChannelRoom().isVerified());
storyObjects.removeAll(storyObjects);
} else {
RealmStory realmStory = database.where(RealmStory.class).equalTo("sessionId", AccountManager.getInstance().getCurrentUser().getId()).equalTo("userId", stories.get(i).getOriginatorId()).findFirst();
if (realmStory != null) {
realmStory.deleteFromRealm();
}
}
}
} else if (stories.size() != 0 && stories.size() < database.where(RealmStory.class).equalTo("sessionId", AccountManager.getInstance().getCurrentUser().getId()).findAll().size()) {
boolean isExist = false;
List<RealmStory> realmStories = database.where(RealmStory.class).equalTo("sessionId", AccountManager.getInstance().getCurrentUser().getId()).findAll();
if (realmStories != null && realmStories.size() > 0) {
for (int i = 0; i < realmStories.size(); i++) {
for (int j = 0; j < stories.size(); j++) {
if (stories.get(j).getOriginatorValue() == 0) {
if (realmStories.get(i).getUserId() == stories.get(j).getOriginatorId()) {
isExist = true;
break;
}
} else {
if (realmStories.get(i).getRoomId() == stories.get(j).getOriginatorId()) {
isExist = true;
break;
}
}
}
if (!isExist) {
long userId = realmStories.get(i).getUserId();
long roomId = realmStories.get(i).getRoomId();
int orginatorValue = realmStories.get(i).getOrginatorValue();
RealmStory realmStory = database.where(RealmStory.class).equalTo("sessionId", AccountManager.getInstance().getCurrentUser().getId()).equalTo(realmStories.get(i).getOrginatorValue() == 0 ? "userId" : "roomId", realmStories.get(i).getOrginatorValue() == 0 ? userId : roomId).findFirst();
if (realmStory != null && realmStory.isSentAll()) {
realmStory.deleteFromRealm();
}
RealmResults<RealmStoryProto> realmStoryProtos = database.where(RealmStoryProto.class).equalTo("sessionId", AccountManager.getInstance().getCurrentUser().getId()).equalTo("isForReply", false).equalTo(orginatorValue == 0 ? "userId" : "roomId", userId).equalTo("status", MessageObject.STATUS_SENT).findAll();
if (realmStoryProtos != null && realmStoryProtos.size() > 0) {
for (int y = 0; y < realmStoryProtos.size(); y++) {
if (realmStoryProtos.get(y).getFile() != null) {
String filepath = realmStoryProtos.get(y).getFile().getLocalFilePath() != null ? realmStoryProtos.get(y).getFile().getLocalFilePath() : AndroidUtils.getFilePathWithCashId(realmStoryProtos.get(y).getFile().getCacheId(), realmStoryProtos.get(y).getFile().getName(), ProtoGlobal.RoomMessageType.STORY);
if (filepath != null) {
File file = new File(filepath);
if (file.exists())
file.delete();
}
}
}
realmStoryProtos.deleteAllFromRealm();
}
}
isExist = false;
}
}
for (int i = 0; i < stories.size(); i++) {
if (stories.get(i).getStoriesList().size() > 0) {
RealmRegisteredInfo realmRegisteredInfo = database.where(RealmRegisteredInfo.class).equalTo("id", stories.get(i).getOriginatorId()).findFirst();
boolean isForRoom = false;
RealmRoom realmRoom = null;
for (int j = 0; j < stories.get(i).getStoriesList().size(); j++) {
if (stories.get(i).getStoriesList().get(j).getRoomId() != 0) {
realmRoom = database.where(RealmRoom.class).equalTo("id", stories.get(i).getStoriesList().get(j).getRoomId()).findFirst();
isForRoom = true;
if (realmRoom == null) {
new RequestClientGetRoom().clientGetRoom(stories.get(i).getStoriesList().get(j).getRoomId(), RequestClientGetRoom.CreateRoomMode.justInfo);
}
} else {
isForRoom = false;
}
storyObjects.add(StoryObject.create(stories.get(i).getStoriesList().get(j), j, stories.get(i).getSelf() && isForRoom && realmRoom != null ? realmRoom.getTitle() : stories.get(i).getOriginatorName(), !stories.get(i).getSelf() && isForRoom ? realmRoom != null ? realmRoom.getColor() : "#4aca69" : realmRegisteredInfo != null ? realmRegisteredInfo.getColor() : "#4aca69", isForRoom, isForRoom && realmRoom != null && realmRoom.getType() == ProtoGlobal.Room.Type.CHANNEL && realmRoom.getChannelRoom().isVerified()));
}
putStoriesToDatabase(database, stories.get(i).getSeenAllGroupStories(), stories.get(i).getOriginatorId(), storyObjects, stories.get(i).getOriginatorName(), realmRegisteredInfo != null ? realmRegisteredInfo.getColor() : "#4aca69", stories.get(i).getOriginatorValue(), !stories.get(i).getSelf() && stories.get(i).getOriginatorValue() == 1 && (realmRoom != null && realmRoom.getType() == ProtoGlobal.Room.Type.CHANNEL) && realmRoom.getChannelRoom().isVerified());
storyObjects.removeAll(storyObjects);
} else {
RealmStory realmStory = database.where(RealmStory.class).equalTo("sessionId", AccountManager.getInstance().getCurrentUser().getId()).equalTo("userId", stories.get(i).getOriginatorId()).findFirst();
if (realmStory != null) {
realmStory.deleteFromRealm();
}
}
}
} else if (stories.size() == 0) {
RealmResults<RealmStoryProto> realmStoryProtos = database.where(RealmStoryProto.class).equalTo("sessionId", AccountManager.getInstance().getCurrentUser().getId()).equalTo("isForReply", false).equalTo("status", MessageObject.STATUS_SENT).findAll();
if (realmStoryProtos != null && realmStoryProtos.size() > 0) {
for (int y = 0; y < realmStoryProtos.size(); y++) {
if (realmStoryProtos.get(y).getFile() != null) {
String filepath = realmStoryProtos.get(y).getFile().getLocalFilePath() != null ? realmStoryProtos.get(y).getFile().getLocalFilePath() : AndroidUtils.getFilePathWithCashId(realmStoryProtos.get(y).getFile().getCacheId(), realmStoryProtos.get(y).getFile().getName(), ProtoGlobal.RoomMessageType.STORY);
if (filepath != null) {
File file = new File(filepath);
if (file.exists())
file.delete();
}
}
}
realmStoryProtos.deleteAllFromRealm();
}
List<RealmStory> realmStories = database.where(RealmStory.class).equalTo("sessionId", AccountManager.getInstance().getCurrentUser().getId()).findAll();
if (realmStories != null && realmStories.size() > 0) {
for (int i = 0; i < realmStories.size(); i++) {
if (realmStories.get(i).getRealmStoryProtos().size() == 0) {
database.where(RealmStory.class).equalTo("sessionId", AccountManager.getInstance().getCurrentUser().getId()).equalTo("userId", realmStories.get(i).getUserId()).findAll().deleteAllFromRealm();
}
}
}
}
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();
UserLoginResponse.isFetched = true;
G.runOnUiThread(() -> {
if (G.onUnreadChange != null) {
G.onUnreadChange.onChange(storyUnReadCount[0], true);
}
StoryFragment.storyListFetched = false;
getEventManager().postEvent(EventManager.STORY_LIST_FETCHED);
});
} catch (Exception e) {
Log.e("Fskhfjksdhjkshdf", "updateUserAddedStoryWithStoryObjects: " + "/" + e.getMessage());
FileLog.e(e);
}
});
}
use of net.iGap.request.RequestClientGetRoom in project iGap-Android by KianIranian-STDG.
the class MessageController method onUpdate.
public void onUpdate(AbstractObject object) {
if (object == null) {
return;
}
FileLog.i(TAG, "onUpdate " + object);
if (object instanceof IG_RPC.Res_Channel_Avatar) {
IG_RPC.Res_Channel_Avatar channelAvatar = (IG_RPC.Res_Channel_Avatar) object;
updateChannelAvatarInternal(channelAvatar);
} else if (object instanceof IG_RPC.Res_Group_Create) {
IG_RPC.Res_Group_Create res = (IG_RPC.Res_Group_Create) object;
new RequestClientGetRoom().clientGetRoom(res.roomId, RequestClientGetRoom.CreateRoomMode.requestFromOwner);
} else if (object instanceof IG_RPC.Res_Channel_Create) {
IG_RPC.Res_Channel_Create res = (IG_RPC.Res_Channel_Create) object;
new RequestClientGetRoom().clientGetRoom(res.roomId, RequestClientGetRoom.CreateRoomMode.requestFromOwner);
} else if (object instanceof IG_RPC.Res_Channel_Delete) {
IG_RPC.Res_Channel_Delete res = (IG_RPC.Res_Channel_Delete) object;
getMessageDataStorage().deleteRoomFromStorage(res.roomId);
} else if (object instanceof IG_RPC.Res_Group_Edit_Message || object instanceof IG_RPC.Res_Chat_Edit_Message || object instanceof IG_RPC.Res_Channel_Edit_Message) {
onMessageEditResponse(object, true);
} else if (object instanceof IG_RPC.Group_pin_message_response || object instanceof IG_RPC.Channel_pin_message_response) {
onPinMessageResponse(object);
} else if (object instanceof IG_RPC.Res_Chat_Delete_Message) {
IG_RPC.Res_Chat_Delete_Message res = (IG_RPC.Res_Chat_Delete_Message) object;
onDeleteMessageResponse(res, true);
} else if (object instanceof IG_RPC.Res_Group_Delete_Message) {
IG_RPC.Res_Group_Delete_Message res = (IG_RPC.Res_Group_Delete_Message) object;
onDeleteMessageResponse(res, true);
} else if (object instanceof IG_RPC.Res_Channel_Delete_Message) {
IG_RPC.Res_Channel_Delete_Message res = (IG_RPC.Res_Channel_Delete_Message) object;
onDeleteMessageResponse(res, true);
} else if (object instanceof IG_RPC.Res_Chat_Update_Status || object instanceof IG_RPC.Res_Group_Update_Status) {
onMessageStatusResponse(object, true);
} else if (object instanceof IG_RPC.Res_Story_User_Add_New) {
onUserAddStoryResponse(object, true);
} else if (object instanceof IG_RPC.Res_Story_Delete) {
onUserDeletedStoryResponse(object, true);
} else if (object instanceof IG_RPC.Res_Story_Add_View) {
onUserStoryAddViewResponse(object, true);
} else if (object instanceof IG_RPC.Res_Story_Room_Add_New) {
onRoomAddStoryResponse(object, true);
}
}
Aggregations