Skip to content

Commit

Permalink
Merge pull request #224 from enpitut2018/feature/push_yell
Browse files Browse the repository at this point in the history
Feature/push yell
  • Loading branch information
Ryoma-Suizu authored Dec 14, 2018
2 parents e61d37d + dca38aa commit 77561fe
Show file tree
Hide file tree
Showing 5 changed files with 148 additions and 132 deletions.
8 changes: 6 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ GEM
addressable (2.5.2)
public_suffix (>= 2.0.2, < 4.0)
arel (8.0.0)
ast (2.4.0)
awesome_nested_set (3.1.4)
activerecord (>= 4.0.0, < 5.3)
bcrypt (3.1.12)
Expand Down Expand Up @@ -113,7 +114,7 @@ GEM
graphiql-rails (1.5.0)
railties
sprockets-rails
graphql (1.7.7)
graphql (1.8.11)
hashie (3.5.7)
hkdf (0.3.0)
http (3.3.0)
Expand Down Expand Up @@ -174,6 +175,8 @@ GEM
omniauth-oauth (~> 1.1)
rack
orm_adapter (0.5.0)
parser (2.5.3.0)
ast (~> 2.4.0)
pg (0.21.0)
pg (0.21.0-x64-mingw32)
polyamorous (1.3.3)
Expand Down Expand Up @@ -351,12 +354,13 @@ DEPENDENCIES
factory_girl_rails (~> 4.2.1)
faker (~> 1.1.2)
graphiql-rails
graphql (= 1.7.7)
graphql (~> 1.8, >= 1.8.11)
jbuilder (~> 2.5)
jquery-rails
launchy (~> 2.3.0)
listen (>= 3.0.5, < 3.2)
omniauth-twitter
parser (~> 2.3, >= 2.3.1.2)
pg (~> 0.18)
puma (~> 3.7)
rack-cors
Expand Down
9 changes: 8 additions & 1 deletion app/graphql/mutations/create_clap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,18 @@ class Mutations::CreateClap < GraphQL::Schema::Mutation

def resolve(task_id:)
task = Task.find(task_id)
task.clap = task.clap + 1
count = task.clap + 1
task.clap = count
if task.save
{ task: task, errors: [] }
else
{ task: task, errors: task.errors.full_messages }
end

client = User.find(task.user_id)
body = {
name: "あなたの頑張りを応援しています! 応援人数:#{count}人"
}
notification(client, body)
end
end
216 changes: 108 additions & 108 deletions db/schema.rb
Original file line number Diff line number Diff line change
@@ -1,108 +1,108 @@
# This file is auto-generated from the current state of the database. Instead
# of editing this file, please use the migrations feature of Active Record to
# incrementally modify your database, and then regenerate this schema definition.
#
# Note that this schema.rb definition is the authoritative source for your
# database schema. If you need to create the application database on another
# system, you should be using db:schema:load, not running all the migrations
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
# you'll amass, the slower it'll run and the greater likelihood for issues).
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20181213203003) do

create_table "audio_tests", force: :cascade do |t|
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end

create_table "contributions", force: :cascade do |t|
t.integer "user_id", null: false
t.integer "task_id", null: false
t.datetime "finished_at"
t.boolean "finality", default: false, null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.boolean "status", default: true, null: false
t.index ["task_id"], name: "index_contributions_on_task_id"
t.index ["user_id"], name: "index_contributions_on_user_id"
end

create_table "groups", force: :cascade do |t|
t.integer "parent_id"
t.string "name", null: false
t.integer "user_id", null: false
t.integer "importance"
t.datetime "deadline"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.boolean "public", default: true, null: false
end

create_table "jwt_blacklists", force: :cascade do |t|
t.string "jti", null: false
t.datetime "exp", null: false
t.index ["jti"], name: "index_jwt_blacklists_on_jti"
end

create_table "oauths", force: :cascade do |t|
t.integer "user_id"
t.string "access_token"
t.string "access_token_secret"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end

create_table "tasks", force: :cascade do |t|
t.string "name", null: false
t.datetime "deadline", null: false
t.integer "importance", null: false
t.text "note"
t.integer "status", default: 1, null: false
t.datetime "start_time"
t.datetime "finish_time"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer "user_id"
t.integer "urgency"
t.integer "priority"
t.integer "group_id", null: false
t.integer "clap", default: 0, null: false
t.index ["deadline"], name: "index_tasks_on_deadline"
end

create_table "users", force: :cascade do |t|
t.string "email", default: "", null: false
t.string "encrypted_password", default: "", null: false
t.string "reset_password_token"
t.datetime "reset_password_sent_at"
t.datetime "remember_created_at"
t.integer "sign_in_count", default: 0, null: false
t.datetime "current_sign_in_at"
t.datetime "last_sign_in_at"
t.string "current_sign_in_ip"
t.string "last_sign_in_ip"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "confirmation_token"
t.datetime "confirmed_at"
t.datetime "confirmation_sent_at"
t.string "unconfirmed_email"
t.string "failed_attempts", default: "0", null: false
t.string "unlock_token"
t.datetime "locked_at"
t.string "provider"
t.string "uid"
t.string "username"
t.string "endpoint"
t.string "key"
t.string "auth"
t.string "encoding"
t.index ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true
t.index ["email"], name: "index_users_on_email", unique: true
t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
t.index ["unlock_token"], name: "index_users_on_unlock_token", unique: true
end

