use strict front
This commit is contained in:
parent
e3d8d3cf9b
commit
4bff5be6c1
@ -1,19 +1,19 @@
|
||||
import API from "./API";
|
||||
|
||||
export default {
|
||||
registerAccount(data) {
|
||||
registerAccount(data: object) {
|
||||
return API().post("/mail/account", data);
|
||||
},
|
||||
getAccounts() {
|
||||
return API().get("/mail/accounts");
|
||||
},
|
||||
getRooms(mailboxId) {
|
||||
getRooms(mailboxId: number) {
|
||||
return API().get(`/mail/${mailboxId}/rooms`);
|
||||
},
|
||||
getMessages(roomId) {
|
||||
getMessages(roomId: number) {
|
||||
return API().get(`/mail/${roomId}/messages`);
|
||||
},
|
||||
getMembers(roomId) {
|
||||
getMembers(roomId: number) {
|
||||
return API().get(`/mail/${roomId}/members`);
|
||||
},
|
||||
};
|
||||
|
@ -7,6 +7,10 @@ export enum RoomType {
|
||||
THREAD = 4,
|
||||
};
|
||||
|
||||
export interface Message {
|
||||
|
||||
}
|
||||
|
||||
export interface Room {
|
||||
id: number;
|
||||
roomName: string;
|
||||
@ -15,7 +19,7 @@ export interface Room {
|
||||
user: string;
|
||||
userId: number;
|
||||
unseen: number;
|
||||
messages: object[];
|
||||
messages: Message[];
|
||||
messagesFetched: boolean;
|
||||
threads: object[];
|
||||
}
|
||||
|
@ -1,8 +1,24 @@
|
||||
import API from "@/services/imapAPI";
|
||||
import { createStore, Store } from "vuex";
|
||||
import { Room, Account, Address } from "./models/model";
|
||||
import { Room, Account, Address, RoomType, Message } from "./models/model";
|
||||
|
||||
function createRoom(options): Room {
|
||||
interface RoomFromBack {
|
||||
id: number;
|
||||
roomName: string;
|
||||
roomType: RoomType;
|
||||
mailboxId: number;
|
||||
user: string;
|
||||
userId: number;
|
||||
// unseen: number;
|
||||
// todo thread
|
||||
}
|
||||
|
||||
interface AccountFromBack {
|
||||
id: number;
|
||||
email: string;
|
||||
}
|
||||
|
||||
function createRoom(options: RoomFromBack): Room {
|
||||
return {
|
||||
id: options.id,
|
||||
roomName: options.roomName,
|
||||
@ -10,7 +26,7 @@ function createRoom(options): Room {
|
||||
mailboxId: options.mailboxId,
|
||||
userId: options.userId,
|
||||
user: options.user,
|
||||
unseen: options.unseen,
|
||||
unseen: 0,
|
||||
messages: [],
|
||||
messagesFetched: false,
|
||||
threads: [],
|
||||
@ -48,13 +64,13 @@ const store = createStore<State>({
|
||||
store.dispatch("fetchMessages", { roomId: payload, room: room });
|
||||
},
|
||||
addAccounts(state, payload) {
|
||||
payload.forEach((account) => {
|
||||
payload.forEach((account: AccountFromBack) => {
|
||||
state.accounts.push({ id: account.id, email: account.email, fetched: false });
|
||||
});
|
||||
},
|
||||
addRooms(state, payload) {
|
||||
// todo add if not exist
|
||||
payload.rooms.forEach((room) => {
|
||||
payload.rooms.forEach((room: RoomFromBack) => {
|
||||
state.rooms.push(createRoom(room));
|
||||
});
|
||||
},
|
||||
@ -62,14 +78,14 @@ const store = createStore<State>({
|
||||
// todo add if not exist
|
||||
const room = state.rooms.find((room) => room.id == payload.roomId);
|
||||
if (!room) return;
|
||||
payload.messages.forEach((message) => {
|
||||
payload.messages.forEach((message: Message) => {
|
||||
room.messages.push(message);
|
||||
});
|
||||
room.messagesFetched = true;
|
||||
},
|
||||
addAddress(state, payload) {
|
||||
// todo add if not exist
|
||||
payload.addresses.forEach((address) => {
|
||||
payload.addresses.forEach((address: Address) => {
|
||||
state.addresses.push(address);
|
||||
});
|
||||
},
|
||||
@ -79,7 +95,7 @@ const store = createStore<State>({
|
||||
if (state.activeAccount === 0) return state.rooms;
|
||||
return state.rooms.filter((room) => room.mailboxId == state.activeAccount);
|
||||
},
|
||||
messages: (state) => (roomId) => {
|
||||
messages: (state) => (roomId: number) => {
|
||||
const room = state.rooms.find((room) => room.id == roomId);
|
||||
if (!room) return [];
|
||||
if (!room.messagesFetched) {
|
||||
|
@ -1,6 +1,6 @@
|
||||
export function decodeEmojis(text) {
|
||||
export function decodeEmojis(text: string): string {
|
||||
if (!text) return text;
|
||||
const regex = /\\u{([^}]+)}/g;
|
||||
const decodedText = text.replace(regex, (_, hex) => String.fromCodePoint(parseInt(hex, 16)));
|
||||
const decodedText = text.replace(regex, (_: string, hex: string) => String.fromCodePoint(parseInt(hex, 16)));
|
||||
return decodedText;
|
||||
}
|
||||
|
@ -2,7 +2,7 @@
|
||||
"compilerOptions": {
|
||||
"target": "es5",
|
||||
"module": "esnext",
|
||||
// "strict": true,
|
||||
"strict": true,
|
||||
"jsx": "preserve",
|
||||
"importHelpers": true,
|
||||
"moduleResolution": "node",
|
||||
|
Loading…
Reference in New Issue
Block a user