Re: Javascript weirdness
By: deon to All on Sun Apr 17 2022 08:21 pm
> Howdy,
>
> Hoping somebody could help me understand something unusual that's happening
> wth Javascript. I think it's a bug, but who knows somebody might see the err
> of my ways.
>
> I have created an object "MsgArea" which represents a message area and the
> ability to get a list of "tagged" messages and "untagged" messages.
>
> Here is the relevant part of the object:
>
> ====
> function MsgArea() {
> this.msgbase = undefined;
> this.headers = undefined;
> this.tagged_list = undefined;
> this.untagged_list = undefined;
>
> const PAGE_LENGTH = 4; // The size of our page tag.
> const PAGE_LAST_KEY = 'last_page';
>
> Object.defineProperty(this,'code',{
> set: function(code) {
> this.msgbase = new MsgBase(code);
>
> if (! this.msgbase.open('r')) {
What significance is this 'r'? I don't think that'll have any effect.
> writeln(ma.areas[i].code+' cannot be opened?');
'ma' and 'i' don't appear to be defined in this scope. I don't this error handle
r is going to execute as intended.
> exit(2);
> }
>
> this.headers = this.msgbase.get_all_msg_headers(false,false);
> this.msgbase.close();
> }
> });
>
> // Total tagged messages
> Object.defineProperty(this,'list_tagged',{
> get: function() {
> if (this.tagged_list === undefined) {
> this.tagged_list = [];
>
> if (! this.headers)
> return this.tagged_list;
>
> for(var x in this.headers) {
> if (this.headers[x].tags && (this.headers[x].tags.length
> === PAGE_LENGTH)) {
> this.tagged_list.push(this.headers[x]);
> write(); // Needed else this is not working?
That's pretty strange.
> }
> }
> }
>
> return this.tagged_list;
> }
> });
> ====
>
> I'm seeing two problems:
>
> 1)
>
> If I use:
> var x = new MsgArea();
> x.code = 'PVT_TEST';
> writeln('Tagged Messages: '+x.list_tagged.length);
>
> It reports 36 (which is correct). If I comment out the "write()" in the
> function list_tagged, it reports 25. Why? (And I have confirmed that 23 of
> the 25 do have a "tags" header.)
Woudn't 23 be the right answer then?
>
> 2)
>
> The other 2 messages of the 25 I cannot set a "tags" value in the header -
> the function put_msg_header() returns an error, but no details.
If put_msg_header() returns false, the details will be contained in MsgBase.erro
r and MsgBase.status. Check/log those property values upon error.
> Here is one of those message headers (in which I set the tags header to
> "1829"):
>
> {"number":27,"tags":"1829","to":"Clearing Houz","subject":"Address Link
> Code","from":"Hub
> Robot","from_net_type":2,"from_net_addr":"10:1/1","id":"<625A
> 907B.27.pvt_test@mybbs.com>","ftn_area":"PVT_TEST","date":"Fri, 25 Mar 2022
> 11:05:08
> +1100","attr":0,"votes":0,"auxattr":0,"netattr":0,"when_written_time": 16481
> 66708,"when_written_zone":660,"when_imported_time":1650102395,"when_import e
> d_zone":0,"thread_id":27,"thread_next":0,"thread_first":0,"delivery_attempts
> ": 0,"field_list":[{"type":160,"data":"RESCANNED
> 10:1/1@private"},{"type":162,"data":"1/1
> 998"},{"type":163,"data":"1/1"}],"offs et":26,"type":0,"version":768,"when_w
> ritten_zone_offset":660,"when_imported_zon e_offset":0,"thread_back":0,"data
> _length":869,"text_length":869,"upvotes":0,"do
> wnvotes":0,"total_votes":0,"is_utf8":0,"can_read":true}
>
> Why does the update header error?
The error/status MsgBase property values will tell you why.
--
digital man (rob)
Rush quote #11:
Struck between the eyes by the big time world, walking uneasy streets
Norco, CA WX: 74.4°F, 46.0% humidity, 7 mph SSE wind, 0.00 inches rain/24hrs
---
■ Synchronet ■ Vertrauen ■ Home of Synchronet ■ [vert/cvs/bbs].synchro.net
|