nahid / talk

Talk is a real-time users messaging and chatting system for Laravel.
MIT License
1.61k stars 327 forks source link

count unread messages #19

Closed 13dev closed 7 years ago

13dev commented 8 years ago

how i can count all unread messages of user ?

nahid commented 8 years ago

In inbox message are already count unread messages.

newbielinuxuser commented 7 years ago

@nahid which method should we use for count unread messages?

13dev commented 7 years ago

getInbox

newbielinuxuser commented 7 years ago

@13dev Below is how I write the codes,

Controller $threads = Talk::threads(); return view('inbox', ['threads' => $threads]); View @foreach($threads as $value) {{dd($value)}} @endforeach

I use threads cuz threads are alias to getInbox, but even if i dump it, i still couldn't see the unread messages, what is the object name ?

13dev commented 7 years ago

you have this?

Talk::setAuthUserId(auth()->user()->id);

newbielinuxuser commented 7 years ago

Yes, i put it as a constructor public function __construct() { Talk::setAuthUserId(Auth::user()->id); }

13dev commented 7 years ago

in controller dd($threads); before return and watch if returning anything

13dev commented 7 years ago

and dd(Auth::user()->id);

newbielinuxuser commented 7 years ago

uh, yes, it does return something, same goes to the view that i commented just now, i just didn't know which object name it would be.

{#383 ▼ +"thread": Message {#388 ▼

table: "messages"

+timestamps: true
#touches: array:1 [▶]
+fillable: array:6 [▶]
#connection: null
#primaryKey: "id"
#keyType: "int"
#perPage: 15
+incrementing: true
#attributes: array:9 [▶]
#original: array:9 [▶]
#relations: array:1 [▶]
#hidden: []
#visible: []
#appends: []
#guarded: array:1 [▶]
#dates: []
#dateFormat: null
#casts: []
#observables: []
#with: []
#morphClass: null
+exists: true
+wasRecentlyCreated: false

} +"withUser": User {#381 ▶} }

13dev commented 7 years ago

watch fillable

newbielinuxuser commented 7 years ago
+fillable: array:6 [▼
  0 => "message"
  1 => "is_seen"
  2 => "deleted_from_sender"
  3 => "deleted_from_receiver"
  4 => "user_id"
  5 => "conversation_id"
]
13dev commented 7 years ago

is_seen return if message is read or not

newbielinuxuser commented 7 years ago

alright, so i have to loop and count manually ? since im trying to get the total unread message.

13dev commented 7 years ago

you have to use getconversationByUserId()

newbielinuxuser commented 7 years ago

done