summaryrefslogtreecommitdiff
path: root/src/client/app/common/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/app/common/scripts')
-rw-r--r--src/client/app/common/scripts/check-for-update.ts13
-rw-r--r--src/client/app/common/scripts/compose-notification.ts10
-rw-r--r--src/client/app/common/scripts/copy-to-clipboard.ts30
-rw-r--r--src/client/app/common/scripts/format-uptime.ts25
-rw-r--r--src/client/app/common/scripts/fuck-ad-block.ts2
-rw-r--r--src/client/app/common/scripts/get-face.ts2
-rw-r--r--src/client/app/common/scripts/get-md5.ts4
-rw-r--r--src/client/app/common/scripts/get-median.ts11
-rw-r--r--src/client/app/common/scripts/note-mixin.ts28
-rw-r--r--src/client/app/common/scripts/note-subscriber.ts21
-rw-r--r--src/client/app/common/scripts/should-mute-note.ts34
-rw-r--r--src/client/app/common/scripts/stream.ts10
12 files changed, 122 insertions, 68 deletions
diff --git a/src/client/app/common/scripts/check-for-update.ts b/src/client/app/common/scripts/check-for-update.ts
index 7fe9d8d50c..20da83a0c2 100644
--- a/src/client/app/common/scripts/check-for-update.ts
+++ b/src/client/app/common/scripts/check-for-update.ts
@@ -14,19 +14,20 @@ export default async function($root: any, force = false, silent = false) {
navigator.serviceWorker.controller.postMessage('clear');
}
- navigator.serviceWorker.getRegistrations().then(registrations => {
- registrations.forEach(registration => registration.unregister());
- });
+ const registrations = await navigator.serviceWorker.getRegistrations();
+ for (const registration of registrations) {
+ registration.unregister();
+ }
} catch (e) {
console.error(e);
}
- if (!silent) {
- $root.alert({
+ /*if (!silent) {
+ $root.dialog({
title: $root.$t('@.update-available-title'),
text: $root.$t('@.update-available', { newer, current })
});
- }
+ }*/
return newer;
} else {
diff --git a/src/client/app/common/scripts/compose-notification.ts b/src/client/app/common/scripts/compose-notification.ts
index 65087cc98e..f65672ee30 100644
--- a/src/client/app/common/scripts/compose-notification.ts
+++ b/src/client/app/common/scripts/compose-notification.ts
@@ -22,7 +22,7 @@ export default function(type, data): Notification {
case 'unreadMessagingMessage':
return {
- title: '%i18n:common.notification.message-from%'.split("{}")[0] + `${getUserName(data.user)}` + '%i18n:common.notification.message-from%'.split("{}")[1] ,
+ title: '%i18n:common.notification.message-from%'.split('{}')[0] + `${getUserName(data.user)}` + '%i18n:common.notification.message-from%'.split('{}')[1] ,
body: data.text, // TODO: getMessagingMessageSummary(data),
icon: data.user.avatarUrl
};
@@ -30,7 +30,7 @@ export default function(type, data): Notification {
case 'reversiInvited':
return {
title: '%i18n:common.notification.reversi-invited%',
- body: '%i18n:common.notification.reversi-invited-by%'.split("{}")[0] + `${getUserName(data.parent)}` + '%i18n:common.notification.reversi-invited-by%'.split("{}")[1],
+ body: '%i18n:common.notification.reversi-invited-by%'.split('{}')[0] + `${getUserName(data.parent)}` + '%i18n:common.notification.reversi-invited-by%'.split('{}')[1],
icon: data.parent.avatarUrl
};
@@ -38,21 +38,21 @@ export default function(type, data): Notification {
switch (data.type) {
case 'mention':
return {
- title: '%i18n:common.notification.notified-by%'.split("{}")[0] + `${getUserName(data.user)}:` + '%i18n:common.notification.notified-by%'.split("{}")[1],
+ title: '%i18n:common.notification.notified-by%'.split('{}')[0] + `${getUserName(data.user)}:` + '%i18n:common.notification.notified-by%'.split('{}')[1],
body: getNoteSummary(data),
icon: data.user.avatarUrl
};
case 'reply':
return {
- title: '%i18n:common.notification.reply-from%'.split("{}")[0] + `${getUserName(data.user)}` + '%i18n:common.notification.reply-from%'.split("{}")[1],
+ title: '%i18n:common.notification.reply-from%'.split('{}')[0] + `${getUserName(data.user)}` + '%i18n:common.notification.reply-from%'.split('{}')[1],
body: getNoteSummary(data),
icon: data.user.avatarUrl
};
case 'quote':
return {
- title: '%i18n:common.notification.quoted-by%'.split("{}")[0] + `${getUserName(data.user)}` + '%i18n:common.notification.quoted-by%'.split("{}")[1],
+ title: '%i18n:common.notification.quoted-by%'.split('{}')[0] + `${getUserName(data.user)}` + '%i18n:common.notification.quoted-by%'.split('{}')[1],
body: getNoteSummary(data),
icon: data.user.avatarUrl
};
diff --git a/src/client/app/common/scripts/copy-to-clipboard.ts b/src/client/app/common/scripts/copy-to-clipboard.ts
index 3d2741f8d7..ab13cab970 100644
--- a/src/client/app/common/scripts/copy-to-clipboard.ts
+++ b/src/client/app/common/scripts/copy-to-clipboard.ts
@@ -2,12 +2,32 @@
* Clipboardに値をコピー(TODO: 文字列以外も対応)
*/
export default val => {
- const form = document.createElement('textarea');
- form.textContent = val;
- document.body.appendChild(form);
- form.select();
+ // 空div 生成
+ const tmp = document.createElement('div');
+ // 選択用のタグ生成
+ const pre = document.createElement('pre');
+
+ // 親要素のCSSで user-select: none だとコピーできないので書き換える
+ pre.style.webkitUserSelect = 'auto';
+ pre.style.userSelect = 'auto';
+
+ tmp.appendChild(pre).textContent = val;
+
+ // 要素を画面外へ
+ const s = tmp.style;
+ s.position = 'fixed';
+ s.right = '200%';
+
+ // body に追加
+ document.body.appendChild(tmp);
+ // 要素を選択
+ document.getSelection().selectAllChildren(tmp);
+
+ // クリップボードにコピー
const result = document.execCommand('copy');
- document.body.removeChild(form);
+
+ // 要素削除
+ document.body.removeChild(tmp);
return result;
};
diff --git a/src/client/app/common/scripts/format-uptime.ts b/src/client/app/common/scripts/format-uptime.ts
new file mode 100644
index 0000000000..6550e4cc39
--- /dev/null
+++ b/src/client/app/common/scripts/format-uptime.ts
@@ -0,0 +1,25 @@
+
+/**
+ * Format like the uptime command
+ */
+export default function(sec) {
+ if (!sec) return sec;
+
+ const day = Math.floor(sec / 86400);
+ const tod = sec % 86400;
+
+ // Days part in string: 2 days, 1 day, null
+ const d = day >= 2 ? `${day} days` : day >= 1 ? `${day} day` : null;
+
+ // Time part in string: 1 sec, 1 min, 1:01
+ const t
+ = tod < 60 ? `${Math.floor(tod)} sec`
+ : tod < 3600 ? `${Math.floor(tod / 60)} min`
+ : `${Math.floor(tod / 60 / 60)}:${Math.floor((tod / 60) % 60).toString().padStart(2, '0')}`;
+
+ let str = '';
+ if (d) str += `${d}, `;
+ str += t;
+
+ return str;
+}
diff --git a/src/client/app/common/scripts/fuck-ad-block.ts b/src/client/app/common/scripts/fuck-ad-block.ts
index f5cc1b71f2..ba7e5a9f87 100644
--- a/src/client/app/common/scripts/fuck-ad-block.ts
+++ b/src/client/app/common/scripts/fuck-ad-block.ts
@@ -4,7 +4,7 @@ export default ($root: any) => {
require('fuckadblock');
function adBlockDetected() {
- $root.alert({
+ $root.dialog({
title: $root.$t('@.adblock.detected'),
text: $root.$t('@.adblock.warning')
});
diff --git a/src/client/app/common/scripts/get-face.ts b/src/client/app/common/scripts/get-face.ts
index 79cf7a1be4..b523948bd3 100644
--- a/src/client/app/common/scripts/get-face.ts
+++ b/src/client/app/common/scripts/get-face.ts
@@ -2,7 +2,7 @@ const faces = [
'(=^・・^=)',
'v(\'ω\')v',
'🐡( \'-\' 🐡 )フグパンチ!!!!',
- '🖕(´・_・`)🖕',
+ '✌️(´・_・`)✌️',
'(。>﹏<。)',
'(Δ・x・Δ)'
];
diff --git a/src/client/app/common/scripts/get-md5.ts b/src/client/app/common/scripts/get-md5.ts
index 51a45b30d5..b78a598118 100644
--- a/src/client/app/common/scripts/get-md5.ts
+++ b/src/client/app/common/scripts/get-md5.ts
@@ -3,8 +3,8 @@
export default (data: ArrayBuffer) => {
//const buf = new Buffer(data);
- //const hash = crypto.createHash("md5");
+ //const hash = crypto.createHash('md5');
//hash.update(buf);
- //return hash.digest("hex");
+ //return hash.digest('hex');
return '';
};
diff --git a/src/client/app/common/scripts/get-median.ts b/src/client/app/common/scripts/get-median.ts
deleted file mode 100644
index 91a415d5b2..0000000000
--- a/src/client/app/common/scripts/get-median.ts
+++ /dev/null
@@ -1,11 +0,0 @@
-/**
- * 中央値を求めます
- * @param samples サンプル
- */
-export default function(samples) {
- if (!samples.length) return 0;
- const numbers = samples.slice(0).sort((a, b) => a - b);
- const middle = Math.floor(numbers.length / 2);
- const isEven = numbers.length % 2 === 0;
- return isEven ? (numbers[middle] + numbers[middle - 1]) / 2 : numbers[middle];
-}
diff --git a/src/client/app/common/scripts/note-mixin.ts b/src/client/app/common/scripts/note-mixin.ts
index e0df788b34..047e2ae55e 100644
--- a/src/client/app/common/scripts/note-mixin.ts
+++ b/src/client/app/common/scripts/note-mixin.ts
@@ -65,6 +65,10 @@ export default (opts: Opts = {}) => ({
return this.isRenote ? this.note.renote : this.note;
},
+ isMyNote(): boolean {
+ return this.$store.getters.isSignedIn && (this.$store.state.i.id === this.appearNote.userId);
+ },
+
reactionsCount(): number {
return this.appearNote.reactionCounts
? sum(Object.values(this.appearNote.reactionCounts))
@@ -72,15 +76,16 @@ export default (opts: Opts = {}) => ({
},
title(): string {
- return new Date(this.appearNote.createdAt).toLocaleString();
+ return '';
},
urls(): string[] {
if (this.appearNote.text) {
const ast = parse(this.appearNote.text);
+ // TODO: 再帰的にURL要素がないか調べる
return unique(ast
- .filter(t => (t.type == 'url' || t.type == 'link') && !t.silent)
- .map(t => t.url));
+ .filter(t => ((t.node.type == 'url' || t.node.type == 'link') && t.node.props.url && !t.node.props.silent))
+ .map(t => t.node.props.url));
} else {
return null;
}
@@ -124,9 +129,7 @@ export default (opts: Opts = {}) => ({
source: this.$refs.reactButton,
note: this.appearNote,
showFocus: viaKeyboard,
- animation: !viaKeyboard,
- compact: opts.mobile,
- big: opts.mobile
+ animation: !viaKeyboard
}).$once('closed', this.focus);
},
@@ -137,11 +140,19 @@ export default (opts: Opts = {}) => ({
});
},
+ undoReact(note) {
+ const oldReaction = note.myReaction;
+ if (!oldReaction) return;
+ this.$root.api('notes/reactions/delete', {
+ noteId: note.id
+ });
+ },
+
favorite() {
this.$root.api('notes/favorites/create', {
noteId: this.appearNote.id
}).then(() => {
- this.$root.alert({
+ this.$root.dialog({
type: 'success',
splash: true
});
@@ -158,8 +169,7 @@ export default (opts: Opts = {}) => ({
this.$root.new(MkNoteMenu, {
source: this.$refs.menuButton,
note: this.appearNote,
- animation: !viaKeyboard,
- compact: opts.mobile,
+ animation: !viaKeyboard
}).$once('closed', this.focus);
},
diff --git a/src/client/app/common/scripts/note-subscriber.ts b/src/client/app/common/scripts/note-subscriber.ts
index bc434c4360..9545b5406b 100644
--- a/src/client/app/common/scripts/note-subscriber.ts
+++ b/src/client/app/common/scripts/note-subscriber.ts
@@ -95,6 +95,7 @@ export default prop => ({
Vue.set(this.$_ns_target.reactionCounts, reaction, 0);
}
+ // Increment the count
this.$_ns_target.reactionCounts[reaction]++;
if (body.userId == this.$store.state.i.id) {
@@ -103,6 +104,26 @@ export default prop => ({
break;
}
+ case 'unreacted': {
+ const reaction = body.reaction;
+
+ if (this.$_ns_target.reactionCounts == null) {
+ return;
+ }
+
+ if (this.$_ns_target.reactionCounts[reaction] == null) {
+ return;
+ }
+
+ // Decrement the count
+ if (this.$_ns_target.reactionCounts[reaction] > 0) this.$_ns_target.reactionCounts[reaction]--;
+
+ if (body.userId == this.$store.state.i.id) {
+ Vue.set(this.$_ns_target, 'myReaction', null);
+ }
+ break;
+ }
+
case 'pollVoted': {
if (body.userId == this.$store.state.i.id) return;
const choice = body.choice;
diff --git a/src/client/app/common/scripts/should-mute-note.ts b/src/client/app/common/scripts/should-mute-note.ts
index a849135763..8a6430b1df 100644
--- a/src/client/app/common/scripts/should-mute-note.ts
+++ b/src/client/app/common/scripts/should-mute-note.ts
@@ -2,27 +2,17 @@ export default function(me, settings, note) {
const isMyNote = note.userId == me.id;
const isPureRenote = note.renoteId != null && note.text == null && note.fileIds.length == 0 && note.poll == null;
- if (settings.showMyRenotes === false) {
- if (isMyNote && isPureRenote) {
- return true;
- }
- }
+ const includesMutedWords = (text: string) =>
+ text
+ ? settings.mutedWords.some(q => q.length > 0 && !q.some(word => !text.includes(word)))
+ : false;
- if (settings.showRenotedMyNotes === false) {
- if (isPureRenote && (note.renote.userId == me.id)) {
- return true;
- }
- }
-
- if (settings.showLocalRenotes === false) {
- if (isPureRenote && (note.renote.user.host == null)) {
- return true;
- }
- }
-
- if (!isMyNote && note.text && settings.mutedWords.some(q => !q.some(word => !note.text.includes(word)))) {
- return true;
- }
-
- return false;
+ return (
+ (!isMyNote && note.reply && includesMutedWords(note.reply.text)) ||
+ (!isMyNote && note.renote && includesMutedWords(note.renote.text)) ||
+ (settings.showMyRenotes === false && isMyNote && isPureRenote) ||
+ (settings.showRenotedMyNotes === false && isPureRenote && note.renote.userId == me.id) ||
+ (settings.showLocalRenotes === false && isPureRenote && note.renote.user.host == null) ||
+ (!isMyNote && includesMutedWords(note.text))
+ );
}
diff --git a/src/client/app/common/scripts/stream.ts b/src/client/app/common/scripts/stream.ts
index 345b112b15..23f839ae85 100644
--- a/src/client/app/common/scripts/stream.ts
+++ b/src/client/app/common/scripts/stream.ts
@@ -75,12 +75,10 @@ export default class Stream extends EventEmitter {
// チャンネル再接続
if (isReconnect) {
- this.sharedConnectionPools.forEach(p => {
+ for (const p of this.sharedConnectionPools)
p.connect();
- });
- this.nonSharedConnections.forEach(c => {
+ for (const c of this.nonSharedConnections)
c.connect();
- });
}
}
@@ -113,9 +111,9 @@ export default class Stream extends EventEmitter {
connections = [this.nonSharedConnections.find(c => c.id === id)];
}
- connections.filter(c => c != null).forEach(c => {
+ for (const c of connections.filter(c => c != null)) {
c.emit(body.type, body.body);
- });
+ }
} else {
this.emit(type, body);
}