use of org.matrix.androidsdk.rest.model.ReceiptData in project matrix-android-sdk by matrix-org.
the class MXFileStore method saveReceipts.
/**
* Flush the events receipts
*
* @param roomId the roomId.
*/
private void saveReceipts(final String roomId) {
synchronized (mRoomReceiptsToLoad) {
// please wait
if (mRoomReceiptsToLoad.contains(roomId)) {
return;
}
}
final List<ReceiptData> receipts;
synchronized (mReceiptsByRoomIdLock) {
if (mReceiptsByRoomId.containsKey(roomId)) {
receipts = new ArrayList<>(mReceiptsByRoomId.get(roomId).values());
} else {
receipts = null;
}
}
// sanity check
if (null == receipts) {
return;
}
Runnable r = new Runnable() {
@Override
public void run() {
mFileStoreHandler.post(new Runnable() {
public void run() {
if (!mIsKilled) {
long start = System.currentTimeMillis();
writeObject("saveReceipts " + roomId, new File(mStoreRoomsMessagesReceiptsFolderFile, roomId), receipts);
Log.d(LOG_TAG, "saveReceipts : roomId " + roomId + " eventId : " + (System.currentTimeMillis() - start) + " ms");
}
}
});
}
};
Thread t = new Thread(r);
t.start();
}
use of org.matrix.androidsdk.rest.model.ReceiptData in project matrix-android-sdk by matrix-org.
the class MXDataHandler method deleteRoom.
/**
* Delete a room from its room id.
* The room data is copied into the left rooms store.
*
* @param roomId the room id
*/
public void deleteRoom(String roomId) {
// copy the room from a store to another one
Room r = this.getStore().getRoom(roomId);
if (null != r) {
if (mAreLeftRoomsSynced) {
Room leftRoom = getRoom(mLeftRoomsStore, roomId, true);
leftRoom.setIsLeft(true);
// copy the summary
RoomSummary summary = getStore().getSummary(roomId);
if (null != summary) {
mLeftRoomsStore.storeSummary(new RoomSummary(summary, summary.getLatestReceivedEvent(), summary.getLatestRoomState(), getUserId()));
}
// copy events and receiptData
// it is not required but it is better, it could be useful later
// the room summary should be enough to be displayed in the recent pages
ArrayList<ReceiptData> receipts = new ArrayList<>();
Collection<Event> events = getStore().getRoomMessages(roomId);
if (null != events) {
for (Event e : events) {
receipts.addAll(getStore().getEventReceipts(roomId, e.eventId, false, false));
mLeftRoomsStore.storeLiveRoomEvent(e);
}
for (ReceiptData receipt : receipts) {
mLeftRoomsStore.storeReceipt(receipt, roomId);
}
}
// copy the state
leftRoom.getLiveTimeLine().setState(r.getLiveTimeLine().getState());
}
// remove the previous definition
getStore().deleteRoom(roomId);
}
}
use of org.matrix.androidsdk.rest.model.ReceiptData in project matrix-android-sdk by matrix-org.
the class MXMemoryStore method unreadEvents.
/**
* Provides the unread events list.
*
* @param roomId the room id.
* @param types an array of event types strings (Event.EVENT_TYPE_XXX).
* @return the unread events list.
*/
@Override
public List<Event> unreadEvents(String roomId, List<String> types) {
List<Event> res = null;
synchronized (mReceiptsByRoomIdLock) {
if (mReceiptsByRoomId.containsKey(roomId)) {
Map<String, ReceiptData> receiptsByUserId = mReceiptsByRoomId.get(roomId);
if (receiptsByUserId.containsKey(mCredentials.userId)) {
ReceiptData data = receiptsByUserId.get(mCredentials.userId);
res = eventsAfter(roomId, data.eventId, mCredentials.userId, types);
}
}
}
if (null == res) {
res = new ArrayList<>();
}
return res;
}
use of org.matrix.androidsdk.rest.model.ReceiptData in project matrix-android-sdk by matrix-org.
the class MXMemoryStore method isEventRead.
/**
* Check if an event has been read by an user.
*
* @param roomId the room Id
* @param userId the user id
* @param eventIdTotest the event id
* @return true if the user has read the message.
*/
@Override
public boolean isEventRead(String roomId, String userId, String eventIdTotest) {
boolean res = false;
// sanity check
if ((null != roomId) && (null != userId)) {
synchronized (mReceiptsByRoomIdLock) {
synchronized (mRoomEventsLock) {
if (mReceiptsByRoomId.containsKey(roomId) && mRoomEvents.containsKey(roomId)) {
Map<String, ReceiptData> receiptsByUserId = mReceiptsByRoomId.get(roomId);
LinkedHashMap<String, Event> eventsMap = mRoomEvents.get(roomId);
// check if the event is known
if (eventsMap.containsKey(eventIdTotest) && receiptsByUserId.containsKey(userId)) {
ReceiptData data = receiptsByUserId.get(userId);
ArrayList<String> eventIds = new ArrayList<>(eventsMap.keySet());
// the message has been read if it was sent before the latest read one
res = eventIds.indexOf(eventIdTotest) <= eventIds.indexOf(data.eventId);
} else if (receiptsByUserId.containsKey(userId)) {
// the event is not known so assume it is has been flushed
res = true;
}
}
}
}
}
return res;
}
use of org.matrix.androidsdk.rest.model.ReceiptData in project matrix-android-sdk by matrix-org.
the class MXMemoryStore method getEventReceipts.
/**
* Returns the receipts list for an event in a dedicated room.
* if sort is set to YES, they are sorted from the latest to the oldest ones.
*
* @param roomId The room Id.
* @param eventId The event Id. (null to retrieve all existing receipts)
* @param excludeSelf exclude the oneself read receipts.
* @param sort to sort them from the latest to the oldest
* @return the receipts for an event in a dedicated room.
*/
@Override
public List<ReceiptData> getEventReceipts(String roomId, String eventId, boolean excludeSelf, boolean sort) {
ArrayList<ReceiptData> receipts = new ArrayList<>();
synchronized (mReceiptsByRoomIdLock) {
if (mReceiptsByRoomId.containsKey(roomId)) {
String myUserID = mCredentials.userId;
Map<String, ReceiptData> receiptsByUserId = mReceiptsByRoomId.get(roomId);
// copy the user id list to avoid having update while looping
ArrayList<String> userIds = new ArrayList<>(receiptsByUserId.keySet());
if (null == eventId) {
receipts.addAll(receiptsByUserId.values());
} else {
for (String userId : userIds) {
if (receiptsByUserId.containsKey(userId) && (!excludeSelf || !TextUtils.equals(myUserID, userId))) {
ReceiptData receipt = receiptsByUserId.get(userId);
if (TextUtils.equals(receipt.eventId, eventId)) {
receipts.add(receipt);
}
}
}
}
}
}
if (sort && (receipts.size() > 0)) {
Collections.sort(receipts, ReceiptData.descComparator);
}
return receipts;
}
Aggregations