use of com.fanap.podchat.mainmodel.PinMessageVO in project pod-chat-android-sdk by FanapSoft.
the class MessageDatabaseHelper method addPinnedMessageOfThread.
private void addPinnedMessageOfThread(ThreadVo threadVo) {
worker(() -> {
PinMessageVO pinnedMessage = messageDao.getThreadPinnedMessage(threadVo.getId());
if (pinnedMessage != null) {
// get cached participant
if (pinnedMessage.getParticipantId() > 0) {
CacheParticipant cacheParticipant = messageDao.getParticipant(pinnedMessage.getParticipantId());
if (cacheParticipant != null) {
// convert cached participant to participant
Participant participant = cacheToParticipantMapper(cacheParticipant, false, null);
pinnedMessage.setParticipant(participant);
}
}
threadVo.setPinMessageVO(pinnedMessage);
}
});
}
use of com.fanap.podchat.mainmodel.PinMessageVO in project pod-chat-android-sdk by FanapSoft.
the class MessageDatabaseHelper method insertPinnedMessage.
private void insertPinnedMessage(Thread thread) {
PinMessageVO pinMessageVO = thread.getPinMessageVO();
pinMessageVO.setThreadId(thread.getId());
try {
Participant participant = pinMessageVO.getParticipant();
if (participant != null) {
String participantJson = App.getGson().toJson(participant);
CacheParticipant cacheParticipant = App.getGson().fromJson(participantJson, CacheParticipant.class);
messageDao.insertParticipant(cacheParticipant);
pinMessageVO.setParticipantId(cacheParticipant.getId());
}
} catch (Exception e) {
e.printStackTrace();
}
messageDao.insertPinnedMessage(pinMessageVO);
}
use of com.fanap.podchat.mainmodel.PinMessageVO in project pod-chat-android-sdk by FanapSoft.
the class MessageDatabaseHelper method savePinMessage.
public void savePinMessage(ChatResponse<ResultPinMessage> response, long subjectId) {
worker(() -> {
ResultPinMessage result = response.getResult();
PinMessageVO pinMessageVO = new PinMessageVO();
pinMessageVO.setThreadId(subjectId);
pinMessageVO.setMessageId(result.getMessageId());
pinMessageVO.setNotifyAll(result.isNotifyAll());
pinMessageVO.setText(result.getText());
pinMessageVO.setTime(result.getTime());
if (result.getParticipant() != null) {
Participant participant = result.getParticipant();
String participantJson = App.getGson().toJson(participant);
CacheParticipant cacheParticipant = App.getGson().fromJson(participantJson, CacheParticipant.class);
messageDao.insertParticipant(cacheParticipant);
pinMessageVO.setParticipantId(cacheParticipant.getId());
}
messageDao.insertPinnedMessage(pinMessageVO);
});
}
use of com.fanap.podchat.mainmodel.PinMessageVO in project pod-chat-android-sdk by FanapSoft.
the class MessageDatabaseHelper method deleteMessage.
public void deleteMessage(long id, long subjectId) {
// if this message is thread last message
// get previous message and then delete this
// then set previous message as last message
worker(() -> {
if (subjectId > 0) {
ThreadVo threadVo = messageDao.getThreadById(subjectId);
if (threadVo != null) {
long threadLastMessageId = threadVo.getLastMessageVOId();
if (threadLastMessageId == id && threadLastMessageId > 0) {
// this is last message
List<CacheMessageVO> cacheMessage = messageDao.getMessage(id);
if (!Util.isNullOrEmpty(cacheMessage)) {
long previousMessageId = cacheMessage.get(0).getPreviousId();
// Get previous message
List<CacheMessageVO> previousMessage = messageDao.getMessage(previousMessageId);
if (!Util.isNullOrEmpty(previousMessage)) {
String message = previousMessage.get(0).getMessage();
messageDao.updateThreadLastMessageVOId(subjectId, previousMessageId, message);
}
}
}
}
// delete from pinned message
PinMessageVO pinnedMessage = messageDao.getThreadPinnedMessage(subjectId);
if (pinnedMessage != null && pinnedMessage.getMessageId() == id) {
messageDao.deletePinnedMessageById(id);
}
}
messageDao.deleteMessage(id);
});
}
Aggregations