├── .gitignore
├── Gemfile
├── Gemfile.lock
├── README.md
├── Rakefile
├── app
├── assets
│ ├── config
│ │ └── manifest.js
│ ├── images
│ │ ├── .keep
│ │ ├── discord-background.png
│ │ ├── discord-favicon.png
│ │ ├── discord-logo.png
│ │ ├── discord-small-logo.png
│ │ └── login-background.jpg
│ ├── javascripts
│ │ ├── api
│ │ │ ├── servers.coffee
│ │ │ ├── sessions.coffee
│ │ │ ├── user_servers.coffee
│ │ │ └── users.coffee
│ │ ├── application.js
│ │ ├── cable.js
│ │ ├── channels
│ │ │ ├── .keep
│ │ │ └── chat.coffee
│ │ ├── messages.coffee
│ │ └── static_pages.coffee
│ └── stylesheets
│ │ ├── api
│ │ ├── servers.scss
│ │ ├── sessions.scss
│ │ ├── user_servers.scss
│ │ └── users.scss
│ │ ├── application.css
│ │ ├── channel_index.css
│ │ ├── chat.css
│ │ ├── discord.css
│ │ ├── landing_channel.css
│ │ ├── login.css
│ │ ├── messages.scss
│ │ ├── modal.css
│ │ ├── reset.css
│ │ ├── static_pages.scss
│ │ └── style.css
├── channels
│ ├── application_cable
│ │ ├── channel.rb
│ │ └── connection.rb
│ └── chat_channel.rb
├── controllers
│ ├── api
│ │ ├── messages_controller.rb
│ │ ├── servers_controller.rb
│ │ ├── sessions_controller.rb
│ │ ├── user_servers_controller.rb
│ │ └── users_controller.rb
│ ├── application_controller.rb
│ ├── concerns
│ │ └── .keep
│ └── static_pages_controller.rb
├── helpers
│ ├── api
│ │ ├── servers_helper.rb
│ │ ├── sessions_helper.rb
│ │ ├── user_servers_helper.rb
│ │ └── users_helper.rb
│ ├── application_helper.rb
│ ├── messages_helper.rb
│ └── static_pages_helper.rb
├── jobs
│ └── application_job.rb
├── mailers
│ └── application_mailer.rb
├── models
│ ├── application_record.rb
│ ├── concerns
│ │ └── .keep
│ ├── message.rb
│ ├── server.rb
│ ├── user.rb
│ └── user_server.rb
└── views
│ ├── api
│ ├── messages
│ │ ├── _message.json.jbuilder
│ │ └── index.json.jbuilder
│ ├── servers
│ │ ├── _server.json.jbuilder
│ │ ├── index.json.jbuilder
│ │ └── show.json.jbuilder
│ └── users
│ │ ├── _user.json.jbuilder
│ │ ├── index.json.jbuilder
│ │ └── show.json.jbuilder
│ ├── layouts
│ ├── application.html.erb
│ ├── mailer.html.erb
│ └── mailer.text.erb
│ └── static_pages
│ └── root.html.erb
├── bin
├── bundle
├── rails
├── rake
├── setup
├── spring
├── update
└── yarn
├── config.ru
├── config
├── application.rb
├── boot.rb
├── cable.yml
├── credentials.yml.enc
├── database.yml
├── environment.rb
├── environments
│ ├── development.rb
│ ├── production.rb
│ └── test.rb
├── initializers
│ ├── application_controller_renderer.rb
│ ├── assets.rb
│ ├── backtrace_silencers.rb
│ ├── content_security_policy.rb
│ ├── cookies_serializer.rb
│ ├── filter_parameter_logging.rb
│ ├── inflections.rb
│ ├── mime_types.rb
│ └── wrap_parameters.rb
├── locales
│ └── en.yml
├── puma.rb
├── routes.rb
├── spring.rb
└── storage.yml
├── db
├── migrate
│ ├── 20190430204220_create_users.rb
│ ├── 20190503164923_create_servers.rb
│ ├── 20190503165736_create_user_servers.rb
│ ├── 20190506161859_add_invite_link_to_servers.rb
│ ├── 20190506162112_change_invite_link_in_servers.rb
│ ├── 20190507171852_add_unique_pairs_to_user_server.rb
│ ├── 20190507214035_create_messages.rb
│ ├── 20190507214423_add_sender_to_message.rb
│ ├── 20190508004239_add_custom_timestamp_to_messages.rb
│ ├── 20190509222821_add_channel_id_to_messages.rb
│ ├── 20190509224332_remove_channel_id_from_messages.rb
│ └── 20190509224655_add_channel_id_to_messages_again.rb
├── schema.rb
└── seeds.rb
├── docs
├── gifs
│ ├── landing.gif
│ ├── login_errors.gif
│ └── reguster_errors.gif
└── images
│ ├── expanding-text-field-screenshot.png
│ ├── server-screenshot-blurred.png
│ ├── user-auth-errors-more.png
│ └── user-auth-errors.png
├── frontend
├── actions
│ ├── chat_actions.js
│ ├── modal_actions.js
│ ├── server_actions.js
│ └── session_actions.js
├── components
│ ├── app.jsx
│ ├── cable_chat
│ │ ├── chat_room.jsx
│ │ ├── chat_room_container.jsx
│ │ ├── member_list.jsx
│ │ ├── member_list_container.jsx
│ │ ├── member_list_items.jsx
│ │ ├── message_form.jsx
│ │ └── message_form_container.jsx
│ ├── channel_content
│ │ ├── activity_display.jsx
│ │ ├── channel_index.jsx
│ │ ├── channel_index_container.jsx
│ │ ├── landing_channel.jsx
│ │ ├── landing_channel_container.jsx
│ │ └── user_info_bar.jsx
│ ├── discord_servers
│ │ ├── add_server_container.jsx
│ │ ├── add_server_icon.jsx
│ │ ├── server_index.jsx
│ │ ├── server_index_container.jsx
│ │ └── server_list_item.jsx
│ ├── landing_page
│ │ └── landing_page.jsx
│ ├── modal
│ │ ├── invite_link_modal.jsx
│ │ ├── invite_link_modal_container.jsx
│ │ ├── modal.jsx
│ │ ├── modal_container.jsx
│ │ ├── remove_server_modal.jsx
│ │ ├── remove_server_modal_container.jsx
│ │ ├── server_modal.jsx
│ │ └── server_modal_container.jsx
│ ├── root.jsx
│ └── session_form
│ │ ├── login_form_container.jsx
│ │ ├── session_form.jsx
│ │ └── signup_form_container.jsx
├── index.jsx
├── reducers
│ ├── entities_reducer.js
│ ├── errors_reducer.js
│ ├── messages_reducer.js
│ ├── modal_reducer.js
│ ├── root_reducer.js
│ ├── servers_errors_reducer.js
│ ├── servers_reducer.js
│ ├── session_errors_reducer.js
│ ├── session_reducer.js
│ ├── ui_reducer.js
│ └── users_reducer.js
├── store
│ └── store.js
└── util
│ ├── chat_util.js
│ ├── route_util.jsx
│ ├── server_api_util.js
│ ├── session_api_util.js
│ └── user_util.js
├── lib
├── assets
│ └── .keep
└── tasks
│ └── .keep
├── log
└── .keep
├── package.json
├── public
├── 404.html
├── 422.html
├── 500.html
├── apple-touch-icon-precomposed.png
├── apple-touch-icon.png
├── favicon.ico
└── robots.txt
├── storage
└── .keep
├── test
├── application_system_test_case.rb
├── controllers
│ ├── .keep
│ ├── api
│ │ ├── servers_controller_test.rb
│ │ ├── sessions_controller_test.rb
│ │ ├── user_servers_controller_test.rb
│ │ └── users_controller_test.rb
│ ├── messages_controller_test.rb
│ └── static_pages_controller_test.rb
├── fixtures
│ ├── .keep
│ ├── files
│ │ └── .keep
│ ├── messages.yml
│ ├── servers.yml
│ ├── user_servers.yml
│ └── users.yml
├── helpers
│ └── .keep
├── integration
│ └── .keep
├── mailers
│ └── .keep
├── models
│ ├── .keep
│ ├── message_test.rb
│ ├── server_test.rb
│ ├── user_server_test.rb
│ └── user_test.rb
├── system
│ └── .keep
└── test_helper.rb
├── tmp
└── .keep
├── vendor
└── .keep
└── webpack.config.jsx
/.gitignore:
--------------------------------------------------------------------------------
1 | # See https://help.github.com/articles/ignoring-files for more about ignoring files.
2 | #
3 | # If you find yourself ignoring temporary files generated by your text editor
4 | # or operating system, you probably want to add a global ignore instead:
5 | # git config --global core.excludesfile '~/.gitignore_global'
6 |
7 | # Ignore bundler config.
8 | /.bundle
9 |
10 | # Ignore all logfiles and tempfiles.
11 | /log/*
12 | /tmp/*
13 | !/log/.keep
14 | !/tmp/.keep
15 |
16 | # Ignore uploaded files in development
17 | /storage/*
18 | !/storage/.keep
19 |
20 | /node_modules
21 | /yarn-error.log
22 |
23 | /public/assets
24 | .byebug_history
25 |
26 | # Ignore master key for decrypting credentials and more.
27 | /config/master.key
28 |
29 | # Ignore project webpack and other things
30 | /bundle.js*
31 | bundle.js
32 | /bundle.js.map
33 | /.DS_Store
34 | /npm-debug.log
--------------------------------------------------------------------------------
/Gemfile:
--------------------------------------------------------------------------------
1 | source 'https://rubygems.org'
2 | git_source(:github) { |repo| "https://github.com/#{repo}.git" }
3 |
4 | ruby '2.5.1'
5 |
6 | # Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
7 | gem 'rails', '~> 5.2.3'
8 | # Use postgresql as the database for Active Record
9 | gem 'pg', '>= 0.18', '< 2.0'
10 | # Use Puma as the app server
11 | gem 'puma', '~> 3.11'
12 | # Use SCSS for stylesheets
13 | gem 'sass-rails', '~> 5.0'
14 | # Use Uglifier as compressor for JavaScript assets
15 | gem 'uglifier', '>= 1.3.0'
16 | # See https://github.com/rails/execjs#readme for more supported runtimes
17 | # gem 'mini_racer', platforms: :ruby
18 |
19 | # Use CoffeeScript for .coffee assets and views
20 | gem 'coffee-rails', '~> 4.2'
21 | # Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
22 | gem 'jbuilder', '~> 2.5'
23 | # Use Redis adapter to run Action Cable in production
24 | gem 'redis', '~> 4.0'
25 | # Use ActiveModel has_secure_password
26 | gem 'bcrypt', '~> 3.1.7'
27 | gem 'jquery-rails'
28 |
29 | # Use ActiveStorage variant
30 | # gem 'mini_magick', '~> 4.8'
31 |
32 | # Use Capistrano for deployment
33 | # gem 'capistrano-rails', group: :development
34 |
35 | # Reduces boot times through caching; required in config/boot.rb
36 | gem 'bootsnap', '>= 1.1.0', require: false
37 |
38 | group :development, :test do
39 | # Call 'byebug' anywhere in the code to stop execution and get a debugger console
40 | gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
41 | end
42 |
43 | group :development do
44 | # Access an interactive console on exception pages or by calling 'console' anywhere in the code.
45 | gem 'web-console', '>= 3.3.0'
46 | gem 'listen', '>= 3.0.5', '< 3.2'
47 | # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
48 | gem 'spring'
49 | gem 'spring-watcher-listen', '~> 2.0.0'
50 |
51 | gem 'better_errors'
52 | gem 'binding_of_caller'
53 | gem 'pry-rails'
54 | gem 'annotate'
55 | end
56 |
57 | group :test do
58 | # Adds support for Capybara system testing and selenium driver
59 | gem 'capybara', '>= 2.15'
60 | gem 'selenium-webdriver'
61 | # Easy installation and use of chromedriver to run system tests with Chrome
62 | gem 'chromedriver-helper'
63 | end
64 |
65 | # Windows does not include zoneinfo files, so bundle the tzinfo-data gem
66 | gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
67 |
--------------------------------------------------------------------------------
/Gemfile.lock:
--------------------------------------------------------------------------------
1 | GEM
2 | remote: https://rubygems.org/
3 | specs:
4 | actioncable (5.2.3)
5 | actionpack (= 5.2.3)
6 | nio4r (~> 2.0)
7 | websocket-driver (>= 0.6.1)
8 | actionmailer (5.2.3)
9 | actionpack (= 5.2.3)
10 | actionview (= 5.2.3)
11 | activejob (= 5.2.3)
12 | mail (~> 2.5, >= 2.5.4)
13 | rails-dom-testing (~> 2.0)
14 | actionpack (5.2.3)
15 | actionview (= 5.2.3)
16 | activesupport (= 5.2.3)
17 | rack (~> 2.0)
18 | rack-test (>= 0.6.3)
19 | rails-dom-testing (~> 2.0)
20 | rails-html-sanitizer (~> 1.0, >= 1.0.2)
21 | actionview (5.2.3)
22 | activesupport (= 5.2.3)
23 | builder (~> 3.1)
24 | erubi (~> 1.4)
25 | rails-dom-testing (~> 2.0)
26 | rails-html-sanitizer (~> 1.0, >= 1.0.3)
27 | activejob (5.2.3)
28 | activesupport (= 5.2.3)
29 | globalid (>= 0.3.6)
30 | activemodel (5.2.3)
31 | activesupport (= 5.2.3)
32 | activerecord (5.2.3)
33 | activemodel (= 5.2.3)
34 | activesupport (= 5.2.3)
35 | arel (>= 9.0)
36 | activestorage (5.2.3)
37 | actionpack (= 5.2.3)
38 | activerecord (= 5.2.3)
39 | marcel (~> 0.3.1)
40 | activesupport (5.2.3)
41 | concurrent-ruby (~> 1.0, >= 1.0.2)
42 | i18n (>= 0.7, < 2)
43 | minitest (~> 5.1)
44 | tzinfo (~> 1.1)
45 | addressable (2.6.0)
46 | public_suffix (>= 2.0.2, < 4.0)
47 | annotate (2.7.5)
48 | activerecord (>= 3.2, < 7.0)
49 | rake (>= 10.4, < 13.0)
50 | archive-zip (0.12.0)
51 | io-like (~> 0.3.0)
52 | arel (9.0.0)
53 | bcrypt (3.1.12)
54 | better_errors (2.5.1)
55 | coderay (>= 1.0.0)
56 | erubi (>= 1.0.0)
57 | rack (>= 0.9.0)
58 | bindex (0.7.0)
59 | binding_of_caller (0.8.0)
60 | debug_inspector (>= 0.0.1)
61 | bootsnap (1.4.4)
62 | msgpack (~> 1.0)
63 | builder (3.2.3)
64 | byebug (11.0.1)
65 | capybara (3.18.0)
66 | addressable
67 | mini_mime (>= 0.1.3)
68 | nokogiri (~> 1.8)
69 | rack (>= 1.6.0)
70 | rack-test (>= 0.6.3)
71 | regexp_parser (~> 1.2)
72 | xpath (~> 3.2)
73 | childprocess (1.0.1)
74 | rake (< 13.0)
75 | chromedriver-helper (2.1.1)
76 | archive-zip (~> 0.10)
77 | nokogiri (~> 1.8)
78 | coderay (1.1.2)
79 | coffee-rails (4.2.2)
80 | coffee-script (>= 2.2.0)
81 | railties (>= 4.0.0)
82 | coffee-script (2.4.1)
83 | coffee-script-source
84 | execjs
85 | coffee-script-source (1.12.2)
86 | concurrent-ruby (1.1.5)
87 | crass (1.0.4)
88 | debug_inspector (0.0.3)
89 | erubi (1.8.0)
90 | execjs (2.7.0)
91 | ffi (1.10.0)
92 | globalid (0.4.2)
93 | activesupport (>= 4.2.0)
94 | i18n (1.6.0)
95 | concurrent-ruby (~> 1.0)
96 | io-like (0.3.0)
97 | jbuilder (2.8.0)
98 | activesupport (>= 4.2.0)
99 | multi_json (>= 1.2)
100 | jquery-rails (4.3.3)
101 | rails-dom-testing (>= 1, < 3)
102 | railties (>= 4.2.0)
103 | thor (>= 0.14, < 2.0)
104 | listen (3.1.5)
105 | rb-fsevent (~> 0.9, >= 0.9.4)
106 | rb-inotify (~> 0.9, >= 0.9.7)
107 | ruby_dep (~> 1.2)
108 | loofah (2.2.3)
109 | crass (~> 1.0.2)
110 | nokogiri (>= 1.5.9)
111 | mail (2.7.1)
112 | mini_mime (>= 0.1.1)
113 | marcel (0.3.3)
114 | mimemagic (~> 0.3.2)
115 | method_source (0.9.2)
116 | mimemagic (0.3.3)
117 | mini_mime (1.0.1)
118 | mini_portile2 (2.4.0)
119 | minitest (5.11.3)
120 | msgpack (1.2.10)
121 | multi_json (1.13.1)
122 | nio4r (2.3.1)
123 | nokogiri (1.10.3)
124 | mini_portile2 (~> 2.4.0)
125 | pg (1.1.4)
126 | pry (0.12.2)
127 | coderay (~> 1.1.0)
128 | method_source (~> 0.9.0)
129 | pry-rails (0.3.9)
130 | pry (>= 0.10.4)
131 | public_suffix (3.0.3)
132 | puma (3.12.1)
133 | rack (2.0.7)
134 | rack-test (1.1.0)
135 | rack (>= 1.0, < 3)
136 | rails (5.2.3)
137 | actioncable (= 5.2.3)
138 | actionmailer (= 5.2.3)
139 | actionpack (= 5.2.3)
140 | actionview (= 5.2.3)
141 | activejob (= 5.2.3)
142 | activemodel (= 5.2.3)
143 | activerecord (= 5.2.3)
144 | activestorage (= 5.2.3)
145 | activesupport (= 5.2.3)
146 | bundler (>= 1.3.0)
147 | railties (= 5.2.3)
148 | sprockets-rails (>= 2.0.0)
149 | rails-dom-testing (2.0.3)
150 | activesupport (>= 4.2.0)
151 | nokogiri (>= 1.6)
152 | rails-html-sanitizer (1.0.4)
153 | loofah (~> 2.2, >= 2.2.2)
154 | railties (5.2.3)
155 | actionpack (= 5.2.3)
156 | activesupport (= 5.2.3)
157 | method_source
158 | rake (>= 0.8.7)
159 | thor (>= 0.19.0, < 2.0)
160 | rake (12.3.2)
161 | rb-fsevent (0.10.3)
162 | rb-inotify (0.10.0)
163 | ffi (~> 1.0)
164 | redis (4.1.1)
165 | regexp_parser (1.4.0)
166 | ruby_dep (1.5.0)
167 | rubyzip (1.2.2)
168 | sass (3.7.4)
169 | sass-listen (~> 4.0.0)
170 | sass-listen (4.0.0)
171 | rb-fsevent (~> 0.9, >= 0.9.4)
172 | rb-inotify (~> 0.9, >= 0.9.7)
173 | sass-rails (5.0.7)
174 | railties (>= 4.0.0, < 6)
175 | sass (~> 3.1)
176 | sprockets (>= 2.8, < 4.0)
177 | sprockets-rails (>= 2.0, < 4.0)
178 | tilt (>= 1.1, < 3)
179 | selenium-webdriver (3.142.0)
180 | childprocess (>= 0.5, < 2.0)
181 | rubyzip (~> 1.2, >= 1.2.2)
182 | spring (2.0.2)
183 | activesupport (>= 4.2)
184 | spring-watcher-listen (2.0.1)
185 | listen (>= 2.7, < 4.0)
186 | spring (>= 1.2, < 3.0)
187 | sprockets (3.7.2)
188 | concurrent-ruby (~> 1.0)
189 | rack (> 1, < 3)
190 | sprockets-rails (3.2.1)
191 | actionpack (>= 4.0)
192 | activesupport (>= 4.0)
193 | sprockets (>= 3.0.0)
194 | thor (0.20.3)
195 | thread_safe (0.3.6)
196 | tilt (2.0.9)
197 | tzinfo (1.2.5)
198 | thread_safe (~> 0.1)
199 | uglifier (4.1.20)
200 | execjs (>= 0.3.0, < 3)
201 | web-console (3.7.0)
202 | actionview (>= 5.0)
203 | activemodel (>= 5.0)
204 | bindex (>= 0.4.0)
205 | railties (>= 5.0)
206 | websocket-driver (0.7.0)
207 | websocket-extensions (>= 0.1.0)
208 | websocket-extensions (0.1.3)
209 | xpath (3.2.0)
210 | nokogiri (~> 1.8)
211 |
212 | PLATFORMS
213 | ruby
214 |
215 | DEPENDENCIES
216 | annotate
217 | bcrypt (~> 3.1.7)
218 | better_errors
219 | binding_of_caller
220 | bootsnap (>= 1.1.0)
221 | byebug
222 | capybara (>= 2.15)
223 | chromedriver-helper
224 | coffee-rails (~> 4.2)
225 | jbuilder (~> 2.5)
226 | jquery-rails
227 | listen (>= 3.0.5, < 3.2)
228 | pg (>= 0.18, < 2.0)
229 | pry-rails
230 | puma (~> 3.11)
231 | rails (~> 5.2.3)
232 | redis (~> 4.0)
233 | sass-rails (~> 5.0)
234 | selenium-webdriver
235 | spring
236 | spring-watcher-listen (~> 2.0.0)
237 | tzinfo-data
238 | uglifier (>= 1.3.0)
239 | web-console (>= 3.3.0)
240 |
241 | RUBY VERSION
242 | ruby 2.5.1p57
243 |
244 | BUNDLED WITH
245 | 2.0.1
246 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Discourse - A Discord clone
2 | [Live Demo!](https://discord-clone.herokuapp.com/#/)
3 |
4 | Discourse is a platform for text chat aimed at gamers, inspired by Discord. Implementing Action Cable to utilize websocket connections, and backed by Rails and postgreSQL, Discourse operates with the popular React.js and Redux libraries on the front end. As of now, features are limited due to the 10 day time-frame, however may be updated in the near future to add additional functionality.
5 |
6 | ## Features
7 | * Standard User Authentication utilizing session tokens and BCrypt encryption
8 | * Users are assigned an avatar with the Discourse logo and a random background color
9 | * Discourse servers can be created, and deleted only by their owner
10 | * Invite 'codes' can be easily copied and sent to friends to join the server
11 | * Each server has a chat room that can only be accessed by those on the server
12 | * Chat is updated whenever someone sends a message, and chat history is automatically loaded
13 |
14 | ## Channel display page
15 | A basic channel layout styled based off the official Discord styling and color palette is show upon navigating to a server. The chat history will show a default message encouraging users to send a message if there is no message history, and a list of users who are in the server is shown on the right. The document title changes according to the current server.
16 | 
17 | The message display is managed by a conditional that checks whether or not any message history exists based on information fetched when the component is mounted, and renders either the default message or the message history.
18 | ```javascript
19 | if (this.state.messages.length === 0) {
20 | messageList =
21 |
22 |
23 |
24 | There seems to be no previous messages... you can call dibs on 'first'!
25 |
26 |
27 |
28 | } else {
29 | ...
30 | }
31 | ```
32 | Each message in the message history is then displayed accordingly, based on the received information from the Action Cable subscription that was created upon component mounting. Each subsequent message will then be posted to the database and broadcasted to the relevant channels with information about the body, sender, and a custom timestamp that utilizes the Moment.js library to render a nicely formatted timestamp, and allow for relative time display if desired (e.g. 2 hours ago, now, etc.).
33 | ```javascript
34 | // In main channel component
35 | received: (data) => {
36 | switch (data.type) {
37 | case 'message':
38 | this.setState({
39 | messages: this.state.messages.concat(
40 | {
41 | body: data.message.body,
42 | sender: data.message.sender,
43 | custom_timestamp: data.message.custom_timestamp
44 | }
45 | )
46 | });
47 | break;
48 | case 'messages':
49 | this.setState({
50 | messages: Object.values(data.messages)
51 | });
52 | break;
53 | }
54 | }
55 |
56 | // In message form component, on submit
57 | let moment = require('moment');
58 | let date = moment().format('MMMM Do YYYY, h:mm:ss a');
59 | App.cable.subscriptions.subscriptions[0].speak({
60 | message: this.state.body,
61 | sender: this.props.currentUser.username,
62 | custom_timestamp: date,
63 | channel_id: this.props.match.params.id
64 | });
65 | ```
66 |
67 | ## Automatically expanding input field
68 | A deceptively difficult feature to implement was the expanding text field that had a maximum height before adding a scroll bar. This feature is used when typing or pasting long messages to accommodate for the length of the message to a certain degree, then adding a scroll bar when it exceeds the maximum height so the user can still continue typing. Submission of this input was also slightly complicated as it was a quality of life feature that pressing "Enter" should submit the field, while "Shift + Enter" should make a new line.
69 |
70 | 
71 |
72 | In order to implement this feature properly, the input had to be converted to a textarea, and the actual logic implemented in both CSS and JS constraints. A simple fix for the "Enter" and "Shift + Enter" keystrokes is implemented with the following handler:
73 |
74 | ```javascript
75 | handleEnter(evt) {
76 | if (evt.which === 13 && !evt.shiftKey) {
77 | evt.preventDefault();
78 | this.callSpeak();
79 | // This handles the broadcasting of a message to the channel
80 | }
81 | }
82 | ```
83 |
84 | To handle the expanding text field, a method had to be written that changes the text area input size based on the content, with a defined minimum and maximum. The minimum size is defined by the (lack of) scroll and CSS, while the maximum is determined by just the CSS constraint. Upon field update, the field is reset to account for potential copy/pasting that can affect the size, and then resized to the appropriate size, with the container and decorative divider increased as well.
85 |
86 | ```javascript
87 | resizeTextarea(e) {
88 | let currentTarget = e.currentTarget;
89 | currentTarget.style.height = "1px";
90 | currentTarget.style.height = (currentTarget.scrollHeight) + "px";
91 | let container = document.getElementsByClassName('message-form-container')[0];
92 | container.style.height = "1px";
93 | container.style.height = (65 + currentTarget.scrollHeight) + "px";
94 | }
95 | ```
96 |
97 | While this handles the expanding of the text field, a separate method is required to reset the text area and container to default heights upon submission.
98 |
99 | ## User Authentication errors
100 | By combining both HTML validations as well as custom backend validations, multiple errors can be rendered to ensure all conditions are properly met before attempting to save a user's information to the database. Errors can appear next to the appropriate field by parsing through the error and determining which one it is associated with.
101 |
102 | 
103 |
104 | An alternative, more efficient method would be saving the errors under respective slices of state and render accordingly, however, due to time constraints and the (relatively) small variety of errors that could be thrown, the approach of parsing through the actual error itself is adopted to save time.
105 |
106 | # Project Design
107 |
108 | Discourse was designed to be a clone of Discord, imitating the simplistic but effective design, implementing features only if necessary and if it enhanced the user experience. With the short time period of two weeks, many features had to be left out in order to complete as many MVPs (minimum viable products) as possible, however due to the learning and implementing of action cable, many crucial features could not be implemented without additional time.
109 |
110 | ## Technologies
111 |
112 | As mentioned prior, Discourse utilizes a React and Redux frontend in order to handle (presentational) components and state through various actions and reducers. The backend is comprised of a postgreSQL database managed by Ruby on Rails, chosen for its' simplicity and RESTful routes. Although not the most popular technologies nowadays, these were chosen as the best fit for a project with a short time period.
113 |
114 | ## Potential features
115 |
116 | Without a time limit, the following features should also have been implemented:
117 | * Channel CRUD within servers
118 | * Separate chatrooms for each channel
119 | * Private mssaging
120 | * Ability to upload user/server avatars
121 | * Pasting invite link direclty to URL for invite
122 | * Checking user subscription to channel (green dot for 'online' users)
123 |
--------------------------------------------------------------------------------
/Rakefile:
--------------------------------------------------------------------------------
1 | # Add your own tasks in files placed in lib/tasks ending in .rake,
2 | # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3 |
4 | require_relative 'config/application'
5 |
6 | Rails.application.load_tasks
7 |
--------------------------------------------------------------------------------
/app/assets/config/manifest.js:
--------------------------------------------------------------------------------
1 | //= link_tree ../images
2 | //= link_directory ../javascripts .js
3 | //= link_directory ../stylesheets .css
4 |
--------------------------------------------------------------------------------
/app/assets/images/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dowinterfor6/discourse/085d2f02fbbd9f6aa4516b3bd29849ef4c3f305a/app/assets/images/.keep
--------------------------------------------------------------------------------
/app/assets/images/discord-background.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dowinterfor6/discourse/085d2f02fbbd9f6aa4516b3bd29849ef4c3f305a/app/assets/images/discord-background.png
--------------------------------------------------------------------------------
/app/assets/images/discord-favicon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dowinterfor6/discourse/085d2f02fbbd9f6aa4516b3bd29849ef4c3f305a/app/assets/images/discord-favicon.png
--------------------------------------------------------------------------------
/app/assets/images/discord-logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dowinterfor6/discourse/085d2f02fbbd9f6aa4516b3bd29849ef4c3f305a/app/assets/images/discord-logo.png
--------------------------------------------------------------------------------
/app/assets/images/discord-small-logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dowinterfor6/discourse/085d2f02fbbd9f6aa4516b3bd29849ef4c3f305a/app/assets/images/discord-small-logo.png
--------------------------------------------------------------------------------
/app/assets/images/login-background.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dowinterfor6/discourse/085d2f02fbbd9f6aa4516b3bd29849ef4c3f305a/app/assets/images/login-background.jpg
--------------------------------------------------------------------------------
/app/assets/javascripts/api/servers.coffee:
--------------------------------------------------------------------------------
1 | # Place all the behaviors and hooks related to the matching controller here.
2 | # All this logic will automatically be available in application.js.
3 | # You can use CoffeeScript in this file: http://coffeescript.org/
4 |
--------------------------------------------------------------------------------
/app/assets/javascripts/api/sessions.coffee:
--------------------------------------------------------------------------------
1 | # Place all the behaviors and hooks related to the matching controller here.
2 | # All this logic will automatically be available in application.js.
3 | # You can use CoffeeScript in this file: http://coffeescript.org/
4 |
--------------------------------------------------------------------------------
/app/assets/javascripts/api/user_servers.coffee:
--------------------------------------------------------------------------------
1 | # Place all the behaviors and hooks related to the matching controller here.
2 | # All this logic will automatically be available in application.js.
3 | # You can use CoffeeScript in this file: http://coffeescript.org/
4 |
--------------------------------------------------------------------------------
/app/assets/javascripts/api/users.coffee:
--------------------------------------------------------------------------------
1 | # Place all the behaviors and hooks related to the matching controller here.
2 | # All this logic will automatically be available in application.js.
3 | # You can use CoffeeScript in this file: http://coffeescript.org/
4 |
--------------------------------------------------------------------------------
/app/assets/javascripts/application.js:
--------------------------------------------------------------------------------
1 | // This is a manifest file that'll be compiled into application.js, which will include all the files
2 | // listed below.
3 | //
4 | // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, or any plugin's
5 | // vendor/assets/javascripts directory can be referenced here using a relative path.
6 | //
7 | // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8 | // compiled file. JavaScript code in this file should be added after the last require_* statement.
9 | //
10 | // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
11 | // about supported directives.
12 | //
13 | //= require rails-ujs
14 | //= require activestorage
15 | //= require_tree .
16 | //= require jquery
17 | //= require jquery_ujs
--------------------------------------------------------------------------------
/app/assets/javascripts/cable.js:
--------------------------------------------------------------------------------
1 | // Action Cable provides the framework to deal with WebSockets in Rails.
2 | // You can generate new channels where WebSocket features live using the `rails generate channel` command.
3 | //
4 | //= require action_cable
5 | //= require_self
6 | //= require_tree ./channels
7 |
8 | (function() {
9 | this.App || (this.App = {});
10 |
11 | App.cable = ActionCable.createConsumer();
12 |
13 | }).call(this);
14 |
--------------------------------------------------------------------------------
/app/assets/javascripts/channels/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dowinterfor6/discourse/085d2f02fbbd9f6aa4516b3bd29849ef4c3f305a/app/assets/javascripts/channels/.keep
--------------------------------------------------------------------------------
/app/assets/javascripts/channels/chat.coffee:
--------------------------------------------------------------------------------
1 | # App.chat = App.cable.subscriptions.create "ChatChannel",
2 | # connected: ->
3 | # # Called when the subscription is ready for use on the server
4 |
5 | # disconnected: ->
6 | # # Called when the subscription has been terminated by the server
7 |
8 | # received: (data) ->
9 | # # Called when there's incoming data on the websocket for this channel
10 |
--------------------------------------------------------------------------------
/app/assets/javascripts/messages.coffee:
--------------------------------------------------------------------------------
1 | # Place all the behaviors and hooks related to the matching controller here.
2 | # All this logic will automatically be available in application.js.
3 | # You can use CoffeeScript in this file: http://coffeescript.org/
4 |
--------------------------------------------------------------------------------
/app/assets/javascripts/static_pages.coffee:
--------------------------------------------------------------------------------
1 | # Place all the behaviors and hooks related to the matching controller here.
2 | # All this logic will automatically be available in application.js.
3 | # You can use CoffeeScript in this file: http://coffeescript.org/
4 |
--------------------------------------------------------------------------------
/app/assets/stylesheets/api/servers.scss:
--------------------------------------------------------------------------------
1 | // Place all the styles related to the Api::Servers controller here.
2 | // They will automatically be included in application.css.
3 | // You can use Sass (SCSS) here: http://sass-lang.com/
4 |
--------------------------------------------------------------------------------
/app/assets/stylesheets/api/sessions.scss:
--------------------------------------------------------------------------------
1 | // Place all the styles related to the Api::Sessions controller here.
2 | // They will automatically be included in application.css.
3 | // You can use Sass (SCSS) here: http://sass-lang.com/
4 |
--------------------------------------------------------------------------------
/app/assets/stylesheets/api/user_servers.scss:
--------------------------------------------------------------------------------
1 | // Place all the styles related to the Api::UserServers controller here.
2 | // They will automatically be included in application.css.
3 | // You can use Sass (SCSS) here: http://sass-lang.com/
4 |
--------------------------------------------------------------------------------
/app/assets/stylesheets/api/users.scss:
--------------------------------------------------------------------------------
1 | // Place all the styles related to the Api::Users controller here.
2 | // They will automatically be included in application.css.
3 | // You can use Sass (SCSS) here: http://sass-lang.com/
4 |
--------------------------------------------------------------------------------
/app/assets/stylesheets/application.css:
--------------------------------------------------------------------------------
1 | /*
2 | * This is a manifest file that'll be compiled into application.css, which will include all the files
3 | * listed below.
4 | *
5 | * Any CSS and SCSS file within this directory, lib/assets/stylesheets, or any plugin's
6 | * vendor/assets/stylesheets directory can be referenced here using a relative path.
7 | *
8 | * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9 | * compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
10 | * files in this directory. Styles in this file should be added after the last require_* statement.
11 | * It is generally better to create a new file per style scope.
12 | *
13 | *= require_tree .
14 | *= require_self
15 | */
16 |
--------------------------------------------------------------------------------
/app/assets/stylesheets/channel_index.css:
--------------------------------------------------------------------------------
1 | :root {
2 | --tertiary-background-color: #202225;
3 | }
4 |
5 | .channel-title-container {
6 | width: 100%;
7 | padding: 0 10px;
8 | display: flex;
9 | justify-content: space-between;
10 | align-items: center;
11 | }
12 |
13 | .dropdown-container {
14 | height: 100px;
15 | width: 220px;
16 | position: absolute;
17 | top: 55px;
18 | left: 84px;
19 | overflow: hidden;
20 | }
21 |
22 | .channel-title-dropdown {
23 | border-radius: 2px;
24 | z-index: 5;
25 | height: 100%;
26 | width: 100%;
27 | position: absolute;
28 | background: var(--tertiary-background-color);
29 | display: flex;
30 | flex-direction: column;
31 | justify-content: space-evenly;
32 | align-items: flex-start;
33 | cursor: pointer;
34 | }
35 |
36 | .hidden {
37 | display: none;
38 | }
39 |
40 | .channel-title-dropdown li {
41 | width: 100%;
42 | display: grid;
43 | grid-template-columns: 1fr 5fr;
44 | margin: 0 10px;
45 | align-items: center;
46 | font-size: 1.8em;
47 | }
48 |
49 | .channel-title-dropdown li:hover {
50 | color: white;
51 | }
52 |
53 | .dropdown-icon {
54 | cursor: pointer;
55 | }
56 |
57 | .dropdown-icon:hover {
58 | color: white;
59 | }
60 |
61 | @keyframes slideInDown {
62 | from {
63 | -webkit-transform: translate3d(0, -100%, 0);
64 | transform: translate3d(0, -100%, 0);
65 | visibility: visible;
66 | }
67 |
68 | to {
69 | -webkit-transform: translate3d(0, 0, 0);
70 | transform: translate3d(0, 0, 0);
71 | }
72 | }
73 |
74 | .slideInDown {
75 | -webkit-animation-name: slideInDown;
76 | animation-name: slideInDown;
77 | animation-duration: 0.2s;
78 | }
--------------------------------------------------------------------------------
/app/assets/stylesheets/chat.css:
--------------------------------------------------------------------------------
1 | :root {
2 | --app-primary-background-color: #36393f;
3 | --app-secondary-background-color: #2F3136;
4 | --app-tertiary-background-color: #202225;
5 | }
6 |
7 | /* Channel content chat styling */
8 |
9 | .channel-content {
10 | max-height: 100%;
11 | }
12 |
13 | .chatroom-container {
14 | height: 100%;
15 | display: flex;
16 | flex-direction: column;
17 | justify-content: space-between;
18 | }
19 |
20 | .message-list {
21 | overflow: scroll;
22 | overflow-x: hidden;
23 | overflow-y: auto;
24 | max-height: calc(100vh - 150px);
25 | padding: 0 25px;
26 | width: calc(100% - 50px);
27 | }
28 |
29 | .message-list li {
30 | border-bottom: 1px solid #42454a;
31 | padding: 20px 0;
32 | cursor: auto;
33 | line-height: 2em;
34 | max-width: calc(100vw - 360px);
35 | }
36 |
37 | .message-form-container {
38 | display: flex;
39 | justify-content: center;
40 | align-items: center;
41 | min-height: 110px;
42 | max-height: 265px;
43 | }
44 |
45 | /* width */
46 | .message-list::-webkit-scrollbar {
47 | position: relative;
48 | width: 10px;
49 | background: transparent;
50 | }
51 |
52 | /* Track */
53 | .message-list::-webkit-scrollbar-track {
54 | cursor: pointer;
55 | background: transparent;
56 | }
57 |
58 | /* Handle */
59 | .message-list::-webkit-scrollbar-thumb {
60 | background: var(--app-tertiary-background-color);
61 | }
62 |
63 | .message-form-divider {
64 | border-top: 1px solid #42454a;
65 | width: calc(100% - 50px);
66 | height: calc(100% - 1px);
67 | display: flex;
68 | align-items: center;
69 | }
70 |
71 | .message-form {
72 | border-radius: 5px;
73 | background-color: #484b52;
74 | width: 100%;
75 | display: grid;
76 | grid-template-columns: 1fr 100px;
77 | justify-content: space-between;
78 | align-items: center;
79 | }
80 |
81 | .message-form textarea {
82 | background: transparent;
83 | box-sizing: border-box;
84 | padding: 5px;
85 | min-height: 100%;
86 | max-height: 200px;
87 | outline: none;
88 | border: none;
89 | color: #c8c9cb;
90 |
91 | max-width: 100%;
92 | overflow: auto;
93 | overflow-wrap: break-word;
94 | resize: none;
95 | }
96 |
97 | /* width */
98 | .message-form textarea::-webkit-scrollbar {
99 | position: relative;
100 | width: 10px;
101 | background: transparent;
102 | }
103 |
104 | /* Track */
105 | .message-form textarea::-webkit-scrollbar-track {
106 | background: transparent;
107 | }
108 |
109 | /* Handle */
110 | .message-form textarea::-webkit-scrollbar-thumb {
111 | background: var(--app-tertiary-background-color);
112 | }
113 |
114 | .message-form button {
115 | width: 100%;
116 | margin: 0;
117 | }
118 |
119 | .message-form button:hover {
120 | background-color: #5f74bb;
121 | }
122 |
123 | .message-sender {
124 | font-size: 20px;
125 | display: flex;
126 | align-items: baseline;
127 | }
128 |
129 | .message-sender-time {
130 | color: #5d5e61;
131 | margin-left: 10px;
132 | font-size: 12px;
133 | }
134 |
135 | .message-content {
136 | font-size: 18px;
137 | overflow-wrap: break-word;
138 | }
139 |
140 | .message-content pre {
141 | overflow-x: auto;
142 | white-space: pre-wrap;
143 | word-wrap: break-word;
144 | }
145 |
146 | /* MEMBER LIST */
147 |
148 | .member-list-description {
149 | background-color: var(--app-primary-background-color);
150 | box-sizing: border-box;
151 | border-bottom: 1px solid black;
152 | width: 100%;
153 | font-size: 10px;
154 | display: flex;
155 | /* justify-content: space-between; */
156 | justify-content: flex-end;
157 | align-items: center;
158 | padding-right: 20px;
159 | }
160 |
161 | .member-list-description i:hover {
162 | color: white;
163 | cursor: pointer;
164 | }
165 |
166 | .member-list {
167 | background-color: var(--app-secondary-background-color);
168 | box-sizing: border-box;
169 | padding: 10px;
170 | }
171 |
172 | .member-list p {
173 | margin: 0;
174 | margin-bottom: 10px;
175 | }
176 |
177 | .member-listing-show {
178 | display: flex;
179 | margin: 10px 0;
180 | align-items: center;
181 | height: 50px;
182 | }
183 |
184 | .avatar-background {
185 | height: 45px;
186 | width: 45px;
187 | border-radius: 100px;
188 | margin-right: 10px;
189 | }
190 |
191 | .avatar {
192 | background: url('https://cdn.discordapp.com/attachments/560127966688837672/576138524873457674/discourse-logo-transparent.png');
193 | background-position: center;
194 | background-size: contain;
195 | height: 100%;
196 | width: 100%;
197 | display: flex;
198 | justify-content: flex-end;
199 | align-items: flex-end;
200 | }
201 |
202 | .online-status {
203 | height: 10px;
204 | width: 10px;
205 | border-radius: 100px;
206 | border: 1px solid black;
207 | background-color: #43b581;
208 | }
--------------------------------------------------------------------------------
/app/assets/stylesheets/discord.css:
--------------------------------------------------------------------------------
1 | /* Color Palette */
2 | :root {
3 | --app-primary-background-color: #36393f;
4 | --app-secondary-background-color: #2F3136;
5 | --app-tertiary-background-color: #202225;
6 | --font-primary: #FFF;
7 | --primary-hover-color: #7289da;
8 | --secondary-hover-color: #43b581;
9 | /*
10 | --font-secondary: #c8c8c9;
11 | */
12 | }
13 |
14 | /* layout */
15 |
16 | .discord-main {
17 | display: grid;
18 | grid-template-columns: 70px 1fr;
19 | }
20 |
21 | /* NAV BAR */
22 |
23 | /* section {
24 | border: 1px solid red;
25 | } */
26 |
27 | .discord-nav-bar {
28 | display: flex;
29 | flex-direction: column;
30 | justify-content: flex-start;
31 | align-items: center;
32 | height: 100vh;
33 | background-color: var(--app-tertiary-background-color);
34 | }
35 |
36 | /* https://stackoverflow.com/questions/16670931/hide-scroll-bar-but-while-still-being-able-to-scroll */
37 | .discord-nav-bar {
38 | overflow: scroll;
39 | overflow-x: hidden;
40 | }
41 |
42 | .discord-nav-bar::-webkit-scrollbar {
43 | width: 0px; /* Remove scrollbar space */
44 | background: transparent; /* Optional: just make scrollbar invisible */
45 | }
46 |
47 | .discord-nav-bar li,
48 | .home-icon,
49 | .add-server-icon {
50 | display: flex;
51 | justify-content: center;
52 | align-items: center;
53 | color: white;
54 | background-color: #2f3136;
55 | border-radius: 100%;
56 | margin: 7.5px;
57 | height: 50px;
58 | width: 50px;
59 | user-select: none;
60 | cursor: pointer;
61 | }
62 |
63 | .discord-nav-bar li:hover,
64 | .home-icon:hover,
65 | .add-server-icon:hover {
66 | transition-duration: 0.1s;
67 | border-radius: 15px;
68 | background-color: var(--primary-hover-color);
69 | }
70 |
71 | .discord-nav-bar li.nav-in-focus,
72 | .home-icon.nav-in-focus {
73 | border-radius: 15px;
74 | background-color: var(--primary-hover-color);
75 | }
76 |
77 | .home-icon,
78 | .add-server-icon {
79 | min-height: 50px;
80 | min-width: 50px;
81 | }
82 |
83 | .home-icon {
84 | background-color: #2f3136;
85 | margin: 10px auto 7.5px auto;
86 | display: flex;
87 | justify-content: center;
88 | align-items: center;
89 | }
90 |
91 | .home-icon img {
92 | margin: auto;
93 | height: 100%;
94 | }
95 |
96 | .home-icon-divider {
97 | min-height: 1px;
98 | width: 60%;
99 | background-color: var(--app-primary-background-color);
100 | }
101 |
102 | .add-server-icon {
103 | text-align: center;
104 | line-height: initial;
105 | margin: 0 auto 10px auto;
106 | font-size: 3em;
107 | color: var(--secondary-hover-color);
108 | background-color: #2f3136;
109 | }
110 |
111 | .add-server-icon:hover {
112 | color: var(--font-primary);
113 | background-color: var(--secondary-hover-color);
114 | }
115 |
116 | /* CONTENT STYLING */
117 |
118 | .discord-main-content-container {
119 | height: 100vh;
120 | display: grid;
121 | /* grid-template-columns: 240px 1fr;
122 | grid-template-rows: 50px 1fr; */
123 |
124 | grid-template-columns: 240px calc(100vw - 550px) 240px;
125 | grid-template-rows: 50px calc(100vh - 50px);
126 | }
127 |
128 | .discord-main-content-container.activity-channel-content-container {
129 | grid-template-columns: 240px calc(100vw - 310px);
130 | }
131 |
132 | .title {
133 | font-size: 0.75em;
134 | display: flex;
135 | justify-content: center;
136 | align-items: center;
137 | border-bottom: 1px solid black;
138 | background-color: var(--app-secondary-background-color);
139 | }
140 |
141 | .description {
142 | font-size: 0.75em;
143 | display: flex;
144 | justify-content: space-between;
145 | align-items: center;
146 | border-bottom: 1px solid black;
147 | text-transform: lowercase;
148 | background-color: var(--app-primary-background-color);
149 | padding: 0 10px;
150 | }
151 |
152 | .left-description {
153 | display: flex;
154 | justify-content: flex-start;
155 | align-items: center;
156 | user-select: none;
157 | }
158 |
159 | .left-description i {
160 | color: #72767d;
161 | margin-right: 10px;
162 | }
163 |
164 | .right-description {
165 | display: flex;
166 | }
167 |
168 | .right-description i {
169 | margin: auto 10px;
170 | cursor: pointer;
171 | }
172 |
173 | .right-description i:hover {
174 | color: white;
175 | }
176 |
177 | .right-description input {
178 | margin: auto 0 auto 10px;
179 | }
180 |
181 | /* Temporary logout */
182 |
183 | .right-description label {
184 | display: flex;
185 | justify-content: flex-end;
186 | align-items: center;
187 | margin-left: 10px;
188 | }
189 |
190 | .right-description label span {
191 | font-size: 2em;
192 | }
193 |
194 | .right-description label i {
195 | margin-left: 5px;
196 | }
197 |
198 | .right-description label:hover {
199 | color: var(--font-primary);
200 | cursor: pointer;
201 | }
202 |
203 | /* just styling */
204 |
205 | .channel-content {
206 | background-color: var(--app-primary-background-color);
207 | }
208 |
209 | /* CHANNELS */
210 |
211 | .channels {
212 | background-color: var(--app-secondary-background-color);
213 | display: flex;
214 | flex-direction: column;
215 | justify-content: flex-start;
216 | align-items: flex-start;
217 | font-size: 1.1em;
218 | }
219 |
220 | .channels ul {
221 | box-sizing: border-box;
222 | padding: 10px;
223 | width: 100%;
224 | }
225 |
226 | .channel-list li {
227 | display: flex;
228 | align-items: center;
229 | width: 100%;
230 | box-sizing: border-box;
231 | padding: 10px;
232 | border-radius: 5px;
233 | background-color: #40444b;
234 | color: var(--font-primary);
235 | }
236 |
237 | .channel-list li i {
238 | color: #72767d;
239 | margin-right: 7.5px;
240 | }
--------------------------------------------------------------------------------
/app/assets/stylesheets/landing_channel.css:
--------------------------------------------------------------------------------
1 | :root {
2 | --user-bar-color: #2A2C31;
3 | --font-primary: #FFF;
4 | --app-primary-background-color: #36393f;
5 | --app-tertiary-background-color: #202225;
6 | --search-text-color: #72767D;
7 | }
8 |
9 | /* GENERAL STYLING */
10 |
11 | .channels {
12 | display: flex;
13 | height: calc(100vh - 50px);
14 | flex-direction: column;
15 | justify-content: space-between;
16 | }
17 |
18 | .landing.channels-top-info {
19 | padding-top: 0;
20 | }
21 |
22 | .channels-top-info {
23 | box-sizing: border-box;
24 | padding: 10px 15px 0 15px;
25 | width: 100%;
26 | user-select: none;
27 | overflow: hidden;
28 | }
29 |
30 | .channels-top-info:hover {
31 | overflow: scroll;
32 | overflow-x: hidden;
33 | overflow-y: auto;
34 | }
35 |
36 | /* Search Bar */
37 |
38 | .search-container {
39 | margin: auto;
40 | width: 90%;
41 | display: flex;
42 | justify-content: center;
43 | align-items: center;
44 | height: 60%;
45 | }
46 |
47 | .search-container input {
48 | margin: auto;
49 | width: 100%;
50 | height: 100%;
51 | padding: 0 5px 0 5px;
52 | border-radius: 5px;
53 | background-color: var(--app-tertiary-background-color);
54 | color: var(--search-text-color);
55 | outline: none;
56 | border: none;
57 | font-size: 16px;
58 | cursor: auto;
59 | }
60 |
61 | /* width */
62 | .channels-top-info::-webkit-scrollbar {
63 | position: relative;
64 | width: 10px;
65 | background: transparent;
66 | }
67 |
68 | /* Track */
69 | .channels-top-info::-webkit-scrollbar-track {
70 | background: transparent;
71 | }
72 |
73 | /* Handle */
74 | .channels-top-info::-webkit-scrollbar-thumb {
75 | background: var(--app-tertiary-background-color);
76 | }
77 |
78 | /* ICON BAR */
79 |
80 | .header-list {
81 | display: grid;
82 | grid-template-columns: 50px 150px;
83 | justify-content: flex-start;
84 | align-items: center;
85 | grid-gap: 20px;
86 | }
87 |
88 | .landing-title {
89 | box-sizing: border-box;
90 | height: 100%;
91 | width: 100%;
92 | padding: 0 10px;
93 | display: grid;
94 | grid-template-columns: 35px 1fr;
95 | align-items: center;
96 | user-select: none;
97 | }
98 |
99 | .title i {
100 | width: 24.38px;
101 | color: #72767d;
102 | margin-right: 10px;
103 | }
104 |
105 | .selected {
106 | color: white;
107 | }
108 |
109 | /* MESSAGES */
110 |
111 | .message-container p {
112 | margin: 0;
113 | text-transform: uppercase;
114 | }
115 |
116 | /* USER INFO BAR */
117 |
118 | .user-info-bar {
119 | width: 100%;
120 | min-height: 50px;
121 | display: flex;
122 | justify-content: space-between;
123 | align-items: center;
124 | background-color: var(--user-bar-color);
125 | }
126 |
127 | .user-info-bar h5 {
128 | width: 150px;
129 | font-size: 18px;
130 | display: flex;
131 | text-overflow: ellipsis;
132 | overflow: hidden;
133 | margin: 0 10px;
134 | }
135 |
136 | .nav-icon-container {
137 | padding: 0 5px;
138 | width: auto;
139 | display: flex;
140 | justify-content: flex-end;
141 | align-items: center;
142 | }
143 |
144 | .nav-icon-container i {
145 | margin: 0 5px;
146 | }
147 |
148 | .nav-icon-container i:hover {
149 | cursor: pointer;
150 | color: var(--font-primary);
151 | }
152 |
153 | /* ACTIVITY DISPLAY STYLING */
154 |
155 | .activity-display-container {
156 | display: flex;
157 | background-color: var(--app-primary-background-color);
158 | /* height: calc(100vh - 70px); */
159 | width: auto;
160 | box-sizing: border-box;
161 | padding: 20px 0;
162 | }
163 |
164 | .activities-display-list {
165 | display: grid;
166 | grid-template-columns: repeat(auto-fit, 400px);
167 | grid-gap: 10px;
168 | justify-content: center;
169 | width: 100%;
170 | }
171 |
172 | .activities-display-list li {
173 | border: 2px solid black;
174 | border-radius: 5px;
175 | height: 450px;
176 | cursor: auto;
177 | background-color: var(--app-tertiary-background-color);
178 | }
179 |
180 | .activities-display-list {
181 | overflow: scroll;
182 | overflow-x: hidden;
183 | overflow-y: auto;
184 | }
185 |
186 | /* width */
187 | .activities-display-list::-webkit-scrollbar {
188 | width: 10px;
189 | background: transparent;
190 | }
191 |
192 | /* Track */
193 | .activities-display-list::-webkit-scrollbar-track {
194 | background: transparent;
195 | }
196 |
197 | /* Handle */
198 | .activities-display-list::-webkit-scrollbar-thumb {
199 | background: var(--app-tertiary-background-color);
200 | }
201 |
202 | /* Activity display content */
203 |
204 | .activity-video-content {
205 | width: 100%;
206 | height: 50%;
207 | }
208 |
209 | .activity-photo-content {
210 | width: 100%;
211 | height: 50%;
212 | overflow: hidden;
213 |
214 | }
215 |
216 | .activity-content-text {
217 | font-size: 18px;
218 | padding: 10px;
219 | }
220 |
--------------------------------------------------------------------------------
/app/assets/stylesheets/login.css:
--------------------------------------------------------------------------------
1 | /* COLOR PALETTE */
2 |
3 | :root {
4 | --font-primary: #FFF;
5 | --form-text-color: #5d6168;
6 | --form-background-color: #36393f;
7 | --input-border: #212327;
8 | --input-border-hover: black;
9 | --input-background: #303338;
10 | --button-hover: #667bc4;
11 | --link-color: #7289DA;
12 | --error-color: #d84545;
13 | }
14 |
15 | /* LOGIN */
16 |
17 | .login-body {
18 | height: 100vh;
19 | overflow: hidden;
20 | /* TODO: Bandaid fix to temporary scrollbar on animation */
21 | }
22 |
23 | .login-main {
24 | display: flex;
25 | height: 100%;
26 | background-image: url("https://cdn.discordapp.com/attachments/560127966688837672/573313318110887937/login-background.jpg");
27 | background-size: cover;
28 | background-repeat: no-repeat;
29 | background-position: center;
30 | -webkit-user-select: none;
31 | }
32 |
33 | .login-logo {
34 | position: absolute;
35 | top: 30px;
36 | left: 37.5px;
37 | margin: 0;
38 | }
39 |
40 | .login-form {
41 | padding: 45px;
42 | width: 375px;
43 | margin: auto;
44 | display: grid;
45 | grid-template-columns: 100%;
46 | grid-gap: 15px;
47 | background: var(--form-background-color);
48 | border-radius: 5px;
49 | }
50 |
51 | .login-form label {
52 | display: flex;
53 | flex-direction: column;
54 | align-items: flex-start;
55 | text-transform: uppercase;
56 | }
57 |
58 | .login-form label input {
59 | margin-top: 10px;
60 | height: 35px;
61 | width: 363px;
62 | border-radius: 5px;
63 | border: 1px solid var(--input-border);
64 | background: var(--input-background);
65 | color: var(--font-primary);
66 | padding: 0 5px;
67 | }
68 |
69 | .login-form label input:hover {
70 | border-color: var(--input-border-hover);
71 | }
72 |
73 | .login-form label input:focus {
74 | border-color: var(--button-hover);
75 | outline: none;
76 | }
77 |
78 | .login-form h2,
79 | h3,
80 | button {
81 | margin: auto;
82 | }
83 |
84 | .login-form h3, p {
85 | color: var(--form-text-color);
86 | }
87 |
88 | .login-form h2 {
89 | font-size: 1.75em;
90 | }
91 |
92 | .login-form h3 {
93 | font-size: 1.25em;
94 | }
95 |
96 | .login-form button {
97 | width: 100%;
98 | text-transform: capitalize;
99 | }
100 |
101 | .login-form button:hover {
102 | background-color: var(--button-hover);
103 | }
104 |
105 | .login-form p {
106 | margin: 0;
107 | }
108 |
109 | .login-form a, h4 {
110 | color: var(--link-color);
111 | text-decoration: none;
112 | }
113 |
114 | .login-form h4:hover {
115 | cursor: pointer;
116 | }
117 |
118 | .other-form-container {
119 | display: flex;
120 | align-items: flex-end;
121 | }
122 |
123 | /* ERROR-ED OUT FORM STYLING */
124 |
125 | .error-form label {
126 | color: var(--error-color);
127 | }
128 |
129 | .error-form label input {
130 | border-color: var(--error-color);
131 | }
132 |
133 | .error-form label input:hover {
134 | border-color: var(--error-color);
135 | }
136 |
137 | .error-form label input:focus {
138 | border-color: var(--error-color);
139 | }
140 |
141 | .error-form label h5 {
142 | font-style: italic;
143 | text-transform: none;
144 | font-size: 13px;
145 | }
146 |
147 | .error-form label div {
148 | display: flex;
149 | justify-content: flex-start;
150 | align-items: flex-end;
151 | }
152 |
153 | /* Playing around with animations */
154 | /* https://daneden.github.io/animate.css/ */
155 |
156 | @keyframes bounceInDown {
157 | from,
158 | 60%,
159 | 75%,
160 | 90%,
161 | to {
162 | -webkit-animation-timing-function: cubic-bezier(0.215, 0.61, 0.355, 1);
163 | animation-timing-function: cubic-bezier(0.215, 0.61, 0.355, 1);
164 | }
165 |
166 | 0% {
167 | opacity: 0;
168 | -webkit-transform: translate3d(0, -3000px, 0);
169 | transform: translate3d(0, -3000px, 0);
170 | }
171 |
172 | 60% {
173 | opacity: 1;
174 | -webkit-transform: translate3d(0, 25px, 0);
175 | transform: translate3d(0, 25px, 0);
176 | }
177 |
178 | 75% {
179 | -webkit-transform: translate3d(0, -10px, 0);
180 | transform: translate3d(0, -10px, 0);
181 | }
182 |
183 | 90% {
184 | -webkit-transform: translate3d(0, 5px, 0);
185 | transform: translate3d(0, 5px, 0);
186 | }
187 |
188 | to {
189 | -webkit-transform: translate3d(0, 0, 0);
190 | transform: translate3d(0, 0, 0);
191 | }
192 | }
193 |
194 | .bounceInDown {
195 | -webkit-animation-name: bounceInDown;
196 | animation-name: bounceInDown;
197 | animation-duration: 0.2s;
198 | }
--------------------------------------------------------------------------------
/app/assets/stylesheets/messages.scss:
--------------------------------------------------------------------------------
1 | // Place all the styles related to the Messages controller here.
2 | // They will automatically be included in application.css.
3 | // You can use Sass (SCSS) here: http://sass-lang.com/
4 |
--------------------------------------------------------------------------------
/app/assets/stylesheets/reset.css:
--------------------------------------------------------------------------------
1 | /* http://meyerweb.com/eric/tools/css/reset/
2 | v2.0 | 20110126
3 | License: none (public domain)
4 | */
5 |
6 | html, body, div, span, applet, object, iframe,
7 | h1, h2, h3, h4, h5, h6, p, blockquote, pre,
8 | a, abbr, acronym, address, big, cite, code,
9 | del, dfn, em, img, ins, kbd, q, s, samp,
10 | small, strike, strong, sub, sup, tt, var,
11 | b, u, i, center,
12 | dl, dt, dd, ol, ul, li,
13 | fieldset, form, label, legend,
14 | table, caption, tbody, tfoot, thead, tr, th, td,
15 | article, aside, canvas, details, embed,
16 | figure, figcaption, footer, header, hgroup,
17 | menu, nav, output, ruby, section, summary,
18 | time, mark, audio, video {
19 | margin: 0;
20 | padding: 0;
21 | border: 0;
22 | font-size: 100%;
23 | font: inherit;
24 | vertical-align: baseline;
25 | }
26 | /* HTML5 display-role reset for older browsers */
27 | article, aside, details, figcaption, figure,
28 | footer, header, hgroup, menu, nav, section {
29 | display: block;
30 | }
31 | body {
32 | line-height: 1;
33 | }
34 | ol, ul {
35 | list-style: none;
36 | }
37 | blockquote, q {
38 | quotes: none;
39 | }
40 | blockquote:before, blockquote:after,
41 | q:before, q:after {
42 | content: '';
43 | content: none;
44 | }
45 | table {
46 | border-collapse: collapse;
47 | border-spacing: 0;
48 | }
49 |
50 | /* CUSTOM */
51 | /*Color Palette*/
52 | :root {
53 | --background-primary: #26262b;
54 | --font-primary: #FFF;
55 | --font-secondary: #c8c8c9;
56 | --button-color: #7289da;
57 | --font-family-primary: Whitney, Helvetica Neue, Helvetica, Arial, sans-serif;
58 | }
59 |
60 | body {
61 | background-color: var(--background-primary);
62 | color: var(--font-secondary);
63 | font-size: 13px;
64 | margin: auto;
65 | font-family: var(--font-family-primary);
66 | }
67 |
68 | h1 {
69 | font-size: 2.2em;
70 | font-weight: 700;
71 | }
72 |
73 | h2 {
74 | font-size: 1.8em;
75 | font-weight: 100;
76 | color: var(--font-primary);
77 | }
78 |
79 | h3 {
80 | font-size: 1.8em;
81 | text-transform: none;
82 | color: var(--font-primary);
83 | }
84 |
85 | h4 {
86 | font-size: 15px;
87 | }
88 |
89 | p {
90 | font-size: 15px;
91 | font-weight: lighter;
92 | margin: 30px auto;
93 | color: var(--font-secondary);
94 | }
95 |
96 | a {
97 | font-size: 15px;
98 | text-decoration: none;
99 | color: inherit;
100 | }
101 |
102 | i {
103 | cursor: pointer;
104 | }
105 |
106 | button {
107 | width: 250px;
108 | height: 45px;
109 | font-size: 1.05em;
110 | border-radius: 4px;
111 | background-color: var(--button-color);
112 | border: none;
113 | color: var(--font-primary);
114 | cursor: pointer;
115 | position: relative;
116 | }
117 |
118 | button:focus,
119 | button:hover:active {
120 | outline: none;
121 | }
--------------------------------------------------------------------------------
/app/assets/stylesheets/static_pages.scss:
--------------------------------------------------------------------------------
1 | // Place all the styles related to the StaticPages controller here.
2 | // They will automatically be included in application.css.
3 | // You can use Sass (SCSS) here: http://sass-lang.com/
4 |
--------------------------------------------------------------------------------
/app/assets/stylesheets/style.css:
--------------------------------------------------------------------------------
1 | /* COLOR PALETTE */
2 |
3 | :root {
4 | --font-primary: #FFF;
5 | --font-secondary: #c8c8c9;
6 | --font-tertiary: #4a4a4e;
7 | --border-primary: #48484c;
8 | --text-hover-color: #FFF;
9 | --button-hover: #667bc4;
10 | }
11 |
12 | /* NAV BAR CSS */
13 |
14 | .nav-bar {
15 | margin: 30px 20px;
16 | display: flex;
17 | justify-content: space-between;
18 | align-items: center;
19 | }
20 |
21 | .left-nav {
22 | display: flex;
23 | justify-content: flex-start;
24 | align-items: center;
25 | }
26 |
27 | .right-nav {
28 | display: flex;
29 | justify-content: flex-end;
30 | align-items: center;
31 | }
32 |
33 | .left-nav li {
34 | padding: 0 17px;
35 | }
36 |
37 | .right-nav li {
38 | padding: 0 10px;
39 | }
40 |
41 | li.login-link-container {
42 | margin-left: 10px;
43 | padding-left: 20px;
44 | border-left: 1px solid var(--border-primary);
45 | }
46 |
47 | .right-nav li:hover {
48 | color: var(--text-hover-color);
49 | }
50 |
51 | .login-link {
52 | padding: 6.5px 16.5px;
53 | border: 2px solid var(--font-secondary);
54 | border-radius: 17px;
55 | text-decoration: none;
56 | color: inherit;
57 | margin-right: 10px;
58 | }
59 |
60 | .login-link:hover {
61 | border-color: var(--text-hover-color);
62 | }
63 |
64 | .discourse-logo-wrapper {
65 | display: flex;
66 | align-items: center;
67 | justify-content: space-between;
68 | width: 215px;
69 | }
70 |
71 | .discourse-logo-wrapper img {
72 | display: flex;
73 | width: auto;
74 | height: 42.5px;
75 | }
76 |
77 | .discourse-logo-text {
78 | text-transform: uppercase;
79 | font-size: 35px;
80 | font-weight: bold;
81 | color: var(--font-primary);
82 | font-family: 'Cuprum', sans-serif;
83 | letter-spacing: 2px;
84 | display: flex;
85 | align-items: center;
86 | position: relative;
87 | top: 2px;
88 | user-select: none;
89 | }
90 | /* MAIN CONTENT */
91 |
92 | .main-content {
93 | margin: 125px auto 0 auto;
94 | width: 50%;
95 | display: flex;
96 | flex-direction: column;
97 | justify-content: center;
98 | color: var(--font-primary);
99 | line-height: 1.5em;
100 | text-align: center;
101 | }
102 |
103 | .main-content h1,
104 | p {
105 | user-select: none;
106 | line-height: 1em;
107 | }
108 |
109 | #content-buttons {
110 | display: grid;
111 | grid-template-columns: repeat(auto-fit, 250px);
112 | grid-column-gap: 40px;
113 | grid-row-gap: 10px;
114 | justify-content: center;
115 | justify-items: center;
116 | animation: fadein 2s;
117 | }
118 |
119 | #content-buttons a button {
120 | font-family: Whitney, Helvetica Neue, Helvetica, Arial, sans-serif;
121 | }
122 |
123 | /* via SO, http://jsfiddle.net/SO_AMK/VV2ek/ */
124 | @keyframes fadein {
125 | from {
126 | opacity:0;
127 | }
128 | to {
129 | opacity:1;
130 | }
131 | }
132 |
133 | #content-buttons a:first-of-type button {
134 | background-color: white;
135 | color: var(--font-tertiary);
136 | }
137 |
138 | #content-buttons a button:hover {
139 | top: 1px;
140 | transition: top 2s;
141 | }
142 |
143 | /* BACKGROUND IMAGE CONTAINER */
144 |
145 | .background-image-container {
146 | margin-top: 10px;
147 | height: 650px;
148 | background-image: url("https://cdn.discordapp.com/attachments/560127966688837672/573313319369179156/discord-background.png");
149 | background-repeat: no-repeat;
150 | background-position: center;
151 | }
152 |
153 | /* FOOTER */
154 |
155 | .bottom-content {
156 | display: flex;
157 | flex-direction: column;
158 | justify-content: flex-end;
159 | align-items: center;
160 | }
161 |
162 | .bottom-content ul {
163 | width: 100%;
164 | display: grid;
165 | grid-template-columns: repeat(4, 1fr);
166 | column-gap: 2em;
167 | }
168 |
169 | .footer {
170 | margin-top: 150px;
171 | width: 75%;
172 | margin-bottom: 50px;
173 | }
174 |
175 | .footer ul, li {
176 | line-height: 1.5em;
177 | }
178 |
179 | #foot-header {
180 | display: flex;
181 | flex-direction: column;
182 | justify-content: flex-start;
183 | user-select: none;
184 | }
185 |
186 | #header {
187 | font-weight: bold;
188 | }
189 |
190 | .header {
191 | margin-bottom: 10px;
192 | cursor: auto;
193 | color: var(--font-primary);
194 | }
195 |
196 | .footer ul img {
197 | max-width: 25px;
198 | height: auto;
199 | }
200 |
201 | /* BELOW-FOOTER */
202 |
203 | .below-footer {
204 | width: 75%;
205 | display: flex;
206 | justify-content: space-between;
207 | align-items: center;
208 | padding: 50px 0;
209 | border-top: 1px solid var(--border-primary);
210 | }
211 |
212 | .below-footer button {
213 | width: 105px;
214 | }
215 |
216 | .below-footer button:hover {
217 | background-color: var(--button-hover);
218 | }
219 |
220 | #left-footer p {
221 | text-transform: uppercase;
222 | margin: 1em 0;
223 | user-select: none;
224 | }
225 |
226 | #left-footer h2 {
227 | user-select: none;
228 | }
--------------------------------------------------------------------------------
/app/channels/application_cable/channel.rb:
--------------------------------------------------------------------------------
1 | module ApplicationCable
2 | class Channel < ActionCable::Channel::Base
3 | end
4 | end
5 |
--------------------------------------------------------------------------------
/app/channels/application_cable/connection.rb:
--------------------------------------------------------------------------------
1 | module ApplicationCable
2 | class Connection < ActionCable::Connection::Base
3 |
4 | end
5 | end
6 |
--------------------------------------------------------------------------------
/app/channels/chat_channel.rb:
--------------------------------------------------------------------------------
1 | class ChatChannel < ApplicationCable::Channel
2 | def subscribed
3 | stream_for 'chat_channel'
4 |
5 | end
6 |
7 | def speak(data)
8 | message = Message.new(
9 | body: data['message'],
10 | sender: data['sender'],
11 | custom_timestamp: data['custom_timestamp'],
12 | channel_id: data['channel_id']
13 | )
14 | if message.save
15 | socket = { message: message, type: 'message'}
16 | ChatChannel.broadcast_to('chat_channel', socket)
17 | end
18 | end
19 |
20 | def load
21 | messages = Message.all
22 | message_arr = []
23 | messages.each do |message|
24 | message_el = {
25 | body: message.body,
26 | sender: message.sender,
27 | custom_timestamp: message.custom_timestamp
28 | }
29 | message_arr.push(message_el)
30 | end
31 | socket = { messages: message_arr, type: 'messages' }
32 | ChatChannel.broadcast_to('chat_channel', socket)
33 | end
34 |
35 | def unsubscribed
36 | # Any cleanup needed when channel is unsubscribed
37 | end
38 | end
39 |
--------------------------------------------------------------------------------
/app/controllers/api/messages_controller.rb:
--------------------------------------------------------------------------------
1 | class Api::MessagesController < ApplicationController
2 | def index
3 | # @messages = Message.all
4 | @messages = Message.where(channel_id: params[:server_id])
5 | render 'api/messages/index'
6 | end
7 | end
8 |
--------------------------------------------------------------------------------
/app/controllers/api/servers_controller.rb:
--------------------------------------------------------------------------------
1 | class Api::ServersController < ApplicationController
2 | def create
3 | @server = Server.new(server_params)
4 | @server.owner_id = current_user.id
5 |
6 | if @server.save
7 | UserServer.create!(user_id: current_user.id, server_id: @server.id)
8 | render 'api/servers/show'
9 | else
10 | render json: @server.errors.full_messages, status: 422
11 | end
12 | end
13 |
14 | def destroy
15 | @server = Server.find_by(id: params[:id])
16 | # TODO: CHECK IF USEDRSERVER IS REMOVED
17 | if (@server)
18 | @server.destroy!
19 | user_servers = @server.user_servers;
20 | # user_servers.map (|user_server| user_server.delete!);
21 | user_servers.map(&:destroy!)
22 |
23 | # TODO: FIX THIS, does this work this way with actions now?
24 | # index
25 | render 'api/servers/show'
26 | else
27 | render json: { errors: "You cannot destroy a server that doesn't exist!" }, status: 404
28 | end
29 | end
30 |
31 | def index
32 | @servers = current_user.servers
33 | if @servers
34 | render 'api/servers/index'
35 | else
36 | render json: { errors: 'You cannot access a server you are not in!' }, status: 401
37 | end
38 | end
39 |
40 | def show
41 | @server = current_user.servers.find_by(id: params[:id])
42 | if @server
43 | render 'api/servers/show'
44 | else
45 | render json: { errors: 'You cannot access a server you are not in!'}, status: 401
46 | end
47 | end
48 |
49 | private
50 |
51 | def server_params
52 | params.require(:server).permit(:name)
53 | end
54 | end
55 |
--------------------------------------------------------------------------------
/app/controllers/api/sessions_controller.rb:
--------------------------------------------------------------------------------
1 | class Api::SessionsController < ApplicationController
2 | def create
3 | @user = User.find_by_credentials(params[:user][:username], params[:user][:password])
4 |
5 | if @user
6 | login(@user)
7 | render 'api/users/show' #Is this the right info?
8 | else
9 | render json: ['Invalid credentials'], status: 401 #Is this the right status?
10 | end
11 | end
12 |
13 | def destroy
14 | @user = current_user
15 | if @user
16 | logout
17 | render 'api/users/show' #Is this the right info?
18 | else
19 | render json: ['Must have logged in user to log out'], status: 404
20 | end
21 | end
22 | end
23 |
--------------------------------------------------------------------------------
/app/controllers/api/user_servers_controller.rb:
--------------------------------------------------------------------------------
1 | class Api::UserServersController < ApplicationController
2 | def destroy
3 | @user_server = UserServer.find_by(server_id: params[:id], user_id: current_user.id)
4 | if @user_server
5 | @user_server.delete
6 | @server = Server.find_by(id: params[:id])
7 | render 'api/servers/show'
8 | else
9 | render json: ['Must be in the server before trying to leave it!'], status: 418
10 | end
11 | end
12 |
13 | def create
14 | @server = Server.find_by(invite_link: params[:invite_link])
15 | user_id = current_user.id
16 | unless @server
17 | render json: ['Cannot find server!'], status: 418
18 | else
19 | @user_server = UserServer.new(user_id: user_id, server_id: @server.id)
20 |
21 | if @user_server.save
22 | render 'api/servers/show'
23 | else
24 | render json: ['Cannot join server!'], status: 418
25 | end
26 | end
27 | end
28 |
29 | private
30 |
31 | def user_servers_params
32 | params.require(:user_server).permit(:invite_link)
33 | end
34 | end
35 |
--------------------------------------------------------------------------------
/app/controllers/api/users_controller.rb:
--------------------------------------------------------------------------------
1 | class Api::UsersController < ApplicationController
2 | def create
3 | @user = User.new(user_params)
4 |
5 | if @user.save
6 | login(@user)
7 | render 'api/users/show' #Is this the right place?
8 | else
9 | render json: @user.errors.full_messages, status: 422 #Is this the right status?
10 | end
11 | end
12 |
13 | def index
14 | @users = User.all
15 | render 'api/users/index'
16 | end
17 |
18 | private
19 |
20 | def user_params
21 | params.require(:user).permit(:username, :email, :password)
22 | end
23 | end
24 |
--------------------------------------------------------------------------------
/app/controllers/application_controller.rb:
--------------------------------------------------------------------------------
1 | class ApplicationController < ActionController::Base
2 | protect_from_forgery with: :exception
3 |
4 | helper_method :current_user, :logged_in?
5 |
6 | def current_user
7 | return nil unless session[:session_token]
8 | @current_user ||= User.find_by_session_token(session[:session_token])
9 | end
10 |
11 | private
12 |
13 | def logged_in?
14 | !!current_user
15 | end
16 |
17 | def login(user)
18 | user.reset_session_token!
19 | session[:session_token] = user.session_token
20 | @current_user = user
21 | end
22 |
23 | def logout
24 | current_user.reset_session_token!
25 | session[:session_token] = nil
26 | @current_user = nil
27 | end
28 |
29 | def require_logged_in
30 | unless current_user
31 | render json: { errors: ['You must be logged in'] }, status: 401 # Double check this
32 | end
33 | end
34 |
35 | end
36 |
--------------------------------------------------------------------------------
/app/controllers/concerns/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dowinterfor6/discourse/085d2f02fbbd9f6aa4516b3bd29849ef4c3f305a/app/controllers/concerns/.keep
--------------------------------------------------------------------------------
/app/controllers/static_pages_controller.rb:
--------------------------------------------------------------------------------
1 | class StaticPagesController < ApplicationController
2 | def root
3 | end
4 | end
5 |
--------------------------------------------------------------------------------
/app/helpers/api/servers_helper.rb:
--------------------------------------------------------------------------------
1 | module Api::ServersHelper
2 | end
3 |
--------------------------------------------------------------------------------
/app/helpers/api/sessions_helper.rb:
--------------------------------------------------------------------------------
1 | module Api::SessionsHelper
2 | end
3 |
--------------------------------------------------------------------------------
/app/helpers/api/user_servers_helper.rb:
--------------------------------------------------------------------------------
1 | module Api::UserServersHelper
2 | end
3 |
--------------------------------------------------------------------------------
/app/helpers/api/users_helper.rb:
--------------------------------------------------------------------------------
1 | module Api::UsersHelper
2 | end
3 |
--------------------------------------------------------------------------------
/app/helpers/application_helper.rb:
--------------------------------------------------------------------------------
1 | module ApplicationHelper
2 | end
3 |
--------------------------------------------------------------------------------
/app/helpers/messages_helper.rb:
--------------------------------------------------------------------------------
1 | module MessagesHelper
2 | end
3 |
--------------------------------------------------------------------------------
/app/helpers/static_pages_helper.rb:
--------------------------------------------------------------------------------
1 | module StaticPagesHelper
2 | end
3 |
--------------------------------------------------------------------------------
/app/jobs/application_job.rb:
--------------------------------------------------------------------------------
1 | class ApplicationJob < ActiveJob::Base
2 | end
3 |
--------------------------------------------------------------------------------
/app/mailers/application_mailer.rb:
--------------------------------------------------------------------------------
1 | class ApplicationMailer < ActionMailer::Base
2 | default from: 'from@example.com'
3 | layout 'mailer'
4 | end
5 |
--------------------------------------------------------------------------------
/app/models/application_record.rb:
--------------------------------------------------------------------------------
1 | class ApplicationRecord < ActiveRecord::Base
2 | self.abstract_class = true
3 | end
4 |
--------------------------------------------------------------------------------
/app/models/concerns/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dowinterfor6/discourse/085d2f02fbbd9f6aa4516b3bd29849ef4c3f305a/app/models/concerns/.keep
--------------------------------------------------------------------------------
/app/models/message.rb:
--------------------------------------------------------------------------------
1 | # == Schema Information
2 | #
3 | # Table name: messages
4 | #
5 | # id :bigint not null, primary key
6 | # body :string not null
7 | # created_at :datetime not null
8 | # updated_at :datetime not null
9 | # sender :string not null
10 | # custom_timestamp :string not null
11 | # channel_id :integer not null
12 | #
13 |
14 | class Message < ApplicationRecord
15 | validates :body, :sender, :channel_id, presence: true
16 | end
17 |
--------------------------------------------------------------------------------
/app/models/server.rb:
--------------------------------------------------------------------------------
1 | # == Schema Information
2 | #
3 | # Table name: servers
4 | #
5 | # id :bigint not null, primary key
6 | # name :string not null
7 | # owner_id :integer not null
8 | # created_at :datetime not null
9 | # updated_at :datetime not null
10 | # invite_link :string not null
11 | #
12 |
13 | class Server < ApplicationRecord
14 | validates :name, :owner_id, :invite_link, presence: true
15 |
16 | has_many :user_servers
17 | has_many :users, through: :user_servers
18 | belongs_to :owner,
19 | foreign_key: :owner_id,
20 | class_name: :User
21 |
22 | after_initialize :ensure_invite_link
23 |
24 | private
25 |
26 | def ensure_invite_link
27 | unless self.invite_link
28 | self.invite_link = generate_invite_link
29 | while (Server.find_by(invite_link: self.invite_link))
30 | self.invite_link = generate_invite_link
31 | end
32 | end
33 | end
34 |
35 | def generate_invite_link
36 | "discourse_invite/" + SecureRandom.urlsafe_base64
37 | end
38 |
39 | end
40 |
--------------------------------------------------------------------------------
/app/models/user.rb:
--------------------------------------------------------------------------------
1 | # == Schema Information
2 | #
3 | # Table name: users
4 | #
5 | # id :bigint not null, primary key
6 | # username :string not null
7 | # email :string not null
8 | # password_digest :string not null
9 | # session_token :string not null
10 | # created_at :datetime not null
11 | # updated_at :datetime not null
12 | #
13 |
14 | class User < ApplicationRecord
15 |
16 | attr_reader :password
17 |
18 | validates :username, :email, :password_digest, :session_token, presence: true
19 | validates :username, :email, uniqueness: true
20 | validates :password, length: { minimum: 6 }, allow_nil: true
21 |
22 | after_initialize :ensure_session_token
23 |
24 | has_many :user_servers
25 | has_many :servers, through: :user_servers
26 | has_many :owned_servers,
27 | foreign_key: :owner_id,
28 | class_name: :Server
29 |
30 | # Add associations here
31 |
32 | def reset_session_token!
33 | self.session_token = generate_session_token
34 | save!
35 | self.session_token
36 | end
37 |
38 | def self.find_by_credentials(username, password)
39 | user = User.find_by(username: username)
40 | return nil unless user
41 | user.is_password?(password) ? user : nil
42 | end
43 |
44 | def password=(password)
45 | @password = password
46 | self.password_digest = BCrypt::Password.create(password)
47 | end
48 |
49 | def is_password?(password)
50 | BCrypt::Password.new(self.password_digest).is_password?(password)
51 | end
52 |
53 | private
54 |
55 | def ensure_session_token
56 | self.session_token ||= generate_session_token
57 | end
58 |
59 | # Ensure no collisions
60 | def generate_session_token
61 | self.session_token = SecureRandom.urlsafe_base64
62 | while User.find_by_session_token(self.session_token)
63 | self.session_token = SecureRandom.urlsafe_base64
64 | end
65 | self.session_token
66 | end
67 | end
68 |
--------------------------------------------------------------------------------
/app/models/user_server.rb:
--------------------------------------------------------------------------------
1 | # == Schema Information
2 | #
3 | # Table name: user_servers
4 | #
5 | # id :bigint not null, primary key
6 | # user_id :integer not null
7 | # server_id :integer not null
8 | # created_at :datetime not null
9 | # updated_at :datetime not null
10 | #
11 |
12 | class UserServer < ApplicationRecord
13 | validates :user_id, :server_id, presence: true
14 | validates :user_id, uniqueness: { scope: :server_id }
15 |
16 | belongs_to :user
17 | belongs_to :server
18 | end
19 |
--------------------------------------------------------------------------------
/app/views/api/messages/_message.json.jbuilder:
--------------------------------------------------------------------------------
1 | json.extract! message, :body, :sender, :custom_timestamp
--------------------------------------------------------------------------------
/app/views/api/messages/index.json.jbuilder:
--------------------------------------------------------------------------------
1 | @messages.each do |message|
2 | json.set! message.id do
3 | json.partial! "api/messages/message", message: message
4 | end
5 | end
--------------------------------------------------------------------------------
/app/views/api/servers/_server.json.jbuilder:
--------------------------------------------------------------------------------
1 | json.extract! server, :id, :name, :owner_id, :invite_link
--------------------------------------------------------------------------------
/app/views/api/servers/index.json.jbuilder:
--------------------------------------------------------------------------------
1 | @servers.each do |server|
2 | json.set! server.id do
3 | json.partial! "api/servers/server", server: server
4 | end
5 | end
--------------------------------------------------------------------------------
/app/views/api/servers/show.json.jbuilder:
--------------------------------------------------------------------------------
1 | json.partial! "api/servers/server", server: @server
2 |
3 | json.users do
4 | @server.users.each do |user|
5 | json.set! user.id do
6 | json.partial! "api/users/user", user: user
7 | end
8 | end
9 | end
--------------------------------------------------------------------------------
/app/views/api/users/_user.json.jbuilder:
--------------------------------------------------------------------------------
1 | json.extract! user, :id, :username
--------------------------------------------------------------------------------
/app/views/api/users/index.json.jbuilder:
--------------------------------------------------------------------------------
1 | json.users do
2 | @users.each do |user|
3 | json.set! user.id do
4 | json.partial! "api/users/user", user: user
5 | end
6 | end
7 | end
--------------------------------------------------------------------------------
/app/views/api/users/show.json.jbuilder:
--------------------------------------------------------------------------------
1 | json.partial! "api/users/user", user: @user
2 |
--------------------------------------------------------------------------------
/app/views/layouts/application.html.erb:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Discourse - A Discord clone
5 | <%= csrf_meta_tags %>
6 | <%= csp_meta_tag %>
7 |
8 | <%= stylesheet_link_tag 'application', media: 'all' %>
9 | <%= javascript_include_tag 'application' %>
10 |
11 |
12 |
13 |
19 |
20 |
21 |
22 | <%= yield %>
23 |
24 |
25 |
--------------------------------------------------------------------------------
/app/views/layouts/mailer.html.erb:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
8 |
9 |
10 |
11 | <%= yield %>
12 |
13 |
14 |
--------------------------------------------------------------------------------
/app/views/layouts/mailer.text.erb:
--------------------------------------------------------------------------------
1 | <%= yield %>
2 |
--------------------------------------------------------------------------------
/app/views/static_pages/root.html.erb:
--------------------------------------------------------------------------------
1 | <% if logged_in? %>
2 |
8 | <% end %>
9 |
10 | REACT COME BACK PLS
--------------------------------------------------------------------------------
/bin/bundle:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env ruby
2 | ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
3 | load Gem.bin_path('bundler', 'bundle')
4 |
--------------------------------------------------------------------------------
/bin/rails:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env ruby
2 | begin
3 | load File.expand_path('../spring', __FILE__)
4 | rescue LoadError => e
5 | raise unless e.message.include?('spring')
6 | end
7 | APP_PATH = File.expand_path('../config/application', __dir__)
8 | require_relative '../config/boot'
9 | require 'rails/commands'
10 |
--------------------------------------------------------------------------------
/bin/rake:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env ruby
2 | begin
3 | load File.expand_path('../spring', __FILE__)
4 | rescue LoadError => e
5 | raise unless e.message.include?('spring')
6 | end
7 | require_relative '../config/boot'
8 | require 'rake'
9 | Rake.application.run
10 |
--------------------------------------------------------------------------------
/bin/setup:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env ruby
2 | require 'fileutils'
3 | include FileUtils
4 |
5 | # path to your application root.
6 | APP_ROOT = File.expand_path('..', __dir__)
7 |
8 | def system!(*args)
9 | system(*args) || abort("\n== Command #{args} failed ==")
10 | end
11 |
12 | chdir APP_ROOT do
13 | # This script is a starting point to setup your application.
14 | # Add necessary setup steps to this file.
15 |
16 | puts '== Installing dependencies =='
17 | system! 'gem install bundler --conservative'
18 | system('bundle check') || system!('bundle install')
19 |
20 | # Install JavaScript dependencies if using Yarn
21 | # system('bin/yarn')
22 |
23 | # puts "\n== Copying sample files =="
24 | # unless File.exist?('config/database.yml')
25 | # cp 'config/database.yml.sample', 'config/database.yml'
26 | # end
27 |
28 | puts "\n== Preparing database =="
29 | system! 'bin/rails db:setup'
30 |
31 | puts "\n== Removing old logs and tempfiles =="
32 | system! 'bin/rails log:clear tmp:clear'
33 |
34 | puts "\n== Restarting application server =="
35 | system! 'bin/rails restart'
36 | end
37 |
--------------------------------------------------------------------------------
/bin/spring:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env ruby
2 |
3 | # This file loads spring without using Bundler, in order to be fast.
4 | # It gets overwritten when you run the `spring binstub` command.
5 |
6 | unless defined?(Spring)
7 | require 'rubygems'
8 | require 'bundler'
9 |
10 | lockfile = Bundler::LockfileParser.new(Bundler.default_lockfile.read)
11 | spring = lockfile.specs.detect { |spec| spec.name == "spring" }
12 | if spring
13 | Gem.use_paths Gem.dir, Bundler.bundle_path.to_s, *Gem.path
14 | gem 'spring', spring.version
15 | require 'spring/binstub'
16 | end
17 | end
18 |
--------------------------------------------------------------------------------
/bin/update:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env ruby
2 | require 'fileutils'
3 | include FileUtils
4 |
5 | # path to your application root.
6 | APP_ROOT = File.expand_path('..', __dir__)
7 |
8 | def system!(*args)
9 | system(*args) || abort("\n== Command #{args} failed ==")
10 | end
11 |
12 | chdir APP_ROOT do
13 | # This script is a way to update your development environment automatically.
14 | # Add necessary update steps to this file.
15 |
16 | puts '== Installing dependencies =='
17 | system! 'gem install bundler --conservative'
18 | system('bundle check') || system!('bundle install')
19 |
20 | # Install JavaScript dependencies if using Yarn
21 | # system('bin/yarn')
22 |
23 | puts "\n== Updating database =="
24 | system! 'bin/rails db:migrate'
25 |
26 | puts "\n== Removing old logs and tempfiles =="
27 | system! 'bin/rails log:clear tmp:clear'
28 |
29 | puts "\n== Restarting application server =="
30 | system! 'bin/rails restart'
31 | end
32 |
--------------------------------------------------------------------------------
/bin/yarn:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env ruby
2 | APP_ROOT = File.expand_path('..', __dir__)
3 | Dir.chdir(APP_ROOT) do
4 | begin
5 | exec "yarnpkg", *ARGV
6 | rescue Errno::ENOENT
7 | $stderr.puts "Yarn executable was not detected in the system."
8 | $stderr.puts "Download Yarn at https://yarnpkg.com/en/docs/install"
9 | exit 1
10 | end
11 | end
12 |
--------------------------------------------------------------------------------
/config.ru:
--------------------------------------------------------------------------------
1 | # This file is used by Rack-based servers to start the application.
2 |
3 | require_relative 'config/environment'
4 |
5 | run Rails.application
6 |
--------------------------------------------------------------------------------
/config/application.rb:
--------------------------------------------------------------------------------
1 | require_relative 'boot'
2 |
3 | require 'rails/all'
4 |
5 | # Require the gems listed in Gemfile, including any gems
6 | # you've limited to :test, :development, or :production.
7 | Bundler.require(*Rails.groups)
8 |
9 | module Cordless
10 | class Application < Rails::Application
11 | # Initialize configuration defaults for originally generated Rails version.
12 | config.load_defaults 5.2
13 |
14 | # Settings in config/environments/* take precedence over those specified here.
15 | # Application configuration can go into files in config/initializers
16 | # -- all .rb files in that directory are automatically loaded after loading
17 | # the framework and any gems in your application.
18 | end
19 | end
20 |
--------------------------------------------------------------------------------
/config/boot.rb:
--------------------------------------------------------------------------------
1 | ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
2 |
3 | require 'bundler/setup' # Set up gems listed in the Gemfile.
4 | require 'bootsnap/setup' # Speed up boot time by caching expensive operations.
5 |
--------------------------------------------------------------------------------
/config/cable.yml:
--------------------------------------------------------------------------------
1 | development:
2 | adapter: async
3 |
4 | test:
5 | adapter: async
6 |
7 | production:
8 | adapter: redis
9 | # url: <%= ENV.fetch("REDIS_URL") { "redis://localhost:6379/1" } %>
10 | url: <%= ENV['REDIS_URL'] %>
11 | channel_prefix: cordless_production
12 |
--------------------------------------------------------------------------------
/config/credentials.yml.enc:
--------------------------------------------------------------------------------
1 | 3vb1iDS4Ghu2SYDyRPQvu2uSSHUwiyi+eA6GJMbZUCd4dHuDZKf0QQmkrcpata2Slh5pvSxBCln2ebO0isJHmEjKKw8b0+Xo7y3/ztwVz+44fTiTMwUXtwFoDVld7YfvScJANZg2SRtD8OnLU5xmLJIoq1UwMOnZdLiBts+lCP6RotwURam2nYjUlp+9jK2NlBp/TI+8XXaQrb46kV3xA+UkbZ+oqEqxHhJJVrZtSKEaI3ISfqkg/TS/u2tTTOp/CjDgBc4yT3ZGY+IQeXBCMeY3xdti3o3jj39F3EZ+kUifnhaZ2NwGbqoyQm+8YStNJiPtSx0AIVEUrYx13ajAn6l1E38Lj5HWCC6rfDQ7fnJWHEXZvMSjcdrDVvzuFXlQhuRXtiNcH0KwJ1QOdUDpcmp1CmLitr/3sjN/--65NO9jC06f5lJJ1g--ZraPKmXmtGut96g/cHCjeA==
--------------------------------------------------------------------------------
/config/database.yml:
--------------------------------------------------------------------------------
1 | # PostgreSQL. Versions 9.1 and up are supported.
2 | #
3 | # Install the pg driver:
4 | # gem install pg
5 | # On OS X with Homebrew:
6 | # gem install pg -- --with-pg-config=/usr/local/bin/pg_config
7 | # On OS X with MacPorts:
8 | # gem install pg -- --with-pg-config=/opt/local/lib/postgresql84/bin/pg_config
9 | # On Windows:
10 | # gem install pg
11 | # Choose the win32 build.
12 | # Install PostgreSQL and put its /bin directory on your path.
13 | #
14 | # Configure Using Gemfile
15 | # gem 'pg'
16 | #
17 | default: &default
18 | adapter: postgresql
19 | encoding: unicode
20 | # For details on connection pooling, see Rails configuration guide
21 | # http://guides.rubyonrails.org/configuring.html#database-pooling
22 | pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
23 |
24 | development:
25 | <<: *default
26 | database: cordless_development
27 |
28 | # The specified database role being used to connect to postgres.
29 | # To create additional roles in postgres see `$ createuser --help`.
30 | # When left blank, postgres will use the default role. This is
31 | # the same name as the operating system user that initialized the database.
32 | #username: cordless
33 |
34 | # The password associated with the postgres role (username).
35 | #password:
36 |
37 | # Connect on a TCP socket. Omitted by default since the client uses a
38 | # domain socket that doesn't need configuration. Windows does not have
39 | # domain sockets, so uncomment these lines.
40 | #host: localhost
41 |
42 | # The TCP port the server listens on. Defaults to 5432.
43 | # If your server runs on a different port number, change accordingly.
44 | #port: 5432
45 |
46 | # Schema search path. The server defaults to $user,public
47 | #schema_search_path: myapp,sharedapp,public
48 |
49 | # Minimum log levels, in increasing order:
50 | # debug5, debug4, debug3, debug2, debug1,
51 | # log, notice, warning, error, fatal, and panic
52 | # Defaults to warning.
53 | #min_messages: notice
54 |
55 | # Warning: The database defined as "test" will be erased and
56 | # re-generated from your development database when you run "rake".
57 | # Do not set this db to the same as development or production.
58 | test:
59 | <<: *default
60 | database: cordless_test
61 |
62 | # As with config/secrets.yml, you never want to store sensitive information,
63 | # like your database password, in your source code. If your source code is
64 | # ever seen by anyone, they now have access to your database.
65 | #
66 | # Instead, provide the password as a unix environment variable when you boot
67 | # the app. Read http://guides.rubyonrails.org/configuring.html#configuring-a-database
68 | # for a full rundown on how to provide these environment variables in a
69 | # production deployment.
70 | #
71 | # On Heroku and other platform providers, you may have a full connection URL
72 | # available as an environment variable. For example:
73 | #
74 | # DATABASE_URL="postgres://myuser:mypass@localhost/somedatabase"
75 | #
76 | # You can use this database configuration with:
77 | #
78 | # production:
79 | # url: <%= ENV['DATABASE_URL'] %>
80 | #
81 | production:
82 | <<: *default
83 | database: cordless_production
84 | username: cordless
85 | password: <%= ENV['CORDLESS_DATABASE_PASSWORD'] %>
86 |
--------------------------------------------------------------------------------
/config/environment.rb:
--------------------------------------------------------------------------------
1 | # Load the Rails application.
2 | require_relative 'application'
3 |
4 | # Initialize the Rails application.
5 | Rails.application.initialize!
6 |
--------------------------------------------------------------------------------
/config/environments/development.rb:
--------------------------------------------------------------------------------
1 | Rails.application.configure do
2 | # Settings specified here will take precedence over those in config/application.rb.
3 |
4 | # In the development environment your application's code is reloaded on
5 | # every request. This slows down response time but is perfect for development
6 | # since you don't have to restart the web server when you make code changes.
7 | config.cache_classes = false
8 |
9 | # Do not eager load code on boot.
10 | config.eager_load = false
11 |
12 | # Show full error reports.
13 | config.consider_all_requests_local = true
14 |
15 | # Enable/disable caching. By default caching is disabled.
16 | # Run rails dev:cache to toggle caching.
17 | if Rails.root.join('tmp', 'caching-dev.txt').exist?
18 | config.action_controller.perform_caching = true
19 |
20 | config.cache_store = :memory_store
21 | config.public_file_server.headers = {
22 | 'Cache-Control' => "public, max-age=#{2.days.to_i}"
23 | }
24 | else
25 | config.action_controller.perform_caching = false
26 |
27 | config.cache_store = :null_store
28 | end
29 |
30 | # Store uploaded files on the local file system (see config/storage.yml for options)
31 | config.active_storage.service = :local
32 |
33 | # Don't care if the mailer can't send.
34 | config.action_mailer.raise_delivery_errors = false
35 |
36 | config.action_mailer.perform_caching = false
37 |
38 | # Print deprecation notices to the Rails logger.
39 | config.active_support.deprecation = :log
40 |
41 | # Raise an error on page load if there are pending migrations.
42 | config.active_record.migration_error = :page_load
43 |
44 | # Highlight code that triggered database queries in logs.
45 | config.active_record.verbose_query_logs = true
46 |
47 | # Debug mode disables concatenation and preprocessing of assets.
48 | # This option may cause significant delays in view rendering with a large
49 | # number of complex assets.
50 | config.assets.debug = true
51 |
52 | # Suppress logger output for asset requests.
53 | config.assets.quiet = true
54 |
55 | # Raises error for missing translations
56 | # config.action_view.raise_on_missing_translations = true
57 |
58 | # Use an evented file watcher to asynchronously detect changes in source code,
59 | # routes, locales, etc. This feature depends on the listen gem.
60 | config.file_watcher = ActiveSupport::EventedFileUpdateChecker
61 | end
62 |
--------------------------------------------------------------------------------
/config/environments/production.rb:
--------------------------------------------------------------------------------
1 | Rails.application.configure do
2 | # Settings specified here will take precedence over those in config/application.rb.
3 |
4 | # Code is not reloaded between requests.
5 | config.cache_classes = true
6 |
7 | # Eager load code on boot. This eager loads most of Rails and
8 | # your application in memory, allowing both threaded web servers
9 | # and those relying on copy on write to perform better.
10 | # Rake tasks automatically ignore this option for performance.
11 | config.eager_load = true
12 |
13 | # Full error reports are disabled and caching is turned on.
14 | config.consider_all_requests_local = false
15 | config.action_controller.perform_caching = true
16 |
17 | # Ensures that a master key has been made available in either ENV["RAILS_MASTER_KEY"]
18 | # or in config/master.key. This key is used to decrypt credentials (and other encrypted files).
19 | # config.require_master_key = true
20 |
21 | # Disable serving static files from the `/public` folder by default since
22 | # Apache or NGINX already handles this.
23 | config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present?
24 |
25 | # Compress JavaScripts and CSS.
26 | config.assets.js_compressor = :uglifier
27 | # config.assets.css_compressor = :sass
28 |
29 | # Do not fallback to assets pipeline if a precompiled asset is missed.
30 | config.assets.compile = false
31 |
32 | # `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb
33 |
34 | # Enable serving of images, stylesheets, and JavaScripts from an asset server.
35 | # config.action_controller.asset_host = 'http://assets.example.com'
36 |
37 | # Specifies the header that your server uses for sending files.
38 | # config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache
39 | # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX
40 |
41 | # Store uploaded files on the local file system (see config/storage.yml for options)
42 | config.active_storage.service = :local
43 |
44 | # Mount Action Cable outside main process or domain
45 | # config.action_cable.mount_path = nil
46 | # config.action_cable.url = 'wss://example.com/cable'
47 | # config.action_cable.allowed_request_origins = [ 'http://example.com', /http:\/\/example.*/ ]
48 |
49 | # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
50 | # config.force_ssl = true
51 |
52 | # Use the lowest log level to ensure availability of diagnostic information
53 | # when problems arise.
54 | config.log_level = :debug
55 |
56 | # Prepend all log lines with the following tags.
57 | config.log_tags = [ :request_id ]
58 |
59 | # Use a different cache store in production.
60 | # config.cache_store = :mem_cache_store
61 |
62 | # Use a real queuing backend for Active Job (and separate queues per environment)
63 | # config.active_job.queue_adapter = :resque
64 | # config.active_job.queue_name_prefix = "cordless_#{Rails.env}"
65 |
66 | config.action_mailer.perform_caching = false
67 |
68 | # Ignore bad email addresses and do not raise email delivery errors.
69 | # Set this to true and configure the email server for immediate delivery to raise delivery errors.
70 | # config.action_mailer.raise_delivery_errors = false
71 |
72 | # Enable locale fallbacks for I18n (makes lookups for any locale fall back to
73 | # the I18n.default_locale when a translation cannot be found).
74 | config.i18n.fallbacks = true
75 |
76 | # Send deprecation notices to registered listeners.
77 | config.active_support.deprecation = :notify
78 |
79 | # Use default logging formatter so that PID and timestamp are not suppressed.
80 | config.log_formatter = ::Logger::Formatter.new
81 |
82 | # Use a different logger for distributed setups.
83 | # require 'syslog/logger'
84 | # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name')
85 |
86 | if ENV["RAILS_LOG_TO_STDOUT"].present?
87 | logger = ActiveSupport::Logger.new(STDOUT)
88 | logger.formatter = config.log_formatter
89 | config.logger = ActiveSupport::TaggedLogging.new(logger)
90 | end
91 |
92 | # Do not dump schema after migrations.
93 | config.active_record.dump_schema_after_migration = false
94 | end
95 |
--------------------------------------------------------------------------------
/config/environments/test.rb:
--------------------------------------------------------------------------------
1 | Rails.application.configure do
2 | # Settings specified here will take precedence over those in config/application.rb.
3 |
4 | # The test environment is used exclusively to run your application's
5 | # test suite. You never need to work with it otherwise. Remember that
6 | # your test database is "scratch space" for the test suite and is wiped
7 | # and recreated between test runs. Don't rely on the data there!
8 | config.cache_classes = true
9 |
10 | # Do not eager load code on boot. This avoids loading your whole application
11 | # just for the purpose of running a single test. If you are using a tool that
12 | # preloads Rails for running tests, you may have to set it to true.
13 | config.eager_load = false
14 |
15 | # Configure public file server for tests with Cache-Control for performance.
16 | config.public_file_server.enabled = true
17 | config.public_file_server.headers = {
18 | 'Cache-Control' => "public, max-age=#{1.hour.to_i}"
19 | }
20 |
21 | # Show full error reports and disable caching.
22 | config.consider_all_requests_local = true
23 | config.action_controller.perform_caching = false
24 |
25 | # Raise exceptions instead of rendering exception templates.
26 | config.action_dispatch.show_exceptions = false
27 |
28 | # Disable request forgery protection in test environment.
29 | config.action_controller.allow_forgery_protection = false
30 |
31 | # Store uploaded files on the local file system in a temporary directory
32 | config.active_storage.service = :test
33 |
34 | config.action_mailer.perform_caching = false
35 |
36 | # Tell Action Mailer not to deliver emails to the real world.
37 | # The :test delivery method accumulates sent emails in the
38 | # ActionMailer::Base.deliveries array.
39 | config.action_mailer.delivery_method = :test
40 |
41 | # Print deprecation notices to the stderr.
42 | config.active_support.deprecation = :stderr
43 |
44 | # Raises error for missing translations
45 | # config.action_view.raise_on_missing_translations = true
46 | end
47 |
--------------------------------------------------------------------------------
/config/initializers/application_controller_renderer.rb:
--------------------------------------------------------------------------------
1 | # Be sure to restart your server when you modify this file.
2 |
3 | # ActiveSupport::Reloader.to_prepare do
4 | # ApplicationController.renderer.defaults.merge!(
5 | # http_host: 'example.org',
6 | # https: false
7 | # )
8 | # end
9 |
--------------------------------------------------------------------------------
/config/initializers/assets.rb:
--------------------------------------------------------------------------------
1 | # Be sure to restart your server when you modify this file.
2 |
3 | # Version of your assets, change this if you want to expire all your assets.
4 | Rails.application.config.assets.version = '1.0'
5 |
6 | # Add additional assets to the asset load path.
7 | # Rails.application.config.assets.paths << Emoji.images_path
8 | # Add Yarn node_modules folder to the asset load path.
9 | Rails.application.config.assets.paths << Rails.root.join('node_modules')
10 |
11 | # Precompile additional assets.
12 | # application.js, application.css, and all non-JS/CSS in the app/assets
13 | # folder are already added.
14 | # Rails.application.config.assets.precompile += %w( admin.js admin.css )
15 |
--------------------------------------------------------------------------------
/config/initializers/backtrace_silencers.rb:
--------------------------------------------------------------------------------
1 | # Be sure to restart your server when you modify this file.
2 |
3 | # You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
4 | # Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
5 |
6 | # You can also remove all the silencers if you're trying to debug a problem that might stem from framework code.
7 | # Rails.backtrace_cleaner.remove_silencers!
8 |
--------------------------------------------------------------------------------
/config/initializers/content_security_policy.rb:
--------------------------------------------------------------------------------
1 | # Be sure to restart your server when you modify this file.
2 |
3 | # Define an application-wide content security policy
4 | # For further information see the following documentation
5 | # https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy
6 |
7 | # Rails.application.config.content_security_policy do |policy|
8 | # policy.default_src :self, :https
9 | # policy.font_src :self, :https, :data
10 | # policy.img_src :self, :https, :data
11 | # policy.object_src :none
12 | # policy.script_src :self, :https
13 | # policy.style_src :self, :https
14 |
15 | # # Specify URI for violation reports
16 | # # policy.report_uri "/csp-violation-report-endpoint"
17 | # end
18 |
19 | # If you are using UJS then enable automatic nonce generation
20 | # Rails.application.config.content_security_policy_nonce_generator = -> request { SecureRandom.base64(16) }
21 |
22 | # Report CSP violations to a specified URI
23 | # For further information see the following documentation:
24 | # https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy-Report-Only
25 | # Rails.application.config.content_security_policy_report_only = true
26 |
--------------------------------------------------------------------------------
/config/initializers/cookies_serializer.rb:
--------------------------------------------------------------------------------
1 | # Be sure to restart your server when you modify this file.
2 |
3 | # Specify a serializer for the signed and encrypted cookie jars.
4 | # Valid options are :json, :marshal, and :hybrid.
5 | Rails.application.config.action_dispatch.cookies_serializer = :json
6 |
--------------------------------------------------------------------------------
/config/initializers/filter_parameter_logging.rb:
--------------------------------------------------------------------------------
1 | # Be sure to restart your server when you modify this file.
2 |
3 | # Configure sensitive parameters which will be filtered from the log file.
4 | Rails.application.config.filter_parameters += [:password]
5 |
--------------------------------------------------------------------------------
/config/initializers/inflections.rb:
--------------------------------------------------------------------------------
1 | # Be sure to restart your server when you modify this file.
2 |
3 | # Add new inflection rules using the following format. Inflections
4 | # are locale specific, and you may define rules for as many different
5 | # locales as you wish. All of these examples are active by default:
6 | # ActiveSupport::Inflector.inflections(:en) do |inflect|
7 | # inflect.plural /^(ox)$/i, '\1en'
8 | # inflect.singular /^(ox)en/i, '\1'
9 | # inflect.irregular 'person', 'people'
10 | # inflect.uncountable %w( fish sheep )
11 | # end
12 |
13 | # These inflection rules are supported but not enabled by default:
14 | # ActiveSupport::Inflector.inflections(:en) do |inflect|
15 | # inflect.acronym 'RESTful'
16 | # end
17 |
--------------------------------------------------------------------------------
/config/initializers/mime_types.rb:
--------------------------------------------------------------------------------
1 | # Be sure to restart your server when you modify this file.
2 |
3 | # Add new mime types for use in respond_to blocks:
4 | # Mime::Type.register "text/richtext", :rtf
5 |
--------------------------------------------------------------------------------
/config/initializers/wrap_parameters.rb:
--------------------------------------------------------------------------------
1 | # Be sure to restart your server when you modify this file.
2 |
3 | # This file contains settings for ActionController::ParamsWrapper which
4 | # is enabled by default.
5 |
6 | # Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
7 | ActiveSupport.on_load(:action_controller) do
8 | wrap_parameters format: [:json]
9 | end
10 |
11 | # To enable root element in JSON for ActiveRecord objects.
12 | # ActiveSupport.on_load(:active_record) do
13 | # self.include_root_in_json = true
14 | # end
15 |
--------------------------------------------------------------------------------
/config/locales/en.yml:
--------------------------------------------------------------------------------
1 | # Files in the config/locales directory are used for internationalization
2 | # and are automatically loaded by Rails. If you want to use locales other
3 | # than English, add the necessary files in this directory.
4 | #
5 | # To use the locales, use `I18n.t`:
6 | #
7 | # I18n.t 'hello'
8 | #
9 | # In views, this is aliased to just `t`:
10 | #
11 | # <%= t('hello') %>
12 | #
13 | # To use a different locale, set it with `I18n.locale`:
14 | #
15 | # I18n.locale = :es
16 | #
17 | # This would use the information in config/locales/es.yml.
18 | #
19 | # The following keys must be escaped otherwise they will not be retrieved by
20 | # the default I18n backend:
21 | #
22 | # true, false, on, off, yes, no
23 | #
24 | # Instead, surround them with single quotes.
25 | #
26 | # en:
27 | # 'true': 'foo'
28 | #
29 | # To learn more, please read the Rails Internationalization guide
30 | # available at http://guides.rubyonrails.org/i18n.html.
31 |
32 | en:
33 | hello: "Hello world"
34 |
--------------------------------------------------------------------------------
/config/puma.rb:
--------------------------------------------------------------------------------
1 | # Puma can serve each request in a thread from an internal thread pool.
2 | # The `threads` method setting takes two numbers: a minimum and maximum.
3 | # Any libraries that use thread pools should be configured to match
4 | # the maximum value specified for Puma. Default is set to 5 threads for minimum
5 | # and maximum; this matches the default thread size of Active Record.
6 | #
7 | threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 }
8 | threads threads_count, threads_count
9 |
10 | # Specifies the `port` that Puma will listen on to receive requests; default is 3000.
11 | #
12 | port ENV.fetch("PORT") { 3000 }
13 |
14 | # Specifies the `environment` that Puma will run in.
15 | #
16 | environment ENV.fetch("RAILS_ENV") { "development" }
17 |
18 | # Specifies the number of `workers` to boot in clustered mode.
19 | # Workers are forked webserver processes. If using threads and workers together
20 | # the concurrency of the application would be max `threads` * `workers`.
21 | # Workers do not work on JRuby or Windows (both of which do not support
22 | # processes).
23 | #
24 | # workers ENV.fetch("WEB_CONCURRENCY") { 2 }
25 |
26 | # Use the `preload_app!` method when specifying a `workers` number.
27 | # This directive tells Puma to first boot the application and load code
28 | # before forking the application. This takes advantage of Copy On Write
29 | # process behavior so workers use less memory.
30 | #
31 | # preload_app!
32 |
33 | # Allow puma to be restarted by `rails restart` command.
34 | plugin :tmp_restart
35 |
--------------------------------------------------------------------------------
/config/routes.rb:
--------------------------------------------------------------------------------
1 | Rails.application.routes.draw do
2 | namespace :api, defaults: {format: :json} do
3 | resource :user, only: [:create]
4 | resources :users, only: [:index]
5 | resource :session, only: [:create, :destroy]
6 | resources :servers, only: [:create, :destroy, :show, :index] do
7 | resources :messages, only: [:index]
8 | end
9 | resources :user_servers, only: [:destroy, :create]
10 | end
11 |
12 | mount ActionCable.server, at: '/cable'
13 |
14 | root "static_pages#root"
15 | end
16 |
--------------------------------------------------------------------------------
/config/spring.rb:
--------------------------------------------------------------------------------
1 | %w[
2 | .ruby-version
3 | .rbenv-vars
4 | tmp/restart.txt
5 | tmp/caching-dev.txt
6 | ].each { |path| Spring.watch(path) }
7 |
--------------------------------------------------------------------------------
/config/storage.yml:
--------------------------------------------------------------------------------
1 | test:
2 | service: Disk
3 | root: <%= Rails.root.join("tmp/storage") %>
4 |
5 | local:
6 | service: Disk
7 | root: <%= Rails.root.join("storage") %>
8 |
9 | # Use rails credentials:edit to set the AWS secrets (as aws:access_key_id|secret_access_key)
10 | # amazon:
11 | # service: S3
12 | # access_key_id: <%= Rails.application.credentials.dig(:aws, :access_key_id) %>
13 | # secret_access_key: <%= Rails.application.credentials.dig(:aws, :secret_access_key) %>
14 | # region: us-east-1
15 | # bucket: your_own_bucket
16 |
17 | # Remember not to checkin your GCS keyfile to a repository
18 | # google:
19 | # service: GCS
20 | # project: your_project
21 | # credentials: <%= Rails.root.join("path/to/gcs.keyfile") %>
22 | # bucket: your_own_bucket
23 |
24 | # Use rails credentials:edit to set the Azure Storage secret (as azure_storage:storage_access_key)
25 | # microsoft:
26 | # service: AzureStorage
27 | # storage_account_name: your_account_name
28 | # storage_access_key: <%= Rails.application.credentials.dig(:azure_storage, :storage_access_key) %>
29 | # container: your_container_name
30 |
31 | # mirror:
32 | # service: Mirror
33 | # primary: local
34 | # mirrors: [ amazon, google, microsoft ]
35 |
--------------------------------------------------------------------------------
/db/migrate/20190430204220_create_users.rb:
--------------------------------------------------------------------------------
1 | class CreateUsers < ActiveRecord::Migration[5.2]
2 | def change
3 | create_table :users do |t|
4 | t.string :username, null: false
5 | t.string :email, null: false
6 | t.string :password_digest, null: false
7 | t.string :session_token, null: false
8 |
9 | t.timestamps
10 | end
11 |
12 | add_index :users, :username, unique: true
13 | add_index :users, :email, unique: true
14 | add_index :users, :session_token, unique: true
15 | end
16 | end
17 |
--------------------------------------------------------------------------------
/db/migrate/20190503164923_create_servers.rb:
--------------------------------------------------------------------------------
1 | class CreateServers < ActiveRecord::Migration[5.2]
2 | def change
3 | create_table :servers do |t|
4 | t.string :name, null: false
5 | t.integer :owner_id, null: false
6 |
7 | t.timestamps
8 | end
9 | add_index :servers, :owner_id
10 | end
11 | end
12 |
--------------------------------------------------------------------------------
/db/migrate/20190503165736_create_user_servers.rb:
--------------------------------------------------------------------------------
1 | class CreateUserServers < ActiveRecord::Migration[5.2]
2 | def change
3 | create_table :user_servers do |t|
4 | t.integer :user_id, null: false
5 | t.integer :server_id, null: false
6 | t.timestamps
7 | end
8 |
9 | add_index :user_servers, :user_id
10 | add_index :user_servers, :server_id
11 | end
12 | end
13 |
--------------------------------------------------------------------------------
/db/migrate/20190506161859_add_invite_link_to_servers.rb:
--------------------------------------------------------------------------------
1 | class AddInviteLinkToServers < ActiveRecord::Migration[5.2]
2 | def change
3 | add_column :servers, :invite_link, :string
4 | end
5 | end
6 |
--------------------------------------------------------------------------------
/db/migrate/20190506162112_change_invite_link_in_servers.rb:
--------------------------------------------------------------------------------
1 | class ChangeInviteLinkInServers < ActiveRecord::Migration[5.2]
2 | def change
3 | remove_column :servers, :invite_link, :string
4 | add_column :servers, :invite_link, :string, null: false
5 | end
6 | end
7 |
--------------------------------------------------------------------------------
/db/migrate/20190507171852_add_unique_pairs_to_user_server.rb:
--------------------------------------------------------------------------------
1 | class AddUniquePairsToUserServer < ActiveRecord::Migration[5.2]
2 | def change
3 | add_index :user_servers, [:user_id, :server_id], unique: true
4 | end
5 | end
6 |
--------------------------------------------------------------------------------
/db/migrate/20190507214035_create_messages.rb:
--------------------------------------------------------------------------------
1 | class CreateMessages < ActiveRecord::Migration[5.2]
2 | def change
3 | create_table :messages do |t|
4 | t.string :body, null: false
5 |
6 | t.timestamps
7 | end
8 | end
9 | end
10 |
--------------------------------------------------------------------------------
/db/migrate/20190507214423_add_sender_to_message.rb:
--------------------------------------------------------------------------------
1 | class AddSenderToMessage < ActiveRecord::Migration[5.2]
2 | def change
3 | add_column :messages, :sender, :string, null: false
4 | end
5 | end
6 |
--------------------------------------------------------------------------------
/db/migrate/20190508004239_add_custom_timestamp_to_messages.rb:
--------------------------------------------------------------------------------
1 | class AddCustomTimestampToMessages < ActiveRecord::Migration[5.2]
2 | def change
3 | add_column :messages, :custom_timestamp, :string, null: false
4 | end
5 | end
6 |
--------------------------------------------------------------------------------
/db/migrate/20190509222821_add_channel_id_to_messages.rb:
--------------------------------------------------------------------------------
1 | class AddChannelIdToMessages < ActiveRecord::Migration[5.2]
2 | def change
3 | add_column :messages, :channel_id, :integer, null: false
4 | end
5 | end
6 |
--------------------------------------------------------------------------------
/db/migrate/20190509224332_remove_channel_id_from_messages.rb:
--------------------------------------------------------------------------------
1 | class RemoveChannelIdFromMessages < ActiveRecord::Migration[5.2]
2 | def change
3 | remove_column :messages, :channel_id
4 | end
5 | end
6 |
--------------------------------------------------------------------------------
/db/migrate/20190509224655_add_channel_id_to_messages_again.rb:
--------------------------------------------------------------------------------
1 | class AddChannelIdToMessagesAgain < ActiveRecord::Migration[5.2]
2 | def change
3 | add_column :messages, :channel_id, :integer, null: false
4 | end
5 | end
6 |
--------------------------------------------------------------------------------
/db/schema.rb:
--------------------------------------------------------------------------------
1 | # This file is auto-generated from the current state of the database. Instead
2 | # of editing this file, please use the migrations feature of Active Record to
3 | # incrementally modify your database, and then regenerate this schema definition.
4 | #
5 | # Note that this schema.rb definition is the authoritative source for your
6 | # database schema. If you need to create the application database on another
7 | # system, you should be using db:schema:load, not running all the migrations
8 | # from scratch. The latter is a flawed and unsustainable approach (the more migrations
9 | # you'll amass, the slower it'll run and the greater likelihood for issues).
10 | #
11 | # It's strongly recommended that you check this file into your version control system.
12 |
13 | ActiveRecord::Schema.define(version: 2019_05_09_224655) do
14 |
15 | # These are extensions that must be enabled in order to support this database
16 | enable_extension "plpgsql"
17 |
18 | create_table "messages", force: :cascade do |t|
19 | t.string "body", null: false
20 | t.datetime "created_at", null: false
21 | t.datetime "updated_at", null: false
22 | t.string "sender", null: false
23 | t.string "custom_timestamp", null: false
24 | t.integer "channel_id", null: false
25 | end
26 |
27 | create_table "servers", force: :cascade do |t|
28 | t.string "name", null: false
29 | t.integer "owner_id", null: false
30 | t.datetime "created_at", null: false
31 | t.datetime "updated_at", null: false
32 | t.string "invite_link", null: false
33 | t.index ["owner_id"], name: "index_servers_on_owner_id"
34 | end
35 |
36 | create_table "user_servers", force: :cascade do |t|
37 | t.integer "user_id", null: false
38 | t.integer "server_id", null: false
39 | t.datetime "created_at", null: false
40 | t.datetime "updated_at", null: false
41 | t.index ["server_id"], name: "index_user_servers_on_server_id"
42 | t.index ["user_id", "server_id"], name: "index_user_servers_on_user_id_and_server_id", unique: true
43 | t.index ["user_id"], name: "index_user_servers_on_user_id"
44 | end
45 |
46 | create_table "users", force: :cascade do |t|
47 | t.string "username", null: false
48 | t.string "email", null: false
49 | t.string "password_digest", null: false
50 | t.string "session_token", null: false
51 | t.datetime "created_at", null: false
52 | t.datetime "updated_at", null: false
53 | t.index ["email"], name: "index_users_on_email", unique: true
54 | t.index ["session_token"], name: "index_users_on_session_token", unique: true
55 | t.index ["username"], name: "index_users_on_username", unique: true
56 | end
57 |
58 | end
59 |
--------------------------------------------------------------------------------
/db/seeds.rb:
--------------------------------------------------------------------------------
1 | # This file should contain all the record creation needed to seed the database with its default values.
2 | # The data can then be loaded with the rails db:seed command (or created alongside the database with db:setup).
3 | #
4 | # Examples:
5 | #
6 | # movies = Movie.create([{ name: 'Star Wars' }, { name: 'Lord of the Rings' }])
7 | # Character.create(name: 'Luke', movie: movies.first)
8 |
9 | User.destroy_all
10 | User.create!(username: 'demo_user', email:'demo@gmail.com', password: 'password')
11 | User.create!(username: 'dowinterfor6', email:'winter@gmail.com', password: 'dowinterfor6')
12 | User.create!(username: 'username', email:'user@gmail.com', password: 'password')
13 | User.create!(username: 'xXdragonmasterXx', email:'dragon@gmail.com', password: 'password')
14 | User.create!(username: 'ginger_baker', email:'gbaker@gmail.com', password: 'password')
15 | User.create!(username: 'lil_wizard_boi', email:'wiz@gmail.com', password: 'password')
16 |
17 | user_1 = User.find_by(username: 'demo_user')
18 | user_2 = User.find_by(username: 'dowinterfor6')
19 | user_3 = User.find_by(username: 'username')
20 | user_4 = User.find_by(username: 'xXdragonmasterXx')
21 | user_5 = User.find_by(username: 'ginger_baker')
22 | user_6 = User.find_by(username: 'lil_wizard_boi')
23 |
24 | Server.destroy_all
25 | Server.create!(name: "Demo user's amazing server", owner_id: user_1.id, invite_link: "discourse_invite/4hPkZ5_oRK-pc53WBAU0MQ")
26 | Server.create!(name: 'Elder Memes Online', owner_id: user_2.id, invite_link: "discourse_invite/EHIw9SswhUSwABrqsKzGvg")
27 | Server.create!(name: "Bakers' hangout", owner_id: user_5.id, invite_link: "discourse_invite/2o03IdUt26KZDZVZ1fEcjA")
28 |
29 | server_1 = Server.find_by(name: "Demo user's amazing server")
30 | server_2 = Server.find_by(name: 'Elder Memes Online')
31 | server_3 = Server.find_by(name: "Bakers' hangout")
32 |
33 | UserServer.destroy_all
34 | UserServer.create!(user_id: user_1.id,server_id: server_1.id)
35 | UserServer.create!(user_id: user_2.id,server_id: server_1.id)
36 | UserServer.create!(user_id: user_3.id,server_id: server_1.id)
37 | UserServer.create!(user_id: user_4.id,server_id: server_1.id)
38 | UserServer.create!(user_id: user_5.id,server_id: server_1.id)
39 |
40 | UserServer.create!(user_id: user_2.id,server_id: server_2.id)
41 | UserServer.create!(user_id: user_4.id,server_id: server_2.id)
42 | UserServer.create!(user_id: user_5.id,server_id: server_2.id)
43 |
44 | UserServer.create!(user_id: user_5.id,server_id: server_3.id)
45 | UserServer.create!(user_id: user_1.id,server_id: server_3.id)
46 | UserServer.create!(user_id: user_3.id,server_id: server_3.id)
47 |
48 | # TESTING DELETE
49 |
50 | Server.create!(name: "Another bakers hangout", owner_id: user_5.id, invite_link: "discourse_invite/2o03IdUt26=ZDZVZ1fEcjA")
51 | Server.create!(name: "Best server NA", owner_id: user_2.id, invite_link: "discourse_invite/2o03IdUt26KdDZVZ1fEcjA")
52 | Server.create!(name: "Club Penguin lives on", owner_id: user_3.id, invite_link: "discourse_invite/2o03IdUt2sKZDZVZ1fEcjA")
53 | Server.create!(name: "Dungeons and Dragons", owner_id: user_4.id, invite_link: "discourse_invite/2o03IdUt26KZDZcZ1fEcjA")
54 |
55 | server_4 = Server.find_by(name: "Another bakers hangout")
56 | server_5 = Server.find_by(name: "Best server NA")
57 | server_6 = Server.find_by(name: "Club Penguin lives on")
58 | server_7 = Server.find_by(name: "Dungeons and Dragons")
59 |
60 | UserServer.create!(user_id: user_1.id,server_id: server_4.id)
61 | UserServer.create!(user_id: user_1.id,server_id: server_5.id)
62 | UserServer.create!(user_id: user_1.id,server_id: server_6.id)
63 | UserServer.create!(user_id: user_1.id,server_id: server_7.id)
64 |
65 | UserServer.create!(user_id: user_5.id,server_id: server_4.id)
66 | UserServer.create!(user_id: user_2.id,server_id: server_5.id)
67 | UserServer.create!(user_id: user_3.id,server_id: server_6.id)
68 | UserServer.create!(user_id: user_4.id,server_id: server_7.id)
69 | UserServer.create!(user_id: user_6.id,server_id: server_7.id)
70 |
71 | Message.destroy_all
72 |
73 | Message.create!(body: 'This is a test for Demo user\'s crappy server', sender: 'Admin', custom_timestamp: 'At the beginning of time', channel_id: server_1.id)
74 | Message.create!(body: 'This is a test for THE bakers\'s hangout', sender: 'Admin', custom_timestamp: 'At the beginning of time', channel_id: server_3.id)
75 | Message.create!(body: "Honestly, I've been to ginger baker's bakery and it's not as amazing as everyone says it is. The pastries are nice and fresh, but don't really stand out from the crowd. I've been to other bakeries in the area where the mere smell of the food is enough to entice you to walk in and try out their stuff, while ginger baker's place doesn't really have that type of draw to it. The prices are good though, and that's what keeps me coming back. The doughnuts are a classic, but the croissants are average at best, and they are usually left so long on the counter that they end up turning slightly cold, and aren't reheated thoroughly before serving to customers. They do have a deal where you can buy a pastry paired with some coffee for a discount, and while it is also a very good deal, the coffee is mediocre at best - what else would you expect from a bakery making coffee? The taste is slightly watered down, and the coffee isn't hot enough. Overall, while it is a cheap place, I feel like ginger baker's bakery isn't somewhere I would recommend to a friend for quality, but rather for convenience and price. I'm wondering if anyone else has had a similar experience, or if there are better places with comparable prices that I can visit to experience higher quality pastries? I am a big fan of chocolate croissants and would really appreciate suggestions for a bakery that makes them the right way. Sorry for the long message.", sender: 'A salty pastry enthusiast', custom_timestamp: 'May 10th 2019, 11:22:08 am', channel_id: server_3.id)
76 | Message.create!(body: "This is my server", sender: "xXdragonmasterXx", custom_timestamp: "May 10th 2019, 11:42:02 am", channel_id: server_7.id)
77 | Message.create!(body: "That's debatable...", sender: "lil_wizard_boi", custom_timestamp: "May 10th 2019, 11:43:19 am", channel_id: server_7.id)
--------------------------------------------------------------------------------
/docs/gifs/landing.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dowinterfor6/discourse/085d2f02fbbd9f6aa4516b3bd29849ef4c3f305a/docs/gifs/landing.gif
--------------------------------------------------------------------------------
/docs/gifs/login_errors.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dowinterfor6/discourse/085d2f02fbbd9f6aa4516b3bd29849ef4c3f305a/docs/gifs/login_errors.gif
--------------------------------------------------------------------------------
/docs/gifs/reguster_errors.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dowinterfor6/discourse/085d2f02fbbd9f6aa4516b3bd29849ef4c3f305a/docs/gifs/reguster_errors.gif
--------------------------------------------------------------------------------
/docs/images/expanding-text-field-screenshot.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dowinterfor6/discourse/085d2f02fbbd9f6aa4516b3bd29849ef4c3f305a/docs/images/expanding-text-field-screenshot.png
--------------------------------------------------------------------------------
/docs/images/server-screenshot-blurred.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dowinterfor6/discourse/085d2f02fbbd9f6aa4516b3bd29849ef4c3f305a/docs/images/server-screenshot-blurred.png
--------------------------------------------------------------------------------
/docs/images/user-auth-errors-more.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dowinterfor6/discourse/085d2f02fbbd9f6aa4516b3bd29849ef4c3f305a/docs/images/user-auth-errors-more.png
--------------------------------------------------------------------------------
/docs/images/user-auth-errors.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dowinterfor6/discourse/085d2f02fbbd9f6aa4516b3bd29849ef4c3f305a/docs/images/user-auth-errors.png
--------------------------------------------------------------------------------
/frontend/actions/chat_actions.js:
--------------------------------------------------------------------------------
1 | import * as chatUtil from '../util/chat_util'
2 | export const RECEIVE_CHAT_HISTORY = "RECEIVE_CHAT_HISTORY"
3 |
4 | const receiveChatHistory = (messages) => ({
5 | type: RECEIVE_CHAT_HISTORY,
6 | messages
7 | });
8 |
9 | export const fetchChatHistory = (server_id) => (dispatch) => (
10 | chatUtil.getChatHistory(server_id)
11 | .then(
12 | (messages) => dispatch(receiveChatHistory(messages))
13 | )
14 | );
--------------------------------------------------------------------------------
/frontend/actions/modal_actions.js:
--------------------------------------------------------------------------------
1 | export const OPEN_MODAL = "OPEN_MODAL";
2 | export const CLOSE_MODAL = "CLOSE_MODAL";
3 |
4 | export const openModal = (modal, id) => {
5 | return {
6 | type: OPEN_MODAL,
7 | modal: {
8 | modal,
9 | id
10 | }
11 | }
12 | }
13 |
14 | export const closeModal = () => {
15 | return {
16 | type: CLOSE_MODAL
17 | }
18 | }
--------------------------------------------------------------------------------
/frontend/actions/server_actions.js:
--------------------------------------------------------------------------------
1 | import * as APIUtil from "../util/server_api_util";
2 |
3 | export const RECEIVE_ALL_SERVERS = "RECEIVE_ALL_SERVERS"; //Index, fetch
4 | export const RECEIVE_SERVER = "RECEIVE_SERVER"; //Show
5 | export const RECEIVE_SERVER_ERRORS = "RECEIVE_SERVER_ERRORS";
6 | export const REMOVE_SERVER = "REMOVE_SERVER";
7 | export const LEAVE_SERVER = "LEAVE_SERVER";
8 |
9 | //Need current user info?
10 | const receiveAllServers = (servers) => ({
11 | type: RECEIVE_ALL_SERVERS,
12 | servers
13 | });
14 |
15 | //Server
16 | const receiveServer = (server) => ({
17 | type: RECEIVE_SERVER,
18 | server
19 | });
20 |
21 | //TODO: Passing in ID (to get from match.params.id)
22 | const removeServer = ({id}) => ({
23 | type: REMOVE_SERVER,
24 | id
25 | });
26 |
27 | //TODO: MIGHT NOT WORK
28 | const leaveServerAction = ({id}) => ({
29 | type: LEAVE_SERVER,
30 | id
31 | })
32 |
33 | const receiveErrors = (errors) => ({
34 | type: RECEIVE_SERVER_ERRORS,
35 | errors
36 | });
37 |
38 | //TODO: Do i need this?
39 | export const deleteServerErrors = () => (dispatch) => (
40 | dispatch(receiveErrors([]))
41 | );
42 |
43 | export const fetchAllServers = () => (dispatch) => (
44 | APIUtil.serverIndex()
45 | .then(
46 | (servers) => dispatch(receiveAllServers(servers)),
47 | (errors) => dispatch(receiveErrors(errors.responseJSON))
48 | )
49 | );
50 |
51 | //TODO: Returns server, use .then
52 | export const fetchServer = (id) => (dispatch) => (
53 | APIUtil.showServer(id)
54 | .then(
55 | (server) => dispatch(receiveServer(server)),
56 | (errors) => dispatch(receiveErrors(errors.responseJSON))
57 | )
58 | );
59 |
60 | export const createServer = (newServer) => (dispatch) => (
61 | APIUtil.createServer(newServer)
62 | .then(
63 | (server) => dispatch(receiveServer(server)),
64 | (errors) => dispatch(receiveErrors(errors.responseJSON))
65 | )
66 | )
67 |
68 | //TODO: returns information on action creator
69 | export const deleteServer = (id) => (dispatch) => (
70 | APIUtil.deleteServer(id)
71 | .then(
72 | (server) => dispatch(removeServer(server)),
73 | (errors) => dispatch(receiveErrors(errors.responseJSON))
74 | )
75 | )
76 |
77 | export const leaveServer = (id) => (dispatch) => (
78 | APIUtil.leaveServer(id)
79 | .then(
80 | (server) => dispatch(leaveServerAction(server))
81 | )
82 | )
83 |
84 | //TODO: CHECK ERRORS
85 | export const joinServer = (link) => (dispatch) => (
86 | APIUtil.joinServer(link)
87 | .then(
88 | (server) => dispatch(receiveServer(server)),
89 | (errors) => dispatch(receiveErrors(errors.responseJSON))
90 | )
91 | )
--------------------------------------------------------------------------------
/frontend/actions/session_actions.js:
--------------------------------------------------------------------------------
1 | import * as APIUtil from '../util/session_api_util';
2 |
3 | export const RECEIVE_CURRENT_USER = 'RECEIVE_CURRENT_USER';
4 | export const LOGOUT_CURRENT_USER = 'LOGOUT_CURRENT_USER';
5 | export const RECEIVE_SESSION_ERRORS = 'RECEIVE_SESSION_ERRORS';
6 | export const REMOVE_ERRORS = 'REMOVE_ERRORS';
7 |
8 | const receiveCurrentUser = (currentUser) => ({
9 | type: RECEIVE_CURRENT_USER,
10 | currentUser
11 | });
12 |
13 | const logoutCurrentUser = () => ({
14 | type: LOGOUT_CURRENT_USER
15 | });
16 |
17 | const receiveErrors = (errors) => ({
18 | type: RECEIVE_SESSION_ERRORS,
19 | errors
20 | });
21 |
22 | export const deleteErrors = () => (dispatch) => (
23 | dispatch(receiveErrors([]))
24 | );
25 |
26 | export const login = (user) => (dispatch) => (
27 | APIUtil.login(user)
28 | .then(
29 | (user) => dispatch(receiveCurrentUser(user)),
30 | (error) => dispatch(receiveErrors(error.responseJSON)) //Why .responseJSON
31 | )
32 | );
33 |
34 | export const signup = (user) => (dispatch) => (
35 | APIUtil.signup(user)
36 | .then(
37 | (user) => dispatch(receiveCurrentUser(user)),
38 | (error) => dispatch(receiveErrors(error.responseJSON))
39 | )
40 | );
41 |
42 | export const logout = () => (dispatch) => (
43 | APIUtil.logout()
44 | .then(
45 | () => dispatch(logoutCurrentUser())
46 | )
47 | );
--------------------------------------------------------------------------------
/frontend/components/app.jsx:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import { Route, Redirect, Switch, Link, HashRouter } from 'react-router-dom';
3 | import landingPage from './landing_page/landing_page';
4 | import loginFormContainer from './session_form/login_form_container';
5 | import signupFormContainer from './session_form/signup_form_container';
6 | import serverIndexContainer from './discord_servers/server_index_container';
7 | import { AuthRoute, ProtectedRoute } from '../util/route_util';
8 | import landingChannelContainer from './channel_content/landing_channel_container';
9 |
10 | const App = () => (
11 |
12 | {/*
*/}
13 |
14 | {/* */}
15 |
16 |
17 |
18 | {/* */}
19 |
20 | )
21 |
22 | export default App;
--------------------------------------------------------------------------------
/frontend/components/cable_chat/chat_room.jsx:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import MessageFormContainer from './message_form_container';
3 | import {withRouter} from 'react-router-dom';
4 |
5 | class ChatRoom extends React.Component {
6 | constructor(props) {
7 | super(props);
8 | this.state = {
9 | messages: []
10 | };
11 | this.bottom = React.createRef();
12 | }
13 |
14 | componentDidMount() {
15 | App.cable.subscriptions.create(
16 | "ChatChannel",
17 | {
18 | received: (data) => {
19 | switch (data.type) {
20 | case 'message':
21 | this.setState({
22 | messages: this.state.messages.concat(
23 | {
24 | body: data.message.body,
25 | sender: data.message.sender,
26 | custom_timestamp: data.message.custom_timestamp
27 | }
28 | )
29 | });
30 | break;
31 | case 'messages':
32 | this.setState({
33 | messages: Object.values(data.messages)
34 | });
35 | break;
36 | }
37 | },
38 | speak: function(data) {
39 | return this.perform("speak", data);
40 | },
41 | load: function() {
42 | return this.perform("load");
43 | },
44 | }
45 | )
46 |
47 | this.props.fetchChatHistory(this.props.match.params.id).then(
48 | (data) => {
49 | this.setState({messages: Object.values(data.messages)});
50 | }
51 | )
52 | }
53 |
54 | componentDidUpdate(prevProps) {
55 | if (this.bottom.current) {
56 | this.bottom.current.scrollIntoView();
57 | };
58 | if (prevProps.match.params.id !== this.props.match.params.id) {
59 | this.props.fetchChatHistory(this.props.match.params.id).then(
60 | (data) => {
61 | this.setState({ messages: Object.values(data.messages) });
62 | }
63 | )
64 | }
65 | }
66 |
67 | render() {
68 | let messageList;
69 | if (this.state.messages.length === 0) {
70 | messageList =
71 |
72 |
73 |
74 | There seems to be no previous messages... you can call dibs on 'first'!
75 |
76 |
77 |
78 | } else {
79 | messageList = this.state.messages.map((message, idx) => {
80 | return (
81 |
82 |
83 |
84 | {message.sender}
85 |
86 |
87 | {message.custom_timestamp}
88 |
89 |
90 |
93 |
94 |
95 | )
96 | });
97 | }
98 |
99 | return (
100 |
101 |
102 | {messageList}
103 |
104 |
105 |
106 |
107 | )
108 | }
109 | }
110 |
111 | export default withRouter(ChatRoom);
--------------------------------------------------------------------------------
/frontend/components/cable_chat/chat_room_container.jsx:
--------------------------------------------------------------------------------
1 | import { connect } from "react-redux";
2 | import { fetchChatHistory } from "../../actions/chat_actions";
3 | import ChatRoom from "./chat_room";
4 |
5 | const mapDispatchToProps = (dispatch) => {
6 | return {
7 | fetchChatHistory: (server_id) => dispatch(fetchChatHistory(server_id))
8 | }
9 | };
10 |
11 | export default connect(
12 | null,
13 | mapDispatchToProps
14 | )(ChatRoom);
--------------------------------------------------------------------------------
/frontend/components/cable_chat/member_list.jsx:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import MemberListItem from './member_list_items';
3 | import {withRouter} from 'react-router-dom';
4 |
5 | class MemberList extends React.Component {
6 | constructor(props) {
7 | super(props);
8 | this.state = {
9 | users: {}
10 | }
11 | this.refetchServerMembers = this.refetchServerMembers.bind(this);
12 | }
13 |
14 | refetchServerMembers() {
15 | this.props.fetchServer(this.props.match.params.id)
16 | .then(
17 | (data) => {
18 | this.setState({ users: data.server.users });
19 | }
20 | )
21 | }
22 |
23 | componentDidMount() {
24 | this.refetchServerMembers();
25 | }
26 |
27 | componentDidUpdate(prevProps) {
28 | if (prevProps.match.params.id !== this.props.match.params.id) {
29 | this.refetchServerMembers();
30 | }
31 | }
32 |
33 | render() {
34 | let users = Object.values(this.state.users);
35 | return (
36 | <>
37 | Users - {users.length}
38 |
39 | {users.map((user, idx) => (
40 |
41 | ))}
42 |
43 | >
44 | )
45 | }
46 | }
47 |
48 | export default withRouter(MemberList);
--------------------------------------------------------------------------------
/frontend/components/cable_chat/member_list_container.jsx:
--------------------------------------------------------------------------------
1 | import { connect } from "react-redux";
2 | import MemberList from "./member_list";
3 | import { fetchServer } from "../../actions/server_actions";
4 |
5 | const mapDispatchToProps = (dispatch) => {
6 | return {
7 | fetchServer: (id) => dispatch(fetchServer(id))
8 | }
9 | };
10 |
11 | export default connect(
12 | null,
13 | mapDispatchToProps
14 | )(MemberList);
--------------------------------------------------------------------------------
/frontend/components/cable_chat/member_list_items.jsx:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 |
3 | class MemberListItem extends React.Component {
4 | constructor(props) {
5 | super(props);
6 | }
7 |
8 | avatarColorRandomizer(id) {
9 | let colors = {
10 | 0: '#96ec5f',
11 | 1: '#4d963c',
12 | 2: '#1c6028',
13 | 3: '#a51919',
14 | 4: '#ffb321',
15 | 5: '#4f3985',
16 | 6: '#00c5ff'
17 | }
18 | return colors[id % (Object.keys(colors).length - 1)];
19 | }
20 |
21 | render() {
22 | let backgroundColor = this.avatarColorRandomizer(this.props.id);
23 | let online = true;
24 | return(
25 |
26 |
27 |
28 | {online ?
29 |
30 |
31 | :
32 | null
33 | }
34 |
35 |
36 | {this.props.username}
37 |
38 | )
39 | }
40 | }
41 |
42 | export default MemberListItem;
--------------------------------------------------------------------------------
/frontend/components/cable_chat/message_form.jsx:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import {withRouter} from 'react-router-dom';
3 |
4 | class MessageForm extends React.Component {
5 | constructor(props) {
6 | super(props);
7 | this.state = {
8 | body: ""
9 | }
10 | this.handleSubmit = this.handleSubmit.bind(this);
11 | this.handleEnter = this.handleEnter.bind(this);
12 | this.callSpeak = this.callSpeak.bind(this);
13 | }
14 |
15 | update(field) {
16 | return (e) => {
17 | this.setState({[field]: e.currentTarget.value});
18 | this.resizeTextarea(e);
19 | }
20 | }
21 |
22 | resizeTextarea(e) {
23 | let currentTarget = e.currentTarget;
24 | currentTarget.style.height = "1px";
25 | currentTarget.style.height = (currentTarget.scrollHeight) + "px";
26 | let container = document.getElementsByClassName('message-form-container')[0];
27 | container.style.height = "1px";
28 | container.style.height = (65 + currentTarget.scrollHeight) + "px";
29 | }
30 |
31 | resetTextarea() {
32 | let textArea = document.getElementsByClassName('message-form-textarea')[0];
33 | if (textArea.scrollHeight > 45) {
34 | textArea.style.height = "45px";
35 | let container = document.getElementsByClassName('message-form-container')[0];
36 | container.style.height = "100px";
37 | }
38 | }
39 |
40 | handleSubmit(e) {
41 | e.preventDefault();
42 | this.callSpeak();
43 | }
44 |
45 | callSpeak() {
46 | if (this.state.body) {
47 | let moment = require('moment');
48 | let date = moment().format('MMMM Do YYYY, h:mm:ss a');
49 | App.cable.subscriptions.subscriptions[0].speak({
50 | message: this.state.body,
51 | sender: this.props.currentUser.username,
52 | custom_timestamp: date,
53 | channel_id: this.props.match.params.id
54 | });
55 | this.setState({ body: "" });
56 | this.resetTextarea();
57 | }
58 | }
59 |
60 | handleEnter(evt) {
61 | if (evt.which === 13 && !evt.shiftKey) {
62 | evt.preventDefault();
63 | this.callSpeak();
64 | }
65 | }
66 |
67 | render() {
68 | return (
69 |
86 | )
87 | }
88 | }
89 |
90 | export default withRouter(MessageForm);
--------------------------------------------------------------------------------
/frontend/components/cable_chat/message_form_container.jsx:
--------------------------------------------------------------------------------
1 | import { connect } from "react-redux";
2 | import MessageForm from "./message_form";
3 |
4 | const mapStateToProps = (state) => {
5 | return {
6 | currentUser: Object.values(state.entities.users)[0]
7 | }
8 | };
9 |
10 | export default connect(
11 | mapStateToProps,
12 | null
13 | )(MessageForm);
--------------------------------------------------------------------------------
/frontend/components/channel_content/activity_display.jsx:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 |
3 | class ActivityDisplay extends React.Component {
4 |
5 | render() {
6 | return (
7 |
8 |
9 |
10 |
15 |
16 | In Fallout 76, the first nuke is launched and it has a huge effect:
17 | deathclaws get wings, the world is thrown into a nuclear winter,
18 | and technology is set back to the Iron Age. Your player wakes up in a cart
19 | with his hands bound, greeted by the fresh smell of pine and the voices
20 | of a few other men. "Hey you, finally awake? You were trying to cross
21 | the border right?" one of them asks, as a title appears in the sky:
22 | "Elder Scrolls V: Skyrim".
23 |
24 |
25 |
26 |
31 |
32 | Half-Life 3 is the most elusive sequel in gaming history. There have been
33 | multiple false reports of the game being in development, but have been
34 | squashed by critics who severely doubt Valve's counting ability. "Two is the
35 | highest the company can count to, there's no denying that fact!" - Angry Steam Review
36 |
37 |
38 |
39 |
44 |
45 | Monster Hunter Go, the long awaited collaboration between Capcom and Niantic,
46 | introducing the beasts of the Monster Hunter series into the world of AR (augmented
47 | reality). Experience your world like never before, preparing for battles around
48 | every corner, hunting the elusive Silver Rathalos, or running for your life from
49 | the vicious Lunastra.
50 |
51 |
52 |
53 |
58 |
59 | Metal Gear Solid: Kojima Returns is the latest installment in the MGS series.
60 | After being ousted from Konami productions, Hideo Kojima became an icon of hope
61 | and inspiration for fans of the game, who have come together to create a fan-made
62 | sequel to the popular series.
63 |
64 |
65 |
66 |
71 |
72 | Following the success of the game for over a decade, Riot Games have decided
73 | to live up to the plural in their company name, and have released the sequel;
74 | League of Legends 2: Legends Royale. Dropped in the unforgiving landscape of
75 | Summoner's Saltmine, champions must scavenge the area for items to enhance
76 | their abilities and fight each other to the death.
77 |
78 |
79 |
80 |
81 | )
82 | }
83 | }
84 |
85 | export default ActivityDisplay;
--------------------------------------------------------------------------------
/frontend/components/channel_content/channel_index.jsx:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import { Link } from 'react-router-dom';
3 | import UserInfoBar from './user_info_bar';
4 | import ChatRoom from '../cable_chat/chat_room';
5 | import ChatRoomContainer from '../cable_chat/chat_room_container';
6 | import MemberList from '../cable_chat/member_list';
7 | import MemberListContainer from '../cable_chat/member_list_container';
8 |
9 | class ChannelIndex extends React.Component {
10 | constructor(props) {
11 | super(props);
12 | this.state = {
13 | currentServer: {},
14 | servers: {},
15 | dropdownState: false
16 | };
17 | this.updateStateWithFetch = this.updateStateWithFetch.bind(this);
18 | this.handleDropdownIconClick = this.handleDropdownIconClick.bind(this);
19 | this.handleOpenModal = this.handleOpenModal.bind(this);
20 | }
21 |
22 | updateStateWithFetch() {
23 | return (
24 | this.props.fetchAllServers()
25 | .then(
26 | (res) => this.setState({ servers: res.servers })
27 | ).then(
28 | () => this.setState({ currentServer: this.state.servers[this.props.match.params.id] })
29 | )
30 | );
31 | }
32 |
33 | componentDidMount() {
34 | this.updateStateWithFetch()
35 | .then(
36 | () => {
37 | //TODO: this is actually dumbaf please fix this asap
38 | //I dont know when another component has mounted
39 | //use global state?
40 | window.setTimeout(() => {
41 | if (!document.getElementsByClassName('nav-in-focus')[0]) {
42 | let elementPreload;
43 | elementPreload = document.getElementsByClassName(`${this.props.match.params.id}`)[0];
44 | elementPreload.classList.add('nav-in-focus');
45 | }
46 | }, 200);
47 | }
48 | )
49 | }
50 |
51 | componentDidUpdate(prevProps) {
52 | if (prevProps.match.params.id !== this.props.match.params.id) {
53 | let dropdownComponent = document.getElementsByClassName('channel-title-dropdown')[0];
54 | dropdownComponent.classList.add('hidden');
55 | this.setState({dropdownState: false});
56 | this.updateStateWithFetch();
57 | }
58 | }
59 |
60 | handleDropdownIconClick(e) {
61 | let dropdownNextState = !this.state.dropdownState;
62 | let dropdownComponent = document.getElementsByClassName('channel-title-dropdown')[0];
63 | if (!this.state.dropdownState) {
64 | dropdownComponent.classList.remove('hidden');
65 | dropdownComponent.classList.add('slideInDown');
66 | window.setTimeout(() => {
67 | dropdownComponent.classList.remove('slideInDown');
68 | }, 200);
69 | } else {
70 | dropdownComponent.classList.add('hidden');
71 | }
72 | this.setState({dropdownState: dropdownNextState});
73 | }
74 |
75 | handleOpenModal(e) {
76 | //TODO: match params works here
77 | let dropdownComponent = document.getElementsByClassName('channel-title-dropdown')[0];
78 | dropdownComponent.classList.add('hidden');
79 | this.setState({ dropdownState: false });
80 | let modalIdentifier;
81 | if (e.currentTarget.innerHTML.includes('Invite')) {
82 | modalIdentifier = 'invite-link-display';
83 | } else if (e.currentTarget.innerHTML.includes('Delete')){
84 | modalIdentifier = 'delete-server-modal';
85 | } else {
86 | modalIdentifier = 'leave-server-modal';
87 | }
88 | this.props.openModal(modalIdentifier, this.props.match.params.id); //payload
89 | }
90 |
91 | render() {
92 | // TODO: APP NEEDS REFRESH AFTER LOGIN TO UPDATE CURRENT USER
93 | let serverName;
94 | let currentUserId;
95 | let currentServerOwnerId;
96 | if (this.state.currentServer) {
97 | serverName = this.state.currentServer.name;
98 | document.title = serverName; //TODO: CHANGE TO CHANNEL NAME LATER
99 | currentUserId = this.props.currentUser.id;
100 | currentServerOwnerId = this.state.currentServer.owner_id;
101 | }
102 |
103 | return (
104 |
105 |
106 |
107 |
{serverName}
108 |
109 | {this.state.dropdownState ?
110 |
111 | :
112 |
113 | }
114 |
115 |
116 |
117 |
118 |
119 | Invite your friends!
120 |
121 |
122 | {currentUserId === currentServerOwnerId ?
123 | <>
124 |
125 | Delete server
126 | >
127 | :
128 | <>
129 |
130 | Leave server
131 | >
132 | }
133 |
134 |
135 |
136 |
137 |
138 |
139 |
153 |
154 |
159 |
160 |
161 | {/* TODO: refactor and add channel_list_item component */}
162 |
165 |
166 |
167 |
168 |
171 |
172 |
175 |
176 | )
177 | }
178 | }
179 |
180 | export default ChannelIndex;
--------------------------------------------------------------------------------
/frontend/components/channel_content/channel_index_container.jsx:
--------------------------------------------------------------------------------
1 | import { logout } from "../../actions/session_actions";
2 | import { connect } from "react-redux";
3 | import ChannelIndex from "./channel_index";
4 | import { fetchServer, fetchAllServers } from "../../actions/server_actions";
5 | import { openModal } from "../../actions/modal_actions";
6 |
7 | const mapStateToProps = (state) => {
8 | return {
9 | currentUser: Object.values(state.entities.users)[0]
10 | }
11 | };
12 |
13 | const mapDispatchToProps = (dispatch) => ({
14 | logout: () => dispatch(logout()),
15 | fetchServer: (id) => dispatch(fetchServer(id)),
16 | fetchAllServers: () => dispatch(fetchAllServers()),
17 | openModal: (modal, id) => dispatch(openModal(modal, id))
18 | });
19 |
20 | export default connect(
21 | mapStateToProps,
22 | mapDispatchToProps
23 | )(ChannelIndex);
--------------------------------------------------------------------------------
/frontend/components/channel_content/landing_channel.jsx:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import { Link } from 'react-router-dom';
3 | import UserInfoBar from './user_info_bar';
4 | import ActivityDisplay from './activity_display';
5 | import MemberListItem from '../cable_chat/member_list_items';
6 |
7 | class LandingChannel extends React.Component {
8 | constructor(props) {
9 | super(props);
10 |
11 | this.state = {
12 | userList: {}
13 | };
14 | }
15 |
16 | updateDocumentTitle() {
17 | if (document.title !== 'Activity') {
18 | document.title = 'Activity';
19 | }
20 | }
21 |
22 | componentDidUpdate() {
23 | this.updateDocumentTitle();
24 | }
25 |
26 | componentDidMount() {
27 | this.updateDocumentTitle();
28 | this.props.fetchUsers().then(
29 | (data) => this.setState({ userList: data.users })
30 | );
31 | }
32 |
33 | render() {
34 | let currentUser = this.props.currentUser;
35 | let userDisplay;
36 | if (this.state.userList) {
37 | userDisplay = Object.values(this.state.userList).map(
38 | (user, idx) => (
39 |
40 | )
41 | )
42 | }
43 |
44 | return (
45 |
46 |
47 |
60 |
61 |
62 |
63 |
64 |
Activity
65 |
66 |
67 | {/* */}
68 | {/* */}
69 |
70 |
71 |
72 |
73 |
74 | {/* */}
75 | {/*
76 | Activity
77 |
78 | Library
79 |
80 | Nitro
81 | */}
82 | {/* */}
83 |
88 |
89 |
90 |
91 |
92 |
93 |
94 | )
95 | }
96 | }
97 |
98 | export default LandingChannel;
--------------------------------------------------------------------------------
/frontend/components/channel_content/landing_channel_container.jsx:
--------------------------------------------------------------------------------
1 | import { logout } from "../../actions/session_actions";
2 | import { connect } from "react-redux";
3 | import LandingChannel from "./landing_channel";
4 | import { userIndex } from "../../util/user_util";
5 |
6 | const mapStateToProps = (state) => {
7 | return {
8 | currentUser: Object.values(state.entities.users)[0]
9 | }
10 | };
11 |
12 | const mapDispatchToProps = (dispatch) => ({
13 | logout: () => dispatch(logout()),
14 | fetchUsers: () => dispatch(userIndex)
15 | });
16 |
17 | export default connect(
18 | mapStateToProps,
19 | mapDispatchToProps
20 | )(LandingChannel);
--------------------------------------------------------------------------------
/frontend/components/channel_content/user_info_bar.jsx:
--------------------------------------------------------------------------------
1 | import React from 'react'
2 |
3 | const UserInfoBar = ({currentUser, logout}) => (
4 |
5 | {currentUser.username}
6 |
7 | {/* */}
8 |
9 |
10 |
11 |
12 |
13 | );
14 |
15 | export default UserInfoBar;
--------------------------------------------------------------------------------
/frontend/components/discord_servers/add_server_container.jsx:
--------------------------------------------------------------------------------
1 | import AddServerIcon from './add_server_icon';
2 | import { createServer } from '../../actions/server_actions';
3 | import { connect } from 'react-redux';
4 | import { openModal } from '../../actions/modal_actions';
5 |
6 | const mapDispatchToProps = (dispatch) => ({
7 | openModal: (modal) => dispatch(openModal(modal))
8 | });
9 |
10 | export default connect(
11 | null,
12 | mapDispatchToProps
13 | )(AddServerIcon);
--------------------------------------------------------------------------------
/frontend/components/discord_servers/add_server_icon.jsx:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import ModalContainer from '../modal/modal_container';
3 |
4 | class AddServerIcon extends React.Component {
5 | constructor(props) {
6 | super(props);
7 | this.handleOpenModal = this.handleOpenModal.bind(this);
8 | }
9 |
10 | handleOpenModal(e) {
11 | this.props.openModal('server-modal');
12 | }
13 |
14 | render() {
15 | return (
16 | <>
17 | +
18 |
19 | >
20 | )
21 | }
22 | }
23 |
24 | export default AddServerIcon;
--------------------------------------------------------------------------------
/frontend/components/discord_servers/server_index.jsx:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import {Link, Switch, Route} from 'react-router-dom';
3 | import { AuthRoute, ProtectedRoute } from '../../util/route_util';
4 | import LandingChannelContainer from '../channel_content/landing_channel_container';
5 | import ChannelIndexContainer from '../channel_content/channel_index_container';
6 | import {withRouter} from 'react-router-dom';
7 | import ServerListItem from './server_list_item';
8 | import AddServerContainer from './add_server_container';
9 |
10 | class serverIndex extends React.Component {
11 | constructor(props) {
12 | super(props);
13 | this.state = {
14 | servers: {}
15 | }
16 | this.handleActivityNav = this.handleActivityNav.bind(this);
17 | }
18 |
19 | //TODO: Sort server list by time UserServer was added?
20 | componentDidMount() {
21 | this.props.fetchAllServers().then(
22 | () => {
23 | this.setState({
24 | servers: this.props.servers
25 | });
26 | }
27 | ).then(
28 | () => {
29 | if (this.props.location.pathname === "/servers") {
30 | let elementPreload;
31 | elementPreload = document.getElementsByClassName('home-icon')[0];
32 | elementPreload.classList.add('nav-in-focus');
33 | }
34 | }
35 | )
36 | }
37 |
38 | //TODO: THIS WORKS LMAO, how do I compare array equality?
39 | componentDidUpdate(prevProps) {
40 | if (Object.keys(prevProps.servers).length !== Object.keys(this.state.servers).length) {
41 | this.setState({
42 | servers: this.props.servers
43 | });
44 | }
45 | }
46 |
47 | handleActivityNav(e) {
48 | let listElement = document.getElementsByClassName('nav-in-focus')[0];
49 | if (listElement) {
50 | listElement.classList.remove('nav-in-focus');
51 | }
52 | e.currentTarget.classList.add('nav-in-focus');
53 | this.props.history.push('/servers');
54 | }
55 |
56 | render() {
57 | let serverIds = Object.keys(this.state.servers);
58 | return (
59 |
60 |
61 | {/* */}
62 |
63 | {/*
*/}
64 |
65 |
66 | {/* */}
67 |
68 |
69 | {serverIds.map((id) => (
70 |
71 | ))}
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 | )
82 | }
83 | }
84 |
85 | export default withRouter(serverIndex);
--------------------------------------------------------------------------------
/frontend/components/discord_servers/server_index_container.jsx:
--------------------------------------------------------------------------------
1 | import { logout } from "../../actions/session_actions";
2 | import { connect } from "react-redux";
3 | import serverIndex from "./server_index";
4 | import { fetchAllServers, fetchServer, createServer, deleteServer } from "../../actions/server_actions";
5 |
6 | const mapStateToProps = (state) => {
7 | return {
8 | servers: state.entities.servers
9 | }
10 | };
11 |
12 | const mapDispatchToProps = (dispatch) => ({
13 | logout: () => dispatch(logout()),
14 | fetchAllServers: () => dispatch(fetchAllServers()),
15 | fetchServer: (id) => dispatch(fetchServer(id)),
16 | createServer: (newServer) => dispatch(createServer(newServer)),
17 | deleteServer: (id) => dispatch(deleteServer(id))
18 | });
19 |
20 | export default connect(
21 | mapStateToProps,
22 | mapDispatchToProps
23 | )(serverIndex);
--------------------------------------------------------------------------------
/frontend/components/discord_servers/server_list_item.jsx:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import {withRouter} from 'react-router-dom';
3 |
4 | class ServerListItem extends React.Component {
5 | constructor(props) {
6 | super(props);
7 | this.handleServerNavigation = this.handleServerNavigation.bind(this);
8 | }
9 |
10 | // TODO: Change document.title to channel name later
11 | // TODO: User componentDidUpdate to account for url navigation
12 | // TODO: Match params id doesn't work because this is associated with /servers
13 | // and not /servers/:id, need to use channelindex to check.
14 | handleServerNavigation(e) {
15 | this.props.history.push(`/servers/${this.props.server.id}`);
16 | let listElement = document.getElementsByClassName('nav-in-focus')[0];
17 | if (listElement) {
18 | listElement.classList.remove('nav-in-focus');
19 | }
20 | e.currentTarget.classList.add('nav-in-focus');
21 | }
22 |
23 | render() {
24 | return (
25 |
26 | {this.props.server.name[0]}
27 |
28 | )}
29 | }
30 |
31 | export default withRouter(ServerListItem);
--------------------------------------------------------------------------------
/frontend/components/landing_page/landing_page.jsx:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import {Link} from 'react-router-dom';
3 |
4 | const landingPage = () => (
5 | <>
6 |
7 |
8 |
9 |
10 |
11 | Discourse
12 |
13 |
14 | {/* Download
15 | Nitro
16 | Jobs
17 | Developers
18 | Community
19 | Support */}
20 |
21 |
22 | {/*
23 |
24 | */}
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 | Login
37 |
38 | {/* Language */}
39 |
40 |
41 |
42 |
43 | It's time to ditch Scype and Teamspoke.
44 | Nothing-in-one voice and text chat for gamers that's free, insecure, and works
45 | (mostly). Stop paying for TeamSpoke servers and hassling with Scype. Complicate your
46 | life with Discourse.
47 |
55 |
56 |
57 |
60 |
61 |
62 |
63 |
64 |
67 |
71 |
78 |
84 | {/*
90 | */}
98 |
99 |
100 |
101 |
110 |
111 | >
112 | )
113 |
114 | export default landingPage;
--------------------------------------------------------------------------------
/frontend/components/modal/invite_link_modal.jsx:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import {withRouter} from 'react-router-dom';
3 |
4 | class InviteLinkDisplayModal extends React.Component {
5 | constructor(props) {
6 | super(props);
7 | }
8 |
9 | handleCopy(e) {
10 | let text = document.getElementsByClassName('invite-text')[0];
11 | text.select();
12 | document.execCommand("copy");
13 | }
14 |
15 | render() {
16 | return (
17 | e.stopPropagation()}>
18 |
19 |
Invite friends to {this.props.currentServer.name}
20 |
Send a server invite link to a friend
21 |
22 | e.preventDefault()}
28 | />
29 | Copy
30 |
31 |
32 |
33 | )
34 | }
35 | }
36 |
37 | export default withRouter(InviteLinkDisplayModal);
--------------------------------------------------------------------------------
/frontend/components/modal/invite_link_modal_container.jsx:
--------------------------------------------------------------------------------
1 | import { connect } from 'react-redux';
2 | import { closeModal } from '../../actions/modal_actions';
3 | import InviteLinkDisplayModal from './invite_link_modal';
4 | import {withRouter} from 'react-router-dom';
5 |
6 | const mapStateToProps = (state, ownProps) => {
7 | return {
8 | servers: state.entities.servers
9 | }
10 | }
11 |
12 | const mapDispatchToProps = (dispatch) => {
13 | return {
14 | closeModal: () => dispatch(closeModal())
15 | }
16 | };
17 |
18 | export default withRouter(
19 | connect(
20 | null,
21 | mapDispatchToProps
22 | )(InviteLinkDisplayModal)
23 | );
--------------------------------------------------------------------------------
/frontend/components/modal/modal.jsx:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import ServerModalContainer from './server_modal_container';
3 | import InviteLinkModalContainer from './invite_link_modal_container';
4 | import {withRouter} from 'react-router-dom';
5 | import RemoveServerModalContainer from './remove_server_modal_container';
6 |
7 | class Modal extends React.Component {
8 | constructor(props) {
9 | super(props);
10 | }
11 |
12 | render() {
13 | if (!this.props.modal) {
14 | return null;
15 | }
16 | let component;
17 | switch (this.props.modal.modal) {
18 | case 'server-modal':
19 | component = ;
20 | break;
21 | case 'invite-link-display':
22 | // TODO: do i need to check if it exists?
23 | if (this.props.modal.id) {
24 | let server = this.props.servers[this.props.modal.id];
25 | component = ;
26 | break;
27 | } else {
28 | break;
29 | }
30 | case 'delete-server-modal':
31 | if (this.props.modal.id) {
32 | let server = this.props.servers[this.props.modal.id];
33 | component = ;
34 | break;
35 | } else {
36 | break;
37 | }
38 | case 'leave-server-modal':
39 | //TODO: UserServer modal stuff
40 | if (this.props.modal.id) {
41 | let server = this.props.servers[this.props.modal.id];
42 | component = ;
43 | break;
44 | } else {
45 | break;
46 | }
47 | default:
48 | return null;
49 | }
50 |
51 | return (
52 |
53 | {component}
54 |
55 | )
56 | }
57 | }
58 |
59 | export default withRouter(Modal);
--------------------------------------------------------------------------------
/frontend/components/modal/modal_container.jsx:
--------------------------------------------------------------------------------
1 | import {connect} from 'react-redux';
2 | import { closeModal } from '../../actions/modal_actions';
3 | import Modal from './modal';
4 | import { fetchServer } from '../../actions/server_actions';
5 |
6 | const mapStateToProps = (state) => {
7 | return {
8 | modal: state.ui.modal,
9 | servers: state.entities.servers
10 | };
11 | };
12 |
13 | const mapDispatchToProps = (dispatch) => {
14 | return {
15 | closeModal: () => dispatch(closeModal())
16 | }
17 | }
18 |
19 | export default connect(
20 | mapStateToProps,
21 | mapDispatchToProps
22 | )(Modal)
--------------------------------------------------------------------------------
/frontend/components/modal/remove_server_modal.jsx:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import { withRouter } from 'react-router-dom';
3 |
4 | class RemoveServerModal extends React.Component {
5 | constructor(props) {
6 | super(props);
7 | this.handleRemoveServer = this.handleRemoveServer.bind(this);
8 | }
9 |
10 | handleRemoveServer(e) {
11 | if (e.currentTarget.innerHTML.split(" ")[0] === 'Delete') {
12 | this.props.deleteServer(this.props.currentServer.id)
13 | .then(
14 | () => {
15 | this.props.closeModal();
16 | this.props.history.push('/servers');
17 | }
18 | )
19 | } else {
20 | this.props.leaveServer(this.props.currentServer.id)
21 | .then(
22 | () => {
23 | this.props.closeModal();
24 | this.props.history.push('/servers');
25 | }
26 | )
27 | }
28 | let elementPreload;
29 | elementPreload = document.getElementsByClassName('home-icon')[0];
30 | elementPreload.classList.add('nav-in-focus');
31 | }
32 |
33 | render() {
34 | if (!this.props.currentServer) {
35 | return null;
36 | }
37 | return (
38 | e.stopPropagation()}>
39 |
40 |
{this.props.type.toUpperCase()} "{this.props.currentServer.name}"
41 |
42 | Are you sure you want to {this.props.type.toLowerCase()} "
43 | {this.props.currentServer.name}"? This action cannot be undone.
44 |
45 |
51 |
52 |
53 | )
54 | }
55 | }
56 |
57 | export default withRouter(RemoveServerModal);
--------------------------------------------------------------------------------
/frontend/components/modal/remove_server_modal_container.jsx:
--------------------------------------------------------------------------------
1 | import { connect } from 'react-redux';
2 | import { closeModal } from '../../actions/modal_actions';
3 | import RemoveServerModal from './remove_server_modal';
4 | import { deleteServer, leaveServer } from '../../actions/server_actions';
5 |
6 | const mapStateToProps = (state, ownProps) => {
7 | return {
8 | servers: state.entities.servers
9 | }
10 | }
11 |
12 | const mapDispatchToProps = (dispatch) => {
13 | return {
14 | closeModal: () => dispatch(closeModal()),
15 | deleteServer: (id) => dispatch(deleteServer(id)),
16 | leaveServer: (id) => dispatch(leaveServer(id))
17 | }
18 | };
19 |
20 | export default connect(
21 | null,
22 | mapDispatchToProps
23 | )(RemoveServerModal)
--------------------------------------------------------------------------------
/frontend/components/modal/server_modal.jsx:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import {withRouter} from 'react-router-dom';
3 |
4 | class ServerModal extends React.Component {
5 | constructor(props) {
6 | super(props);
7 | this.state = {
8 | active: 'initial',
9 | data: {
10 | server: {
11 | name: ''
12 | }
13 | },
14 | link: ''
15 | };
16 | this.handleBack = this.handleBack.bind(this);
17 | this.handleNavigation = this.handleNavigation.bind(this);
18 | this.index = this.index.bind(this);
19 | this.create = this.create.bind(this);
20 | this.update = this.update.bind(this);
21 | this.handleSubmit = this.handleSubmit.bind(this);
22 | this.handleJoinSubmit = this.handleJoinSubmit.bind(this);
23 | this.afterSubmitActions = this.afterSubmitActions.bind(this);
24 | this.removeErrorsOnNavigate = this.removeErrorsOnNavigate.bind(this);
25 | }
26 |
27 | nodeGetter(className, animationName) {
28 | let serverModalNode = document.getElementsByClassName(className)[0];
29 | serverModalNode.classList.add(animationName);
30 | window.setTimeout(() => {
31 | serverModalNode.classList.remove(animationName);
32 | }, 200);
33 | }
34 |
35 | componentDidMount() {
36 | this.nodeGetter('modal-form-index', 'zoomIn');
37 | }
38 |
39 | removeErrorsOnNavigate() {
40 | this.props.deleteServerErrors();
41 | }
42 |
43 | handleBack(e) {
44 | this.nodeGetter(`modal-form-${this.state.active}`, 'slideOutRight');
45 | this.setState({ active: 'index' });
46 | this.removeErrorsOnNavigate();
47 | }
48 |
49 | handleNavigation(e) {
50 | let nextModal = e.currentTarget.innerText.split(" ")[0].toLowerCase();
51 | this.setState({active: nextModal});
52 | }
53 |
54 | update(property) {
55 | if (property === 'name') {
56 | return (
57 | (e) => {
58 | this.setState({
59 | data: {
60 | server: {
61 | [property]: e.currentTarget.value
62 | }
63 | }
64 | });
65 | }
66 | )
67 | } else {
68 | return (
69 | (e) => {
70 | this.setState({
71 | link: e.currentTarget.value
72 | })
73 | }
74 | )
75 | }
76 | };
77 |
78 | handleSubmit(e) {
79 | e.preventDefault();
80 | this.removeErrorsOnNavigate();
81 | this.props.createServer(this.state.data)
82 | .then(
83 | (res) => {
84 | this.afterSubmitActions(res);
85 | }
86 | );
87 | }
88 |
89 | handleJoinSubmit(e) {
90 | e.preventDefault();
91 | this.removeErrorsOnNavigate();
92 | this.props.joinServer(this.state.link)
93 | .then(
94 | (res) => {
95 | this.afterSubmitActions(res);
96 | }
97 | );
98 | }
99 |
100 | //TODO: SOMETIMES NEED TO LEAVE SERVER TWICE
101 |
102 | afterSubmitActions(res) {
103 | this.props.closeModal();
104 | this.props.history.push(`/servers/${res.server.id}`);
105 | let listElement = document.getElementsByClassName('nav-in-focus')[0];
106 | if (listElement) {
107 | listElement.classList.remove('nav-in-focus');
108 | }
109 | let newElement = document.getElementsByClassName(res.server.id)[0];
110 | newElement.classList.add('nav-in-focus');
111 | }
112 |
113 | index() {
114 | let initialTest = this.state.active;
115 | let landingClass = "modal-form-landing" + (initialTest === 'initial' ? '' : ' slideInLeft');
116 | return (
117 |
118 |
Oh, another server huh?
119 |
120 |
121 |
Create
122 |
Create a new server and invite your friends, it's free!
123 |
Create a server
124 |
125 |
or
126 |
127 |
Join
128 |
Enter an instant invite and join your friend's server
129 |
Join a server
130 |
131 |
132 |
133 | )
134 | }
135 |
136 | create() {
137 | return (
138 |
139 |
Create your server
140 |
By creating a server, you will have access to free voice and text
141 | (coming soon, not guaranteed) chat to use amongst your friends.
142 |
143 |
144 |
145 | {this.props.errors.map((err, idx) => (
146 |
{err}
147 | ))}
148 |
149 |
150 |
151 |
152 | Server Name
153 |
154 |
155 |
156 |
157 |
158 |
159 |
160 | Back
161 |
162 |
Create
163 |
164 |
165 |
166 | )
167 | }
168 |
169 | join() {
170 | return (
171 |
172 |
Join a server
173 |
Enter an instant invite below to join an existing server. The invite
174 | will look something like this:
175 |
176 |
discourse_invite/2o03IhUt26=ZDZVZ1fEcjA
177 |
178 |
179 |
180 | {this.props.errors.map((err, idx) => (
181 |
{err}
182 | ))}
183 |
184 |
185 |
186 |
187 |
188 |
189 | Back
190 |
191 |
Join
192 |
193 |
194 |
195 | )
196 | }
197 |
198 | render() {
199 | let component;
200 | switch (this.state.active) {
201 | case ('create'):
202 | component = this.create();
203 | break;
204 | case ('join'):
205 | component = this.join();
206 | break;
207 | default:
208 | component = this.index();
209 | break;
210 | }
211 | return (
212 | e.stopPropagation()}>
213 |
214 | {component}
215 |
216 |
217 | )
218 | }
219 | }
220 |
221 | export default withRouter(ServerModal);
--------------------------------------------------------------------------------
/frontend/components/modal/server_modal_container.jsx:
--------------------------------------------------------------------------------
1 | import { connect } from 'react-redux';
2 | import ServerModal from './server_modal';
3 | import { createServer, joinServer, deleteServerErrors } from '../../actions/server_actions';
4 | import { closeModal } from '../../actions/modal_actions';
5 |
6 | const mapStateToProps = ({errors}) => ({
7 | errors: errors.servers
8 | })
9 |
10 | const mapDispatchToProps = (dispatch) => {
11 | return {
12 | createServer: (newServer) => dispatch(createServer(newServer)),
13 | joinServer: (link) => dispatch(joinServer(link)),
14 | closeModal: () => dispatch(closeModal()),
15 | deleteServerErrors: () => dispatch(deleteServerErrors())
16 | }
17 | };
18 |
19 | export default connect(
20 | mapStateToProps,
21 | mapDispatchToProps
22 | )(ServerModal);
--------------------------------------------------------------------------------
/frontend/components/root.jsx:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import {Provider} from 'react-redux';
3 | import {HashRouter} from 'react-router-dom';
4 | import App from './app';
5 |
6 | const Root = ({store}) => (
7 |
8 |
9 |
10 |
11 |
12 | );
13 |
14 | export default Root;
--------------------------------------------------------------------------------
/frontend/components/session_form/login_form_container.jsx:
--------------------------------------------------------------------------------
1 | import {connect} from 'react-redux';
2 | import {login, deleteErrors} from '../../actions/session_actions';
3 | import sessionForm from './session_form';
4 |
5 | const mapStateToProps = ({errors}) => ({
6 | formType: 'login',
7 | errors: errors.session
8 | });
9 |
10 | // Could refactor this somehow
11 | const mapDispatchToProps = (dispatch) => ({
12 | processForm: (user) => dispatch(login(user)),
13 | demoLogin: (user) => dispatch(login(user)),
14 | deleteErrors: () => dispatch(deleteErrors())
15 | });
16 |
17 | export default connect(
18 | mapStateToProps,
19 | mapDispatchToProps
20 | )(sessionForm);
--------------------------------------------------------------------------------
/frontend/components/session_form/session_form.jsx:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import merge from 'lodash/merge';
3 | import {Link} from 'react-router-dom';
4 |
5 | class SessionForm extends React.Component {
6 | constructor(props) {
7 | super(props);
8 | this.state = {
9 | username: "",
10 | email: "",
11 | password: ""
12 | };
13 | this.handleSubmit = this.handleSubmit.bind(this);
14 | this.handleDemoLogin = this.handleDemoLogin.bind(this);
15 | this.parseErrors = this.parseErrors.bind(this);
16 | }
17 |
18 | handleSubmit(e) {
19 | e.preventDefault();
20 | const user = merge({}, this.state);
21 | this.props.processForm(user)
22 | .then(() => {
23 | if (this.props.match.path.url === '/servers') {
24 | return this.props.history.push('/servers');
25 | }
26 | });
27 | }
28 |
29 | componentWillUnmount() {
30 | this.props.deleteErrors();
31 | }
32 |
33 | componentDidUpdate() {
34 | this.renderErrors();
35 | }
36 |
37 | componentDidMount() {
38 | document.title = 'Discourse - A Discord clone';
39 | }
40 |
41 | update(field) {
42 | return (e) => (this.setState({[field]: e.currentTarget.value}));
43 | }
44 |
45 | handleDemoLogin() {
46 | const demoUser = {
47 | username: 'demo_user',
48 | password: 'password'
49 | };
50 | this.props.demoLogin(demoUser)
51 | .then(() => {
52 | if (this.props.match.path.url === '/servers') {
53 | return this.props.history.push('/servers');
54 | }
55 | });
56 | }
57 |
58 | renderErrors() {
59 | if (this.props.errors.length > 0) {
60 | let errorsParse;
61 | const form = document.querySelector('form');
62 | if (!form.className.includes('error-form')) {
63 | form.className += ' error-form';
64 | };
65 | errorsParse = this.parseErrors();
66 | Object.keys(errorsParse).forEach((key) => {
67 | if (errorsParse[key].length > 0) {
68 | let textContainer = document.createElement('h5');
69 | let errorText = `- ${errorsParse[key]}`;
70 | if (key === 'login') {
71 | key = 'username';
72 | }
73 | textContainer.appendChild(document.createTextNode(errorText));
74 | let labelContainer = document.getElementById(`${key}-label`);
75 | if (labelContainer.childNodes && labelContainer.childNodes.length > 1) {
76 | labelContainer.replaceChild(textContainer, labelContainer.childNodes[1])
77 | } else {
78 | labelContainer.appendChild(textContainer);
79 | }
80 | }
81 | })
82 | }
83 | }
84 |
85 | parseErrors() {
86 | let errorObj = {
87 | email: '',
88 | username: '',
89 | password: '',
90 | login: ''
91 | };
92 |
93 | this.props.errors.forEach((err) => {
94 | let errDisp = err;
95 | err = err.toLowerCase();
96 | if (err.includes('email')) {
97 | errorObj.email = errDisp;
98 | } else if (err.includes('username')) {
99 | errorObj.username = errDisp;
100 | } else if (err.includes('password')) {
101 | errorObj.password = errDisp;
102 | } else {
103 | errorObj.login = errDisp;
104 | }
105 | });
106 |
107 | return errorObj;
108 | }
109 |
110 | render() {
111 | // TODO: asdjlkj
112 | // Probably needs refactoring somehow
113 | // Maybe put in props?
114 | let otherFormLink;
115 | let formHeader;
116 | let emailForm;
117 | let forgotPassword;
118 | switch (this.props.formType) {
119 | case 'login':
120 | otherFormLink =
121 |
122 |
Need an account?
123 |
Register
124 |
or
125 |
Demo Login
126 |
;
127 | formHeader =
128 | <>
129 | Welcome back!
130 | We're so excited to see you again!
131 | >;
132 | forgotPassword =
133 |
134 | Forgot your password? (too bad)
135 |
;
136 | break;
137 | case 'signup':
138 | otherFormLink = 'login';
139 | formHeader =
140 | Create an account ;
141 | emailForm =
142 |
143 |
144 | Email
145 |
146 |
150 |
151 | ;
152 | otherFormLink =
153 |
154 |
Already have an account?
155 |
Login
156 |
or
157 |
Demo Login
158 |
;
159 | break;
160 | default:
161 | formHeader =
162 |
163 | How did you end up here?!
164 | ;
165 | otherFormLink =
166 |
167 |
Get me out!
168 |
*Flies away*
169 |
;
170 | // How do you even get here lol
171 | break;
172 | }
173 |
174 | return (
175 |
176 |
177 |
178 |
179 |
180 |
181 | Discourse
182 |
183 |
184 |
185 |
186 | {formHeader}
187 | {emailForm}
188 |
189 |
190 | Username
191 |
192 |
195 |
196 |
197 |
198 |
199 | Password
200 |
201 |
205 |
206 |
207 | {forgotPassword}
208 | {this.props.formType}
209 | {otherFormLink}
210 |
211 |
212 |
213 | )
214 |
215 | }
216 | }
217 |
218 | export default SessionForm;
--------------------------------------------------------------------------------
/frontend/components/session_form/signup_form_container.jsx:
--------------------------------------------------------------------------------
1 | import { connect } from 'react-redux';
2 | import { signup, login, deleteErrors } from '../../actions/session_actions';
3 | import sessionForm from './session_form';
4 |
5 | const mapStateToProps = ({errors}) => ({
6 | formType: 'signup',
7 | errors: errors.session
8 | });
9 |
10 | // Could refactor this somehow
11 | const mapDispatchToProps = (dispatch) => ({
12 | processForm: (user) => dispatch(signup(user)),
13 | demoLogin: (user) => dispatch(login(user)),
14 | deleteErrors: () => dispatch(deleteErrors())
15 | });
16 |
17 | export default connect(
18 | mapStateToProps,
19 | mapDispatchToProps
20 | )(sessionForm);
--------------------------------------------------------------------------------
/frontend/index.jsx:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import ReactDOM from 'react-dom';
3 | import Root from './components/root';
4 | import configureStore from './store/store';
5 |
6 | document.addEventListener('DOMContentLoaded', () => {
7 | let store;
8 | if (window.currentUser) {
9 | const preloadedState = {
10 | // TODO: Add server slice of state
11 | entities: {
12 | users: { [window.currentUser.id]: window.currentUser }
13 | },
14 | session: { id: window.currentUser.id }
15 | };
16 | store = configureStore(preloadedState);
17 | delete window.currentUser;
18 | } else {
19 | store = configureStore();
20 | }
21 | const root = document.getElementById('root');
22 | ReactDOM.render(, root);
23 | });
--------------------------------------------------------------------------------
/frontend/reducers/entities_reducer.js:
--------------------------------------------------------------------------------
1 | import {combineReducers} from 'redux';
2 | import usersReducer from './users_reducer';
3 | import serversReducer from './servers_reducer';
4 | import messagesReducer from './messages_reducer';
5 |
6 | const entitiesReducer = combineReducers({
7 | users: usersReducer,
8 | servers: serversReducer,
9 | messages: messagesReducer
10 | })
11 |
12 | export default entitiesReducer;
--------------------------------------------------------------------------------
/frontend/reducers/errors_reducer.js:
--------------------------------------------------------------------------------
1 | import { combineReducers } from "redux";
2 | import sessionErrorsReducer from "./session_errors_reducer";
3 | import serversErrorsReducer from "./servers_errors_reducer";
4 |
5 | const errorsReducer = combineReducers({
6 | session: sessionErrorsReducer,
7 | servers: serversErrorsReducer
8 | })
9 |
10 | export default errorsReducer;
--------------------------------------------------------------------------------
/frontend/reducers/messages_reducer.js:
--------------------------------------------------------------------------------
1 | import { RECEIVE_CHAT_HISTORY } from '../actions/chat_actions';
2 |
3 | const messagesReducer = (state = {}, action) => {
4 | Object.freeze(state);
5 | switch (action.type) {
6 | case RECEIVE_CHAT_HISTORY:
7 | return action.messages;
8 | default:
9 | return state;
10 | }
11 | }
12 |
13 | export default messagesReducer;
--------------------------------------------------------------------------------
/frontend/reducers/modal_reducer.js:
--------------------------------------------------------------------------------
1 | import { OPEN_MODAL, CLOSE_MODAL } from '../actions/modal_actions';
2 |
3 | const modalReducer = (state = null, action) => {
4 | Object.freeze(state);
5 | switch (action.type) {
6 | case OPEN_MODAL:
7 | return action.modal;
8 | case CLOSE_MODAL:
9 | return null;
10 | default:
11 | return state;
12 | }
13 | }
14 |
15 | export default modalReducer;
--------------------------------------------------------------------------------
/frontend/reducers/root_reducer.js:
--------------------------------------------------------------------------------
1 | import {combineReducers} from 'redux';
2 | import entitiesReducer from './entities_reducer';
3 | import sessionReducer from './session_reducer';
4 | import errorsReducer from './errors_reducer';
5 | import uiReducer from './ui_reducer';
6 |
7 | const rootReducer = combineReducers({
8 | entities: entitiesReducer,
9 | session: sessionReducer,
10 | errors: errorsReducer,
11 | ui: uiReducer
12 | });
13 |
14 | export default rootReducer;
--------------------------------------------------------------------------------
/frontend/reducers/servers_errors_reducer.js:
--------------------------------------------------------------------------------
1 | import { RECEIVE_SERVER_ERRORS, RECEIVE_SERVER } from "../actions/server_actions";
2 |
3 | const serversErrorsReducer = (state = [], action) => {
4 | Object.freeze(state);
5 | switch (action.type) {
6 | case RECEIVE_SERVER_ERRORS:
7 | return action.errors;
8 | case RECEIVE_SERVER:
9 | return [];
10 | default:
11 | return state;
12 | }
13 | }
14 |
15 | export default serversErrorsReducer;
--------------------------------------------------------------------------------
/frontend/reducers/servers_reducer.js:
--------------------------------------------------------------------------------
1 | import merge from 'lodash/merge';
2 | import { RECEIVE_ALL_SERVERS, RECEIVE_SERVER, REMOVE_SERVER, LEAVE_SERVER } from '../actions/server_actions';
3 |
4 | const serversReducer = (state = {}, action) => {
5 | Object.freeze(state);
6 | let newState;
7 | switch (action.type) {
8 | case RECEIVE_ALL_SERVERS:
9 | return action.servers;
10 | case RECEIVE_SERVER:
11 | newState = merge({}, state);
12 | return merge({}, newState, {[action.server.id]: action.server});
13 | case REMOVE_SERVER:
14 | newState = merge({}, state);
15 | delete newState[action.id];
16 | return newState;
17 | case LEAVE_SERVER:
18 | newState = merge({}, state);
19 | delete newState[action.id];
20 | return newState;
21 | default:
22 | return state;
23 | }
24 | }
25 |
26 | export default serversReducer;
--------------------------------------------------------------------------------
/frontend/reducers/session_errors_reducer.js:
--------------------------------------------------------------------------------
1 | import { RECEIVE_SESSION_ERRORS, RECEIVE_CURRENT_USER, REMOVE_ERRORS } from "../actions/session_actions";
2 |
3 | const sessionErrorsReducer = (state = [], action) => {
4 | Object.freeze(state);
5 | switch (action.type) {
6 | case RECEIVE_SESSION_ERRORS:
7 | return action.errors;
8 | case RECEIVE_CURRENT_USER:
9 | return [];
10 | default:
11 | return state;
12 | }
13 | }
14 |
15 | export default sessionErrorsReducer;
--------------------------------------------------------------------------------
/frontend/reducers/session_reducer.js:
--------------------------------------------------------------------------------
1 | import { RECEIVE_CURRENT_USER, LOGOUT_CURRENT_USER } from "../actions/session_actions";
2 |
3 | //Default state
4 | const _nullUser = Object.freeze({
5 | id: null
6 | });
7 |
8 | const sessionReducer = (state = _nullUser, action) => {
9 | Object.freeze(state);
10 | switch (action.type) {
11 | case RECEIVE_CURRENT_USER:
12 | return { id: action.currentUser.id };
13 | case LOGOUT_CURRENT_USER:
14 | return _nullUser;
15 | default:
16 | return state;
17 | }
18 | };
19 |
20 | export default sessionReducer;
--------------------------------------------------------------------------------
/frontend/reducers/ui_reducer.js:
--------------------------------------------------------------------------------
1 | import { combineReducers } from 'redux';
2 | import modalReducer from './modal_reducer';
3 |
4 | //TODO: Implement loading screen if i have time
5 | const uiReducer = combineReducers({
6 | modal: modalReducer
7 | })
8 |
9 | export default uiReducer;
--------------------------------------------------------------------------------
/frontend/reducers/users_reducer.js:
--------------------------------------------------------------------------------
1 | import merge from 'lodash/merge';
2 | import { RECEIVE_CURRENT_USER, LOGOUT_CURRENT_USER } from '../actions/session_actions';
3 |
4 | const usersReducer = (state = {}, action) => {
5 | Object.freeze(state);
6 | switch (action.type) {
7 | case RECEIVE_CURRENT_USER:
8 | return merge({}, state, {[action.currentUser.id]: action.currentUser});
9 | case LOGOUT_CURRENT_USER:
10 | return {id: null};
11 | default:
12 | return state;
13 | }
14 | }
15 |
16 | export default usersReducer;
--------------------------------------------------------------------------------
/frontend/store/store.js:
--------------------------------------------------------------------------------
1 | import { createStore, applyMiddleware } from "redux";
2 | import rootReducer from "../reducers/root_reducer";
3 | import logger from 'redux-logger';
4 | import thunk from 'redux-thunk';
5 |
6 | const configureStore = (preloadedState = {}) => {
7 | let middleware = [thunk];
8 | if (process.env.NODE_ENV !== 'production') {
9 | middleware = [...middleware, logger];
10 | }
11 | return createStore(
12 | rootReducer,
13 | preloadedState,
14 | applyMiddleware(...middleware)
15 | );
16 | };
17 |
18 | export default configureStore
--------------------------------------------------------------------------------
/frontend/util/chat_util.js:
--------------------------------------------------------------------------------
1 | export const getChatHistory = (server_id) => (
2 | $.ajax({
3 | method: 'GET',
4 | url: `/api/servers/${server_id}/messages`
5 | })
6 | )
--------------------------------------------------------------------------------
/frontend/util/route_util.jsx:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import { connect } from 'react-redux';
3 | import { Route, Redirect, withRouter } from 'react-router-dom';
4 |
5 | const Auth = ({ component: Component, path, loggedIn, exact }) => (
6 | (
7 | !loggedIn ? (
8 |
9 | ) : (
10 |
11 | )
12 | )} />
13 | );
14 |
15 | const Protected = ({ component: Component, path, loggedIn, exact }) => (
16 | (
17 | loggedIn ? (
18 |
19 | ) : (
20 |
21 | )
22 | )} />
23 | );
24 |
25 | const mapStateToProps = state => (
26 | { loggedIn: Boolean(state.session.id) }
27 | );
28 |
29 | export const AuthRoute = withRouter(connect(mapStateToProps)(Auth));
30 |
31 | export const ProtectedRoute = withRouter(connect(mapStateToProps)(Protected));
--------------------------------------------------------------------------------
/frontend/util/server_api_util.js:
--------------------------------------------------------------------------------
1 | export const serverIndex = () => (
2 | $.ajax({
3 | method: 'GET',
4 | url: '/api/servers'
5 | })
6 | );
7 |
8 | export const showServer = (id) => (
9 | $.ajax({
10 | method: 'GET',
11 | url: `/api/servers/${id}`
12 | })
13 | );
14 |
15 | export const createServer = (server) => (
16 | $.ajax({
17 | method: 'POST',
18 | url: '/api/servers',
19 | data: server
20 | })
21 | )
22 |
23 | export const deleteServer = (id) => (
24 | $.ajax({
25 | method: 'DELETE',
26 | url: `/api/servers/${id}`
27 | })
28 | )
29 |
30 | export const leaveServer = (serverId) => (
31 | $.ajax({
32 | method: 'DELETE',
33 | url: `/api/user_servers/${serverId}`
34 | })
35 | )
36 |
37 | export const joinServer = (link) => (
38 | $.ajax({
39 | method: 'POST',
40 | url: '/api/user_servers',
41 | data: {
42 | invite_link: link
43 | }
44 | })
45 | )
--------------------------------------------------------------------------------
/frontend/util/session_api_util.js:
--------------------------------------------------------------------------------
1 | export const login = (user) => (
2 | $.ajax({
3 | method: 'POST',
4 | url: '/api/session',
5 | data: { user }
6 | })
7 | );
8 |
9 | export const logout = () => (
10 | $.ajax({
11 | method: 'DELETE',
12 | url: '/api/session'
13 | })
14 | );
15 |
16 | export const signup = (user) => (
17 | $.ajax({
18 | method: 'POST',
19 | url: '/api/user',
20 | data: { user }
21 | })
22 | );
--------------------------------------------------------------------------------
/frontend/util/user_util.js:
--------------------------------------------------------------------------------
1 | export const userIndex = () => (
2 | $.ajax({
3 | method: 'GET',
4 | url: '/api/users'
5 | })
6 | );
--------------------------------------------------------------------------------
/lib/assets/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dowinterfor6/discourse/085d2f02fbbd9f6aa4516b3bd29849ef4c3f305a/lib/assets/.keep
--------------------------------------------------------------------------------
/lib/tasks/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dowinterfor6/discourse/085d2f02fbbd9f6aa4516b3bd29849ef4c3f305a/lib/tasks/.keep
--------------------------------------------------------------------------------
/log/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dowinterfor6/discourse/085d2f02fbbd9f6aa4516b3bd29849ef4c3f305a/log/.keep
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "discourse",
3 | "version": "1.0.0",
4 | "description": "Discourse - A Discord clone!",
5 | "main": "index.js",
6 | "scripts": {
7 | "test": "echo \"Error: no test specified\" && exit 1",
8 | "postinstall": "webpack",
9 | "webpack": "webpack --watch --mode=development"
10 | },
11 | "repository": {
12 | "type": "git",
13 | "url": "git+https://github.com/dowinterfor6/discourse.git"
14 | },
15 | "keywords": [],
16 | "author": "",
17 | "license": "ISC",
18 | "bugs": {
19 | "url": "https://github.com/dowinterfor6/discourse/issues"
20 | },
21 | "homepage": "https://github.com/dowinterfor6/discourse#readme",
22 | "dependencies": {
23 | "@babel/core": "^7.4.4",
24 | "@babel/preset-env": "^7.4.4",
25 | "@babel/preset-react": "^7.0.0",
26 | "babel-loader": "^8.0.5",
27 | "lodash": "^4.17.11",
28 | "moment": "^2.24.0",
29 | "react": "^16.8.6",
30 | "react-dom": "^16.8.6",
31 | "react-redux": "^7.0.3",
32 | "react-router-dom": "^5.0.0",
33 | "redux": "^4.0.1",
34 | "redux-logger": "^3.0.6",
35 | "redux-thunk": "^2.3.0",
36 | "webpack": "^4.30.0",
37 | "webpack-cli": "^3.3.1"
38 | },
39 | "engines": {
40 | "node": "8.10.0",
41 | "npm": "3.10.10"
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/public/404.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | The page you were looking for doesn't exist (404)
5 |
6 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
The page you were looking for doesn't exist.
62 |
You may have mistyped the address or the page may have moved.
63 |
64 |
If you are the application owner check the logs for more information.
65 |
66 |
67 |
68 |
--------------------------------------------------------------------------------
/public/422.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | The change you wanted was rejected (422)
5 |
6 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
The change you wanted was rejected.
62 |
Maybe you tried to change something you didn't have access to.
63 |
64 |
If you are the application owner check the logs for more information.
65 |
66 |
67 |
68 |
--------------------------------------------------------------------------------
/public/500.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | We're sorry, but something went wrong (500)
5 |
6 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
We're sorry, but something went wrong.
62 |
63 |
If you are the application owner check the logs for more information.
64 |
65 |
66 |
67 |
--------------------------------------------------------------------------------
/public/apple-touch-icon-precomposed.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dowinterfor6/discourse/085d2f02fbbd9f6aa4516b3bd29849ef4c3f305a/public/apple-touch-icon-precomposed.png
--------------------------------------------------------------------------------
/public/apple-touch-icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dowinterfor6/discourse/085d2f02fbbd9f6aa4516b3bd29849ef4c3f305a/public/apple-touch-icon.png
--------------------------------------------------------------------------------
/public/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dowinterfor6/discourse/085d2f02fbbd9f6aa4516b3bd29849ef4c3f305a/public/favicon.ico
--------------------------------------------------------------------------------
/public/robots.txt:
--------------------------------------------------------------------------------
1 | # See http://www.robotstxt.org/robotstxt.html for documentation on how to use the robots.txt file
2 |
--------------------------------------------------------------------------------
/storage/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dowinterfor6/discourse/085d2f02fbbd9f6aa4516b3bd29849ef4c3f305a/storage/.keep
--------------------------------------------------------------------------------
/test/application_system_test_case.rb:
--------------------------------------------------------------------------------
1 | require "test_helper"
2 |
3 | class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
4 | driven_by :selenium, using: :chrome, screen_size: [1400, 1400]
5 | end
6 |
--------------------------------------------------------------------------------
/test/controllers/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dowinterfor6/discourse/085d2f02fbbd9f6aa4516b3bd29849ef4c3f305a/test/controllers/.keep
--------------------------------------------------------------------------------
/test/controllers/api/servers_controller_test.rb:
--------------------------------------------------------------------------------
1 | require 'test_helper'
2 |
3 | class Api::ServersControllerTest < ActionDispatch::IntegrationTest
4 | test "should get show" do
5 | get api_servers_show_url
6 | assert_response :success
7 | end
8 |
9 | end
10 |
--------------------------------------------------------------------------------
/test/controllers/api/sessions_controller_test.rb:
--------------------------------------------------------------------------------
1 | require 'test_helper'
2 |
3 | class Api::SessionsControllerTest < ActionDispatch::IntegrationTest
4 | test "should get create" do
5 | get api_sessions_create_url
6 | assert_response :success
7 | end
8 |
9 | test "should get destroy" do
10 | get api_sessions_destroy_url
11 | assert_response :success
12 | end
13 |
14 | end
15 |
--------------------------------------------------------------------------------
/test/controllers/api/user_servers_controller_test.rb:
--------------------------------------------------------------------------------
1 | require 'test_helper'
2 |
3 | class Api::UserServersControllerTest < ActionDispatch::IntegrationTest
4 | # test "the truth" do
5 | # assert true
6 | # end
7 | end
8 |
--------------------------------------------------------------------------------
/test/controllers/api/users_controller_test.rb:
--------------------------------------------------------------------------------
1 | require 'test_helper'
2 |
3 | class Api::UsersControllerTest < ActionDispatch::IntegrationTest
4 | test "should get create" do
5 | get api_users_create_url
6 | assert_response :success
7 | end
8 |
9 | end
10 |
--------------------------------------------------------------------------------
/test/controllers/messages_controller_test.rb:
--------------------------------------------------------------------------------
1 | require 'test_helper'
2 |
3 | class MessagesControllerTest < ActionDispatch::IntegrationTest
4 | # test "the truth" do
5 | # assert true
6 | # end
7 | end
8 |
--------------------------------------------------------------------------------
/test/controllers/static_pages_controller_test.rb:
--------------------------------------------------------------------------------
1 | require 'test_helper'
2 |
3 | class StaticPagesControllerTest < ActionDispatch::IntegrationTest
4 | test "should get root" do
5 | get static_pages_root_url
6 | assert_response :success
7 | end
8 |
9 | end
10 |
--------------------------------------------------------------------------------
/test/fixtures/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dowinterfor6/discourse/085d2f02fbbd9f6aa4516b3bd29849ef4c3f305a/test/fixtures/.keep
--------------------------------------------------------------------------------
/test/fixtures/files/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dowinterfor6/discourse/085d2f02fbbd9f6aa4516b3bd29849ef4c3f305a/test/fixtures/files/.keep
--------------------------------------------------------------------------------
/test/fixtures/messages.yml:
--------------------------------------------------------------------------------
1 | # == Schema Information
2 | #
3 | # Table name: messages
4 | #
5 | # id :bigint not null, primary key
6 | # body :string not null
7 | # created_at :datetime not null
8 | # updated_at :datetime not null
9 | # sender :string not null
10 | # custom_timestamp :string not null
11 | # channel_id :integer not null
12 | #
13 |
14 | # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
15 |
16 | one:
17 | body: MyString
18 |
19 | two:
20 | body: MyString
21 |
--------------------------------------------------------------------------------
/test/fixtures/servers.yml:
--------------------------------------------------------------------------------
1 | # == Schema Information
2 | #
3 | # Table name: servers
4 | #
5 | # id :bigint not null, primary key
6 | # name :string not null
7 | # owner_id :integer not null
8 | # created_at :datetime not null
9 | # updated_at :datetime not null
10 | # invite_link :string not null
11 | #
12 |
13 | # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
14 |
15 | one:
16 | name: MyString
17 | owner_id: MyString
18 | integer: MyString
19 |
20 | two:
21 | name: MyString
22 | owner_id: MyString
23 | integer: MyString
24 |
--------------------------------------------------------------------------------
/test/fixtures/user_servers.yml:
--------------------------------------------------------------------------------
1 | # == Schema Information
2 | #
3 | # Table name: user_servers
4 | #
5 | # id :bigint not null, primary key
6 | # user_id :integer not null
7 | # server_id :integer not null
8 | # created_at :datetime not null
9 | # updated_at :datetime not null
10 | #
11 |
12 | # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
13 |
14 | # This model initially had no columns defined. If you add columns to the
15 | # model remove the '{}' from the fixture names and add the columns immediately
16 | # below each fixture, per the syntax in the comments below
17 | #
18 | one: {}
19 | # column: value
20 | #
21 | two: {}
22 | # column: value
23 |
--------------------------------------------------------------------------------
/test/fixtures/users.yml:
--------------------------------------------------------------------------------
1 | # == Schema Information
2 | #
3 | # Table name: users
4 | #
5 | # id :bigint not null, primary key
6 | # username :string not null
7 | # email :string not null
8 | # password_digest :string not null
9 | # session_token :string not null
10 | # created_at :datetime not null
11 | # updated_at :datetime not null
12 | #
13 |
14 | # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
15 |
16 | one:
17 | username: MyString
18 | email: MyString
19 | password_digest: MyString
20 |
21 | two:
22 | username: MyString
23 | email: MyString
24 | password_digest: MyString
25 |
--------------------------------------------------------------------------------
/test/helpers/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dowinterfor6/discourse/085d2f02fbbd9f6aa4516b3bd29849ef4c3f305a/test/helpers/.keep
--------------------------------------------------------------------------------
/test/integration/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dowinterfor6/discourse/085d2f02fbbd9f6aa4516b3bd29849ef4c3f305a/test/integration/.keep
--------------------------------------------------------------------------------
/test/mailers/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dowinterfor6/discourse/085d2f02fbbd9f6aa4516b3bd29849ef4c3f305a/test/mailers/.keep
--------------------------------------------------------------------------------
/test/models/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dowinterfor6/discourse/085d2f02fbbd9f6aa4516b3bd29849ef4c3f305a/test/models/.keep
--------------------------------------------------------------------------------
/test/models/message_test.rb:
--------------------------------------------------------------------------------
1 | # == Schema Information
2 | #
3 | # Table name: messages
4 | #
5 | # id :bigint not null, primary key
6 | # body :string not null
7 | # created_at :datetime not null
8 | # updated_at :datetime not null
9 | # sender :string not null
10 | # custom_timestamp :string not null
11 | # channel_id :integer not null
12 | #
13 |
14 | require 'test_helper'
15 |
16 | class MessageTest < ActiveSupport::TestCase
17 | # test "the truth" do
18 | # assert true
19 | # end
20 | end
21 |
--------------------------------------------------------------------------------
/test/models/server_test.rb:
--------------------------------------------------------------------------------
1 | # == Schema Information
2 | #
3 | # Table name: servers
4 | #
5 | # id :bigint not null, primary key
6 | # name :string not null
7 | # owner_id :integer not null
8 | # created_at :datetime not null
9 | # updated_at :datetime not null
10 | # invite_link :string not null
11 | #
12 |
13 | require 'test_helper'
14 |
15 | class ServerTest < ActiveSupport::TestCase
16 | # test "the truth" do
17 | # assert true
18 | # end
19 | end
20 |
--------------------------------------------------------------------------------
/test/models/user_server_test.rb:
--------------------------------------------------------------------------------
1 | # == Schema Information
2 | #
3 | # Table name: user_servers
4 | #
5 | # id :bigint not null, primary key
6 | # user_id :integer not null
7 | # server_id :integer not null
8 | # created_at :datetime not null
9 | # updated_at :datetime not null
10 | #
11 |
12 | require 'test_helper'
13 |
14 | class UserServerTest < ActiveSupport::TestCase
15 | # test "the truth" do
16 | # assert true
17 | # end
18 | end
19 |
--------------------------------------------------------------------------------
/test/models/user_test.rb:
--------------------------------------------------------------------------------
1 | # == Schema Information
2 | #
3 | # Table name: users
4 | #
5 | # id :bigint not null, primary key
6 | # username :string not null
7 | # email :string not null
8 | # password_digest :string not null
9 | # session_token :string not null
10 | # created_at :datetime not null
11 | # updated_at :datetime not null
12 | #
13 |
14 | require 'test_helper'
15 |
16 | class UserTest < ActiveSupport::TestCase
17 | # test "the truth" do
18 | # assert true
19 | # end
20 | end
21 |
--------------------------------------------------------------------------------
/test/system/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dowinterfor6/discourse/085d2f02fbbd9f6aa4516b3bd29849ef4c3f305a/test/system/.keep
--------------------------------------------------------------------------------
/test/test_helper.rb:
--------------------------------------------------------------------------------
1 | ENV['RAILS_ENV'] ||= 'test'
2 | require_relative '../config/environment'
3 | require 'rails/test_help'
4 |
5 | class ActiveSupport::TestCase
6 | # Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order.
7 | fixtures :all
8 |
9 | # Add more helper methods to be used by all tests here...
10 | end
11 |
--------------------------------------------------------------------------------
/tmp/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dowinterfor6/discourse/085d2f02fbbd9f6aa4516b3bd29849ef4c3f305a/tmp/.keep
--------------------------------------------------------------------------------
/vendor/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dowinterfor6/discourse/085d2f02fbbd9f6aa4516b3bd29849ef4c3f305a/vendor/.keep
--------------------------------------------------------------------------------
/webpack.config.jsx:
--------------------------------------------------------------------------------
1 | const path = require('path');
2 |
3 | module.exports = {
4 | context: __dirname,
5 | entry: './frontend/index.jsx',
6 | output: {
7 | path: path.resolve(__dirname, 'app', 'assets', 'javascripts'),
8 | filename: 'bundle.js'
9 | },
10 | module: {
11 | rules: [
12 | {
13 | test: /\.jsx?$/,
14 | exclude: /(node_modules)/,
15 | use: {
16 | loader: 'babel-loader',
17 | query: {
18 | presets: ['@babel/env', '@babel/react']
19 | }
20 | },
21 | }
22 | ]
23 | },
24 | devtool: 'inline-source-map',
25 | resolve: {
26 | extensions: [".js", ".jsx", "*"]
27 | }
28 | };
--------------------------------------------------------------------------------