Skip to content

Commit

Permalink
fix(publish): modify the location of the read/write push prop method
Browse files Browse the repository at this point in the history
  • Loading branch information
Red-Asuka authored and ysfscream committed Dec 21, 2022
1 parent b6fa0f8 commit 83216f6
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 48 deletions.
8 changes: 4 additions & 4 deletions src/components/MsgPublish.vue
Original file line number Diff line number Diff line change
Expand Up @@ -390,8 +390,8 @@ export default class MsgPublish extends Vue {
const propRecords = Object.entries(this.MQTT5PropsForm).filter(([_, v]) => v !== null && v !== undefined && v !== 0)
const props = Object.fromEntries(propRecords)
const { messageService } = useServices()
return await messageService.addPushProp(props, this.$route.params.id)
const { connectionService } = useServices()
return await connectionService.addPushProp(props, this.$route.params.id)
}
private async send() {
Expand Down Expand Up @@ -492,8 +492,8 @@ export default class MsgPublish extends Vue {
private async loadProperties() {
this.MQTT5PropsForm = {}
if (this.mqtt5PropsEnable) {
const { messageService } = useServices()
const pushProps = await messageService.getPushProp(this.$route.params.id)
const { connectionService } = useServices()
const pushProps = await connectionService.getPushProp(this.$route.params.id)
if (pushProps) {
this.MQTT5PropsForm = pushProps
this.MQTT5PropsSend = _.cloneDeep(this.MQTT5PropsForm)
Expand Down
38 changes: 38 additions & 0 deletions src/database/services/ConnectionService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -505,4 +505,42 @@ export default class ConnectionService {
subs.filter((subInMemory) => query.some((subInDb) => subInMemory.id === subInDb.id)),
)
}

public async addPushProp(properties: MessageModel['properties'], connectionId: string) {
if (!properties) return
const query = await this.connectionRepository.findOne(connectionId)
if (!query) {
return
}
const updateAt = time.getNowDate()
this.connectionRepository.update(connectionId, {
...query,
pushPropsPayloadFormatIndicator: properties?.payloadFormatIndicator,
pushPropsMessageExpiryInterval: properties?.messageExpiryInterval,
pushPropsTopicAlias: properties?.topicAlias,
pushPropsResponseTopic: properties?.responseTopic,
pushPropsCorrelationData: properties?.correlationData?.toString(),
pushPropsUserProperties: JSON.stringify(properties?.userProperties),
pushPropsSubscriptionIdentifier: properties?.subscriptionIdentifier,
pushPropsContentType: properties?.contentType,
updateAt,
})
}

public async getPushProp(connectionId: string): Promise<MessageModel['properties'] | undefined> {
const query = await this.connectionRepository.findOne(connectionId)
if (!query) {
return
}
return {
payloadFormatIndicator: query.pushPropsPayloadFormatIndicator,
messageExpiryInterval: query.pushPropsMessageExpiryInterval,
topicAlias: query.pushPropsTopicAlias,
responseTopic: query.pushPropsResponseTopic,
correlationData: query.pushPropsCorrelationData,
userProperties: query.pushPropsUserProperties ? JSON.parse(query.pushPropsUserProperties) : undefined,
subscriptionIdentifier: query.pushPropsSubscriptionIdentifier,
contentType: query.pushPropsContentType,
} as MessageModel['properties']
}
}
42 changes: 0 additions & 42 deletions src/database/services/MessageService.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
import { Service } from 'typedi'
import { InjectRepository } from 'typeorm-typedi-extensions'
import MessageEntity from '../models/MessageEntity'
import ConnectionEntity from '../models/ConnectionEntity'
import { Repository } from 'typeorm'
import time from '@/utils/time'

@Service()
export default class MessageService {
constructor(
@InjectRepository(MessageEntity)
private messageRepository: Repository<MessageEntity>,
@InjectRepository(ConnectionEntity)
private connectionRepository: Repository<ConnectionEntity>,
) {}

public static modelToEntity(model: MessageModel, connectionId: string | undefined): MessageEntity {
Expand Down Expand Up @@ -39,44 +35,6 @@ export default class MessageService {
} as MessageModel
}

public async addPushProp(properties: MessageModel['properties'], connectionId: string) {
if (!properties) return
const query = await this.connectionRepository.findOne(connectionId)
if (!query) {
return
}
const updateAt = time.getNowDate()
this.connectionRepository.update(connectionId, {
...query,
pushPropsPayloadFormatIndicator: properties?.payloadFormatIndicator,
pushPropsMessageExpiryInterval: properties?.messageExpiryInterval,
pushPropsTopicAlias: properties?.topicAlias,
pushPropsResponseTopic: properties?.responseTopic,
pushPropsCorrelationData: properties?.correlationData?.toString(),
pushPropsUserProperties: JSON.stringify(properties?.userProperties),
pushPropsSubscriptionIdentifier: properties?.subscriptionIdentifier,
pushPropsContentType: properties?.contentType,
updateAt,
})
}

public async getPushProp(connectionId: string): Promise<MessageModel['properties'] | undefined> {
const query = await this.connectionRepository.findOne(connectionId)
if (!query) {
return
}
return {
payloadFormatIndicator: query.pushPropsPayloadFormatIndicator,
messageExpiryInterval: query.pushPropsMessageExpiryInterval,
topicAlias: query.pushPropsTopicAlias,
responseTopic: query.pushPropsResponseTopic,
correlationData: query.pushPropsCorrelationData,
userProperties: query.pushPropsUserProperties ? JSON.parse(query.pushPropsUserProperties) : undefined,
subscriptionIdentifier: query.pushPropsSubscriptionIdentifier,
contentType: query.pushPropsContentType,
} as MessageModel['properties']
}

public async pushToConnection(
message: MessageModel | MessageModel[],
connectionId: string,
Expand Down
4 changes: 2 additions & 2 deletions src/views/connections/ConnectionForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -804,7 +804,7 @@ export default class ConnectionForm extends Vue {
}
}
private async loadData(reload: boolean = false): Promise<void> {
private async loadSuggestConnections(reload: boolean = false): Promise<void> {
const { connectionService } = useServices()
const res: ConnectionModel[] | undefined = await connectionService.getLeatests()
if (res) {
Expand Down Expand Up @@ -837,7 +837,7 @@ export default class ConnectionForm extends Vue {
}
private async created() {
await this.loadData()
await this.loadSuggestConnections()
const { id } = this.$route.params
if (this.oper === 'edit' && id !== '0') {
this.loadDetail(id)
Expand Down

0 comments on commit 83216f6

Please sign in to comment.