forked from Gitlink/forgeplus
add: notice message skeletal code
This commit is contained in:
parent
8c60ce1d76
commit
86d634d94f
|
@ -0,0 +1,121 @@
|
|||
class Users::MessagesController < Users::BaseController
|
||||
before_action :private_user_resources!
|
||||
|
||||
def index
|
||||
data = {
|
||||
"receiver": 2,
|
||||
"type": @message_type,
|
||||
"unread_total": 5,
|
||||
"unread_notification": 3,
|
||||
"unread_atme": 2,
|
||||
"records": [
|
||||
{
|
||||
"id": 1,
|
||||
"sender": 5,
|
||||
"receiver": 2,
|
||||
"content": "Atme Message Content 1",
|
||||
"status": 1,
|
||||
"type": 2,
|
||||
"source": "PullRequestAtme",
|
||||
"notification_url": "http://www.baidu.com",
|
||||
"created_at": "2021-09-09 14:34:40"
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"sender": 4,
|
||||
"receiver": 2,
|
||||
"content": "Atme Message Content 2",
|
||||
"status": 0,
|
||||
"type": 2,
|
||||
"source": "IssueAtme",
|
||||
"notification_url": "http://www.baidu.com",
|
||||
"created_at": "2021-09-09 14:34:40"
|
||||
},
|
||||
{
|
||||
"id": 3,
|
||||
"sender": -1,
|
||||
"receiver": 2,
|
||||
"content": "Notification Message Content 1",
|
||||
"status": 1,
|
||||
"type": 1,
|
||||
"source": "IssueDelete",
|
||||
"notification_url": "http://www.baidu.com",
|
||||
"created_at": "2021-09-09 14:34:40"
|
||||
},
|
||||
{
|
||||
"id": 4,
|
||||
"sender": -1,
|
||||
"receiver": 2,
|
||||
"content": "Notification Message Content 2",
|
||||
"status": 0,
|
||||
"type": 1,
|
||||
"source": "IssueChanged",
|
||||
"notification_url": "http://www.baidu.com",
|
||||
"created_at": "2021-09-09 14:34:40"
|
||||
},
|
||||
{
|
||||
"id": 5,
|
||||
"sender": -1,
|
||||
"receiver": 2,
|
||||
"content": "Notification Message Content 3",
|
||||
"status": 0,
|
||||
"type": 1,
|
||||
"source": "ProjectJoined",
|
||||
"notification_url": "http://www.baidu.com",
|
||||
"created_at": "2021-09-09 14:34:40"
|
||||
}
|
||||
],
|
||||
"records_count": 5,
|
||||
"page_num": 1,
|
||||
"total_page_size": 1,
|
||||
"page_size": 10
|
||||
}
|
||||
result = [1, "请求成功", data]
|
||||
return render_error if result.nil?
|
||||
puts result
|
||||
@data = result[2].stringify_keys
|
||||
|
||||
end
|
||||
|
||||
def create
|
||||
return render_forbidden unless %w(3).include(@message_type)
|
||||
render_ok
|
||||
end
|
||||
|
||||
def delete
|
||||
return render_forbidden unless %w(2).include(@message_type)
|
||||
render_ok
|
||||
end
|
||||
|
||||
def read
|
||||
render_ok
|
||||
end
|
||||
|
||||
private
|
||||
def message_type
|
||||
@message_type = begin
|
||||
case params[:type]
|
||||
when "notification"
|
||||
1
|
||||
when "atme"
|
||||
2
|
||||
else
|
||||
-1
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def message_params
|
||||
{
|
||||
sender: current_user.id,
|
||||
reservers: @receiver.id,
|
||||
type: @message_type,
|
||||
content: params[:content]
|
||||
}
|
||||
end
|
||||
|
||||
|
||||
def find_receiver
|
||||
@receiver = User.find_by(login: params[:receiver_login])
|
||||
end
|
||||
end
|
|
@ -1,7 +1,7 @@
|
|||
<!--
|
||||
* @Date: 2021-03-01 10:35:21
|
||||
* @LastEditors: viletyy
|
||||
* @LastEditTime: 2021-06-11 16:28:51
|
||||
* @LastEditTime: 2021-09-09 16:24:28
|
||||
* @FilePath: /forgeplus/app/docs/slate/source/includes/_users.md
|
||||
-->
|
||||
# Users
|
||||
|
@ -47,6 +47,254 @@ await octokit.request('GET /api/users/me.json')
|
|||
Success Data.
|
||||
</aside>
|
||||
|
||||
## 用户消息列表
|
||||
获取用户消息列表
|
||||
|
||||
> 示例:
|
||||
|
||||
```shell
|
||||
curl -X GET http://localhost:3000/api/users/:login/messages.json
|
||||
```
|
||||
|
||||
```javascript
|
||||
await octokit.request('GET /api/users/:login/messages.json')
|
||||
```
|
||||
|
||||
### HTTP 请求
|
||||
`GET api/users/yystopf/messages.json`
|
||||
|
||||
### 请求字段说明:
|
||||
参数 | 类型 | 字段说明
|
||||
--------- | ----------- | -----------
|
||||
|type | string | 消息类型,不传为所有消息,notification为系统消息,atme为@我消息|
|
||||
|status | integer | 是否已读,不传为所有消息,0为未读,1为已读 |
|
||||
|limit | integer | 每页个数 |
|
||||
|page | integer | 页码 |
|
||||
|
||||
### 返回字段说明:
|
||||
参数 | 类型 | 字段说明
|
||||
--------- | ----------- | -----------
|
||||
|total_count | integer | 消息总数 |
|
||||
|type | string | 消息类型 |
|
||||
|unread_notification | integer | 未读系统通知数量 |
|
||||
|unread_atme | integer | 未读@我数量 |
|
||||
|messages.id | integer | 消息id |
|
||||
|messages.status | integer | 消息是否已读,0为未读,1为已读 |
|
||||
|messages.content | string | 消息内容 |
|
||||
|messages.notification_url | string | 消息跳转地址 |
|
||||
|messages.source | string | 消息来源 |
|
||||
|messages.type | string | 消息类型,notification为系统消息,atme为@我消息|
|
||||
|sender | object | 消息发送者 |
|
||||
|
||||
#### 消息来源source字段说明
|
||||
类型|说明
|
||||
--------- | -----------
|
||||
|IssueAssigned | 有新指派给我的易修 |
|
||||
|IssueAssignerExpire | 我负责的易修截止日期到达最后一天 |
|
||||
|IssueAtme | 在易修中@我 |
|
||||
|IssueChanged | 我创建或负责的易修状态变更 |
|
||||
|IssueCreatorExpire | 我创建的易修截止日期到达最后一天 |
|
||||
|IssueDeleted | 我创建或负责的易修删除 |
|
||||
|IssueJournal | 我创建或负责的易修有新的评论 |
|
||||
|LoginIpTip | 登录异常提示 |
|
||||
|OrganizationJoined | 账号被拉入组织 |
|
||||
|OrganizationLeft | 账号被移出组织 |
|
||||
|OrganizationRole | 账号组织权限变更 |
|
||||
|ProjectDelete | 我关注的仓库被删除 |
|
||||
|ProjectFollowed | 我管理的仓库被关注 |
|
||||
|ProjectForked | 我管理的仓库被复刻 |
|
||||
|ProjectIssue | 我管理/关注的仓库有新的易修 |
|
||||
|ProjectJoined | 账号被拉入项目 |
|
||||
|ProjectLeft | 账号被移出项目 |
|
||||
|ProjectMemberJoined | 我管理的仓库有成员加入 |
|
||||
|ProjectMemberLeft | 我管理的仓库有成员移出 |
|
||||
|ProjectMilestone | 我管理的仓库有新的里程碑 |
|
||||
|ProjectPraised | 我管理的仓库被点赞 |
|
||||
|ProjectPullRequest | 我管理/关注的仓库有新的合并请求 |
|
||||
|ProjectRole | 账号仓库权限变更 |
|
||||
|ProjectSettingChanged | 我管理的仓库项目设置被更改 |
|
||||
|ProjectTransfer | 我关注的仓库被转移 |
|
||||
|ProjectVersion | 我关注的仓库有新的发行版 |
|
||||
|PullRequestAssigned | 有新指派给我的合并请求 |
|
||||
|PullReuqestAtme | 在合并请求中@我 |
|
||||
|PullRequestChanged | 我创建或负责的合并请求状态变更 |
|
||||
|PullRequestJournal | 我创建或负责的合并请求有新的评论 |
|
||||
|
||||
|
||||
> 返回的JSON示例:
|
||||
|
||||
```json
|
||||
{
|
||||
"total_count": 5,
|
||||
"type": "",
|
||||
"unread_notification": 3,
|
||||
"unread_atme": 2,
|
||||
"messages": [
|
||||
{
|
||||
"id": 1,
|
||||
"status": 1,
|
||||
"content": "Atme Message Content 1",
|
||||
"notification_url": "http://www.baidu.com",
|
||||
"source": "PullRequestAtme",
|
||||
"type": "atme",
|
||||
"sender": {
|
||||
"id": 5,
|
||||
"type": "User",
|
||||
"name": "testforge2",
|
||||
"login": "testforge2",
|
||||
"image_url": "system/lets/letter_avatars/2/T/236_177_85/120.png"
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"status": 0,
|
||||
"content": "Atme Message Content 2",
|
||||
"notification_url": "http://www.baidu.com",
|
||||
"source": "IssueAtme",
|
||||
"type": "atme",
|
||||
"sender": {
|
||||
"id": 4,
|
||||
"type": "User",
|
||||
"name": "testforge1",
|
||||
"login": "testforge1",
|
||||
"image_url": "system/lets/letter_avatars/2/T/19_237_174/120.png"
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": 3,
|
||||
"status": 1,
|
||||
"content": "Notification Message Content 1",
|
||||
"notification_url": "http://www.baidu.com",
|
||||
"source": "IssueDelete",
|
||||
"type": "notification"
|
||||
},
|
||||
{
|
||||
"id": 4,
|
||||
"status": 0,
|
||||
"content": "Notification Message Content 2",
|
||||
"notification_url": "http://www.baidu.com",
|
||||
"source": "IssueChanged",
|
||||
"type": "notification"
|
||||
},
|
||||
{
|
||||
"id": 5,
|
||||
"status": 0,
|
||||
"content": "Notification Message Content 3",
|
||||
"notification_url": "http://www.baidu.com",
|
||||
"source": "ProjectJoined",
|
||||
"type": "notification"
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
<aside class="success">
|
||||
Success Data.
|
||||
</aside>
|
||||
|
||||
## 发送消息
|
||||
发送消息
|
||||
|
||||
> 示例:
|
||||
|
||||
```shell
|
||||
curl -X POST http://localhost:3000/api/users/:login/messages.json
|
||||
```
|
||||
|
||||
```javascript
|
||||
await octokit.request('POST /api/users/:login/messages.json')
|
||||
```
|
||||
|
||||
### HTTP 请求
|
||||
`POST api/users/yystopf/messages.json`
|
||||
|
||||
### 请求字段说明:
|
||||
参数 | 类型 | 字段说明
|
||||
--------- | ----------- | -----------
|
||||
|type | string | 消息类型 |
|
||||
|recervers_login | array | 需要发送消息的用户名数组|
|
||||
|content | string | 消息内容 |
|
||||
|
||||
> 返回的JSON示例:
|
||||
|
||||
```json
|
||||
{
|
||||
"status": 0,
|
||||
"message": "success"
|
||||
}
|
||||
```
|
||||
<aside class="success">
|
||||
Success Data.
|
||||
</aside>
|
||||
|
||||
## 阅读消息
|
||||
阅读消息
|
||||
|
||||
> 示例:
|
||||
|
||||
```shell
|
||||
curl -X POST http://localhost:3000/api/users/:login/messages/read.json
|
||||
```
|
||||
|
||||
```javascript
|
||||
await octokit.request('POST /api/users/:login/messages/read.json')
|
||||
```
|
||||
|
||||
### HTTP 请求
|
||||
`POST api/users/yystopf/messages/read.json`
|
||||
|
||||
### 请求字段说明:
|
||||
参数 | 类型 | 字段说明
|
||||
--------- | ----------- | -----------
|
||||
|type | string | 消息类型,不传为所有消息,notification为系统消息,atme为@我消息|
|
||||
|ids | array | 消息id数组,包含-1则把所有未读消息标记为已读|
|
||||
|
||||
> 返回的JSON示例:
|
||||
|
||||
```json
|
||||
{
|
||||
"status": 0,
|
||||
"message": "success"
|
||||
}
|
||||
```
|
||||
<aside class="success">
|
||||
Success Data.
|
||||
</aside>
|
||||
|
||||
## 删除消息
|
||||
删除消息
|
||||
|
||||
> 示例:
|
||||
|
||||
```shell
|
||||
curl -X DELETE http://localhost:3000/api/users/:login/messages.json
|
||||
```
|
||||
|
||||
```javascript
|
||||
await octokit.request('DELETE /api/users/:login/messages.json')
|
||||
```
|
||||
|
||||
### HTTP 请求
|
||||
`DELETE api/users/yystopf/messages.json`
|
||||
|
||||
### 请求字段说明:
|
||||
参数 | 类型 | 字段说明
|
||||
--------- | ----------- | -----------
|
||||
|type | string | 消息类型,atme为@我消息|
|
||||
|ids | array | 消息id数组,包含-1则把所有消息删除|
|
||||
|
||||
> 返回的JSON示例:
|
||||
|
||||
```json
|
||||
{
|
||||
"status": 0,
|
||||
"message": "success"
|
||||
}
|
||||
```
|
||||
<aside class="success">
|
||||
Success Data.
|
||||
</aside>
|
||||
|
||||
|
||||
## 更改用户信息
|
||||
更改用户信息
|
||||
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
module Notice
|
||||
class << self
|
||||
def notice_config
|
||||
notice_config = {}
|
||||
|
||||
begin
|
||||
config = Rails.application.config_for(:configuration).symbolize_keys!
|
||||
notice_config = config[:notice].symbolize_keys!
|
||||
raise 'notice config missing' if notice_config.blank?
|
||||
rescue => exception
|
||||
raise ex if Rails.env.production?
|
||||
|
||||
puts %Q{\033[33m [warning] gitea config or configuration.yml missing,
|
||||
please add it or execute 'cp config/configuration.yml.example config/configuration.yml' \033[0m}
|
||||
notice_config = {}
|
||||
end
|
||||
|
||||
notice_config
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,14 @@
|
|||
# == Schema Information
|
||||
#
|
||||
# Table name: message_templates
|
||||
#
|
||||
# id :integer not null, primary key
|
||||
# type :string(255)
|
||||
# sys_notice :text(65535)
|
||||
# email :text(65535)
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
#
|
||||
|
||||
class MessageTemplate < ApplicationRecord
|
||||
end
|
|
@ -0,0 +1,15 @@
|
|||
# == Schema Information
|
||||
#
|
||||
# Table name: message_templates
|
||||
#
|
||||
# id :integer not null, primary key
|
||||
# type :string(255)
|
||||
# sys_notice :text(65535)
|
||||
# email :text(65535)
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
#
|
||||
|
||||
# 有新指派给我的易修
|
||||
class MessageTemplate::IssueAssigned < MessageTemplate
|
||||
end
|
|
@ -0,0 +1,15 @@
|
|||
# == Schema Information
|
||||
#
|
||||
# Table name: message_templates
|
||||
#
|
||||
# id :integer not null, primary key
|
||||
# type :string(255)
|
||||
# sys_notice :text(65535)
|
||||
# email :text(65535)
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
#
|
||||
|
||||
# 我负责的易修截止日期到达最后一天
|
||||
class MessageTemplate::IssueAssignerExpire < MessageTemplate
|
||||
end
|
|
@ -0,0 +1,15 @@
|
|||
# == Schema Information
|
||||
#
|
||||
# Table name: message_templates
|
||||
#
|
||||
# id :integer not null, primary key
|
||||
# type :string(255)
|
||||
# sys_notice :text(65535)
|
||||
# email :text(65535)
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
#
|
||||
|
||||
# 在易修中@我
|
||||
class MessageTemplate::IssueAtme < MessageTemplate
|
||||
end
|
|
@ -0,0 +1,15 @@
|
|||
# == Schema Information
|
||||
#
|
||||
# Table name: message_templates
|
||||
#
|
||||
# id :integer not null, primary key
|
||||
# type :string(255)
|
||||
# sys_notice :text(65535)
|
||||
# email :text(65535)
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
#
|
||||
|
||||
# 我创建或负责的易修状态变更
|
||||
class MessageTemplate::IssueChanged < MessageTemplate
|
||||
end
|
|
@ -0,0 +1,15 @@
|
|||
# == Schema Information
|
||||
#
|
||||
# Table name: message_templates
|
||||
#
|
||||
# id :integer not null, primary key
|
||||
# type :string(255)
|
||||
# sys_notice :text(65535)
|
||||
# email :text(65535)
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
#
|
||||
|
||||
# 我创建的易修截止日期到达最后一天
|
||||
class MessageTemplate::IssueCreatorExpire < MessageTemplate
|
||||
end
|
|
@ -0,0 +1,15 @@
|
|||
# == Schema Information
|
||||
#
|
||||
# Table name: message_templates
|
||||
#
|
||||
# id :integer not null, primary key
|
||||
# type :string(255)
|
||||
# sys_notice :text(65535)
|
||||
# email :text(65535)
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
#
|
||||
|
||||
# 我创建或负责的易修删除
|
||||
class MessageTemplate::IssueDeleted < MessageTemplate
|
||||
end
|
|
@ -0,0 +1,15 @@
|
|||
# == Schema Information
|
||||
#
|
||||
# Table name: message_templates
|
||||
#
|
||||
# id :integer not null, primary key
|
||||
# type :string(255)
|
||||
# sys_notice :text(65535)
|
||||
# email :text(65535)
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
#
|
||||
|
||||
# 我创建或负责的易修有新的评论
|
||||
class MessageTemplate::IssueJournal < MessageTemplate
|
||||
end
|
|
@ -0,0 +1,15 @@
|
|||
# == Schema Information
|
||||
#
|
||||
# Table name: message_templates
|
||||
#
|
||||
# id :integer not null, primary key
|
||||
# type :string(255)
|
||||
# sys_notice :text(65535)
|
||||
# email :text(65535)
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
#
|
||||
|
||||
# 登录异常提示
|
||||
class MessageTemplate::LoginIpTip < MessageTemplate
|
||||
end
|
|
@ -0,0 +1,15 @@
|
|||
# == Schema Information
|
||||
#
|
||||
# Table name: message_templates
|
||||
#
|
||||
# id :integer not null, primary key
|
||||
# type :string(255)
|
||||
# sys_notice :text(65535)
|
||||
# email :text(65535)
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
#
|
||||
|
||||
# 账号被拉入组织
|
||||
class MessageTemplate::OrganizationJoined < MessageTemplate
|
||||
end
|
|
@ -0,0 +1,15 @@
|
|||
# == Schema Information
|
||||
#
|
||||
# Table name: message_templates
|
||||
#
|
||||
# id :integer not null, primary key
|
||||
# type :string(255)
|
||||
# sys_notice :text(65535)
|
||||
# email :text(65535)
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
#
|
||||
|
||||
# 账号被移出组织
|
||||
class MessageTemplate::OrganizationLeft < MessageTemplate
|
||||
end
|
|
@ -0,0 +1,15 @@
|
|||
# == Schema Information
|
||||
#
|
||||
# Table name: message_templates
|
||||
#
|
||||
# id :integer not null, primary key
|
||||
# type :string(255)
|
||||
# sys_notice :text(65535)
|
||||
# email :text(65535)
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
#
|
||||
|
||||
# 账号组织权限变更
|
||||
class MessageTemplate::OrganizationRole < MessageTemplate
|
||||
end
|
|
@ -0,0 +1,15 @@
|
|||
# == Schema Information
|
||||
#
|
||||
# Table name: message_templates
|
||||
#
|
||||
# id :integer not null, primary key
|
||||
# type :string(255)
|
||||
# sys_notice :text(65535)
|
||||
# email :text(65535)
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
#
|
||||
|
||||
# 我关注的仓库被删除
|
||||
class MessageTemplate::ProjectDelete < MessageTemplate
|
||||
end
|
|
@ -0,0 +1,15 @@
|
|||
# == Schema Information
|
||||
#
|
||||
# Table name: message_templates
|
||||
#
|
||||
# id :integer not null, primary key
|
||||
# type :string(255)
|
||||
# sys_notice :text(65535)
|
||||
# email :text(65535)
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
#
|
||||
|
||||
# 我管理的仓库被关注
|
||||
class MessageTemplate::ProjectFollowed < MessageTemplate
|
||||
end
|
|
@ -0,0 +1,15 @@
|
|||
# == Schema Information
|
||||
#
|
||||
# Table name: message_templates
|
||||
#
|
||||
# id :integer not null, primary key
|
||||
# type :string(255)
|
||||
# sys_notice :text(65535)
|
||||
# email :text(65535)
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
#
|
||||
|
||||
# 我管理的仓库被复刻
|
||||
class MessageTemplate::ProjectForked < MessageTemplate
|
||||
end
|
|
@ -0,0 +1,15 @@
|
|||
# == Schema Information
|
||||
#
|
||||
# Table name: message_templates
|
||||
#
|
||||
# id :integer not null, primary key
|
||||
# type :string(255)
|
||||
# sys_notice :text(65535)
|
||||
# email :text(65535)
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
#
|
||||
|
||||
# 我管理/关注的仓库有新的易修
|
||||
class MessageTemplate::ProjectIssue < MessageTemplate
|
||||
end
|
|
@ -0,0 +1,15 @@
|
|||
# == Schema Information
|
||||
#
|
||||
# Table name: message_templates
|
||||
#
|
||||
# id :integer not null, primary key
|
||||
# type :string(255)
|
||||
# sys_notice :text(65535)
|
||||
# email :text(65535)
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
#
|
||||
|
||||
# 账号被拉入项目
|
||||
class MessageTemplate::ProjectJoined < MessageTemplate
|
||||
end
|
|
@ -0,0 +1,16 @@
|
|||
# == Schema Information
|
||||
#
|
||||
# Table name: message_templates
|
||||
#
|
||||
# id :integer not null, primary key
|
||||
# type :string(255)
|
||||
# sys_notice :text(65535)
|
||||
# email :text(65535)
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
#
|
||||
|
||||
# 账号被移出项目
|
||||
class MessageTemplate::ProjectLeft < MessageTemplate
|
||||
|
||||
end
|
|
@ -0,0 +1,15 @@
|
|||
# == Schema Information
|
||||
#
|
||||
# Table name: message_templates
|
||||
#
|
||||
# id :integer not null, primary key
|
||||
# type :string(255)
|
||||
# sys_notice :text(65535)
|
||||
# email :text(65535)
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
#
|
||||
|
||||
# 我管理的仓库有成员加入
|
||||
class MessageTemplate::ProjectMemberJoined < MessageTemplate
|
||||
end
|
|
@ -0,0 +1,15 @@
|
|||
# == Schema Information
|
||||
#
|
||||
# Table name: message_templates
|
||||
#
|
||||
# id :integer not null, primary key
|
||||
# type :string(255)
|
||||
# sys_notice :text(65535)
|
||||
# email :text(65535)
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
#
|
||||
|
||||
# 我管理的仓库有成员移出
|
||||
class MessageTemplate::ProjectMemberLeft < MessageTemplate
|
||||
end
|
|
@ -0,0 +1,15 @@
|
|||
# == Schema Information
|
||||
#
|
||||
# Table name: message_templates
|
||||
#
|
||||
# id :integer not null, primary key
|
||||
# type :string(255)
|
||||
# sys_notice :text(65535)
|
||||
# email :text(65535)
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
#
|
||||
|
||||
# 我管理的仓库有新的里程碑
|
||||
class MessageTemplate::ProjectMilestone < MessageTemplate
|
||||
end
|
|
@ -0,0 +1,15 @@
|
|||
# == Schema Information
|
||||
#
|
||||
# Table name: message_templates
|
||||
#
|
||||
# id :integer not null, primary key
|
||||
# type :string(255)
|
||||
# sys_notice :text(65535)
|
||||
# email :text(65535)
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
#
|
||||
|
||||
# 我管理的仓库被点赞
|
||||
class MessageTemplate::ProjectPraised < MessageTemplate
|
||||
end
|
|
@ -0,0 +1,15 @@
|
|||
# == Schema Information
|
||||
#
|
||||
# Table name: message_templates
|
||||
#
|
||||
# id :integer not null, primary key
|
||||
# type :string(255)
|
||||
# sys_notice :text(65535)
|
||||
# email :text(65535)
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
#
|
||||
|
||||
# 我管理/关注的仓库有新的合并请求
|
||||
class MessageTemplate::ProjectPullRequest < MessageTemplate
|
||||
end
|
|
@ -0,0 +1,15 @@
|
|||
# == Schema Information
|
||||
#
|
||||
# Table name: message_templates
|
||||
#
|
||||
# id :integer not null, primary key
|
||||
# type :string(255)
|
||||
# sys_notice :text(65535)
|
||||
# email :text(65535)
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
#
|
||||
|
||||
# 账号仓库权限变更
|
||||
class MessageTemplate::ProjectRole < MessageTemplate
|
||||
end
|
|
@ -0,0 +1,15 @@
|
|||
# == Schema Information
|
||||
#
|
||||
# Table name: message_templates
|
||||
#
|
||||
# id :integer not null, primary key
|
||||
# type :string(255)
|
||||
# sys_notice :text(65535)
|
||||
# email :text(65535)
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
#
|
||||
|
||||
# 我管理的仓库项目设置被更改
|
||||
class MessageTemplate::ProjectSettingChanged < MessageTemplate
|
||||
end
|
|
@ -0,0 +1,15 @@
|
|||
# == Schema Information
|
||||
#
|
||||
# Table name: message_templates
|
||||
#
|
||||
# id :integer not null, primary key
|
||||
# type :string(255)
|
||||
# sys_notice :text(65535)
|
||||
# email :text(65535)
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
#
|
||||
|
||||
# 我关注的仓库被转移
|
||||
class MessageTemplate::ProjectTransfer < MessageTemplate
|
||||
end
|
|
@ -0,0 +1,15 @@
|
|||
# == Schema Information
|
||||
#
|
||||
# Table name: message_templates
|
||||
#
|
||||
# id :integer not null, primary key
|
||||
# type :string(255)
|
||||
# sys_notice :text(65535)
|
||||
# email :text(65535)
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
#
|
||||
|
||||
# 我关注的仓库有新的发行版
|
||||
class MessageTemplate::ProjectVersion < MessageTemplate
|
||||
end
|
|
@ -0,0 +1,15 @@
|
|||
# == Schema Information
|
||||
#
|
||||
# Table name: message_templates
|
||||
#
|
||||
# id :integer not null, primary key
|
||||
# type :string(255)
|
||||
# sys_notice :text(65535)
|
||||
# email :text(65535)
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
#
|
||||
|
||||
# 有新指派给我的合并请求
|
||||
class MessageTemplate::PullRequestAssigned < MessageTemplate
|
||||
end
|
|
@ -0,0 +1,15 @@
|
|||
# == Schema Information
|
||||
#
|
||||
# Table name: message_templates
|
||||
#
|
||||
# id :integer not null, primary key
|
||||
# type :string(255)
|
||||
# sys_notice :text(65535)
|
||||
# email :text(65535)
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
#
|
||||
|
||||
# 在合并请求中@我
|
||||
class MessageTemplate::PullReuqestAtme < MessageTemplate
|
||||
end
|
|
@ -0,0 +1,15 @@
|
|||
# == Schema Information
|
||||
#
|
||||
# Table name: message_templates
|
||||
#
|
||||
# id :integer not null, primary key
|
||||
# type :string(255)
|
||||
# sys_notice :text(65535)
|
||||
# email :text(65535)
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
#
|
||||
|
||||
# 我创建或负责的合并请求状态变更
|
||||
class MessageTemplate::PullRequestChanged < MessageTemplate
|
||||
end
|
|
@ -0,0 +1,15 @@
|
|||
# == Schema Information
|
||||
#
|
||||
# Table name: message_templates
|
||||
#
|
||||
# id :integer not null, primary key
|
||||
# type :string(255)
|
||||
# sys_notice :text(65535)
|
||||
# email :text(65535)
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
#
|
||||
|
||||
# 我创建或负责的合并请求有新的评论
|
||||
class MessageTemplate::PullRequestJournal < MessageTemplate
|
||||
end
|
|
@ -0,0 +1,108 @@
|
|||
class Notice::ClientService < ApplicationService
|
||||
attr_reader :url, :params
|
||||
|
||||
def initialize(options={})
|
||||
@url = options[:url]
|
||||
@params = options[:params]
|
||||
end
|
||||
|
||||
def post(url, params={})
|
||||
puts "[notice][POST] request params: #{params}"
|
||||
conn.post do |req|
|
||||
req.url = full_url(url)
|
||||
req.body = params[:data].to_json
|
||||
end
|
||||
end
|
||||
|
||||
def get(url, params={})
|
||||
puts "[notice][GET] request params: #{params}"
|
||||
conn.get do |req|
|
||||
req.url full_url(url, 'get')
|
||||
params.each_pair do |key, value|
|
||||
req.params["#{key}"] = value
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def delete(url, params={})
|
||||
puts "[notice][DELETE] request params: #{params}"
|
||||
conn.delete do |req|
|
||||
req.url full_url(url)
|
||||
reb.body = params[:data].to_json
|
||||
end
|
||||
end
|
||||
|
||||
def patch(url, params={})
|
||||
puts "[notice][PATCH] request params: #{params}"
|
||||
conn.patch do |req|
|
||||
req.url full_url(url)
|
||||
reb.body = params[:data].to_json
|
||||
end
|
||||
end
|
||||
|
||||
def put(url, params={})
|
||||
puts "[notice][PUT] request params: #{params}"
|
||||
conn.put do |req|
|
||||
req.url full_url(url)
|
||||
reb.body = params[:data].to_json
|
||||
end
|
||||
end
|
||||
|
||||
#private
|
||||
def conn
|
||||
@client ||= begin
|
||||
Faraday.new(url: domain) do |req|
|
||||
req.request :url_encoded
|
||||
req.headers['Content-Type'] = 'application/json'
|
||||
req.adapter Faraday.default_adapter
|
||||
end
|
||||
end
|
||||
|
||||
@client
|
||||
end
|
||||
|
||||
def base_url
|
||||
Notice.notice_config[:base_url]
|
||||
end
|
||||
|
||||
def domain
|
||||
Notice.notice_config[:domain]
|
||||
end
|
||||
|
||||
def platform
|
||||
Notice.notice_config[:platform]
|
||||
end
|
||||
|
||||
def api_url
|
||||
[domain, base_url].join('')
|
||||
end
|
||||
|
||||
def full_url(api_rest, action='post')
|
||||
url = [api_url, api_rest].join('').freeze
|
||||
url = action === 'get' ? url : URI.escape(url)
|
||||
url = URI.escape(url) unless url.ascii_only?
|
||||
puts "[notice] request url: #{url}"
|
||||
return url
|
||||
end
|
||||
|
||||
def log_error(status, body)
|
||||
puts "[notice] status: #{status}"
|
||||
puts "[notice] body: #{body&.force_encoding('UTF-8')}"
|
||||
end
|
||||
|
||||
def render_response(response)
|
||||
status = response.status
|
||||
body = response&.body
|
||||
|
||||
log_error(status, body)
|
||||
|
||||
if status == 200
|
||||
if body["code"] == 1
|
||||
return [body["code"], body["message"], body["data"]]
|
||||
else
|
||||
puts "[notice][ERROR] code: #{body["code"]}"
|
||||
puts "[notice][ERROR] message: #{body["message"]}"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -21,4 +21,5 @@ json.province @user.province
|
|||
json.city @user.city
|
||||
json.custom_department @user.custom_department
|
||||
json.description @user.description
|
||||
json.(@user, :show_email, :show_department, :show_location)
|
||||
json.(@user, :show_email, :show_department, :show_location)
|
||||
json.message_unread_total 5
|
|
@ -0,0 +1,22 @@
|
|||
json.id message["id"]
|
||||
# json.receiver do
|
||||
# json.partial! '/users/user_simple', locals: {user: current_user}
|
||||
# end
|
||||
json.status message["status"]
|
||||
json.content message["content"]
|
||||
json.notification_url message["notification_url"]
|
||||
json.source message["source"]
|
||||
case message["type"]
|
||||
when 1
|
||||
json.type "notification"
|
||||
when 2
|
||||
json.type "atme"
|
||||
json.sender do
|
||||
sender = User.find_by_id(message["sender"])
|
||||
if sender.present?
|
||||
json.partial! '/users/user_simple', locals: {user: sender}
|
||||
else
|
||||
json.nil
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,7 @@
|
|||
json.total_count @data["records_count"]
|
||||
json.type %w(notification atme).include?(params[:type]) ? params[:type] : ""
|
||||
json.unread_notification @data["unread_notification"]
|
||||
json.unread_atme @data["unread_atme"]
|
||||
json.messages @data["records"].each do |message|
|
||||
json.partial! "message", message: message.stringify_keys
|
||||
end
|
|
@ -57,6 +57,9 @@ default: &default
|
|||
domain: 'https://testgit.trustie.net'
|
||||
base_url: '/api/v1'
|
||||
|
||||
notice:
|
||||
domain: ''
|
||||
base_url: ''
|
||||
|
||||
production:
|
||||
<<: *default
|
||||
|
|
|
@ -300,6 +300,13 @@ Rails.application.routes.draw do
|
|||
# resources :recent_contacts, only: [:index]
|
||||
# resource :private_message_details, only: [:show]
|
||||
# resource :unread_message_info, only: [:show]
|
||||
|
||||
# 通知中心
|
||||
resources :messages, only: [:index, :create, :delete] do
|
||||
collection do
|
||||
post :read
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
resources :tidings, only: [:index]
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
class CreateMessageTemplates < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
create_table :message_templates do |t|
|
||||
t.string :type
|
||||
t.text :sys_notice
|
||||
t.text :email
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
end
|
||||
end
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,5 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe MessageTemplate, type: :model do
|
||||
pending "add some examples to (or delete) #{__FILE__}"
|
||||
end
|
Loading…
Reference in New Issue