forked from mirror/pixelfed
Update DirectMessageController to support new Metro 2.0 UI DMs
This commit is contained in:
parent
d43908780f
commit
a4659fd2ab
1 changed files with 61 additions and 11 deletions
|
@ -19,6 +19,8 @@ use App\Services\MediaBlocklistService;
|
|||
use App\Jobs\StatusPipeline\NewStatusPipeline;
|
||||
use Illuminate\Support\Str;
|
||||
use App\Util\ActivityPub\Helpers;
|
||||
use App\Services\AccountService;
|
||||
use App\Services\StatusService;
|
||||
use App\Services\WebfingerService;
|
||||
use App\Models\Conversation;
|
||||
|
||||
|
@ -435,8 +437,10 @@ class DirectMessageController extends Controller
|
|||
->get();
|
||||
}
|
||||
|
||||
|
||||
$res = $res->map(function($s) use ($uid){
|
||||
$res = $res->filter(function($s) {
|
||||
return $s && $s->status;
|
||||
})
|
||||
->map(function($s) use ($uid) {
|
||||
return [
|
||||
'id' => (string) $s->id,
|
||||
'hidden' => (bool) $s->is_hidden,
|
||||
|
@ -449,7 +453,8 @@ class DirectMessageController extends Controller
|
|||
'reportId' => (string) $s->status_id,
|
||||
'meta' => json_decode($s->meta,true)
|
||||
];
|
||||
});
|
||||
})
|
||||
->values();
|
||||
|
||||
$w = [
|
||||
'id' => (string) $r->id,
|
||||
|
@ -458,10 +463,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),
|
||||
|
@ -482,17 +487,62 @@ class DirectMessageController extends Controller
|
|||
$pid = $request->user()->profile_id;
|
||||
|
||||
$dm = DirectMessage::whereFromId($pid)
|
||||
->whereStatusId($sid)
|
||||
->firstOrFail();
|
||||
->whereStatusId($sid)
|
||||
->firstOrFail();
|
||||
|
||||
$status = Status::whereProfileId($pid)
|
||||
->findOrFail($dm->status_id);
|
||||
->findOrFail($dm->status_id);
|
||||
|
||||
if($dm->recipient->domain) {
|
||||
$recipient = AccountService::get($dm->to_id);
|
||||
|
||||
if(!$recipient) {
|
||||
return response('', 422);
|
||||
}
|
||||
|
||||
if($recipient['local'] == false) {
|
||||
$dmc = $dm;
|
||||
$this->remoteDelete($dmc);
|
||||
}
|
||||
|
||||
if(Conversation::whereStatusId($sid)->count()) {
|
||||
$latest = DirectMessage::where(['from_id' => $dm->from_id, 'to_id' => $dm->to_id])
|
||||
->orWhere(['to_id' => $dm->from_id, 'from_id' => $dm->to_id])
|
||||
->latest()
|
||||
->first();
|
||||
|
||||
if($latest->status_id == $sid) {
|
||||
Conversation::where(['to_id' => $dm->from_id, 'from_id' => $dm->to_id])
|
||||
->update([
|
||||
'updated_at' => $latest->updated_at,
|
||||
'status_id' => $latest->status_id,
|
||||
'type' => $latest->type,
|
||||
'is_hidden' => false
|
||||
]);
|
||||
|
||||
Conversation::where(['to_id' => $dm->to_id, 'from_id' => $dm->from_id])
|
||||
->update([
|
||||
'updated_at' => $latest->updated_at,
|
||||
'status_id' => $latest->status_id,
|
||||
'type' => $latest->type,
|
||||
'is_hidden' => false
|
||||
]);
|
||||
} else {
|
||||
Conversation::where([
|
||||
'status_id' => $sid,
|
||||
'to_id' => $dm->from_id,
|
||||
'from_id' => $dm->to_id
|
||||
])->delete();
|
||||
|
||||
Conversation::where([
|
||||
'status_id' => $sid,
|
||||
'from_id' => $dm->from_id,
|
||||
'to_id' => $dm->to_id
|
||||
])->delete();
|
||||
}
|
||||
}
|
||||
|
||||
StatusService::del($status->id, true);
|
||||
|
||||
$status->delete();
|
||||
$dm->delete();
|
||||
|
||||
|
|
Loading…
Reference in a new issue