Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Gualter
matrix-sustrares-blog
Commits
2fafda47
Commit
2fafda47
authored
May 04, 2016
by
Simen Graaten
Browse files
Ported more of the blog to new api
parent
da9b39b2
Changes
2
Hide whitespace changes
Inline
Side-by-side
index.html
View file @
2fafda47
<html>
<head>
<title>
Matrix blog v.
1
</title>
<title>
Matrix blog v.
2
</title>
<link
href=
'http://fonts.googleapis.com/css?family=Roboto'
rel=
'stylesheet'
type=
'text/css'
>
<script
src=
"../js/jquery-1.4.2.min.js"
></script>
<script
src=
"lib/browser-matrix-0.5.2.min.js"
></script>
...
...
@@ -52,6 +52,9 @@ time {
.emote
.body
{
color
:
#44d
;
}
.host
{
color
:
#aaa
;
}
.host
:before
{
content
:
":"
;
color
:
#888
;
...
...
matrix-blog.js
View file @
2fafda47
...
...
@@ -20,16 +20,11 @@ var MatrixBlog = function(settings) {
this
.
client
.
getRoomIdForAlias
(
this
.
settings
.
room
,
function
(
err
,
data
)
{
var
$root
=
$
(
self
.
settings
.
selector
);
self
.
roomId
=
data
.
room_id
;
console
.
log
(
"
Found room:
"
+
self
.
roomId
);
// client.sendTyping(roomId, true, 5000, function (err, data) {})
// fetch the last 50 events from our room as inital state
self
.
client
.
on
(
'
Room.timeline
'
,
function
(
evt
,
room
,
toStartOfTimeline
)
{
$root
.
empty
();
$root
.
append
(
self
.
$people
);
$root
.
append
(
self
.
$posts
);
if
(
room
.
roomId
==
self
.
roomId
)
{
self
.
processChunk
(
evt
);
}
...
...
@@ -37,18 +32,21 @@ var MatrixBlog = function(settings) {
console
.
log
(
"
Ignoring room id:
"
+
data
.
rooms
[
j
].
room_id
);
}
// fetch presence to create a nick list on top
for
(
var
i
in
data
.
presence
)
{
self
.
processPresence
(
data
.
presence
[
i
]);
}
self
.
endKey
=
data
.
end
;
self
.
waitForMessage
();
});
self
.
client
.
on
(
'
User.presence
'
,
function
(
evt
,
user
)
{
self
.
processPresence
(
evt
,
user
);
});
self
.
client
.
registerGuest
({},
function
(
err
,
data
)
{
self
.
client
.
_http
.
opts
.
accessToken
=
data
.
access_token
;
self
.
client
.
credentials
.
userId
=
data
.
user_id
;
console
.
log
(
data
,
err
);
$root
.
empty
();
$root
.
append
(
self
.
$people
);
$root
.
append
(
self
.
$posts
);
self
.
client
.
peekInRoom
(
self
.
roomId
);
});
});
...
...
@@ -79,21 +77,30 @@ MatrixBlog.prototype.makeTimeString = function(ts) {
}
// process presence data
MatrixBlog
.
prototype
.
processPresence
=
function
(
person
)
{
if
(
person
.
type
==
'
m.presence
'
)
{
var
mxc
=
person
.
content
.
avatar_url
;
var
url
=
this
.
client
.
getHttpUriForMxc
(
mxc
,
32
,
32
,
"
crop
"
);
MatrixBlog
.
prototype
.
processPresence
=
function
(
evt
,
user
)
{
if
(
evt
.
event
.
type
==
'
m.presence
'
)
{
var
url
=
null
;
if
(
user
.
avatarUrl
)
{
var
mxc
=
user
.
avatarUrl
;
url
=
this
.
client
.
mxcUrlToHttp
(
mxc
,
32
,
32
,
"
crop
"
);
}
var
$item
=
this
.
$people
.
find
(
"
[data-user-id=
"
+
person
.
user_id
);
var
$item
=
this
.
$people
.
find
(
"
[data-user-id=
\"
"
+
user
.
userId
+
"
\"
"
);
if
(
$item
.
length
>
0
)
{
$item
=
$
(
$item
[
0
]);
}
else
{
$item
=
$
(
"
<li>
"
);
$item
.
attr
(
"
data-user-id
"
,
person
.
content
.
user
_i
d
);
$item
.
attr
(
"
data-user-id
"
,
user
.
user
I
d
);
$item
.
attr
(
"
data-updated
"
,
(
new
Date
).
getTime
());
var
$img
=
$
(
"
<img>
"
).
attr
(
"
src
"
,
url
);
$item
.
append
(
$img
);
if
(
url
)
{
var
$img
=
$
(
"
<img>
"
).
attr
(
"
src
"
,
url
);
$item
.
append
(
$img
);
}
else
{
var
$dummy
=
$
(
"
<div>
"
).
text
(
user
.
userId
);
$item
.
append
(
$dummy
);
}
this
.
$people
.
append
(
$item
);
}
}
...
...
@@ -126,7 +133,7 @@ MatrixBlog.prototype.processChunk = function(message) {
else
if
(
message
.
event
.
content
.
msgtype
==
'
m.image
'
)
{
$item
.
addClass
(
'
image
'
);
var
mxc
=
message
.
event
.
content
.
url
;
var
url
=
this
.
client
.
getHttpUriForMxc
(
mxc
,
400
,
400
);
var
url
=
this
.
client
.
mxcUrlToHttp
(
mxc
,
400
,
400
,
"
scale
"
);
var
$img
=
$
(
"
<img>
"
).
attr
(
"
src
"
,
url
);
$item
.
append
(
$user
);
...
...
@@ -145,14 +152,3 @@ MatrixBlog.prototype.processChunk = function(message) {
}
};
// wait for message events
MatrixBlog
.
prototype
.
waitForMessage
=
function
()
{
var
self
=
this
;
this
.
client
.
eventStream
(
this
.
endKey
,
function
(
err
,
data
)
{
self
.
endKey
=
data
.
end
;
for
(
var
i
in
data
.
chunk
)
{
self
.
processChunk
(
data
.
chunk
[
i
]);
}
self
.
waitForMessage
();
});
};
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