Cannot read property 'getUniqueId' of undefined - converse.js

sorry to bother anyone,but i really need help for this,i want to retrieve chat from database(which i already ask this question before),but i try to googling and read all the documentation,and i assumed that i have found the solution,i read the converse.js documentation about developer api,in the Archiving group section,and i got this :
require(['converse'], function (converse) {
converse.plugins.add('myplugin', {
initialize: function () {
this._converse.api.archive.query({'with': 'admin2#localhost'});
}
});
converse.initialize({
jid: 'admin3#localhost',
authentication: 'prebind',
prebind_url: 'bind/bind.php',
allow_logout: false,
debug : true,
whitelisted_plugins: ['converse-inverse','converese-mam','converse-singleton','converse-muc-embedded','myplugin'],
archived_messages_page_size : 20,
message_archiving : "always",
auto_list_rooms: false,
show_chatstate_notifications:true,
message_carbons : true,
sounds_path : "sounds/",
auto_reconnect : true,
use_vcard : true,
auto_subscribe: false,
keepalive : true,
show_send_button:true,
archived_messages_page_size : 20,
bosh_service_url: 'http://localhost:5280/http-bind',
hide_muc_server: false,
play_sounds : true,
show_controlbox_by_default: false,
xhr_user_search: false
});
});
i try it,but i got this error :
Cannot read property 'getUniqueId' of undefined
at Object._converse.queryForArchivedMessages (converse-mam.js:266)
at Object.initialize (dev.html:30)
at PluginSocket.initializePlugin (pluggable.js:196)
at arrayEach (lodash.js:537)
at Object.forEach (lodash.js:9359)
at PluginSocket.initializePlugins (pluggable.js:227)
at Object.initPlugins (converse-core.js:1854)
at Object._converse.initialize (converse-core.js:1875)
at Object.initialize (converse-core.js:2037)
at dev.html:36
i am sorry if this question's kinda simple or stupid,but i really new in using converse.js,and i really like to use and learn more about converse.js in the future because it full features and documentation.

The initialize method of a Converse.js plugin gets called when Converse.js itself gets initialized.
This happens before the user has been logged in (regardless whether that happens automatically or manually).
So you're calling this._converse.api.archive.query({'with': 'admin2#localhost'}); before the user has been logged and an XMPP connection and session has been established.
Instead, you should first listen for the connection event, and then do your query.
converse.plugins.add('myplugin', {
initialize: function () {
var _converse = this._converse;
_converse.on('connected', function () {
_converse.api.archive.query({'with': 'admin2#localhost'});
});
}
});

Related

Postgraphile not exposing non public schema with introspection

When using Postgraphile with express, I can connect to my database, but when running the server via node dist/index.js:
Not working in index.js
const postgraphileOptions: PostGraphileOptions = {
subscriptions: true,
watchPg: true,
dynamicJson: true,
setofFunctionsContainNulls: false,
ignoreRBAC: false,
showErrorStack: 'json',
extendedErrors: ['hint', 'detail', 'errcode'],
appendPlugins: [require('#graphile-contrib/pg-simplify-inflector')],
exportGqlSchemaPath: 'schema.graphql',
graphiql: true,
enhanceGraphiql: true,
allowExplain(_req: any) {
// TODO: customise condition!
return true;
},
enableQueryBatching: true,
legacyRelations: 'omit',
// pgSettings(req: any) {
// /* TODO */
// },
jwtSignOptions: { algorithm: 'RS256' },
jwtPgTypeIdentifier: 'public.jwt_token',
jwtSecret: 'secret',
};
app.use(
postgraphile(
process.env.DATABASE_URL || postgres://postgres:postgres#localhost:5432/my-db,
'private',
{ ...postgraphileOptions }
)
);
The even though I've used comments in the db to hide introspection of some tables in the public schema, these introspections are not hidden.
Nothing in the private schema shows introspection (even when I only specify private in the PostGraphileOptions).
Here's the confusing part. If I run the server using the postgraphile cli, I will see proper introspection and my manually hidden items are not shown.
postgraphile --jwt-token-identifier public.jwt_token --jwt-secret 'secret' -c 'postgres://postgres:postgres#localhost:5432/my-db' -s public,private --watch --enhance-graphiql --dynamic-json
I hope I have provided enough info here. Cheers and thanks in advance!

Why does the Keycloak REST API return an "autheticatorFlow" (sic!) attribute when reading authentication/flows?

