Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

feat: 🎸 channel #228

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
54 changes: 54 additions & 0 deletions src/client/puppet-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -873,6 +873,28 @@ class PuppetService extends PUPPET.Puppet {
return contactId
}

override async messageChannel (
messageId: string,
): Promise<PUPPET.payloads.Channel> {
log.verbose('PuppetService', 'messageChannel(%s)', messageId)

const request = new grpcPuppet.MessageChannelRequest()
request.setId(messageId)

const response = await util.promisify(
this.grpcManager.client.messageChannel
.bind(this.grpcManager.client),
)(request)

const channelPayload = response.getChannel()!.toObject()

const payload: PUPPET.payloads.Channel = {
...channelPayload,
}

return payload
}

override async messageSendMiniProgram (
conversationId : string,
miniProgramPayload : PUPPET.payloads.MiniProgram,
Expand Down Expand Up @@ -951,6 +973,38 @@ class PuppetService extends PUPPET.Puppet {
}
}

override async messageSendChannel (
conversationId: string,
channelPayload: PUPPET.payloads.Channel,
): Promise<void | string> {
log.verbose('PuppetService', 'messageSendChannel(%s, "%s")', conversationId, JSON.stringify(channelPayload))

const request = new grpcPuppet.MessageSendChannelRequest()
request.setConversationId(conversationId)

const pbChannelPayload = new grpcPuppet.ChannelPayload()
if (channelPayload.avatar) { pbChannelPayload.setAvatar(channelPayload.avatar) }
if (channelPayload.coverUrl) { pbChannelPayload.setCoverUrl(channelPayload.coverUrl) }
if (channelPayload.desc) { pbChannelPayload.setDesc(channelPayload.desc) }
if (channelPayload.extras) { pbChannelPayload.setExtras(channelPayload.extras) }
if (channelPayload.feedType) { pbChannelPayload.setFeedType(channelPayload.feedType) }
if (channelPayload.nickname) { pbChannelPayload.setNickname(channelPayload.nickname) }
if (channelPayload.thumbUrl) { pbChannelPayload.setThumbUrl(channelPayload.thumbUrl) }
if (channelPayload.url) { pbChannelPayload.setUrl(channelPayload.url) }
request.setChannel(pbChannelPayload)

const response = await util.promisify(
this.grpcManager.client.messageSendChannel
.bind(this.grpcManager.client),
)(request)

const messageId = response.getId()

if (messageId) {
return messageId
}
}

override async messageRecall (
messageId: string,
): Promise<boolean> {
Expand Down
57 changes: 57 additions & 0 deletions src/server/puppet-implementation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,34 @@ function puppetImplementation (
}
},

messageChannel: async (call, callback) => {
log.verbose('PuppetServiceImpl', 'messageChannel()')

try {
const id = call.request.getId()

const payload = await puppet.messageChannel(id)

const response = new grpcPuppet.MessageChannelResponse()

const pbChannelPayload = new grpcPuppet.ChannelPayload()
if (payload.avatar) { pbChannelPayload.setAvatar(payload.avatar) }
if (payload.coverUrl) { pbChannelPayload.setCoverUrl(payload.coverUrl) }
if (payload.desc) { pbChannelPayload.setDesc(payload.desc) }
if (payload.extras) { pbChannelPayload.setExtras(payload.extras) }
if (payload.feedType) { pbChannelPayload.setFeedType(payload.feedType) }
if (payload.nickname) { pbChannelPayload.setNickname(payload.nickname) }
if (payload.thumbUrl) { pbChannelPayload.setThumbUrl(payload.thumbUrl) }
if (payload.url) { pbChannelPayload.setUrl(payload.url) }
response.setChannel(pbChannelPayload)

return callback(null, response)

} catch (e) {
return grpcError('messageMiniProgram', e, callback)
}
},

messagePayload: async (call, callback) => {
log.verbose('PuppetServiceImpl', 'messagePayload()')

Expand Down Expand Up @@ -992,6 +1020,35 @@ function puppetImplementation (
}
},

messageSendChannel: async (call, callback) => {
log.verbose('PuppetServiceImpl', 'messageSendChannel()')

try {
const conversationId = call.request.getConversationId()
const pbChannelPayload = call.request.getChannel()?.toObject()

if (!pbChannelPayload) {
return grpcError('messageSendUrl', new Error().stack, callback)
}
const payload: PUPPET.payloads.Channel = {
...pbChannelPayload,
}

const messageId = await puppet.messageSendChannel(conversationId, payload)

const response = new grpcPuppet.MessageSendChannelResponse()

if (messageId) {
response.setId(messageId)
}

return callback(null, response)

} catch (e) {
return grpcError('messageSendChannel', e, callback)
}
},

messageUrl: async (call, callback) => {
log.verbose('PuppetServiceImpl', 'messageUrl()')

Expand Down