-
Notifications
You must be signed in to change notification settings - Fork 1
/
ViewMessage.js
168 lines (131 loc) · 4.82 KB
/
ViewMessage.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
// Populate view message with a message in Diaspora inbo
var username = '';
var subject = '';
var dateTime = '';
var content= '';
var replyMessage='';
var token = getToken();
var messageid= $.url().param('messageid');
// variable to hold request
var request;
$.getJSON("https://pod.cscf.me/conversations/" + messageid+".json", function(json) {
dateTime = prettyDate(json.conversation.updated_at);
subject = json.conversation.subject;
// $.each(json, function(arrayID,message) {
// $.each(message, function() {
// for every message, extract author of message,
$.ajax({
async: true,
type: 'GET',
url: 'https://pod.cscf.me/conversations/' +messageid,
success: function(data) {
var matches = data.match(/" class='author from' >(.*)<\/a>/); // regex to extract it, // if there are no matches, it must be a self message
var matches2 = data.match(/<div class='ltr'>\n<p>(.*)<\/p>/); //regex to extract message content,
if (matches != null) {
username = matches[1];
}
else {
username = "Me";
}
// subject = message.conversation.subject;
username = username;
content = matches2[1];
document.getElementById('testSubject').value = subject;
document.getElementById('userField').value = username;
document.getElementById('dateTime').value = dateTime;
var decoded = $('<div/>').html(content).text();
$("#ContentArea").html(content);
//Grab content of new reply message
document.getElementById('contentReply').value = replyMessage;
var request1
// bind to the submit event of our form
$("#send").submit(function(event){
// abort any pending request
if (request1) {
request1.abort();
}
// setup some local variables
var $form = $(this);
// let's select and cache all the fields
var $inputs = $form.find("input, select, button, textarea");
var utf = "%E2%9C%93";
var token = getToken();
var replyContent = $('#contentReply').val();
var reply = "Reply";
var data = new FormData();
data.append('utf8', utf);
data.append('authenticity_token', token);
data.append('message[text]', replyContent);
data.append('commit', reply);
// fire off the request to /form.php
var request1 = $.ajax({
url: 'https://pod.cscf.me/conversations/'+messageid+'/messages',
type: "post",
data: data,
processData: false,
contentType: false,
async: false,
success: function() {
$('#success').html('<button type="button" class="close" data-dismiss="alert">×</button <strong>Success:</strong> Replied to message!');
$('#success').show();
console.log("test");
}
});
// callback handler that will be called regardless
// if the request failed or succeeded
/* request.always(function () {
// reenable the inputs
$inputs.prop("disabled", false);
});*/
// prevent default posting of form
//event.preventDefault();
});
}
});
});
//});
//});
function getToken()
{
$.ajax({
async: false,
type: 'GET',
url: 'https://pod.cscf.me/conversations',
success: function(data) {
var matches = data.match(/<meta content="(.*)" name="csrf-token" \/>/); // regex to extract it,
// if there are no matches, it must be a self message
tok = matches[1];
result = tok;
}
});
return result;
}
var url = $.url(true).fparam('messageid');
$("#delete").click( function()
{
var $form = $(this);
var utf = "%E2%9C%93";
var token = getToken();
var referer = messageid;
var method = "delete";
var data1 = new FormData();
data1.append('utf8', utf);
data1.append('authenticity_token', token);
data1.append('Referer', referer);
data1.append('_method', method);
var requestDelete = $.ajax({
url: 'https://pod.cscf.me/conversations/'+messageid+'/visibility',
type: "post",
data: data1,
processData: false,
contentType: false,
async: false,
success: function() {
$('#success').html('<button type="button" class="close" data-dismiss="alert">×</button <strong>Success:</strong> Deleted Message!');
$('#success').show();
console.log("test");
}
});
window.open('inbox.html', '_self', false);
}
);