end
# This file is auto-generated from the current state of the database. Instead
# of editing this file, please use the migrations feature of Active Record to
# incrementally modify your database, and then regenerate this schema definition.
#
# Note that this schema.rb definition is the authoritative source for your
# database schema. If you need to create the application database on another
# system, you should be using db:schema:load, not running all the migrations
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
# you'll amass, the slower it'll run and the greater likelihood for issues).
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20181213203003) do

create_table "audio_tests", force: :cascade do |t|
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end

create_table "contributions", force: :cascade do |t|
t.integer "user_id", null: false
t.integer "task_id", null: false
t.datetime "finished_at"
t.boolean "finality", default: false, null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.boolean "status", default: true, null: false
t.index ["task_id"], name: "index_contributions_on_task_id"
t.index ["user_id"], name: "index_contributions_on_user_id"
end

create_table "groups", force: :cascade do |t|
t.integer "parent_id"
t.string "name", null: false
t.integer "user_id", null: false
t.integer "importance"
t.datetime "deadline"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.boolean "public", default: true, null: false
end

create_table "jwt_blacklists", force: :cascade do |t|
t.string "jti", null: false
t.datetime "exp", null: false
t.index ["jti"], name: "index_jwt_blacklists_on_jti"
end

create_table "oauths", force: :cascade do |t|
t.integer "user_id"
t.string "access_token"
t.string "access_token_secret"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end

create_table "tasks", force: :cascade do |t|
t.string "name", null: false
t.datetime "deadline", null: false
t.integer "importance", null: false
t.text "note"
t.integer "status", default: 1, null: false
t.datetime "start_time"
t.datetime "finish_time"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer "user_id"
t.integer "urgency"
t.integer "priority"
t.integer "group_id", null: false
t.integer "clap", default: 0, null: false
t.index ["deadline"], name: "index_tasks_on_deadline"
end

create_table "users", force: :cascade do |t|
t.string "email", default: "", null: false
t.string "encrypted_password", default: "", null: false
t.string "reset_password_token"
t.datetime "reset_password_sent_at"
t.datetime "remember_created_at"
t.integer "sign_in_count", default: 0, null: false
t.datetime "current_sign_in_at"
t.datetime "last_sign_in_at"
t.string "current_sign_in_ip"
t.string "last_sign_in_ip"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "confirmation_token"
t.datetime "confirmed_at"
t.datetime "confirmation_sent_at"
t.string "unconfirmed_email"
t.string "failed_attempts", default: "0", null: false
t.string "unlock_token"
t.datetime "locked_at"
t.string "provider"
t.string "uid"
t.string "username"
t.string "endpoint"
t.string "key"
t.string "auth"
t.string "encoding"
t.index ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true
t.index ["email"], name: "index_users_on_email", unique: true
t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
t.index ["unlock_token"], name: "index_users_on_unlock_token", unique: true
end

end
25 changes: 25 additions & 0 deletions lib/assets/notification.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#####################################################################################
#####################################################################################
#第一引数のclientにはcurrent_user.idとかでユーザーモデルを検索した結果のActiveRecordsを
#第二引数のbodyには{name: "hoge"}みたいな形でjsonっぽく書いた文字列を渡してください
#####################################################################################
#####################################################################################

def notification(client, body)
payload = {
endpoint: client.endpoint, # ブラウザでregistration.pushManager.getSubscription()で取得したsubscriptionのendpoint
p256dh: client.key, # 同じくsubscriptionのp256dh
auth: client.auth, # 同じくsubscriptionのauth
ttl: 86400, # 任意の値
vapid: {
subject: 'https://task-driver.sukiyaki.party', # APPサーバのコンタクト用URIとか('mailto:' もしくは 'https://')
public_key: ENV['VAPID_PUBLIC_KEY'],
private_key: ENV['VAPID_SECRET_KEY']
},
message: {
title: "task",
body: body
}.to_json
}
Webpush.payload_send(payload) #送信
end
22 changes: 1 addition & 21 deletions lib/tasks/push.rake
Original file line number Diff line number Diff line change
@@ -1,23 +1,3 @@
def notification(client, body)
payload = {
endpoint: client.endpoint, # ブラウザでregistration.pushManager.getSubscription()で取得したsubscriptionのendpoint
p256dh: client.key, # 同じくsubscriptionのp256dh
auth: client.auth, # 同じくsubscriptionのauth
ttl: 86400, # 任意の値
vapid: {
subject: 'https://task-driver.sukiyaki.party', # APPサーバのコンタクト用URIとか('mailto:' もしくは 'https://')
public_key: ENV['VAPID_PUBLIC_KEY'],
private_key: ENV['VAPID_SECRET_KEY']
},
message: {
title: "task",
body: body
}.to_json
}
Webpush.payload_send(payload) #送信
end


task :push_notification => :environment do
hour = DateTime.now.hour
#if(!(hour > 1 && hour < 7)) then
Expand All @@ -33,7 +13,7 @@ task :push_notification => :environment do
res = JSON.parse(http.get("/tasks/importance?id=#{client.id}")) #resには配列がはいる
}
body = {
name: res[0].name + "最優先タスクとして残ってるよ!",
name: res[0].name + "が最優先タスクとして残ってるよ!",
id: res[0].id,
target_url: "/tasks/"

Expand Down

0 comments on commit 77561fe

Please sign in to comment.