Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

64
LINES

< > BotCompany Repo | #1019644 // Private Chat [Dyn Module]

JavaX source code (Dynamic Module) [tags: use-pretranspiled] - run with: Stefan's OS

Uses 1113K of libraries. Click here for Pure Java version (12231L/64K).

1  
!7
2  
3  
cmodule2 PrivateChat > DynPrintLog {
4  
  S receiver, msg;
5  
  bool sign, verifyBeforeSend;
6  
  transient StefansOS_ConnectToServer connector;
7  
  
8  
  S switchableFields() { ret 'verifyBeforeSend; }
9  
  
10  
  visualize {
11  
    ret centerAndSouthWithMargins(
12  
      super.visualize(),
13  
      westCenterAndEastWithMargin(
14  
        jLine(
15  
          jLabel("Send to"),
16  
          jMinWidth(100, jLiveValueTextField_bothWays(dm_fieldLiveValue('receiver))),
17  
          jLabel(":")),
18  
        onEnterAndCtrlEnter(jLiveValueTextField_bothWays(dm_fieldLiveValue('msg)), rThread sendMsg),
19  
        jLine(
20  
          jLiveValueCheckBox("Sign", dm_fieldLiveValue('sign)),
21  
          jbutton("Send", rThread sendMsg))));
22  
  }
23  
  
24  
  void sendMsg {
25  
    postMsg(receiver, msg, sign);
26  
    setField(msg := "");
27  
  }
28  
  
29  
  void postSigned(S receiver, S msg) { postMsg(receiver, msg, true); }
30  
  
31  
  void postMsg(S receiver, S msg, bool sign) {
32  
    if (empty(receiver = trim(receiver))) ret;
33  
    if (!possibleComputerID(receiver)) ret with infoBox("Not a computer ID: " + receiver);
34  
    if (empty(msg = trim(msg))) ret;
35  
    print("Sending to " + receiver + ": " + shorten(msg, 200));
36  
    if (sign) {
37  
      signWithComputerIDAndDate_verify = verifyBeforeSend;
38  
      msg = signWithComputerIDAndDate(msg);
39  
      print("Signed msg length: " + l(msg));
40  
    }
41  
    vmBus_send('sendingToPrivateChat, receiver, msg);
42  
    //logQuotedWithDate(javaxDataDir("OS Chat/sent.log"), msg);
43  
    connector.sendLine("privateChat:" + receiver + " " + quote(msg));
44  
  }
45  
  
46  
  start {
47  
    thread { exportComputerPublicKeyToServerMechList(); }
48  
    ownResource(connector = new StefansOS_ConnectToServer);
49  
    connector.onLine = voidfunc(S line) {
50  
      new Matches m;
51  
      if (startsWith(line, "privately from ", m)) {
52  
        S s = m.rest();
53  
        int i = indexOf(s, ':');
54  
        S sender = takeFirst(s, i);
55  
        S msg = unquote(substring(s, i+2));
56  
        //if (!startsWith(msg, "done ")) // XXX
57  
          printWithIndent(sender + " >> ", shorten(msg, 1000));
58  
        vmBus_send('gotFromPrivateChat, sender, msg);
59  
        //logQuotedWithDate(stefansOS_chat_receivedLogFile(), msg);
60  
      }
61  
    };
62  
    connector.startWithSubs("privateChat");
63  
  }
64  
}

Author comment

Began life as a copy of #1017119

download  show line numbers  debug dex  old transpilations   

Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, hpgrupgrauku, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1019644
Snippet name: Private Chat [Dyn Module]
Eternal ID of this version: #1019644/21
Text MD5: b287f051285bcf1ca21bf688800efd56
Transpilation MD5: dbe3794c30c1cf3139009638436d6247
Author: stefan
Category: javax / stefan's os
Type: JavaX source code (Dynamic Module)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-06-29 21:42:21
Source code size: 2242 bytes / 64 lines
Pitched / IR pitched: No / No
Views / Downloads: 388 / 559228
Version history: 20 change(s)
Referenced in: [show references]