[FIX] Loading all updated rooms after app resume (#1998)
* [FIX] Loading all updated rooms after app resume * Fix room date on RoomItem Co-authored-by: Diego Mello <diegolmello@gmail.com>
This commit is contained in:
parent
c24c16c932
commit
78441bf345
|
@ -0,0 +1,78 @@
|
||||||
|
import { Q } from '@nozbe/watermelondb';
|
||||||
|
|
||||||
|
import database from '../../database';
|
||||||
|
|
||||||
|
export default async(subscriptions = [], rooms = []) => {
|
||||||
|
try {
|
||||||
|
const db = database.active;
|
||||||
|
const subCollection = db.collections.get('subscriptions');
|
||||||
|
|
||||||
|
const roomIds = rooms.filter(r => !subscriptions.find(s => s.rid === r._id)).map(r => r._id);
|
||||||
|
let existingSubs = await subCollection.query(Q.where('rid', Q.oneOf(roomIds))).fetch();
|
||||||
|
existingSubs = existingSubs.map(s => ({
|
||||||
|
_id: s._id,
|
||||||
|
f: s.f,
|
||||||
|
t: s.t,
|
||||||
|
ts: s.ts,
|
||||||
|
ls: s.ls,
|
||||||
|
name: s.name,
|
||||||
|
fname: s.fname,
|
||||||
|
rid: s.rid,
|
||||||
|
open: s.open,
|
||||||
|
alert: s.alert,
|
||||||
|
unread: s.unread,
|
||||||
|
userMentions: s.userMentions,
|
||||||
|
roomUpdatedAt: s.roomUpdatedAt,
|
||||||
|
ro: s.ro,
|
||||||
|
lastOpen: s.lastOpen,
|
||||||
|
description: s.description,
|
||||||
|
announcement: s.announcement,
|
||||||
|
topic: s.topic,
|
||||||
|
blocked: s.blocked,
|
||||||
|
blocker: s.blocker,
|
||||||
|
reactWhenReadOnly: s.reactWhenReadOnly,
|
||||||
|
archived: s.archived,
|
||||||
|
joinCodeRequired: s.joinCodeRequired,
|
||||||
|
muted: s.muted,
|
||||||
|
broadcast: s.broadcast,
|
||||||
|
prid: s.prid,
|
||||||
|
draftMessage: s.draftMessage,
|
||||||
|
lastThreadSync: s.lastThreadSync,
|
||||||
|
jitsiTimeout: s.jitsiTimeout,
|
||||||
|
autoTranslate: s.autoTranslate,
|
||||||
|
autoTranslateLanguage: s.autoTranslateLanguage,
|
||||||
|
lastMessage: s.lastMessage,
|
||||||
|
usernames: s.usernames,
|
||||||
|
uids: s.uids
|
||||||
|
}));
|
||||||
|
subscriptions = subscriptions.concat(existingSubs);
|
||||||
|
|
||||||
|
const subsIds = subscriptions.filter(s => !rooms.find(r => s.rid === r._id)).map(s => s._id);
|
||||||
|
let existingRooms = await subCollection.query(Q.where('id', Q.oneOf(subsIds))).fetch();
|
||||||
|
existingRooms = existingRooms.map(r => ({
|
||||||
|
_updatedAt: r._updatedAt,
|
||||||
|
lastMessage: r.lastMessage,
|
||||||
|
description: r.description,
|
||||||
|
topic: r.topic,
|
||||||
|
announcement: r.announcement,
|
||||||
|
reactWhenReadOnly: r.reactWhenReadOnly,
|
||||||
|
archived: r.archived,
|
||||||
|
joinCodeRequired: r.joinCodeRequired,
|
||||||
|
jitsiTimeout: r.jitsiTimeout,
|
||||||
|
usernames: r.usernames,
|
||||||
|
uids: r.uids,
|
||||||
|
ro: r.ro,
|
||||||
|
broadcast: r.broadcast,
|
||||||
|
muted: r.muted,
|
||||||
|
sysMes: r.sysMes
|
||||||
|
}));
|
||||||
|
rooms = rooms.concat(existingRooms);
|
||||||
|
} catch {
|
||||||
|
// do nothing
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
subscriptions,
|
||||||
|
rooms
|
||||||
|
};
|
||||||
|
};
|
|
@ -1,6 +1,7 @@
|
||||||
import EJSON from 'ejson';
|
import EJSON from 'ejson';
|
||||||
|
|
||||||
import normalizeMessage from './normalizeMessage';
|
import normalizeMessage from './normalizeMessage';
|
||||||
|
import findSubscriptionsRooms from './findSubscriptionsRooms';
|
||||||
// TODO: delete and update
|
// TODO: delete and update
|
||||||
|
|
||||||
export const merge = (subscription, room) => {
|
export const merge = (subscription, room) => {
|
||||||
|
@ -46,11 +47,14 @@ export const merge = (subscription, room) => {
|
||||||
return subscription;
|
return subscription;
|
||||||
};
|
};
|
||||||
|
|
||||||
export default (subscriptions = [], rooms = []) => {
|
export default async(subscriptions = [], rooms = []) => {
|
||||||
if (subscriptions.update) {
|
if (subscriptions.update) {
|
||||||
subscriptions = subscriptions.update;
|
subscriptions = subscriptions.update;
|
||||||
rooms = rooms.update;
|
rooms = rooms.update;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
({ subscriptions, rooms } = await findSubscriptionsRooms(subscriptions, rooms));
|
||||||
|
|
||||||
return {
|
return {
|
||||||
subscriptions: subscriptions.map((s) => {
|
subscriptions: subscriptions.map((s) => {
|
||||||
const index = rooms.findIndex(({ _id }) => _id === s.rid);
|
const index = rooms.findIndex(({ _id }) => _id === s.rid);
|
||||||
|
|
|
@ -49,7 +49,7 @@ const RoomItem = React.memo(({
|
||||||
}
|
}
|
||||||
}, [connected]);
|
}, [connected]);
|
||||||
|
|
||||||
const date = formatDate(_updatedAt);
|
const date = lastMessage && formatDate(lastMessage.ts);
|
||||||
|
|
||||||
let accessibilityLabel = name;
|
let accessibilityLabel = name;
|
||||||
if (unread === 1) {
|
if (unread === 1) {
|
||||||
|
|
|
@ -41,7 +41,7 @@ const handleRoomsRequest = function* handleRoomsRequest({ params }) {
|
||||||
({ roomsUpdatedAt } = serverRecord);
|
({ roomsUpdatedAt } = serverRecord);
|
||||||
}
|
}
|
||||||
const [subscriptionsResult, roomsResult] = yield RocketChat.getRooms(roomsUpdatedAt);
|
const [subscriptionsResult, roomsResult] = yield RocketChat.getRooms(roomsUpdatedAt);
|
||||||
const { subscriptions } = mergeSubscriptionsRooms(subscriptionsResult, roomsResult);
|
const { subscriptions } = yield mergeSubscriptionsRooms(subscriptionsResult, roomsResult);
|
||||||
|
|
||||||
const db = database.active;
|
const db = database.active;
|
||||||
const subCollection = db.collections.get('subscriptions');
|
const subCollection = db.collections.get('subscriptions');
|
||||||
|
|
Loading…
Reference in New Issue