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).

!7

cmodule2 PrivateChat > DynPrintLog {
  S receiver, msg;
  bool sign, verifyBeforeSend;
  transient StefansOS_ConnectToServer connector;
  
  S switchableFields() { ret 'verifyBeforeSend; }
  
  visualize {
    ret centerAndSouthWithMargins(
      super.visualize(),
      westCenterAndEastWithMargin(
        jLine(
          jLabel("Send to"),
          jMinWidth(100, jLiveValueTextField_bothWays(dm_fieldLiveValue('receiver))),
          jLabel(":")),
        onEnterAndCtrlEnter(jLiveValueTextField_bothWays(dm_fieldLiveValue('msg)), rThread sendMsg),
        jLine(
          jLiveValueCheckBox("Sign", dm_fieldLiveValue('sign)),
          jbutton("Send", rThread sendMsg))));
  }
  
  void sendMsg {
    postMsg(receiver, msg, sign);
    setField(msg := "");
  }
  
  void postSigned(S receiver, S msg) { postMsg(receiver, msg, true); }
  
  void postMsg(S receiver, S msg, bool sign) {
    if (empty(receiver = trim(receiver))) ret;
    if (!possibleComputerID(receiver)) ret with infoBox("Not a computer ID: " + receiver);
    if (empty(msg = trim(msg))) ret;
    print("Sending to " + receiver + ": " + shorten(msg, 200));
    if (sign) {
      signWithComputerIDAndDate_verify = verifyBeforeSend;
      msg = signWithComputerIDAndDate(msg);
      print("Signed msg length: " + l(msg));
    }
    vmBus_send('sendingToPrivateChat, receiver, msg);
    //logQuotedWithDate(javaxDataDir("OS Chat/sent.log"), msg);
    connector.sendLine("privateChat:" + receiver + " " + quote(msg));
  }
  
  start {
    thread { exportComputerPublicKeyToServerMechList(); }
    ownResource(connector = new StefansOS_ConnectToServer);
    connector.onLine = voidfunc(S line) {
      new Matches m;
      if (startsWith(line, "privately from ", m)) {
        S s = m.rest();
        int i = indexOf(s, ':');
        S sender = takeFirst(s, i);
        S msg = unquote(substring(s, i+2));
        //if (!startsWith(msg, "done ")) // XXX
          printWithIndent(sender + " >> ", shorten(msg, 1000));
        vmBus_send('gotFromPrivateChat, sender, msg);
        //logQuotedWithDate(stefansOS_chat_receivedLogFile(), msg);
      }
    };
    connector.startWithSubs("privateChat");
  }
}

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: 322 / 486011
Version history: 20 change(s)
Referenced in: [show references]