承接 amplify/message 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

amplify/message

Composer 安装命令:

composer require amplify/message

包简介

This is a message module for amplify

README 文档

README

This package was initially build by https://github.com/gerardojbaez/messenger And then the dependencies were updated

Chat/Message system for Laravel 8.x.

With Messenger:

  • Users can send and receive messages.
  • Users can participate in multiple conversations.
  • Users can send messages to one or multiple users.

TL;DR

use Messenger;

// Sending a message to one user:
Messenger::from($user)->to($user)->message('Hey!');

// Sending a message to multiple users: (an array of user ids)
Messenger::from($user)->to([1,2,3,4])->message('Who want to chat?!');

// Sending a message to one thread: (perfect for replying to a specific thread!)
Messenger::from($user)->to($thread)->message('I\'ll be there');

Content

Installation

Requirements

  • Laravel 8.x
  • PHP >=7.4.x

Composer

$ composer require shahinur/messenger

Service Provider and Facade

Add the package to your application service providers in config/app.php file.

'providers' => [
	/**
	 * Third Party Service Providers...
	 */
	Shahinur\Messenger\MessengerServiceProvider::class,
]

Add the Facade to your aliases array:

'aliases' => [

	[...]

	'Messenger' => Shahinur\Messenger\Facades\Messenger::class,
]

Config file and Migrations

Publish package config file and migrations with the command:

$ php artisan vendor:publish --provider="Shahinur\Messenger\MessengerServiceProvider"

Then run migrations:

$ php artisan migrate

Traits and Contracts

Add Shahinur/Messenger/Traits/Messageable trait and Shahinur/Messenger/Contracts/MessageableInterface contract to your Users model.

See the following example:

<?php

namespace App\Models;

use Illuminate\Foundation\Auth\User as Authenticatable;use Modules\Message\Interfaces\MessageableInterface;use Shahinur\Messenger\Traits\Messageable;

class User extends Authenticatable implements MessageableInterface
{
    use Messageable;

Usage

Sending to One User

<?php

// Import the facade
use Messenger;

Messenger::from($user)->to($user2)->message('Hey!')->send();

Sending to Multiple Users

<?php

// Import the facade
use Messenger;

Messenger::from($user)->to([1,2,3,4,5])->message('Hey!')->send();

Sending to Thread

<?php

// Import the facade
use Messenger;

Messenger::from($user)->to($thread)->message('That\'s awesome!')->send();

Get count of new messages

Get global count - new messages in all user threads:

<?php

echo $user->unreadMessagesCount;

Get count for a particular user thread:

<?php

echo $user->threads->first()->unreadMessagesCount;

Mark thread as read

To mark a thread as read:

<?php

$user->markThreadAsRead($thread_id);

Thread Dynamic Attributes

Threads dynamic attributes are attributes that doesn't come from the database, instead we generate them based on the data.

For example, threads doesn't have a title by itself, Messenger will create it based on the participants list.

Attributes:

  • $thread->title
  • $thread->creator to get the thread creator.
  • $thread->lastMessage to get the latest message in the thread.

Displaying user threads

The controller:

public function index()
{
    // Eager Loading - this helps prevent hitting the
    // database more than the necessary.
    $this->user->load('threads.messages.sender');

    return view('messages.index', [
        'threads' => $this->user->threads
    ]);
}

The view:

<div class="panel panel-default">
    <div class="list-group">
        @if($threads->count() > 0)
            @foreach($threads as $thread)
                @if($thread->lastMessage)
                    <a href="#" class="list-group-item">
                        <div class="clearfix">
                            <div class="pull-left">
                                <span class="h5">{{ $thread->title }}</span>
                                @if($thread->unreadMessagesCount > 0)
                                    <span class="label label-success">{!! $thread->unreadMessagesCount !!}</span>
                                @endif
                            </div>
                            <span class="text-muted pull-right">{{ $thread->lastMessage->created_at->diffForHumans() }}</span>
                        </div>
                        <p class="text-muted no-margin">{{ str_limit($thread->lastMessage->body, 35) }}</p>
                    </a>
                @endif
            @endforeach
        @endif
    </div>
</div>

Using Models

Messenger has 3 models:

Shahinur\Messenger\Models\Message;
Shahinur\Messenger\Models\MessageThread;
Shahinur\Messenger\Models\MessageThreadParticipant;

You can use these as normal. For more details take a look to each model and the Shahinur\Messenger\Traits\Messageable trait.

Config File

For now you can configure what models to use.

License

This package is free software distributed under the terms of the MIT license.

amplify/message 适用场景与选型建议

amplify/message 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 482 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 12 月 25 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 amplify/message 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 amplify/message 我们能提供哪些服务?
定制开发 / 二次开发

基于 amplify/message 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 482
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 8
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: GPL-3.0-or-later
  • 更新时间: 2024-12-25