mattermost-mobile/patches/@nozbe+watermelondb+0.25.5.patch
Mattermost Build ce5d049a55
Update RN and deps to fix ANR issues (#7078) (#7079)
(cherry picked from commit 82f0b014f4)

Co-authored-by: Elias Nahum <nahumhbl@gmail.com>
2023-02-02 14:44:09 +02:00

134 lines
5.7 KiB
Diff

diff --git a/node_modules/@nozbe/watermelondb/Database/index.js b/node_modules/@nozbe/watermelondb/Database/index.js
index 8d71c6f..9ad75d6 100644
--- a/node_modules/@nozbe/watermelondb/Database/index.js
+++ b/node_modules/@nozbe/watermelondb/Database/index.js
@@ -126,6 +126,10 @@ var Database = /*#__PURE__*/function () {
// subsequent changes to the record don't trip up the invariant
// TODO: What if this fails?
record._preparedState = null;
+
+ if ('update' === preparedState) {
+ record.__original = null;
+ }
}
if (!changeNotifications[table]) {
diff --git a/node_modules/@nozbe/watermelondb/Model/index.d.ts b/node_modules/@nozbe/watermelondb/Model/index.d.ts
index 96114ec..ecfe3c1 100644
--- a/node_modules/@nozbe/watermelondb/Model/index.d.ts
+++ b/node_modules/@nozbe/watermelondb/Model/index.d.ts
@@ -61,6 +61,8 @@ export default class Model {
// database.batch()
prepareUpdate(recordUpdater?: (_: this) => void): this
+ cancelPrepareUpdate(): void
+
prepareMarkAsDeleted(): this
prepareDestroyPermanently(): this
diff --git a/node_modules/@nozbe/watermelondb/Model/index.js b/node_modules/@nozbe/watermelondb/Model/index.js
index b0e3a83..57ecb8d 100644
--- a/node_modules/@nozbe/watermelondb/Model/index.js
+++ b/node_modules/@nozbe/watermelondb/Model/index.js
@@ -81,7 +81,7 @@ var Model = /*#__PURE__*/function () {
_proto.prepareUpdate = function prepareUpdate(recordUpdater = _noop.default) {
var _this = this;
- (0, _invariant.default)(!this._preparedState, "Cannot update a record with pending changes");
+ (0, _invariant.default)(!this._preparedState, "Cannot update a record with pending changes in table " + _this.table);
this.__ensureNotDisposable("Model.prepareUpdate()");
@@ -92,6 +92,7 @@ var Model = /*#__PURE__*/function () {
} // Perform updates
+ this.__original = Object.assign({}, this._raw);
(0, _ensureSync.default)(recordUpdater(this));
this._isEditing = false;
this._preparedState = 'update'; // TODO: `process.nextTick` doesn't work on React Native
@@ -107,6 +108,19 @@ var Model = /*#__PURE__*/function () {
return this;
};
+ _proto.cancelPrepareUpdate = function cancelPrepareUpdate() {
+ if ('test' !== process.env.NODE_ENV && 'undefined' !== typeof process && process) {
+ (0, _invariant.default)('update' !== _this._preparedState, "Cannot cancel an update on a model that has not been prepared in table " + this.table);
+ }
+ this.__changes = null;
+ this._preparedState = null;
+ if (this.__original) {
+ this._raw = this.__original;
+ }
+ this.__original = undefined;
+ };
+
+
_proto.prepareMarkAsDeleted = function prepareMarkAsDeleted() {
(0, _invariant.default)(!this._preparedState, "Cannot mark a record with pending changes as deleted");
diff --git a/node_modules/@nozbe/watermelondb/native/android/src/main/java/com/nozbe/watermelondb/Database.kt b/node_modules/@nozbe/watermelondb/native/android/src/main/java/com/nozbe/watermelondb/Database.kt
index ca31e20..b45c753 100644
--- a/node_modules/@nozbe/watermelondb/native/android/src/main/java/com/nozbe/watermelondb/Database.kt
+++ b/node_modules/@nozbe/watermelondb/native/android/src/main/java/com/nozbe/watermelondb/Database.kt
@@ -22,6 +22,21 @@ class Database(
if (name == ":memory:" || name.contains("mode=memory")) {
context.cacheDir.delete()
File(context.cacheDir, name).path
+ } else if (name.contains("/") || name.contains("file")) {
+ // Extracts the database name from the path
+ val dbName = name.substringAfterLast("/")
+
+ // Extracts the real path where the *.db file will be created
+ val truePath = name.substringAfterLast("file://").substringBeforeLast("/")
+
+ // Creates the directory
+ if (!truePath.contains("databases")) {
+ val fileObj = File(truePath, "databases")
+ fileObj.mkdir()
+ File("${truePath}/databases", dbName).path
+ } else {
+ File(truePath, dbName).path
+ }
} else {
// On some systems there is some kind of lock on `/databases` folder ¯\_(ツ)_/¯
context.getDatabasePath("$name.db").path.replace("/databases", "")
diff --git a/node_modules/@nozbe/watermelondb/native/shared/Database.cpp b/node_modules/@nozbe/watermelondb/native/shared/Database.cpp
index 1a1cabf..01bbb2b 100644
--- a/node_modules/@nozbe/watermelondb/native/shared/Database.cpp
+++ b/node_modules/@nozbe/watermelondb/native/shared/Database.cpp
@@ -54,6 +54,7 @@ void Database::destroy() {
const std::lock_guard<std::mutex> lock(mutex_);
if (isDestroyed_) {
+ db_->markAsDestroyed();
return;
}
isDestroyed_ = true;
diff --git a/node_modules/@nozbe/watermelondb/native/shared/Sqlite.cpp b/node_modules/@nozbe/watermelondb/native/shared/Sqlite.cpp
index e740c29..6963734 100644
--- a/node_modules/@nozbe/watermelondb/native/shared/Sqlite.cpp
+++ b/node_modules/@nozbe/watermelondb/native/shared/Sqlite.cpp
@@ -67,6 +67,10 @@ void SqliteDb::destroy() {
}
}
+void SqliteDb::markAsDestroyed() {
+ isDestroyed_ = true;
+}
+
SqliteDb::~SqliteDb() {
destroy();
}
diff --git a/node_modules/@nozbe/watermelondb/native/shared/Sqlite.h b/node_modules/@nozbe/watermelondb/native/shared/Sqlite.h
index 22cffa7..4b74a7f 100644
--- a/node_modules/@nozbe/watermelondb/native/shared/Sqlite.h
+++ b/node_modules/@nozbe/watermelondb/native/shared/Sqlite.h
@@ -11,6 +11,7 @@ public:
SqliteDb(std::string path);
~SqliteDb();
void destroy();
+ void markAsDestroyed();
sqlite3 *sqlite;