diff --git a/es/aspects/session.js b/es/aspects/session.js index ec0bd4605..c92345c35 100644 --- a/es/aspects/session.js +++ b/es/aspects/session.js @@ -59,6 +59,7 @@ export async function createSession(params, context) { }, filter: { openId: FromUserName, + applicationId: entityId, }, }, {}); const result = await context.select('session', { @@ -76,28 +77,95 @@ export async function createSession(params, context) { openId: FromUserName, }, }, {}); + const sessionMessage = { + id: await generateNewIdAsync(), + applicationId: entityId, + wechatUserId: wechatUser?.id, + createTime: Number(CreateTime) * 1000, + type: MsgType, + aaoe: false, + extra: data, + userId, + }; + if (MsgType === 'text') { + Object.assign(sessionMessage, { + text: Content, + }); + } + else if (MsgType === 'image') { + Object.assign(sessionMessage, { + extraFile$entity: [ + { + id: await generateNewIdAsync(), + action: 'create', + data: { + id: await generateNewIdAsync(), + applicationId: entityId, + origin: 'wechat', + type: 'image', + tag1: 'image', + objectId: generateNewIdAsync(), + sort: 1000, + uploadState: 'success', + extra1: data.MediaId, + extra2: { + isPermanent: false, + }, + }, + }, + ], + }); + } + else if (MsgType === 'video') { + Object.assign(sessionMessage, { + extraFile$entity: [ + { + id: await generateNewIdAsync(), + action: 'create', + data: { + id: await generateNewIdAsync(), + applicationId: entityId, + origin: 'wechat', + type: 'video', + tag1: 'video', + objectId: generateNewIdAsync(), + sort: 1000, + uploadState: 'success', + extra1: data.MediaId, + }, + }, + ], + }); + } + else if (MsgType === 'voice') { + Object.assign(sessionMessage, { + extraFile$entity: [ + { + id: await generateNewIdAsync(), + action: 'create', + data: { + id: await generateNewIdAsync(), + applicationId: entityId, + origin: 'wechat', + type: 'audio', + tag1: 'audio', + objectId: generateNewIdAsync(), + sort: 1000, + uploadState: 'success', + extra1: data.MediaId, + }, + }, + ], + }); + } session = result[0]; sessionMessage$session = [ { id: await generateNewIdAsync(), action: 'create', - data: { - id: await generateNewIdAsync(), - applicationId: wechatUser?.applicationId, - wechatUserId: wechatUser?.id, - createTime: Number(CreateTime) * 1000, - type: MsgType, - text: Content, - aaoe: false, - }, + data: sessionMessage, }, ]; - if (MsgType === 'image') { - } - else if (MsgType === 'video') { - } - else if (MsgType === 'voice') { - } break; } default: { diff --git a/es/components/extraFile/commit/index.d.ts b/es/components/extraFile/commit/index.d.ts index e8db30e8e..ab52a6310 100644 --- a/es/components/extraFile/commit/index.d.ts +++ b/es/components/extraFile/commit/index.d.ts @@ -8,6 +8,6 @@ declare const _default: (props: import("oak-frontend-base").ReactComponentProps< executeText: string; buttonProps: {}; afterCommit: () => void; - beforeCommit: () => boolean | undefined; + beforeCommit: () => boolean | undefined | Promise; }>) => import("react").ReactElement>; export default _default; diff --git a/es/components/extraFile/commit/web.d.ts b/es/components/extraFile/commit/web.d.ts index f81b54a70..a8323fade 100644 --- a/es/components/extraFile/commit/web.d.ts +++ b/es/components/extraFile/commit/web.d.ts @@ -9,7 +9,7 @@ export default function render(props: WebComponentProps Promise | boolean; + beforeCommit?: () => Promise | boolean | undefined; afterCommit?: () => void; }, { upload: () => Promise; diff --git a/es/components/sessionMessage/list/index.js b/es/components/sessionMessage/list/index.js index d8527f511..a9a9520f3 100644 --- a/es/components/sessionMessage/list/index.js +++ b/es/components/sessionMessage/list/index.js @@ -275,7 +275,6 @@ export default OakComponent({ fileType: type, size, extension, - entity: 'sessionMessage', objectId: generateNewId(), id: generateNewId(), uploadState: 'uploading', @@ -283,22 +282,28 @@ export default OakComponent({ extra2: { isPermanent: false, }, + entity: 'sessionMessage', + entityId: sessionMessageId, }; + await this.features.extraFile2.autoUpload(extraFile, originFileObj); try { this.updateItem({ createTime: Date.now(), type: 'image', - extraFile$entity: [ - { - id: generateNewId(), - action: 'create', - data: extraFile, - }, - ], + // extraFile$entity: [ + // { + // id: generateNewId(), + // action: 'create', + // data: extraFile, + // }, + // ], }, sessionMessageId); - this.features.extraFile2.addLocalFile(extraFile?.id, originFileObj); + // this.features.extraFile2.addLocalFile( + // extraFile?.id, + // originFileObj + // ); await this.execute(undefined, false); - this.features.extraFile2.upload(extraFile?.id); + // this.features.extraFile2.upload(extraFile?.id); this.pageScroll('comment'); this.createItem(); } diff --git a/es/entities/SessionMessage.d.ts b/es/entities/SessionMessage.d.ts index 4a467da95..0da86cc9e 100644 --- a/es/entities/SessionMessage.d.ts +++ b/es/entities/SessionMessage.d.ts @@ -15,7 +15,7 @@ export interface Schema extends EntityShape { type: Type; text?: Text; files?: ExtraFile[]; - news?: String<128>; + link?: String<128>; aaoe?: Boolean; extra?: Object; } diff --git a/es/entities/SessionMessage.js b/es/entities/SessionMessage.js index 254e495c8..2758cffff 100644 --- a/es/entities/SessionMessage.js +++ b/es/entities/SessionMessage.js @@ -10,11 +10,11 @@ const entityDesc = { wechatUser: '微信用户', createTime: '发送时间', type: '消息类型', - text: '文字内容', + text: '文本内容', files: '文件', - news: '文章', + link: '图文', aaoe: '作为实体的发起者', - extra: '构额外信息', + extra: '额外信息', }, v: { type: { diff --git a/es/features/extraFile2.js b/es/features/extraFile2.js index 2250bd9ad..48402a960 100644 --- a/es/features/extraFile2.js +++ b/es/features/extraFile2.js @@ -141,11 +141,12 @@ export class ExtraFile2 extends Feature { } async autoUpload(extraFile, file) { const extraFileId = extraFile.id || generateNewId(); + const applicationId = extraFile.applicationId || this.application.getApplicationId(); await this.cache.operate('extraFile', { action: 'create', data: Object.assign(extraFile, { id: extraFileId, - applicationId: this.application.getApplicationId(), + applicationId, }), id: await generateNewIdAsync(), }); diff --git a/es/oak-app-domain/SessionMessage/Schema.d.ts b/es/oak-app-domain/SessionMessage/Schema.d.ts index fc2e54e1a..cf49a1152 100644 --- a/es/oak-app-domain/SessionMessage/Schema.d.ts +++ b/es/oak-app-domain/SessionMessage/Schema.d.ts @@ -19,7 +19,7 @@ export type OpSchema = EntityShape & { createTime?: Datetime | null; type: Type; text?: Text | null; - news?: String<128> | null; + link?: String<128> | null; aaoe?: Boolean | null; extra?: Object | null; }; @@ -32,7 +32,7 @@ export type Schema = EntityShape & { createTime?: Datetime | null; type: Type; text?: Text | null; - news?: String<128> | null; + link?: String<128> | null; aaoe?: Boolean | null; extra?: Object | null; application: Application.Schema; @@ -60,7 +60,7 @@ type AttrFilter = { createTime: Q_DateValue; type: Q_EnumValue; text: Q_StringValue; - news: Q_StringValue; + link: Q_StringValue; aaoe: Q_BooleanValue; extra: Object; extraFile$entity: ExtraFile.Filter & SubQueryPredicateMetadata; @@ -84,7 +84,7 @@ export type Projection = { createTime?: number; type?: number; text?: number; - news?: number; + link?: number; aaoe?: number; extra?: number | Object; extraFile$entity?: ExtraFile.Selection & { @@ -140,7 +140,7 @@ export type SortAttr = { } | { text: number; } | { - news: number; + link: number; } | { aaoe: number; } | { diff --git a/es/oak-app-domain/SessionMessage/Storage.js b/es/oak-app-domain/SessionMessage/Storage.js index 5cb95138f..b2d091d3c 100644 --- a/es/oak-app-domain/SessionMessage/Storage.js +++ b/es/oak-app-domain/SessionMessage/Storage.js @@ -30,7 +30,7 @@ export const desc = { text: { type: "text" }, - news: { + link: { type: "varchar", params: { length: 128 diff --git a/es/oak-app-domain/SessionMessage/locales/zh_CN.json b/es/oak-app-domain/SessionMessage/locales/zh_CN.json index b9a74305a..1c2de9066 100644 --- a/es/oak-app-domain/SessionMessage/locales/zh_CN.json +++ b/es/oak-app-domain/SessionMessage/locales/zh_CN.json @@ -1 +1 @@ -{ "name": "消息", "attr": { "application": "应用", "session": "会话", "user": "用户", "wechatUser": "微信用户", "createTime": "发送时间", "type": "消息类型", "text": "文字内容", "files": "文件", "news": "文章", "aaoe": "作为实体的发起者", "extra": "构额外信息" }, "v": { "type": { "text": "文字", "image": "图片", "voice": "音频", "video": "视频", "link": "图文", "location": "位置", "event": "事件", "miniprogrampage": "小程序" } } } +{ "name": "消息", "attr": { "application": "应用", "session": "会话", "user": "用户", "wechatUser": "微信用户", "createTime": "发送时间", "type": "消息类型", "text": "文本内容", "files": "文件", "link": "图文", "aaoe": "作为实体的发起者", "extra": "额外信息" }, "v": { "type": { "text": "文字", "image": "图片", "voice": "音频", "video": "视频", "link": "图文", "location": "位置", "event": "事件", "miniprogrampage": "小程序" } } } diff --git a/es/triggers/sessionMessage.js b/es/triggers/sessionMessage.js index 134802bc2..e12f5ec36 100644 --- a/es/triggers/sessionMessage.js +++ b/es/triggers/sessionMessage.js @@ -1,6 +1,7 @@ import { generateNewIdAsync } from 'oak-domain/lib/utils/uuid'; import { assert } from 'oak-domain/lib/utils/assert'; import { WechatSDK, } from 'oak-external-sdk'; +import { extraFileProjection } from '../types/Projection'; const triggers = [ { name: '当sessionMessage创建时时,使其相关session更新lmts', @@ -41,7 +42,35 @@ const triggers = [ const closeRootMode = context.openRootMode(); try { for (const row of rows) { - const { sessionId, aaoe, type, text } = row; + const { id } = row; + const [currentSessionMessage] = await context.select('sessionMessage', { + data: { + id: 1, + sessionId: 1, + text: 1, + type: 1, + userId: 1, + wechatUserId: 1, + wechatUser: { + id: 1, + openId: 1, + }, + applicationId: 1, + createTime: 1, + $$createAt$$: 1, + aaoe: 1, + extraFile$entity: { + $entity: 'extraFile', + data: extraFileProjection, + }, + }, + filter: { + id, + }, + count: 1, + indexFrom: 0, + }, {}); + const { sessionId, aaoe, type, text, extraFile$entity } = currentSessionMessage; if (aaoe) { const msgType = type; const [sessionMessage] = await context.select('sessionMessage', { @@ -127,14 +156,19 @@ const triggers = [ }); break; } - // case 'image' :{ - // wechatInstance.sendServeMessage({ - // openId: sessionMessage.wechatUser?.openId!, - // type: msgType, - // mediaId: '', - // }); - // break; - // } + case 'image': { + const extraFile = extraFile$entity && extraFile$entity[0]; + if (extraFile) { + const mediaId = extraFile.extra1; + wechatInstance.sendServeMessage({ + openId: sessionMessage.wechatUser + ?.openId, + type: msgType, + mediaId, + }); + } + break; + } default: { assert(false, `消息类型「${msgType}」尚未支持`); } diff --git a/lib/aspects/session.js b/lib/aspects/session.js index dd37b4832..970167546 100644 --- a/lib/aspects/session.js +++ b/lib/aspects/session.js @@ -62,6 +62,7 @@ async function createSession(params, context) { }, filter: { openId: FromUserName, + applicationId: entityId, }, }, {}); const result = await context.select('session', { @@ -79,28 +80,95 @@ async function createSession(params, context) { openId: FromUserName, }, }, {}); + const sessionMessage = { + id: await (0, uuid_1.generateNewIdAsync)(), + applicationId: entityId, + wechatUserId: wechatUser?.id, + createTime: Number(CreateTime) * 1000, + type: MsgType, + aaoe: false, + extra: data, + userId, + }; + if (MsgType === 'text') { + Object.assign(sessionMessage, { + text: Content, + }); + } + else if (MsgType === 'image') { + Object.assign(sessionMessage, { + extraFile$entity: [ + { + id: await (0, uuid_1.generateNewIdAsync)(), + action: 'create', + data: { + id: await (0, uuid_1.generateNewIdAsync)(), + applicationId: entityId, + origin: 'wechat', + type: 'image', + tag1: 'image', + objectId: (0, uuid_1.generateNewIdAsync)(), + sort: 1000, + uploadState: 'success', + extra1: data.MediaId, + extra2: { + isPermanent: false, + }, + }, + }, + ], + }); + } + else if (MsgType === 'video') { + Object.assign(sessionMessage, { + extraFile$entity: [ + { + id: await (0, uuid_1.generateNewIdAsync)(), + action: 'create', + data: { + id: await (0, uuid_1.generateNewIdAsync)(), + applicationId: entityId, + origin: 'wechat', + type: 'video', + tag1: 'video', + objectId: (0, uuid_1.generateNewIdAsync)(), + sort: 1000, + uploadState: 'success', + extra1: data.MediaId, + }, + }, + ], + }); + } + else if (MsgType === 'voice') { + Object.assign(sessionMessage, { + extraFile$entity: [ + { + id: await (0, uuid_1.generateNewIdAsync)(), + action: 'create', + data: { + id: await (0, uuid_1.generateNewIdAsync)(), + applicationId: entityId, + origin: 'wechat', + type: 'audio', + tag1: 'audio', + objectId: (0, uuid_1.generateNewIdAsync)(), + sort: 1000, + uploadState: 'success', + extra1: data.MediaId, + }, + }, + ], + }); + } session = result[0]; sessionMessage$session = [ { id: await (0, uuid_1.generateNewIdAsync)(), action: 'create', - data: { - id: await (0, uuid_1.generateNewIdAsync)(), - applicationId: wechatUser?.applicationId, - wechatUserId: wechatUser?.id, - createTime: Number(CreateTime) * 1000, - type: MsgType, - text: Content, - aaoe: false, - }, + data: sessionMessage, }, ]; - if (MsgType === 'image') { - } - else if (MsgType === 'video') { - } - else if (MsgType === 'voice') { - } break; } default: { diff --git a/lib/components/extraFile/commit/index.d.ts b/lib/components/extraFile/commit/index.d.ts index e8db30e8e..ab52a6310 100644 --- a/lib/components/extraFile/commit/index.d.ts +++ b/lib/components/extraFile/commit/index.d.ts @@ -8,6 +8,6 @@ declare const _default: (props: import("oak-frontend-base").ReactComponentProps< executeText: string; buttonProps: {}; afterCommit: () => void; - beforeCommit: () => boolean | undefined; + beforeCommit: () => boolean | undefined | Promise; }>) => import("react").ReactElement>; export default _default; diff --git a/lib/components/extraFile/commit/web.d.ts b/lib/components/extraFile/commit/web.d.ts index f81b54a70..a8323fade 100644 --- a/lib/components/extraFile/commit/web.d.ts +++ b/lib/components/extraFile/commit/web.d.ts @@ -9,7 +9,7 @@ export default function render(props: WebComponentProps Promise | boolean; + beforeCommit?: () => Promise | boolean | undefined; afterCommit?: () => void; }, { upload: () => Promise; diff --git a/lib/components/sessionMessage/list/index.js b/lib/components/sessionMessage/list/index.js index 8c55284aa..e0256a139 100644 --- a/lib/components/sessionMessage/list/index.js +++ b/lib/components/sessionMessage/list/index.js @@ -277,7 +277,6 @@ exports.default = OakComponent({ fileType: type, size, extension, - entity: 'sessionMessage', objectId: (0, uuid_1.generateNewId)(), id: (0, uuid_1.generateNewId)(), uploadState: 'uploading', @@ -285,22 +284,28 @@ exports.default = OakComponent({ extra2: { isPermanent: false, }, + entity: 'sessionMessage', + entityId: sessionMessageId, }; + await this.features.extraFile2.autoUpload(extraFile, originFileObj); try { this.updateItem({ createTime: Date.now(), type: 'image', - extraFile$entity: [ - { - id: (0, uuid_1.generateNewId)(), - action: 'create', - data: extraFile, - }, - ], + // extraFile$entity: [ + // { + // id: generateNewId(), + // action: 'create', + // data: extraFile, + // }, + // ], }, sessionMessageId); - this.features.extraFile2.addLocalFile(extraFile?.id, originFileObj); + // this.features.extraFile2.addLocalFile( + // extraFile?.id, + // originFileObj + // ); await this.execute(undefined, false); - this.features.extraFile2.upload(extraFile?.id); + // this.features.extraFile2.upload(extraFile?.id); this.pageScroll('comment'); this.createItem(); } diff --git a/lib/entities/SessionMessage.d.ts b/lib/entities/SessionMessage.d.ts index 4a467da95..0da86cc9e 100644 --- a/lib/entities/SessionMessage.d.ts +++ b/lib/entities/SessionMessage.d.ts @@ -15,7 +15,7 @@ export interface Schema extends EntityShape { type: Type; text?: Text; files?: ExtraFile[]; - news?: String<128>; + link?: String<128>; aaoe?: Boolean; extra?: Object; } diff --git a/lib/entities/SessionMessage.js b/lib/entities/SessionMessage.js index ded6d1d18..b9e2b9e6a 100644 --- a/lib/entities/SessionMessage.js +++ b/lib/entities/SessionMessage.js @@ -12,11 +12,11 @@ const entityDesc = { wechatUser: '微信用户', createTime: '发送时间', type: '消息类型', - text: '文字内容', + text: '文本内容', files: '文件', - news: '文章', + link: '图文', aaoe: '作为实体的发起者', - extra: '构额外信息', + extra: '额外信息', }, v: { type: { diff --git a/lib/features/extraFile2.js b/lib/features/extraFile2.js index 0cf037cc7..3436743e4 100644 --- a/lib/features/extraFile2.js +++ b/lib/features/extraFile2.js @@ -144,11 +144,12 @@ class ExtraFile2 extends oak_frontend_base_1.Feature { } async autoUpload(extraFile, file) { const extraFileId = extraFile.id || (0, oak_domain_1.generateNewId)(); + const applicationId = extraFile.applicationId || this.application.getApplicationId(); await this.cache.operate('extraFile', { action: 'create', data: Object.assign(extraFile, { id: extraFileId, - applicationId: this.application.getApplicationId(), + applicationId, }), id: await (0, oak_domain_1.generateNewIdAsync)(), }); diff --git a/lib/oak-app-domain/SessionMessage/Schema.d.ts b/lib/oak-app-domain/SessionMessage/Schema.d.ts index fc2e54e1a..cf49a1152 100644 --- a/lib/oak-app-domain/SessionMessage/Schema.d.ts +++ b/lib/oak-app-domain/SessionMessage/Schema.d.ts @@ -19,7 +19,7 @@ export type OpSchema = EntityShape & { createTime?: Datetime | null; type: Type; text?: Text | null; - news?: String<128> | null; + link?: String<128> | null; aaoe?: Boolean | null; extra?: Object | null; }; @@ -32,7 +32,7 @@ export type Schema = EntityShape & { createTime?: Datetime | null; type: Type; text?: Text | null; - news?: String<128> | null; + link?: String<128> | null; aaoe?: Boolean | null; extra?: Object | null; application: Application.Schema; @@ -60,7 +60,7 @@ type AttrFilter = { createTime: Q_DateValue; type: Q_EnumValue; text: Q_StringValue; - news: Q_StringValue; + link: Q_StringValue; aaoe: Q_BooleanValue; extra: Object; extraFile$entity: ExtraFile.Filter & SubQueryPredicateMetadata; @@ -84,7 +84,7 @@ export type Projection = { createTime?: number; type?: number; text?: number; - news?: number; + link?: number; aaoe?: number; extra?: number | Object; extraFile$entity?: ExtraFile.Selection & { @@ -140,7 +140,7 @@ export type SortAttr = { } | { text: number; } | { - news: number; + link: number; } | { aaoe: number; } | { diff --git a/lib/oak-app-domain/SessionMessage/Storage.js b/lib/oak-app-domain/SessionMessage/Storage.js index d4f4fb060..115d2ccf6 100644 --- a/lib/oak-app-domain/SessionMessage/Storage.js +++ b/lib/oak-app-domain/SessionMessage/Storage.js @@ -33,7 +33,7 @@ exports.desc = { text: { type: "text" }, - news: { + link: { type: "varchar", params: { length: 128 diff --git a/lib/oak-app-domain/SessionMessage/locales/zh_CN.json b/lib/oak-app-domain/SessionMessage/locales/zh_CN.json index b9a74305a..1c2de9066 100644 --- a/lib/oak-app-domain/SessionMessage/locales/zh_CN.json +++ b/lib/oak-app-domain/SessionMessage/locales/zh_CN.json @@ -1 +1 @@ -{ "name": "消息", "attr": { "application": "应用", "session": "会话", "user": "用户", "wechatUser": "微信用户", "createTime": "发送时间", "type": "消息类型", "text": "文字内容", "files": "文件", "news": "文章", "aaoe": "作为实体的发起者", "extra": "构额外信息" }, "v": { "type": { "text": "文字", "image": "图片", "voice": "音频", "video": "视频", "link": "图文", "location": "位置", "event": "事件", "miniprogrampage": "小程序" } } } +{ "name": "消息", "attr": { "application": "应用", "session": "会话", "user": "用户", "wechatUser": "微信用户", "createTime": "发送时间", "type": "消息类型", "text": "文本内容", "files": "文件", "link": "图文", "aaoe": "作为实体的发起者", "extra": "额外信息" }, "v": { "type": { "text": "文字", "image": "图片", "voice": "音频", "video": "视频", "link": "图文", "location": "位置", "event": "事件", "miniprogrampage": "小程序" } } } diff --git a/lib/triggers/sessionMessage.js b/lib/triggers/sessionMessage.js index b9c5996fd..7dbd06b11 100644 --- a/lib/triggers/sessionMessage.js +++ b/lib/triggers/sessionMessage.js @@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true }); const uuid_1 = require("oak-domain/lib/utils/uuid"); const assert_1 = require("oak-domain/lib/utils/assert"); const oak_external_sdk_1 = require("oak-external-sdk"); +const Projection_1 = require("../types/Projection"); const triggers = [ { name: '当sessionMessage创建时时,使其相关session更新lmts', @@ -43,7 +44,35 @@ const triggers = [ const closeRootMode = context.openRootMode(); try { for (const row of rows) { - const { sessionId, aaoe, type, text } = row; + const { id } = row; + const [currentSessionMessage] = await context.select('sessionMessage', { + data: { + id: 1, + sessionId: 1, + text: 1, + type: 1, + userId: 1, + wechatUserId: 1, + wechatUser: { + id: 1, + openId: 1, + }, + applicationId: 1, + createTime: 1, + $$createAt$$: 1, + aaoe: 1, + extraFile$entity: { + $entity: 'extraFile', + data: Projection_1.extraFileProjection, + }, + }, + filter: { + id, + }, + count: 1, + indexFrom: 0, + }, {}); + const { sessionId, aaoe, type, text, extraFile$entity } = currentSessionMessage; if (aaoe) { const msgType = type; const [sessionMessage] = await context.select('sessionMessage', { @@ -129,14 +158,19 @@ const triggers = [ }); break; } - // case 'image' :{ - // wechatInstance.sendServeMessage({ - // openId: sessionMessage.wechatUser?.openId!, - // type: msgType, - // mediaId: '', - // }); - // break; - // } + case 'image': { + const extraFile = extraFile$entity && extraFile$entity[0]; + if (extraFile) { + const mediaId = extraFile.extra1; + wechatInstance.sendServeMessage({ + openId: sessionMessage.wechatUser + ?.openId, + type: msgType, + mediaId, + }); + } + break; + } default: { (0, assert_1.assert)(false, `消息类型「${msgType}」尚未支持`); } diff --git a/src/aspects/session.ts b/src/aspects/session.ts index bdb0fcf15..636ae07cc 100644 --- a/src/aspects/session.ts +++ b/src/aspects/session.ts @@ -97,6 +97,7 @@ export async function createSession< }, filter: { openId: FromUserName, + applicationId: entityId, }, }, {} @@ -120,27 +121,95 @@ export async function createSession< }, {} ); + + const sessionMessage = { + id: await generateNewIdAsync(), + applicationId: entityId, + wechatUserId: wechatUser?.id, + createTime: Number(CreateTime) * 1000, + type: MsgType, + aaoe: false, + extra: data, + userId, + }; + if (MsgType === 'text') { + Object.assign(sessionMessage, { + text: Content, + }); + } else if (MsgType === 'image') { + Object.assign(sessionMessage, { + extraFile$entity: [ + { + id: await generateNewIdAsync(), + action: 'create', + data: { + id: await generateNewIdAsync(), + applicationId: entityId, + origin: 'wechat', + type: 'image', + tag1: 'image', + objectId: generateNewIdAsync(), // 这个域用来标识唯一性 + sort: 1000, + uploadState: 'success', + extra1: data.MediaId, + extra2: { + isPermanent: false, + }, + }, + }, + ], + }); + } else if (MsgType === 'video') { + Object.assign(sessionMessage, { + extraFile$entity: [ + { + id: await generateNewIdAsync(), + action: 'create', + data: { + id: await generateNewIdAsync(), + applicationId: entityId, + origin: 'wechat', + type: 'video', + tag1: 'video', + objectId: generateNewIdAsync(), // 这个域用来标识唯一性 + sort: 1000, + uploadState: 'success', + extra1: data.MediaId, + }, + }, + ], + }); + } else if (MsgType === 'voice') { + Object.assign(sessionMessage, { + extraFile$entity: [ + { + id: await generateNewIdAsync(), + action: 'create', + data: { + id: await generateNewIdAsync(), + applicationId: entityId, + origin: 'wechat', + type: 'audio', + tag1: 'audio', + objectId: generateNewIdAsync(), // 这个域用来标识唯一性 + sort: 1000, + uploadState: 'success', + extra1: data.MediaId, + }, + }, + ], + }); + } + session = result[0]; sessionMessage$session = [ { id: await generateNewIdAsync(), action: 'create', - data: { - id: await generateNewIdAsync(), - applicationId: wechatUser?.applicationId, - wechatUserId: wechatUser?.id, - createTime: Number(CreateTime) * 1000, - type: MsgType, - text: Content, - aaoe: false, - }, + data: sessionMessage, }, ]; - if (MsgType === 'image') { - } else if (MsgType === 'video') { - } else if (MsgType === 'voice') { - } - + break; } default: { diff --git a/src/components/extraFile/commit/index.ts b/src/components/extraFile/commit/index.ts index 783265f6b..9d610ae6d 100644 --- a/src/components/extraFile/commit/index.ts +++ b/src/components/extraFile/commit/index.ts @@ -2,6 +2,7 @@ import assert from 'assert'; import { EntityDict } from '../../../oak-app-domain'; import { FileState } from '../../../features/extraFile2'; + export default OakComponent({ formData({ features }) { const ids: string[] = this.getEfIds(); @@ -28,7 +29,7 @@ export default OakComponent({ executeText: '', buttonProps: {}, afterCommit: () => {}, - beforeCommit: (() => true) as () => boolean | undefined, + beforeCommit: (() => true) as () => boolean | undefined | Promise, }, methods: { getEfIds() { diff --git a/src/components/extraFile/commit/web.tsx b/src/components/extraFile/commit/web.tsx index f27dbb233..8db226e9b 100644 --- a/src/components/extraFile/commit/web.tsx +++ b/src/components/extraFile/commit/web.tsx @@ -16,7 +16,10 @@ export default function render( type?: ButtonProps['type']; executeText?: string; buttonProps?: ButtonProps; - beforeCommit?: () => Promise | boolean; + beforeCommit?: () => + | Promise + | boolean + | undefined; afterCommit?: () => void; }, { diff --git a/src/components/sessionMessage/list/index.ts b/src/components/sessionMessage/list/index.ts index 6a0671162..c1e56f5b6 100644 --- a/src/components/sessionMessage/list/index.ts +++ b/src/components/sessionMessage/list/index.ts @@ -317,7 +317,6 @@ export default OakComponent({ fileType: type, size, extension, - entity: 'sessionMessage', objectId: generateNewId(), id: generateNewId(), uploadState: 'uploading', @@ -325,29 +324,36 @@ export default OakComponent({ extra2: { isPermanent: false, }, + entity: 'sessionMessage', + entityId: sessionMessageId, } as EntityDict['extraFile']['CreateSingle']['data']; + await this.features.extraFile2.autoUpload( + extraFile as EntityDict['extraFile']['OpSchema'], + originFileObj + ); + try { this.updateItem( { createTime: Date.now(), type: 'image', - extraFile$entity: [ - { - id: generateNewId(), - action: 'create', - data: extraFile, - }, - ], + // extraFile$entity: [ + // { + // id: generateNewId(), + // action: 'create', + // data: extraFile, + // }, + // ], }, sessionMessageId ); - this.features.extraFile2.addLocalFile( - extraFile?.id, - originFileObj - ); + // this.features.extraFile2.addLocalFile( + // extraFile?.id, + // originFileObj + // ); await this.execute(undefined, false); - this.features.extraFile2.upload(extraFile?.id); + // this.features.extraFile2.upload(extraFile?.id); this.pageScroll('comment'); this.createItem(); } catch (err) { diff --git a/src/entities/SessionMessage.ts b/src/entities/SessionMessage.ts index 5763228e5..03710f1fe 100644 --- a/src/entities/SessionMessage.ts +++ b/src/entities/SessionMessage.ts @@ -26,7 +26,7 @@ export interface Schema extends EntityShape { type: Type; text?: Text; files?: ExtraFile[]; - news?: String<128>; + link?: String<128>; aaoe?: Boolean; // as agent of entity extra?: Object; }; @@ -42,11 +42,11 @@ const entityDesc: EntityDesc = { wechatUser: '微信用户', createTime: '发送时间', type: '消息类型', - text: '文字内容', + text: '文本内容', files: '文件', - news: '文章', + link: '图文', aaoe: '作为实体的发起者', - extra: '构额外信息', + extra: '额外信息', }, v: { type: { diff --git a/src/features/extraFile2.ts b/src/features/extraFile2.ts index a25839645..edb821ce9 100644 --- a/src/features/extraFile2.ts +++ b/src/features/extraFile2.ts @@ -210,11 +210,13 @@ export class ExtraFile2< file: File | string ) { const extraFileId = extraFile.id || generateNewId(); + const applicationId = + extraFile.applicationId || this.application.getApplicationId(); await this.cache.operate('extraFile', { action: 'create', data: Object.assign(extraFile, { id: extraFileId, - applicationId: this.application.getApplicationId(), + applicationId, }), id: await generateNewIdAsync(), } as EntityDict['extraFile']['Operation']); diff --git a/src/oak-app-domain/SessionMessage/Schema.ts b/src/oak-app-domain/SessionMessage/Schema.ts index d863f9de0..e97a1338b 100644 --- a/src/oak-app-domain/SessionMessage/Schema.ts +++ b/src/oak-app-domain/SessionMessage/Schema.ts @@ -20,7 +20,7 @@ export type OpSchema = EntityShape & { createTime?: Datetime | null; type: Type; text?: Text | null; - news?: String<128> | null; + link?: String<128> | null; aaoe?: Boolean | null; extra?: Object | null; }; @@ -33,7 +33,7 @@ export type Schema = EntityShape & { createTime?: Datetime | null; type: Type; text?: Text | null; - news?: String<128> | null; + link?: String<128> | null; aaoe?: Boolean | null; extra?: Object | null; application: Application.Schema; @@ -61,7 +61,7 @@ type AttrFilter = { createTime: Q_DateValue; type: Q_EnumValue; text: Q_StringValue; - news: Q_StringValue; + link: Q_StringValue; aaoe: Q_BooleanValue; extra: Object; extraFile$entity: ExtraFile.Filter & SubQueryPredicateMetadata; @@ -85,7 +85,7 @@ export type Projection = { createTime?: number; type?: number; text?: number; - news?: number; + link?: number; aaoe?: number; extra?: number | Object; extraFile$entity?: ExtraFile.Selection & { @@ -141,7 +141,7 @@ export type SortAttr = { } | { text: number; } | { - news: number; + link: number; } | { aaoe: number; } | { diff --git a/src/oak-app-domain/SessionMessage/Storage.ts b/src/oak-app-domain/SessionMessage/Storage.ts index 5fe02af04..445fafc2e 100644 --- a/src/oak-app-domain/SessionMessage/Storage.ts +++ b/src/oak-app-domain/SessionMessage/Storage.ts @@ -32,7 +32,7 @@ export const desc: StorageDesc = { text: { type: "text" }, - news: { + link: { type: "varchar", params: { length: 128 diff --git a/src/oak-app-domain/SessionMessage/locales/zh_CN.json b/src/oak-app-domain/SessionMessage/locales/zh_CN.json index 77acf6986..af104ed7c 100644 --- a/src/oak-app-domain/SessionMessage/locales/zh_CN.json +++ b/src/oak-app-domain/SessionMessage/locales/zh_CN.json @@ -1 +1 @@ -{"name":"消息","attr":{"application":"应用","session":"会话","user":"用户","wechatUser":"微信用户","createTime":"发送时间","type":"消息类型","text":"文字内容","files":"文件","news":"文章","aaoe":"作为实体的发起者","extra":"构额外信息"},"v":{"type":{"text":"文字","image":"图片","voice":"音频","video":"视频","link":"图文","location":"位置","event":"事件","miniprogrampage":"小程序"}}} \ No newline at end of file +{"name":"消息","attr":{"application":"应用","session":"会话","user":"用户","wechatUser":"微信用户","createTime":"发送时间","type":"消息类型","text":"文本内容","files":"文件","link":"图文","aaoe":"作为实体的发起者","extra":"额外信息"},"v":{"type":{"text":"文字","image":"图片","voice":"音频","video":"视频","link":"图文","location":"位置","event":"事件","miniprogrampage":"小程序"}}} \ No newline at end of file diff --git a/src/triggers/sessionMessage.ts b/src/triggers/sessionMessage.ts index e78bed447..df8000920 100644 --- a/src/triggers/sessionMessage.ts +++ b/src/triggers/sessionMessage.ts @@ -11,6 +11,7 @@ import { WechatMpInstance, WechatPublicInstance, } from 'oak-external-sdk'; +import { extraFileProjection } from '../types/Projection' const triggers: Trigger< EntityDict, @@ -69,7 +70,41 @@ const triggers: Trigger< const closeRootMode = context.openRootMode(); try { for (const row of rows) { - const { sessionId, aaoe, type, text } = row; + const { id } = row; + + const [currentSessionMessage] = await context.select( + 'sessionMessage', + { + data: { + id: 1, + sessionId: 1, + text: 1, + type: 1, + userId: 1, + wechatUserId: 1, + wechatUser: { + id: 1, + openId: 1, + }, + applicationId: 1, + createTime: 1, + $$createAt$$: 1, + aaoe: 1, + extraFile$entity: { + $entity: 'extraFile', + data: extraFileProjection, + }, + }, + filter: { + id, + }, + count: 1, + indexFrom: 0, + }, + {} + ); + + const { sessionId, aaoe, type, text, extraFile$entity } = currentSessionMessage; if (aaoe) { const msgType = type; @@ -184,14 +219,20 @@ const triggers: Trigger< }); break; } - // case 'image' :{ - // wechatInstance.sendServeMessage({ - // openId: sessionMessage.wechatUser?.openId!, - // type: msgType, - // mediaId: '', - // }); - // break; - // } + case 'image': { + const extraFile = extraFile$entity && extraFile$entity[0]; + if (extraFile) { + const mediaId = extraFile.extra1!; + wechatInstance.sendServeMessage({ + openId: sessionMessage.wechatUser + ?.openId!, + type: msgType, + mediaId, + }); + } + + break; + } default: { assert( false,