-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6a5a585
commit d3ee1ce
Showing
11 changed files
with
118 additions
and
40 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import addHandler from "#cmd/handlePacket"; | ||
|
||
// list of all the chats of this player | ||
addHandler('chats list', (c, data) => { | ||
c.sendChatsList(); | ||
}); |
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,17 +1,29 @@ | ||
import SendStuff from "#cmd/sendStuff"; | ||
import { IMessage } from "#schemas/chat"; | ||
import Chat from "#concepts/chat"; | ||
import { IMessage, messageSerialize } from "#schemas/chat"; | ||
|
||
declare module '#cmd/sendStuff' { | ||
interface SendStuff { | ||
sendChatMessage(chat_id:string, message:IMessage):void | ||
sendChatHistory(chat_id:string, messages:IMessage[]):void | ||
sendChatInfo(chat:Chat):void | ||
sendChatsList():void | ||
} | ||
} | ||
|
||
SendStuff.prototype.sendChatMessage = function(chat_id:string, message:IMessage) { | ||
this.send({ cmd: 'chat msg', chat_id, message }); | ||
this.send({ cmd: 'chat msg', chat_id, message: messageSerialize(message) }); | ||
} | ||
|
||
SendStuff.prototype.sendChatHistory = function(chat_id:string, messages:IMessage[]) { | ||
this.send({ cmd: 'chat history', chat_id, history: messages }); | ||
// this.send({ cmd: 'chat history', chat_id, history: messages.map(m => ({ content: m.content, name: m.name, profile_id: null })) }); | ||
this.send({ cmd: 'chat history', chat_id, history: messages.map(messageSerialize) }) | ||
} | ||
|
||
SendStuff.prototype.sendChatInfo = function(chat:Chat) { | ||
this.send({ cmd: 'chat info', chat: chat.serialize() }); | ||
} | ||
|
||
SendStuff.prototype.sendChatsList = function() { | ||
this.send({ cmd: 'chats list', chats: this.chats.map(chat => chat.chat_id) }); | ||
} |
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,11 +1,21 @@ | ||
import Chat, { chatCreate } from "#concepts/chat"; | ||
import ChatLog from "#schemas/chat"; | ||
|
||
// create instances of every chat from the DB | ||
const chatLogs = await ChatLog.find({}); | ||
chatLogs.forEach(chatlog => { | ||
let chat = new Chat(chatlog); | ||
global.chats[chat.chat_id] = chat; | ||
}); | ||
|
||
|
||
// create a new id=0 "global" chat if it doesn't exist already | ||
if (global.chats['0'] === undefined) { | ||
let chatlog = new ChatLog(); | ||
chatlog._id = '0'; | ||
|
||
let chat = new Chat(chatlog); | ||
global.chats['0'] = chat; | ||
} | ||
|
||
// chatCreate([]); |
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