1 // This module handles instant message related functions.
3 // Copyright (c) 1996-2023 by the citadel.org team
5 // This program is open source software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License, version 3.
8 // This program is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
15 // display the form for paging (x-messaging) another user
16 void display_page(void) {
19 strcpy(recp, bstr("recp"));
21 output_headers(1, 1, 1, 0, 0, 0);
22 wc_printf("<div id=\"room_banner_override\">\n");
24 wc_printf(_("Send instant message"));
26 wc_printf("</div>\n");
28 wc_printf("<div id=\"content\" class=\"service\">\n");
30 wc_printf("<table class=\"paging_background\"><tr><td>\n");
32 wc_printf(_("Send an instant message to: "));
36 wc_printf("<FORM METHOD=\"POST\" action=\"page_user\">\n");
37 wc_printf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WC->nonce);
38 wc_printf("<input type=\"hidden\" name=\"template\" value=\"who\">\n");
40 wc_printf("<TABLE border=0 width=100%%><TR><TD>\n");
42 wc_printf("<INPUT TYPE=\"hidden\" NAME=\"recp\" VALUE=\"");
46 wc_printf(_("Enter message text:"));
49 wc_printf("<TEXTAREA NAME=\"msgtext\" wrap=soft ROWS=5 COLS=40 "
50 "WIDTH=40></TEXTAREA>\n");
52 wc_printf("</TD></TR></TABLE><br>\n");
54 wc_printf("<INPUT TYPE=\"submit\" NAME=\"send_button\" VALUE=\"%s\">", _("Send message"));
55 wc_printf("<br><a href=\"javascript:window.close();\"%s</A>\n", _("Cancel"));
57 wc_printf("</FORM></CENTER>\n");
58 wc_printf("</td></tr></table>\n");
64 void page_user(void) {
68 safestrncpy(recp, bstr("recp"), sizeof recp);
70 if (!havebstr("send_button")) {
71 AppendImportantMessage(_("Message was not sent."), -1);
75 serv_printf("SEXP %s|-", recp);
76 StrBuf_ServGetln(Line);
77 if (GetServerStatusMsg(Line, NULL, 0, 0) == 4) {
79 text_to_server(bstr("msgtext"));
81 stresc(buf, 256, recp, 0, 0);
82 AppendImportantMessage(buf, -1);
83 AppendImportantMessage(_("Message has been sent to "), -1);
92 // If there are instant messages waiting, and we notice that we haven't checked them in
93 // a while, it probably means that we need to open the instant messenger window.
94 int Conditional_PAGE_WAITING(StrBuf *Target, WCTemplputParams *TP) {
98 // JavaScript function to alert the user that popups are probably blocked
99 // First, do the check as part of our page load.
101 len = serv_getln(buf, sizeof buf);
102 if ((len >= 3) && (buf[3] == '*')) {
103 if ((time(NULL) - WC->last_pager_check) > 60) {
108 // Then schedule it to happen again a minute from now if the user is idle.
112 void ajax_send_instant_message(void) {
116 safestrncpy(recp, bstr("recp"), sizeof recp);
118 serv_printf("SEXP %s|-", recp);
119 serv_getln(buf, sizeof buf);
122 text_to_server(bstr("msg"));
126 escputs(buf); // doesn't really matter what we return - the client ignores it
134 WebcitAddUrlHandler(HKEY("display_page"), "", 0, display_page, 0);
135 WebcitAddUrlHandler(HKEY("page_user"), "", 0, page_user, 0);
136 WebcitAddUrlHandler(HKEY("ajax_send_instant_message"), "", 0, ajax_send_instant_message, AJAX);
137 RegisterConditional("COND:PAGE:WAITING", 0, Conditional_PAGE_WAITING, CTX_NONE);
142 SessionDestroyModule_PAGING
145 /* nothing here anymore */