Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
インターネット蟹工船
mastodon
Commits
ef879a88
Commit
ef879a88
authored
Apr 15, 2017
by
Joachim Viide
Committed by
Eugen
Apr 15, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Send initial state in a <script type="application/json"> tag (#1806)
parent
9240ca6c
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
25 additions
and
17 deletions
+25
-17
app/assets/javascripts/components/containers/mastodon.jsx
app/assets/javascripts/components/containers/mastodon.jsx
+4
-3
app/assets/javascripts/components/features/community_timeline/index.jsx
...ascripts/components/features/community_timeline/index.jsx
+4
-2
app/assets/javascripts/components/features/hashtag_timeline/index.jsx
...avascripts/components/features/hashtag_timeline/index.jsx
+4
-2
app/assets/javascripts/components/features/public_timeline/index.jsx
...javascripts/components/features/public_timeline/index.jsx
+4
-2
app/assets/javascripts/components/reducers/meta.jsx
app/assets/javascripts/components/reducers/meta.jsx
+1
-0
app/assets/javascripts/components/stream.jsx
app/assets/javascripts/components/stream.jsx
+2
-2
app/controllers/home_controller.rb
app/controllers/home_controller.rb
+4
-3
app/views/home/index.html.haml
app/views/home/index.html.haml
+1
-3
app/views/home/initial_state.json.rabl
app/views/home/initial_state.json.rabl
+1
-0
No files found.
app/assets/javascripts/components/containers/mastodon.jsx
View file @
ef879a88
...
...
@@ -61,8 +61,8 @@ import { hydrateStore } from '../actions/store';
import
createStream
from
'
../stream
'
;
const
store
=
configureStore
();
store
.
dispatch
(
hydrateStore
(
w
in
dow
.
INITIAL_STATE
));
const
initialState
=
JSON
.
parse
(
document
.
getElementById
(
"
initial-state
"
).
textContent
);
store
.
dispatch
(
hydrateStore
(
in
itialState
));
const
browserHistory
=
useRouterHistory
(
createBrowserHistory
)({
basename
:
'
/web
'
...
...
@@ -95,9 +95,10 @@ const Mastodon = React.createClass({
componentDidMount
()
{
const
{
locale
}
=
this
.
props
;
const
streamingAPIBaseURL
=
store
.
getState
().
getIn
([
'
meta
'
,
'
streaming_api_base_url
'
]);
const
accessToken
=
store
.
getState
().
getIn
([
'
meta
'
,
'
access_token
'
]);
this
.
subscription
=
createStream
(
accessToken
,
'
user
'
,
{
this
.
subscription
=
createStream
(
streamingAPIBaseURL
,
accessToken
,
'
user
'
,
{
connected
()
{
store
.
dispatch
(
connectTimeline
(
'
home
'
));
...
...
app/assets/javascripts/components/features/community_timeline/index.jsx
View file @
ef879a88
...
...
@@ -19,6 +19,7 @@ const messages = defineMessages({
const
mapStateToProps
=
state
=>
({
hasUnread
:
state
.
getIn
([
'
timelines
'
,
'
community
'
,
'
unread
'
])
>
0
,
streamingAPIBaseURL
:
state
.
getIn
([
'
meta
'
,
'
streaming_api_base_url
'
]),
accessToken
:
state
.
getIn
([
'
meta
'
,
'
access_token
'
])
});
...
...
@@ -29,6 +30,7 @@ const CommunityTimeline = React.createClass({
propTypes
:
{
dispatch
:
React
.
PropTypes
.
func
.
isRequired
,
intl
:
React
.
PropTypes
.
object
.
isRequired
,
streamingAPIBaseURL
:
React
.
PropTypes
.
string
.
isRequired
,
accessToken
:
React
.
PropTypes
.
string
.
isRequired
,
hasUnread
:
React
.
PropTypes
.
bool
},
...
...
@@ -36,7 +38,7 @@ const CommunityTimeline = React.createClass({
mixins
:
[
PureRenderMixin
],
componentDidMount
()
{
const
{
dispatch
,
accessToken
}
=
this
.
props
;
const
{
dispatch
,
streamingAPIBaseURL
,
accessToken
}
=
this
.
props
;
dispatch
(
refreshTimeline
(
'
community
'
));
...
...
@@ -44,7 +46,7 @@ const CommunityTimeline = React.createClass({
return
;
}
subscription
=
createStream
(
accessToken
,
'
public:local
'
,
{
subscription
=
createStream
(
streamingAPIBaseURL
,
accessToken
,
'
public:local
'
,
{
connected
()
{
dispatch
(
connectTimeline
(
'
community
'
));
...
...
app/assets/javascripts/components/features/hashtag_timeline/index.jsx
View file @
ef879a88
...
...
@@ -13,6 +13,7 @@ import createStream from '../../stream';
const
mapStateToProps
=
state
=>
({
hasUnread
:
state
.
getIn
([
'
timelines
'
,
'
tag
'
,
'
unread
'
])
>
0
,
streamingAPIBaseURL
:
state
.
getIn
([
'
meta
'
,
'
streaming_api_base_url
'
]),
accessToken
:
state
.
getIn
([
'
meta
'
,
'
access_token
'
])
});
...
...
@@ -21,6 +22,7 @@ const HashtagTimeline = React.createClass({
propTypes
:
{
params
:
React
.
PropTypes
.
object
.
isRequired
,
dispatch
:
React
.
PropTypes
.
func
.
isRequired
,
streamingAPIBaseURL
:
React
.
PropTypes
.
string
.
isRequired
,
accessToken
:
React
.
PropTypes
.
string
.
isRequired
,
hasUnread
:
React
.
PropTypes
.
bool
},
...
...
@@ -28,9 +30,9 @@ const HashtagTimeline = React.createClass({
mixins
:
[
PureRenderMixin
],
_subscribe
(
dispatch
,
id
)
{
const
{
accessToken
}
=
this
.
props
;
const
{
streamingAPIBaseURL
,
accessToken
}
=
this
.
props
;
this
.
subscription
=
createStream
(
accessToken
,
`hashtag&tag=
${
id
}
`
,
{
this
.
subscription
=
createStream
(
streamingAPIBaseURL
,
accessToken
,
`hashtag&tag=
${
id
}
`
,
{
received
(
data
)
{
switch
(
data
.
event
)
{
...
...
app/assets/javascripts/components/features/public_timeline/index.jsx
View file @
ef879a88
...
...
@@ -19,6 +19,7 @@ const messages = defineMessages({
const
mapStateToProps
=
state
=>
({
hasUnread
:
state
.
getIn
([
'
timelines
'
,
'
public
'
,
'
unread
'
])
>
0
,
streamingAPIBaseURL
:
state
.
getIn
([
'
meta
'
,
'
streaming_api_base_url
'
]),
accessToken
:
state
.
getIn
([
'
meta
'
,
'
access_token
'
])
});
...
...
@@ -29,6 +30,7 @@ const PublicTimeline = React.createClass({
propTypes
:
{
dispatch
:
React
.
PropTypes
.
func
.
isRequired
,
intl
:
React
.
PropTypes
.
object
.
isRequired
,
streamingAPIBaseURL
:
React
.
PropTypes
.
string
.
isRequired
,
accessToken
:
React
.
PropTypes
.
string
.
isRequired
,
hasUnread
:
React
.
PropTypes
.
bool
},
...
...
@@ -36,7 +38,7 @@ const PublicTimeline = React.createClass({
mixins
:
[
PureRenderMixin
],
componentDidMount
()
{
const
{
dispatch
,
accessToken
}
=
this
.
props
;
const
{
dispatch
,
streamingAPIBaseURL
,
accessToken
}
=
this
.
props
;
dispatch
(
refreshTimeline
(
'
public
'
));
...
...
@@ -44,7 +46,7 @@ const PublicTimeline = React.createClass({
return
;
}
subscription
=
createStream
(
accessToken
,
'
public
'
,
{
subscription
=
createStream
(
streamingAPIBaseURL
,
accessToken
,
'
public
'
,
{
connected
()
{
dispatch
(
connectTimeline
(
'
public
'
));
...
...
app/assets/javascripts/components/reducers/meta.jsx
View file @
ef879a88
...
...
@@ -2,6 +2,7 @@ import { STORE_HYDRATE } from '../actions/store';
import
Immutable
from
'
immutable
'
;
const
initialState
=
Immutable
.
Map
({
streaming_api_base_url
:
null
,
access_token
:
null
,
me
:
null
});
...
...
app/assets/javascripts/components/stream.jsx
View file @
ef879a88
...
...
@@ -10,8 +10,8 @@ const createWebSocketURL = (url) => {
return
a
.
href
;
};
export
default
function
getStream
(
accessToken
,
stream
,
{
connected
,
received
,
disconnected
,
reconnected
})
{
const
ws
=
new
WebSocketClient
(
`
${
createWebSocketURL
(
STREAMING_API_BASE_
URL
)}
/api/v1/streaming/?access_token=
${
accessToken
}
&stream=
${
stream
}
`
);
export
default
function
getStream
(
streamingAPIBaseURL
,
accessToken
,
stream
,
{
connected
,
received
,
disconnected
,
reconnected
})
{
const
ws
=
new
WebSocketClient
(
`
${
createWebSocketURL
(
streamingAPIBase
URL
)}
/api/v1/streaming/?access_token=
${
accessToken
}
&stream=
${
stream
}
`
);
ws
.
onopen
=
connected
;
ws
.
onmessage
=
e
=>
received
(
JSON
.
parse
(
e
.
data
));
...
...
app/controllers/home_controller.rb
View file @
ef879a88
...
...
@@ -4,9 +4,10 @@ class HomeController < ApplicationController
before_action
:authenticate_user!
def
index
@body_classes
=
'app-body'
@token
=
find_or_create_access_token
.
token
@web_settings
=
Web
::
Setting
.
find_by
(
user:
current_user
)
&
.
data
||
{}
@body_classes
=
'app-body'
@token
=
find_or_create_access_token
.
token
@web_settings
=
Web
::
Setting
.
find_by
(
user:
current_user
)
&
.
data
||
{}
@streaming_api_base_url
=
Rails
.
configuration
.
x
.
streaming_api_base_url
end
private
...
...
app/views/home/index.html.haml
View file @
ef879a88
-
content_for
:header_tags
do
:javascript
window
.
STREAMING_API_BASE_URL
=
'
#{
Rails
.
configuration
.
x
.
streaming_api_base_url
}
'
;
window
.
INITIAL_STATE
=
#{
json_escape
(
render
(
file:
'home/initial_state'
,
formats: :json
))
}
%script
#initial-state
{
:type
=>
'application/json'
}!=
json_escape
(
render
(
file:
'home/initial_state'
,
formats: :json
))
=
javascript_include_tag
'application'
,
integrity:
true
...
...
app/views/home/initial_state.json.rabl
View file @
ef879a88
...
...
@@ -2,6 +2,7 @@ object false
node(:meta) do
{
streaming_api_base_url: @streaming_api_base_url,
access_token: @token,
locale: I18n.locale,
me: current_account.id,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment