Update DirectMessageController
This commit is contained in:
parent
da4c5fb808
commit
f796cc7c11
|
@ -19,6 +19,7 @@ use App\Services\MediaBlocklistService;
|
|||
use App\Jobs\StatusPipeline\NewStatusPipeline;
|
||||
use Illuminate\Support\Str;
|
||||
use App\Util\ActivityPub\Helpers;
|
||||
use App\Services\WebfingerService;
|
||||
|
||||
class DirectMessageController extends Controller
|
||||
{
|
||||
|
@ -241,6 +242,7 @@ class DirectMessageController extends Controller
|
|||
$res = [
|
||||
'id' => (string) $dm->id,
|
||||
'isAuthor' => $profile->id == $dm->from_id,
|
||||
'reportId' => (string) $dm->status_id,
|
||||
'hidden' => (bool) $dm->is_hidden,
|
||||
'type' => $dm->type,
|
||||
'text' => $dm->status->caption,
|
||||
|
@ -264,7 +266,7 @@ class DirectMessageController extends Controller
|
|||
$min_id = $request->input('min_id');
|
||||
|
||||
$r = Profile::findOrFail($pid);
|
||||
// $r = Profile::whereNull('domain')->findOrFail($pid);
|
||||
// $r = Profile::whereNull('domain')->findOrFail($pid);
|
||||
|
||||
if($min_id) {
|
||||
$res = DirectMessage::select('*')
|
||||
|
@ -319,10 +321,10 @@ class DirectMessageController extends Controller
|
|||
'avatar' => $r->avatarUrl(),
|
||||
'url' => $r->url(),
|
||||
'muted' => UserFilter::whereUserId($uid)
|
||||
->whereFilterableId($r->id)
|
||||
->whereFilterableType('App\Profile')
|
||||
->whereFilterType('dm.mute')
|
||||
->first() ? true : false,
|
||||
->whereFilterableId($r->id)
|
||||
->whereFilterableType('App\Profile')
|
||||
->whereFilterType('dm.mute')
|
||||
->first() ? true : false,
|
||||
'isLocal' => (bool) !$r->domain,
|
||||
'domain' => $r->domain,
|
||||
'timeAgo' => $r->created_at->diffForHumans(null, true, true),
|
||||
|
@ -343,7 +345,8 @@ class DirectMessageController extends Controller
|
|||
$pid = $request->user()->profile_id;
|
||||
|
||||
$dm = DirectMessage::whereFromId($pid)
|
||||
->findOrFail($sid);
|
||||
->whereStatusId($sid)
|
||||
->firstOrFail();
|
||||
|
||||
$status = Status::whereProfileId($pid)
|
||||
->findOrFail($dm->status_id);
|
||||
|
@ -452,6 +455,8 @@ class DirectMessageController extends Controller
|
|||
}
|
||||
|
||||
return [
|
||||
'id' => $dm->id,
|
||||
'reportId' => (string) $dm->status_id,
|
||||
'type' => $dm->type,
|
||||
'url' => $media->url()
|
||||
];
|
||||
|
@ -460,12 +465,50 @@ class DirectMessageController extends Controller
|
|||
public function composeLookup(Request $request)
|
||||
{
|
||||
$this->validate($request, [
|
||||
'username' => 'required'
|
||||
'q' => 'required|string|min:1|max:50',
|
||||
'remote' => 'nullable|boolean',
|
||||
]);
|
||||
$username = $request->input('username');
|
||||
$profile = Profile::whereUsername($username)->firstOrFail();
|
||||
|
||||
return ['id' => (string)$profile->id];
|
||||
$q = $request->input('q');
|
||||
$r = $request->input('remote');
|
||||
|
||||
if($r && Helpers::validateUrl($q)) {
|
||||
Helpers::profileFetch($q);
|
||||
}
|
||||
|
||||
if(Str::of($q)->startsWith('@')) {
|
||||
if(strlen($q) < 3) {
|
||||
return [];
|
||||
}
|
||||
if(substr_count($q, '@') == 2) {
|
||||
WebfingerService::lookup($q);
|
||||
}
|
||||
$q = mb_substr($q, 1);
|
||||
}
|
||||
|
||||
$blocked = UserFilter::whereFilterableType('App\Profile')
|
||||
->whereFilterType('block')
|
||||
->whereFilterableId($request->user()->profile_id)
|
||||
->pluck('user_id');
|
||||
|
||||
$blocked->push($request->user()->profile_id);
|
||||
|
||||
$results = Profile::select('id','domain','username')
|
||||
->whereNotIn('id', $blocked)
|
||||
->where('username','like','%'.$q.'%')
|
||||
->limit(15)
|
||||
->get()
|
||||
->map(function($r) {
|
||||
return [
|
||||
'local' => (bool) !$r->domain,
|
||||
'id' => (string) $r->id,
|
||||
'name' => $r->username,
|
||||
'privacy' => true,
|
||||
'avatar' => $r->avatarUrl()
|
||||
];
|
||||
});
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
||||
public function read(Request $request)
|
||||
|
@ -529,6 +572,7 @@ class DirectMessageController extends Controller
|
|||
->firstOrFail();
|
||||
|
||||
$f->delete();
|
||||
|
||||
return [200];
|
||||
}
|
||||
|
||||
|
@ -536,6 +580,7 @@ class DirectMessageController extends Controller
|
|||
{
|
||||
$profile = $dm->author;
|
||||
$url = $dm->recipient->inbox_url;
|
||||
|
||||
$tags = [
|
||||
[
|
||||
'type' => 'Mention',
|
||||
|
@ -543,6 +588,7 @@ class DirectMessageController extends Controller
|
|||
'name' => $dm->recipient->emailUrl(),
|
||||
]
|
||||
];
|
||||
|
||||
$body = [
|
||||
'@context' => [
|
||||
'https://www.w3.org/ns/activitystreams',
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
<div class="card-header bg-white py-4">
|
||||
<span class="h4 font-weight-bold mb-0">Direct Messages</span>
|
||||
<span class="float-right">
|
||||
<a class="btn btn-outline-primary font-weight-bold py-0" href="#" @click.prevent="goto('add')">New Message</a>
|
||||
<a class="btn btn-outline-primary font-weight-bold py-0 rounded-pill" href="#" @click.prevent="goto('add')">New Message</a>
|
||||
</span>
|
||||
</div>
|
||||
<div class="card-header bg-white">
|
||||
|
@ -155,17 +155,11 @@
|
|||
<span><i class="fas fa-chevron-right text-white"></i></span>
|
||||
</div>
|
||||
<div class="card-body d-flex align-items-center justify-content-center" style="height: 60vh;">
|
||||
<div class="">
|
||||
<p class="form-group">
|
||||
<label>To:</label>
|
||||
<!-- <div class="input-group pt-0">
|
||||
<div class="input-group-prepend">
|
||||
<span class="input-group-text" id="basic-addon1">@</span>
|
||||
</div>
|
||||
<input v-model="composeUsername" type="text" class="form-control" placeholder="dansup">
|
||||
</div> -->
|
||||
<autocomplete
|
||||
<div>
|
||||
<p class="mb-0 font-weight-bold">Select Recipient</p>
|
||||
<autocomplete
|
||||
:search="composeSearch"
|
||||
:disabled="composeLoading"
|
||||
placeholder="@dansup"
|
||||
aria-label="Search usernames"
|
||||
:get-result-value="getTagResultValue"
|
||||
|
@ -173,15 +167,7 @@
|
|||
ref="autocomplete"
|
||||
>
|
||||
</autocomplete>
|
||||
<span class="help-text small text-muted">Select a username to send a message to.</span>
|
||||
</p>
|
||||
<hr>
|
||||
<!-- <p>
|
||||
<button type="button" class="btn btn-primary font-weight-bold btn-block" @click="composeUsernameSelect()" :disabled="!composeUsername.length">Next</button>
|
||||
</p> -->
|
||||
<ul class="text-muted">
|
||||
<li>You cannot message remote accounts yet.</li>
|
||||
</ul>
|
||||
<div style="width:300px;"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -229,7 +215,10 @@ export default {
|
|||
inbox: [],
|
||||
sent: [],
|
||||
filtered: []
|
||||
}
|
||||
},
|
||||
|
||||
newType: 'select',
|
||||
composeLoading: false,
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -259,18 +248,9 @@ export default {
|
|||
window._sharedData.curUser = res.data;
|
||||
});
|
||||
},
|
||||
|
||||
goto(l = 'browse') {
|
||||
this.page = l;
|
||||
let url = '/account/direct';
|
||||
switch(l) {
|
||||
case 'read':
|
||||
url = '/account/direct/t/' + this.thread.id;
|
||||
break;
|
||||
case 'add':
|
||||
url += '#/new';
|
||||
break;
|
||||
}
|
||||
window.history.pushState({},'',url);
|
||||
},
|
||||
|
||||
loadMessage(id) {
|
||||
|
@ -279,24 +259,6 @@ export default {
|
|||
return;
|
||||
},
|
||||
|
||||
composeUsernameSelect() {
|
||||
if(this.profile.username == this.composeUsername) {
|
||||
swal('Ooops!', 'You cannot send a direct message to yourself.', 'error');
|
||||
this.composeUsername = '';
|
||||
return;
|
||||
}
|
||||
axios.post('/api/direct/lookup', {
|
||||
username: this.composeUsername
|
||||
}).then(res => {
|
||||
let url = '/account/direct/t/' + res.data.id;
|
||||
window.location.href = url;
|
||||
}).catch(err => {
|
||||
let msg = 'The username you entered is incorrect. Please try again';
|
||||
swal('Ooops!', msg, 'error');
|
||||
this.composeUsername = '';
|
||||
});
|
||||
},
|
||||
|
||||
truncate(t) {
|
||||
return _.truncate(t);
|
||||
},
|
||||
|
@ -345,21 +307,21 @@ export default {
|
|||
if (input.length < 1) { return []; };
|
||||
let self = this;
|
||||
let results = [];
|
||||
return axios.get('/api/local/compose/tag/search', {
|
||||
params: {
|
||||
q: input
|
||||
}
|
||||
return axios.post('/api/direct/lookup', {
|
||||
q: input
|
||||
}).then(res => {
|
||||
return res.data;
|
||||
});
|
||||
},
|
||||
|
||||
getTagResultValue(result) {
|
||||
return '@' + result.name;
|
||||
// return '@' + result.name;
|
||||
return result.local ? '@' + result.name : result.name;
|
||||
},
|
||||
|
||||
onTagSubmitLocation(result) {
|
||||
//this.$refs.autocomplete.value = '';
|
||||
this.composeLoading = true;
|
||||
window.location.href = '/account/direct/t/' + result.id;
|
||||
return;
|
||||
},
|
||||
|
|
|
@ -480,7 +480,7 @@
|
|||
if(c) {
|
||||
axios.delete('/api/direct/message', {
|
||||
params: {
|
||||
id: self.ctxContext.id
|
||||
id: self.ctxContext.reportId
|
||||
}
|
||||
}).then(res => {
|
||||
self.threads[self.threadIndex].messages.splice(self.ctxIndex,1);
|
||||
|
@ -543,8 +543,9 @@
|
|||
self.uploadProgress = 100;
|
||||
self.uploading = false;
|
||||
let msg = {
|
||||
id: Date.now(),
|
||||
id: e.data.id,
|
||||
type: e.data.type,
|
||||
reportId: e.data.reportId,
|
||||
isAuthor: true,
|
||||
text: null,
|
||||
media: e.data.url,
|
||||
|
|
Loading…
Reference in a new issue