|
|
@@ -166,7 +166,75 @@ module.exports = {
|
|
166
|
166
|
})
|
|
167
|
167
|
});
|
|
168
|
168
|
}
|
|
169
|
|
- })
|
|
|
169
|
+ });
|
|
|
170
|
+ },
|
|
|
171
|
+
|
|
|
172
|
+ add_friend: function(friend, auth, complete) {
|
|
|
173
|
+ var self = this;
|
|
|
174
|
+ friend = friend.toLowerCase();
|
|
|
175
|
+ self.get_user_from_auth(auth, function (username) {
|
|
|
176
|
+ if (username) {
|
|
|
177
|
+ self.get_public_user_info(username, function (userdata) {
|
|
|
178
|
+ var friends = userdata.user.friends;
|
|
|
179
|
+ if (friends.indexOf(friend) > -1) {
|
|
|
180
|
+ complete({
|
|
|
181
|
+ "success": 0,
|
|
|
182
|
+ "error": 2
|
|
|
183
|
+ });
|
|
|
184
|
+ } else {
|
|
|
185
|
+ self.user_exists(friend, function (exists) {
|
|
|
186
|
+ if (exists) {
|
|
|
187
|
+ friends.push(friend);
|
|
|
188
|
+ redis.hset("user:" + username.toLowerCase(), "friends", JSON.stringify(friends));
|
|
|
189
|
+ complete({
|
|
|
190
|
+ "success": 1,
|
|
|
191
|
+ "error": 0
|
|
|
192
|
+ });
|
|
|
193
|
+ } else {
|
|
|
194
|
+ complete({
|
|
|
195
|
+ "success": 0,
|
|
|
196
|
+ "error": 3
|
|
|
197
|
+ });
|
|
|
198
|
+ }
|
|
|
199
|
+ });
|
|
|
200
|
+ }
|
|
|
201
|
+ });
|
|
|
202
|
+ } else {
|
|
|
203
|
+ complete({
|
|
|
204
|
+ "success": 0,
|
|
|
205
|
+ "error": 1
|
|
|
206
|
+ });
|
|
|
207
|
+ }
|
|
|
208
|
+ });
|
|
|
209
|
+ },
|
|
170
|
210
|
|
|
|
211
|
+ remove_friend: function(friend, auth, complete) {
|
|
|
212
|
+ var self = this;
|
|
|
213
|
+ friend = friend.toLowerCase();
|
|
|
214
|
+ self.get_user_from_auth(auth, function (username) {
|
|
|
215
|
+ if (username) {
|
|
|
216
|
+ self.get_public_user_info(username, function (userdata) {
|
|
|
217
|
+ var friends = userdata.user.friends;
|
|
|
218
|
+ if (friends.indexOf(friend) === -1) {
|
|
|
219
|
+ complete({
|
|
|
220
|
+ "success": 0,
|
|
|
221
|
+ "error": 2
|
|
|
222
|
+ });
|
|
|
223
|
+ } else {
|
|
|
224
|
+ friends.splice(friends.indexOf(friend), 1);
|
|
|
225
|
+ redis.hset("user:" + username.toLowerCase(), "friends", JSON.stringify(friends));
|
|
|
226
|
+ complete({
|
|
|
227
|
+ "success": 1,
|
|
|
228
|
+ "error": 0
|
|
|
229
|
+ });
|
|
|
230
|
+ }
|
|
|
231
|
+ });
|
|
|
232
|
+ } else {
|
|
|
233
|
+ complete({
|
|
|
234
|
+ "success": 0,
|
|
|
235
|
+ "error": 1
|
|
|
236
|
+ });
|
|
|
237
|
+ }
|
|
|
238
|
+ });
|
|
171
|
239
|
}
|
|
172
|
240
|
}
|