Update DirectMessageController

This commit is contained in:
Daniel Supernault 2020-11-18 23:07:00 -07:00
parent da4c5fb808
commit f796cc7c11
No known key found for this signature in database
GPG key ID: 0DEF1C662C9033F7
3 changed files with 77 additions and 68 deletions

View file

@ -19,6 +19,7 @@ use App\Services\MediaBlocklistService;
use App\Jobs\StatusPipeline\NewStatusPipeline; use App\Jobs\StatusPipeline\NewStatusPipeline;
use Illuminate\Support\Str; use Illuminate\Support\Str;
use App\Util\ActivityPub\Helpers; use App\Util\ActivityPub\Helpers;
use App\Services\WebfingerService;
class DirectMessageController extends Controller class DirectMessageController extends Controller
{ {
@ -241,6 +242,7 @@ class DirectMessageController extends Controller
$res = [ $res = [
'id' => (string) $dm->id, 'id' => (string) $dm->id,
'isAuthor' => $profile->id == $dm->from_id, 'isAuthor' => $profile->id == $dm->from_id,
'reportId' => (string) $dm->status_id,
'hidden' => (bool) $dm->is_hidden, 'hidden' => (bool) $dm->is_hidden,
'type' => $dm->type, 'type' => $dm->type,
'text' => $dm->status->caption, 'text' => $dm->status->caption,
@ -343,7 +345,8 @@ class DirectMessageController extends Controller
$pid = $request->user()->profile_id; $pid = $request->user()->profile_id;
$dm = DirectMessage::whereFromId($pid) $dm = DirectMessage::whereFromId($pid)
->findOrFail($sid); ->whereStatusId($sid)
->firstOrFail();
$status = Status::whereProfileId($pid) $status = Status::whereProfileId($pid)
->findOrFail($dm->status_id); ->findOrFail($dm->status_id);
@ -452,6 +455,8 @@ class DirectMessageController extends Controller
} }
return [ return [
'id' => $dm->id,
'reportId' => (string) $dm->status_id,
'type' => $dm->type, 'type' => $dm->type,
'url' => $media->url() 'url' => $media->url()
]; ];
@ -460,12 +465,50 @@ class DirectMessageController extends Controller
public function composeLookup(Request $request) public function composeLookup(Request $request)
{ {
$this->validate($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) public function read(Request $request)
@ -529,6 +572,7 @@ class DirectMessageController extends Controller
->firstOrFail(); ->firstOrFail();
$f->delete(); $f->delete();
return [200]; return [200];
} }
@ -536,6 +580,7 @@ class DirectMessageController extends Controller
{ {
$profile = $dm->author; $profile = $dm->author;
$url = $dm->recipient->inbox_url; $url = $dm->recipient->inbox_url;
$tags = [ $tags = [
[ [
'type' => 'Mention', 'type' => 'Mention',
@ -543,6 +588,7 @@ class DirectMessageController extends Controller
'name' => $dm->recipient->emailUrl(), 'name' => $dm->recipient->emailUrl(),
] ]
]; ];
$body = [ $body = [
'@context' => [ '@context' => [
'https://www.w3.org/ns/activitystreams', 'https://www.w3.org/ns/activitystreams',

View file

@ -6,7 +6,7 @@
<div class="card-header bg-white py-4"> <div class="card-header bg-white py-4">
<span class="h4 font-weight-bold mb-0">Direct Messages</span> <span class="h4 font-weight-bold mb-0">Direct Messages</span>
<span class="float-right"> <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> </span>
</div> </div>
<div class="card-header bg-white"> <div class="card-header bg-white">
@ -155,17 +155,11 @@
<span><i class="fas fa-chevron-right text-white"></i></span> <span><i class="fas fa-chevron-right text-white"></i></span>
</div> </div>
<div class="card-body d-flex align-items-center justify-content-center" style="height: 60vh;"> <div class="card-body d-flex align-items-center justify-content-center" style="height: 60vh;">
<div class=""> <div>
<p class="form-group"> <p class="mb-0 font-weight-bold">Select Recipient</p>
<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 <autocomplete
:search="composeSearch" :search="composeSearch"
:disabled="composeLoading"
placeholder="@dansup" placeholder="@dansup"
aria-label="Search usernames" aria-label="Search usernames"
:get-result-value="getTagResultValue" :get-result-value="getTagResultValue"
@ -173,15 +167,7 @@
ref="autocomplete" ref="autocomplete"
> >
</autocomplete> </autocomplete>
<span class="help-text small text-muted">Select a username to send a message to.</span> <div style="width:300px;"></div>
</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> </div>
</div> </div>
</div> </div>
@ -229,7 +215,10 @@ export default {
inbox: [], inbox: [],
sent: [], sent: [],
filtered: [] filtered: []
} },
newType: 'select',
composeLoading: false,
} }
}, },
@ -259,18 +248,9 @@ export default {
window._sharedData.curUser = res.data; window._sharedData.curUser = res.data;
}); });
}, },
goto(l = 'browse') { goto(l = 'browse') {
this.page = l; 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) { loadMessage(id) {
@ -279,24 +259,6 @@ export default {
return; 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) { truncate(t) {
return _.truncate(t); return _.truncate(t);
}, },
@ -345,21 +307,21 @@ export default {
if (input.length < 1) { return []; }; if (input.length < 1) { return []; };
let self = this; let self = this;
let results = []; let results = [];
return axios.get('/api/local/compose/tag/search', { return axios.post('/api/direct/lookup', {
params: {
q: input q: input
}
}).then(res => { }).then(res => {
return res.data; return res.data;
}); });
}, },
getTagResultValue(result) { getTagResultValue(result) {
return '@' + result.name; // return '@' + result.name;
return result.local ? '@' + result.name : result.name;
}, },
onTagSubmitLocation(result) { onTagSubmitLocation(result) {
//this.$refs.autocomplete.value = ''; //this.$refs.autocomplete.value = '';
this.composeLoading = true;
window.location.href = '/account/direct/t/' + result.id; window.location.href = '/account/direct/t/' + result.id;
return; return;
}, },

View file

@ -480,7 +480,7 @@
if(c) { if(c) {
axios.delete('/api/direct/message', { axios.delete('/api/direct/message', {
params: { params: {
id: self.ctxContext.id id: self.ctxContext.reportId
} }
}).then(res => { }).then(res => {
self.threads[self.threadIndex].messages.splice(self.ctxIndex,1); self.threads[self.threadIndex].messages.splice(self.ctxIndex,1);
@ -543,8 +543,9 @@
self.uploadProgress = 100; self.uploadProgress = 100;
self.uploading = false; self.uploading = false;
let msg = { let msg = {
id: Date.now(), id: e.data.id,
type: e.data.type, type: e.data.type,
reportId: e.data.reportId,
isAuthor: true, isAuthor: true,
text: null, text: null,
media: e.data.url, media: e.data.url,