Repositories | Polyback | Log in to see private repositories


polyback-website / 614f95c3c341c30330ef2016ea9bf11385e0c61a / chat.php

3,446 bytes | root directory

<?php require $_SERVER['DOCUMENT_ROOT'].'/api/private/core.php';

use pizzaboxer\ProjectPolygon\Users;
use pizzaboxer\ProjectPolygon\Chat;
use pizzaboxer\ProjectPolygon\PageBuilder;

Users::RequireLogin();

// /chat?with=<user id> opens that friend's conversation
$with = (int) ($_GET["with"] ?? 0);

$pageBuilder = new PageBuilder(["title" => "Chat"]);
$pageBuilder->addAppAttribute("data-chat-with", $with);
$pageBuilder->addAppAttribute("data-chat-max-length", Chat::MAX_LENGTH);
// the Join button is the game page's own (games.js + the footer's launcher modal)
$pageBuilder->addResource("scripts", "/js/protocolcheck.js");
$pageBuilder->addResource("polygonScripts", "/js/polygon/games.js");
$pageBuilder->addResource("polygonScripts", "/js/polygon/chat.js");
$pageBuilder->buildHeader();
?>
<style>
	.chat-friends { max-height: 520px; overflow-y: auto; }
	.chat-friends .list-group-item { cursor: pointer; }
	.chat-friends .chat-avatar { width: 40px; height: 40px; }
	.chat-friends .chat-friend-status { font-size: 0.8rem; }
	.chat-status-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 3px; }
	.chat-status-online .chat-status-dot { background-color: #007bff; }
	.chat-status-ingame .chat-status-dot { background-color: #28a745; }
	.chat-status-offline .chat-status-dot { background-color: #adb5bd; }
	.chat-messages { height: 400px; overflow-y: auto; }
	.chat-message { max-width: 80%; white-space: pre-wrap; word-wrap: break-word; overflow-wrap: anywhere; }
	.chat-message-mine { margin-left: auto; }
	.chat-message-theirs { background-color: rgba(127, 127, 127, 0.18); color: inherit; } /* readable in the light and dark themes */
	.chat-typing { min-height: 1.5rem; font-size: 0.85rem; }
</style>
<h2 class="font-weight-normal">Chat</h2>
<div class="row pt-2">
	<div class="col-md-4 mb-3">
		<div class="card">
			<div class="card-header bg-cardpanel py-2">Friends</div>
			<div class="chat-friends list-group list-group-flush">
				<div class="loading text-center py-3"><span class="spinner-border" role="status"></span></div>
			</div>
			<p class="chat-no-friends text-muted text-center my-3 px-2 d-none">You don't have any friends yet. Find people to add on the <a href="/browse">People</a> page.</p>
		</div>
	</div>
	<div class="col-md-8 mb-3">
		<div class="card chat-conversation">
			<div class="card-header bg-cardpanel py-2 d-flex align-items-center">
				<div class="chat-conversation-title flex-grow-1">Select a friend to chat with</div>
				<div class="chat-conversation-actions"></div>
			</div>
			<div class="card-body chat-messages p-2">
				<p class="chat-placeholder text-muted text-center mt-5">Click one of your friends to start chatting.</p>
			</div>
			<div class="card-footer p-2 d-none chat-compose">
				<div class="chat-typing text-muted font-italic px-1"></div>
				<form class="chat-form" autocomplete="off">
					<div class="input-group">
						<input type="text" class="form-control chat-input" maxlength="<?= Chat::MAX_LENGTH ?>" placeholder="Type a message..." aria-label="Message">
						<div class="input-group-append">
							<button class="btn btn-primary chat-send" type="submit"><span class="spinner-border spinner-border-sm d-none"></span> Send</button>
						</div>
					</div>
					<small class="text-muted chat-counter float-right">0/<?= Chat::MAX_LENGTH ?></small>
				</form>
			</div>
		</div>
	</div>
</div>
<?php $pageBuilder->buildFooter(); ?>