Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Private messages should work with names (regular send-message plugin) #230

Open
janagoetze opened this issue Dec 21, 2021 · 1 comment
Open

Comments

@janagoetze
Copy link
Contributor

janagoetze commented Dec 21, 2021

Sending private messages with the @ syntax (@<user> <message>) should trigger on names. Currently triggers on User IDs (that are not visible in the browser window)

cf.

} else if (text.match("^@")) {
let user = text.substr(1, text.indexOf(" ") - 1);

submit_private_text(user, message, () => {

function submit_private_text(receiver, text, resolve, reject) {
socket.emit('text', { room: self_room, receiver_id: receiver, message: text }, (success, error) => {

@wencke-lm
Copy link
Contributor

wencke-lm commented Dec 22, 2021

I noted the same a while ago. Tim said, that this part of the code was originally only meant for easier debugging.

The most logical thing would probably be to translate the name to id, directly where it is received in send-message.js. The variable user map, is instantiated when displaying the current users of a room.

+    let user_name = text.substr(1, text.indexOf(" ") - 1);
+    let user = "";
+    for (let u in user_map) {
+        if (user_map[u] === user_name) {
+            user = u;
+       }
+    }

Disadvantages when using this variable would be, that it only contains the users inside a room, so when someone tries to address someone in a different room, normally they received an error User <id> is not in this room, but in this way, they would receive the error User "" does not exist. And I think some time in the future one might allow writing messages to users in other rooms, then there would be two places in the code that need updating.

The resolution of the passed receiver happens here:

receiver = db.query(User).get(receiver_id)

One could try to retrieve by name there instead, but that would affect all private messages, also those sent by bots.

receiver = db.query(User).filter_by(name=receiver_id).one_or_none()

One could also check for both.

  receiver = db.query(User).filter(
      or_(
          User.name == receiver_id,
          User.id == receiver_id
      )
  ).one_or_none()

At the moment names are not restricted to be unique. One would definitely have to change this. Also for the last approach, names should not take the form of ids, so one would have to add the restriction, that names can't only be numbers.

name = Column(String, nullable=False)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants