Compare commits

..

14 Commits

Author SHA1 Message Date
Paul
4474061103 chore: bump to 0.5.3-alpha.10 2021-11-23 08:57:34 +00:00
Paul
788580a64f fix: broken index migration
feat: add new index
2021-11-23 08:57:17 +00:00
Paul
1303dbc844 chore: bump version to 0.5.3-alpha.9 2021-11-20 13:20:21 +00:00
Paul
7981748b7b fix: include associated user ids (system messages)
fixes #3
2021-11-20 13:18:13 +00:00
Paul
53277cb235 feat(push): include URL for each notification 2021-11-20 12:49:57 +00:00
Paul
92c7f023b1 fix(push): use correct query to fetch sessions 2021-11-20 12:49:28 +00:00
Paul
839d7d0d9a feat(db): add indexes to various collections 2021-11-20 12:46:42 +00:00
Paul
ea8784215d feat: add new badges [skip ci] 2021-11-13 19:43:08 +00:00
insertish
084c635e9c ci: Synced local '.github/workflows/triage_pr.yml' with remote 'workflows/triage_pr.yml' 2021-11-11 20:08:22 +00:00
insertish
924398df1d ci: Created local '.github/workflows/triage_pr.yml' from remote 'workflows/triage_pr.yml' 2021-11-11 19:08:47 +00:00
insertish
c204288b76 ci: Synced local '.github/workflows/triage_issue.yml' with remote 'workflows/triage_issue.yml' 2021-11-11 19:01:42 +00:00
Paul Makles
dcee48c69f Merge pull request #118 from revoltchat/bot/update-global-workflow-651726897879937c474b292841037fc969ff31b9 2021-11-11 18:34:39 +00:00
web-flow
c6efe3b190 ci: update global workflows 2021-11-11 18:33:27 +00:00
Paul Makles
13ed849657 feat: get rid of arm64 because problems
todo: bring it back later
2021-11-09 23:59:24 +00:00
12 changed files with 313 additions and 46 deletions

View File

@@ -101,41 +101,3 @@ jobs:
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
publish_arm64:
needs: [test]
runs-on: ubuntu-latest
if: github.event_name != 'pull_request' && startsWith(github.ref, 'refs/tags')
steps:
- name: Checkout
uses: actions/checkout@v2
with:
submodules: "recursive"
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Docker meta
id: meta
uses: docker/metadata-action@v3
with:
images: revoltchat/server, ghcr.io/revoltchat/server
- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Login to Github Container Registry
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and publish
uses: docker/build-push-action@v2
with:
context: .
push: true
platforms: linux/arm64
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

49
.github/workflows/triage_issue.yml vendored Normal file
View File

@@ -0,0 +1,49 @@
name: Add Issue to Board
on:
issues:
types: [opened]
jobs:
track_issue:
runs-on: ubuntu-latest
steps:
- name: Get project data
env:
GITHUB_TOKEN: ${{ secrets.PAT }}
run: |
gh api graphql -f query='
query {
organization(login: "revoltchat"){
projectNext(number: 3) {
id
fields(first:20) {
nodes {
id
name
settings
}
}
}
}
}' > project_data.json
echo 'PROJECT_ID='$(jq '.data.organization.projectNext.id' project_data.json) >> $GITHUB_ENV
echo 'STATUS_FIELD_ID='$(jq '.data.organization.projectNext.fields.nodes[] | select(.name== "Status") | .id' project_data.json) >> $GITHUB_ENV
echo 'TODO_OPTION_ID='$(jq '.data.organization.projectNext.fields.nodes[] | select(.name== "Status") |.settings | fromjson.options[] | select(.name=="Todo") |.id' project_data.json) >> $GITHUB_ENV
- name: Add issue to project
env:
GITHUB_TOKEN: ${{ secrets.PAT }}
ISSUE_ID: ${{ github.event.issue.node_id }}
run: |
item_id="$( gh api graphql -f query='
mutation($project:ID!, $issue:ID!) {
addProjectNextItem(input: {projectId: $project, contentId: $issue}) {
projectNextItem {
id
}
}
}' -f project=$PROJECT_ID -f issue=$ISSUE_ID --jq '.data.addProjectNextItem.projectNextItem.id')"
echo 'ITEM_ID='$item_id >> $GITHUB_ENV

72
.github/workflows/triage_pr.yml vendored Normal file
View File

