-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: handle
hint_(gauche|droite)
to build a dummy `MessageRecipien…
…t` type
- Loading branch information
Showing
10 changed files
with
112 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,25 @@ | ||
export enum PronoteApiUserMessageRecipientType { | ||
Teacher = 3, | ||
Student = 4 | ||
Student = 4, | ||
Personal = 34 | ||
// TODO: Find other types | ||
} | ||
|
||
export interface PronoteApiUserMessageRecipient { | ||
N: string | ||
|
||
/** Name of the recipient. */ | ||
L: string | ||
|
||
/** | ||
* Type of the recipient. | ||
* Tells whether the recipient is a teacher, student, ... | ||
*/ | ||
G: PronoteApiUserMessageRecipientType | ||
|
||
/** NOTE: Not sure what this is. */ | ||
P: number | ||
|
||
/** Whether the recipient refuses messages. */ | ||
refusMess?: boolean | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import type { PronoteApiUserMessageRecipient, PronoteApiUserMessageRecipientType } from "~/constants/recipients"; | ||
|
||
export class BaseMessageRecipient { | ||
readonly #name: string; | ||
readonly #type: PronoteApiUserMessageRecipientType; | ||
|
||
constructor (data: Omit<PronoteApiUserMessageRecipient, "N" | "P" | "refusMess">) { | ||
this.#name = data.L; | ||
this.#type = data.G; | ||
} | ||
|
||
public get name (): string { | ||
return this.#name; | ||
} | ||
|
||
public get type (): PronoteApiUserMessageRecipientType { | ||
return this.#type; | ||
} | ||
} | ||
|
||
export class FetchedMessageRecipient extends BaseMessageRecipient { | ||
readonly #id: string; | ||
readonly #refuseMessages: boolean; | ||
|
||
constructor (data: PronoteApiUserMessageRecipient) { | ||
super(data); | ||
this.#id = data.N; | ||
this.#refuseMessages = data.refusMess ?? false; | ||
} | ||
|
||
public get id (): string { | ||
return this.#id; | ||
} | ||
|
||
public get refuseMessages (): boolean { | ||
return this.#refuseMessages; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { PronoteApiUserMessageRecipientType } from "~/constants/recipients"; | ||
import { BaseMessageRecipient } from "~/parser/recipient"; | ||
|
||
export const parseHintToType = (hint: string): PronoteApiUserMessageRecipientType => { | ||
let type: PronoteApiUserMessageRecipientType; | ||
|
||
switch (hint) { | ||
case "Professeur": | ||
type = PronoteApiUserMessageRecipientType.Teacher; | ||
break; | ||
case "Personnel": | ||
type = PronoteApiUserMessageRecipientType.Personal; | ||
break; | ||
default: | ||
type = PronoteApiUserMessageRecipientType.Student; | ||
} | ||
|
||
return type; | ||
}; | ||
|
||
export const makeDummyRecipient = (name: string, type: PronoteApiUserMessageRecipientType): BaseMessageRecipient => { | ||
return new BaseMessageRecipient({ | ||
L: name, | ||
G: type | ||
}); | ||
}; |