When reading authentication flows with
kcadm.sh get authentication/flows -r master
I get this result for the builtin flows
{
"id" : "cee86f07-db10-4e84-9a5e-a9c6ae1c3703",
"alias" : "http challenge",
"description" : "An authentication flow based on challenge-response HTTP Authentication Schemes",
"providerId" : "basic-flow",
"topLevel" : true,
"builtIn" : true,
"authenticationExecutions" : [ {
"authenticator" : "no-cookie-redirect",
"authenticatorFlow" : false, <---
"autheticatorFlow" : false, <---
"requirement" : "REQUIRED",
"priority" : 10,
"userSetupAllowed" : false
}, {
"authenticatorFlow" : true,
"requirement" : "REQUIRED",
"priority" : 20,
"autheticatorFlow" : true,
"flowAlias" : "Authentication Options",
"userSetupAllowed" : false
} ]
}
That field is nowhere mentioned in the REST API documentation. Is there a deeper meaning in this, or is this just some leftover typo that is kept for compatibility (like HTTP Referer vs HTTP Referrer)? Do I have to set this undocumented field when creating a new flow via REST API?
Short story: Use "authenticatorFlow"
It would appear this is a long standing spelling typo. If you dig into the keycloak source code e.g. v15.1.1 here:
https://github.com/keycloak/keycloak/blob/15.1.1/core/src/main/java/org/keycloak/representations/idm/AbstractAuthenticationExecutionRepresentation.java#L71 You will see the misspelled "autheticatorFlow" is marked as deprecated.
#Deprecated
public void setAutheticatorFlow(boolean autheticatorFlow) {
this.authenticatorFlow = autheticatorFlow;
}
...snip...
public void setAuthenticatorFlow(boolean authenticatorFlow) {
this.authenticatorFlow = authenticatorFlow;
}
In other parts of the source you will see a setter for the correctly spelled property "authenticatorFlow" e.g. here:
https://github.com/keycloak/keycloak/blob/15.1.1/model/jpa/src/main/java/org/keycloak/models/jpa/RealmAdapter.java#L1649
(which shows the misspelling is down to the db column).
model.setAuthenticatorFlow(entity.isAutheticatorFlow());
It should be safe to use the correctly spelled "authenticatorFlow". However always evaluate for your specific version.

Is there a way to not show invite popups in conversejs when converse is initialized as singleton in embeded mode?

I am using conversejs as client for providing a multiuser chat embeded in an html page. User might be added to a lot of groups. When a user is chating in a group and gets invite to join another group a popup is shown to accept the invite, i do not want the user to see that invitation and rather user should stay in the same group that he has opened.
Given bellow is the initialization sample :
converse.initialize({
authentication: 'login',
credentials_url: 'https://myserver.primet.com/chatapi/apiserver/api/chat/autologin/auth?token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiIsImtpZCI6ImFQY3R3X29kdlJPb0VOZzNWb09sSWgydGlFcyJ9.eyJhdWQiOiI2YTE1NzNkMS03ZDZjLTRkZGItYjVlYS1hZGQyZWM1MDkzZjEiLCJpc3MiOiJodHRwczovL2xvZ2luLm1pY3Jvc29mdG9ubGluZS5jb20vZmNlNTAxOTUtMjMxNS00N2FmLWE2ODQtZmY5M',
auto_login: 'true',
bosh_service_url: 'https://myserver.primet.com/chatserver/http-bind/',
jid: ‘james#qachatserver.primet.com',
keepalive: true,
trusted: false,
auto_reconnect: true,
muc_nickname_from_jid: true,
auto_join_rooms: ['deal_909090390898989090909#conference.qachatserver.primet.com'],
auto_focus: false,
locked_muc_nickname: true,
show_desktop_notifications: false,
send_chat_state_notifications: false,
blacklisted_plugins: [
'converse-notification'
],
singleton: true,
muc_show_join_leave: false,
visible_toolbar_buttons: {
call: false,
spoiler: false,
emoji: false,
toggle_occupants: true
},
notify_all_room_messages: false,
notification_delay: 3000,
allow_message_corrections: 'false',
view_mode: 'embedded'
}).then(() => { setTimeout(function(){ var toggleButton = document.getElementsByClassName('toggle-occupants fa fa-angle-double-right')[0]; if (toggleButton) { toggleButton.click(); toggleButton.style.display="none"}},500);})
You can set allow_muc_invitations to false.

running background job on a specific action in sails js

