When adding a new contact or joining a tribe, that contact/tribe should show at top of the chat list on apps, but on some cases it doesn't happen.
Chat list order: the chat list order is defined considering the following:
Last message date (if exists)
contact or tribe created_at value coming from relay
Initially this was enough to have the contacts and tribes showing at top of the list just after created/joined, but after some feature additions these issues come up
Issues:
Tribes: when joining a tribe the member gets the history of last 40 or so messages through MQTT. If the last message on that tribe is from 1 week ago for example, then that last message date will be considered on the order and the tribe will move way down on the list: this can be easily fixed from the app considering the most recent date between last_message.date and chat.created_at and not just the last_message.date if exists
Contacts: When we implemented tribes we added a new column on sphinx_contacts table with name from_group. So contacts created on relay because they are members on a tribe you are admin of, or admin of tribes you joined will have from_group=true initially, which will prevent them to show on your apps (even when they exist on relay db). If you want to add that contact as a real contact later, relay will find it on the db and will just update from_group to false. On this specific case the created_at value will be on the past and the contact that now is visible on the apps will be way down on the chat list as well (because there won't be messages, then the created_at value will be considered for the order).
One way to fix this would be updating the created_at value of a contact when creating it if the contact was already there as from_group=true. But that doesn't seem the right approach since we will be changing a value that could be needed in the future.
Solution:
Add new column on relay: order_date / Date type on sphinx_contacts table
Set that column to Now() when a contact is created or when a from_group contact becomes from_group=false
Apps will get this value from relay on each contact and the order will be done using the more recent date from: created_at, order_date and last_message.date
When adding a new contact or joining a tribe, that contact/tribe should show at top of the chat list on apps, but on some cases it doesn't happen.
Chat list order: the chat list order is defined considering the following:
date
(if exists)created_at
value coming from relayInitially this was enough to have the contacts and tribes showing at top of the list just after created/joined, but after some feature additions these issues come up
Issues:
last_message.date
andchat.created_at
and not just thelast_message.date
if existssphinx_contacts
table with namefrom_group
. So contacts created on relay because they are members on a tribe you are admin of, or admin of tribes you joined will havefrom_group=true
initially, which will prevent them to show on your apps (even when they exist on relay db). If you want to add that contact as a real contact later, relay will find it on the db and will just updatefrom_group
tofalse
. On this specific case thecreated_at
value will be on the past and the contact that now is visible on the apps will be way down on the chat list as well (because there won't be messages, then thecreated_at
value will be considered for the order).One way to fix this would be updating the
created_at
value of a contact when creating it if the contact was already there asfrom_group=true
. But that doesn't seem the right approach since we will be changing a value that could be needed in the future.Solution:
order_date / Date type
onsphinx_contacts
tablefrom_group
contact becomesfrom_group=false
created_at
,order_date
andlast_message.date