How to use readMessage method in wpt

Best JavaScript code snippet using wpt

readMessages.js

Source:readMessages.js Github

copy

Full Screen

1import _ from 'underscore';2/* DEFINITIONS3- If window loses focus user needs to scroll or click/touch some place4- On hit ESC enable read, force read of current room and remove unread mark5- When user change room disable read until user interaction6- Only read if mark of *first-unread* is visible for user or if flag *force* was passed7- Always read the opened room8- The default method *read* has a delay of 2000ms to prevent multiple reads and to user be able to see the mark9*/10// Meteor.startup ->11// window.addEventListener 'focus', ->12// readMessage.refreshUnreadMark(undefined, true)13const readMessage = new class {14 constructor() {15 this.debug = false;16 this.callbacks = [];17 this.read = _.debounce((force) => this.readNow(force), 1000);18 this.canReadMessage = false;19 }20 readNow(force) {21 if (force == null) { force = false; }22 if (this.debug) { console.log('--------------'); }23 if (this.debug) { console.log('readMessage -> readNow init process force:', force); }24 const self = this;25 self.refreshUnreadMark();26 if ((force !== true) && (this.canReadMessage === false)) {27 if (this.debug) { console.log('readMessage -> readNow canceled by canReadMessage: false'); }28 return;29 }30 const rid = Session.get('openedRoom');31 if (rid == null) {32 if (this.debug) { console.log('readMessage -> readNow canceled, no rid informed'); }33 return;34 }35 if (force === true) {36 if (this.debug) { console.log('readMessage -> readNow via force rid:', rid); }37 return Meteor.call('readMessages', rid, function() {38 RoomHistoryManager.getRoom(rid).unreadNotLoaded.set(0);39 self.refreshUnreadMark();40 return self.fireRead(rid);41 });42 }43 const subscription = ChatSubscription.findOne({rid});44 if (subscription == null) {45 if (this.debug) { console.log('readMessage -> readNow canceled, no subscription found for rid:', rid); }46 return;47 }48 if ((subscription.alert === false) && (subscription.unread === 0)) {49 if (this.debug) { console.log('readMessage -> readNow canceled, alert', subscription.alert, 'and unread', subscription.unread); }50 return;51 }52 const room = RoomManager.getOpenedRoomByRid(rid);53 if (room == null) {54 if (this.debug) { console.log('readMessage -> readNow canceled, no room found for typeName:', subscription.t + subscription.name); }55 return;56 }57 // Only read messages if user saw the first unread message58 const unreadMark = $('.message.first-unread');59 if (unreadMark.length > 0) {60 const position = unreadMark.position();61 const visible = (position != null ? position.top : undefined) >= 0;62 if (!visible && (room.unreadSince.get() != null)) {63 if (this.debug) { console.log('readMessage -> readNow canceled, unread mark visible:', visible, 'unread since exists', (room.unreadSince.get() != null)); }64 return;65 }66 // if unread mark is not visible and there is more more not loaded unread messages67 } else if (RoomHistoryManager.getRoom(rid).unreadNotLoaded.get() > 0) {68 return;69 }70 if (this.debug) { console.log('readMessage -> readNow rid:', rid); }71 Meteor.call('readMessages', rid, function() {72 RoomHistoryManager.getRoom(rid).unreadNotLoaded.set(0);73 self.refreshUnreadMark();74 return self.fireRead(rid);75 });76 }77 disable() {78 return this.canReadMessage = false;79 }80 enable() {81 return this.canReadMessage = document.hasFocus();82 }83 isEnable() {84 return this.canReadMessage === true;85 }86 onRead(cb) {87 return this.callbacks.push(cb);88 }89 fireRead(rid) {90 return Array.from(this.callbacks).map((cb) => cb(rid));91 }92 refreshUnreadMark(rid, force) {93 if (rid == null) { rid = Session.get('openedRoom'); }94 if (rid == null) {95 return;96 }97 const subscription = ChatSubscription.findOne({rid}, {reactive: false});98 if (subscription == null) {99 return;100 }101 const room = RoomManager.openedRooms[subscription.t + subscription.name];102 if (room == null) {103 return;104 }105 if (!subscription.alert && (subscription.unread === 0)) {106 room.unreadSince.set(undefined);107 return;108 }109 if ((force == null) && (subscription.rid === Session.get('openedRoom')) && document.hasFocus()) {110 return;111 }112 let lastReadRecord = ChatMessage.findOne({113 rid: subscription.rid,114 ts: {115 $lt: subscription.ls116 }117 }118 // 'u._id':119 // $ne: Meteor.userId()120 , {121 sort: {122 ts: -1123 }124 }125 );126 if ((lastReadRecord == null) && (RoomHistoryManager.getRoom(room.rid).unreadNotLoaded.get() === 0)) {127 lastReadRecord =128 {ts: new Date(0)};129 }130 if ((lastReadRecord != null) || (RoomHistoryManager.getRoom(room.rid).unreadNotLoaded.get() > 0)) {131 room.unreadSince.set(subscription.ls);132 } else {133 room.unreadSince.set(undefined);134 }135 if (lastReadRecord != null) {136 const firstUnreadRecord = ChatMessage.findOne({137 rid: subscription.rid,138 ts: {139 $gt: lastReadRecord.ts140 },141 'u._id': {142 $ne: Meteor.userId()143 }144 }145 , {146 sort: {147 ts: 1148 }149 }150 );151 if (firstUnreadRecord != null) {152 room.unreadFirstId = firstUnreadRecord._id;153 $(room.dom).find(`.message.first-unread:not(#${ firstUnreadRecord._id })`).removeClass('first-unread');154 $(room.dom).find(`.message#${ firstUnreadRecord._id }`).addClass('first-unread');155 }156 }157 }158};159Meteor.startup(function() {160 $(window).on('blur', () => readMessage.disable());161 $(window).on('focus', () => {162 readMessage.enable();163 return readMessage.read();164 });165 $(window).on('click', () => {166 readMessage.enable();167 return readMessage.read();168 });169 $(window).on('touchend', () => {170 readMessage.enable();171 return readMessage.read();172 });173 $(window).on('keyup', (e) => {174 const key = e.which;175 if (key === 27) {176 readMessage.enable();177 readMessage.readNow(true);178 return $('.message.first-unread').removeClass('first-unread');179 }180 });181});182export { readMessage };...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require("wpt");2var wpt = new WebPageTest("www.webpagetest.org");3wpt.runTest("www.google.com", function(err, data) {4 if (err) return console.log(err);5 wpt.readMessage(data.data.testId, function(err, data) {6 if (err) return console.log(err);7 console.log(data);8 });9});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('wpt');2var wpt = new WebPageTest('www.webpagetest.org');3wpt.readMessage('1234567890', function(err, data) {4 if (err) {5 console.log('Error: ' + err);6 } else {7 console.log('Message: ' + data);8 }9});10The MIT License (MIT)11This project is inspired by [webpagetest-api](

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('wpt');2var wpt = new WebPageTest('www.webpagetest.org');3wpt.readMessage('1234567890', function(err, data) {4 console.log(data);5});6var wpt = require('wpt');7var wpt = new WebPageTest('www.webpagetest.org');8 console.log(data);9});10var wpt = require('wpt');11var wpt = new WebPageTest('www.webpagetest.org');12 console.log(data);13});14var wpt = require('wpt');15var wpt = new WebPageTest('www.webpagetest.org');16wpt.getTestStatus('1234567890', function(err, data) {17 console.log(data);18});19var wpt = require('wpt');20var wpt = new WebPageTest('www.webpagetest.org');21wpt.getTestResults('1234567890', function(err, data) {22 console.log(data);23});24var wpt = require('wpt');25var wpt = new WebPageTest('www.webpagetest.org');26wpt.getTestResults('1234567890', {k: 'v'}, function(err, data) {27 console.log(data);28});29var wpt = require('wpt');30var wpt = new WebPageTest('www.webpagetest.org');

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('wpt');2var wpt = new WebPageTest('www.webpagetest.org', 'A.2d1b5f7d5f8e5c7a3d3e5b7c5d5b3f9c');3 if (err) return console.error(err);4 wpt.readMessage(data.data.testId, function(err, data) {5 if (err) return console.error(err);6 console.log(data);7 });8});9var wpt = require('wpt');10var wpt = new WebPageTest('www.webpagetest.org', 'A.2d1b5f7d5f8e5c7a3d3e5b7c5d5b3f9c');11 if (err) return console.error(err);12 wpt.waitForTestComplete(data.data.testId, function(err, data) {13 if (err) return console.error(err);14 console.log(data);15 });16});17var wpt = require('wpt');18var wpt = new WebPageTest('www.webpagetest.org', 'A.2d1b5f7d5f8e5c7a3d3e5b7c5d5b3f9c');19 if (err) return console.error(err);20 console.log(data);21});22var wpt = require('wpt');23var wpt = new WebPageTest('www.webpagetest.org', 'A.2d1b5f7d5f8e5c7

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run wpt automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful