Chat Controller distinguish between sender and receiver

Hello,

i create a private chat. Now i got the problem to assign sender and receiver messages. I only get the receiver messages.

Controller:

  public function chatPanelAction(){
      $receiverId = $this->request->get("chatUserId");
      $this->view->user = Users::findFirst($receiverId);
      $this->view->setVar('loggedUser',$this->auth->getUser());

      $this->view->setRenderLevel(
          View::LEVEL_ACTION_VIEW
      );
  }

Volt

  <table class="table" id="panelId{{user.id}}">
          {% for p in user.chat %}
          {% if p.senderId === loggedUser.id AND p.receiverId == user.id %}
               sender
              <tr class="msg-row-container">
              <td>
                  <div class="msg-row">
                      <div class="avatar"></div>
                      <div class="messageSender">
                          <span class="user-label">
                                  <a href="#" style="color: #6D84B4;">Sender</a>
                          </span>
               <span class="msg-time"></span>
               <span>{{ p.message }}</span>
                          </div>
                      </div>
                  </td>
              </tr>

          {% elseif p.receiverId === loggedUser.id AND p.senderId === user.id %}
              receiver
              <tr class="msg-row-container">
                  <td>
                      <div class="msg-row">
                          <div class="avatar"></div>
                          <div class="messageReceiver">
                          <span class="user-label">
               <a href="#" style="color: #6D84B4;">{{ user.name }}</a>
               <span class="msg-time"></span>
               </span><br/>{{ p.message }}</span>
                          </div>
                      </div>
                  </td>
              </tr>
          {% endif %}
          {% endfor %}

      </table>

Table chat

  chatid | senderId | receiverId | message | date
  1            12               13                  hello          xxxxx
  2            13               12                  hi               xxxxx
  3            12               13                  h r u          xxxxx

Thx for help

Rgds Stefan



46.8k

You can learn how to implement Websockets with Phalcon by looking at:



19.5k

Hello dschissler,

thx for your reply, i ordered the book days ago.

Rgds Stefan