-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathutil.js
74 lines (65 loc) · 2.19 KB
/
util.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
const EXTENSION_ID = "nhhlllajciiopehklclflnjoiocmgima";
// sends a message to the background script to return messages persisted in local storage
export function getPersistedMessages(callback) {
chrome.runtime.sendMessage(EXTENSION_ID, {
getPersistedMessages: true
}, (response) => {
callback(response);
});
}
// sends a message to the background script to set receivedMessages in local storage
export function setReceivedMessages(receivedMessages) {
chrome.runtime.sendMessage(EXTENSION_ID, {
receivedMessages: JSON.stringify(receivedMessages)
});
}
// sends a message to the background script to set removedMessages in local storage
export function setRemovedMessages(removedMessages) {
chrome.runtime.sendMessage(EXTENSION_ID, {
removedMessages: JSON.stringify(removedMessages)
});
}
// sends a message to the background script to set lastPurgeTime in local storage
export function setLastPurgeTime() {
chrome.runtime.sendMessage(EXTENSION_ID, {
lastPurgeTime: new Date().getTime()
});
}
// returns the removed message for a message removed by the current user (yourself)
export function _getViewerAuthorFbt(removedMessage) {
return `You removed a message${getRemovedMessageText(removedMessage)}`;
}
// returns the removed message for a message removed by a contact
export function _getOtherAuthorFbt(name, removedMessage) {
return `${name} removed a message${getRemovedMessageText(removedMessage)}` ;
}
// returns the removed message for a message removed by an unknown user
export function _getUnknownAuthorFbt(removedMessage) {
return `A contact removed a message${getRemovedMessageText(removedMessage)}`;
}
// returns removedMessage if it's not null, else returns an empty string
function getRemovedMessageText(removedMessage) {
return removedMessage ? `: ${removedMessage}` : '';
}
// returns a reduced form of the message object (only the necessary keys and values)
export function getReducedMessageObject({
message_id,
thread_id,
offline_threading_id,
author,
body,
has_attachment,
attachments,
timestamp
}) {
return {
message_id,
thread_id,
offline_threading_id,
author,
body,
has_attachment,
attachments,
timestamp
};
}