mirror of
https://gitlab.com/comunic/comunicapiv2
synced 2024-11-22 05:19:22 +00:00
Send an event when a conversation message is created
This commit is contained in:
parent
f69271d42f
commit
a1194312de
@ -437,7 +437,7 @@ export class ConversationsHelper {
|
|||||||
const t = time();
|
const t = time();
|
||||||
|
|
||||||
// Insert the message in the database
|
// Insert the message in the database
|
||||||
await DatabaseHelper.InsertRow(
|
const id = await DatabaseHelper.InsertRow(
|
||||||
MESSAGES_TABLE,
|
MESSAGES_TABLE,
|
||||||
{
|
{
|
||||||
conv_id: message.convID,
|
conv_id: message.convID,
|
||||||
@ -448,6 +448,16 @@ export class ConversationsHelper {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Generate full message info
|
||||||
|
const newMessage = new ConversationMessage({
|
||||||
|
id: id,
|
||||||
|
timeSent: t,
|
||||||
|
userID: message.userID,
|
||||||
|
convID: message.convID,
|
||||||
|
message: message.message,
|
||||||
|
imagePath: message.imagePath
|
||||||
|
});
|
||||||
|
|
||||||
// Update the last activity of the conversation
|
// Update the last activity of the conversation
|
||||||
await DatabaseHelper.UpdateRows({
|
await DatabaseHelper.UpdateRows({
|
||||||
table: LIST_TABLE,
|
table: LIST_TABLE,
|
||||||
@ -489,6 +499,11 @@ export class ConversationsHelper {
|
|||||||
await EventsHelper.Emit("updated_number_unread_conversations", {
|
await EventsHelper.Emit("updated_number_unread_conversations", {
|
||||||
usersID: listToNotify
|
usersID: listToNotify
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// Notify about newly created message
|
||||||
|
await EventsHelper.Emit("sent_conversation_message", {
|
||||||
|
msg: newMessage
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { EventEmitter } from "events";
|
|
||||||
import { APIClient } from "../entities/APIClient";
|
import { APIClient } from "../entities/APIClient";
|
||||||
|
import { ConversationMessage } from "../entities/ConversationMessage";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Events manager
|
* Events manager
|
||||||
@ -19,17 +19,23 @@ export interface UpdatedNotificationsNumberEvent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// When some users have an updated number of unread conversations
|
// When some users have an updated number of unread conversations
|
||||||
export interface UpdateNumberUnreadConversations {
|
export interface UpdateNumberUnreadConversationsEvent {
|
||||||
usersID: number[]
|
usersID: number[]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// When a new conversatino message is sent
|
||||||
|
export interface SentNewConversationMessageEvent {
|
||||||
|
msg: ConversationMessage
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Global map of all possible events
|
* Global map of all possible events
|
||||||
*/
|
*/
|
||||||
export interface EventsMap {
|
export interface EventsMap {
|
||||||
"destroyed_login_tokens": DestroyedLoginTokensEvent,
|
"destroyed_login_tokens": DestroyedLoginTokensEvent,
|
||||||
"updated_number_notifications": UpdatedNotificationsNumberEvent,
|
"updated_number_notifications": UpdatedNotificationsNumberEvent,
|
||||||
"updated_number_unread_conversations": UpdateNumberUnreadConversations
|
"updated_number_unread_conversations": UpdateNumberUnreadConversationsEvent,
|
||||||
|
"sent_conversation_message": SentNewConversationMessageEvent
|
||||||
}
|
}
|
||||||
|
|
||||||
export class EventsHelper {
|
export class EventsHelper {
|
||||||
|
Loading…
Reference in New Issue
Block a user