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 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\AccountService;
|
||||||
|
use App\Services\StatusService;
|
||||||
use App\Services\WebfingerService;
|
use App\Services\WebfingerService;
|
||||||
use App\Models\Conversation;
|
use App\Models\Conversation;
|
||||||
|
|
||||||
|
@ -435,8 +437,10 @@ class DirectMessageController extends Controller
|
||||||
->get();
|
->get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$res = $res->filter(function($s) {
|
||||||
$res = $res->map(function($s) use ($uid){
|
return $s && $s->status;
|
||||||
|
})
|
||||||
|
->map(function($s) use ($uid) {
|
||||||
return [
|
return [
|
||||||
'id' => (string) $s->id,
|
'id' => (string) $s->id,
|
||||||
'hidden' => (bool) $s->is_hidden,
|
'hidden' => (bool) $s->is_hidden,
|
||||||
|
@ -449,7 +453,8 @@ class DirectMessageController extends Controller
|
||||||
'reportId' => (string) $s->status_id,
|
'reportId' => (string) $s->status_id,
|
||||||
'meta' => json_decode($s->meta,true)
|
'meta' => json_decode($s->meta,true)
|
||||||
];
|
];
|
||||||
});
|
})
|
||||||
|
->values();
|
||||||
|
|
||||||
$w = [
|
$w = [
|
||||||
'id' => (string) $r->id,
|
'id' => (string) $r->id,
|
||||||
|
@ -458,10 +463,10 @@ class DirectMessageController extends Controller
|
||||||
'avatar' => $r->avatarUrl(),
|
'avatar' => $r->avatarUrl(),
|
||||||
'url' => $r->url(),
|
'url' => $r->url(),
|
||||||
'muted' => UserFilter::whereUserId($uid)
|
'muted' => UserFilter::whereUserId($uid)
|
||||||
->whereFilterableId($r->id)
|
->whereFilterableId($r->id)
|
||||||
->whereFilterableType('App\Profile')
|
->whereFilterableType('App\Profile')
|
||||||
->whereFilterType('dm.mute')
|
->whereFilterType('dm.mute')
|
||||||
->first() ? true : false,
|
->first() ? true : false,
|
||||||
'isLocal' => (bool) !$r->domain,
|
'isLocal' => (bool) !$r->domain,
|
||||||
'domain' => $r->domain,
|
'domain' => $r->domain,
|
||||||
'timeAgo' => $r->created_at->diffForHumans(null, true, true),
|
'timeAgo' => $r->created_at->diffForHumans(null, true, true),
|
||||||
|
@ -482,17 +487,62 @@ class DirectMessageController extends Controller
|
||||||
$pid = $request->user()->profile_id;
|
$pid = $request->user()->profile_id;
|
||||||
|
|
||||||
$dm = DirectMessage::whereFromId($pid)
|
$dm = DirectMessage::whereFromId($pid)
|
||||||
->whereStatusId($sid)
|
->whereStatusId($sid)
|
||||||
->firstOrFail();
|
->firstOrFail();
|
||||||
|
|
||||||
$status = Status::whereProfileId($pid)
|
$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;
|
$dmc = $dm;
|
||||||
$this->remoteDelete($dmc);
|
$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();
|
$status->delete();
|
||||||
$dm->delete();
|
$dm->delete();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue