Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: unread mention [WPB-5786] #2663

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,12 @@ DELETE FROM UnreadEvent WHERE id = ? AND conversation_id = ?;
deleteUnreadEvents:
DELETE FROM UnreadEvent WHERE creation_date <= ? AND conversation_id = ?;

insertEvent:
INSERT OR IGNORE INTO UnreadEvent(id, type, conversation_id, creation_date)
VALUES(?, ?, ?, ?);

updateEvent:
UPDATE OR IGNORE UnreadEvent
SET type = :type
WHERE id = :id AND conversation_id = :conversation_id;
upsertEvent:
INSERT INTO UnreadEvent(id, type, conversation_id, creation_date)
VALUES (?, ?, ?, ?)
ON CONFLICT(id, conversation_id) DO UPDATE SET
type = excluded.type,
creation_date = excluded.creation_date;

getUnreadEvents:
SELECT conversation_id, type FROM UnreadEvent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@ internal class MessageDAOImpl internal constructor(
queries.markMessageAsEdited(editTimeStamp.toInstant(), currentMessageId, conversationId)
reactionsQueries.deleteAllReactionsForMessage(currentMessageId, conversationId)
queries.deleteMessageMentions(currentMessageId, conversationId)
unreadEventsQueries.deleteUnreadEvent(currentMessageId, conversationId)
queries.updateMessageTextContent(newTextContent.messageBody, currentMessageId, conversationId)
newTextContent.mentions.forEach {
queries.insertMessageMention(
Expand All @@ -343,14 +344,15 @@ internal class MessageDAOImpl internal constructor(
)
}
val selfMention = newTextContent.mentions.firstNotNullOfOrNull { it.userId == selfUserId }
if (selfMention != null) {
unreadEventsQueries.updateEvent(UnreadEventTypeEntity.MENTION, currentMessageId, conversationId)
} else {
unreadEventsQueries.updateEvent(UnreadEventTypeEntity.MESSAGE, currentMessageId, conversationId)
}

queries.updateMessageId(newMessageId, currentMessageId, conversationId)
queries.updateQuotedMessageId(newMessageId, currentMessageId, conversationId)

if (selfMention != null) {
unreadEventsQueries.upsertEvent(newMessageId, UnreadEventTypeEntity.MENTION, conversationId, editTimeStamp.toInstant())
} else {
unreadEventsQueries.upsertEvent(newMessageId, UnreadEventTypeEntity.MESSAGE, conversationId, editTimeStamp.toInstant())
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ internal class MessageInsertExtensionImpl(

if (!message.isSelfMessage && message.date > lastRead) {
when (message.content) {
is MessageEntityContent.Knock -> unreadEventsQueries.insertEvent(
is MessageEntityContent.Knock -> unreadEventsQueries.upsertEvent(
message.id,
UnreadEventTypeEntity.KNOCK,
message.conversationId,
Expand All @@ -324,14 +324,14 @@ internal class MessageInsertExtensionImpl(
is MessageEntityContent.RestrictedAsset,
is MessageEntityContent.Composite,
is MessageEntityContent.Location,
is MessageEntityContent.FailedDecryption -> unreadEventsQueries.insertEvent(
is MessageEntityContent.FailedDecryption -> unreadEventsQueries.upsertEvent(
message.id,
UnreadEventTypeEntity.MESSAGE,
message.conversationId,
message.date
)

MessageEntityContent.MissedCall -> unreadEventsQueries.insertEvent(
MessageEntityContent.MissedCall -> unreadEventsQueries.upsertEvent(
message.id,
UnreadEventTypeEntity.MISSED_CALL,
message.conversationId,
Expand Down Expand Up @@ -377,22 +377,22 @@ internal class MessageInsertExtensionImpl(
isQuotingSelfUser = senderId == selfUserIDEntity
}
when {
isQuotingSelfUser -> unreadEventsQueries.insertEvent(
isQuotingSelfUser -> unreadEventsQueries.upsertEvent(
message.id,
UnreadEventTypeEntity.REPLY,
message.conversationId,
message.date
)

textContent.mentions.map { it.userId }.contains(selfUserIDEntity) ->
unreadEventsQueries.insertEvent(
unreadEventsQueries.upsertEvent(
message.id,
UnreadEventTypeEntity.MENTION,
message.conversationId,
message.date
)

else -> unreadEventsQueries.insertEvent(
else -> unreadEventsQueries.upsertEvent(
message.id,
UnreadEventTypeEntity.MESSAGE,
message.conversationId,
Expand Down
Loading