i am trying to make a service that runs in background when specific event happens. As an example when user verifies email i want my service of deleting possible unverified duplicate emails form database. i tried using kue to save my purpose but i think its more like the services will run once the sails lift fires?
so how to run a service when specific event happens? any help would be much appreciated.
thanks
You can indeed use Kue for this purpose.
Create a config file kue.js for Kue
var kue = require('kue');
var kue_engine = kue.createQueue({
prefix: 'kue',
redis: {
port: '6379',
host: 'localhost'
}
});
process.once('SIGTERM', function (sig) {
kue_engine.shutdown( 5000, function(err) {
console.log( 'Kue shutdown: ', err||'' );
process.exit( 0 );
});
});
module.exports.kue = kue_engine;
Add the job to Kue in relevant controller action.
var kue_engine = sails.config.kue;
kue_engine.create('delete_verified_email', {email: '123#456.com'})
.priority('medium')
.attempts(3)
.save();
Create a worker.js in project root to consume kue jobs.
var kue = require('kue');
require('sails').load({
hooks: {
blueprints: false,
cors: false,
csrf: false,
grunt: false,
http: false,
i18n: false,
logger: false,
policies: false,
pubsub: false,
request: false,
responses: false,
session: false,
sockets: false,
views: false
}
}, function (err, app) {
sails.log.info('Starting kue');
var kue_engine = sails.config.kue;
//register kue.
kue_engine.on('job complete', function (id) {
sails.log.info('Removing completed job: ' + id);
kue.Job.get(id, function (err, job) {
job.remove();
});
});
kue_engine.process('delete_verified_email', 20, function (job, done) {
// you can access the data passed while creating job at job.data
// all the sails models, services are available here
console.log(job.data.email)
done && done();
});
Run the worker.js to consume the kue jobs created by your sails app.
Maybe Sails.js lifecycle hooks could help you. We are using them for instance to update statistics, e.g. persisting number of users per type after a user update call.
Also we are using Node Agenda (Sails.js hook) to create jobs to be executed either one time to a defined time in the future or like a cron job. Maybe you will want to collect the invalid/ expired email address verification entries to be purged and delete them in a hourly batch.

How to read POST data with node.js without using express or connect

Edit
Make sure you don't juxtapose the request and response objects. things will be easier if you dont.
I am trying to POST data from a form with two inputs to a specific url node responds to.
Originally I was using the javascript xmlHTTPrequest object to send it. The data was received but node could never read the object I tried sending which was JSON format. Here is what it looked like when I converted it to a string:
{ output: [],
outputEncodings: [],
writable: true,
_last: false,
chunkedEncoding: false,
shouldKeepAlive: true,
useChunkedEncodingByDefault: true,
_hasBody: true,
_trailer: '',
finished: false,
socket:
{ _handle:
{ writeQueueSize: 0,
socket: [Circular],
onread: [Function: onread] },
_pendingWriteReqs: 0,
_flags: 0,
_connectQueueSize: 0,
destroyed: false,
errorEmitted: false,
bytesRead: 8442,
bytesWritten: 1669569,
allowHalfOpen: true,
writable: true,
readable: true,
This was not the full string. I switched over to use an ajax post request instead because I thought serializearray() might create a different format that node could read but it was the same. My server side code is essentially just:
function email(request, response)
form = '';
request.setEncoding("utf8");
request.on('data', function(chunk) {
console.log('data received');
form += chunk.toString();
});
request.on('end', function() {
console.log('done receiving post data');
});
My form looks like this
<form name="email" action="javascript:true;">
<input type="text" name="address" value="Enter your email address" onFocus="this.value=''">
<input class="special" type="text" name="honeypot">
<input type="submit" value="submit">
</form>
If I try parsing with JSON.parse, there is an error caused by unexpected o
If I try parsing with querystring, it returns an empty object
If I try something like console.log(form.address) the output is undefined but should be one of the values i submitted in the form.
my http server would route to /email and this is the function that responds to /email.
I checked and I know the on 'data' event has not expired because my code is set up to notify me of a 'data'event and I can see the event happening. Locally, this code works fine and I can read the data submitted but on the development server it just doesn't work.
I know people will say I should be using connect or express but let's just suppose that was not an option, how could I get node to correctly process this data? The jquery that submits the form is more or less standard. Many thanks!
EDIT:
Sorry, I thought the problem would be fixed as I noticed immediately the posted string was not JSON. Here is the code I am using to send the post.
$(document).ready(function() {
$("#email").submit(function(event) {
event.preventDefault();
var data = $(this).serializeArray();
$.ajax({
type: 'POST',
dataType: 'json',
url: '/email',
data: JSON.stringify(data),
success: function(msg) {
$("#aviso").html(msg);
}
});
});
});
Here is the string the data variable holds:
[
{
"name": "address",
"value": "foo#bar.com"
},
{
"name": "honeypot",
"value": "irobot"
}
]
This is valid JSON as per jsonlint. But still the same error when it reaches the server. Node handles the 'data' event and all is well until I try to parse the string, it causes an error undefined:1 unexpected o.
The data you're sending is not valid JSON, which requires that all object keys are double-quoted.