【发布时间】:2018-07-11 17:59:35
【问题描述】:
我有一个 MESSAGE 表。
它的列是
| seq | sender_email | receiver_email | content | date | is_read | sender_profile_icon_url|
在我的 Android 应用中,我想先显示用户列表。
你可以想象一下普通的Messenger应用,比如Kakaotalk、Line、Whatsapp等。
If A ever sent a message to B OR if B ever sent a message to A.
1. A's view
B's information(email, photo) with the most recent message between
B and A must be shown in the list(MessageUserList Activity) of A.
If you click B, you see all the messages between B and A.
2. B's view
A's information(email, photo) with the most recent message between
A and B must be shown in the list(MessageUserList Activity) of A.
If you click B, you see all the messages between B and A.
所以,它看起来像这样(chanjungskim@gmail.com 的观点):
左:显示曾经发送或接收过至少一条消息的用户。
右:点击第一个用户(fman1335@gmail)后显示所有消息。
您应该知道的是,您可以向自己发送消息。然后,所有消息都会以绿色放置在右侧。
图片看起来很完美……但事实并非如此。
我对左图的尝试是......
select m3.*
from
( SELECT m1.*
from message as m1
left outer join message as m2 ON m1.sender_email = m2.sender_email
and (m1.date < m2.date
or (m1.date = m2.date
and m1.seq < m2.seq)
)
where m2.sender_email is null
) as m3
where m3.sender_email=?
or m3.receiver_email=?
order by date desc
limit 30;
我用正确的图片尝试的是......
select *
from message
where sender_email=?
or receiver_email=?
or sender_email=?
or receiver_email=?
order by date;
它带来了错误的数据。
目前的问题是
如果A和B互相发送消息,那么A、B在双方的MessageUserListActivity上。它需要分别是一个(例如 A 看到 B,B 看到 A。)。而如果 A 点击列表中的 A 用户,那么会带来错误的数据。
我不知道我需要解决什么问题。有什么问题?
【问题讨论】:
标签: android mysql sql mariadb messenger