I’m trying to create a chat system. I want to show the number of new messages (unread). Each time a user reads a message, I update a field called readTime
with the current time. This way I can count the number of messages that come after that time.
There can be multiple channels in a group. I would like to show the number of unread messages for each channel based on the readTime of each channel. Also, I would like to show the total number of unread messages for the entire group.
The following query works when there is a single channel in the group and errors when there is more:
gt expects only 1 argument. Got: [ ]
Any suggestions would be appreciated!
{
q(func: type(ChannelMember))
@filter(uid_in(ChannelMember.group,0x3347bd) and uid_in(ChannelMember.user,0x2e631)) {
readTime : RT as ChannelMember.readTime
channel : ChannelMember.channel {
uid
newMessages : count(Channel.messages) @filter(gt(Message.createdAt,val(RT)))
messages : Channel.messages (first: 1, orderdesc: Message.createdAt) {
id : uid
author : Message.author {
id : uid
}
msg : Message.msg
createdAt : Message.createdAt
}
members : Channel.members {
id : uid
user : ChannelMember.user {
id : uid
firstName : User.firstName
lastName : User.lastName
photoURL : User.photoURL
}
joined : ChannelMember.joined
}
}
}
}