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