mirror of
				https://gitlab.com/comunic/comunicapiv2
				synced 2025-11-04 03:24:04 +00:00 
			
		
		
		
	Send an event when a conversation message is created
This commit is contained in:
		@@ -437,7 +437,7 @@ export class ConversationsHelper {
 | 
			
		||||
		const t = time();
 | 
			
		||||
 | 
			
		||||
		// Insert the message in the database
 | 
			
		||||
		await DatabaseHelper.InsertRow(
 | 
			
		||||
		const id = await DatabaseHelper.InsertRow(
 | 
			
		||||
			MESSAGES_TABLE,
 | 
			
		||||
			{
 | 
			
		||||
				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
 | 
			
		||||
		await DatabaseHelper.UpdateRows({
 | 
			
		||||
			table: LIST_TABLE,
 | 
			
		||||
@@ -489,6 +499,11 @@ export class ConversationsHelper {
 | 
			
		||||
		await EventsHelper.Emit("updated_number_unread_conversations", {
 | 
			
		||||
			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 { ConversationMessage } from "../entities/ConversationMessage";
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Events manager
 | 
			
		||||
@@ -19,17 +19,23 @@ export interface UpdatedNotificationsNumberEvent {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// When some users have an updated number of unread conversations
 | 
			
		||||
export interface UpdateNumberUnreadConversations {
 | 
			
		||||
export interface UpdateNumberUnreadConversationsEvent {
 | 
			
		||||
	usersID: number[]
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// When a new conversatino message is sent
 | 
			
		||||
export interface SentNewConversationMessageEvent {
 | 
			
		||||
	msg: ConversationMessage
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Global map of all possible events
 | 
			
		||||
 */
 | 
			
		||||
export interface EventsMap {
 | 
			
		||||
	"destroyed_login_tokens": DestroyedLoginTokensEvent,
 | 
			
		||||
	"updated_number_notifications": UpdatedNotificationsNumberEvent,
 | 
			
		||||
	"updated_number_unread_conversations": UpdateNumberUnreadConversations
 | 
			
		||||
	"updated_number_unread_conversations": UpdateNumberUnreadConversationsEvent,
 | 
			
		||||
	"sent_conversation_message": SentNewConversationMessageEvent
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export class EventsHelper {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user