Git Product home page Git Product logo

tbmsg's Introduction

Hi there ๐Ÿ‘‹

I am Tzook Bar Noy, a passionate and creative software engineer from ๐Ÿ‡ฎ๐Ÿ‡ฑ and now living in ๐Ÿ‡บ๐Ÿ‡ธ with 10+ years of professional experience.

I mostly work with Python, Node, PHP, Javascript, React, AWS and other technologies. ๐Ÿš€

๐Ÿ“ฑ How to reach me?

tbmsg's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

tbmsg's Issues

Creating Conversation Bug?

$conv_id = \TBMsg::createConversation($users_ids=array(Auth::user()->id, $data['owner']->id  ));
$conv = \TBMsg::addMessageToConversation($conv_id, Auth::user()->id, $body_message);

Let me know if I am doing it right? I am starting a conversation then will add message, but when inserting to message, somehow I am getting this error:
UserNotInConvException in EloquentTBMsgRepository.php line 67:

Please let me know if the above code is the right way to start a conversation?

database table prefix is not used

Hi tzookb,
I'm just checking out your messaging system and noticed that table names are hardwired into the code.

Our database.php contains:
'connections' => array(
'mysql' => array(
'prefix' => 'bo_',

therefore the table is named bo_messages which fails at least with the code in TBMsg.php.

$convs = DB::select(
'
SELECT ...
FROM messages msg

What to do with the method getUserConversations?

Hi there!

First of all, this project looks promising. I'm trying to implement it into a current project. It has worked smoothly thus far. Except, I'm not sure how to actually get all messages of a specific user.

I've tried this:

TBMsg::getUserConversations($user_id)->first();

I get this output:

object(Tzookb\TBMsg\Entities\Conversation)[317]
  protected 'id' => int 9
  protected 'participants' => 
    array (size=2)
      50 => boolean true
      49 => boolean true
  protected 'messages' => 
    object(Illuminate\Support\Collection)[309]
      protected 'items' => 
        array (size=1)
          4 => 
            object(Tzookb\TBMsg\Entities\Message)[321]
              ...
  protected 'created' => null
  protected 'type' => null

I can see the messages Collection, but the property is protected.
How can I access the messages now?

Thanks!

Conversations pagination and missing title/subject

Maybe I have missed this. There is no way to paginate the conversations; supposing a user has 100 conversations it is not safe to return all conversations.

Conventionally messages/threads/conversations require a title. There is no field a conversation title in the conversations table.

TBMsg 1.1 not compatible with laravel 4.2

Hi,
I would like to report that TBMsg 1.1 isn't compatible with laravel 4.2.
This is because the new version makes use of the packages illuminate/database version 5.0.
Are new versions of TBMsg only compatible with laravel 5.0?

Raoul

Eh, doesn't seem to work...

There's no examples on using this. What exactly am I supposed to do? I followed the tests examples, and no luck there. Try to just create a convo between two users, like shown in the examples you have an I get.. "Non-static method Tzookb\TBMsg\TBMsg::createConversation() should not be called statically, assuming $this from incompatible context"

I'm so annoyed D: I cannot fathom why it wont work...

TBMsg::createConversation not creating corresponding entries in conv_users table

The package used to work perfectly, until I reset my database and switched from MySQL to Postgres.

The TBMsg::createConversation doesn't work as it should anymore.

It creates an entry in the conversations table, but it fails to make any corresponding entries in the conv_users table.

Here's the relevant code:

if ($validator->passes()) {
$conv = TBMsg::getConversationByTwoUsers($user_id, $recepient_id);
if($conv < 0) {
$conv = TBMsg::createConversation([$user_id, $recepient_id]);
$conv = $conv->id;
}
$to_conv = TBMsg::addMessageToConversation($conv, $user_id, $content); //this is where it fails because it can't find the user in the conversation.
return Redirect::route('messages.index');
}

TBMsg::getUserConversations Not Returning Convo

I am trying to retrieve a newly created convo with 'TBMsg::getUserConversations($self->id)' but no convos are being returned. I check the database and there a convo with 2 participants. participants id 1 and 6. For some reason I am not getting the open convo.

Problem for delete conversations.

Hey, in your deleteConversation Method

public function deleteConversation($conv_id, $user_id) {

    DB::statement(
        '
        UPDATE messages_status mst
        SET mst.status='.self::DELETED.'
        WHERE mst.user_id=?
        AND mst.status=?
        AND mst.msg_id IN (
          SELECT msg.id
          FROM messages msg
          WHERE msg.conv_id=?
        )
        ',
        array($user_id, self::UNREAD, $conv_id)
    );
}

There is one condition with status UNREAD, why ? Why can you delete only unread conversations ? that's not sense i think.

If i remove status line, it works.

public function deleteConversation($conv_id, $user_id) {

    DB::statement(
        '
        UPDATE messages_status mst
        SET mst.status='.self::DELETED.'
        WHERE mst.user_id=?
        AND mst.msg_id IN (
          SELECT msg.id
          FROM messages msg
          WHERE msg.conv_id=?
        )
        ',
        array($user_id,  $conv_id)
    );
}

1.1.* branch needs an update

Hey,

I just found that the 1.1.1 release uses an old commit. The 1.1 branch needs an update to commit 0467f65 to contain all the last commits for laravel 4.2. Could you make a 1.1.2 release?

Raoul

tbmsg-1.0.0.zip doesn't contain the folder Repositories

Hey, sorry to bother you agian. But Composer never downloaded the folder 'Repositories'. Checking your tbmsg-1.0.0.zip on github and it seems like this folder was never added.

Im using the following composer line; "tzookb/tbmsg": "1.*"

Example of an error i get calling "TBMsg::createConversation($user1,$user2))":

Symfony \ Component \ Debug \ Exception \ FatalErrorException
Class 'Tzookb\TBMsg\Repositories\Eloquent\Objects\Conversation' not found

Cheers

Laravel 5

I changed Conversation.php and ConversationUsers.php to reference
use Illuminate\Database\Eloquent\Model as Eloquent;

Is this also works in Laravel 4.2? If so, you can updated.

getConversationMessages Sorted on user_id

Messages returned from the method getConversationMessages are sorted on user_id in an ascending mater on their user_id and not on created date. Messages sorted on created_at is more useful.

An easy fix would be to add: 'ORDER BY msg.created_at' at the end of the sql query.

public function getConversationMessages($conv_id, $user_id) {
    $results = DB::select(
        '
        SELECT msg.id as msgID, msg.content, msg.created_at, us.id as userId, up.username, up.photo
        FROM messages_status mst
        INNER JOIN messages msg
        ON mst.msg_id=msg.id
        INNER JOIN users us
        ON msg.sender_id=us.id
        INNER JOIN profiles up 
        ON us.id=up.user_id
        WHERE msg.conv_id=?
        AND mst.user_id = ?
        AND mst.status NOT IN (?,?)
        ORDER BY msg.created_at
        '
        , array($conv_id, $user_id, self::DELETED, self::ARCHIVED));
    return $results;
}

Titles

Why is there no titles for convos?

TBMsg::getConversationMessages($conv_id, $user_id);

Hi, I've just chosen you package, after comparing with the existing for a messaging system on my website, and I have installed it via composer.

I have a little issue here and I cannot get all of message from a certain conversation, using this: conv = TBMsg::getConversationMessages('1', $user->id); // i've set the id=1, for a demo, while I'm developing this module.

The only thing I get is the last inserted message from a conversation, instead of listing default order by DESC all of them, for the $conv_id provided.

Could be please help ?

Dumps information about users table name

Hi,

It seems like in Tzookb\TBMsg\TBMsgServiceProvider at line 39 you forgot a var_dump:

var_dump($usersTable);

Edit (forgot to include version):

tzookb/tbmsg (v 2.0.0)

Needs small update for Laravel 5.4

[Symfony\Component\Debug\Exception\FatalThrowableError]
Call to undefined method Illuminate\Foundation\Application::share()

This call simply has to be changed to singleton i guess.

Error sending messages with postgres

Hi,

I keep getting the following error when trying to send a message on my Debian VPS with PHP5.4 , postgres and laravel 4.2. My code works fine using MySQL.

[2015-01-15 22:33:44] production.ERROR: exception 'Tzookb\TBMsg\Exceptions\UserNotInConvException' in /var/www/laravel/2015011301/vendor/tzookb/tbmsg/src/Tzookb/TBMsg/Repositories/EloquentTBMsgRepository.php:68
Stack trace:
#0 /var/www/laravel/2015011301/vendor/tzookb/tbmsg/src/Tzookb/TBMsg/TBMsg.php(246): Tzookb\TBMsg\Repositories\EloquentTBMsgRepository->addMessageToConversation(5, 1, 'why')
#1 /var/www/laravel/2015011301/bootstrap/compiled.php(3263): Tzookb\TBMsg\TBMsg->sendMessageBetweenTwoUsers(1, 506, 'why')
#2 /var/www/laravel/2015011301/app/controllers/ConversationsController.php(90): Illuminate\Support\Facades\Facade::__callStatic('sendMessageBetw...', Array)
#3 /var/www/laravel/2015011301/app/controllers/ConversationsController.php(90): Tzookb\TBMsg\Facade\TBMsg::sendMessageBetweenTwoUsers(1, 506, 'why')
#4 [internal function]: ConversationsController->update('redlion383')
#5 /var/www/laravel/2015011301/vendor/laravel/framework/src/Illuminate/Routing/Controller.php(231): call_user_func_array(Array, Array)
#6 /var/www/laravel/2015011301/bootstrap/compiled.php(5834): Illuminate\Routing\Controller->callAction('update', Array)
#7 /var/www/laravel/2015011301/bootstrap/compiled.php(5822): Illuminate\Routing\ControllerDispatcher->call(Object(ConversationsController), Object(Illuminate\Routing\Route), 'update')
#8 /var/www/laravel/2015011301/bootstrap/compiled.php(5027): Illuminate\Routing\ControllerDispatcher->dispatch(Object(Illuminate\Routing\Route), Object(Illuminate\Http\Request), 'ConversationsCo...', 'update')
#9 [internal function]: Illuminate\Routing\Router->Illuminate\Routing\{closure}('redlion383')
#10 /var/www/laravel/2015011301/bootstrap/compiled.php(5385): call_user_func_array(Object(Closure), Array)
#11 /var/www/laravel/2015011301/bootstrap/compiled.php(5052): Illuminate\Routing\Route->run(Object(Illuminate\Http\Request))
#12 /var/www/laravel/2015011301/bootstrap/compiled.php(5040): Illuminate\Routing\Router->dispatchToRoute(Object(Illuminate\Http\Request))
#13 /var/www/laravel/2015011301/bootstrap/compiled.php(715): Illuminate\Routing\Router->dispatch(Object(Illuminate\Http\Request))
#14 /var/www/laravel/2015011301/bootstrap/compiled.php(696): Illuminate\Foundation\Application->dispatch(Object(Illuminate\Http\Request))
#15 /var/www/laravel/2015011301/bootstrap/compiled.php(7812): Illuminate\Foundation\Application->handle(Object(Illuminate\Http\Request), 1, true)
#16 /var/www/laravel/2015011301/bootstrap/compiled.php(8419): Illuminate\Session\Middleware->handle(Object(Illuminate\Http\Request), 1, true)
#17 /var/www/laravel/2015011301/bootstrap/compiled.php(8366): Illuminate\Cookie\Queue->handle(Object(Illuminate\Http\Request), 1, true)
#18 /var/www/laravel/2015011301/bootstrap/compiled.php(11029): Illuminate\Cookie\Guard->handle(Object(Illuminate\Http\Request), 1, true)
#19 /var/www/laravel/2015011301/bootstrap/compiled.php(657): Stack\StackedHttpKernel->handle(Object(Illuminate\Http\Request))
#20 /var/www/laravel/2015011301/public/index.php(48): Illuminate\Foundation\Application->run()
#21 {main} [] []

My code, i added a few comments explaining what im doing:

public function update($participant)
{
        // Check if message exists and is not empty
        if(!Input::has('msg')) {
            return Redirect::route('chat.show', $participant)->with('flash-error', 'Bericht moet inhoud bevatten.');
        }

        $msg = Input::get('msg');
        $participantProfile = Profile::findByUsernameOrFail($participant); // username used in the URL so we need to get the user ID.
        $user = App::make('user'); // Will return user model of logged in user

       // This function checks if 2 users have an conversation but doesn't work on Postgres.
        TBMsg::sendMessageBetweenTwoUsers($user->info->id, $participantProfile->user_id, $msg);

        return Redirect::route('chat.show', [$participant]);
    }

Thanks,
Raoul

Deleting viewer copy of individual messages

Any plans on implementing this?

Basically, if you have a conversation, I should be able to delete (set the status to 0) either a message I've sent or received so that I no longer see it, but the other person (or people if it's a group) still do.

I've created a function for this outside your core library, but the one downside is if you delete the last message (set the status to 0 for the user), that conversation won't return when you call TBMsg::getUserConversations(userID), because it only checks the last created message in a conversation for a status that isn't either deleted or archived.

Return false on getConversationByTwoUsers

Hi, it's me again. Great update!!

Won't it be practical to return False if 2 users don't have a conversation in the methode "getConversationByTwoUsers" instead of an empty element?
This would make if() statements shorter.
Would like to hear your thoughts.

Table prefix error

My tables have a prefix named lara_, published the migration, tried to test, and get an error

SQLSTATE[42S02]: Base table or view not found: 1146 Table 'lara.messages' doesn't exist (SQL: SELECT msg.conv_id as conv_id, msg.created_at, msg.id msgId, msg.content, mst.status, mst.self, us.id userId FROM messages msg INNER JOIN ( SELECT MAX(created_at) created_at FROM messages GROUP BY conv_id ) m2 ON msg.created_at = m2.created_at INNER JOIN messages_status mst ON msg.id=mst.msg_id INNER JOIN users us ON msg.sender_id=us.id WHERE mst.user_id = 1 AND mst.status NOT IN (0, 3) ORDER BY msg.created_at DESC )

lara.messages, should be lara_messages, any help with this?

Return id of last message inserted

Can we get the the id of the message that was added to a conversation? currently i do the following to add a message:

$conv = TBMsg::sendMessageBetweenTwoUsers($user->id, $toUser->id, $request->content);

this returns the following object:
array:4 [
"senderId" => 11
"convUsersIds" => array:2 [
0 => 9
1 => 11
]
"content" => "asdf asd asd arwtwrget hrth,reth htrhwsrthwrt"
"convId" => 1
]

the inserted message id should also be returned. How can i do this?

Migration problem

When running
php artisan migrate:refresh
I get this error:
screenshot157

This did not happen before installing this package. Any clue what it might be?

Conversation subject

I couldn't find anything about this: is there a way to add a subject to each conversation?

docs?

can you explain how this works? how to use etc

How to resolve the sender to the User model?

So, I'm fetching a message via

$conversations = $this->messages->getUserConversations($user_id)->first();
$message = $conversations->getLastMessage();

Result:

object(Tzookb\TBMsg\Entities\Message)[323]
  protected 'id' => int 5
  protected 'sender' => int 50
  protected 'status' => int 1
  protected 'self' => int 0
  protected 'content' => string 'dfsdfsd' (length=7)
  protected 'created' => string '2014-06-14 22:52:25' (length=19)

Now, in my template I'd do something like

<div class="author">{{ $message->sender }}</div>

It's not possible, since all properties on the object are protected. I assume this is still a bug, right?

Updating Package

Hey buddy - it's been a long time but it's great to see so many updates!

I'm trying to upgrade to the latest version but I must be doing something wrong. When I execute composer update tzookb/tbmsg it tells me there's nothing to update. DId I miss a step?

Loving the new data structure!

Paginate

Is it possible to add a paginate function for messages in convos and for conversations?

TBMsg::createConversation doesn't handle empty user_id

I would suggest moving the 'return $conv' (line 217 TBMsg/TBMsg.php) inside the if statement and returning false if the user_ids array is empty.

Currently if you pass an empty array in it throws an error because $conv never gets initiated.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.