mirror of
https://github.com/sp-tarkov/server.git
synced 2025-02-13 09:50:43 -05:00
Handle additional events: ignore/set and ignore/remove
Pass full request object generateDialogueView instead of just id Handle case when getting dialogue from profile that does not exist Improve `getMessagePreview()` nullguard properties that may be missing
This commit is contained in:
parent
295ed59739
commit
965e3efbc7
@ -90,7 +90,7 @@ export class DialogueCallbacks implements OnUpdate
|
|||||||
/** Handle client/mail/dialog/view */
|
/** Handle client/mail/dialog/view */
|
||||||
public getMailDialogView(url: string, info: IGetMailDialogViewRequestData, sessionID: string): IGetBodyResponseData<IGetMailDialogViewResponseData>
|
public getMailDialogView(url: string, info: IGetMailDialogViewRequestData, sessionID: string): IGetBodyResponseData<IGetMailDialogViewResponseData>
|
||||||
{
|
{
|
||||||
return this.httpResponse.getBody(this.dialogueController.generateDialogueView(info.dialogId, sessionID));
|
return this.httpResponse.getBody(this.dialogueController.generateDialogueView(info, sessionID));
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Handle client/mail/dialog/info */
|
/** Handle client/mail/dialog/info */
|
||||||
@ -136,6 +136,12 @@ export class DialogueCallbacks implements OnUpdate
|
|||||||
return this.httpResponse.getBody(this.dialogueController.getAllAttachments(info.dialogId, sessionID));
|
return this.httpResponse.getBody(this.dialogueController.getAllAttachments(info.dialogId, sessionID));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Handle client/mail/msg/send */
|
||||||
|
public sendMessage(url: string, request: ISendMessageRequest, sessionID: string): IGetBodyResponseData<string>
|
||||||
|
{
|
||||||
|
return this.httpResponse.getBody(this.dialogueController.sendMessage(sessionID, request));
|
||||||
|
}
|
||||||
|
|
||||||
/** Handle client/friend/request/list/outbox */
|
/** Handle client/friend/request/list/outbox */
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
public listOutbox(url: string, info: IEmptyRequestData, sessionID: string): IGetBodyResponseData<any[]>
|
public listOutbox(url: string, info: IEmptyRequestData, sessionID: string): IGetBodyResponseData<any[]>
|
||||||
@ -188,9 +194,16 @@ export class DialogueCallbacks implements OnUpdate
|
|||||||
|
|
||||||
/** Handle client/friend/ignore/set */
|
/** Handle client/friend/ignore/set */
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
public sendMessage(url: string, request: ISendMessageRequest, sessionID: string): IGetBodyResponseData<number>
|
public ignoreFriend(url: string, request: {uid: string}, sessionID: string): any
|
||||||
{
|
{
|
||||||
return this.httpResponse.getBody(1);
|
return this.httpResponse.nullResponse();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Handle client/friend/ignore/set */
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
|
public unIgnoreFriend(url: string, request: {uid: string}, sessionID: string): any
|
||||||
|
{
|
||||||
|
return this.httpResponse.nullResponse();
|
||||||
}
|
}
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
|
@ -3,10 +3,12 @@ import { inject, injectable } from "tsyringe";
|
|||||||
import { DialogueHelper } from "../helpers/DialogueHelper";
|
import { DialogueHelper } from "../helpers/DialogueHelper";
|
||||||
import { IGetAllAttachmentsResponse } from "../models/eft/dialog/IGetAllAttachmentsResponse";
|
import { IGetAllAttachmentsResponse } from "../models/eft/dialog/IGetAllAttachmentsResponse";
|
||||||
import { IGetFriendListDataResponse } from "../models/eft/dialog/IGetFriendListDataResponse";
|
import { IGetFriendListDataResponse } from "../models/eft/dialog/IGetFriendListDataResponse";
|
||||||
|
import { IGetMailDialogViewRequestData } from "../models/eft/dialog/IGetMailDialogViewRequestData";
|
||||||
import {
|
import {
|
||||||
IGetMailDialogViewResponseData
|
IGetMailDialogViewResponseData
|
||||||
} from "../models/eft/dialog/IGetMailDialogViewResponseData";
|
} from "../models/eft/dialog/IGetMailDialogViewResponseData";
|
||||||
import { DialogueInfo, IAkiProfile, IUserDialogInfo, Message } from "../models/eft/profile/IAkiProfile";
|
import { ISendMessageRequest } from "../models/eft/dialog/ISendMessageRequest";
|
||||||
|
import { Dialogue, DialogueInfo, IAkiProfile, IUserDialogInfo, Message } from "../models/eft/profile/IAkiProfile";
|
||||||
import { MemberCategory } from "../models/enums/MemberCategory";
|
import { MemberCategory } from "../models/enums/MemberCategory";
|
||||||
import { MessageType } from "../models/enums/MessageType";
|
import { MessageType } from "../models/enums/MessageType";
|
||||||
import { SaveServer } from "../servers/SaveServer";
|
import { SaveServer } from "../servers/SaveServer";
|
||||||
@ -42,12 +44,12 @@ export class DialogueController
|
|||||||
return {
|
return {
|
||||||
"Friends": [
|
"Friends": [
|
||||||
{
|
{
|
||||||
_id: "123456789abc",
|
_id: "sptfriend",
|
||||||
Info: {
|
Info: {
|
||||||
Level: 1,
|
Level: 1,
|
||||||
MemberCategory: MemberCategory.DEVELOPER,
|
MemberCategory: MemberCategory.DEVELOPER,
|
||||||
Nickname: "SPT",
|
Nickname: "SPT",
|
||||||
Side: "usec"
|
Side: "Usec"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
@ -102,18 +104,20 @@ export class DialogueController
|
|||||||
* Handle player clicking 'messenger' and seeing all the messages they've recieved
|
* Handle player clicking 'messenger' and seeing all the messages they've recieved
|
||||||
* Set the content of the dialogue on the details panel, showing all the messages
|
* Set the content of the dialogue on the details panel, showing all the messages
|
||||||
* for the specified dialogue.
|
* for the specified dialogue.
|
||||||
* @param dialogueID Dialog id
|
* @param request Get dialog request
|
||||||
* @param sessionID Session id
|
* @param sessionId Session id
|
||||||
* @returns IGetMailDialogViewResponseData object
|
* @returns IGetMailDialogViewResponseData object
|
||||||
*/
|
*/
|
||||||
public generateDialogueView(dialogueID: string, sessionID: string): IGetMailDialogViewResponseData
|
public generateDialogueView(request: IGetMailDialogViewRequestData, sessionId: string): IGetMailDialogViewResponseData
|
||||||
{
|
{
|
||||||
const profile = this.saveServer.getProfile(sessionID);
|
const dialogueId = request.dialogId;
|
||||||
const dialogue = profile.dialogues[dialogueID];
|
const profile = this.saveServer.getProfile(sessionId);
|
||||||
|
const dialogue = this.getDialogByIdFromProfile(profile, request);
|
||||||
|
|
||||||
dialogue.new = 0;
|
dialogue.new = 0;
|
||||||
|
|
||||||
// Set number of new attachments, but ignore those that have expired.
|
// Set number of new attachments, but ignore those that have expired.
|
||||||
dialogue.attachmentsNew = this.getUnreadMessagesWithAttachmentsCount(sessionID, dialogueID);
|
dialogue.attachmentsNew = this.getUnreadMessagesWithAttachmentsCount(sessionId, dialogueId);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
messages: dialogue.messages,
|
messages: dialogue.messages,
|
||||||
@ -122,6 +126,43 @@ export class DialogueController
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get dialog from player profile, create if doesn't exist
|
||||||
|
* @param profile Player profile
|
||||||
|
* @param request get dialog request (params used when dialog doesnt exist in profile)
|
||||||
|
* @returns Dialogue
|
||||||
|
*/
|
||||||
|
protected getDialogByIdFromProfile(profile: IAkiProfile, request: IGetMailDialogViewRequestData): Dialogue
|
||||||
|
{
|
||||||
|
if (!profile.dialogues[request.dialogId])
|
||||||
|
{
|
||||||
|
profile.dialogues[request.dialogId] = {
|
||||||
|
_id: request.dialogId,
|
||||||
|
attachmentsNew: 0,
|
||||||
|
pinned: false,
|
||||||
|
messages: [],
|
||||||
|
new: 0,
|
||||||
|
type: request.type
|
||||||
|
};
|
||||||
|
|
||||||
|
if (request.type === MessageType.USER_MESSAGE)
|
||||||
|
{
|
||||||
|
profile.dialogues[request.dialogId].Users = [];
|
||||||
|
profile.dialogues[request.dialogId].Users.push({
|
||||||
|
_id: request.dialogId,
|
||||||
|
info: {
|
||||||
|
Level:1,
|
||||||
|
Nickname: "SPT",
|
||||||
|
Side: "Usec",
|
||||||
|
MemberCategory: MemberCategory.DEFAULT
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return profile.dialogues[request.dialogId];
|
||||||
|
}
|
||||||
|
|
||||||
protected getProfilesForMail(pmcProfile: IAkiProfile, dialogUsers: IUserDialogInfo[]): IUserDialogInfo[]
|
protected getProfilesForMail(pmcProfile: IAkiProfile, dialogUsers: IUserDialogInfo[]): IUserDialogInfo[]
|
||||||
{
|
{
|
||||||
const result: IUserDialogInfo[] = [];
|
const result: IUserDialogInfo[] = [];
|
||||||
@ -218,6 +259,41 @@ export class DialogueController
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** client/mail/msg/send */
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
|
public sendMessage(sessionId: string, request: ISendMessageRequest): string
|
||||||
|
{
|
||||||
|
const profile = this.saveServer.getProfile(sessionId);
|
||||||
|
const dialog = profile.dialogues[request.dialogId];
|
||||||
|
dialog.messages.push({
|
||||||
|
_id: sessionId,
|
||||||
|
dt: this.timeUtil.getTimestamp(),
|
||||||
|
hasRewards: false,
|
||||||
|
items: {},
|
||||||
|
uid: sessionId,
|
||||||
|
type: MessageType.USER_MESSAGE,
|
||||||
|
rewardCollected: false,
|
||||||
|
text: request.text
|
||||||
|
});
|
||||||
|
|
||||||
|
if (request.dialogId.includes("sptfriend") && request.text.includes("love you"))
|
||||||
|
{
|
||||||
|
dialog.messages.push({
|
||||||
|
_id: "sptfriend",
|
||||||
|
dt: this.timeUtil.getTimestamp()+1,
|
||||||
|
hasRewards: false,
|
||||||
|
items: {},
|
||||||
|
uid: "sptfriend",
|
||||||
|
type: MessageType.USER_MESSAGE,
|
||||||
|
rewardCollected: false,
|
||||||
|
text: "i love you too buddy :3"
|
||||||
|
});
|
||||||
|
dialog.new = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return request.dialogId;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get messages from a specific dialog that have items not expired
|
* Get messages from a specific dialog that have items not expired
|
||||||
* @param sessionId Session id
|
* @param sessionId Session id
|
||||||
|
@ -161,18 +161,18 @@ export class DialogueHelper
|
|||||||
// The last message of the dialogue should be shown on the preview.
|
// The last message of the dialogue should be shown on the preview.
|
||||||
const message = dialogue.messages[dialogue.messages.length - 1];
|
const message = dialogue.messages[dialogue.messages.length - 1];
|
||||||
const result: MessagePreview = {
|
const result: MessagePreview = {
|
||||||
dt: message.dt,
|
dt: message?.dt,
|
||||||
type: message.type,
|
type: message?.type,
|
||||||
templateId: message.templateId,
|
templateId: message?.templateId,
|
||||||
uid: dialogue._id
|
uid: dialogue._id
|
||||||
};
|
};
|
||||||
|
|
||||||
if (message.text)
|
if (message?.text)
|
||||||
{
|
{
|
||||||
result.text = message.text;
|
result.text = message.text;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (message.systemData)
|
if (message?.systemData)
|
||||||
{
|
{
|
||||||
result.systemData = message.systemData;
|
result.systemData = message.systemData;
|
||||||
}
|
}
|
||||||
|
@ -163,6 +163,22 @@ export class DialogStaticRouter extends StaticRouter
|
|||||||
{
|
{
|
||||||
return this.dialogueCallbacks.deleteFriend(url, info, sessionID);
|
return this.dialogueCallbacks.deleteFriend(url, info, sessionID);
|
||||||
}
|
}
|
||||||
|
),
|
||||||
|
new RouteAction(
|
||||||
|
"/client/friend/ignore/set",
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
|
(url: string, info: any, sessionID: string, output: string): any =>
|
||||||
|
{
|
||||||
|
return this.dialogueCallbacks.ignoreFriend(url, info, sessionID);
|
||||||
|
}
|
||||||
|
),
|
||||||
|
new RouteAction(
|
||||||
|
"/client/friend/ignore/remove",
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
|
(url: string, info: any, sessionID: string, output: string): any =>
|
||||||
|
{
|
||||||
|
return this.dialogueCallbacks.unIgnoreFriend(url, info, sessionID);
|
||||||
|
}
|
||||||
)
|
)
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user