Skip to content

Commit 4091816

Browse files
authored
Merge pull request #12 from yakshaG/v1.0.1
V1.0.1
2 parents 124dd0a + a94fe2f commit 4091816

3 files changed

Lines changed: 26 additions & 16 deletions

File tree

extension/background.js

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -77,19 +77,19 @@ function webRequestCallback(eventType, uuid) {
7777

7878

7979
function readPreMeetingSlackStatus() {
80-
var key;
80+
let key;
8181
chrome.storage.sync.get(["meetSlackKey", "statusText"], function (data) {
8282
if (data.meetSlackKey) {
8383
key = data.meetSlackKey;
8484

85-
var myHeaders = new Headers();
85+
const myHeaders = new Headers();
8686
myHeaders.append(
8787
"Authorization",
8888
`Bearer ${key}`
8989
);
9090
myHeaders.append("Content-Type", "application/x-www-form-urlencoded");
9191

92-
var requestOptions = {
92+
const requestOptions = {
9393
method: "GET",
9494
headers: myHeaders,
9595
redirect: "follow",
@@ -100,7 +100,7 @@ function readPreMeetingSlackStatus() {
100100
.then((result) => {
101101
// Save Pre meeting slack status, if status read was successful
102102
if (result.ok === true) {
103-
console.log(result.profile.status_emoji + " | " + result.profile.status_text + " | " + data.statusText + " | " + result.profile.status_expiration)
103+
console.log(data.statusText + " | " + result.profile.status_emoji + " | " + result.profile.status_text + " | " + result.profile.status_expiration)
104104

105105
let preMeetingSlackStatusJSON;
106106
if (data.statusText == result.profile.status_text) {
@@ -161,15 +161,15 @@ function setSlackStatus() {
161161
text = result.statusText;
162162
}
163163

164-
var raw = JSON.stringify({
164+
const raw = JSON.stringify({
165165
profile: {
166166
status_text: text,
167167
status_emoji: emoji,
168168
status_expiration: 0,
169169
},
170170
});
171171

172-
makeSlackAPICall(raw, "set");
172+
makeSlackAPICall(raw);
173173
});
174174
}
175175

@@ -178,10 +178,20 @@ function clearSlackStatus() {
178178
let raw;
179179
if (result.preMeetingSlackStatus) {
180180
let preMeetingSlackStatus = JSON.parse(result.preMeetingSlackStatus)
181-
console.log("Status expiry diff " + (preMeetingSlackStatus.status_expiration - parseInt(Date.now() / 1000)))
182-
if (((preMeetingSlackStatus.status_expiration - parseInt(Date.now() / 1000)) > 0)) {
181+
const statusExpiryDelta = (preMeetingSlackStatus.status_expiration - parseInt(Date.now() / 1000))
182+
console.log(`Status expiry diff ${statusExpiryDelta}`)
183+
if (preMeetingSlackStatus.status_expiration == 0) {
184+
console.log("Status validity is indefinite. Setting that status blindly.")
185+
raw = JSON.stringify({
186+
profile: {
187+
status_text: preMeetingSlackStatus.status_text,
188+
status_emoji: preMeetingSlackStatus.status_emoji,
189+
status_expiration: preMeetingSlackStatus.status_expiration,
190+
},
191+
});
192+
}
193+
else if (statusExpiryDelta > 0) {
183194
console.log("Found pre meeting slack status. Putting it back. " + result.preMeetingSlackStatus)
184-
185195
raw = JSON.stringify({
186196
profile: {
187197
status_text: preMeetingSlackStatus.status_text,
@@ -212,26 +222,26 @@ function clearSlackStatus() {
212222
});
213223
}
214224

215-
makeSlackAPICall(raw, "clear");
225+
makeSlackAPICall(raw);
216226
})
217227
}
218228

219229

220-
function makeSlackAPICall(raw, type) {
221-
var key;
230+
function makeSlackAPICall(raw) {
231+
let key;
222232
chrome.storage.sync.get(["meetSlackKey"], function (result) {
223233

224234
if (result.meetSlackKey) {
225235
key = result.meetSlackKey;
226236

227-
var myHeaders = new Headers();
237+
const myHeaders = new Headers();
228238
myHeaders.append(
229239
"Authorization",
230240
`Bearer ${key}`
231241
);
232242
myHeaders.append("Content-Type", "application/json");
233243

234-
var requestOptions = {
244+
const requestOptions = {
235245
method: "POST",
236246
headers: myHeaders,
237247
body: raw,
@@ -241,7 +251,7 @@ function makeSlackAPICall(raw, type) {
241251
fetch("https://slack.com/api/users.profile.set", requestOptions)
242252
.then((response) => response.text())
243253
.then((result) => {
244-
// console.log("Slack status altered")
254+
console.log(`Slack status altered ${JSON.parse(result).ok}`)
245255
})
246256
.catch((error) => console.log("error", error));
247257
}

extension/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "Google Meet ⇔ Slack integration",
3-
"version": "1.0.0",
3+
"version": "1.0.1",
44
"manifest_version": 3,
55
"description": "Real-time Google Meet status on Slack, just like Slack huddles.",
66
"action": {

extension_screenshot_2.png

431 KB
Loading

0 commit comments

Comments
 (0)