-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
259 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import Widgets from 'flarum/extensions/afrux-forum-widgets-core/common/extend/Widgets'; | ||
|
||
import WebsocketOnlineUsersWidget from './WebsocketOnlineUsersWidget'; | ||
|
||
export default function(app) { | ||
(new Widgets).add({ | ||
key: 'WebsocketOnlineUsersWidget', | ||
component: WebsocketOnlineUsersWidget, | ||
|
||
isDisabled: false, | ||
|
||
placement: 'end', | ||
position: 1, | ||
}).extend(app, 'kyrne-websocket'); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
import LoadingIndicator from 'flarum/components/LoadingIndicator'; | ||
import Tooltip from 'flarum/components/Tooltip'; | ||
import avatar from 'flarum/helpers/avatar'; | ||
import Link from 'flarum/components/Link'; | ||
import stringToColor from 'flarum/utils/stringToColor'; | ||
import Stream from 'flarum/utils/Stream'; | ||
|
||
import Widget from 'flarum/extensions/afrux-forum-widgets-core/common/components/Widget'; | ||
|
||
let WebsocketWidget = null; | ||
|
||
if (Widget) { | ||
WebsocketWidget = class WebsocketOnlineUsersWidget extends Widget { | ||
oninit(vnode) { | ||
super.oninit(vnode); | ||
|
||
this.users = []; | ||
this.loading = true; | ||
} | ||
|
||
oncreate(vnode) { | ||
super.oncreate(vnode); | ||
|
||
app.pusher.then(object => { | ||
const presence = object.channels.presence; | ||
|
||
const existingMembers = Object.keys(presence.members.members); | ||
|
||
if (existingMembers.length === 0) { | ||
|
||
presence.bind("pusher:subscription_succeeded", members => { | ||
Object.keys(members.members).map(member => { | ||
if (presence.members.myID != member && !member.includes('Guest')) { | ||
members.members[member].id = member; | ||
this.pushMember(members.members[member]); | ||
} | ||
}) | ||
this.loading = false; | ||
m.redraw(); | ||
}); | ||
} else { | ||
existingMembers.map(member => { | ||
if (presence.members.myID != member && !member.includes('Guest')) { | ||
presence.members.members[member].id = member; | ||
this.pushMember(presence.members.members[member]); | ||
} | ||
}) | ||
this.loading = false; | ||
m.redraw(); | ||
} | ||
|
||
presence.bind("pusher:member_removed", (member) => { | ||
this.users.some((user, i) => { | ||
if (user.id() == member.id) { | ||
this.users.splice(i, 1); | ||
m.redraw(); | ||
return true; | ||
} | ||
}); | ||
}); | ||
|
||
presence.bind("pusher:member_added", (member) => { | ||
if (presence.members.myID != member.id && typeof member.id !== 'string') { | ||
member.info.id = member.id; | ||
this.pushMember(member.info); | ||
m.redraw(); | ||
} | ||
}); | ||
}); | ||
} | ||
|
||
pushMember(member) { | ||
this.users.push({ | ||
id: Stream(member.id), | ||
color: Stream('#' + stringToColor(member.username)), | ||
displayName: Stream(member.username), | ||
avatarUrl: Stream(member.avatarUrl), | ||
slug: Stream(member.slug) | ||
}); | ||
} | ||
|
||
className() { | ||
return 'WebsocketOnlineUsersWidget'; | ||
} | ||
|
||
icon() { | ||
return 'fas fa-user-friends'; | ||
} | ||
|
||
title() { | ||
return app.translator.trans('kyrne-websocket.forum.widget.title'); | ||
} | ||
|
||
content() { | ||
if (this.loading) { | ||
return <LoadingIndicator/>; | ||
} | ||
|
||
const max = 15; | ||
const users = this.users; | ||
|
||
return ( | ||
<div className="WebsocketOnlineUsersWidget-users"> | ||
<div className="WebsocketOnlineUsersWidget-users-message"> | ||
{users.length === 0 ? app.translator.trans('kyrne-websocket.forum.widget.empty') : null} | ||
</div> | ||
<div className="WebsocketOnlineUsersWidget-users-list"> | ||
{users.slice(0, max).map((user) => ( | ||
<Link href={app.route('user', {username: user.slug()})} className="WebsocketOnlineUsersWidget-users-item"> | ||
<Tooltip text={user.displayName()}>{avatar(user)}</Tooltip> | ||
</Link> | ||
))} | ||
{users.length > max ? ( | ||
<span className="WebsocketOnlineUsersWidget-users-item WebsocketOnlineUsersWidget-users-item--plus"> | ||
<span className="Avatar">{`+${max}`}</span> | ||
</span> | ||
) : null} | ||
</div> | ||
</div> | ||
); | ||
} | ||
} | ||
} else { | ||
WebsocketWidget = class WebsocketOnlineUsersWidget {}; | ||
} | ||
|
||
export default WebsocketWidget; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.