[FIX] Pending update (#2066)
Co-authored-by: Diego Mello <diegolmello@gmail.com>
This commit is contained in:
parent
a34929fb9b
commit
56dc7243dd
|
@ -160,22 +160,17 @@ export default class RoomSubscription {
|
||||||
const msgCollection = db.collections.get('messages');
|
const msgCollection = db.collections.get('messages');
|
||||||
const threadsCollection = db.collections.get('threads');
|
const threadsCollection = db.collections.get('threads');
|
||||||
const threadMessagesCollection = db.collections.get('thread_messages');
|
const threadMessagesCollection = db.collections.get('thread_messages');
|
||||||
let messageRecord;
|
|
||||||
let threadRecord;
|
|
||||||
let threadMessageRecord;
|
|
||||||
|
|
||||||
// Create or update message
|
// Create or update message
|
||||||
try {
|
try {
|
||||||
messageRecord = await msgCollection.find(message._id);
|
const messageRecord = await msgCollection.find(message._id);
|
||||||
} catch (error) {
|
if (!messageRecord._hasPendingUpdate) {
|
||||||
// Do nothing
|
const update = messageRecord.prepareUpdate(protectedFunction((m) => {
|
||||||
}
|
Object.assign(m, message);
|
||||||
if (messageRecord) {
|
}));
|
||||||
const update = messageRecord.prepareUpdate((m) => {
|
this._messagesBatch[message._id] = update;
|
||||||
Object.assign(m, message);
|
}
|
||||||
});
|
} catch {
|
||||||
this._messagesBatch[message._id] = update;
|
|
||||||
} else {
|
|
||||||
const create = msgCollection.prepareCreate(protectedFunction((m) => {
|
const create = msgCollection.prepareCreate(protectedFunction((m) => {
|
||||||
m._raw = sanitizedRaw({ id: message._id }, msgCollection.schema);
|
m._raw = sanitizedRaw({ id: message._id }, msgCollection.schema);
|
||||||
m.subscription.id = this.rid;
|
m.subscription.id = this.rid;
|
||||||
|
@ -187,17 +182,14 @@ export default class RoomSubscription {
|
||||||
// Create or update thread
|
// Create or update thread
|
||||||
if (message.tlm) {
|
if (message.tlm) {
|
||||||
try {
|
try {
|
||||||
threadRecord = await threadsCollection.find(message._id);
|
const threadRecord = await threadsCollection.find(message._id);
|
||||||
} catch (error) {
|
if (!threadRecord._hasPendingUpdate) {
|
||||||
// Do nothing
|
const updateThread = threadRecord.prepareUpdate(protectedFunction((t) => {
|
||||||
}
|
Object.assign(t, message);
|
||||||
|
}));
|
||||||
if (threadRecord) {
|
this._threadsBatch[message._id] = updateThread;
|
||||||
const updateThread = threadRecord.prepareUpdate(protectedFunction((t) => {
|
}
|
||||||
Object.assign(t, message);
|
} catch {
|
||||||
}));
|
|
||||||
this._threadsBatch[message._id] = updateThread;
|
|
||||||
} else {
|
|
||||||
const createThread = threadsCollection.prepareCreate(protectedFunction((t) => {
|
const createThread = threadsCollection.prepareCreate(protectedFunction((t) => {
|
||||||
t._raw = sanitizedRaw({ id: message._id }, threadsCollection.schema);
|
t._raw = sanitizedRaw({ id: message._id }, threadsCollection.schema);
|
||||||
t.subscription.id = this.rid;
|
t.subscription.id = this.rid;
|
||||||
|
@ -210,19 +202,16 @@ export default class RoomSubscription {
|
||||||
// Create or update thread message
|
// Create or update thread message
|
||||||
if (message.tmid) {
|
if (message.tmid) {
|
||||||
try {
|
try {
|
||||||
threadMessageRecord = await threadMessagesCollection.find(message._id);
|
const threadMessageRecord = await threadMessagesCollection.find(message._id);
|
||||||
} catch (error) {
|
if (!threadMessageRecord._hasPendingUpdate) {
|
||||||
// Do nothing
|
const updateThreadMessage = threadMessageRecord.prepareUpdate(protectedFunction((tm) => {
|
||||||
}
|
Object.assign(tm, message);
|
||||||
|
tm.rid = message.tmid;
|
||||||
if (threadMessageRecord) {
|
delete tm.tmid;
|
||||||
const updateThreadMessage = threadMessageRecord.prepareUpdate(protectedFunction((tm) => {
|
}));
|
||||||
Object.assign(tm, message);
|
this._threadMessagesBatch[message._id] = updateThreadMessage;
|
||||||
tm.rid = message.tmid;
|
}
|
||||||
delete tm.tmid;
|
} catch {
|
||||||
}));
|
|
||||||
this._threadMessagesBatch[message._id] = updateThreadMessage;
|
|
||||||
} else {
|
|
||||||
const createThreadMessage = threadMessagesCollection.prepareCreate(protectedFunction((tm) => {
|
const createThreadMessage = threadMessagesCollection.prepareCreate(protectedFunction((tm) => {
|
||||||
tm._raw = sanitizedRaw({ id: message._id }, threadMessagesCollection.schema);
|
tm._raw = sanitizedRaw({ id: message._id }, threadMessagesCollection.schema);
|
||||||
Object.assign(tm, message);
|
Object.assign(tm, message);
|
||||||
|
|
Loading…
Reference in New Issue