Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

feat(message): support message push prop history #798

Merged
merged 3 commits into from
Dec 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 19 additions & 4 deletions src/components/MsgPublish.vue
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,6 @@ import validFormatJson from '@/utils/validFormatJson'
import useServices from '@/database/useServices'
import time from '@/utils/time'

type UserPairObect = { key: string; value: string; checked: boolean }

@Component({
components: {
Editor,
Expand Down Expand Up @@ -318,7 +316,7 @@ export default class MsgPublish extends Vue {
}

public defaultPropObj = { key: '', value: '', checked: true }
public listData: UserPairObect[] = [_.cloneDeep(this.defaultPropObj)]
public listData: UserPropsPairObject[] = [_.cloneDeep(this.defaultPropObj)]

private hasMqtt5Prop: boolean = false

Expand Down Expand Up @@ -465,10 +463,27 @@ export default class MsgPublish extends Vue {
}

private async loadHistoryData(isNewPayload?: boolean, isLoadData?: boolean) {
const { historyMessageHeaderService, historyMessagePayloadService } = useServices()
const { historyMessageHeaderService, historyMessagePayloadService, messageService } = useServices()
const headersHistory = (await historyMessageHeaderService.getAll()) ?? []
const payloadsHistory = (await historyMessagePayloadService.getAll()) ?? []
if (this.mqtt5PropsEnable) {
const propHistory = await messageService.getMessageProp(this.$route.params.id)
if (propHistory) {
this.MQTT5Props = propHistory
if (propHistory.userProperties) {
this.listData = Object.entries(propHistory.userProperties).map(([key, value]) => {
return {
key,
value,
checked: true,
} as UserPropsPairObject
})
}
}
}

const historyMsg = payloadsHistory[payloadsHistory.length - 1]

if (historyMsg && isLoadData) {
this.payloadType = historyMsg.payloadType
}
Expand Down
2 changes: 2 additions & 0 deletions src/database/database.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { autoScroll1635155945767 } from './migration/1635155945767-autoScroll'
import { huLang1635392304194 } from './migration/1635393164071-huLang'
import { messageProps1637636965786 } from './migration/1637636965786-messageProps'
import { enhanceMessageType1638081576988 } from './migration/1638081576988-enhanceMessageType'
import { messageHistoryProps1638375518392 } from './migration/1638375518392-messageHistoryProps'

const STORE_PATH = getAppDataPath('MQTTX')
try {
Expand Down Expand Up @@ -55,6 +56,7 @@ const ORMConfig = {
huLang1635392304194,
messageProps1637636965786,
enhanceMessageType1638081576988,
messageHistoryProps1638375518392,
],
migrationsTableName: 'temp_migration_table',
entities: [
Expand Down
291 changes: 291 additions & 0 deletions src/database/migration/1638375518392-messageHistoryProps.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,291 @@
import { MigrationInterface, QueryRunner } from 'typeorm'

export class messageHistoryProps1638375518392 implements MigrationInterface {
name = 'messageHistoryProps1638375518392'

public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`
DROP INDEX "IDX_6fcc95296b7ab85477d47b698f"
`)
await queryRunner.query(`
CREATE TABLE "temporary_ConnectionEntity" (
"id" varchar PRIMARY KEY NOT NULL,
"client_id" varchar NOT NULL,
"name" varchar NOT NULL,
"clean" boolean NOT NULL DEFAULT (1),
"protocol" varchar CHECK(protocol IN ('ws', 'wss', 'mqtt', 'mqtts')) NOT NULL DEFAULT ('mqtt'),
"host" varchar NOT NULL,
"port" integer NOT NULL,
"keepalive" integer NOT NULL DEFAULT (60),
"connectTimeout" integer NOT NULL,
"reconnect" boolean NOT NULL,
"username" varchar,
"password" varchar,
"path" varchar,
"certType" varchar DEFAULT (''),
"ssl" boolean NOT NULL,
"mqttVersion" varchar NOT NULL,
"unreadMessageCount" integer NOT NULL,
"clientIdWithTime" boolean DEFAULT (0),
"parent_id" varchar,
"orderId" integer,
"rejectUnauthorized" boolean DEFAULT (1),
"ca" varchar NOT NULL,
"cert" varchar NOT NULL,
"key" varchar NOT NULL,
"isCollection" boolean NOT NULL DEFAULT (0),
"createAt" datetime NOT NULL DEFAULT (CURRENT_TIMESTAMP),
"updateAt" datetime NOT NULL DEFAULT (CURRENT_TIMESTAMP),
"willId" varchar,
"sessionExpiryInterval" integer,
"receiveMaximum" integer,
"maximumPacketSize" integer,
"topicAliasMaximum" integer,
"requestResponseInformation" boolean,
"requestProblemInformation" boolean,
"userProperties" varchar,
"authenticationMethod" varchar,
"authenticationData" varchar,
"pushPropsPayloadFormatIndicator" boolean,
"pushPropsMessageExpiryInterval" integer,
"pushPropsTopicAlias" integer,
"pushPropsResponseTopic" varchar,
"pushPropsCorrelationData" varchar,
"pushPropsUserProperties" varchar,
"pushPropsSubscriptionIdentifier" integer,
"pushPropsContentType" varchar,
CONSTRAINT "REL_71db93dbf719b8b12e835e343f" UNIQUE ("willId"),
CONSTRAINT "FK_71db93dbf719b8b12e835e343fe" FOREIGN KEY ("willId") REFERENCES "WillEntity" ("id") ON DELETE CASCADE ON UPDATE NO ACTION,
CONSTRAINT "FK_9beef409e9fbe4bd50dd024bac4" FOREIGN KEY ("parent_id") REFERENCES "CollectionEntity" ("id") ON DELETE CASCADE ON UPDATE NO ACTION
)
`)
await queryRunner.query(`
INSERT INTO "temporary_ConnectionEntity"(
"id",
"client_id",
"name",
"clean",
"protocol",
"host",
"port",
"keepalive",
"connectTimeout",
"reconnect",
"username",
"password",
"path",
"certType",
"ssl",
"mqttVersion",
"unreadMessageCount",
"clientIdWithTime",
"parent_id",
"orderId",
"rejectUnauthorized",
"ca",
"cert",
"key",
"isCollection",
"createAt",
"updateAt",
"willId",
"sessionExpiryInterval",
"receiveMaximum",
"maximumPacketSize",
"topicAliasMaximum",
"requestResponseInformation",
"requestProblemInformation",
"userProperties",
"authenticationMethod",
"authenticationData"
)
SELECT "id",
"client_id",
"name",
"clean",
"protocol",
"host",
"port",
"keepalive",
"connectTimeout",
"reconnect",
"username",
"password",
"path",
"certType",
"ssl",
"mqttVersion",
"unreadMessageCount",
"clientIdWithTime",
"parent_id",
"orderId",
"rejectUnauthorized",
"ca",
"cert",
"key",
"isCollection",
"createAt",
"updateAt",
"willId",
"sessionExpiryInterval",
"receiveMaximum",
"maximumPacketSize",
"topicAliasMaximum",
"requestResponseInformation",
"requestProblemInformation",
"userProperties",
"authenticationMethod",
"authenticationData"
FROM "ConnectionEntity"
`)
await queryRunner.query(`
DROP TABLE "ConnectionEntity"
`)
await queryRunner.query(`
ALTER TABLE "temporary_ConnectionEntity"
RENAME TO "ConnectionEntity"
`)
await queryRunner.query(`
CREATE UNIQUE INDEX "IDX_6fcc95296b7ab85477d47b698f" ON "ConnectionEntity" ("client_id")
`)
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`
DROP INDEX "IDX_6fcc95296b7ab85477d47b698f"
`)
await queryRunner.query(`
ALTER TABLE "ConnectionEntity"
RENAME TO "temporary_ConnectionEntity"
`)
await queryRunner.query(`
CREATE TABLE "ConnectionEntity" (
"id" varchar PRIMARY KEY NOT NULL,
"client_id" varchar NOT NULL,
"name" varchar NOT NULL,
"clean" boolean NOT NULL DEFAULT (1),
"protocol" varchar CHECK(protocol IN ('ws', 'wss', 'mqtt', 'mqtts')) NOT NULL DEFAULT ('mqtt'),
"host" varchar NOT NULL,
"port" integer NOT NULL,
"keepalive" integer NOT NULL DEFAULT (60),
"connectTimeout" integer NOT NULL,
"reconnect" boolean NOT NULL,
"username" varchar,
"password" varchar,
"path" varchar,
"certType" varchar DEFAULT (''),
"ssl" boolean NOT NULL,
"mqttVersion" varchar NOT NULL,
"unreadMessageCount" integer NOT NULL,
"clientIdWithTime" boolean DEFAULT (0),
"parent_id" varchar,
"orderId" integer,
"rejectUnauthorized" boolean DEFAULT (1),
"ca" varchar NOT NULL,
"cert" varchar NOT NULL,
"key" varchar NOT NULL,
"isCollection" boolean NOT NULL DEFAULT (0),
"createAt" datetime NOT NULL DEFAULT (CURRENT_TIMESTAMP),
"updateAt" datetime NOT NULL DEFAULT (CURRENT_TIMESTAMP),
"willId" varchar,
"sessionExpiryInterval" integer,
"receiveMaximum" integer,
"maximumPacketSize" integer,
"topicAliasMaximum" integer,
"requestResponseInformation" boolean,
"requestProblemInformation" boolean,
"userProperties" varchar,
"authenticationMethod" varchar,
"authenticationData" varchar,
CONSTRAINT "REL_71db93dbf719b8b12e835e343f" UNIQUE ("willId"),
CONSTRAINT "FK_71db93dbf719b8b12e835e343fe" FOREIGN KEY ("willId") REFERENCES "WillEntity" ("id") ON DELETE CASCADE ON UPDATE NO ACTION,
CONSTRAINT "FK_9beef409e9fbe4bd50dd024bac4" FOREIGN KEY ("parent_id") REFERENCES "CollectionEntity" ("id") ON DELETE CASCADE ON UPDATE NO ACTION
)
`)
await queryRunner.query(`
INSERT INTO "ConnectionEntity"(
"id",
"client_id",
"name",
"clean",
"protocol",
"host",
"port",
"keepalive",
"connectTimeout",
"reconnect",
"username",
"password",
"path",
"certType",
"ssl",
"mqttVersion",
"unreadMessageCount",
"clientIdWithTime",
"parent_id",
"orderId",
"rejectUnauthorized",
"ca",
"cert",
"key",
"isCollection",
"createAt",
"updateAt",
"willId",
"sessionExpiryInterval",
"receiveMaximum",
"maximumPacketSize",
"topicAliasMaximum",
"requestResponseInformation",
"requestProblemInformation",
"userProperties",
"authenticationMethod",
"authenticationData"
)
SELECT "id",
"client_id",
"name",
"clean",
"protocol",
"host",
"port",
"keepalive",
"connectTimeout",
"reconnect",
"username",
"password",
"path",
"certType",
"ssl",
"mqttVersion",
"unreadMessageCount",
"clientIdWithTime",
"parent_id",
"orderId",
"rejectUnauthorized",
"ca",
"cert",
"key",
"isCollection",
"createAt",
"updateAt",
"willId",
"sessionExpiryInterval",
"receiveMaximum",
"maximumPacketSize",
"topicAliasMaximum",
"requestResponseInformation",
"requestProblemInformation",
"userProperties",
"authenticationMethod",
"authenticationData"
FROM "temporary_ConnectionEntity"
`)
await queryRunner.query(`
DROP TABLE "temporary_ConnectionEntity"
`)
await queryRunner.query(`
CREATE UNIQUE INDEX "IDX_6fcc95296b7ab85477d47b698f" ON "ConnectionEntity" ("client_id")
`)
}
}
25 changes: 25 additions & 0 deletions src/database/models/ConnectionEntity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,31 @@ export default class ConnectionEntity {
@Column({ type: 'boolean', default: false, nullable: true })
clientIdWithTime?: boolean

// message push props
@Column({ type: 'boolean', nullable: true })
pushPropsPayloadFormatIndicator?: boolean

@Column({ type: 'integer', nullable: true })
pushPropsMessageExpiryInterval?: number

@Column({ type: 'integer', nullable: true })
pushPropsTopicAlias?: number

@Column({ type: 'varchar', nullable: true })
pushPropsResponseTopic?: string

@Column({ type: 'varchar', nullable: true })
pushPropsCorrelationData?: string

@Column({ type: 'varchar', nullable: true })
pushPropsUserProperties?: string

@Column({ type: 'integer', nullable: true })
pushPropsSubscriptionIdentifier?: number

@Column({ type: 'varchar', nullable: true })
pushPropsContentType?: string

// ManyToOne entities
@ManyToOne(() => CollectionEntity, (collection) => collection.connections, { onDelete: 'CASCADE', nullable: true })
@JoinColumn({ name: 'parent_id', referencedColumnName: 'id' })
Expand Down
Loading