Skip to content

Send and receive SMS messages using your Android phone programmatically via a simple HTTP API

Fix prettier

Acho Arnoldedee09a6d2bc
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index 3bdf9354..f2df5afe 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -14,6 +14,6 @@ repos:
- id: trailing-whitespace
- repo: https://github.com/pre-commit/mirrors-prettier
- rev: v3.0.0-alpha.6
+ rev: v2.7.1
hooks:
- id: prettier
diff --git a/web/components/FirebaseAuth.vue b/web/components/FirebaseAuth.vue
index c53ea9f7..061c0b36 100644
--- a/web/components/FirebaseAuth.vue
+++ b/web/components/FirebaseAuth.vue
@@ -46,7 +46,7 @@ export default class FirebaseAuth extends Vue {
return {
callbacks: {
signInSuccessWithAuthResult: (
- authResult: firebase.auth.UserCredential,
+ authResult: firebase.auth.UserCredential
) => {
this.$store.dispatch('addNotification', {
message: 'Login successfull!',
@@ -66,7 +66,7 @@ export default class FirebaseAuth extends Vue {
this.firebaseUIInitialized = true
const container = this.$refs.authContainer as HTMLElement
Array.from(
- container.getElementsByClassName('firebaseui-idp-text-long'),
+ container.getElementsByClassName('firebaseui-idp-text-long')
).forEach((item: Element) => {
item.textContent =
item.textContent?.replace('Sign in with', 'Continue with') || null
diff --git a/web/layouts/default.vue b/web/layouts/default.vue
index 0be46745..c72c2aad 100644
--- a/web/layouts/default.vue
+++ b/web/layouts/default.vue
@@ -40,14 +40,11 @@ export default class DefaultLayout extends Vue {
mounted() {
// this.startPoller()
- setTimeout(
- () => {
- if (this.poller) {
- clearInterval(this.poller)
- }
- },
- 60 * 1000 * 60,
- )
+ setTimeout(() => {
+ if (this.poller) {
+ clearInterval(this.poller)
+ }
+ }, 60 * 1000 * 60)
}
beforeDestroy(): void {
@@ -65,7 +62,7 @@ export default class DefaultLayout extends Vue {
setAuthHeader((await this.$fire.auth.currentUser?.getIdToken()) ?? '')
promises.push(
this.$store.dispatch('loadThreads'),
- this.$store.dispatch('getHeartbeat'),
+ this.$store.dispatch('getHeartbeat')
)
}
@@ -77,8 +74,8 @@ export default class DefaultLayout extends Vue {
promises.push(
this.$store.dispatch(
'loadThreadMessages',
- this.$store.getters.getThread.id,
- ),
+ this.$store.getters.getThread.id
+ )
)
}
await Promise.all(promises)
diff --git a/web/package.json b/web/package.json
index 5d114b01..d77c990f 100644
--- a/web/package.json
+++ b/web/package.json
@@ -62,7 +62,7 @@
"jest": "^27.4.4",
"lint-staged": "^13.2.0",
"postcss-html": "^1.5.0",
- "prettier": "3.0.0-alpha.6",
+ "prettier": "^2.8.4",
"stylelint": "^14.16.1",
"stylelint-config-prettier": "^9.0.5",
"stylelint-config-recommended-vue": "^1.1.0",
diff --git a/web/pages/billing/index.vue b/web/pages/billing/index.vue
index 16710aaf..819bb0ed 100644
--- a/web/pages/billing/index.vue
+++ b/web/pages/billing/index.vue
@@ -49,7 +49,7 @@
Your next bill is for <b>${{ plan.price }}</b> on
<b>{{
new Date(
- $store.getters.getUser.subscription_renews_at,
+ $store.getters.getUser.subscription_renews_at
).toLocaleDateString()
}}</b>
</p>
@@ -64,7 +64,7 @@
You will be downgraded to the <b>FREE</b> plan on
<b>{{
new Date(
- $store.getters.getUser.subscription_ends_at,
+ $store.getters.getUser.subscription_ends_at
).toLocaleDateString()
}}</b>
</p>
@@ -116,7 +116,7 @@
of the current billing period on
<b>{{
new Date(
- $store.getters.getUser.subscription_renews_at,
+ $store.getters.getUser.subscription_renews_at
).toLocaleDateString()
}}</b>
</p>
@@ -399,7 +399,7 @@ export default Vue.extend({
plan(): PaymentPlan {
return this.plans.find(
(x) =>
- x.id === (this.$store.getters.getUser?.subscription_name || 'free'),
+ x.id === (this.$store.getters.getUser?.subscription_name || 'free')
)!
},
isOnFreePlan(): boolean {
diff --git a/web/pages/messages/index.vue b/web/pages/messages/index.vue
index 3406443a..30ab925f 100644
--- a/web/pages/messages/index.vue
+++ b/web/pages/messages/index.vue
@@ -96,8 +96,8 @@ export default {
errors.set(
'to',
response.data.data.to.map((x) =>
- x.replace('to field', 'phone number field'),
- ),
+ x.replace('to field', 'phone number field')
+ )
)
}
if (response.data.data.from) {
diff --git a/web/pages/terms-and-conditions/index.vue b/web/pages/terms-and-conditions/index.vue
index adafd775..beb3979d 100644
--- a/web/pages/terms-and-conditions/index.vue
+++ b/web/pages/terms-and-conditions/index.vue
@@ -169,7 +169,7 @@ export default Vue.extend({
},
head() {
return {
- title: 'Terms And Conditions - Http SMS',
+ title: 'Terms And Conditions - httpSMS',
}
},
})
diff --git a/web/pages/threads/_id.vue b/web/pages/threads/_id.vue
index 0f4fda80..c1cf21ae 100644
--- a/web/pages/threads/_id.vue
+++ b/web/pages/threads/_id.vue
@@ -265,6 +265,7 @@ export default Vue.extend({
mdiCheckAll,
mdiCheck,
mdiAlert,
+ messages: [] as Message[],
mdiPackageUp,
mdiPackageDown,
mdiAccount,
@@ -277,13 +278,10 @@ export default Vue.extend({
},
head() {
return {
- title: 'Messages - Http SMS',
+ title: 'Messages - httpSMS',
}
},
computed: {
- messages(): Array<Message> {
- return [...this.$store.getters.getThreadMessages].reverse()
- },
contactIsPhoneNumber(): boolean {
return isValidPhoneNumber(this.$store.getters.getThread.contact)
},
@@ -320,17 +318,23 @@ export default Vue.extend({
)
},
+ loadMessages() {
+ this.$store
+ .dispatch('loadThreadMessages', this.$route.params.id)
+ .then((messages: Array<Message>) => {
+ this.messages = [...messages].reverse()
+ })
+ this.scrollToElement()
+ },
+
async loadData() {
await this.$store.dispatch('loadPhones')
await this.$store.dispatch('loadThreads')
if (!this.$store.getters.hasThreadId(this.$route.params.id)) {
await this.$router.push({ name: 'threads' })
- return
+ this.loadMessages()
}
-
- await this.$store.dispatch('loadThreadMessages', this.$route.params.id)
- this.scrollToElement()
},
isMT(message: Message): boolean {
@@ -373,12 +377,7 @@ export default Vue.extend({
this.selectedMenuItem = -1
}, 1000)
- await this.$store.dispatch(
- 'loadThreadMessages',
- this.$store.getters.getThread.id,
- )
-
- this.scrollToElement()
+ this.loadMessages()
},
async sendMessage(event: KeyboardEvent) {
diff --git a/web/pages/threads/index.vue b/web/pages/threads/index.vue
index 09452fae..cfb91a06 100644
--- a/web/pages/threads/index.vue
+++ b/web/pages/threads/index.vue
@@ -30,7 +30,7 @@ export default {
middleware: ['auth'],
head() {
return {
- title: 'Threads - Http SMS',
+ title: 'Threads - httpSMS',
}
},
async mounted() {
diff --git a/web/plugins/errors.ts b/web/plugins/errors.ts
index 437b641f..813c6b63 100644
--- a/web/plugins/errors.ts
+++ b/web/plugins/errors.ts
@@ -21,7 +21,7 @@ const sanitize = (key: string, values: Array<string>): Array<string> => {
.split(' char')
.join(' character')
.split(' field ')
- .join(' '),
+ .join(' ')
)
})
}
diff --git a/web/store/index.ts b/web/store/index.ts
index 2c35192a..2b10bf6a 100644
--- a/web/store/index.ts
+++ b/web/store/index.ts
@@ -57,7 +57,6 @@ export type State = {
heartbeat: null | Heartbeat
pooling: boolean
notification: Notification
- threadMessages: Array<Message>
}
export const state = (): State => ({
@@ -72,7 +71,6 @@ export const state = (): State => ({
archivedThreads: false,
loadingMessages: true,
pooling: false,
- threadMessages: [],
phones: [],
user: null,
owner: null,
@@ -172,10 +170,6 @@ export const getters = {
return state.loadingMessages
},
- getThreadMessages(state: State): Array<Message> {
- return state.threadMessages
- },
-
getThread(state: State): MessageThread {
const thread = state.threads.find((x) => x.id === state.threadId)
if (thread === undefined) {
@@ -215,10 +209,6 @@ export const mutations = {
setBillingUsage(state: State, payload: BillingUsage | null) {
state.billingUsage = payload
},
- setThreadMessages(state: State, payload: Array<Message>) {
- state.threadMessages = payload
- state.loadingMessages = false
- },
setHeartbeat(state: State, payload: Heartbeat | null) {
state.heartbeat = payload
},
@@ -277,7 +267,6 @@ export const mutations = {
state.phones = []
state.user = null
state.threadId = null
- state.threadMessages = []
state.archivedThreads = false
state.owner = null
},
@@ -355,7 +344,7 @@ export const actions = {
fcm_token: phone.fcm_token,
phone_number: phone.phone_number,
message_expiration_seconds: parseInt(
- phone.message_expiration_seconds.toString(),
+ phone.message_expiration_seconds.toString()
),
max_send_attempts: parseInt(phone.max_send_attempts.toString()),
messages_per_minute: parseInt(phone.messages_per_minute.toString()),
@@ -375,7 +364,7 @@ export const actions = {
async handleAxiosError(
context: ActionContext<State, State>,
- error: AxiosError,
+ error: AxiosError
) {
const errorMessage =
error.response?.data?.data[Object.keys(error.response?.data?.data)[0]][0]
@@ -410,7 +399,7 @@ export const actions = {
async sendMessage(
context: ActionContext<State, State>,
- request: SendMessageRequest,
+ request: SendMessageRequest
) {
try {
const response = await axios.post('/v1/messages/send', request)
@@ -426,10 +415,7 @@ export const actions = {
type: 'error',
})
}
- await Promise.all([
- context.dispatch('loadThreadMessages', context.getters.getThread.id),
- context.dispatch('loadThreads'),
- ])
+ await Promise.all([context.dispatch('loadThreads')])
},
setThreadId(context: ActionContext<State, State>, threadId: string | null) {
@@ -438,7 +424,7 @@ export const actions = {
addNotification(
context: ActionContext<State, State>,
- request: NotificationRequest,
+ request: NotificationRequest
) {
context.commit('setNotification', request)
},
@@ -447,24 +433,37 @@ export const actions = {
context.commit('disableNotification')
},
- async loadThreadMessages(
+ loadThreadMessages(
context: ActionContext<State, State>,
- threadId: string | null,
- ) {
- await context.commit('setThreadId', threadId)
- const response = await axios.get('/v1/messages', {
- params: {
- contact: context.getters.getThread.contact,
- owner: context.getters.getThread.owner,
- limit: 100,
- },
+ threadId: string | null
+ ): Promise<Array<Message>> {
+ context.commit('setThreadId', threadId)
+ return new Promise<Array<Message>>((resolve, reject) => {
+ axios
+ .get('/v1/messages', {
+ params: {
+ contact: context.getters.getThread.contact,
+ owner: context.getters.getThread.owner,
+ limit: 100,
+ },
+ })
+ .then((response: AxiosResponse) => {
+ resolve(response.data.data)
+ })
+ .catch(async (error: AxiosError) => {
+ await context.dispatch('addNotification', {
+ message:
+ error.response?.data?.message ?? 'Errors while fetching messages',
+ type: 'error',
+ })
+ reject(error)
+ })
})
- context.commit('setThreadMessages', response.data.data)
},
async setAuthUser(
context: ActionContext<State, State>,
- user: AuthUser | null | undefined,
+ user: AuthUser | null | undefined
) {
const userChanged = user?.id !== context.getters.getAuthUser?.id
@@ -481,7 +480,7 @@ export const actions = {
])
const phone = context.getters.getPhones.find(
- (x: Phone) => x.id === context.getters.getUser.active_phone_id,
+ (x: Phone) => x.id === context.getters.getUser.active_phone_id
)
if (phone) {
await context.dispatch('setOwner', phone.phone_number)
@@ -491,7 +490,7 @@ export const actions = {
async onAuthStateChanged(
context: ActionContext<State, State>,
// @ts-ignore
- { authUser },
+ { authUser }
) {
if (authUser == null) {
await Promise.all([
@@ -510,7 +509,7 @@ export const actions = {
async onIdTokenChanged(
_: ActionContext<State, State>,
// @ts-ignore
- { authUser },
+ { authUser }
) {
if (authUser == null) {
return
@@ -539,7 +538,7 @@ export const actions = {
async updateThread(
context: ActionContext<State, State>,
- payload: { threadId: string; isArchived: boolean },
+ payload: { threadId: string; isArchived: boolean }
) {
await axios.put(`/v1/message-threads/${payload.threadId}`, {
is_archived: payload.isArchived,
@@ -592,7 +591,7 @@ export const actions = {
createWebhook(
context: ActionContext<State, State>,
- payload: RequestsWebhookStore,
+ payload: RequestsWebhookStore
) {
return new Promise<EntitiesWebhook>((resolve, reject) => {
axios
@@ -640,7 +639,7 @@ export const actions = {
updateWebhook(
context: ActionContext<State, State>,
- payload: RequestsWebhookUpdate & { id: string },
+ payload: RequestsWebhookUpdate & { id: string }
) {
return new Promise<EntitiesWebhook>((resolve, reject) => {
axios
diff --git a/web/yarn.lock b/web/yarn.lock
index eb7a2ba0..e9f7ed0f 100644
--- a/web/yarn.lock
+++ b/web/yarn.lock
@@ -11398,12 +11398,7 @@ prepend-http@^1.0.0:
resolved "https://registry.yarnpkg.com/prepend-http/-/prepend-http-1.0.4.tgz#d4f4562b0ce3696e41ac52d0e002e57a635dc6dc"
integrity sha512-PhmXi5XmoyKw1Un4E+opM2KcsJInDvKyuOumcjjw3waw86ZNjHwVUOOWLc4bCzLdcKNaWBH9e99sbWzDQsVaYg==
- version "3.0.0-alpha.6"
- resolved "https://registry.yarnpkg.com/prettier/-/prettier-3.0.0-alpha.6.tgz#c562f9f54966aff792c6920e6a29fbffd1ae07b6"
- integrity sha512-AdbQSZ6Oo+iy9Ekzmsgno05P1uX2vqPkjOMJqRfP8hTe+m6iDw4Nt7bPFpWZ/HYCU+3f0P5U0o2ghxQwwkLH7A==
-
-"prettier@^1.18.2 || ^2.0.0":
+"prettier@^1.18.2 || ^2.0.0", prettier@^2.8.4:
version "2.8.4"
resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.8.4.tgz#34dd2595629bfbb79d344ac4a91ff948694463c3"
integrity sha512-vIS4Rlc2FNh0BySk3Wkd6xmwxB0FpOndW5fisM5H8hsZSxU2VWVB5CWIkIjWvrHjIhxk2g3bfMKM87zNTrZddw==