Skip to content

Commit b5f2d4b

Browse files
author
hidespb
committed
group-related actions, profile pictures and more
1 parent 3b5878c commit b5f2d4b

File tree

6 files changed

+228
-60
lines changed

6 files changed

+228
-60
lines changed

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
node-whatsapi
22
=============
33

4-
Node.js version for (https://github.com/venomous0x/WhatsAPI)
4+
Node.js version for (https://github.com/venomous0x/WhatsAPI)
5+
6+
Install via [npm]:
7+
8+
npm install whatsapi

challenge

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +0,0 @@
1-
�A�1��@�u%"��P�ޙ

package.json

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "whatsapi",
33
"main": "whatsapi",
44
"description": "WhatsApp messenger interface",
5-
"version": "0.1.3",
5+
"version": "0.1.7",
66
"keywords": [
77
"WhatsApp",
88
"WhatsApi"
@@ -25,6 +25,10 @@
2525
"bugs": {
2626
"url": "https://github.com/hidespb/node-whatsapi/issues"
2727
},
28-
"_id": "whatsapi@0.1.2",
29-
"_from": "whatsapi@>=0.1.0"
28+
"_id": "whatsapi@0.1.3",
29+
"_from": "whatsapi@>=0.1.0",
30+
"dist": {
31+
"shasum": "9965ccf1c8741d57298ddea98369460137c2d457"
32+
},
33+
"_resolved": "https://registry.npmjs.org/whatsapi/-/whatsapi-0.1.3.tgz"
3034
}

processors.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,14 @@ function Aggregate(list) {
1515
}
1616

1717
Aggregate.prototype.setAdapter = function(adapter) {
18-
this.selfAddress = new RegExp(adapter.config.msisdn + '@' + adapter.config.server);
19-
this.adapter = adapter;
18+
this.adapter = adapter;
2019

2120
this.list.forEach(function(processor) {
2221
processor.setAdapter(adapter);
2322
}, this);
2423
};
2524

2625
Aggregate.prototype.process = function(node) {
27-
if(!node.attribute('from').match(this.selfAddress)) {
28-
this.adapter.sendNode(this.adapter.createReceivedNode(node));
29-
}
30-
3126
this.list.forEach(function(processor) {
3227
if(processor.match(node)) {
3328
processor.process(node);
@@ -49,7 +44,8 @@ Text.prototype.process = function(node) {
4944
node.attribute('from'),
5045
node.attribute('id'),
5146
node.child('notify').attribute('name'),
52-
node.child('body').data()
47+
node.child('body').data(),
48+
node.attribute('author')
5349
);
5450
};
5551

@@ -72,7 +68,8 @@ Location.prototype.process = function(node) {
7268
location.attribute('latitude'),
7369
location.attribute('longitude'),
7470
location.attribute('name'),
75-
location.attribute('url')
71+
location.attribute('url'),
72+
node.attribute('author')
7673
);
7774
};
7875

@@ -108,7 +105,8 @@ Image.prototype.process = function(node) {
108105
image.attribute('filehash'),
109106
image.attribute('width'),
110107
image.attribute('height'),
111-
image.data()
108+
image.data(),
109+
node.attribute('author')
112110
);
113111
};
114112

@@ -134,7 +132,8 @@ Video.prototype.process = function(node) {
134132
video.attribute('duration'),
135133
video.attribute('vcodec'),
136134
video.attribute('acodec'),
137-
video.data()
135+
video.data(),
136+
node.attribute('author')
138137
);
139138
};
140139

@@ -158,7 +157,8 @@ Audio.prototype.process = function(node) {
158157
audio.attribute('mimetype'),
159158
audio.attribute('filehash'),
160159
audio.attribute('duration'),
161-
audio.attribute('acodec')
160+
audio.attribute('acodec'),
161+
node.attribute('author')
162162
);
163163
};
164164

protocol.js

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,11 @@ Node.prototype.data = function() {
128128
return this.contents.data;
129129
};
130130

131+
Node.prototype.shouldBeReplied = function() {
132+
return this.tag() === 'message'
133+
&& (this.child('notify') || this.child('received') || this.child('request'));
134+
};
135+
131136
Node.prototype.isChallenge = function() {
132137
return this.tag() === 'challenge';
133138
};
@@ -137,7 +142,8 @@ Node.prototype.isSuccess = function() {
137142
};
138143

139144
Node.prototype.isMessage = function() {
140-
return this.tag() === 'message';
145+
return this.tag() === 'message' && this.child('notify') &&
146+
this.child('notify').attribute('name') !== null;
141147
};
142148

143149
Node.prototype.isPing = function() {
@@ -162,6 +168,23 @@ Node.prototype.isGroupAdd = function() {
162168
this.child('body').attribute('event') === 'add';
163169
};
164170

171+
Node.prototype.isGroupTopic = function() {
172+
return this.tag() === 'message' && this.attribute('type') === 'subject' && this.child('body');
173+
};
174+
175+
Node.prototype.isGroupMembers = function() {
176+
return this.tag() === 'iq' && this.attribute('type') === 'result' && this.child(0)
177+
&& this.child(0).tag() === 'participant' && this.child(0).attribute('xmlns') === 'w:g';
178+
};
179+
180+
Node.prototype.isGroupNewcomer = function() {
181+
return this.tag() === 'presence' && this.attribute('xmlns') === 'w' && this.attribute('add');
182+
};
183+
184+
Node.prototype.isGroupOutcomer = function() {
185+
return this.tag() === 'presence' && this.attribute('xmlns') === 'w' && this.attribute('remove');
186+
};
187+
165188
Node.prototype.isLastSeen = function() {
166189
return this.child('query') && this.child('query').attribute('xmlns') === 'jabber:iq:last';
167190
};
@@ -175,6 +198,14 @@ Node.prototype.isFailure = function() {
175198
return this.tag() === 'failure';
176199
};
177200

201+
Node.prototype.isReceived = function() {
202+
return this.tag() === 'message' && this.child('received');
203+
};
204+
205+
Node.prototype.isProfilePicture = function() {
206+
return this.tag() === 'iq' && this.child(0) && this.child(0).tag() === 'picture';
207+
};
208+
178209
Node.prototype.toXml = function(prefix) {
179210
prefix = prefix || '';
180211

0 commit comments

Comments
 (0)