Skip to content

Commit a5548a2

Browse files
committed
add the show_avatar option
1 parent 6a61b89 commit a5548a2

File tree

4 files changed

+21
-10
lines changed

4 files changed

+21
-10
lines changed

client/pfc-core.js

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ var phpFreeChat = (function (pfc, $, window, undefined) {
125125
user.op = ($.inArray(user.id, pfc.channels[pfc.cid].op) >= 0);
126126
user.role = user.op ? 'admin' : 'user';
127127
user.name = (user.name !== undefined) ? user.name : 'Guest ' + Math.round(Math.random() * 100);
128-
user.email = (user.email !== undefined) ? user.email : '';
128+
user.email = (user.email !== undefined) ? user.email : user.name + '@phpfreechat.net';
129129
user.active = (user.active !== undefined) ? user.active : true;
130130

131131
// user list DOM element
@@ -152,9 +152,10 @@ var phpFreeChat = (function (pfc, $, window, undefined) {
152152
if (user.op) {
153153
html.find('div.status').addClass('st-op');
154154
}
155+
if (pfc.options.show_avatar) {
156+
html.find('div.avatar').append('<img src="http://www.gravatar.com/avatar/' + pfc.md5(user.email) + '?d=wavatar&amp;s=20" alt="" />');
157+
}
155158

156-
//html.find('div.avatar').append('<img src="http://www.gravatar.com/avatar/' + pfc.md5(user.email) + '?d=wavatar&amp;s=20" alt="" />');
157-
158159
// get all userids from the list (could be cached)
159160
var userids = [];
160161
$(pfc.element).find('div.pfc-users li.user').each(function (i, dom_user) {
@@ -224,6 +225,12 @@ var phpFreeChat = (function (pfc, $, window, undefined) {
224225
msg.body = (msg.body !== undefined) ? msg.body : '';
225226
msg.timestamp = (msg.timestamp !== undefined) ? msg.timestamp : Math.round(new Date().getTime() / 1000);
226227
msg.date = new Date(msg.timestamp * 1000).toLocaleTimeString();
228+
229+
msg.avatar = (pfc.users[msg.sender] !== undefined) ?
230+
(pfc.users[msg.sender].email ?
231+
pfc.md5(pfc.users[msg.sender].email)
232+
: pfc.md5(pfc.users[msg.sender].name + '@phpfreechat.net'))
233+
: '';
227234

228235
// reformat body text
229236
if (msg.type == 'join') {
@@ -237,12 +244,13 @@ var phpFreeChat = (function (pfc, $, window, undefined) {
237244
var html = null;
238245
if (groupmsg_dom.attr('data-from') != msg.from) {
239246
html = $('<div class="messages-group" data-stamp="" data-from="">'
240-
// + ' <div class="avatar"><img src="http://www.gravatar.com/avatar/00000000000000000000000000000001?d=wavatar&s=30" alt="" /></div>'
241-
// + ' <div class="avatar"><div style="width:30px; height: 30px; background-color: #DDD;"></div></div>'
247+
+ (pfc.options.show_avatar ?
248+
' <div class="avatar"><img src="http://www.gravatar.com/avatar/' + msg.avatar + '?d=wavatar&s=30" alt="" /></div>' :
249+
'')
242250
+ ' <div class="date"></div>'
243251
+ ' <div class="name"></div>'
244252
+ ' </div>');
245-
253+
246254
// system messages (join, error ...)
247255
if (/^system-/.test(msg.from)) {
248256
html.addClass('from-' + msg.from);

client/pfc.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,10 @@ var phpFreeChat = (function (pfc, $, window, undefined) {
5050
skip_intro: false,
5151

5252
// skip login step ? (if true, chat will not be usable)
53-
skip_auth: false
53+
skip_auth: false,
54+
55+
// show user avatar or not
56+
show_avatar: false
5457
};
5558

5659
function Plugin(element, options) {

client/themes/default/pfc-notimplemented.less

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
// Not planned for pfc 2.0
33
//
44

5-
@userlist-avatar-w: 0px; // avatar not planned for 2.0
6-
@message-padding-left: 0px; // avatar not planned for 2.0
5+
/*@userlist-avatar-w: 0px; // avatar not planned for 2.0
6+
@message-padding-left: 0px; // avatar not planned for 2.0*/
77
/*@users-role-title-display: none; // role not planned for 2.0
88
@users-role-title-border-width: 0px; // role not planned for 2.0*/
99

examples/default.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ <h1 style="font-size:1.5em">phpFreeChat - default theme and default parameters</
5656

5757
<div class="pfc-hook"><a href="http://www.phpfreechat.net">Creating chat rooms everywhere - phpFreeChat</a></div>
5858
<script type="text/javascript">
59-
$('.pfc-hook').phpfreechat();
59+
$('.pfc-hook').phpfreechat({show_avatar: true});
6060
</script>
6161

6262
</div>

0 commit comments

Comments
 (0)