use of com.fanap.podchat.cachemodel.CacheParticipantRoles in project pod-chat-android-sdk by FanapSoft.
the class MessageDatabaseHelper method saveParticipant.
public void saveParticipant(@NonNull CacheParticipant participant, long threadId, int expireSecond) {
worker(() -> {
participant.setThreadId(threadId);
SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss", Locale.getDefault());
Calendar c = Calendar.getInstance();
c.setTime(new Date());
c.add(Calendar.SECOND, expireSecond);
String expireDate = format.format(c.getTime());
messageDao.insertParticipant(participant);
CacheThreadParticipant ctp = new CacheThreadParticipant();
ctp.setExpireDate(expireDate);
ctp.setParticipantId(participant.getId());
ctp.setThreadId(threadId);
messageDao.insertThreadParticipant(ctp);
if (!Util.isNullOrEmpty(participant.getRoles())) {
CacheParticipantRoles cpr = new CacheParticipantRoles();
cpr.setId(participant.getId());
cpr.setThreadId(threadId);
cpr.setRoles(participant.getRoles());
Log.d("MTAG", "SAVE CPR: " + cpr);
messageDao.insertRoles(cpr);
}
if (participant.getChatProfileVO() != null) {
ChatProfileVO chatProfileVO = participant.getChatProfileVO();
chatProfileVO.setId(participant.getId());
messageDao.insertChatProfile(chatProfileVO);
}
});
}
use of com.fanap.podchat.cachemodel.CacheParticipantRoles in project pod-chat-android-sdk by FanapSoft.
the class MessageDatabaseHelper method saveParticipants.
/**
* Cache participant
*/
public void saveParticipants(@NonNull List<CacheParticipant> participants, long threadId, int expireSecond) {
worker(() -> {
for (CacheParticipant participant : participants) {
participant.setThreadId(threadId);
SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss", Locale.getDefault());
Calendar c = Calendar.getInstance();
c.setTime(new Date());
c.add(Calendar.SECOND, expireSecond);
String expireDate = format.format(c.getTime());
messageDao.insertParticipant(participant);
CacheThreadParticipant ctp = new CacheThreadParticipant();
ctp.setExpireDate(expireDate);
ctp.setParticipantId(participant.getId());
ctp.setThreadId(threadId);
messageDao.insertThreadParticipant(ctp);
if (!Util.isNullOrEmpty(participant.getRoles())) {
CacheParticipantRoles cpr = new CacheParticipantRoles();
cpr.setId(participant.getId());
cpr.setThreadId(threadId);
cpr.setRoles(participant.getRoles());
Log.d("MTAG", "SAVE CPR: " + cpr);
messageDao.insertRoles(cpr);
}
if (participant.getChatProfileVO() != null) {
ChatProfileVO chatProfileVO = participant.getChatProfileVO();
chatProfileVO.setId(participant.getId());
messageDao.insertChatProfile(chatProfileVO);
}
}
});
}
use of com.fanap.podchat.cachemodel.CacheParticipantRoles in project pod-chat-android-sdk by FanapSoft.
the class MessageDatabaseHelper method getThreadAdmins.
public void getThreadAdmins(long offset, long count, long threadId, FunctionalListener listener) throws RoomIntegrityException {
if (!canUseDatabase())
throw new RoomIntegrityException();
worker(() -> {
List<Participant> participants = new ArrayList<>();
List<CacheThreadParticipant> listCtp = messageDao.getAllThreadParticipants(offset, count, threadId);
long participantCount = messageDao.getParticipantCount(threadId);
if (listCtp == null) {
listener.onWorkDone(participantCount, participants);
} else {
SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss", Locale.getDefault());
Calendar c = Calendar.getInstance();
c.setTime(new Date());
Date nowDate = c.getTime();
for (CacheThreadParticipant threadParticipant : listCtp) {
try {
Date expireDate = format.parse(threadParticipant.getExpireDate());
long participantId = threadParticipant.getParticipantId();
if (expireDate != null) {
if (expireDate.compareTo(nowDate) < 0) {
messageDao.deleteCacheThreadParticipant(participantId);
} else {
CacheParticipant cParticipant = messageDao.getParticipant(participantId);
ChatProfileVO chatProfileVO = messageDao.getChatProfileVOById(cParticipant.getId());
if (chatProfileVO != null) {
cParticipant.setChatProfileVO(chatProfileVO);
}
List<String> roles = new ArrayList<>();
CacheParticipantRoles cachedRoles = messageDao.getParticipantRoles(participantId, threadId);
if (cachedRoles != null) {
if (cachedRoles.getRoles().size() > 0)
roles = cachedRoles.getRoles();
}
if (roles.size() > 0) {
Participant participant = cacheToParticipantMapper(cParticipant, true, roles);
participants.add(participant);
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
listener.onWorkDone(participantCount, participants);
});
}
use of com.fanap.podchat.cachemodel.CacheParticipantRoles in project pod-chat-android-sdk by FanapSoft.
the class MessageDatabaseHelper method updateParticipantRoles.
/**
* Participants have expire date after expTime that you can set it manually
*/
public void updateParticipantRoles(long participantId, long threadId, List<String> roles) {
worker(() -> {
CacheParticipantRoles cpr = new CacheParticipantRoles();
cpr.setId(participantId);
cpr.setThreadId(threadId);
cpr.setRoles(roles);
messageDao.insertRoles(cpr);
});
}
Aggregations