diff --git a/app/actions/remote/channel.ts b/app/actions/remote/channel.ts index 5d5488ed9..8f75d80b9 100644 --- a/app/actions/remote/channel.ts +++ b/app/actions/remote/channel.ts @@ -429,6 +429,7 @@ export async function fetchChannelStats(serverUrl: string, channelId: string, fe id: channelId, member_count: stats.member_count, pinned_post_count: stats.pinnedpost_count, + files_count: stats.files_count, }]; await operator.handleChannelInfo({channelInfos, prepareRecordsOnly: false}); } diff --git a/app/database/migration/server/index.ts b/app/database/migration/server/index.ts index 3c5d0ae24..cacdeaa56 100644 --- a/app/database/migration/server/index.ts +++ b/app/database/migration/server/index.ts @@ -4,6 +4,22 @@ // NOTE : To implement migration, please follow this document // https://nozbe.github.io/WatermelonDB/Advanced/Migrations.html -import {schemaMigrations} from '@nozbe/watermelondb/Schema/migrations'; +import {addColumns, schemaMigrations} from '@nozbe/watermelondb/Schema/migrations'; -export default schemaMigrations({migrations: []}); +import {MM_TABLES} from '@constants/database'; + +const {CHANNEL_INFO} = MM_TABLES.SERVER; + +export default schemaMigrations({migrations: [ + { + toVersion: 2, + steps: [ + addColumns({ + table: CHANNEL_INFO, + columns: [ + {name: 'files_count', type: 'number'}, + ], + }), + ], + }, +]}); diff --git a/app/database/models/server/channel_info.ts b/app/database/models/server/channel_info.ts index f25726863..b80fbe065 100644 --- a/app/database/models/server/channel_info.ts +++ b/app/database/models/server/channel_info.ts @@ -37,6 +37,9 @@ export default class ChannelInfoModel extends Model implements ChannelInfoInterf /** pinned_post_count : The number of post pinned in this channel */ @field('pinned_post_count') pinnedPostCount!: number; + /** files_count : The number of files in this channel */ + @field('files_count') filesCount!: number; + /** purpose: The intention behind this channel */ @field('purpose') purpose!: string; diff --git a/app/database/operator/server_data_operator/handlers/channel.ts b/app/database/operator/server_data_operator/handlers/channel.ts index 807a35e96..c5b750721 100644 --- a/app/database/operator/server_data_operator/handlers/channel.ts +++ b/app/database/operator/server_data_operator/handlers/channel.ts @@ -188,6 +188,7 @@ const ChannelHandler = >(super ci.member_count !== e.memberCount || ci.header !== e.header || ci.pinned_post_count !== e.pinnedPostCount || + ci.files_count !== e.filesCount || ci.purpose !== e.purpose ) { res.push(ci); diff --git a/app/database/operator/server_data_operator/transformers/channel.test.ts b/app/database/operator/server_data_operator/transformers/channel.test.ts index 571bec3dc..4c4d337f2 100644 --- a/app/database/operator/server_data_operator/transformers/channel.test.ts +++ b/app/database/operator/server_data_operator/transformers/channel.test.ts @@ -103,6 +103,7 @@ describe('*** CHANNEL Prepare Records Test ***', () => { header: 'channel info header', member_count: 10, pinned_post_count: 3, + files_count: 0, purpose: 'sample channel ', }, }, diff --git a/app/database/operator/server_data_operator/transformers/channel.ts b/app/database/operator/server_data_operator/transformers/channel.ts index bc79a7ffa..4c124c691 100644 --- a/app/database/operator/server_data_operator/transformers/channel.ts +++ b/app/database/operator/server_data_operator/transformers/channel.ts @@ -101,6 +101,7 @@ export const transformChannelInfoRecord = ({action, database, value}: Transforme channelInfo.header = raw.header ?? channelInfo.header ?? ''; channelInfo.memberCount = raw.member_count ?? channelInfo.memberCount ?? 0; channelInfo.pinnedPostCount = raw.pinned_post_count ?? channelInfo.pinnedPostCount ?? 0; + channelInfo.filesCount = raw.files_count ?? channelInfo.filesCount ?? 0; channelInfo.purpose = raw.purpose ?? channelInfo.purpose ?? ''; }; diff --git a/app/database/schema/server/index.ts b/app/database/schema/server/index.ts index e5c837e4b..cf5f107ea 100644 --- a/app/database/schema/server/index.ts +++ b/app/database/schema/server/index.ts @@ -39,7 +39,7 @@ import { } from './table_schemas'; export const serverSchema: AppSchema = appSchema({ - version: 1, + version: 2, tables: [ CategorySchema, CategoryChannelSchema, diff --git a/app/database/schema/server/table_schemas/channel_info.ts b/app/database/schema/server/table_schemas/channel_info.ts index 621944188..7a97f3c52 100644 --- a/app/database/schema/server/table_schemas/channel_info.ts +++ b/app/database/schema/server/table_schemas/channel_info.ts @@ -14,6 +14,7 @@ export default tableSchema({ {name: 'header', type: 'string'}, {name: 'member_count', type: 'number'}, {name: 'pinned_post_count', type: 'number'}, + {name: 'files_count', type: 'number'}, {name: 'purpose', type: 'string'}, ], }); diff --git a/app/database/schema/server/test.ts b/app/database/schema/server/test.ts index 1711ea8d1..1a6c1690d 100644 --- a/app/database/schema/server/test.ts +++ b/app/database/schema/server/test.ts @@ -45,7 +45,7 @@ const { describe('*** Test schema for SERVER database ***', () => { it('=> The SERVER SCHEMA should strictly match', () => { expect(serverSchema).toEqual({ - version: 1, + version: 2, unsafeSql: undefined, tables: { [CATEGORY]: { @@ -92,6 +92,7 @@ describe('*** Test schema for SERVER database ***', () => { header: {name: 'header', type: 'string'}, member_count: {name: 'member_count', type: 'number'}, pinned_post_count: {name: 'pinned_post_count', type: 'number'}, + files_count: {name: 'files_count', type: 'number'}, purpose: {name: 'purpose', type: 'string'}, }, columnArray: [ @@ -99,6 +100,7 @@ describe('*** Test schema for SERVER database ***', () => { {name: 'header', type: 'string'}, {name: 'member_count', type: 'number'}, {name: 'pinned_post_count', type: 'number'}, + {name: 'files_count', type: 'number'}, {name: 'purpose', type: 'string'}, ], }, diff --git a/app/queries/servers/channel.ts b/app/queries/servers/channel.ts index 3fec06123..e679ea64d 100644 --- a/app/queries/servers/channel.ts +++ b/app/queries/servers/channel.ts @@ -41,6 +41,7 @@ export function prepareMissingChannelsForAllTeams(operator: ServerDataOperator, guest_count: 0, member_count: 0, pinned_post_count: 0, + files_count: 0, }); } @@ -95,12 +96,14 @@ export const prepareMyChannelsForTeam = async (operator: ServerDataOperator, tea let member_count = 0; let guest_count = 0; let pinned_post_count = 0; + let files_count = 0; if (storedChannel) { storedInfo = allChannelsInfoForTeam[c.id]; if (storedInfo) { member_count = storedInfo.memberCount; guest_count = storedInfo.guestCount; pinned_post_count = storedInfo.pinnedPostCount; + files_count = storedInfo.filesCount; } } @@ -111,6 +114,7 @@ export const prepareMyChannelsForTeam = async (operator: ServerDataOperator, tea guest_count, member_count, pinned_post_count, + files_count, }); } diff --git a/app/utils/graphql.ts b/app/utils/graphql.ts index 23247879d..6551975c5 100644 --- a/app/utils/graphql.ts +++ b/app/utils/graphql.ts @@ -172,6 +172,7 @@ export const gqlToClientChannelStats = (s: Partial): ChannelStats => guest_count: s.stats?.guestCount || 0, member_count: s.stats?.memberCount || 0, pinnedpost_count: s.stats?.pinnePostCount || 0, + files_count: s.stats?.filesCount || 0, }; }; diff --git a/docs/database/server/server.md b/docs/database/server/server.md index 0d5c03c04..93b3f9bf2 100644 --- a/docs/database/server/server.md +++ b/docs/database/server/server.md @@ -1,4 +1,4 @@ -# Server Database - Schema Version 1 +# Server Database - Schema Version 2 # Please bump the version by 1, any time the schema changes. # Also, include the migration plan under app/database/migration/server, # update all models, relationships and types. @@ -48,6 +48,7 @@ guest_count number header string member_count number pinned_post_count number +files_count number purpose string ChannelMembership diff --git a/types/api/channels.d.ts b/types/api/channels.d.ts index 48ae8c1fd..26baed1ce 100644 --- a/types/api/channels.d.ts +++ b/types/api/channels.d.ts @@ -6,6 +6,7 @@ type ChannelStats = { guest_count: number; member_count: number; pinnedpost_count: number; + files_count: number; }; type NotificationLevel = 'default' | 'all' | 'mention' | 'none'; diff --git a/types/api/graphql.d.ts b/types/api/graphql.d.ts index 61a3de981..56b16b3ae 100644 --- a/types/api/graphql.d.ts +++ b/types/api/graphql.d.ts @@ -174,6 +174,7 @@ type GQLStats = { guestCount: number; memberCount: number; pinnePostCount: number; + filesCount: number; } type GQLRole = { diff --git a/types/database/models/servers/channel_info.ts b/types/database/models/servers/channel_info.ts index 79d522ef3..5828a0231 100644 --- a/types/database/models/servers/channel_info.ts +++ b/types/database/models/servers/channel_info.ts @@ -26,6 +26,9 @@ declare class ChannelInfoModel extends Model { /** pinned_post_count : The number of post pinned in this channel */ pinnedPostCount: number; + /** files_count : The number of files in this channel */ + filesCount: number; + /** purpose: The intention behind this channel */ purpose: string; diff --git a/types/database/raw_values.d.ts b/types/database/raw_values.d.ts index 3d6e40a18..d059df55f 100644 --- a/types/database/raw_values.d.ts +++ b/types/database/raw_values.d.ts @@ -13,6 +13,7 @@ type ChannelInfo = { header: string; member_count: number; pinned_post_count: number; + files_count: number; purpose: string; };