Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ did not install via Composer or you want to publish the assets yourself, move th
the library's **assets/** directory into your **public/** directory. You can then include them
in your `<head>` tag or use the **Assets** config file to load them for certain routes:

```
```php
public $routes = [
'' => [
'vendor/bootstrap/bootstrap.min.css',
Expand All @@ -47,7 +47,14 @@ in your `<head>` tag or use the **Assets** config file to load them for certain
],
```

If you install assets manually be sure to include Bootstrap.
If you install assets manually be sure to include Bootstrap. Once the files are in place set
the site URL with a `<script>` tag in your views or layouts:

```html
<script>
var baseUrl = "<?= base_url() ?>";
</script>
```

### Authentication

Expand All @@ -62,7 +69,7 @@ your own.
The easiest way to start a chat is with the helper. Load the helper file (`helper('chat')`)
and then use the `chat($uid, $title)` command wherever you would use a partial view:

```
```html
<div id="main">
<h3>Yellow Widgets</h3>
<p>Main product info here!</p>
Expand Down
2 changes: 1 addition & 1 deletion assets/chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ $(".card-body").scrollTop(10000);

// Handle submitting messages via AJAX
function sendMessage(formElement) {
const url = siteUrl + 'chatapi/messages';
const url = siteUrl + '/chatapi/messages';
const data = new URLSearchParams(new FormData(formElement));

fetch(url, {
Expand Down
9 changes: 9 additions & 0 deletions src/Views/conversation.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@

<?php foreach ($conversation->messages as $message): ?>

<?php if (empty($day) || $day !== $message->created_at->format('n/j/Y')): ?>
<?php $day = $message->created_at->format('n/j/Y'); ?>
<div class="row">
<div class="col-5"><hr></div>
<div class="col-2"><?= $day ?></div>
<div class="col-5"><hr></div>
</div>
<?php endif; ?>

<?= view('Tatter\Chat\Views\message', ['message' => $message]) ?>

<?php endforeach; ?>
Expand Down
62 changes: 58 additions & 4 deletions src/Views/message.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,69 @@
<?php if ($message->participant->user_id == user_id()): ?>

<div class="chat-row text-right">
<span class="chat-message d-inline-block m-1 py-1 px-2 rounded-lg small text-white bg-primary"><?= $message->content ?></span>
<span class="chat-avatar d-inline-block m-1 p-2 rounded-circle text-uppercase text-dark bg-light" data-toggle="tooltip" title="<?= $message->participant->username ?>"><?= substr($message->participant->username, 0, 2) ?></span>
<span
class="
chat-message
d-inline-block
rounded-lg
small
text-white
bg-primary
m-1
py-1
px-2
"
data-toggle="tooltip"
title="<?= $message->created_at->format('g:i A') ?>"
><?= $message->content ?></span>
<span
class="
chat-avatar
d-inline-block
rounded-circle
text-uppercase
text-dark
bg-light
m-1
p-2
"
data-toggle="tooltip"
title="<?= $message->participant->name ?: $message->participant->username ?>"
><?= substr($message->participant->username, 0, 2) ?></span>
</div>

<?php else: ?>

<div class="chat-row">
<span class="chat-avatar d-inline-block m-1 p-2 rounded-circle text-uppercase text-dark bg-light" data-toggle="tooltip" title="<?= $message->participant->username ?>"><?= substr($message->participant->username, 0, 2) ?></span>
<span class="chat-message d-inline-block m-1 py-1 px-2 rounded-lg small text-white bg-secondary"><?= $message->content ?></span>
<span
class="
chat-avatar
d-inline-block
rounded-circle
text-uppercase
text-dark
bg-light
m-1
p-2
"
data-toggle="tooltip"
title="<?= $message->participant->name ?: $message->participant->username ?>"
><?= substr($message->participant->username, 0, 2) ?></span>
<span
class="
chat-message
d-inline-block
rounded-lg
small
text-white
bg-secondary
m-1
py-1
px-2
"
data-toggle="tooltip"
title="<?= $message->created_at->format('g:i A') ?>"
><?= $message->content ?></span>
</div>

<?php endif; ?>