]> git.mxchange.org Git - friendica-addons.git/blob - jappixmini/jappix/js/receipts.js
Merge pull request #520 from rabuzarus/20180206_-_membersince_frio_support
[friendica-addons.git] / jappixmini / jappix / js / receipts.js
1 /*
2
3 Jappix - An open social platform
4 These are the receipts JS scripts for Jappix
5
6 -------------------------------------------------
7
8 License: AGPL
9 Author: Vanaryon
10 Last revision: 26/12/10
11
12 */
13
14 // Checks if we can send a receipt request
15 function receiptRequest(hash) {
16         // Entity have support for receipt?
17         if($('#' + hash + ' .message-area').attr('data-receipts') == 'true')
18                 return true;
19         
20         return false;
21 }
22
23 // Checks if there is a receipt request
24 function hasReceipt(packet) {
25         // Any receipt request?
26         if(packet.getChild('request', NS_URN_RECEIPTS))
27                 return true;
28         
29         return false;
30 }
31
32 // Checks if there is a received reply
33 function hasReceived(packet) {
34         // Any received reply?
35         if(packet.getChild('received', NS_URN_RECEIPTS))
36                 return true;
37         
38         return false;
39 }
40
41 // Sends a received notification
42 function sendReceived(type, to, id) {
43         var aMsg = new JSJaCMessage();
44         aMsg.setTo(to);
45         aMsg.setID(id);
46         
47         // Any type?
48         if(type)
49                 aMsg.setType(type);
50         
51         // Append the received node
52         aMsg.appendNode('received', {'xmlns': NS_URN_RECEIPTS, 'id': id});
53         
54         con.send(aMsg);
55         
56         logThis('Sent received to: ' + to);
57 }
58
59 // Tells the message has been received
60 function messageReceived(hash, id) {
61         // Line selector
62         var path = $('#' + hash + ' .one-line[data-id=' + id + ']');
63         
64         // Add a received marker
65         path.attr('data-received', 'true')
66             .removeAttr('data-lost');
67         
68         // Group selector
69         var group = path.parent();
70         
71         // Remove the group marker
72         if(!group.find('.one-line[data-lost]').size()) {
73                 group.find('b.name').removeClass('talk-images')
74                                     .removeAttr('title');
75         }
76         
77         return false;
78 }
79
80 // Checks if the message has been received
81 function checkReceived(hash, id) {
82         // Fire a check 10 seconds later
83         $('#' + hash + ' .one-line[data-id=' + id + ']').oneTime('10s', function() {
84                 // Not received?
85                 if($(this).attr('data-received') != 'true') {
86                         // Add a "lost" marker
87                         $(this).attr('data-lost', 'true');
88                         
89                         // Add a warn on the buddy-name
90                         $(this).parent().find('b.name').addClass('talk-images')
91                                                        .attr('title', _e("Your friend seems not to have received your message(s)!"));
92                 }
93         });
94 }