Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
converse.js
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
converse.js
Commits
adf34c84
Commit
adf34c84
authored
May 03, 2018
by
JC Brand
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Render chatbox avatar via the vcards collection
parent
71ed5bbd
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
44 additions
and
36 deletions
+44
-36
src/converse-chatboxes.js
src/converse-chatboxes.js
+5
-0
src/converse-chatview.js
src/converse-chatview.js
+10
-11
src/converse-message-view.js
src/converse-message-view.js
+28
-25
src/templates/chatbox_head.html
src/templates/chatbox_head.html
+1
-0
No files found.
src/converse-chatboxes.js
View file @
adf34c84
...
@@ -213,6 +213,11 @@
...
@@ -213,6 +213,11 @@
},
},
initialize
()
{
initialize
()
{
this
.
vcard
=
_converse
.
vcards
.
findWhere
({
'
jid
'
:
this
.
get
(
'
jid
'
)});
if
(
_
.
isNil
(
this
.
vcard
))
{
this
.
vcard
=
_converse
.
vcards
.
create
({
'
jid
'
:
this
.
get
(
'
jid
'
)});
}
this
.
messages
=
new
_converse
.
Messages
();
this
.
messages
=
new
_converse
.
Messages
();
this
.
messages
.
browserStorage
=
new
Backbone
.
BrowserStorage
[
_converse
.
message_storage
](
this
.
messages
.
browserStorage
=
new
Backbone
.
BrowserStorage
[
_converse
.
message_storage
](
b64_sha1
(
`converse.messages
${
this
.
get
(
'
jid
'
)}${
_converse
.
bare_jid
}
`
));
b64_sha1
(
`converse.messages
${
this
.
get
(
'
jid
'
)}${
_converse
.
bare_jid
}
`
));
...
...
src/converse-chatview.js
View file @
adf34c84
...
@@ -102,8 +102,6 @@
...
@@ -102,8 +102,6 @@
_converse
.
api
.
settings
.
update
({
_converse
.
api
.
settings
.
update
({
'
use_emojione
'
:
false
,
'
use_emojione
'
:
false
,
'
emojione_image_path
'
:
emojione
.
imagePathPNG
,
'
emojione_image_path
'
:
emojione
.
imagePathPNG
,
'
chatview_avatar_height
'
:
32
,
'
chatview_avatar_width
'
:
32
,
'
show_toolbar
'
:
true
,
'
show_toolbar
'
:
true
,
'
time_format
'
:
'
HH:mm
'
,
'
time_format
'
:
'
HH:mm
'
,
'
visible_toolbar_buttons
'
:
{
'
visible_toolbar_buttons
'
:
{
...
@@ -204,23 +202,24 @@
...
@@ -204,23 +202,24 @@
}
}
});
});
_converse
.
ChatBoxHeading
=
Backbone
.
NativeView
.
extend
({
_converse
.
ChatBoxHeading
=
_converse
.
ViewWithAvatar
.
extend
({
initialize
()
{
initialize
()
{
this
.
model
.
on
(
'
change:image
'
,
this
.
render
,
this
);
this
.
model
.
on
(
'
change:status
'
,
this
.
onStatusMessageChanged
,
this
);
this
.
model
.
on
(
'
change:status
'
,
this
.
onStatusMessageChanged
,
this
);
this
.
model
.
on
(
'
change:fullnam
e
'
,
this
.
render
,
this
);
this
.
model
.
vcard
.
on
(
'
chang
e
'
,
this
.
render
,
this
);
},
},
render
()
{
render
()
{
this
.
el
.
innerHTML
=
tpl_chatbox_head
(
this
.
el
.
innerHTML
=
tpl_chatbox_head
(
_
.
extend
(
this
.
model
.
toJSON
(),
{
_
.
extend
(
'
_converse
'
:
_converse
,
this
.
model
.
toJSON
(),
'
avatar_width
'
:
_converse
.
chatview_avatar_width
,
this
.
model
.
vcard
.
toJSON
(),
'
avatar_height
'
:
_converse
.
chatview_avatar_height
,
{
'
_converse
'
:
_converse
,
'
info_close
'
:
__
(
'
Close this chat box
'
),
'
info_close
'
:
__
(
'
Close this chat box
'
)
})
}
)
);
);
this
.
renderAvatar
();
return
this
;
return
this
;
},
},
...
...
src/converse-message-view.js
View file @
adf34c84
...
@@ -41,7 +41,33 @@
...
@@ -41,7 +41,33 @@
const
{
_converse
}
=
this
,
const
{
_converse
}
=
this
,
{
__
}
=
_converse
;
{
__
}
=
_converse
;
_converse
.
MessageView
=
Backbone
.
NativeView
.
extend
({
_converse
.
ViewWithAvatar
=
Backbone
.
NativeView
.
extend
({
renderAvatar
()
{
const
canvas_el
=
this
.
el
.
querySelector
(
'
canvas
'
);
if
(
_
.
isNull
(
canvas_el
))
{
return
;
}
const
image_type
=
this
.
model
.
vcard
.
get
(
'
image_type
'
),
image
=
this
.
model
.
vcard
.
get
(
'
image
'
),
img_src
=
"
data:
"
+
image_type
+
"
;base64,
"
+
image
,
img
=
new
Image
();
img
.
onload
=
()
=>
{
const
ctx
=
canvas_el
.
getContext
(
'
2d
'
),
ratio
=
img
.
width
/
img
.
height
;
ctx
.
clearRect
(
0
,
0
,
canvas_el
.
width
,
canvas_el
.
height
);
if
(
ratio
<
1
)
{
ctx
.
drawImage
(
img
,
0
,
0
,
canvas_el
.
width
,
canvas_el
.
height
*
(
1
/
ratio
));
}
else
{
ctx
.
drawImage
(
img
,
0
,
0
,
canvas_el
.
width
,
canvas_el
.
height
*
ratio
);
}
};
img
.
src
=
img_src
;
},
});
_converse
.
MessageView
=
_converse
.
ViewWithAvatar
.
extend
({
initialize
()
{
initialize
()
{
this
.
chatbox
=
this
.
model
.
collection
.
chatbox
;
this
.
chatbox
=
this
.
model
.
collection
.
chatbox
;
...
@@ -53,7 +79,7 @@
...
@@ -53,7 +79,7 @@
})
})
}
}
});
});
this
.
model
.
vcard
.
on
(
'
change:image
'
,
()
=>
this
.
renderAvatar
()
);
this
.
model
.
vcard
.
on
(
'
change:image
'
,
this
.
renderAvatar
,
this
);
this
.
model
.
on
(
'
change:fullname
'
,
this
.
render
,
this
);
this
.
model
.
on
(
'
change:fullname
'
,
this
.
render
,
this
);
this
.
model
.
on
(
'
change:progress
'
,
this
.
renderFileUploadProgresBar
,
this
);
this
.
model
.
on
(
'
change:progress
'
,
this
.
renderFileUploadProgresBar
,
this
);
this
.
model
.
on
(
'
change:type
'
,
this
.
render
,
this
);
this
.
model
.
on
(
'
change:type
'
,
this
.
render
,
this
);
...
@@ -121,29 +147,6 @@
...
@@ -121,29 +147,6 @@
}
}
},
},
renderAvatar
()
{
const
canvas_el
=
this
.
el
.
querySelector
(
'
canvas
'
);
if
(
_
.
isNull
(
canvas_el
))
{
return
;
}
const
image_type
=
this
.
model
.
vcard
.
get
(
'
image_type
'
),
image
=
this
.
model
.
vcard
.
get
(
'
image
'
),
img_src
=
"
data:
"
+
image_type
+
"
;base64,
"
+
image
,
img
=
new
Image
();
img
.
onload
=
()
=>
{
const
ctx
=
canvas_el
.
getContext
(
'
2d
'
),
ratio
=
img
.
width
/
img
.
height
;
ctx
.
clearRect
(
0
,
0
,
canvas_el
.
width
,
canvas_el
.
height
);
if
(
ratio
<
1
)
{
ctx
.
drawImage
(
img
,
0
,
0
,
canvas_el
.
width
,
canvas_el
.
height
*
(
1
/
ratio
));
}
else
{
ctx
.
drawImage
(
img
,
0
,
0
,
canvas_el
.
width
,
canvas_el
.
height
*
ratio
);
}
};
img
.
src
=
img_src
;
},
replaceElement
(
msg
)
{
replaceElement
(
msg
)
{
if
(
!
_
.
isNil
(
this
.
el
.
parentElement
))
{
if
(
!
_
.
isNil
(
this
.
el
.
parentElement
))
{
this
.
el
.
parentElement
.
replaceChild
(
msg
,
this
.
el
);
this
.
el
.
parentElement
.
replaceChild
(
msg
,
this
.
el
);
...
...
src/templates/chatbox_head.html
View file @
adf34c84
<div
class=
"chat-head chat-head-chatbox row no-gutters"
>
<div
class=
"chat-head chat-head-chatbox row no-gutters"
>
<div
class=
"col"
>
<div
class=
"col"
>
<div
class=
"row no-gutters"
>
<div
class=
"row no-gutters"
>
<canvas
class=
"avatar"
height=
"36"
width=
"36"
></canvas>
<div
class=
"col chat-title"
title=
"{{{o.jid}}}"
>
<div
class=
"col chat-title"
title=
"{{{o.jid}}}"
>
{[ if (o.url) { ]}
{[ if (o.url) { ]}
<a
href=
"{{{o.url}}}"
target=
"_blank"
rel=
"noopener"
class=
"user"
>
<a
href=
"{{{o.url}}}"
target=
"_blank"
rel=
"noopener"
class=
"user"
>
...
...
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