@@ -0,0 +1,72 @@
name: Add PR to Board
on:
pull_request_target:
types: [opened]
jobs:
track_pr:
runs-on: ubuntu-latest
steps:
- name: Get project data
env:
GITHUB_TOKEN: ${{ secrets.PAT }}
run: |
gh api graphql -f query='
query {
organization(login: "revoltchat"){
projectNext(number: 3) {
id
fields(first:20) {
nodes {
id
name
settings
}
}
}
}
}' > project_data.json
echo 'PROJECT_ID='$(jq '.data.organization.projectNext.id' project_data.json) >> $GITHUB_ENV
echo 'STATUS_FIELD_ID='$(jq '.data.organization.projectNext.fields.nodes[] | select(.name== "Status") | .id' project_data.json) >> $GITHUB_ENV
echo 'INCOMING_OPTION_ID='$(jq '.data.organization.projectNext.fields.nodes[] | select(.name== "Status") |.settings | fromjson.options[] | select(.name=="Incoming PRs") |.id' project_data.json) >> $GITHUB_ENV
- name: Add PR to project
env:
GITHUB_TOKEN: ${{ secrets.PAT }}
PR_ID: ${{ github.event.pull_request.node_id }}
run: |
item_id="$( gh api graphql -f query='
mutation($project:ID!, $pr:ID!) {
addProjectNextItem(input: {projectId: $project, contentId: $pr}) {
projectNextItem {
id
}
}
}' -f project=$PROJECT_ID -f pr=$PR_ID --jq '.data.addProjectNextItem.projectNextItem.id')"
echo 'ITEM_ID='$item_id >> $GITHUB_ENV
- name: Set fields
env:
GITHUB_TOKEN: ${{ secrets.PAT }}
run: |
gh api graphql -f query='
mutation (
$project: ID!
$item: ID!
$status_field: ID!
$status_value: String!
) {
set_status: updateProjectNextItemField(input: {
projectId: $project
itemId: $item
fieldId: $status_field
value: $status_value
}) {
projectNextItem {
id
}
}
}' -f project=$PROJECT_ID -f item=$ITEM_ID -f status_field=$STATUS_FIELD_ID -f status_value=${{ env.INCOMING_OPTION_ID }} --silent

View File

@@ -1,3 +1,3 @@
#!/bin/bash
export version=0.5.3-alpha.8
export version=0.5.3-alpha.10
echo "pub const VERSION: &str = \"${version}\";" > src/version.rs

View File

@@ -1,4 +1,4 @@
use crate::util::variables::{USE_JANUARY, PUBLIC_URL};
use crate::util::variables::{USE_JANUARY, PUBLIC_URL, APP_URL};
use crate::{
database::*,
notifications::{events::ClientboundNotification, websocket::is_online},
@@ -10,6 +10,7 @@ use rocket::serde::json::Value;
use serde::{Deserialize, Serialize};
use ulid::Ulid;
use validator::Validate;
use std::collections::HashSet;
use std::time::SystemTime;
#[derive(Serialize, Deserialize, Debug, Clone)]
@@ -21,6 +22,7 @@ pub struct PushNotification {
pub body: String,
pub tag: String,
pub timestamp: u64,
pub url: String,
}
impl PushNotification {
@@ -64,6 +66,7 @@ impl PushNotification {
body,
tag: channel.id().to_string(),
timestamp,
url: format!("{}/channel/{}/{}", *APP_URL, channel.id(), msg.id),
}
}
}
@@ -338,4 +341,23 @@ impl Message {
Ok(())
}
pub fn add_associated_user_ids(&self, ids: &mut HashSet<String>) {
ids.insert(self.author.clone());
if let Content::SystemMessage(sys) = &self.content {
match sys {
SystemMessage::Text { .. } => {},
SystemMessage::UserAdded { id, by } => { ids.insert(id.clone()); ids.insert(by.clone()); },
SystemMessage::UserRemove { id, by } => { ids.insert(id.clone()); ids.insert(by.clone()); },
SystemMessage::UserJoined { id } => { ids.insert(id.clone()); },
SystemMessage::UserLeft { id } => { ids.insert(id.clone()); },
SystemMessage::UserKicked { id } => { ids.insert(id.clone()); },
SystemMessage::UserBanned { id } => { ids.insert(id.clone()); },
SystemMessage::ChannelRenamed { by, .. } => { ids.insert(by.clone()); },
SystemMessage::ChannelDescriptionChanged { by } => { ids.insert(by.clone()); },
SystemMessage::ChannelIconChanged { by } => { ids.insert(by.clone()); }
}
}
}
}

View File

