test unseen behavior

This commit is contained in:
grimhilt
2023-04-05 14:21:46 +02:00
parent 65631f8e9a
commit 86f321c0a1
5 changed files with 159 additions and 72 deletions

View File

@@ -1,7 +1,7 @@
import {
createRoom,
registerMessageInRoom,
isRoomGroup,
getRoomType,
findRoomsFromMessage,
hasSameMembersAsParent,
registerThread,
@@ -9,6 +9,7 @@ import {
getAllMembers,
getThreadInfo,
incrementNotSeenRoom,
getThreadInfoOnId,
} from "../db/saveMessage-db";
import { findRoomByOwner, getAddresseId, getUserIdOfMailbox } from "../db/utils/mail";
@@ -111,7 +112,6 @@ export default class RegisterMessageInApp {
// not a reply, add to the list of message if this sender
await registerMessageInRoom(this.messageId, res[0].room_id, this.envelope.date);
await this.incrementNotSeen(res[0].room_id);
}
});
}
@@ -121,27 +121,33 @@ export default class RegisterMessageInApp {
async (threadId: number) => {
// find parent room infos
let roomId: number;
let root_id: number;
await getThreadInfo(this.inReplyTo).then(async (room) => {
// todo room not lenght, reply to transfer ?
roomId = room[0].room_id;
let root_id = room[0].root_id;
root_id = room[0].root_id;
if (root_id === undefined) root_id = roomId;
await registerThread(threadId, roomId, root_id);
});
// impl register previous message or go back
await registerMessageInRoom(this.messageId, threadId, this.envelope.date);
await this.incrementNotSeen(roomId);
await this.incrementNotSeen(root_id);
await this.incrementNotSeen(threadId);
await this.registerMembers(threadId);
},
);
}
async createOrRegisterOnMembers(roomId: number) {
async createOrRegisterOnMembers(roomId: number, isThread?: boolean) {
const hasSameMembers = await hasSameMembersAsParent(this.messageId, this.inReplyTo);
if (hasSameMembers) {
await registerMessageInRoom(this.messageId, roomId, this.envelope.date);
await this.incrementNotSeen(roomId);
if (isThread) {
await getThreadInfoOnId(roomId).then(async (res) => {
await this.incrementNotSeen(res[0].root_id);
});
}
} else {
await this.initiateThread();
}
@@ -178,18 +184,17 @@ export default class RegisterMessageInApp {
} else if (rooms.length === 1) {
// only one room so message is only in a room and not in a thread
// as a thread is associated to a room
await isRoomGroup(rooms[0].room_id).then(async (isGroup: boolean) => {
if (isGroup) {
this.createOrRegisterOnMembers(rooms[0].room_id);
} else {
// reply from CHANNEL or DM or ROOM
await this.initiateThread();
// todo
// if (sender == owner) { // correction from the original sender
// // leave in the same channel
// }
}
});
const roomType = (await getRoomType(rooms[0].room_id))[0].room_type;
if (roomType == RoomType.GROUP || roomType == RoomType.THREAD) {
await this.createOrRegisterOnMembers(rooms[0].room_id, roomType == RoomType.THREAD);
} else {
// reply from CHANNEL or DM or ROOM
await this.initiateThread();
// todo
// if (sender == owner) { // correction from the original sender
// // leave in the same channel
// }
}
} else if (rooms.length > 1) {
// get the lowest thread (order by room_id)
const roomId = rooms[rooms.length - 1].room_id;