Chat
TsgcHTMLComponent_Chat — una messaggistica in stile WhatsApp con messaggi di testo, immagine, file, audio e video, conferme di lettura, risposte e separatori di data, in Delphi, C++ Builder e .NET.
TsgcHTMLComponent_Chat — una messaggistica in stile WhatsApp con messaggi di testo, immagine, file, audio e video, conferme di lettura, risposte e separatori di data, in Delphi, C++ Builder e .NET.
Una superficie di chat completa che emette CSS dedicato più il markup della messaggistica: un’intestazione con avatar, bolle raggruppate, spunte di stato, allegati multimediali e un campo di composizione. Aggiungi i messaggi, imposta l’intestazione, quindi leggi la proprietà HTML.
TsgcHTMLComponent_Chat
Scoped CSS + messenger markup
Delphi, C++ Builder, .NET
Imposta l’intestazione (Title, Subtitle, HeaderAvatarInitials), aggiungi messaggi di testo, immagine e file, gestisci OnSendMessage, quindi leggi 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
I membri che utilizzerai più spesso.
Messages è una collezione TsgcHTMLChat_Messages; ogni TsgcHTMLChat_Message porta Text, MessageType (text/image/file/audio/video/system), Status, ReplyToSender/ReplyToText e IsForwarded.
AddMessage, AddImageMessage, AddFileMessage e AddSystemMessage(...) aggiungono bolle; maLeft/maRight scelgono il lato.
Title, Subtitle, HeaderAvatarURL e HeaderAvatarInitials costruiscono l’intestazione della conversazione (un sottotitolo "online" aggiunge l’indicatore verde).
ShowInput, InputPlaceholder, ShowAttachButton, ShowEmojiButton, ShowTypingIndicator e TypingText regolano la barra inferiore.
Options (un TsgcHTMLChat_Options) imposta MaxBubbleWidth, i colori di bolle/sfondo, ShowTimestamp, ShowStatus, GroupConsecutive e ShowDateSeparators.
OnSendMessage si attiva quando il visitatore invia dal campo di composizione; OnMediaClick si attiva al tocco di un contenuto multimediale. HTML restituisce la chat; GetLastMessageHTML restituisce solo la bolla più recente per gli aggiornamenti live.