@@ -68,8 +68,12 @@ pub enum Badges {
Translator = 2,
Supporter = 4,
ResponsibleDisclosure = 8,
RevoltTeam = 16,
Founder = 16,
PlatformModeration = 32,
ActiveSupporter = 64,
Paw = 128,
EarlyAdopter = 256,
ReservedRelevantJokeBadge1 = 512
}
impl_op_ex_commutative!(+ |a: &i32, b: &Badges| -> i32 { *a | *b as i32 });

View File

@@ -102,6 +102,19 @@ pub async fn create_database() {
"content": "text"
},
"name": "content"
},
{
"key": {
"channel": 1
},
"name": "channel"
},
{
"key": {
"channel": 1,
"_id": 1
},
"name": "channel_id_compound"
}
]
},
@@ -110,6 +123,56 @@ pub async fn create_database() {
.await
.expect("Failed to create message index.");
get_db()
.run_command(
doc! {
"createIndexes": "channel_unreads",
"indexes": [
{
"key": {
"_id.channel": 1,
"_id.user": 1,
},
"name": "compound_id"
},
{
"key": {
"_id.user": 1,
},
"name": "user_id"
}
]
},
None,
)
.await
.expect("Failed to create channel_unreads index.");
get_db()
.run_command(
doc! {
"createIndexes": "server_members",
"indexes": [
{
"key": {
"_id.server": 1,
"_id.user": 1,
},
"name": "compound_id"
},
{
"key": {
"_id.user": 1,
},
"name": "user_id"
}
]
},
None,
)
.await
.expect("Failed to create server_members index.");
db.collection("migrations")
.insert_one(
doc! {

View File

@@ -11,7 +11,7 @@ struct MigrationInfo {
revision: i32,
}
pub const LATEST_REVISION: i32 = 11;
pub const LATEST_REVISION: i32 = 13;
pub async fn migrate_database() {
let migrations = get_collection("migrations");
@@ -372,6 +372,101 @@ pub async fn run_migrations(revision: i32) -> i32 {
.unwrap();
}
if revision <= 11 {
info!("Running migration [revision 11 / 2021-11-14]: Add indexes to database.");
get_db()
.run_command(
doc! {
"createIndexes": "messages",
"indexes": [
{
"key": {
"channel": 1
},
"name": "channel"
}
]
},
None,
)
.await
.expect("Failed to create message index.");
get_db()
.run_command(
doc! {
"createIndexes": "channel_unreads",
"indexes": [
{
"key": {
"_id.channel": 1,
"_id.user": 1,
},
"name": "compound_id"
},
{
"key": {
"_id.user": 1,
},
"name": "user_id"
}
]
},
None,
)
.await
.expect("Failed to create channel_unreads index.");
get_db()
.run_command(
doc! {
"createIndexes": "server_members",
"indexes": [
{
"key": {
"_id.server": 1,
"_id.user": 1,
},
"name": "compound_id"
},
{
"key": {
"_id.user": 1,
},
"name": "user_id"
}
]
},
None,
)
.await
.expect("Failed to create server_members index.");
}
if revision <= 12 {
info!("Running migration [revision 12 / 2021-11-21]: Add indexes to database.");
get_db()
.run_command(
doc! {
"createIndexes": "messages",
"indexes": [
{
"key": {
"channel": 1,
"_id": 1
},
"name": "channel_id_compound"
}
]
},
None,
)
.await
.expect("Failed to create message index.");
}
// Need to migrate fields on attachments, change `user_id`, `object_id`, etc to `parent`.
// Reminder to update LATEST_REVISION when adding new migrations.

View File

@@ -161,7 +161,7 @@ pub async fn req(user: User, target: Ref, options: Options) -> Result<Value> {
if options.include_users.unwrap_or_else(|| false) {
let mut ids = HashSet::new();
for message in &messages {
ids.insert(message.author.clone());
message.add_associated_user_ids(&mut ids);
}
ids.remove(&user.id);

View File

@@ -137,7 +137,7 @@ pub async fn req(user: User, target: Ref, options: Json<Options>) -> Result<Valu
if options.include_users.unwrap_or_else(|| false) {
let mut ids = HashSet::new();
for message in &messages {
ids.insert(message.author.clone());
message.add_associated_user_ids(&mut ids);
}
ids.remove(&user.id);

View File

@@ -30,7 +30,7 @@ pub async fn run() {
if let Ok(mut cursor) = Session::find(
&get_db(),
doc! {
"_id": {
"user_id": {
"$in": recipients
},
"subscription": {

View File

@@ -1 +1 @@
pub const VERSION: &str = "0.5.3-alpha.8";
pub const VERSION: &str = "0.5.3-alpha.10";