Skip to content

Commit

Permalink
regression: add updateLastOpen function to update the last open date …
Browse files Browse the repository at this point in the history
…of a subscription (#5737)

* regression: add updateLastOpen function to update the last open date of a subscription

* 💅

* chore: remove try catch
  • Loading branch information
dnlsilva authored and diegolmello committed Jun 12, 2024
1 parent 8f22564 commit 658b526
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
3 changes: 2 additions & 1 deletion app/lib/methods/subscriptions/room.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { IDDPMessage } from '../../../definitions/IDDPMessage';
import sdk from '../../services/sdk';
import { readMessages } from '../readMessages';
import { loadMissedMessages } from '../loadMissedMessages';
import { updateLastOpen } from '../updateLastOpen';

const WINDOW_TIME = 1000;

Expand Down Expand Up @@ -74,7 +75,7 @@ export default class RoomSubscription {

unsubscribe = async () => {
console.log(`[RCRN] Unsubscribing from room ${this.rid}`);
readMessages(this.rid, new Date(), true).catch(e => console.log(e));
updateLastOpen(this.rid);
this.isAlive = false;
reduxStore.dispatch(unsubscribeRoom(this.rid));
if (this.promises) {
Expand Down
17 changes: 17 additions & 0 deletions app/lib/methods/updateLastOpen.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import database from '../database';
import log from './helpers/log';
import { TSubscriptionModel } from '../../definitions';

export async function updateLastOpen(rid: string, lastOpen = new Date()): Promise<void> {
try {
const db = database.active;
const subscription = await db.get('subscriptions').find(rid);
await db.write(async () => {
await subscription.update((s: TSubscriptionModel) => {
s.lastOpen = lastOpen;
});
});
} catch (e) {
log(e);
}
}

0 comments on commit 658b526

Please sign in to comment.