Chat
TsgcHTMLComponent_Chat — un mensajero estilo WhatsApp con mensajes de texto, imagen, archivo, audio y vídeo, confirmaciones de lectura, respuestas y separadores de fecha, en Delphi, C++ Builder y .NET.
TsgcHTMLComponent_Chat — un mensajero estilo WhatsApp con mensajes de texto, imagen, archivo, audio y vídeo, confirmaciones de lectura, respuestas y separadores de fecha, en Delphi, C++ Builder y .NET.
Una superficie de chat completa que emite CSS con ámbito más el marcado del mensajero: una cabecera con avatar, burbujas agrupadas, marcas de estado, adjuntos multimedia y un redactor. Añade mensajes, define la cabecera y luego lee la propiedad HTML.
TsgcHTMLComponent_Chat
CSS con ámbito + marcado del mensajero
Delphi, C++ Builder, .NET
Define la cabecera (Title, Subtitle, HeaderAvatarInitials), añade mensajes de texto, imagen y archivo, gestiona OnSendMessage y luego lee HTML.
uses
sgcHTML_Enums, sgcHTML_Component_Chat;
var
oChat: TsgcHTMLComponent_Chat;
begin
oChat := TsgcHTMLComponent_Chat.Create(nil);
try
oChat.Title := 'Alice Johnson';
oChat.Subtitle := 'online';
oChat.HeaderAvatarInitials := 'AJ';
oChat.Height := '500px';
oChat.ShowTypingIndicator := True;
oChat.OnSendMessage := DoSendMessage; // browser -> your code
oChat.AddSystemMessage('Today');
oChat.AddMessage('Alice', 'Hey! Did you get the file?', maLeft);
oChat.AddImageMessage('You', '/img/receipt.png', maRight,
hcPrimary, 'Here it is');
oChat.AddFileMessage('You', '/files/report.pdf',
'report.pdf', '248 KB', maRight);
WebModule.Response := oChat.HTML; // messenger markup + scoped CSS
finally
oChat.Free;
end;
end;
// OnSendMessage fires when the visitor submits the composer:
procedure TForm1.DoSendMessage(Sender: TObject; const aMessage: string);
begin
oChat.AddMessage('You', aMessage, maRight, hcPrimary);
WebSocket.WriteData(oChat.GetLastMessageHTML);
end;
// includes: sgcHTML_Enums.hpp, sgcHTML_Component_Chat.hpp
TsgcHTMLComponent_Chat *oChat = new TsgcHTMLComponent_Chat(NULL);
try
{
oChat->Title = "Alice Johnson";
oChat->Subtitle = "online";
oChat->HeaderAvatarInitials = "AJ";
oChat->Height = "500px";
oChat->ShowTypingIndicator = true;
oChat->OnSendMessage = DoSendMessage; // browser -> your code
oChat->AddSystemMessage("Today");
oChat->AddMessage("Alice", "Hey! Did you get the file?", maLeft);
oChat->AddImageMessage("You", "/img/receipt.png", maRight,
hcPrimary, "Here it is");
oChat->AddFileMessage("You", "/files/report.pdf",
"report.pdf", "248 KB", maRight);
String html = oChat->HTML; // messenger markup + scoped CSS
}
__finally
{
delete oChat;
}
using esegece.sgcWebSockets;
var chat = new TsgcHTMLComponent_Chat();
chat.Title = "Alice Johnson";
chat.Subtitle = "online";
chat.HeaderAvatarInitials = "AJ";
chat.Height = "500px";
chat.ShowTypingIndicator = true;
chat.OnSendMessage += (sender, message) => // browser -> your code
{
chat.AddMessage("You", message, TsgcHTMLChatMessageAlign.maRight, TsgcHTMLColor.hcPrimary);
};
chat.AddSystemMessage("Today");
chat.AddMessage("Alice", "Hey! Did you get the file?", TsgcHTMLChatMessageAlign.maLeft);
chat.AddImageMessage("You", "/img/receipt.png", TsgcHTMLChatMessageAlign.maRight,
TsgcHTMLColor.hcPrimary, "Here it is");
chat.AddFileMessage("You", "/files/report.pdf",
"report.pdf", "248 KB", TsgcHTMLChatMessageAlign.maRight);
string html = chat.HTML; // messenger markup + scoped CSS
Los miembros que más vas a usar.
Messages es una colección TsgcHTMLChat_Messages; cada TsgcHTMLChat_Message lleva Text, MessageType (texto/imagen/archivo/audio/vídeo/sistema), Status, ReplyToSender/ReplyToText e IsForwarded.
AddMessage, AddImageMessage, AddFileMessage y AddSystemMessage(...) añaden burbujas; maLeft/maRight eligen el lado.
Title, Subtitle, HeaderAvatarURL y HeaderAvatarInitials construyen la cabecera de la conversación (un subtítulo "online" añade el punto verde).
ShowInput, InputPlaceholder, ShowAttachButton, ShowEmojiButton, ShowTypingIndicator y TypingText ajustan la barra inferior.
Options (un TsgcHTMLChat_Options) define MaxBubbleWidth, los colores de burbuja/fondo, ShowTimestamp, ShowStatus, GroupConsecutive y ShowDateSeparators.
OnSendMessage se dispara cuando el visitante envía el redactor; OnMediaClick se dispara al pulsar un elemento multimedia. HTML devuelve el chat; GetLastMessageHTML devuelve solo la burbuja más reciente para envíos en vivo.