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

fix: muti-channel related problems #68

Merged
merged 6 commits into from
May 6, 2023

Conversation

WangEdward
Copy link
Contributor

  • 修复 message 页面未知通道
  • 增加 /api/channel/short 接口

仍存在的问题:

  • 需要修复设置页面 默认推送方式 ,这里请求 /api/channel/short,把选项替换掉就行了,我不怎么会写 react,大佬就交给你啦😜
    <Form.Select
    label='默认推送方式'
    name='channel'
    options={[
    { key: 'email', text: '邮件', value: 'email' },
    { key: 'test', text: '微信测试号', value: 'test' },
    { key: 'corp_app', text: '企业微信应用号', value: 'corp_app' },
    { key: 'corp', text: '企业微信群机器人', value: 'corp' },
    { key: 'lark', text: '飞书群机器人', value: 'lark' },
    { key: 'ding', text: '钉钉群机器人', value: 'ding' },
    { key: 'bark', text: 'Bark App', value: 'bark' },
    { key: 'client', text: 'WebSocket 客户端', value: 'client' },
    { key: 'telegram', text: 'Telegram 机器人', value: 'telegram' },
    { key: 'discord', text: 'Discord 群机器人', value: 'discord' },
    ]}
    value={inputs.channel}
    onChange={handleInputChange}
    />

@songquanpeng
Copy link
Owner

我没太理解 /api/channel/short 这个接口是干嘛用的。

@WangEdward
Copy link
Contributor Author

因为现在的 channel 识别符为 channel 的 name 字段,所以使用原先诸如 corp_apptelegramdiscord之类的标识符就应该在推送方式中被替代,很多场景下需要使用 channel 名(如设置推送方式) ,但是 /api/channel/ 请求过于臃肿且有分页因此引入了 /api/channel/short 接口

@WangEdward
Copy link
Contributor Author

此处目前是有 bug 的,使用 option 列表中的设置在请求 push 消息接口时会返回{"message":"无效的渠道名称:wechat_corp","success":false} 因此需要将下拉框的内容替换为 /api/channel/short 返回的内容
Screenshot 2023-05-06 at 18 07 41

@songquanpeng
Copy link
Owner

songquanpeng commented May 6, 2023 via email

@WangEdward
Copy link
Contributor Author

/api/channel/short 就是用于获取用户的通道列表的啊😂

@WangEdward
Copy link
Contributor Author

#69

@songquanpeng
Copy link
Owner

我感觉没有必要专门定义一个接口和结构体。

目前打算在 GET /api/channel 上加一个 query 参数来解决这个问题。

@WangEdward
Copy link
Contributor Author

WangEdward commented May 6, 2023

新建结构体是按照 gorm 官方的指南写的 Smart Select Fields
这是 ‘Smart’ 的做法好吧

@songquanpeng
Copy link
Owner

这样,看来有必要找个时间读完官方文档看一下有没有漏掉的最佳实践。

@songquanpeng
Copy link
Owner

改好了:
image

@songquanpeng songquanpeng merged commit c70cc3a into songquanpeng:master May 6, 2023
@@ -67,6 +74,11 @@ func GetChannelsByUserId(userId int, startIdx int, num int) (channels []*Channel
return channels, err
}

func GetBriefChannelsByUserId(userId int) (channels []*BriefChannel, err error) {
err = DB.Model(&Channel{}).Select("id", "name", "description").Where("user_id = ? and status = ?", userId, common.ChannelStatusEnabled).Find(&channels).Error
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这一小段或许是可以删掉的?.Select("id", "name", "description")

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

确实,不过应该不影响性能。

@@ -20,6 +20,13 @@ export function renderChannel(key) {
</Label>
);
}
if (key) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里要加个判断,不然消息历史页面会显示未知通道,简单方法就直接把 key 打上去,如果要加背景颜色的话可能还是得调 API

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

为什么会显示未知通道?历史消息的通道类型必然是系统里已有的呀。

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我发现这个问题了,问题不是出在这里,而是通道的类型没有传给前端。

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

确实还是你的方法简单直接,先这样搞算了哈哈哈,又不是不能用。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/api/message/?p=0 这个接口的返回 channel 是什么呢?对,是用户自定义的通道名,那这个通道名会在你的CHANNEL_OPTIONS 里吗?不会😅!

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

是这样的,v0.4 版本改动后确实忘记处理这里了。

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

直接渲染就好了:

  <Table.Cell>
    <Label>{message.channel}</Label>
  </Table.Cell>

就不走 renderChannel 了。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

嗯,确实是个好主意

songquanpeng added a commit that referenced this pull request May 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants