connectycube-reactnative-samples icon indicating copy to clipboard operation
connectycube-reactnative-samples copied to clipboard

Want total count

Open itsArfinn opened this issue 2 years ago • 1 comments
trafficstars

Hi, i just want to get the count of message received and send by user, and also outgoing and received calls

itsArfinn avatar Aug 08 '23 05:08 itsArfinn

Hi, @itsArfinn

It is an uncommon thing. Usually, we need to know the amount of unread messages for each dialog. The "want to get the count of message received and send by user" sounds a little strange because it is not clear why this is necessary.

For messages, you should retrieve all dialogs and then all messages for each dialog. Those requests to API have a pagination limit - 100 dialog/messagesю. This can cause a lot of requests at one time.

  • https://developers.connectycube.com/reactnative/messaging?id=list-dialogs
  • https://developers.connectycube.com/reactnative/messaging?id=chat-history A message has the property "sender_id". A message is sent by you if the "sender_id" == "session.user_id" (current user id). Other messages are received messages.

The calls isn't a server implementation. It is WebRTC API. So, it doesn't store history in the server DB. To make the calls history I recommend using the Custom objects API (https://developers.connectycube.com/server/custom_objects?id=custom-objects-api). You can create records depending on call's event and then read them and count the "outgoing and received calls". Then get records and filter to count. For example, after the class (e.g. "CallsHistory") with fields have a prepared scheme:

const CustomObjectClassName = "CallsHistory";
const createData = {
  from: 100001, // user ID
  to: 100002, // user ID
  media: 'video', // video/audio
  duration: 42, // seconds
  type: 'missed' // incoming/outgoing/missed/no_answer, etc.
};
const filters = ...
const updateData = ...
const deleteData = ...

const createResult = await ConnectyCube.data.create(CustomObjectClassName, createData);
const listResult = await ConnectyCube.data.list(CustomObjectClassName, filters);
const updateResult = await ConnectyCube.data.update(CustomObjectClassName, updateData);
const deleteResult = await ConnectyCube.data.delete(CustomObjectClassName, deleteData);

ccvlad avatar Aug 08 '23 10:08 ccvlad