From cc02c9b8cb4c8b700db1a0fbaeecb409425199c5 Mon Sep 17 00:00:00 2001 From: Avinash Lingaloo Date: Tue, 29 Dec 2020 23:01:54 +0400 Subject: [PATCH] MM_30476 : Updated all models and typings for the default server (#5069) --- app/database/default/models/app.ts | 23 ++++++++++++++---- app/database/default/models/global.ts | 24 ++++++++++++------- app/database/default/models/index.ts | 5 ++++ app/database/default/models/server.ts | 16 ------------- app/database/default/models/servers.ts | 33 ++++++++++++++++++++++++++ app/init/emm_provider.ts | 2 +- package-lock.json | 12 ++++------ types/database/app.d.ts | 13 ++++++++++ types/database/global.d.ts | 13 ++++++++-- types/database/server.d.ts | 11 --------- types/database/servers.d.ts | 28 ++++++++++++++++++++++ 11 files changed, 130 insertions(+), 50 deletions(-) create mode 100644 app/database/default/models/index.ts delete mode 100644 app/database/default/models/server.ts create mode 100644 app/database/default/models/servers.ts delete mode 100644 types/database/server.d.ts create mode 100644 types/database/servers.d.ts diff --git a/app/database/default/models/app.ts b/app/database/default/models/app.ts index 8bab79d103..97773363dc 100644 --- a/app/database/default/models/app.ts +++ b/app/database/default/models/app.ts @@ -2,13 +2,26 @@ // See LICENSE.txt for license information. import {Model} from '@nozbe/watermelondb'; +import {field} from '@nozbe/watermelondb/decorators'; + import {MM_TABLES} from '@constants/database'; -import field from '@nozbe/watermelondb/decorators/field'; +const {APP} = MM_TABLES.DEFAULT; + +/** + * The App model will hold information - such as the version number, build number and creation date - + * for the Mattermost mobile app. + */ export default class App extends Model { - static table = MM_TABLES.DEFAULT.APP + /** table (entity name) : app */ + static table = APP; - @field('build_number') buildNumber!: string - @field('created_at') createdAt!: number - @field('version_number') versionNumber!: string + /** build_number : Build number for the app */ + @field('build_number') buildNumber!: string; + + /** created_at : Date of creation for this version */ + @field('created_at') createdAt!: number; + + /** version_number : Version number for the app */ + @field('version_number') versionNumber!: string; } diff --git a/app/database/default/models/global.ts b/app/database/default/models/global.ts index 081e19ef44..933f02f962 100644 --- a/app/database/default/models/global.ts +++ b/app/database/default/models/global.ts @@ -2,17 +2,25 @@ // See LICENSE.txt for license information. import {Model} from '@nozbe/watermelondb'; +import {field, json} from '@nozbe/watermelondb/decorators'; + import {MM_TABLES} from '@constants/database'; -import field from '@nozbe/watermelondb/decorators/field'; -import json from '@nozbe/watermelondb/decorators/json'; +const {GLOBAL} = MM_TABLES.DEFAULT; + +// TODO : add TS definitions to sanitizer function signature. + +/** + * The Global model will act as a dictionary of name-value pairs. The value field can be a JSON object or any other + * data type. It will hold information that applies to the whole app ( e.g. sidebar settings for tablets) + */ export default class Global extends Model { - static table = MM_TABLES.DEFAULT.GLOBAL + /** table (entity name) : global */ + static table = GLOBAL; - @field('name') name!: string + /** name : The label/key to use to retrieve the special 'value' */ + @field('name') name!: string; - // TODO : add TS definitions to sanitizer function signature. - - // TODO : atm, the return type for 'value' is string[]. However, this return type can change to string/number/etc. A broader definition will need to be applied and this return type updated accordingly. - @json('value', (rawJson) => rawJson) value!: string[] + /** value : The value part of the key-value combination */ + @json('value', (rawJson) => rawJson) value!: string; } diff --git a/app/database/default/models/index.ts b/app/database/default/models/index.ts new file mode 100644 index 0000000000..f45e2f442b --- /dev/null +++ b/app/database/default/models/index.ts @@ -0,0 +1,5 @@ +// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. +// See LICENSE.txt for license information. +export {default as App} from './app'; +export {default as Global} from './global'; +export {default as Servers} from './servers'; diff --git a/app/database/default/models/server.ts b/app/database/default/models/server.ts deleted file mode 100644 index 0b35c06a34..0000000000 --- a/app/database/default/models/server.ts +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. -// See LICENSE.txt for license information. -import {Model} from '@nozbe/watermelondb'; -import field from '@nozbe/watermelondb/decorators/field'; - -import {MM_TABLES} from '@constants/database'; - -export default class Server extends Model { - static table = MM_TABLES.DEFAULT.SERVERS - - @field('db_path') dbPath!: string - @field('display_name') displayName!: string - @field('mention_count') mentionCount!: number - @field('unread_count') unreadCount!: number - @field('url') url!: string -} diff --git a/app/database/default/models/servers.ts b/app/database/default/models/servers.ts new file mode 100644 index 0000000000..ecfba43625 --- /dev/null +++ b/app/database/default/models/servers.ts @@ -0,0 +1,33 @@ +// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. +// See LICENSE.txt for license information. + +import {Model} from '@nozbe/watermelondb'; +import {field} from '@nozbe/watermelondb/decorators'; + +import {MM_TABLES} from '@constants/database'; + +const {SERVERS} = MM_TABLES.DEFAULT; + +/** + * The Server model will help us to identify the various servers a user will log in; in the context of + * multi-server support system. The dbPath field will hold the App-Groups file-path + */ +export default class Servers extends Model { + /** table (entity name) : servers */ + static table = SERVERS; + + /** db_path : The file path where the database is stored */ + @field('db_path') dbPath!: string; + + /** display_name : The server display name */ + @field('display_name') displayName!: string; + + /** mention_count : The number of mention on this server */ + @field('mention_count') mentionCount!: number; + + /** unread_count : The number of unread messages on this server */ + @field('unread_count') unreadCount!: number; + + /** url : The online address for the Mattermost server */ + @field('url') url!: string; +} diff --git a/app/init/emm_provider.ts b/app/init/emm_provider.ts index b2224bc655..0c7bc3007f 100644 --- a/app/init/emm_provider.ts +++ b/app/init/emm_provider.ts @@ -203,7 +203,7 @@ class EMMProvider { translations[t('mobile.managed.blocked_by')].replace('{vendor}', this.vendor), message, buttons, - {cancelable: false, onDismiss: resolve}, + {cancelable: false, onDismiss: () => resolve}, ); }); }; diff --git a/package-lock.json b/package-lock.json index a3bec1bbe6..36151dfbcf 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5965,13 +5965,6 @@ "rambdax": "2.15.0", "rxjs": "^6.5.3", "sql-escape-string": "^1.1.0" - }, - "dependencies": { - "lokijs": { - "version": "npm:@nozbe/lokijs@1.5.10-wmelon3", - "resolved": "https://registry.npmjs.org/@nozbe/lokijs/-/lokijs-1.5.10-wmelon3.tgz", - "integrity": "sha512-yfuj/SzYiVVn0e3OP8vjcbekumUR62Df90deG8uH7+5nqJqTLe4HkEzlmwJfss9UE0K8PsTQLACFOUq/2aAJ2A==" - } } }, "@nozbe/with-observables": { @@ -22750,6 +22743,11 @@ } } }, + "lokijs": { + "version": "npm:@nozbe/lokijs@1.5.10-wmelon3", + "resolved": "https://registry.npmjs.org/@nozbe/lokijs/-/lokijs-1.5.10-wmelon3.tgz", + "integrity": "sha512-yfuj/SzYiVVn0e3OP8vjcbekumUR62Df90deG8uH7+5nqJqTLe4HkEzlmwJfss9UE0K8PsTQLACFOUq/2aAJ2A==" + }, "loose-envify": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/loose-envify/-/loose-envify-1.4.0.tgz", diff --git a/types/database/app.d.ts b/types/database/app.d.ts index 6d39bcef40..add014bc09 100644 --- a/types/database/app.d.ts +++ b/types/database/app.d.ts @@ -1,9 +1,22 @@ // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. // See LICENSE.txt for license information. + import {Model} from '@nozbe/watermelondb'; + +/** + * The App model will hold information - such as the version number, build number and creation date - + * for the Mattermost mobile app. + */ export default class App extends Model { + /** table (entity name) : app */ static table: string; + + /** build_number : Build number for the app */ buildNumber: string; + + /** created_at : Date of creation for this version */ createdAt: number; + + /** version_number : Version number for the app */ versionNumber: string; } diff --git a/types/database/global.d.ts b/types/database/global.d.ts index 6d24200d42..1f65d4c45f 100644 --- a/types/database/global.d.ts +++ b/types/database/global.d.ts @@ -1,10 +1,19 @@ // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. // See LICENSE.txt for license information. + import {Model} from '@nozbe/watermelondb'; + +/** + * The Global model will act as a dictionary of name-value pairs. The value field can be a JSON object or any other + * data type. It will hold information that applies to the whole app ( e.g. sidebar settings for tablets) + */ export default class Global extends Model { + /** table (entity name) : global */ static table: string; + + /** name : The label/key to use to retrieve the special 'value' */ name: string; - // TODO : atm, the return type for 'value' is string[]. However, this return type can change to string/number/etc. A broader definition will need to be applied and this return type updated accordingly. - value: string[]; + /** value : The value part of the key-value combination */ + value: string; } diff --git a/types/database/server.d.ts b/types/database/server.d.ts deleted file mode 100644 index e5d7fe9877..0000000000 --- a/types/database/server.d.ts +++ /dev/null @@ -1,11 +0,0 @@ -// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. -// See LICENSE.txt for license information. -import {Model} from '@nozbe/watermelondb'; -export default class Server extends Model { - static table: string; - dbPath: string; - displayName: string; - mentionCount: number; - unreadCount: number; - url: string; -} diff --git a/types/database/servers.d.ts b/types/database/servers.d.ts new file mode 100644 index 0000000000..f6a7f7ed1b --- /dev/null +++ b/types/database/servers.d.ts @@ -0,0 +1,28 @@ +// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. +// See LICENSE.txt for license information. + +import {Model} from '@nozbe/watermelondb'; + +/** + * The Server model will help us to identify the various servers a user will log in; in the context of + * multi-server support system. The dbPath field will hold the App-Groups file-path + */ +export default class Servers extends Model { + /** table (entity name) : servers */ + static table: string; + + /** db_path : The file path where the database is stored */ + dbPath: string; + + /** display_name : The server display name */ + displayName: string; + + /** mention_count : The number of mention on this server */ + mentionCount: number; + + /** unread_count : The number of unread messages on this server */ + unreadCount: number; + + /** url : The online address for the Mattermost server */ + url: string; +}